public class LocalDecl_c extends Stmt_c implements LocalDecl
LocalDecl
is an immutable representation of a local variable
declaration statement: a type, a name and an optional initializer.Modifier and Type | Class and Description |
---|---|
protected static class |
LocalDecl_c.AddDependenciesVisitor |
Term.Instance
Modifier and Type | Field and Description |
---|---|
protected Flags |
flags |
protected Expr |
init |
protected LocalInstance |
li |
protected Id |
name |
protected TypeNode |
type |
exceptions, reachable
Constructor and Description |
---|
LocalDecl_c(Position pos,
Flags flags,
TypeNode type,
Id name,
Expr init) |
LocalDecl_c(Position pos,
Flags flags,
TypeNode type,
Id name,
Expr init,
Ext ext) |
Modifier and Type | Method and Description |
---|---|
<T> java.util.List<T> |
acceptCFG(CFGBuilder<?> v,
java.util.List<T> succs)
Visit this term in evaluation order, calling v.edge() for each successor
in succs, if data flows on that edge.
|
void |
addDecls(Context c)
Add any declarations to the context that should be in scope when
visiting later sibling nodes.
|
Node |
buildTypes(TypeBuilder tb)
Collects classes, methods, and fields from the AST rooted at this node
and constructs type objects for these.
|
Node |
checkConstants(ConstantChecker cc)
Check if the node is a compile-time constant.
|
Type |
childExpectedType(Expr child,
AscriptionVisitor av)
Get the expected type of a child expression of
this . |
boolean |
constantValueSet()
Whether the initializer has been determined to be constant or not.
|
Node |
copy(NodeFactory nf)
Produce a copy of this node using the given NodeFactory.
|
Type |
declType()
Get the type object for the declaration's type.
|
Node |
disambiguate(AmbiguityRemover ar)
Remove any remaining ambiguities from the AST.
|
void |
dump(CodeWriter w)
Dump the AST node for debugging purposes.
|
Context |
enterChildScope(Node child,
Context c)
Add the declaration of the variable as we enter the scope of the
initializer
|
Node |
extRewrite(ExtensionRewriter rw)
Rewrite the AST for the compilation in this language.
|
Term |
firstChild()
Return the first direct subterm performed when evaluating this term.
|
Flags |
flags()
Get the declaration's flags.
|
LocalDecl |
flags(Flags flags)
Set the declaration's flags.
|
protected <N extends LocalDecl_c> |
flags(N n,
Flags flags) |
Id |
id()
Get the declaration's name.
|
LocalDecl |
id(Id name)
Set the declaration's name.
|
protected <N extends LocalDecl_c> |
id(N n,
Id name) |
Expr |
init()
Get the declaration's initializer expression, or null.
|
LocalDecl |
init(Expr init)
Set the declaration's initializer expression.
|
protected <N extends LocalDecl_c> |
init(N n,
Expr init) |
boolean |
isDisambiguated() |
LocalInstance |
localInstance()
Get the type object for the variable declaration.
|
LocalDecl |
localInstance(LocalInstance li)
Set the type object for the local declaration.
|
protected <N extends LocalDecl_c> |
localInstance(N n,
LocalInstance li) |
java.lang.String |
name()
Get the declaration's name.
|
LocalDecl |
name(java.lang.String name)
Set the declaration's name.
|
void |
prettyPrint(CodeWriter w,
PrettyPrinter tr)
Pretty-print the AST using the given
CodeWriter . |
protected <N extends LocalDecl_c> |
reconstruct(N n,
TypeNode type,
Id name,
Expr init)
Reconstruct the declaration.
|
java.lang.String |
toString() |
TypeNode |
type()
Get the declaration's type.
|
protected <N extends LocalDecl_c> |
type(N n,
TypeNode type) |
LocalDecl |
type(TypeNode type)
Set the declaration's type.
|
Node |
typeCheck(TypeChecker tc)
Type check the AST.
|
NodeVisitor |
typeCheckEnter(TypeChecker tc)
Override superclass behavior to check if the variable is multiply
defined.
|
VarInstance |
varInstance()
The variable being initialized.
|
Node |
visitChildren(NodeVisitor v)
Visit the children of the node.
|
exceptionCheck, exceptions, exceptions, exceptions, listChild, reachable, reachable, reachable
buildTypesEnter, copy, copy, copyIfNeeded, del, del, disambiguateEnter, disambiguateOverride, dump, dump, dump, dump, enterScope, error, error, error, exceptionCheckEnter, ext, ext, ext, ext, extRewriteEnter, isTypeChecked, lang, position, position, position, prettyPrint, prettyPrint, prettyPrint, prettyPrint, print, printBlock, printSubStmt, throwTypes, translate, typeCheckOverride, visit, visitChild, visitEdge, visitList
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
exceptions, exceptions, reachable, reachable
del, del, error, error, ext, ext, ext, ext, isTypeChecked, position, position, visit, visitEdge
buildTypesEnter, copy, disambiguateEnter, disambiguateOverride, dump, dump, dump, dump, enterScope, exceptionCheck, exceptionCheckEnter, extRewriteEnter, lang, prettyPrint, prettyPrint, prettyPrint, prettyPrint, throwTypes, translate, typeCheckOverride, visitChild, visitList
protected Flags flags
protected TypeNode type
protected Id name
protected Expr init
protected LocalInstance li
public boolean isDisambiguated()
isDisambiguated
in interface Node
isDisambiguated
in class Node_c
public Type declType()
VarDecl
public LocalDecl flags(Flags flags)
LocalDecl
protected <N extends LocalDecl_c> N flags(N n, Flags flags)
public LocalDecl type(TypeNode type)
LocalDecl
protected <N extends LocalDecl_c> N type(N n, TypeNode type)
public LocalDecl id(Id name)
LocalDecl
protected <N extends LocalDecl_c> N id(N n, Id name)
public java.lang.String name()
VarDecl
public LocalDecl name(java.lang.String name)
LocalDecl
public Expr init()
LocalDecl
public LocalDecl init(Expr init)
LocalDecl
protected <N extends LocalDecl_c> N init(N n, Expr init)
public VarInstance varInstance()
VarInit
varInstance
in interface VarInit
public LocalInstance localInstance()
VarDecl
localInstance
in interface VarDecl
public LocalDecl localInstance(LocalInstance li)
LocalDecl
localInstance
in interface LocalDecl
protected <N extends LocalDecl_c> N localInstance(N n, LocalInstance li)
protected <N extends LocalDecl_c> N reconstruct(N n, TypeNode type, Id name, Expr init)
public Node visitChildren(NodeVisitor v)
NodeOps
visitChildren
in interface NodeOps
visitChildren
in class Node_c
v
- The visitor that will traverse/rewrite the AST.this
.public Context enterChildScope(Node child, Context c)
enterChildScope
in interface NodeOps
enterChildScope
in class Node_c
child
- the child node about to be entered.c
- the current Context
Context
to be used for visiting node
child
public void addDecls(Context c)
Node_c
public Node buildTypes(TypeBuilder tb) throws SemanticException
NodeOps
TypeSystem
.
This method is called by the leave()
method of the
visitor. The method should perform work that should be done
after visiting the children of the node. The method may return
this
or a new copy of the node which will be
installed as a child of the node's parent.buildTypes
in interface NodeOps
buildTypes
in class Node_c
tb
- The visitor which adds new type objects to the
TypeSystem
.SemanticException
public Node disambiguate(AmbiguityRemover ar) throws SemanticException
NodeOps
leave()
method of the
visitor. The method should perform work that should be done
after visiting the children of the node. The method may return
this
or a new copy of the node which will be
installed as a child of the node's parent.
The node should not assume that its children have been disambiguated.
If it depends on a child being disambiguated,
it may just return this
without doing any work.disambiguate
in interface NodeOps
disambiguate
in class Node_c
ar
- The visitor which disambiguates.SemanticException
public NodeVisitor typeCheckEnter(TypeChecker tc) throws SemanticException
typeCheckEnter
in interface NodeOps
typeCheckEnter
in class Node_c
tc
- The type checking visitor.SemanticException
public Node typeCheck(TypeChecker tc) throws SemanticException
NodeOps
leave()
method of the
visitor. The method should perform work that should be done
after visiting the children of the node. The method may return
this
or a new copy of the node which will be
installed as a child of the node's parent.typeCheck
in interface NodeOps
typeCheck
in class Node_c
tc
- The type checking visitor.SemanticException
public Node checkConstants(ConstantChecker cc) throws SemanticException
NodeOps
leave()
method of the
visitor. The method should perform work that should be done
after visiting the children of the node. The method may return
this
or a new copy of the node which will be
installed as a child of the node's parent.checkConstants
in interface NodeOps
checkConstants
in class Node_c
cc
- The constant checking visitor.SemanticException
public boolean constantValueSet()
VarInit
constantValueSet
in interface VarInit
public Type childExpectedType(Expr child, AscriptionVisitor av)
NodeOps
this
.
The expected type is determined by the context in that the child occurs
(e.g., for x = e
, the expected type of e
is
the declared type of x
.
The expected type should impose the least constraints on the child's
type that are allowed by the parent node.childExpectedType
in interface NodeOps
childExpectedType
in class Node_c
child
- A child expression of this node.av
- An ascription visitor.child
.public Node extRewrite(ExtensionRewriter rw) throws SemanticException
NodeOps
leave()
method of the
visitor. The method should perform work that should be done
after visiting the children of the node. The method may return
this
or a new copy of the node which will be
installed as a child of the node's parent.extRewrite
in interface NodeOps
extRewrite
in class Term_c
rw
- The visitor.SemanticException
public void prettyPrint(CodeWriter w, PrettyPrinter tr)
Node_c
CodeWriter
.prettyPrint
in interface NodeOps
prettyPrint
in class Node_c
w
- The code writer to which to write.tr
- The pretty printer. This is not a visitor.public void dump(CodeWriter w)
Node
public Term firstChild()
TermOps
firstChild
in interface TermOps
firstChild
in class Term_c
public <T> java.util.List<T> acceptCFG(CFGBuilder<?> v, java.util.List<T> succs)
TermOps