class %Compiler.COS.Visitor
extends %Compiler.Util.Visitor
property blockTypeStack
as %Integer;
blockTypeStack is a pointer to a stack used to hold the current block type.
The initial state of the code generator visitor is to not be in any block.
Certain node types identify new source code structures and the type of structure
is pushed onto this stack. For example, CREATE PROCEDURE/CREATE FUNCTION
will push a standard statement block token onto this stack, as will BEGIN.
END PROCEDURE and END will pop this stack (no node type for that, just the
last action in the CREATE/BEGIN visit). Loops will push a value as well.
For this Code Generator, the following types are recognized:
SB - Statement Block;
FE - FOREACH;
FL - FOR loop;
WL - WHILE loop;
IS - INDIVIDUAL STATEMENT - this is the initial state of the visitor;
property codeStack
as %Integer;
codestack is a pointer to a stack used to hold code generated by visit methods.
This stack is cleared when visiting nodes that move code into flo.
property compileParameter
as %CacheString [ MultiDimensional ];
property contextStack
as %Integer;
contextStack
Pointer to a stack used to hold the syntax context. If the nodeType on
descent needs a specific codeGenerator context then push the new context
onto this stack. Pop the stack after the node is visited.
context is 'p', 's' or 'c'. 'p' - procedural context, 's' - sql context and
'c' is 'call' context. There are symbol tables for 'p' and 's' but 'c' uses the
'p'-table. 'c' symbol references are coerced to use 'p' context but a '.' precedes
the symbol.
property errorQueue
as %Integer;
property exceptionDepth
as %Integer;
exceptionDepth is the nesting depth of exceptions. The outermost ON EXCEPTION sets this to 1.
Each nested ON EXCEPTION increments the depth. Visiting the ON EXCEPTION node decrements the depth.
property exceptionStack
as %Integer;
exceptionStack is a pointer to a stack used to manage exception handlers in statement blocks
property formalSpec
as %CacheString;
formalSpec - parsed formalSpec in the form produced by serializeFormal^%occName
This value is used to define formal argument symbols when initializing the visitor
#; Serialized formal list is a $list() of argument serializations which is:
#; $ListBuild(,,,,,,,...,,)
property importPackages
as %CacheString;
importPackages - a comma delimited list of package names to be imported into prepared statement implementations. These imports
are used to resolve unqualified SQL names.
property opStack
as %Integer;
opStack - a convenient place to place things for use by a parent node.
An operand stack is the same as any other stack but elements should be managed
using the four argument xxxoperand macros instead of the two argument macros.
To push - $$$pushoperand(,,,)
to pop - $$$popoperand(,,,)
to discard, use the same $$$pop().
property settings
as %CacheString [ MultiDimensional ];
settings is the local copy of the ^%SYS("xsql","informix") configuration options. A local copy is maintained because
Informix source can alter the settings during compilation.
Current settings include:
CASEINSCOMPARE - case insensitive compare. On by default.
QUITONERROR - exit the current procedure if an error is detected
DELIMIDENT - Allow identifiers to be quoted. This changes the default string delimiter from " to '.
TRACE - Generate a TRACE log
property warningQueue
as %Integer;
method %DispatchMethod(methodName As %String, args...)
UNKNOWN
classmethod compile(ByRef source As %CacheString, pPackage As %CacheString = "", ByRef code As %CacheString, ByRef warning As %Status = 1)
as %Status
compile()
This method instantiates the visitor and the element class (the ParseTree)
and invokes the accept() method on the element class. The results are
retrieved from the visitor instance and returned to the caller.
classmethod compileStream(source As %Stream.Object, pPackage As %String(MAXLEN="")="", ByRef code As %CacheString, ByRef warning As %Status = 1)
as %Status
compileStream()
This method instantiates the visitor and the element class (the ParseTree)
and invokes the accept() method on the element class. The results are
retrieved from the visitor instance and returned to the caller.
method finalizeCode(ByRef pSource As %CacheString, ByRef pCode As %CacheString)
as %Status
finalizeCode prepares the code for return to the caller. Normally it is just an array
of code, subscripted by a line number with the array root set to the number of lines.
In some cases, the code returned can be an oref to a class definition object.
pSource is the source argument passed to the compile method. It can be an array or a
stream object. It is passed in case something from the source needs to be included in
the final code value returned by this method.
classmethod interactive(ByRef generated As %CacheString, trigger As %Boolean = 0)
as %Status
interactive - read source from the principle device and pass to the compile method
method v1(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
PlainBlock(1): child list-Line
NOT GENERATED - you MUST run makehptinc.pl if you edit this
Used by %CPT.HPT.* classes.
PROGRAM STRUCTURE
method v10(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
UnknownPreProcessorCommand(10): ann string Snarf:1
method v11(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
CommandSET(11): ann name CommandName:1, optional child PostCondition-Expression:1, optional child Arguments-CommandSETArguments:2
SET COMMAND
method v12(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
CommandSETArguments(12): child list-CommandSETArgument
method v13(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
CommandSETArgument(13): child Lhs-CommandSETArgLhs:1, child Rhs-Expression:2
method v14(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
CommandSETArgLhs(14): ann bool IsMultiple:1, child list-SETTarget
method v15(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
CommandIFLine(15): ann name CommandName:1, optional child Conditions-ListExpressions:1, optional child RestOfLine-ListLineElement:2
nodeclass SETTarget: LvnRef
for now
IF LINE COMMAND
method v16(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
ListLineElements(16): child list-LineElement
method v17(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
CommandIFBlock(17): child If-CommandIFBlockIf:1, optional child ListElseIf-ListCommandIFBlockElseIf:2, optional child Else-CommandIFBlockElse:3
IF CONSTRUCT COMMAND
method v18(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
CommandIFBlockIf(18): ann name CommandName:1, optional child Conditions-ListExpressions:1, child BraceBlock:2
Conditions is omitted if empty
method v19(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
CommandIFBlockElse(19): ann name CommandName:1, child BraceBlock:1
method v2(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
PlainLine(2): optional ann name Label:1, optional child ListFormals:1, optional child Body-LineBody:2
CODE LINES
method v20(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
CommandIFBlockElseIf(20): ann name CommandName:1, optional child Conditions-ListExpressions:1, child BraceBlock:2
Conditions is omitted if empty
method v21(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
BraceBlock(21): child list-Line
method v22(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
ListCommandIFBlockElseIf(22): child list-CommandIFBlockElseIf
method v23(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
CommandWHILEBlock(23): ann name CommandName:1, child Conditions-ListExpressions:1, child BraceBlock:2
WHILE CONSTRUCT COMMAND
method v24(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
CommandDOBlock(24): ann name CommandName:1, child BraceBlock:1, child WhilePart-CommandDOBlockWhile:2
DO CONSTRUCT COMMAND
method v25(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
ListExpressions(25): child list-Expression
EXPRESSIONS
method v26(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
Argument(26): ann string Snarf:1
method v27(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
LiteralString(27): ann string Value:1
nodeclass ExprOrTerm: Expression | Term
nodeclass Term: LvnRef | LiteralString | LiteralNumber | ParenExpr | SystemVar | ObjectRef | GvnRef | SystemFun
| Indirection | ExtrFunCall | SsvnRef | VisualM | SlotVar | MacroCall | PPFunc
VisualM b/w "_"
monops: + - '
method v28(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
LiteralNumber(28): ann string Value:1
method v29(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
ParenExpr(29): child Expr-Expression:1
method v3(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
LineBody(3): optional child ListLineElements:1, optional child LineCommand:2
method v30(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
SystemVar(30): ann string VarName:1
method v31(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
Subscripts(31): child ListExpressions:1
method v32(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
ObjectRef(32): child ObjectRefBase:1, optional child ListMemberRefs:2
method v33(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
ListMemberRefs(33): child list-MemberRef
nodeclass ObjectRefBase: Term | PPClass | DotDotBase
note: HPT only supports the following sorts of Term as an object base: LvnRef, ParenExpr, SystemVar
(just to confirm: ObjectRef won't appear here either)
method v34(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
MemberRef(34): ann name MemberName:1, optional child ActualParameters:1
method v35(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
PPClass(35): ann name ClassKeywordName:1, child ListClassNameComponents:1
method v36(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
ClassNameComponent(36): ann name Name:1
method v37(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
DotDotBase(37): child MemberRef:1
method v38(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
ActualParameters(38): child list-ActualParameter
method v39(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
ByRefLvn(39): child LvnRef:1
nodeclass ActualParameter: Expression | ByRefLvn | Omitted
method v4(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
CommandGeneral(4): ann name CommandName:1, optional child PostCondition-Expression:1, optional child Arguments-CommandGeneralArguments:2
nodeclass LineElement: Command
COMMANDS
not all commands have postconditions so an optional OmittedPostCondition child is used in these cases - no child will ever appear in the tree
... this means that we can fix the common annotation and child indices of non-construct command nodes :-
CommandName is 1, PostCondition is 1, ListCommandArguments is 2
nodeclass Command: PlainCommand | BlockCommand
nodeclass PlainCommand: CommandGeneral | CommandSET | CommandIFLine | CommandDO
nodeclass BlockCommand: CommandIFBlock | CommandWHILEBlock
method v40(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
Omitted(40):
method v41(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
ListClassNameComponents(41): child list-ClassNameComponent
NAMES
method v42(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
GvnRef(42): optional ann name Name:1, optional child Environment:1, optional child Subscripts:2
the Name does not include the "^"
Name and Environment are absent for a naked reference
method v43(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
Environment(43): ann bool BracketsUsed:1, optional child Env1:1, optional child Env2:2
method v44(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
CommandDO(44): ann name CommandName:1, optional child PostCondition-Expression:1, optional child Arguments-CommandDOArguments:2
DO COMMAND
method v45(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
CommandDOArguments(45): child list-CommandDOArgument
method v46(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
SystemFunGeneral(46): ann string FunName:1, child Arguments-ListExpressions:1
SYSTEM FUNCTIONS
nodeclass SystemFun: SystemFunGeneral | SystemFunCASE | SystemFunDATA | SystemFunGET | SystemFunORDER | SystemFunSELECT
method v47(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
CommandDOBlockWhile(47): ann name CommandName:1, child Conditions-ListExpressions:1
method v48(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
SystemFunORDER(48): ann string FunName:1, child Reference:1, optional child Direction-Expression:2, optional child Data-Reference:3
method v49(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
SystemFunDATA(49): ann string FunName:1, child Reference:1, optional child Data-Reference:2
method v5(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
Expression(5): child Lhs-ExprOrTerm:1, optional ann string DyOp:1, optional child Rhs-ExprOrTerm:2
method v50(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
SystemFunGET(50): ann string FunName:1, child Reference:1, optional child Default-Expression:2
method v51(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
SystemFunSELECT(51): ann string FunName:1, child list-SystemFunSELECTItem
method v52(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
SystemFunSELECTItem(52): child Condition-Expression:1, child Result-Expression:2
method v53(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
SystemFunCASE(53): ann string FunName:1, child Base-Expression:1, child Items-ListSystemFunCASEItems:2
method v54(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
ListSystemFunCASEItems(54): child list-SystemFunCASEItem
method v55(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
SystemFunCASEItem(55): optional child Test-Expression:1, child Result-Expression:2
the Test child can only be absent in the final Item in the parent list
method v56(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
PPDim(56): ann name DimName:1, child ListLvns:1, optional child As-PPDimAs:2, optional child Assign-PPDimAssign:3
nodeclass Line: PreProcessorCommand | PlainLine
PREPROCESSOR
nodeclass PreProcessorCommand: PPDim | UnknownPreProcessorCommand
method v57(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
Lvn(57): ann name Name:1
method v58(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
ListLvns(58): child list-Lvn
method v59(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
PPDimAs(59): ann name AsName:1, ann name CollectionTypeName:2, ann name OfName:3, ann enum CollectionType:4, child Class-ListClassNameComponents:1
CollectionTypeName and OfName are empty unless CollectionType is List or Array
enum CollectionType: List:1, Array:2
method v6(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
CommandGeneralArguments(6): child list-Argument
method v60(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
PPDimAssign(60): child Expression:1
method v7(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
ListFormals(7): child list-Formal
method v8(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
Formal(8): ann bool Ampersand:1, ann name Name:2, ann bool Scoop:3, optional child Default-Expression:1
the default Expression will always be a Literal
method v9(parseTree As %Compiler.Util.ParseTree, visit As %Integer, nodePtr As %Integer, parentPtr As %Integer)
LvnRef(9): ann name Name:1, ann enum LvnType:2, optional child Subscripts:1
nodeclass CommandDOArgument: ObjectRef
just that for now
LOCAL/GLOBAL VARIABLES
enum LvnType: Private:1, Public:2, Parameter:3