During the code generation phase ASPC does one very
important task - symbols linking. A symbol is any identifier
used in the statements in the source code. For example a
variable used in statement is a symbol or function called is
a symbol too.
Thus symbol represents a data or code unit of the program
structure. Everything defined by the developer or defined as
par of the standard language functions is a symbol.
Execution of your code is calculation made using symbols
(obtaining their value if they are variables or calling them
if they are routines). Thus symbols are the most important
thing in the application.
The symbol selection mechanism depends on the general
idea realized by the programming language or development
tool. Thus VBScript differs from VB. Read Execution
contexts to learn more about these differences and learn
the details you need to know when using ASPC.
On the diagram you can see the order in which a symbol is
searched. You can read the following description now or
after reading the Execution
contexts chapter.
- When processing a statement ASPC finds a symbol - a
variable name or a function/Sub/Property name. It needs
to know where this symbol points.
- To learn that ASPC searches the containing routine.
Remember that it is already analyzed and the information
about the local variables and arguments is stored in the
enveloping objects in the code
structure tree. Thus ASPC looks if this symbol is
not a local variable or routine argument. If so linking
ends here and symbol remains in VB code "as
is". If the symbol is not found there ASPC searches
the node which contains the routine - it can be a VBS
class or the Root class (class created from the global
part of the code in your page/script). Then for example
if symbol is found in the Root class ASPC changes the
symbol name to point to the member of this class. To do
so ASPC adds a member variable in the VBS classes -
which points to the Root class. Thus all the created
objects have "knowledge" for their creator and
symbol change will include usage of this variable.
- If not found there ASPC looks in the list of
variables, constants and routines declared DLLGlobal.
- After all if the symbol is not found in the tree ASPC
looks for it in the symbols file which lists the VB
language standard Functions/Subs/Constants etc. And if
found it changes the symbol as described in the file or
places it "as is" - what is appropriate.
- If the symbol is not found nor in the tree nor in the
symbols file compiler issues a warning message to remind
you that the symbol is not known. You do not need Option
explicit when working with ASPC but these warnings are
equivalent to the errors issued by VB with this option.
If may want to ignore them but it is strongly
recommended to declare all the variables to prevent at
least future problems caused by their incorrect usage.
Anyway VB seems to be the only popular compiled language
which allows variables to not be declared. It is common
rule across the compiled languages that variable
declarations help to explicitly define the variables
scope thus leaving the language to choose the scope may
cause wrong selection (the compiler may not assume
default scope as you think or you may forget what the
variable is intended for).
|