|
antlraux package v0.2.1 |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--antlraux.context.Declaration
Declarations are the basic contextual information unit.
A declaration is a set of related fields, representing
an bit of contextual information that has to be inserted in a
Scope. Some of these are mandatory and others are
optional (can be null).
Mandatory fields are
astinitialValuefilename,
line, columnThe aim of this class may be better understood with an example. Let's imagine a language whose variables would be declared like in C:
int a,b,c;
Then somewhere in the semantic analyzer some code would have to make
something equivalent to this:
Scope currentScope = getCurrentScope();
currentScope.insert( new Declaration(VARIABLE, intTag, "a"));
currentScope.insert( new Declaration(VARIABLE, intTag, "b"));
currentScope.insert( new Declaration(VARIABLE, intTag, "c"));
Note that in this example we are ignoring optional fields; if possible,
you should not!
Declarations are also valid for declaring types; this:
class A {...}
struct s {...}
Would trigger the generation of a code similar to:
Type AClassType = getTypeForClass("A");
currentScope.insert(new Declaration(CLASS, AClassType, "A"));
Type sStructType = getTypeForStruct("s");
currentScope.insert(new Declaration(STRUCT, sStructType, "s"));
Depending on how you implement the scoping system (with or without
Context- see the comments on Scope for further information )
this codes will be on a subclass of Scope or Context.
Context,
Scope,
Type| Field Summary | |
protected antlr.collections.AST |
ast
The AST that originated the declaration. |
protected int |
column
Lexical information. |
protected java.lang.String |
filename
Lexical information. |
protected antlr.collections.AST |
initialValue
An initial value for the declaration. |
protected int |
line
Lexical information. |
protected java.lang.String |
name
The declaration name |
protected int |
tag
An integer used to store different "declaration types", such as PARAMETER, ATTRIBUTE or CLASS. |
protected Type |
type
The declaration Type. |
| Fields inherited from interface antlraux.util.LexInfo |
DEFAULT_COLUMN, DEFAULT_FILENAME, DEFAULT_LINE |
| Constructor Summary | |
Declaration(int tag,
Type t,
java.lang.String name)
|
|
Declaration(int tag,
Type t,
java.lang.String name,
antlr.collections.AST ast,
antlr.collections.AST initialValue,
LexInfo lexInfo)
|
|
Declaration(int tag,
Type t,
java.lang.String name,
antlr.collections.AST ast,
antlr.collections.AST initialValue,
java.lang.String fileName,
int line,
int column)
|
|
| Method Summary | |
void |
copyLexInfo(LexInfo from)
Copies the lexical information from other LexInfo. |
antlr.collections.AST |
getAST()
|
int |
getColumn()
Get the column for this node |
java.lang.String |
getFilename()
Get the file name for this node |
antlr.collections.AST |
getInitialValue()
|
java.lang.String |
getLexInfoString()
Returns true if all the information (Filename:line:column) is valid; false otherwise. |
int |
getLine()
Get the line for this node |
java.lang.String |
getName()
|
int |
getTag()
|
Type |
getType()
|
void |
initialize(Declaration other)
|
void |
setAST(antlr.collections.AST ast)
|
void |
setColumn(int column)
Set the column for this node |
void |
setFilename(java.lang.String fn)
Sets the file name for this node. |
void |
setInitialValue(antlr.collections.AST initialValue)
|
void |
setLine(int line)
Set the line for this node |
void |
setName(java.lang.String name)
Accessor for name |
void |
setTag(int tag)
|
void |
setType(Type t)
Accessor for type |
java.lang.String |
toString()
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
protected Type type
Type.
protected java.lang.String name
protected int tag
protected antlr.collections.AST ast
protected antlr.collections.AST initialValue
Declaration
______/\______
/ \
int a = 2 + 2 ;
\__ __/
\/
Initial value
In declarations with no initializations, null or a type-
dependent default value could be used.
I've left this member's type as an AST, so you can use
your own; however, I strongly recomment using an instance of
ExpressionAST for it.
protected java.lang.String filename
protected int line
protected int column
| Constructor Detail |
public Declaration(int tag,
Type t,
java.lang.String name)
public Declaration(int tag,
Type t,
java.lang.String name,
antlr.collections.AST ast,
antlr.collections.AST initialValue,
LexInfo lexInfo)
public Declaration(int tag,
Type t,
java.lang.String name,
antlr.collections.AST ast,
antlr.collections.AST initialValue,
java.lang.String fileName,
int line,
int column)
| Method Detail |
public void setName(java.lang.String name)
name
java.lang.IllegalArgumentException - if name==nullpublic java.lang.String getName()
public void setType(Type t)
type
java.lang.IllegalArgumentException - if null==tpublic void setTag(int tag)
public void setAST(antlr.collections.AST ast)
public void setInitialValue(antlr.collections.AST initialValue)
public antlr.collections.AST getAST()
public Type getType()
public int getTag()
public antlr.collections.AST getInitialValue()
public java.lang.String getFilename()
LexInfo
getFilename in interface LexInfopublic int getColumn()
LexInfo
getColumn in interface LexInfopublic int getLine()
LexInfo
getLine in interface LexInfopublic void setFilename(java.lang.String fn)
LexInfo
setFilename in interface LexInfopublic void setColumn(int column)
LexInfo
setColumn in interface LexInfopublic void setLine(int line)
LexInfo
setLine in interface LexInfopublic void copyLexInfo(LexInfo from)
LexInfo
copyLexInfo in interface LexInfopublic java.lang.String getLexInfoString()
LexInfoFileLineFormatter, which authomatically
deals with incompleteness in the information.
getLexInfoString in interface LexInfopublic void initialize(Declaration other)
public java.lang.String toString()
toString in class java.lang.Object
|
antlraux package v0.2.1 |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||