public class JLang_c extends java.lang.Object implements JLang
JLang_c
defines the dispatching mechanism to methods which implement
Java compiler operations. Language extensions may override methods that
determine the appropriate object which implements AST operations (such as
NodeOps) to redirect dispatching to appropriate extension code.Modifier | Constructor and Description |
---|---|
protected |
JLang_c() |
Modifier and Type | Method and Description |
---|---|
<T> java.util.List<T> |
acceptCFG(Term n,
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(Node n,
Context c)
Add any declarations to the context that should be in scope when
visiting later sibling nodes.
|
Node |
addDefaultConstructor(ClassDecl n,
TypeSystem ts,
NodeFactory nf,
ConstructorInstance defaultConstructorInstance) |
Node |
buildTypes(Node n,
TypeBuilder tb)
Collects classes, methods, and fields from the AST rooted at this node
and constructs type objects for these.
|
NodeVisitor |
buildTypesEnter(Node n,
TypeBuilder tb)
Collects classes, methods, and fields from the AST rooted at this node
and constructs type objects for these.
|
protected CallOps |
CallOps(Call n) |
Node |
checkConstants(Node n,
ConstantChecker cc)
Check if the node is a compile-time constant.
|
Type |
childExpectedType(Node n,
Expr child,
AscriptionVisitor av)
Get the expected type of a child expression of
this . |
protected ClassDeclOps |
ClassDeclOps(ClassDecl n) |
boolean |
condIsConstant(Loop n,
JLang lang)
Returns true of cond() evaluates to a constant.
|
boolean |
condIsConstantFalse(Loop n,
JLang lang)
Returns true if cond() is a constant that evaluates to false.
|
boolean |
condIsConstantTrue(Loop n,
JLang lang)
Returns true if cond() is a constant that evaluates to true.
|
java.lang.Object |
constantValue(Expr n,
Lang lang)
Return the constant value of the expression, if any.
|
boolean |
constantValueSet(Expr n,
Lang lang)
Return true iff the compiler has determined whether this expression has a
constant value.
|
ExceptionChecker |
constructTryBlockExceptionChecker(Try n,
ExceptionChecker ec)
Construct an ExceptionChecker that is suitable for checking the try block of
a try-catch-finally AST node.
|
Term |
continueTarget(Loop n)
Target of a continue statement in the loop body.
|
Node |
copy(Node n,
ExtensionInfo extInfo)
Produce a copy of this node using the given ExtensionInfo.
|
Node |
copy(Node n,
NodeFactory nf)
Produce a copy of this node using the given NodeFactory.
|
Node |
disambiguate(Node n,
AmbiguityRemover ar)
Remove any remaining ambiguities from the AST.
|
NodeVisitor |
disambiguateEnter(Node n,
AmbiguityRemover ar)
Remove any remaining ambiguities from the AST.
|
Node |
disambiguateOverride(Node n,
Node parent,
AmbiguityRemover ar)
Disambiguate the AST.
|
void |
dump(Node n,
Lang lang,
java.io.OutputStream os)
Dump the AST for debugging.
|
void |
dump(Node n,
Lang lang,
java.io.Writer w)
Dump the AST for debugging.
|
Context |
enterChildScope(Node n,
Node child,
Context c)
Push a new scope for visiting the child node
child . |
Context |
enterScope(Node n,
Context c)
Push a new scope upon entering this node, and add any declarations to the
context that should be in scope when visiting children of this node.
|
Node |
exceptionCheck(Node n,
ExceptionChecker ec)
Check that exceptions are properly propagated throughout the AST.
|
java.util.List<Catch> |
exceptionCheckCatchBlocks(Try n,
ExceptionChecker ec)
Perform exception checking of the catch blocks of a try-catch-finally
AST node, using the supplied exception checker.
|
NodeVisitor |
exceptionCheckEnter(Node n,
ExceptionChecker ec)
Check that exceptions are properly propagated throughout the AST.
|
Block |
exceptionCheckFinallyBlock(Try n,
ExceptionChecker ec)
Perform exception checking of the finally block of a try-catch-finally
AST node (if there is one), using the supplied exception checker.
|
Block |
exceptionCheckTryBlock(Try n,
ExceptionChecker ec)
Perform exception checking of the try block of a try-catch-finally
AST node, using the supplied exception checker.
|
protected ExprOps |
ExprOps(Expr n) |
Node |
extRewrite(Node n,
ExtensionRewriter rw)
Rewrite the AST for the compilation in this language.
|
NodeVisitor |
extRewriteEnter(Node n,
ExtensionRewriter rw)
Rewrite the AST for the compilation in this language.
|
Type |
findContainer(Call n,
TypeSystem ts,
MethodInstance mi)
Used to find the missing static target of a static method call.
|
ClassType |
findEnclosingClass(New n,
Context c,
ClassType ct) |
TypeNode |
findQualifiedTypeNode(New n,
AmbiguityRemover ar,
ClassType outer,
TypeNode objectType) |
Expr |
findQualifier(New n,
AmbiguityRemover ar,
ClassType ct) |
ReferenceType |
findTargetType(Call n) |
Term |
firstChild(Term n)
Return the first direct subterm performed when evaluating this term.
|
boolean |
isConstant(Expr n,
Lang lang)
Return whether the expression evaluates to a constant.
|
protected LoopOps |
LoopOps(Loop n) |
protected NewOps |
NewOps(New n) |
protected NodeOps |
NodeOps(Node n) |
void |
prettyPrint(Node n,
CodeWriter w,
PrettyPrinter pp)
Pretty-print the AST using the given code writer.
|
void |
prettyPrint(Node n,
Lang lang,
java.io.OutputStream os)
Pretty-print the AST for debugging.
|
void |
prettyPrint(Node n,
Lang lang,
java.io.Writer w)
Pretty-print the AST for debugging.
|
void |
prettyPrintFooter(ClassDecl n,
CodeWriter w,
PrettyPrinter tr) |
void |
prettyPrintHeader(ClassDecl n,
CodeWriter w,
PrettyPrinter tr) |
void |
prettyPrintHeader(ProcedureDecl n,
Flags flags,
CodeWriter w,
PrettyPrinter tr) |
void |
printArgs(ProcedureCall n,
CodeWriter w,
PrettyPrinter tr) |
void |
printBody(New n,
CodeWriter w,
PrettyPrinter tr) |
void |
printQualifier(New n,
CodeWriter w,
PrettyPrinter tr) |
void |
printShortObjectType(New n,
CodeWriter w,
PrettyPrinter tr) |
protected ProcedureCallOps |
ProcedureCallOps(ProcedureCall n) |
protected ProcedureDeclOps |
ProcedureDeclOps(ProcedureDecl n) |
protected TermOps |
TermOps(Term n) |
java.util.List<Type> |
throwTypes(Node n,
TypeSystem ts)
List of Types of exceptions that might get thrown.
|
void |
translate(Node n,
CodeWriter w,
Translator tr)
Translate the AST using the given code writer.
|
protected TryOps |
TryOps(Try n) |
Node |
typeCheck(Node n,
TypeChecker tc)
Type check the AST.
|
NodeVisitor |
typeCheckEnter(Node n,
TypeChecker tc)
Type check the AST.
|
void |
typeCheckFlags(New n,
TypeChecker tc) |
void |
typeCheckNested(New n,
TypeChecker tc) |
Node |
typeCheckNullTarget(Call n,
TypeChecker tc,
java.util.List<Type> argTypes)
Typecheck the Call when the target is null.
|
Node |
typeCheckOverride(Node n,
Node parent,
TypeChecker tc)
Type check the AST.
|
Node |
visitChildren(Node n,
NodeVisitor v)
Visit the children of the node.
|
public static final JLang instance
protected ClassDeclOps ClassDeclOps(ClassDecl n)
protected ProcedureCallOps ProcedureCallOps(ProcedureCall n)
protected ProcedureDeclOps ProcedureDeclOps(ProcedureDecl n)
public final Node visitChildren(Node n, NodeVisitor v)
Lang
visitChildren
in interface Lang
v
- The visitor that will traverse/rewrite the AST.this
.public final Context enterScope(Node n, Context c)
Lang
addDecls
when leaving the node
for that.enterScope
in interface Lang
c
- the current Context
Context
to be used for visiting this node.public final Context enterChildScope(Node n, Node child, Context c)
Lang
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 Lang
child
- The child node about to be entered.c
- The current Context
Context
to be used for visiting node
child
public final void addDecls(Node n, Context c)
Lang
public final NodeVisitor buildTypesEnter(Node n, TypeBuilder tb) throws SemanticException
Lang
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 Lang
tb
- The visitor which adds new type objects to the
TypeSystem
.SemanticException
public final Node buildTypes(Node n, TypeBuilder tb) throws SemanticException
Lang
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 Lang
tb
- The visitor which adds new type objects to the
TypeSystem
.SemanticException
public final Node disambiguateOverride(Node n, Node parent, AmbiguityRemover ar) throws SemanticException
JLang
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 JLang
ar
- The visitor which disambiguates.SemanticException
public final NodeVisitor disambiguateEnter(Node n, AmbiguityRemover ar) throws SemanticException
JLang
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.disambiguateEnter
in interface JLang
ar
- The visitor which disambiguates.SemanticException
public final Node disambiguate(Node n, AmbiguityRemover ar) throws SemanticException
JLang
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 JLang
ar
- The visitor which disambiguates.SemanticException
public final NodeVisitor typeCheckEnter(Node n, TypeChecker tc) throws SemanticException
Lang
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.typeCheckEnter
in interface Lang
tc
- The type checking visitor.SemanticException
public final Node typeCheckOverride(Node n, Node parent, TypeChecker tc) throws SemanticException
Lang
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.typeCheckOverride
in interface Lang
tc
- The type checking visitor.SemanticException
public final Node typeCheck(Node n, TypeChecker tc) throws SemanticException
Lang
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 Lang
tc
- The type checking visitor.SemanticException
public final Type childExpectedType(Node n, Expr child, AscriptionVisitor av)
JLang
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 JLang
child
- A child expression of this node.av
- An ascription visitor.child
.public final Node checkConstants(Node n, ConstantChecker cc) throws SemanticException
JLang
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 JLang
cc
- The constant checking visitor.SemanticException
public final NodeVisitor exceptionCheckEnter(Node n, ExceptionChecker ec) throws SemanticException
JLang
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.exceptionCheckEnter
in interface JLang
ec
- The visitor.SemanticException
public final Node exceptionCheck(Node n, ExceptionChecker ec) throws SemanticException
JLang
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 JLang
ec
- The visitor.SemanticException
public final java.util.List<Type> throwTypes(Node n, TypeSystem ts)
JLang
throwTypes
in interface JLang
public final NodeVisitor extRewriteEnter(Node n, ExtensionRewriter rw) throws SemanticException
Lang
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 Lang
rw
- The visitor.SemanticException
public final Node extRewrite(Node n, ExtensionRewriter rw) throws SemanticException
Lang
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 Lang
rw
- The visitor.SemanticException
public final void dump(Node n, Lang lang, java.io.OutputStream os)
Lang
public final void dump(Node n, Lang lang, java.io.Writer w)
Lang
public final void prettyPrint(Node n, Lang lang, java.io.OutputStream os)
Lang
prettyPrint
in interface Lang
public final void prettyPrint(Node n, Lang lang, java.io.Writer w)
Lang
prettyPrint
in interface Lang
public final void prettyPrint(Node n, CodeWriter w, PrettyPrinter pp)
Lang
prettyPrint
in interface Lang
w
- The code writer to which to write.pp
- The pretty printer. This is not a visitor.public final void translate(Node n, CodeWriter w, Translator tr)
Lang
public final Node copy(Node n, NodeFactory nf)
Lang
public final Node copy(Node n, ExtensionInfo extInfo) throws SemanticException
Lang
copy
in interface Lang
SemanticException
- If the type information cannot be copied.public final Type findContainer(Call n, TypeSystem ts, MethodInstance mi)
JLang
findContainer
in interface JLang
public final ReferenceType findTargetType(Call n) throws SemanticException
findTargetType
in interface JLang
SemanticException
public final Node typeCheckNullTarget(Call n, TypeChecker tc, java.util.List<Type> argTypes) throws SemanticException
JLang
typeCheckNullTarget
in interface JLang
argTypes
- list of Type
s of the argumentsSemanticException
public final void prettyPrintHeader(ClassDecl n, CodeWriter w, PrettyPrinter tr)
prettyPrintHeader
in interface JLang
public final void prettyPrintFooter(ClassDecl n, CodeWriter w, PrettyPrinter tr)
prettyPrintFooter
in interface JLang
public final Node addDefaultConstructor(ClassDecl n, TypeSystem ts, NodeFactory nf, ConstructorInstance defaultConstructorInstance) throws SemanticException
addDefaultConstructor
in interface JLang
SemanticException
public final boolean constantValueSet(Expr n, Lang lang)
Lang
isConstant()
is valid only if
constantValueSet()
is true.constantValueSet
in interface Lang
public final boolean isConstant(Expr n, Lang lang)
Lang
constantValueSet()
is true.isConstant
in interface Lang
public final java.lang.Object constantValue(Expr n, Lang lang)
Lang
isConstant()
is true.constantValue
in interface Lang
public final boolean condIsConstant(Loop n, JLang lang)
JLang
condIsConstant
in interface JLang
public final boolean condIsConstantTrue(Loop n, JLang lang)
JLang
condIsConstantTrue
in interface JLang
public final boolean condIsConstantFalse(Loop n, JLang lang)
JLang
condIsConstantFalse
in interface JLang
public final Term continueTarget(Loop n)
JLang
continueTarget
in interface JLang
public final TypeNode findQualifiedTypeNode(New n, AmbiguityRemover ar, ClassType outer, TypeNode objectType) throws SemanticException
findQualifiedTypeNode
in interface JLang
SemanticException
public final Expr findQualifier(New n, AmbiguityRemover ar, ClassType ct) throws SemanticException
findQualifier
in interface JLang
SemanticException
public final void typeCheckFlags(New n, TypeChecker tc) throws SemanticException
typeCheckFlags
in interface JLang
SemanticException
public final void typeCheckNested(New n, TypeChecker tc) throws SemanticException
typeCheckNested
in interface JLang
SemanticException
public final void printQualifier(New n, CodeWriter w, PrettyPrinter tr)
printQualifier
in interface JLang
public final void printShortObjectType(New n, CodeWriter w, PrettyPrinter tr)
printShortObjectType
in interface JLang
public final void printBody(New n, CodeWriter w, PrettyPrinter tr)
public final ClassType findEnclosingClass(New n, Context c, ClassType ct)
findEnclosingClass
in interface JLang
public final void printArgs(ProcedureCall n, CodeWriter w, PrettyPrinter tr)
public final void prettyPrintHeader(ProcedureDecl n, Flags flags, CodeWriter w, PrettyPrinter tr)
prettyPrintHeader
in interface JLang
public final Term firstChild(Term n)
JLang
firstChild
in interface JLang
public final <T> java.util.List<T> acceptCFG(Term n, CFGBuilder<?> v, java.util.List<T> succs)
JLang
public final ExceptionChecker constructTryBlockExceptionChecker(Try n, ExceptionChecker ec)
JLang
constructTryBlockExceptionChecker
in interface JLang
ec
- The exception checker immediately prior to the try block.public final Block exceptionCheckTryBlock(Try n, ExceptionChecker ec) throws SemanticException
JLang
exceptionCheckTryBlock
in interface JLang
SemanticException
public final java.util.List<Catch> exceptionCheckCatchBlocks(Try n, ExceptionChecker ec) throws SemanticException
JLang
exceptionCheckCatchBlocks
in interface JLang
SemanticException
public final Block exceptionCheckFinallyBlock(Try n, ExceptionChecker ec) throws SemanticException
JLang
exceptionCheckFinallyBlock
in interface JLang
SemanticException