123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
- "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
- <sect1 id="Attribute_Visibility">
- <title>Definition Visibility<indexterm>
- <primary>Definition Visibility</primary>
- </indexterm></title>
- <para>ECL code, definitions, are stored in .ECL files <indexterm>
- <primary>.ECL files</primary>
- </indexterm>in your code repository, which are organized into modules
- (directories or folders on disk). Each .ECL file may only contain a single
- EXPORT or SHARED definition (see below) along with any supporting local
- definitions required to fully define the definition's result. The name of
- the file and the name of its EXPORT or SHARED definition must exactly
- match.</para>
- <para>Within a module (directory or folder on disk), you may have as many
- EXPORT and/or SHARED definitions as needed. An IMPORT statement (see the
- <emphasis role="bold">IMPORT </emphasis>keyword) identifies any other
- modules whose visible definitions will be available for use in the current
- definition.</para>
- <para>The following fundamental definition visibility scopes are available
- in ECL: <emphasis role="bold">"Global," Module</emphasis>, and <emphasis
- role="bold">Local</emphasis>.</para>
- <sect2 id="Global_attribute_visibility">
- <title>"Global"</title>
- <para>Definitions defined as <emphasis
- role="bold">EXPORT</emphasis><indexterm>
- <primary>EXPORT</primary>
- </indexterm> (see the <emphasis role="bold">EXPORT</emphasis> keyword)
- are available throughout the module in which they are defined, and
- throughout any other module that IMPORTs that module (see the <emphasis
- role="bold">IMPORT</emphasis> keyword).</para>
- <programlisting>//inside the Definition1.ecl file (in AnotherModule folder) you have:
- EXPORT Definition1 := 5;
- //EXPORT makes Definition1 available to other modules and
- //also available throughout its own module</programlisting>
- </sect2>
- <sect2 id="Module">
- <title>Module</title>
- <para>The scope of the definitions defined as <emphasis
- role="bold">SHARED<indexterm>
- <primary>SHARED</primary>
- </indexterm></emphasis> (see the <emphasis role="bold">SHARED</emphasis>
- keyword) is limited to that one module, and are available throughout the
- module (unlike local definitions). This allows you to keep private any
- definitions that are only needed to implement internal functionality.
- SHARED definitions are used to support EXPORT definitions.</para>
- <programlisting>//inside the Definition2.ecl file you have:
- IMPORT AnotherModule;
- //makes definitions from AnotherModule available to this code, as needed
- SHARED Definition2 := AnotherModule.Definition1 + 5;
- //Definition2 available throughout its own module, only
- //*****************************************************************************
- //then inside the Definition3.ecl file (in the same folder as Definition2) you have:
- IMPORT $;
- //makes definitions from the current module available to this code, as needed
- EXPORT Definition3 := $.Definition2 + 5;
- //make Definition3 available to other modules and
- //also available throughout its own module</programlisting>
- </sect2>
- <sect2 id="Local">
- <title>Local</title>
- <para>A definition without either the EXPORT or SHARED keywords is
- available only to subsequent definitions, until the end of the next EXPORT
- or SHARED definition. This makes them private definitions used only within
- the scope of that one EXPORT or SHARED definition, which allows you to
- keep private any definitions that are only needed to implement internal
- functionality. Local definitions definitions are used to support the
- EXPORT or SHARED definition in whose file they reside. Local definitions
- are referenced by their definition name alone; no qualification is
- needed.</para>
- <programlisting>//then inside the Definition4.ecl file (in the same folder as Definition2) you have:
- IMPORT $;
- //makes definitions from the current module available to this code, as needed
- LocalDef := 5;
- //local -- available through the end of Definition4's definition, only
- EXPORT Definition4 := LocalDef + 5;
- //EXPORT terminates scope for LocalDef
- LocalDef2 := Definition4 + LocalDef;
- //INVALID SYNTAX -- LocalDef is out of scope here
- //and any local definitions following the EXPORT
- //or SHARED definition in the file are meaningless
- //since they can never be used by anything
- </programlisting>
- <para>The <emphasis role="bold">LOCAL</emphasis><indexterm>
- <primary>LOCAL</primary>
- </indexterm> keyword is valid for use within any nested structure, but
- most useful within a FUNCTIONMACRO structure to clearly identify that the
- scope of a definition is limited to the code generated within the
- FUNCTIONMACRO.</para>
- <programlisting>AddOne(num) := FUNCTIONMACRO
- LOCAL numPlus := num + 1;
- RETURN numPlus;
- ENDMACRO;
- numPlus := 'this is a syntax error without LOCAL in the FUNCTIONMACRO';
- numPlus;
- AddOne(5);
- </programlisting>
- <para>See Also: <link linkend="IMPORT">IMPORT</link>, <link
- linkend="EXPORT">EXPORT</link>, <link linkend="SHARED">SHARED</link>,
- <link linkend="MODULE_Structure">MODULE</link>, <link
- linkend="FUNCTIONMACRO_Structure">FUNCTIONMACRO</link></para>
- </sect2>
- </sect1>
|