Module dev.civl.abc

Interface Program


public interface Program

An abstract representation of a program. This is the highest level representation and the one typically used first in most cases. The program is represented by a single AST, which is obtained by merging a set of ASTs representing translation units.

Future work: change the representation of a program to consist of a set of entities and a set of ASTs, each representing one translation unit. There should be a a method to get the "outer" (file-scope) entities, and a method to get each AST. In this approach, there should not be any need for renaming different entities, i.e., it should be possible, for example, for two structs to have the same name but denote distinct entities because they come from distinct translation units.

It seems that all the constituent ASTs can be analyzed using the same analyzer, factories, etc.

Hence there wil be two ways to create a program: (1) from a collection of ASTs, or (2) from one merged AST (which requires renaming).

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    apply(Transformer transformer)
    Transforms this program using the given Transformer.
    void
    apply(Iterable<Transformer> transformers)
    Applies the given sequence of transformers to this program.
    void
    Transforms program using the transformer specifid by the unique code.
    void
    Applies the sequence of transformers specified by the given code sequence to this program.
    Returns the abstract syntax tree of this program.
    Returns the token factory used for the producing and manipulation of tokens associated to this Program.
    boolean
    Checks if the AST of this program contains any pragma node with the identifier "omp".
    void
    Prints a human readable representation of the program in original language.
    void
    Prints a human readable abstract representation of the program to the given output stream.
    void
     
  • Method Details

    • getAST

      AST getAST()
      Returns the abstract syntax tree of this program. Note that this can return different values as the program is modified. I.e., a whole new AST can replace the current one.
      Returns:
      the current AST of the program
    • getTokenFactory

      TokenFactory getTokenFactory()
      Returns the token factory used for the producing and manipulation of tokens associated to this Program.
      Returns:
      the token factory
    • print

      void print(PrintStream out)
      Prints a human readable abstract representation of the program to the given output stream. (Not in source code format.)
      Parameters:
      out - a print stream
    • prettyPrint

      void prettyPrint(PrintStream out)
      Prints a human readable representation of the program in original language.
      Parameters:
      out - a print stream
    • printSymbolTable

      void printSymbolTable(PrintStream out)
    • apply

      void apply(Transformer transformer) throws SyntaxException
      Transforms this program using the given Transformer.
      Parameters:
      transformer - a program transformer
      Throws:
      SyntaxException - if the syntax of this program is discovered to be incompatible with that expected by the transformer
    • applyTransformer

      void applyTransformer(String code) throws SyntaxException
      Transforms program using the transformer specifid by the unique code.
      Parameters:
      code - transformer code, e.g., "prune" or "mpi"
      Throws:
      SyntaxException - if the syntax of this program is discovered to be incompatible with that expected by the transformer
    • apply

      void apply(Iterable<Transformer> transformers) throws SyntaxException
      Applies the given sequence of transformers to this program. The transformers will be applied in order.
      Parameters:
      transformers - any kind of iterable sequence of transformers
      Throws:
      SyntaxException - if the syntax of this program is discovered to be incompatible with that expected by any transformer in the sequence
    • applyTransformers

      void applyTransformers(Iterable<String> codes) throws SyntaxException
      Applies the sequence of transformers specified by the given code sequence to this program. The transformers will be applied in order.
      Parameters:
      codes - a sequence of transformer codes
      Throws:
      SyntaxException - if the syntax of this program is discovered to be incompatible with that expected by any transformer in the sequence
    • hasOmpPragma

      boolean hasOmpPragma()
      Checks if the AST of this program contains any pragma node with the identifier "omp".
      Returns:
      True if the AST of this program contains at least one pragma nodes with the identifier "omp"