|
||||||||||
前のクラス 次のクラス | フレームあり フレームなし | |||||||||
概要: 入れ子 | フィールド | コンストラクタ | メソッド | 詳細: フィールド | コンストラクタ | メソッド |
SymTable Symbol tabel interface.
An instance of SymTable is created for each scope of symbols corresponding such language constructs as program, subprogram, struct, etc. Relations between symbol table and program constructs: Several symbol tables are constructed according to the structure of given source program. At first, a global symbol table is created by initiate() of SymRoot and symbols inherent to the source language are recorded in it. When a new scope of symbols is opened, a new symbol table is created and linked to ancestor symbol table that contains symbols to be inherited by the new scope (pushSymTable()). When the current scope is closed, the current symbol table is closed and the ancestor symbol table becomes the current symbol table again (by using popSymTable()). Symbols are searched in the current symbol table (symTableCurrent of SymRoot) and its ancestors in the reverse order of scope addition. Popped symbol table is not discarded unless it is empty but made invisible for search procedures so as to make inter-procedure optimization and parallelization can be done. A symbol table usually has corresponding program construct such as subprogram. There are links between such constructs and corresponding symbol table to show their correspondence (getOwner). Anonymous construct (anlnymous Struct, BlockStmt, etc.) may have name generated by the compiler. Scope of symbols: Source program symbols (symbols appearing in source program) have their scope as defined by the grammar of the language. Each Struct and Union opens a new scope. Scope of constants is the entire compile unit. Scope of registers is the subprogram using them. Scope of temporal variables generated by the compiler is the subprogram within which the temporal variables are defined.
メソッドの概要 | |
Sym |
define(java.lang.String pInternedName,
int pSymKind,
Sym pDefinedIn)
define Define a new symbol specified by the parameter pInternedName in the current symbol table. |
Sym |
defineUnique(java.lang.String pInternedName,
int pSymKind,
Sym pDefinedIn)
defineUnique Define a new symbol specified by the parameter pInternedName in the current symbol table without traversing ancestor symbol tables. |
Sym |
generateDerivedSym(Sym pBaseSym)
generateDerivedSym Generate a symbol having the same type and kind as that of pSym in this symbol table. |
Elem |
generateElem(Type pType,
Sym pDefinedIn)
generateElem Generate an element of type pType in this symbol table. |
Label |
generateLabel()
generateLabel Generate an internal label in subpSymTable(). |
Param |
generateParam(Type pType,
Sym pDefinedIn)
generateParam Generate a parameter of type pType in subpSymTable(). |
Sym |
generateSym(Type pType,
int pSymKind,
java.lang.String pPrefix,
Sym pDefinedIn)
generateSym Generate a symbol of type pType in subpSymTable(). |
java.lang.String |
generateSymName(java.lang.String pHeader)
Generate symbol name which is unique in this SymTable and its ancestors. |
Sym |
generateTag()
generateTag Generate a tag name in subpSymTable(). |
Sym |
generateTag(java.lang.String tagname)
|
java.lang.String |
generateUniqueName(Sym pOldSym,
Subp pSubp)
Generate unique name for symbols in the form of subprogramName_originalName_n, where, subprogramName is the name of the subprogram defining the symbol ("" for global symbol), oroginalName is the name of the symbol, n is sequence number (1, 2, 3, ...) |
Var |
generateVar(Type pType)
generateVar Generate a variable of type pType in the symbol table of current subprogram symRoot.subpCurrent (to be used as temporal variable, etc.). |
Var |
generateVar(Type pType,
Sym pDefinedIn)
generateVar Generate a variable of type pType in subpSymTable() starting with "_var" (to be used as temporal variable, etc.). |
SymTable |
getBrother()
getBrother |
SymTable |
getFirstChild()
getFirstChild |
Sym |
getFirstSym()
getFirstSym Get the first symbol recorded in this symbol table. |
Sym |
getOwner()
getOwner Get the owner node to which this symbol table is attached. |
java.lang.String |
getOwnerName()
getOwnerName Get the name of the owner of this symbol table. |
SymTable |
getParent()
getParent Get parent symbol table of this table. |
Subp |
getSubp()
getSubp Get the subprogram to which this symbol table is attached or in which the owner of this symbol table is contained. |
int |
getSymCount()
getSymCount Get the number of symbols recorded in the symbol table. |
SymIterator |
getSymIterator()
getSymIterator Get iterator to scan all symbols recorded in this symbol table. |
SymNestIterator |
getSymNestIterator()
getSymNestIterator (##6) Get iterator to scan all symbols recorded in this symbol table and its children. |
SymTableIterator |
getSymTableIterator()
getSymTableIterator (##10) Get iterator to scan all symbols tables starting from this symbol table and its children. |
boolean |
isInThisSymTable(Sym pSym)
isInThisSymTable |
void |
linkSym(Sym pNewSym)
linkSym Link pNewSym as the last symbol of this symbol table. |
SymTable |
popSymTable()
popSymTable Close this (current) symbol table and make its ancestor symbol table as the current symbol table if this has the ancestor. |
void |
printSymTable()
printSymTable (##2) Print symbols in this symbol table using toString(). |
void |
printSymTableAll(SymTable pSymTable)
printSymTableAll (##2) Print symbols in pSymTable and all its descendent symbol tables using printSymTable. |
void |
printSymTableAllDetail()
printSymTableAllDetail with no param. |
void |
printSymTableAllDetail(SymTable pSymTable)
printSymTableAllDetail (##2) Print symbols in pSymTable and all its descendent symbol tables using printSymTableDetail. |
void |
printSymTableDetail()
printSymTableDetail (##2) Print symbols in this symbol table using toStringDetail(). |
SymTable |
pushSymTable(Sym pOwner)
pushSymTable Make this (current) symbol table as an ancestor symbol table and create a new symbol table making it as the current symbol table. |
Sym |
redefine(Sym pSym,
int pSymKind,
Sym pDefinedIn)
redefine Create a new symbol that has the name same as this symbol but having the symbol kind indicated by the parameter pSymKind in the current symbol table. |
SymTable |
reopenSymTable(SymTable pPreviousSymTable)
reopenSymTable Push this (current) symbol table as the ancestor symbol table and make the symbol table specified by the parameter as the new current symbol table. |
Sym |
search(java.lang.String pInternedName)
search Search the symbol specified by the parameter pInternedName in the current symbol table and its ancestors. |
Sym |
search(java.lang.String pInternedName,
int pSymKind)
search Search symbol having pInternedName as its name and pSymKind as its kind. |
Sym |
searchLocal(java.lang.String pInternedName,
int pSymKind)
searchLocal Search the symbol which is specified by parameter pInternedName and whose kind is the same as pSymKind. |
Sym |
searchLocal(java.lang.String pInternedName,
int pSymKind,
boolean pSpecifiedKind)
searchLocal Search the symbol which is specified by parameter pInternedName. |
Sym |
searchOrAdd(java.lang.String pInternedName,
int pSymKind,
Sym pDefinedIn,
boolean pWithinThisTable,
boolean pSpecifiedKind)
searchOrAdd Search the symbol which is specified by parameter pInternedName, pSymKind. |
SymTableEntry |
searchOrAddEntry(java.lang.String pInternedName,
int pSymKind,
Sym pDefinedIn,
boolean pWithinThisTable,
boolean pSpecifiedKind)
searchOrAddEntry Search a symbol table entry where a symbol is to be placed. |
Sym |
searchOrAddSym(Sym pSym)
searchOrAddSym Search the symbol pSym in this symbol table If found, return it. |
Sym |
searchSymOfThisKind(Sym pSym,
int pSymKind)
searchSymOfThisKind Search for the smbol having the same name as the parameter pSym and its kind is the same to pSymKind in the same manner as Search. |
SymTable |
searchTableHaving(Sym pSym)
searchTableHaving Search the symbol table that has pSym starting from this symbol table and ascending to its sncestors. |
void |
setUniqueNameToAllSym()
setUniqueNameToAllSym Set unique name to all symbols of the kind Var, Param, Subp, Label in the whole compile unit. |
SymTable |
subpSymTable()
subpSymTable Get the symbol table of current subprogram. |
メソッドの詳細 |
public SymTable pushSymTable(Sym pOwner)
pOwner
- Symbol owning the the new SymTable
(subprogram, etc.), null if no symbol corresponds.
public SymTable popSymTable()
public SymTable reopenSymTable(SymTable pPreviousSymTable)
pPreviousSymTable
- a symbol table that was once
a direct descentdant symbol table of this symbol table.
public SymTable getParent()
public SymTable getFirstChild()
public SymTable getBrother()
public SymTable searchTableHaving(Sym pSym)
pSym
- symbol in a symbol table.
public Sym defineUnique(java.lang.String pInternedName, int pSymKind, Sym pDefinedIn)
Define a new symbol specified by the parameter pInternedName in the current symbol table without traversing ancestor symbol tables. If there is already a symbol with the same name as pInternedName, then it is treated as an erronous call and no new symbol is created. "this" should be the current symbol table. Note: If pSymKind is either symKindSubp, symKindVar, symKindParam, symKindElem, or symKindConst, etc. then either Subp, Var, Param, Elem, or Const instance is created each respectively. Several linkages are made between the defined symbol and pDefinedIn symbol (see definedIn(), getFirstParam(), getFirstLocalVar(), getFirstElem(), getNext(), getNextSubp(), etc.) These rules are applied also to Define and redefine.
pInternedName
- unique string representing the symbol to be defined.pSymKind
- kind of the symbol to be created (see GlobalConstants).pDefinedIn
- symbol representing language construct such as
subprogram name or structure name that encloses the definition of
the symbol to be defined; If there is no such construct, specify null.
(See definedIn().)
public Sym define(java.lang.String pInternedName, int pSymKind, Sym pDefinedIn)
Define a new symbol specified by the parameter pInternedName in the current symbol table. If there is already an old symbol with the same name as pInternedName and with the same kind as pSymKind in this symbol table, then no new symbol is created and the old symbol is returned. Ancestor symbol tables are not traversed to find the same symbol. "this" should be the current symbol table.
pInternedName
- unique string representing the symbol to be defined.pSymKind
- kind of the symbol to be created (see GlobalConstants).pDefinedIn
- language construct symbol that encloses the definition
of pInternedName; If there is no such construct, specify null.
public Sym search(java.lang.String pInternedName)
Search the symbol specified by the parameter pInternedName in the current symbol table and its ancestors. The symbol is searched in the current symbol table first, and if not found, then searched in its direct ancestor, and if not found again, then searched in ancestor's ancestor, and so on. If there are more than one symbols having the same name then the one encountered first in the above search process is returned. "this" should be the current symbol table. See searchSymOfThisKind and redefine.
pInternedName
- unique string representing the symbol to be searched.
public Sym search(java.lang.String pInternedName, int pSymKind)
pInternedName
- unique string representing the symbol to be searched.pSymKind
- symbol kind (Sym.KIND_VAR, etc.).
public Sym searchLocal(java.lang.String pInternedName, int pSymKind)
pInternedName
- symbol name which is Interned.pSymKind
- symbol kind (Sym.KIND_VAR, etc.).
public Sym searchLocal(java.lang.String pInternedName, int pSymKind, boolean pSpecifiedKind)
pInternedName
- symbol name which is Interned.pSymKind
- symbol kind (Sym.KIND_VAR, etc.).pSpecifiedKind
- If ture, search symbol of the same name
and the same kind.
public Sym searchSymOfThisKind(Sym pSym, int pSymKind)
pSym
- a symbol having the same name as the one to be searched.pSymKind
- kind of the symbol to be searched;
It may be different from the symbol kind of pSym.
public Sym redefine(Sym pSym, int pSymKind, Sym pDefinedIn)
Create a new symbol that has the name same as this symbol but having the symbol kind indicated by the parameter pSymKind in the current symbol table. "this" should be the current symbol table. Usage of redefine If the source language permits the same name to be defined as a name of different kind in the same scope, then Search may return a symbol having the same name but with different kind. In that case, search ancestors again by searchSymOfThisKind and if not found, then use redefine to define the symbol as the new one of pSymKind. For example, enumerator may have the same name as that of some subprogram in C.
pSymKind
- symbol kind of the symbol to be created.pDefinedIn
- language construct symbol that encloses the
definition
of pSym; If there is no such construct, specify null.
public Sym searchOrAddSym(Sym pSym)
pSym
- symbol to be searched.
public Sym searchOrAdd(java.lang.String pInternedName, int pSymKind, Sym pDefinedIn, boolean pWithinThisTable, boolean pSpecifiedKind)
Search the symbol which is specified by parameter pInternedName, pSymKind. If pWithinThisTable is false search all parents symbol table are as well as searched. If pSpecifiedKind is ture, search the symbol which is same as pInternedName and pSymKind. If the symbol is found and then return it. If not, make new symbol, then add to this symbol table.
pSpecifiedKind
- If ture, search the symbol which is
same name as pInternedName and same kind as pSymKind.
public SymTableEntry searchOrAddEntry(java.lang.String pInternedName, int pSymKind, Sym pDefinedIn, boolean pWithinThisTable, boolean pSpecifiedKind)
public void linkSym(Sym pNewSym)
public SymTable subpSymTable()
public java.lang.String generateSymName(java.lang.String pHeader)
pHeader
- is a string to be used as header of the generated name.
public Var generateVar(Type pType)
pType
- type of the variable to be generated.
public Var generateVar(Type pType, Sym pDefinedIn)
pType
- type of the variable to be generated.pDefinedIn
- language construct symbol that encloses the
definition of the generated variable; If there is no such
construct, specify null.
public Param generateParam(Type pType, Sym pDefinedIn)
pType
- type of the parameter to be generated.pDefinedIn
- Subprogram defining the parameter.
public Elem generateElem(Type pType, Sym pDefinedIn)
pType
- type of the element to be generated.pDefinedIn
- language construct symbol that encloses the
definition
of the element (structure or union name).
public Label generateLabel()
public Sym generateTag()
public Sym generateTag(java.lang.String tagname)
public Sym generateSym(Type pType, int pSymKind, java.lang.String pPrefix, Sym pDefinedIn)
pType
- type of the symbol to be generated.pSymKind
- symbol kind number of the symbol to be generated.pPrefix
- prefix to be attached to the symbol name;
Another prefix "_" preceeds the given prefix pPrefix.pDefinedIn
- language construct symbol that encloses the
definition of the generated variable; If there is no such
construct, specify null.
public Sym generateDerivedSym(Sym pBaseSym)
public void setUniqueNameToAllSym()
public java.lang.String generateUniqueName(Sym pOldSym, Subp pSubp)
pOldSym
- pSubp
-
public Sym getOwner()
public java.lang.String getOwnerName()
public Subp getSubp()
public int getSymCount()
public SymIterator getSymIterator()
public SymNestIterator getSymNestIterator()
public SymTableIterator getSymTableIterator()
public Sym getFirstSym()
public boolean isInThisSymTable(Sym pSym)
pSym
- Any symbol.
public void printSymTable()
public void printSymTableDetail()
public void printSymTableAll(SymTable pSymTable)
pSymTable
- any symbol table.public void printSymTableAllDetail(SymTable pSymTable)
pSymTable
- any symbol table.public void printSymTableAllDetail()
|
||||||||||
前のクラス 次のクラス | フレームあり フレームなし | |||||||||
概要: 入れ子 | フィールド | コンストラクタ | メソッド | 詳細: フィールド | コンストラクタ | メソッド |