polyglot.ext.jl.ast
Class New_c

java.lang.Object
  extended by polyglot.ext.jl.ast.Node_c
      extended by polyglot.ext.jl.ast.Term_c
          extended by polyglot.ext.jl.ast.Expr_c
              extended by polyglot.ext.jl.ast.New_c
All Implemented Interfaces:
java.lang.Cloneable, Expr, JL, New, Node, NodeOps, Prefix, ProcedureCall, Receiver, Term, Typed, Copy

public class New_c
extends Expr_c
implements New

A 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.


Field Summary
protected  ParsedClassType anonType
           
protected  java.util.List arguments
           
protected  ClassBody body
           
protected  ConstructorInstance ci
           
protected  Expr qualifier
           
protected  TypeNode tn
           
 
Fields inherited from class polyglot.ext.jl.ast.Expr_c
type
 
Fields inherited from class polyglot.ext.jl.ast.Term_c
exceptions, reachable
 
Fields inherited from class polyglot.ext.jl.ast.Node_c
del, ext, position
 
Constructor Summary
New_c(Position pos, Expr qualifier, TypeNode tn, java.util.List arguments, ClassBody body)
           
 
Method Summary
 java.util.List acceptCFG(CFGBuilder v, java.util.List succs)
          Visit this term in evaluation order.
 ParsedClassType anonType()
          The type object for anonymous classes, or null.
 New anonType(ParsedClassType anonType)
          Set the type object for anonymous classes.
 java.util.List arguments()
          Actual arguments to pass to the constructor.
 ProcedureCall arguments(java.util.List arguments)
          Set the actual arguments to pass to the constructor.
 ClassBody body()
          The class body for anonymous classes, or null.
 New body(ClassBody body)
          Set the class body for anonymous classes.
 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.
 Node disambiguate(AmbiguityRemover ar)
          Remove any remaining ambiguities from the AST.
 NodeVisitor disambiguateEnter(AmbiguityRemover ar)
          Remove any remaining ambiguities from the AST.
protected  TypeNode disambiguateTypeNode(TypeChecker tc, ClassType ct)
           
 Context enterScope(Node child, Context c)
          Push a new scope for visiting the child node child.
 Term entry()
          Return the first (sub)term performed when evaluating this term.
 Node exceptionCheck(ExceptionChecker ec)
          Check that exceptions are properly propagated throughout the AST.
 TypeNode objectType()
          Get the type we are instantiating.
 New objectType(TypeNode tn)
          Set the type we are instantiating.
protected  TypeNode partialDisambTypeNode(TypeNode tn, TypeChecker tc, ClassType outer)
           
 Precedence precedence()
          Get the precedence of the expression.
 void prettyPrint(CodeWriter w, PrettyPrinter tr)
          Pretty-print the AST using the given CodeWriter.
protected  void printArgs(CodeWriter w, PrettyPrinter tr)
           
protected  void printBody(CodeWriter w, PrettyPrinter tr)
           
protected  void printQualifier(CodeWriter w, PrettyPrinter tr)
           
 ProcedureInstance procedureInstance()
          The type object of the method we are calling.
 Expr qualifier()
          Get the qualifier expression of the allocation.
 New qualifier(Expr qualifier)
          Set the qualifier expression of the allocation.
protected  New_c reconstruct(Expr qualifier, TypeNode tn, java.util.List arguments, ClassBody body)
          Reconstruct the expression.
 java.util.List throwTypes(TypeSystem ts)
          List of Types of exceptions that might get thrown.
 java.lang.String toString()
           
 void translate(CodeWriter w, Translator tr)
          Translate the AST using the given CodeWriter.
 Node typeCheck(TypeChecker tc)
          Type check the AST.
protected  ClassBody typeCheckBody(TypeChecker tc, ClassType superType)
           
 NodeVisitor typeCheckEnter(TypeChecker tc)
          Type check the AST.
protected  Node typeCheckEpilogue(TypeChecker tc)
           
 Node visitChildren(NodeVisitor v)
          Visit the children of the expression.
 
Methods inherited from class polyglot.ext.jl.ast.Expr_c
booleanValue, byteValue, charValue, constantValue, doubleValue, dump, floatValue, intValue, isConstant, longValue, printSubExpr, printSubExpr, shortValue, stringValue, type, type
 
Methods inherited from class polyglot.ext.jl.ast.Term_c
exceptions, exceptions, listEntry, reachable, reachable
 
Methods inherited from class polyglot.ext.jl.ast.Node_c
addDecls, addMembers, addMembersEnter, addMembersOverride, buildTypesOverride, copy, del, del, disambiguateOverride, enterScope, exceptionCheckEnter, exceptionCheckOverride, ext, ext, ext, ext, init, node, position, position, print, printBlock, printSubStmt, typeCheckOverride, visit, visitChild, visitEdge, visitList
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface polyglot.ast.Expr
constantValue, isConstant, printSubExpr, printSubExpr, type
 
