|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object SymbolTableEntry FunctionEntry
FunctionEntry extends SymbolTableEntry by adding data fields to support functions, procedures, and methods. These forms of functional construct are considered equivalent for the purposes of storing data in a symbol table.
The public data fields of a FunctionEntry are a TreeNodeList of formal parameters, a TreeNode body, and a SymbolTable scope. The inherited type field is used to hold the return type of the function.
The scope field holds a reference to the function's own local scope. All of the function's formal parameters and local variables are entered in this local table. In this way, the table defines a scope that belongs to the function, which is the standard semantics in block-structured programming languages.
In programming languages that allow nested function definitions, a function's local scope may have further nested scopes. These are represented simply by having function entries in a parent function's scope table. Nested symbol tables are also used to represent anonymous inner scopes, such as nested declaration/statement blocks, in languages that all such constructs. See the documentation of the SymbolTable class for a large-grain picture and description of nested scope representation.
A function's formal parameters are stored both in the formals list as well as being entered in the local symtab scope. The list is necessary when parameters need to be accessed in left-to-right declared order. The formals are also entered in the function's local scope, so they have a storage identity that is distinct to this scope.
The body data field of a function is a reference to the entire parse tree for its executable body. This tree is used for back-end processing, which can include one or more of the following phases: type checking, interpretation, and/or code generation.
Field Summary | |
TreeNode |
body
Function body, in the form of its raw parse tree. |
TreeNodeList |
formals
Formal parameter list, in declared order. |
SymbolTable |
scope
Local scope for this function. |
Fields inherited from class SymbolTableEntry |
name, type |
Constructor Summary | |
FunctionEntry()
Construct this with null data fields. |
|
FunctionEntry(java.lang.String name,
TreeNode type,
TreeNodeList formals,
TreeNode body,
SymbolTable scope)
Construct this with the given data field values. |
Method Summary | |
protected java.lang.String |
formalsString(int level)
Called by toString to stringify the list of formal parameter names. |
protected java.lang.String |
scopeString(int level)
Called by toString to recursively stringify the scope, if non-null. |
java.lang.String |
toString(int level)
Return the string rep of this. |
Methods inherited from class SymbolTableEntry |
doToString, indentString, toString, toStringDeep, toStringDeep |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public TreeNodeList formals
public TreeNode body
public SymbolTable scope
Constructor Detail |
public FunctionEntry()
public FunctionEntry(java.lang.String name, TreeNode type, TreeNodeList formals, TreeNode body, SymbolTable scope)
Method Detail |
public java.lang.String toString(int level)
toString
in class SymbolTableEntry
protected java.lang.String formalsString(int level)
protected java.lang.String scopeString(int level)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |