Interface CAstNode

  • All Known Implementing Classes:
    CAstImpl.CAstNodeImpl, CAstImpl.CAstValueImpl, CAstOperator, CAstValueImpl.CAstNodeValueImpl, CAstValueImpl.CAstValueValueImpl

    public interface CAstNode
    This interface represents nodes of CAPA Abstract Syntax Trees. It is a deliberately minimal interface, simply assuming that the nodes form a tree and have some minimal state at each node. In particular, a node has a kind---which should be one of the symbolic constants in this file---and potentially has child nodes, a constant values, or possibly both. Note that there is no support for mutating these trees. This is deliberate, and should not be changed. We do not want to force all clients of the capa ast to handle mutating programs. In particular, the DOMO infrastructure has many forms of caching and other operations that rely on the underlying program being immutable. If you need to mutate these trees for some reason---and think carefully if you really need to, since this is meant to be essentially a wire format between components---make specialized implementations that understand how to do that. Also note that this interface does not assume that you need some great big class hierarchy to structure types of nodes in an ast. Some people prefer such hierarchies as a matter of taste, but this interface is designed to not inflict this design choice on others. Finally note that the set of node types in this file is not meant to be exhaustive. As new languages are added, feel free to add new nodes types as needed.
    • Field Detail

      • SWITCH

        static final int SWITCH
        Represents a standard case statement. Children:
    • condition expression
    • BLOCK_STMT containing all the cases
See Also:
Constant Field Values
  • Method Detail

    • getKind

      int getKind()
      What kind of node is this? Should return some constant from this file.
    • getValue

      Object getValue()
      Returns the constant value represented by this node, if appropriate, and null otherwise.
    • getChild

      CAstNode getChild​(int n)
      Return the nth child of this node. If there is no such child, this method should throw a NoSuchElementException.
    • getChildCount

      int getChildCount()
      How many children does this node have?