Methods inherited from interface polyglot.ast.Node
del, del, dump, ext, ext, ext, ext, position, position, visit, visitChild, visitEdge, visitList
 
Methods inherited from interface polyglot.ast.JL
init, node
 
Methods inherited from interface polyglot.ast.NodeOps
addDecls, addMembers, addMembersEnter, enterScope, exceptionCheckEnter
 
Methods inherited from interface polyglot.util.Copy
copy
 
Methods inherited from interface polyglot.ast.Typed
type
 
Methods inherited from interface polyglot.ast.Term
exceptions, exceptions, reachable, reachable
 
Methods inherited from interface polyglot.ast.Term
exceptions, exceptions, reachable, reachable
 

Field Detail

qualifier

protected Expr qualifier

tn

protected TypeNode tn

arguments

protected java.util.List arguments

body

protected ClassBody body

ci

protected ConstructorInstance ci

anonType

protected ParsedClassType anonType
Constructor Detail

New_c

public New_c(Position pos,
             Expr qualifier,
             TypeNode tn,
             java.util.List arguments,
             ClassBody body)
Method Detail

qualifier

public Expr qualifier()
Get the qualifier expression of the allocation.

Specified by:
qualifier in interface New

qualifier

public New qualifier(Expr qualifier)
Set the qualifier expression of the allocation.

Specified by:
qualifier in interface New

objectType

public TypeNode objectType()
Get the type we are instantiating.

Specified by:
objectType in interface New

objectType

public New objectType(TypeNode tn)
Set the type we are instantiating.

Specified by:
objectType in interface New

anonType

public ParsedClassType anonType()
Description copied from interface: New
The type object for anonymous classes, or null.

Specified by:
anonType in interface New

anonType

public New anonType(ParsedClassType anonType)
Description copied from interface: New
Set the type object for anonymous classes.

Specified by:
anonType in interface New

procedureInstance

public ProcedureInstance procedureInstance()
Description copied from interface: ProcedureCall
The type object of the method we are calling. This is, generally, only valid after the type-checking pass.

Specified by:
procedureInstance in interface ProcedureCall

constructorInstance

public ConstructorInstance constructorInstance()
Description copied from interface: New
The constructor invoked by this expression.

Specified by:
constructorInstance in interface New

constructorInstance

public New constructorInstance(ConstructorInstance ci)
Description copied from interface: New
Set the constructor invoked by this expression.

Specified by:
constructorInstance in interface New

arguments

public java.util.List arguments()
Description copied from interface: New
Actual arguments to pass to the constructor.

Specified by:
arguments in interface New
Specified by:
arguments in interface ProcedureCall
Returns:
A list of Expr.

arguments

public ProcedureCall arguments(java.util.List arguments)
Description copied from interface: New
Set the actual arguments to pass to the constructor.

Specified by:
arguments in interface New
Specified by:
arguments in interface ProcedureCall
Parameters:
arguments - A list of Expr.

body

public ClassBody body()
Description copied from interface: New
The class body for anonymous classes, or null.

Specified by:
body in interface New

body

public New body(ClassBody body)
Description copied from interface: New
Set the class body for anonymous classes.

Specified by:
body in interface New

reconstruct

protected New_c reconstruct(Expr qualifier,
                            TypeNode tn,
                            java.util.List arguments,
                            ClassBody body)
Reconstruct the expression.


visitChildren

public Node visitChildren(NodeVisitor v)
Visit the children of the expression.

Specified by:
visitChildren in interface NodeOps
Overrides:
visitChildren in class Node_c
Parameters:
v - The visitor that will traverse/rewrite the AST.
Returns:
A new AST if a change was made, or this.

enterScope

public Context enterScope(Node child,
                          Context c)
Description copied from class: Node_c
Push a new scope for visiting the child node 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.

Specified by:
enterScope in interface NodeOps
Overrides:
enterScope in class Node_c
Parameters:
child - the child node about to be entered.
c - the current Context
Returns:
the Context to be used for visiting node child

buildTypesEnter

public NodeVisitor buildTypesEnter(TypeBuilder tb)
                            throws SemanticException
Description copied from interface: NodeOps
Collects classes, methods, and fields from the AST rooted at this node and constructs type objects for these. These type objects may be ambiguous. Inserts classes into the 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.

Specified by:
buildTypesEnter in interface NodeOps
Overrides:
buildTypesEnter in class Node_c
Parameters:
tb - The visitor which adds new type objects to the TypeSystem.
Throws:
SemanticException

buildTypes

public Node buildTypes(TypeBuilder tb)
                throws SemanticException
Description copied from interface: NodeOps
Collects classes, methods, and fields from the AST rooted at this node and constructs type objects for these. These type objects may be ambiguous. Inserts classes into the 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.

