public class New_c extends Expr_c implements New, NewOps
New
is an immutable representation of the use of the
new
operator to create a new instance of a class. In
addition to the type of the class being created, a New
has a
list of arguments to be passed to the constructor of the object and an
optional ClassBody
used to support anonymous classes.Term.Instance
Modifier and Type | Field and Description |
---|---|
protected ParsedClassType |
anonType |
protected java.util.List<Expr> |
arguments |
protected ClassBody |
body |
protected ConstructorInstance |
ci |
protected TypeNode |
objectType |
protected Expr |
qualifier |
protected boolean |
qualifierImplicit |
exceptions, reachable
Constructor and Description |
---|
New_c(Position pos,
Expr qualifier,
TypeNode tn,
java.util.List<Expr> arguments,
ClassBody body) |
New_c(Position pos,
Expr qualifier,
TypeNode tn,
java.util.List<Expr> arguments,
ClassBody body,
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.
|
ParsedClassType |
anonType()
The type object for anonymous classes, or null.
|
protected <N extends New_c> |
anonType(N n,
ParsedClassType anonType) |
New |
anonType(ParsedClassType anonType)
Set the type object for anonymous classes.
|
java.util.List<Expr> |
arguments()
Actual arguments to pass to the constructor.
|
New |
arguments(java.util.List<Expr> arguments)
Set the actual arguments to pass to the constructor.
|
protected <N extends New_c> |
arguments(N n,
java.util.List<Expr> arguments) |
ClassBody |
body()
The class body for anonymous classes, or null.
|
New |
body(ClassBody body)
Set the class body for anonymous classes.
|
protected <N extends New_c> |
body(N n,
ClassBody body) |
Node |
buildTypes(TypeBuilder tb)
Collects classes, methods, and fields from the AST rooted at this node
and constructs type objects for these.
|
NodeVisitor |
buildTypesEnter(TypeBuilder tb)
Collects classes, methods, and fields from the AST rooted at this node
and constructs type objects for these.
|
Type |
childExpectedType(Expr child,
AscriptionVisitor av)
Get the expected type of a child expression of
this . |
ConstructorInstance |
constructorInstance()
The constructor invoked by this expression.
|
New |
constructorInstance(ConstructorInstance ci)
Set the constructor invoked by this expression.
|
protected <N extends New_c> |
constructorInstance(N n,
ConstructorInstance ci) |
Node |
copy(NodeFactory nf)
Produce a copy of this node using the given NodeFactory.
|
Node |
disambiguate(AmbiguityRemover ar)
Remove any remaining ambiguities from the AST.
|
Node |
disambiguateOverride(Node parent,
AmbiguityRemover ar)
Disambiguate the AST.
|
Context |
enterChildScope(Node child,
Context c)
Push a new scope for visiting the child node
child . |
Node |
exceptionCheck(ExceptionChecker ec)
Check that exceptions are properly propagated throughout the AST.
|
Node |
extRewrite(ExtensionRewriter rw)
Rewrite the AST for the compilation in this language.
|
NodeVisitor |
extRewriteEnter(ExtensionRewriter rw)
Rewrite the AST for the compilation in this language.
|
ClassType |
findEnclosingClass(Context c,
ClassType ct) |
TypeNode |
findQualifiedTypeNode(AmbiguityRemover ar,
ClassType outer,
TypeNode objectType) |
Expr |
findQualifier(AmbiguityRemover ar,
ClassType ct) |
Term |
firstChild()
Return the first direct subterm performed when evaluating this term.
|
boolean |
isQualifierImplicit()
Is the qualifier implicit?
|
TypeNode |
objectType()
The type we are creating, possibly qualified by qualifier.
|
protected <N extends New_c> |
objectType(N n,
TypeNode objectType) |
New |
objectType(TypeNode objectType)
Set the type we are creating.
|
Precedence |
precedence()
Get the precedence of the expression.
|
void |
prettyPrint(CodeWriter w,
PrettyPrinter tr)
Pretty-print the AST using the given
CodeWriter . |
void |
printArgs(CodeWriter w,
PrettyPrinter tr) |
void |
printBody(CodeWriter w,
PrettyPrinter tr) |
void |
printQualifier(CodeWriter w,
PrettyPrinter tr) |
void |
printShortObjectType(CodeWriter w,
PrettyPrinter tr) |
ProcedureInstance |
procedureInstance()
The type object of the procedure we are calling.
|
Expr |
qualifier()
The qualifier expression for the type, or null.
|
New |
qualifier(Expr qualifier)
Set the qualifier expression for the type.
|
protected <N extends New_c> |
qualifier(N n,
Expr qualifier) |
New |
qualifierImplicit(boolean implicit)
Set whether the qualifier of this New is implicit.
|
protected <N extends New_c> |
qualifierImplicit(N n,
boolean implicit) |
protected <N extends New_c> |
reconstruct(N n,
Expr qualifier,
TypeNode tn,
java.util.List<Expr> arguments,
ClassBody body)
Reconstruct the expression.
|
java.util.List<Type> |
throwTypes(TypeSystem ts)
List of Types of exceptions that might get thrown.
|
java.lang.String |
toString() |
Node |
typeCheck(TypeChecker tc)
Type check the AST.
|
void |
typeCheckFlags(TypeChecker tc) |
protected void |
typeCheckFlags(TypeChecker tc,
Flags classFlags) |
void |
typeCheckNested(TypeChecker tc) |
Node |
typeCheckOverride(Node parent,
TypeChecker tc)
Type check the AST.
|
Node |
visitChildren(NodeVisitor v)
Visit the children of the node.
|
booleanValue, byteValue, charValue, constantValue, constantValue, constantValueSet, constantValueSet, doubleValue, dump, floatValue, intValue, isConstant, isConstant, isTypeChecked, lastLang, longValue, printSubExpr, printSubExpr, shortValue, stringValue, type, type, type
exceptions, exceptions, exceptions, listChild, reachable, reachable, reachable
addDecls, checkConstants, copy, copy, copyIfNeeded, del, del, disambiguateEnter, dump, dump, dump, dump, enterScope, error, error, error, exceptionCheckEnter, ext, ext, ext, ext, isDisambiguated, lang, position, position, position, prettyPrint, prettyPrint, prettyPrint, prettyPrint, print, printBlock, printSubStmt, translate, typeCheckEnter, visit, visitChild, visitEdge, visitList
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
constantValue, constantValueSet, isConstant, printSubExpr, printSubExpr, type
del, del, dump, error, error, ext, ext, ext, ext, isDisambiguated, isTypeChecked, position, position, visit, visitEdge
addDecls, checkConstants, copy, disambiguateEnter, dump, dump, dump, dump, enterScope, exceptionCheckEnter, lang, prettyPrint, prettyPrint, prettyPrint, prettyPrint, translate, typeCheckEnter, visitChild, visitList
exceptions, exceptions, reachable, reachable
constantValue, constantValueSet, isConstant
protected Expr qualifier
protected TypeNode objectType
protected java.util.List<Expr> arguments
protected ClassBody body
protected ConstructorInstance ci
protected ParsedClassType anonType
protected boolean qualifierImplicit
public New_c(Position pos, Expr qualifier, TypeNode tn, java.util.List<Expr> arguments, ClassBody body)
public Expr qualifier()
New
public New qualifier(Expr qualifier)
New
public boolean isQualifierImplicit()
New
isQualifierImplicit
in interface New
public New qualifierImplicit(boolean implicit)
New
qualifierImplicit
in interface New
protected <N extends New_c> N qualifierImplicit(N n, boolean implicit)
public TypeNode objectType()
New
objectType
in interface New
public New objectType(TypeNode objectType)
New
objectType
in interface New
public ParsedClassType anonType()
New
public New anonType(ParsedClassType anonType)
New
protected <N extends New_c> N anonType(N n, ParsedClassType anonType)
public ProcedureInstance procedureInstance()
ProcedureCall
procedureInstance
in interface ProcedureCall
public ConstructorInstance constructorInstance()
New
constructorInstance
in interface New
public New constructorInstance(ConstructorInstance ci)
New
constructorInstance
in interface New
protected <N extends New_c> N constructorInstance(N n, ConstructorInstance ci)
public java.util.List<Expr> arguments()
New
arguments
in interface New
arguments
in interface ProcedureCall
Expr
.public New arguments(java.util.List<Expr> arguments)
New
arguments
in interface New
arguments
in interface ProcedureCall
arguments
- A list of Expr
.public ClassBody body()
New
public New body(ClassBody body)
New
protected <N extends New_c> N reconstruct(N n, Expr qualifier, TypeNode tn, java.util.List<Expr> arguments, ClassBody body)
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)
NodeOps
child
.
The default behavior is to delegate the call to the child node, and let
it add appropriate declarations that should be in scope. However,
this method gives parent nodes have the ability to modify this behavior.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 NodeVisitor buildTypesEnter(TypeBuilder tb) throws SemanticException
NodeOps
TypeSystem
.
This method is called by the enter()
method of the
visitor. The * method should perform work that should be done
before visiting the children of the node. The method may return
this
or a new copy of the node on which
visitChildren()
and leave()
will be
invoked.buildTypesEnter
in interface NodeOps
buildTypesEnter
in class Node_c
tb
- The visitor which adds new type objects to the
TypeSystem
.SemanticException
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 Expr_c
tb
- The visitor which adds new type objects to the
TypeSystem
.SemanticException
public Node disambiguateOverride(Node parent, AmbiguityRemover ar) throws SemanticException
NodeOps
override()
method of the
visitor. If this method returns non-null, the node's children
will not be visited automatically. Thus, the method should check
both the node this
and it's children, usually by
invoking visitChildren
with tc
or
with another visitor, returning a non-null node. OR, the method
should do nothing and simply return null
to allow
enter
, visitChildren
, and leave
to be invoked on the node.
The default implementation returns null
.
Overriding of this method is discouraged, but sometimes necessary.disambiguateOverride
in interface NodeOps
disambiguateOverride
in class Node_c
ar
- The visitor which disambiguates.SemanticException
public TypeNode findQualifiedTypeNode(AmbiguityRemover ar, ClassType outer, TypeNode objectType) throws SemanticException
findQualifiedTypeNode
in interface NewOps
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 Expr findQualifier(AmbiguityRemover ar, ClassType ct) throws SemanticException
findQualifier
in interface NewOps
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 void typeCheckNested(TypeChecker tc) throws SemanticException
typeCheckNested
in interface NewOps
SemanticException
public ClassType findEnclosingClass(Context c, ClassType ct)
findEnclosingClass
in interface NewOps
public void typeCheckFlags(TypeChecker tc) throws SemanticException
typeCheckFlags
in interface NewOps
SemanticException
protected void typeCheckFlags(TypeChecker tc, Flags classFlags) throws SemanticException
SemanticException
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 exceptionCheck(ExceptionChecker ec) 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.exceptionCheck
in interface NodeOps
exceptionCheck
in class Term_c
ec
- The visitor.SemanticException
public NodeVisitor extRewriteEnter(ExtensionRewriter rw) throws SemanticException
NodeOps
enter()
method of the
visitor. The method should perform work that should be done
before visiting the children of the node. The method may return
this
or a new copy of the node on which
visitChildren()
and leave()
will be
invoked.extRewriteEnter
in interface NodeOps
extRewriteEnter
in class Node_c
rw
- The visitor.SemanticException
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 Expr_c
rw
- The visitor.SemanticException
public Precedence precedence()
Expr
precedence
in interface Expr
precedence
in class Expr_c
public void printQualifier(CodeWriter w, PrettyPrinter tr)
printQualifier
in interface NewOps
public void printShortObjectType(CodeWriter w, PrettyPrinter tr)
printShortObjectType
in interface NewOps
public void printArgs(CodeWriter w, PrettyPrinter tr)
printArgs
in interface ProcedureCallOps
public void printBody(CodeWriter w, PrettyPrinter tr)
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 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
public java.util.List<Type> throwTypes(TypeSystem ts)
NodeOps
throwTypes
in interface NodeOps
throwTypes
in class Node_c
public Node typeCheckOverride(Node parent, TypeChecker tc) throws SemanticException
Node_c
typeCheckOverride
in interface NodeOps
typeCheckOverride
in class Node_c
tc
- The type checking visitor.SemanticException