public class SourceFile_c extends Node_c implements SourceFile
SourceFile
is an immutable representations of a Java
language source file. It consists of a package name, a list of
Import
s, and a list of GlobalDecl
s.Modifier and Type | Field and Description |
---|---|
protected java.util.List<TopLevelDecl> |
decls |
protected java.util.List<Import> |
imports |
protected ImportTable |
importTable |
protected PackageNode |
package_ |
protected Source |
source |
Constructor and Description |
---|
SourceFile_c(Position pos,
PackageNode package_,
java.util.List<Import> imports,
java.util.List<TopLevelDecl> decls) |
SourceFile_c(Position pos,
PackageNode package_,
java.util.List<Import> imports,
java.util.List<TopLevelDecl> decls,
Ext ext) |
Modifier and Type | Method and Description |
---|---|
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)
Build type objects for the source file.
|
Node |
copy(NodeFactory nf)
Produce a copy of this node using the given NodeFactory.
|
java.util.List<TopLevelDecl> |
decls()
Get the source's top-level declarations.
|
SourceFile |
decls(java.util.List<TopLevelDecl> decls)
Set the source's top-level declarations.
|
protected <N extends SourceFile_c> |
decls(N n,
java.util.List<TopLevelDecl> decls) |
Node |
disambiguateOverride(Node parent,
AmbiguityRemover ar)
Disambiguate the AST.
|
void |
dump(CodeWriter w)
Dump the AST node for debugging purposes.
|
Context |
enterScope(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 |
extRewrite(ExtensionRewriter rw)
Rewrite the AST for the compilation in this language.
|
java.util.List<Import> |
imports()
Get the source's declared imports.
|
SourceFile |
imports(java.util.List<Import> imports)
Set the source's declared imports.
|
protected <N extends SourceFile_c> |
imports(N n,
java.util.List<Import> imports) |
ImportTable |
importTable()
Get the source's import table.
|
SourceFile |
importTable(ImportTable importTable)
Set the source's import table.
|
protected <N extends SourceFile_c> |
importTable(N n,
ImportTable importTable) |
boolean |
isDisambiguated() |
PackageNode |
package_()
Get the source's declared package.
|
protected <N extends SourceFile_c> |
package_(N n,
PackageNode package_) |
SourceFile |
package_(PackageNode package_)
Set the source's declared package.
|
void |
prettyPrint(CodeWriter w,
PrettyPrinter tr)
Pretty-print the AST using the given
CodeWriter . |
protected <N extends SourceFile_c> |
reconstruct(N n,
PackageNode package_,
java.util.List<Import> imports,
java.util.List<TopLevelDecl> decls)
Reconstruct the source file.
|
Source |
source()
Get the source file.
|
protected <N extends SourceFile_c> |
source(N n,
Source source) |
SourceFile |
source(Source source)
Set the source file.
|
java.lang.String |
toString() |
Node |
typeCheck(TypeChecker tc)
Type check the AST.
|
Node |
visitChildren(NodeVisitor v)
Visit the children of the node.
|
addDecls, checkConstants, childExpectedType, copy, copy, copyIfNeeded, del, del, disambiguate, disambiguateEnter, dump, dump, dump, dump, enterChildScope, error, error, error, exceptionCheck, exceptionCheckEnter, ext, ext, ext, ext, extRewriteEnter, isTypeChecked, lang, position, position, position, prettyPrint, prettyPrint, prettyPrint, prettyPrint, print, printBlock, printSubStmt, throwTypes, translate, typeCheckEnter, typeCheckOverride, visit, visitChild, visitEdge, visitList
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
del, del, error, error, ext, ext, ext, ext, isTypeChecked, position, position, visit, visitEdge
addDecls, checkConstants, childExpectedType, copy, disambiguate, disambiguateEnter, dump, dump, dump, dump, enterChildScope, exceptionCheck, exceptionCheckEnter, extRewriteEnter, lang, prettyPrint, prettyPrint, prettyPrint, prettyPrint, throwTypes, translate, typeCheckEnter, typeCheckOverride, visitChild, visitList
protected PackageNode package_
protected java.util.List<Import> imports
protected java.util.List<TopLevelDecl> decls
protected ImportTable importTable
protected Source source
public SourceFile_c(Position pos, PackageNode package_, java.util.List<Import> imports, java.util.List<TopLevelDecl> decls)
public SourceFile_c(Position pos, PackageNode package_, java.util.List<Import> imports, java.util.List<TopLevelDecl> decls, Ext ext)
public boolean isDisambiguated()
isDisambiguated
in interface Node
isDisambiguated
in class Node_c
public Source source()
SourceFile
source
in interface SourceFile
public SourceFile source(Source source)
SourceFile
source
in interface SourceFile
protected <N extends SourceFile_c> N source(N n, Source source)
public PackageNode package_()
SourceFile
package_
in interface SourceFile
public SourceFile package_(PackageNode package_)
SourceFile
package_
in interface SourceFile
protected <N extends SourceFile_c> N package_(N n, PackageNode package_)
public java.util.List<Import> imports()
SourceFile
imports
in interface SourceFile
Import
.public SourceFile imports(java.util.List<Import> imports)
SourceFile
imports
in interface SourceFile
imports
- A list of Import
.protected <N extends SourceFile_c> N imports(N n, java.util.List<Import> imports)
public java.util.List<TopLevelDecl> decls()
SourceFile
decls
in interface SourceFile
TopLevelDecl
.public SourceFile decls(java.util.List<TopLevelDecl> decls)
SourceFile
decls
in interface SourceFile
decls
- A list of TopLevelDecl
.protected <N extends SourceFile_c> N decls(N n, java.util.List<TopLevelDecl> decls)
public ImportTable importTable()
SourceFile
importTable
in interface SourceFile
public SourceFile importTable(ImportTable importTable)
SourceFile
importTable
in interface SourceFile
protected <N extends SourceFile_c> N importTable(N n, ImportTable importTable)
protected <N extends SourceFile_c> N reconstruct(N n, PackageNode package_, java.util.List<Import> imports, java.util.List<TopLevelDecl> decls)
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 NodeVisitor buildTypesEnter(TypeBuilder tb) throws SemanticException
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 Node_c
tb
- The visitor which adds new type objects to the
TypeSystem
.SemanticException
public Context enterScope(Context c)
Node_c
enterScope
in interface NodeOps
enterScope
in class Node_c
c
- the current Context
Context
to be used for visiting this node.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 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 Node_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 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 void dump(CodeWriter w)
Node