Specified by:
buildTypes in interface NodeOps
Overrides:
buildTypes in class Expr_c
Parameters:
tb - The visitor which adds new type objects to the TypeSystem.
Throws:
SemanticException

disambiguateEnter

public NodeVisitor disambiguateEnter(AmbiguityRemover ar)
                              throws SemanticException
Description copied from interface: NodeOps
Remove any remaining ambiguities from the AST. 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.

Specified by:
disambiguateEnter in interface NodeOps
Overrides:
disambiguateEnter in class Node_c
Parameters:
ar - The visitor which disambiguates.
Throws:
SemanticException

disambiguate

public Node disambiguate(AmbiguityRemover ar)
                  throws SemanticException
Description copied from interface: NodeOps
Remove any remaining ambiguities from the AST. 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.

Specified by:
disambiguate in interface NodeOps
Overrides:
disambiguate in class Node_c
Parameters:
ar - The visitor which disambiguates.
Throws:
SemanticException

typeCheckEnter

public NodeVisitor typeCheckEnter(TypeChecker tc)
                           throws SemanticException
Description copied from interface: NodeOps
Type check the AST. 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.

Specified by:
typeCheckEnter in interface NodeOps
Overrides:
typeCheckEnter in class Node_c
Parameters:
tc - The type checking visitor.
Throws:
SemanticException

typeCheck

public Node typeCheck(TypeChecker tc)
               throws SemanticException
Description copied from interface: NodeOps
Type check the AST. 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.

Specified by:
typeCheck in interface NodeOps
Overrides:
typeCheck in class Node_c
Parameters:
tc - The type checking visitor.
Throws:
SemanticException

typeCheckEpilogue

protected Node typeCheckEpilogue(TypeChecker tc)
                          throws SemanticException
Throws:
SemanticException

partialDisambTypeNode

protected TypeNode partialDisambTypeNode(TypeNode tn,
                                         TypeChecker tc,
                                         ClassType outer)
                                  throws SemanticException
Throws:
SemanticException

disambiguateTypeNode

protected TypeNode disambiguateTypeNode(TypeChecker tc,
                                        ClassType ct)
                                 throws SemanticException
Throws:
SemanticException

typeCheckBody

protected ClassBody typeCheckBody(TypeChecker tc,
                                  ClassType superType)
                           throws SemanticException
Throws:
SemanticException

childExpectedType

public Type childExpectedType(Expr child,
                              AscriptionVisitor av)
Description copied from interface: Node
Get the expected type of a child expression of 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.

Specified by:
childExpectedType in interface Node
Overrides:
childExpectedType in class Node_c
Parameters:
child - A child expression of this node.
av - An ascription visitor.
Returns:
The expected type of child.

exceptionCheck

public Node exceptionCheck(ExceptionChecker ec)
                    throws SemanticException
Description copied from interface: NodeOps
Check that exceptions are properly propagated throughout the AST. 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.

Specified by:
exceptionCheck in interface NodeOps
Overrides:
exceptionCheck in class Term_c
Parameters:
ec - The visitor.
Throws:
SemanticException

precedence

public Precedence precedence()
Get the precedence of the expression.

Specified by:
precedence in interface Expr
Overrides:
precedence in class Expr_c

toString

public java.lang.String toString()
Overrides:
toString in class Node_c

printQualifier

protected void printQualifier(CodeWriter w,
                              PrettyPrinter tr)

printArgs

protected void printArgs(CodeWriter w,
                         PrettyPrinter tr)

printBody

protected void printBody(CodeWriter w,
                         PrettyPrinter tr)

prettyPrint

public void prettyPrint(CodeWriter w,
                        PrettyPrinter tr)
Description copied from class: Node_c
Pretty-print the AST using the given CodeWriter.

Specified by:
prettyPrint in interface NodeOps
Overrides:
prettyPrint in class Node_c
Parameters:
w - The code writer to which to write.
tr - The pretty printer. This is not a visitor.

translate

public void translate(CodeWriter w,
                      Translator tr)
Description copied from class: Node_c
Translate the AST using the given CodeWriter.

Specified by:
translate in interface NodeOps
Overrides:
translate in class Node_c
Parameters:
w - The code writer to which to write.
tr - The translation pass. This is not a visitor.

entry

public Term entry()
Description copied from class: Term_c
Return the first (sub)term performed when evaluating this term.

Specified by:
entry in interface Term
Specified by:
entry in class Term_c

acceptCFG

public java.util.List acceptCFG(CFGBuilder v,
                                java.util.List succs)
Description copied from class: Term_c
Visit this term in evaluation order.

Specified by:
acceptCFG in interface Term
Specified by:
acceptCFG in class Term_c

throwTypes

public java.util.List throwTypes(TypeSystem ts)
Description copied from interface: NodeOps
List of Types of exceptions that might get thrown. The result is not necessarily correct until after type checking.

Specified by:
throwTypes in interface NodeOps
Overrides:
throwTypes in class Node_c