Interface Macro

All Known Subinterfaces:
FunctionMacro, ObjectMacro

public interface Macro

An abstract representation of a preprocessor macro. Used to represent both object and function macros.

C11 5.1.1.2(3) states that in translation phase 3 (in which the source is decomposed into preprocessing tokens): "Whether each nonempty sequence of white-space characters other than new-line is retained or replaced by one space character is implementation-defined." Note that in the vocabulary of C11, white-space characters are not preprocessing tokens; they are used to separate preprocessing tokens.

A Macro object maintains the sequence of all tokens in the macro definition body, including the white space tokens. This is called the body token sequence. The subsequence consisting of the non-whitespace tokens is knows as the replacement token sequence (in accord with the vocabulary of C11). To repeat: the replacement token sequence is a subsequence of the body token sequence. This interface provides methods for navigating both sequences.

The index of a token in the macro definition body is its index in the body token sequence, counting from 0. Hence the body tokens have indexes 0, 1, ..., numBodyTokens-1. The replacement ID of a replacement token R is the number of replacement tokens that occur before R in the body; hence the replacement tokens have IDs 0, 1, 2, ..., numReplacementTokens-1.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static class 
    The body of a Macro definition consists of a sequence of Macro.ReplacementUnits, each of which comprises a preprocessing token (a non-whitespace token known as the "replacement token" in C11) plus some possible whitespace.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.antlr.runtime.tree.Tree
    The node in the ANTLR parse tree which is the root of the macro body, i.e., the sequence of replacement tokens.
    org.antlr.runtime.tree.Tree
    The node in the ANTLR parse tree for the preprocessor grammar which is the root of the macro definition for this macro.
    Returns the file in which this macro definition occurs.
    Returns the macro name.
    int
    Gets the number of replacement tokens in the macro definition body.
    getReplacementUnit(int index)
    Returns the index-th Macro.ReplacementUnit object of the Macro body.
  • Method Details

    • getDefinitionNode

      org.antlr.runtime.tree.Tree getDefinitionNode()
      The node in the ANTLR parse tree for the preprocessor grammar which is the root of the macro definition for this macro.
      Returns:
      ANTLR tree node for the macro definition
    • getBodyNode

      org.antlr.runtime.tree.Tree getBodyNode()
      The node in the ANTLR parse tree which is the root of the macro body, i.e., the sequence of replacement tokens. This is a child of the definition node.
      Returns:
      the ANTLR tree node for the macro body
    • getNumReplacements

      int getNumReplacements()
      Gets the number of replacement tokens in the macro definition body.
      Returns:
      number of preprocessing tokens in macro definition body
    • getName

      String getName()
      Returns the macro name.
      Returns:
      the macro name
    • getFile

      SourceFile getFile()
      Returns the file in which this macro definition occurs.
      Returns:
      file containing this macro definition
    • getReplacementUnit

      Macro.ReplacementUnit getReplacementUnit(int index)
      Returns the index-th Macro.ReplacementUnit object of the Macro body.
      Parameters:
      index - integer in range [0,numReplacements-1]
      Returns:
      the index-th replacement in the macro definition body