Package edu.udel.cis.vsl.abc.ast.IF
Interface AST
public interface AST
A representation of a program as an abstract syntax tree.
Each AST encompasses a set of AST nodes. Those nodes are "owned" by the AST. A node can be owned by at most one AST. A node may also be free---not owned by any AST.
The AST also methods to return the internal and external entities associated to the AST.
With few exceptions, nodes owned by an AST cannot be modified. If you want to
modify them (for example, to implement an AST transformation), you first have
to "release" the AST using the method release()
.
Note that an AST is a rooted tree. In particular, there is a unique path from the root to any node in the tree.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(OrdinaryEntity entity) Adds the given entity to this AST.void
removes the entities of this AST.Returns the first difference between this AST and that AST.boolean
Compares this AST with that AST to see if they are equivalent.Returns the ASTFactory associated to this AST.Returns an iterator over all entities with external linkage belonging to this AST.Returns an iterator over all entities with internal linkage belonging to this AST.If this AST contains an entity with internal or external linkage and with the given name, it is returned by this method, else this method returns null.getMain()
Returns the entity for the main function.getNode
(int id) Returns the node with the given id number.int
Returns the number of nodes in the tree.Returns the root node of the abstract syntax tree.Gets the set ofSourceFile
s that formed the source for this AST.boolean
Is this AST representing a whole program? Or is it representing some arbitrary translation unit.void
prettyPrint
(PrintStream out, boolean ignoreStdLibs) Pretty-prints the entire tree, in the form of the original language.void
print
(PrintStream out) Pretty-prints the entire tree.void
release()
Dissolves this AST.void
-
Method Details
-
getASTFactory
ASTFactory getASTFactory()Returns the ASTFactory associated to this AST. This is the factory that was used to create the AST.- Returns:
- the ASTFactory responsible for creating this AST
-
getRootNode
SequenceNode<BlockItemNode> getRootNode()Returns the root node of the abstract syntax tree.- Returns:
- the root node
-
getNumberOfNodes
int getNumberOfNodes()Returns the number of nodes in the tree.- Returns:
- the number of nodes in the tree
-
getNode
Returns the node with the given id number. The id must lie between 0 and n-1, inclusive, where n is the number of nodes.- Returns:
- the node in this tree with the given id
-
getMain
Function getMain()Returns the entity for the main function. Returns null if standard analyses have yet to be performed.- Returns:
- the entity is the main function of the program
-
setMain
-
print
Pretty-prints the entire tree. This should be a human-readable representation. -
prettyPrint
Pretty-prints the entire tree, in the form of the original language.- Parameters:
out
- the output stream for printingignoreStdLibs
- ignore standard libraries? If true, then
-
release
void release()Dissolves this AST. The nodes will be untouched, except they will become "free"--no longer owned by any AST. They can therefore be modified. Also nullifies the sets of internal/external entities associated to the AST. -
getInternalOrExternalEntity
If this AST contains an entity with internal or external linkage and with the given name, it is returned by this method, else this method returns null. The entity will be either a Function, Variable, or Typedef.- Parameters:
name
- name of the entity- Returns:
- the entity
-
getInternalEntities
Iterator<OrdinaryEntity> getInternalEntities()Returns an iterator over all entities with internal linkage belonging to this AST.- Returns:
- entities with internal linkage
-
getExternalEntities
Iterator<OrdinaryEntity> getExternalEntities()Returns an iterator over all entities with external linkage belonging to this AST.- Returns:
- entities with external linkage
-
add
Adds the given entity to this AST.- Parameters:
entity
- an Entity with internal or external linkage
-
diff
Returns the first difference between this AST and that AST.- Parameters:
that
- The AST to be compared with this AST- Returns:
- The difference of this AST and that AST, null if both ASTs are equivalent.
-
equiv
Compares this AST with that AST to see if they are equivalent. Two AST are considered equivalent if they have the same structure of equivalent AST nodes.- Parameters:
that
- The AST to be compared with this AST- Returns:
- true iff this AST is equivalent with that AST
-
clearEntities
void clearEntities()removes the entities of this AST. -
getSourceFiles
Collection<SourceFile> getSourceFiles()Gets the set ofSourceFile
s that formed the source for this AST.- Returns:
- the source file objects for this AST
-
isWholeProgram
boolean isWholeProgram()Is this AST representing a whole program? Or is it representing some arbitrary translation unit. A whole program should contain exactly one main function definition. All identifier used in an expression (except for sizeof or _Alignof operators) or as the function in a function call should have its definition.- Returns:
- true iff this AST is representing a whole program
-