public interface ASTFactory
An ASTFactory is used to create all objects associated to an AST. It actually
encompasses a number of other factories which deal with specific kinds of
objects. For examples, there is a
NodeFactory for creating
ASTNodes, a TypeFactory for creating Types, and so
on.-
Method Summary
Modifier and TypeMethodDescriptiongetASTofLibrary(File file, Configurations.Language language) Constructs the raw (unanalyzed) AST for the translation unit specified by a standard library file name.Returns the node factory used by this AST factory.Returns the token factory used by this AST factory.Returns the type factory used by this AST factory.newAST(SequenceNode<BlockItemNode> root, Collection<SourceFile> sourceFiles, boolean isWholeprogram) Creates a new AST with the given root node.newStringLiteralNode(Formation formation, String representation) Produces a newStringLiteralNode.
-
Method Details
-
newAST
AST newAST(SequenceNode<BlockItemNode> root, Collection<SourceFile> sourceFiles, boolean isWholeprogram) throws SyntaxException Creates a new AST with the given root node. The root node is typically a translation unit, but it may also be the root of an AST formed by merging multiple translation units. This method also checks conformance with many facets of the C11 Standard, resolves references and adds this information to the AST, marks all the AST nodes reachable from root as "owned" by the new AST, and numbers the nodes from 0 to n-1, where n is the number of reachable nodes. After this method returns, the nodes belonging to the new AST will be essentially immutable (with exceptions for certain "harmless" fields that cannot effect the correctness of the AST). If you want to modify the AST, you have to invoke itsAST.release()method, which dissolves the AST but leaves the nodes untouched and free (so mutable again), and then create a new AST once the modifications are complete. You may also invokeASTNode.copy()on the root node and use it to create a new AST equivalent to the original, with all new nodes, if you want to keep the original AST. Some of the interpretation that takes place:- when creating the abstract type of a formal function parameter, the type "qualified array of T" is changed to "qualified pointer to T".
- "f(void)" means 0 parameters. "f()" means unknown parameters.
- determines and sets the cases in the switch statements
- Parameters:
root- the root node of the new ASTisWholeprogram- is this AST representing a whole program (seeAST.isWholeProgram())- Returns:
- the new AST
- Throws:
SyntaxException- if something violating the syntax rules is found while traversing this AST
-
getNodeFactory
NodeFactory getNodeFactory()Returns the node factory used by this AST factory. The node factory is responsible for producing new AST nodes.- Returns:
- the node factory
-
getTokenFactory
TokenFactory getTokenFactory()Returns the token factory used by this AST factory. The token factory is responsible for creating not only tokens, but a number of objects related to tokens, such asSourceandInclusionobjects.- Returns:
- the token factory
-
getTypeFactory
TypeFactory getTypeFactory()Returns the type factory used by this AST factory. The type factory is used to createTypeobjects.- Returns:
- the type factory
-
getASTofLibrary
Constructs the raw (unanalyzed) AST for the translation unit specified by a standard library file name.- Parameters:
file- the file of the system library file, including the path to the file but not including a directory; e.g., "/include/abc/stdlib.h"language- the language of the library- Returns:
- the raw AST for the specified translation unit
- Throws:
ABCException- if something goes wrong while preprocessing, parsing and translating the library file
-
newStringLiteralNode
StringLiteralNode newStringLiteralNode(Formation formation, String representation) throws SyntaxException Produces a newStringLiteralNode.- Parameters:
formation- formation describing how this node was produced; consider usingTokenFactory.newSystemFormation(String)representation- the text of the string literal exactly as it would appear in a program source; this must include the surrounding (single or double) quotes- Returns:
- new string literal node
- Throws:
SyntaxException- if therepresentationdoes not conform to the C11 specification of string literals
-