Interface ASTFactory

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 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 its AST.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 invoke ASTNode.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
      root - the root node of the new AST
      isWholeprogram - is this AST representing a whole program (see AST.isWholeProgram() )
      the new AST
      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.
      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 as Source and Inclusion objects.
      the token factory
    • getTypeFactory

      TypeFactory getTypeFactory()
      Returns the type factory used by this AST factory. The type factory is used to create Type objects.
      the type factory
    • getASTofLibrary

      AST getASTofLibrary(File file, Configurations.Language language) throws ABCException
      Constructs the raw (unanalyzed) AST for the translation unit specified by a standard library file name.
      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
      the raw AST for the specified translation unit
      ABCException - if something goes wrong while preprocessing, parsing and translating the library file