Interface CAstNode
- All Known Subinterfaces:
CAstLeafNode
,JavaScriptCAstNode
- All Known Implementing Classes:
CAstImpl.CAstNodeImpl
,CAstImpl.CAstValueImpl
,CAstOperator
,CAstValueImpl.CAstNodeValueImpl
,CAstValueImpl.CAstValueValueImpl
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.
- Author:
- Julian Dolby (dolby@us.ibm.com), Robert M. Fuhrer (rfuhrer@watson.ibm.com)
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
Represents a block of sequentially-executed nodes, the last of which produces the value for the entire block (like progn from lisp).static final int
Represents a block of sequential statements.static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
Represents an expression statement (e.g.static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
Represents a standard while loop.static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
Represents a standard case statement.static final int
static final int
static final int
Represents a standard try/catch statement.static final int
static final int
static final int
static final int
static final int
static final int
static final int
-
Method Summary
Modifier and TypeMethodDescriptiondefault CAstNode
getChild
(int n) Return the nth child of this node.default int
How many children does this node have?int
getKind()
What kind of node is this? Should return some constant from this file.getValue()
Returns the constant value represented by this node, if appropriate, and null otherwise.
-
Field Details
-
SWITCH
static final int SWITCHRepresents a standard case statement. Children:- condition expression
- BLOCK_STMT containing all the cases
- See Also:
-
LOOP
static final int LOOPRepresents a standard while loop. Children:- expression denoting the loop condition
- statement denoting the loop body
- See Also:
-
BLOCK_STMT
static final int BLOCK_STMTRepresents a block of sequential statements. Children:- statement #1
- statement #2
- ...
- See Also:
-
TRY
static final int TRYRepresents a standard try/catch statement. Note that while some languages choose to bundle together the notion of try/catch and the notion of unwind-protect (aka 'finally'), the CAst does not. There is a separate UNWIND node type. Children:- the code of the try block.
- the code of the catch block
- ...
- See Also:
-
EXPR_STMT
static final int EXPR_STMTRepresents an expression statement (e.g. "foo();"). Children:- the expression
- See Also:
-
DECL_STMT
static final int DECL_STMT- See Also:
-
RETURN
static final int RETURN- See Also:
-
GOTO
static final int GOTO- See Also:
-
BREAK
static final int BREAK- See Also:
-
CONTINUE
static final int CONTINUE- See Also:
-
IF_STMT
static final int IF_STMT- See Also:
-
THROW
static final int THROW- See Also:
-
FUNCTION_STMT
static final int FUNCTION_STMT- See Also:
-
ASSIGN
static final int ASSIGN- See Also:
-
ASSIGN_PRE_OP
static final int ASSIGN_PRE_OP- See Also:
-
ASSIGN_POST_OP
static final int ASSIGN_POST_OP- See Also:
-
LABEL_STMT
static final int LABEL_STMT- See Also:
-
IFGOTO
static final int IFGOTO- See Also:
-
EMPTY
static final int EMPTY- See Also:
-
RETURN_WITHOUT_BRANCH
static final int RETURN_WITHOUT_BRANCH- See Also:
-
CATCH
static final int CATCH- See Also:
-
UNWIND
static final int UNWIND- See Also:
-
MONITOR_ENTER
static final int MONITOR_ENTER- See Also:
-
MONITOR_EXIT
static final int MONITOR_EXIT- See Also:
-
ECHO
static final int ECHO- See Also:
-
YIELD_STMT
static final int YIELD_STMT- See Also:
-
FORIN_LOOP
static final int FORIN_LOOP- See Also:
-
GLOBAL_DECL
static final int GLOBAL_DECL- See Also:
-
CLASS_STMT
static final int CLASS_STMT- See Also:
-
FUNCTION_EXPR
static final int FUNCTION_EXPR- See Also:
-
EXPR_LIST
static final int EXPR_LIST- See Also:
-
CALL
static final int CALL- See Also:
-
GET_CAUGHT_EXCEPTION
static final int GET_CAUGHT_EXCEPTION- See Also:
-
BLOCK_EXPR
static final int BLOCK_EXPRRepresents a block of sequentially-executed nodes, the last of which produces the value for the entire block (like progn from lisp). Children:- node 1
- node 2
- ...
- block value expression
- See Also:
-
BINARY_EXPR
static final int BINARY_EXPR- See Also:
-
UNARY_EXPR
static final int UNARY_EXPR- See Also:
-
IF_EXPR
static final int IF_EXPR- See Also:
-
ANDOR_EXPR
static final int ANDOR_EXPR- See Also:
-
NEW
static final int NEW- See Also:
-
OBJECT_LITERAL
static final int OBJECT_LITERAL- See Also:
-
VAR
static final int VAR- See Also:
-
OBJECT_REF
static final int OBJECT_REF- See Also:
-
CHOICE_EXPR
static final int CHOICE_EXPR- See Also:
-
CHOICE_CASE
static final int CHOICE_CASE- See Also:
-
SUPER
static final int SUPER- See Also:
-
THIS
static final int THIS- See Also:
-
ARRAY_LITERAL
static final int ARRAY_LITERAL- See Also:
-
CAST
static final int CAST- See Also:
-
INSTANCEOF
static final int INSTANCEOF- See Also:
-
ARRAY_REF
static final int ARRAY_REF- See Also:
-
ARRAY_LENGTH
static final int ARRAY_LENGTH- See Also:
-
TYPE_OF
static final int TYPE_OF- See Also:
-
EACH_ELEMENT_HAS_NEXT
static final int EACH_ELEMENT_HAS_NEXT- See Also:
-
EACH_ELEMENT_GET
static final int EACH_ELEMENT_GET- See Also:
-
LIST_EXPR
static final int LIST_EXPR- See Also:
-
EMPTY_LIST_EXPR
static final int EMPTY_LIST_EXPR- See Also:
-
TYPE_LITERAL_EXPR
static final int TYPE_LITERAL_EXPR- See Also:
-
IS_DEFINED_EXPR
static final int IS_DEFINED_EXPR- See Also:
-
MACRO_VAR
static final int MACRO_VAR- See Also:
-
NARY_EXPR
static final int NARY_EXPR- See Also:
-
NEW_ENCLOSING
static final int NEW_ENCLOSING- See Also:
-
COMPREHENSION_EXPR
static final int COMPREHENSION_EXPR- See Also:
-
LOCAL_SCOPE
static final int LOCAL_SCOPE- See Also:
-
SPECIAL_PARENT_SCOPE
static final int SPECIAL_PARENT_SCOPE- See Also:
-
CONSTANT
static final int CONSTANT- See Also:
-
OPERATOR
static final int OPERATOR- See Also:
-
PRIMITIVE
static final int PRIMITIVE- See Also:
-
ERROR
static final int ERROR- See Also:
-
VOID
static final int VOID- See Also:
-
ASSERT
static final int ASSERT- See Also:
-
INCLUDE
static final int INCLUDE- See Also:
-
NAMED_ENTITY_REF
static final int NAMED_ENTITY_REF- See Also:
-
SUB_LANGUAGE_BASE
static final int SUB_LANGUAGE_BASE- See Also:
-
-
Method Details
-
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
Return the nth child of this node. If there is no such child, this method should throw an IndexOutOfBoundsException. -
getChildCount
default int getChildCount()How many children does this node have? -
getChildren
-