Basics-AttributeVisibility.xml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
  4. <sect1 id="Attribute_Visibility">
  5. <title>Definition Visibility<indexterm>
  6. <primary>Definition Visibility</primary>
  7. </indexterm></title>
  8. <para>ECL code, definitions, are stored in .ECL files <indexterm>
  9. <primary>.ECL files</primary>
  10. </indexterm>in your code repository, which are organized into modules
  11. (directories or folders on disk). Each .ECL file may only contain a single
  12. EXPORT or SHARED definition (see below) along with any supporting local
  13. definitions required to fully define the definition's result. The name of
  14. the file and the name of its EXPORT or SHARED definition must exactly
  15. match.</para>
  16. <para>Within a module (directory or folder on disk), you may have as many
  17. EXPORT and/or SHARED definitions as needed. An IMPORT statement (see the
  18. <emphasis role="bold">IMPORT </emphasis>keyword) identifies any other
  19. modules whose visible definitions will be available for use in the current
  20. definition.</para>
  21. <para>The following fundamental definition visibility scopes are available
  22. in ECL: <emphasis role="bold">"Global," Module</emphasis>, and <emphasis
  23. role="bold">Local</emphasis>.</para>
  24. <sect2 id="Global_attribute_visibility">
  25. <title>"Global"</title>
  26. <para>Definitions defined as <emphasis
  27. role="bold">EXPORT</emphasis><indexterm>
  28. <primary>EXPORT</primary>
  29. </indexterm> (see the <emphasis role="bold">EXPORT</emphasis> keyword)
  30. are available throughout the module in which they are defined, and
  31. throughout any other module that IMPORTs that module (see the <emphasis
  32. role="bold">IMPORT</emphasis> keyword).</para>
  33. <programlisting>//inside the Definition1.ecl file (in AnotherModule folder) you have:
  34. EXPORT Definition1 := 5;
  35. //EXPORT makes Definition1 available to other modules and
  36. //also available throughout its own module</programlisting>
  37. </sect2>
  38. <sect2 id="Module">
  39. <title>Module</title>
  40. <para>The scope of the definitions defined as <emphasis
  41. role="bold">SHARED<indexterm>
  42. <primary>SHARED</primary>
  43. </indexterm></emphasis> (see the <emphasis role="bold">SHARED</emphasis>
  44. keyword) is limited to that one module, and are available throughout the
  45. module (unlike local definitions). This allows you to keep private any
  46. definitions that are only needed to implement internal functionality.
  47. SHARED definitions are used to support EXPORT definitions.</para>
  48. <programlisting>//inside the Definition2.ecl file you have:
  49. IMPORT AnotherModule;
  50. //makes definitions from AnotherModule available to this code, as needed
  51. SHARED Definition2 := AnotherModule.Definition1 + 5;
  52. //Definition2 available throughout its own module, only
  53. //*****************************************************************************
  54. //then inside the Definition3.ecl file (in the same folder as Definition2) you have:
  55. IMPORT $;
  56. //makes definitions from the current module available to this code, as needed
  57. EXPORT Definition3 := $.Definition2 + 5;
  58. //make Definition3 available to other modules and
  59. //also available throughout its own module</programlisting>
  60. </sect2>
  61. <sect2 id="Local">
  62. <title>Local</title>
  63. <para>A definition without either the EXPORT or SHARED keywords is
  64. available only to subsequent definitions, until the end of the next EXPORT
  65. or SHARED definition. This makes them private definitions used only within
  66. the scope of that one EXPORT or SHARED definition, which allows you to
  67. keep private any definitions that are only needed to implement internal
  68. functionality. Local definitions definitions are used to support the
  69. EXPORT or SHARED definition in whose file they reside. Local definitions
  70. are referenced by their definition name alone; no qualification is
  71. needed.</para>
  72. <programlisting>//then inside the Definition4.ecl file (in the same folder as Definition2) you have:
  73. IMPORT $;
  74. //makes definitions from the current module available to this code, as needed
  75. LocalDef := 5;
  76. //local -- available through the end of Definition4's definition, only
  77. EXPORT Definition4 := LocalDef + 5;
  78. //EXPORT terminates scope for LocalDef
  79. LocalDef2 := Definition4 + LocalDef;
  80. //INVALID SYNTAX -- LocalDef is out of scope here
  81. //and any local definitions following the EXPORT
  82. //or SHARED definition in the file are meaningless
  83. //since they can never be used by anything
  84. </programlisting>
  85. <para>The <emphasis role="bold">LOCAL</emphasis><indexterm>
  86. <primary>LOCAL</primary>
  87. </indexterm> keyword is valid for use within any nested structure, but
  88. most useful within a FUNCTIONMACRO structure to clearly identify that the
  89. scope of a definition is limited to the code generated within the
  90. FUNCTIONMACRO.</para>
  91. <programlisting>AddOne(num) := FUNCTIONMACRO
  92. LOCAL numPlus := num + 1;
  93. RETURN numPlus;
  94. ENDMACRO;
  95. numPlus := 'this is a syntax error without LOCAL in the FUNCTIONMACRO';
  96. numPlus;
  97. AddOne(5);
  98. </programlisting>
  99. <para>See Also: <link linkend="IMPORT">IMPORT</link>, <link
  100. linkend="EXPORT">EXPORT</link>, <link linkend="SHARED">SHARED</link>,
  101. <link linkend="MODULE_Structure">MODULE</link>, <link
  102. linkend="FUNCTIONMACRO_Structure">FUNCTIONMACRO</link></para>
  103. </sect2>
  104. </sect1>