PUMA Library Reference Manual
|
#include <Puma/CTree.h>
Base class for all C/C++ syntax tree classes.
The syntax tree is the result of the syntactic analysis of the input source code representing its syntactic structure according to the accepted grammar (see class Syntax).
Objects of this class and classes derived from this class are created by the tree builder component of Puma during the parse process. A syntax tree shall be destroyed using the tree builder that has created it by calling its method Builder::destroy(CTree*) with the root node of the syntax tree as its argument.
The navigation in the syntax tree is done using the methods CTree::Parent(), CTree::Sons(), and CTree::Son(int) const. In a syntax tree "sons" are understood as the syntactic child nodes of a syntax tree node, whereas "daughters" are understood are their semantic child nodes.
Another way to traverse a syntax tree is to implement an own tree visitor based on class Puma::CVisitor. This is recommended especially for larger syntax trees.
A syntax tree node can be identified by comparing its node name with the node identifier of the expected syntax tree node:
Based on the syntax tree further semantic analyses can be performed. Semantic information, like scope, value, type, and object information, is linked into the syntax tree. It can be accessed using the methods CTree::SemScope(), CTree::SemValue(), and CTree::SemObject(). Some nodes provide short-cuts to the semantic type and value information by implementing the methods CTree::Type() and CTree::Value().
The information of the syntax tree can be used to perform high-level transformations of the source code (see class ManipCommander).
Public Member Functions | |
virtual | ~CTree () |
Destructor. | |
virtual int | Sons () const =0 |
Get the number of sons. | |
virtual CTree * | Son (int n) const |
Get the n-th son. | |
virtual const char * | NodeName () const =0 |
Get the node name (node identifier). | |
virtual Token * | token () const |
Get the first token of the syntactic construct represented by this sub-tree. | |
virtual Token * | end_token () const |
Get the last token of the syntactic construct represented by this sub-tree. | |
virtual CT_Token * | token_node () const |
Get the CT_Token node of the first token of the syntactic construct represented by this sub-tree. | |
virtual CT_Token * | end_token_node () const |
Get the CT_Token node of the last token of the syntactic construct represented by this sub-tree. | |
virtual void | ReplaceSon (CTree *old_son, CTree *new_son) |
Replace a son. | |
virtual CTree * | Parent () const |
Get the parent node. | |
virtual CTypeInfo * | Type () const |
Get the semantic type of the node. | |
virtual CExprValue * | Value () const |
Get the calculated value of the expression. | |
virtual CSemScope * | SemScope () const |
Get the scope opened by the node. | |
virtual CSemValue * | SemValue () const |
Get the semantic value of the node. | |
virtual CSemObject * | SemObject () const |
Get the semantic information of the node. | |
virtual CT_SimpleName * | IsSimpleName () |
Get a pointer to CT_SimpleName if the current node represents a name. | |
virtual CT_String * | IsString () |
Get a pointer to CT_String if the current node represents a string. | |
virtual CT_Declarator * | IsDeclarator () |
Get a pointer to CT_Declarator if the current node represents a declarator. | |
virtual CT_Statement * | IsStatement () |
Get a pointer to CT_Statement if the current node represents a statement. | |
virtual CT_Expression * | IsExpression () |
Get a pointer to CT_Expression if the current node represents a expression. | |
virtual CT_Decl * | IsDeclaration () |
Get a pointer to CT_Decl if the current node represents a declaration. | |
virtual CT_Call * | IsCall () |
Get a pointer to CT_Call if the current node represents a call expression. | |
virtual CT_List * | IsList () |
Get a pointer to CT_List if the current node represents a list. | |
virtual CT_DelayedParse * | IsDelayedParse () |
Get a pointer to CT_DelayedParse if the current node represents a delayed code fragment. | |
bool | HasValueNull () const |
Return true if the tree has the constant value 0. | |
Static Public Attributes | |
static int | alloc |
static int | release |
Protected Member Functions | |
CTree * | Son (CTree *const *sons, int len, int n) const |
Get the n-th son from given sons array. | |
int | Sons (CTree *const *sons, int len) const |
Get the number of sons in the given sons array. | |
void | ReplaceSon (CTree **sons, int len, CTree *old_son, CTree *new_son) |
Replace a son. | |
void | ReplaceSon (CTree *&son, CTree *old_son, CTree *new_son) |
Replace a son if it equals the given son. | |
void | AddSon (CTree *&son, CTree *new_son) |
Add a new son. | |
void | SetParent (const CTree *parent) |
Set the parent tree node. | |
void | SetParent (CTree *node, const CTree *parent) |
Set the parent tree node of the given tree node. | |
CTree () | |
Default constructor. | |
|
inlineprotected |
Default constructor.
|
inlinevirtual |
Destructor.
Add a new son.
son | The actual son. |
new_son | The new son, overwrites the actual son. |
|
virtual |
Get the last token of the syntactic construct represented by this sub-tree.
Reimplemented in Puma::CT_Token.
|
virtual |
Get the CT_Token node of the last token of the syntactic construct represented by this sub-tree.
Reimplemented in Puma::CT_Token.
bool Puma::CTree::HasValueNull | ( | ) | const |
Return true if the tree has the constant value 0.
|
inlinevirtual |
Get a pointer to CT_Call if the current node represents a call expression.
Reimplemented in Puma::CT_Call.
|
inlinevirtual |
Get a pointer to CT_Decl if the current node represents a declaration.
Reimplemented in Puma::CT_Decl.
|
inlinevirtual |
Get a pointer to CT_Declarator if the current node represents a declarator.
Reimplemented in Puma::CT_Declarator.
|
inlinevirtual |
Get a pointer to CT_DelayedParse if the current node represents a delayed code fragment.
Reimplemented in Puma::CT_DelayedParse.
|
inlinevirtual |
Get a pointer to CT_Expression if the current node represents a expression.
Reimplemented in Puma::CT_Expression.
|
inlinevirtual |
Get a pointer to CT_List if the current node represents a list.
Reimplemented in Puma::CT_List.
|
inlinevirtual |
Get a pointer to CT_SimpleName if the current node represents a name.
Reimplemented in Puma::CT_SimpleName.
|
inlinevirtual |
Get a pointer to CT_Statement if the current node represents a statement.
Reimplemented in Puma::CT_Statement.
|
inlinevirtual |
Get a pointer to CT_String if the current node represents a string.
Reimplemented in Puma::CT_String.
|
pure virtual |
Get the node name (node identifier).
Implemented in Puma::CT_StaticAssert, Puma::Builder::Container, Puma::CT_DelayedParse, Puma::CT_DelayedParseParamInit, Puma::CT_DelayedParseFctTryBlock, Puma::CT_DelayedParseCtorInit, Puma::CT_DelayedParsePureSpec, Puma::CT_DelayedParseFctBody, Puma::CT_DelayedParseSkippedFctBody, Puma::CT_DelayedParseConstInit, Puma::CT_Error, Puma::CT_Token, Puma::CT_ExprList, Puma::CT_DeclaratorList, Puma::CT_EnumeratorList, Puma::CT_DeclList, Puma::CT_DeclSpecSeq, Puma::CT_CmpdStmt, Puma::CT_HandlerSeq, Puma::CT_TemplateParamList, Puma::CT_TemplateArgList, Puma::CT_ExtensionList, Puma::CT_Expression, Puma::CT_Call, Puma::CT_ImplicitCall, Puma::CT_String, Puma::CT_WideString, Puma::CT_Integer, Puma::CT_Character, Puma::CT_WideCharacter, Puma::CT_Float, Puma::CT_Bool, Puma::CT_BracedExpr, Puma::CT_SimpleName, Puma::CT_PrivateName, Puma::CT_DestructorName, Puma::CT_TemplateName, Puma::CT_OperatorName, Puma::CT_ConversionName, Puma::CT_QualName, Puma::CT_RootQualName, Puma::CT_BinaryExpr, Puma::CT_MembPtrExpr, Puma::CT_MembRefExpr, Puma::CT_UnaryExpr, Puma::CT_PostfixExpr, Puma::CT_AddrExpr, Puma::CT_DerefExpr, Puma::CT_DeleteExpr, Puma::CT_NewExpr, Puma::CT_IfThenExpr, Puma::CT_CmpdLiteral, Puma::CT_ConstructExpr, Puma::CT_ThrowExpr, Puma::CT_IndexExpr, Puma::CT_CallExpr, Puma::CT_CastExpr, Puma::CT_StaticCast, Puma::CT_ConstCast, Puma::CT_ReintCast, Puma::CT_DynamicCast, Puma::CT_ImplicitCast, Puma::CT_TypeidExpr, Puma::CT_SizeofExpr, Puma::CT_AlignofExpr, Puma::CT_TypeTraitExpr, Puma::CT_OffsetofExpr, Puma::CT_IndexDesignator, Puma::CT_MembDesignator, Puma::CT_DesignatorSeq, Puma::CT_PrimDeclSpec, Puma::CT_NamedType, Puma::CT_ClassSpec, Puma::CT_UnionSpec, Puma::CT_EnumSpec, Puma::CT_ExceptionSpec, Puma::CT_Program, Puma::CT_ObjDecl, Puma::CT_TemplateDecl, Puma::CT_NonTypeParamDecl, Puma::CT_TypeParamDecl, Puma::CT_EnumDef, Puma::CT_Enumerator, Puma::CT_FctDef, Puma::CT_AsmDef, Puma::CT_Handler, Puma::CT_LinkageSpec, Puma::CT_ArgDecl, Puma::CT_ArgDeclList, Puma::CT_ArgDeclSeq, Puma::CT_ArgNameList, Puma::CT_NamespaceDef, Puma::CT_NamespaceAliasDef, Puma::CT_UsingDirective, Puma::CT_InitDeclarator, Puma::CT_BracedDeclarator, Puma::CT_ArrayDelimiter, Puma::CT_ArrayDeclarator, Puma::CT_FctDeclarator, Puma::CT_RefDeclarator, Puma::CT_PtrDeclarator, Puma::CT_MembPtrDeclarator, Puma::CT_BitFieldDeclarator, Puma::CT_LabelStmt, Puma::CT_DefaultStmt, Puma::CT_TryStmt, Puma::CT_CaseStmt, Puma::CT_ExprStmt, Puma::CT_DeclStmt, Puma::CT_SwitchStmt, Puma::CT_IfStmt, Puma::CT_IfElseStmt, Puma::CT_BreakStmt, Puma::CT_ContinueStmt, Puma::CT_GotoStmt, Puma::CT_ReturnStmt, Puma::CT_WhileStmt, Puma::CT_DoStmt, Puma::CT_ForStmt, Puma::CT_Condition, Puma::CT_ClassDef, Puma::CT_UnionDef, Puma::CT_MembList, Puma::CT_MembInitList, Puma::CT_MembInit, Puma::CT_BaseSpecList, Puma::CT_AccessSpec, Puma::CT_BaseSpec, Puma::CT_AccessDecl, Puma::CT_UsingDecl, Puma::CT_Any, Puma::CT_AnyList, Puma::CT_AnyExtension, Puma::CT_AnyCondition, Puma::CT_GnuAsmSpec, Puma::CT_GnuAsmDef, Puma::CT_GnuAsmOperand, Puma::CT_GnuAsmOperands, Puma::CT_GnuAsmClobbers, Puma::CT_GnuAttribute, Puma::CT_GnuStatementExpr, Puma::CT_GnuTypeof, Puma::CT_GnuLocalLabelStmt, Puma::CT_GnuCaseStmt, and Puma::CT_AsmBlock.
|
inlinevirtual |
Get the parent node.
Replace a son if it equals the given son.
son | The actual son. |
old_son | The son to replace, must match the actual son. |
new_son | The new son, overwrites the actual son. |
Replace a son.
sons | The sons array. |
len | Length of the sons array. |
old_son | The son to replace. |
new_son | The new son. |
Replace a son.
old_son | The son to replace. |
new_son | The son with which to replace. |
Reimplemented in Puma::CT_StaticAssert, Puma::CT_DelayedParse, Puma::CT_List, Puma::CT_ImplicitCall, Puma::CT_Integer, Puma::CT_Character, Puma::CT_Float, Puma::CT_Bool, Puma::CT_BracedExpr, Puma::CT_BinaryExpr, Puma::CT_MembPtrExpr, Puma::CT_UnaryExpr, Puma::CT_DeleteExpr, Puma::CT_NewExpr, Puma::CT_IfThenExpr, Puma::CT_CmpdLiteral, Puma::CT_ConstructExpr, Puma::CT_ThrowExpr, Puma::CT_IndexExpr, Puma::CT_CallExpr, Puma::CT_CastExpr, Puma::CT_StaticCast, Puma::CT_ImplicitCast, Puma::CT_TypeidExpr, Puma::CT_SizeofExpr, Puma::CT_AlignofExpr, Puma::CT_TypeTraitExpr, Puma::CT_OffsetofExpr, Puma::CT_IndexDesignator, Puma::CT_MembDesignator, Puma::CT_PrimDeclSpec, Puma::CT_NamedType, Puma::CT_ClassSpec, Puma::CT_ExceptionSpec, Puma::CT_ObjDecl, Puma::CT_TemplateDecl, Puma::CT_NonTypeParamDecl, Puma::CT_TypeParamDecl, Puma::CT_EnumDef, Puma::CT_Enumerator, Puma::CT_FctDef, Puma::CT_AsmDef, Puma::CT_Handler, Puma::CT_LinkageSpec, Puma::CT_ArgDecl, Puma::CT_NamespaceDef, Puma::CT_NamespaceAliasDef, Puma::CT_UsingDirective, Puma::CT_InitDeclarator, Puma::CT_BracedDeclarator, Puma::CT_ArrayDelimiter, Puma::CT_ArrayDeclarator, Puma::CT_FctDeclarator, Puma::CT_RefDeclarator, Puma::CT_PtrDeclarator, Puma::CT_MembPtrDeclarator, Puma::CT_BitFieldDeclarator, Puma::CT_LabelStmt, Puma::CT_DefaultStmt, Puma::CT_TryStmt, Puma::CT_CaseStmt, Puma::CT_ExprStmt, Puma::CT_DeclStmt, Puma::CT_SwitchStmt, Puma::CT_IfStmt, Puma::CT_IfElseStmt, Puma::CT_BreakStmt, Puma::CT_ContinueStmt, Puma::CT_GotoStmt, Puma::CT_ReturnStmt, Puma::CT_WhileStmt, Puma::CT_DoStmt, Puma::CT_ForStmt, Puma::CT_Condition, Puma::CT_ClassDef, Puma::CT_MembInit, Puma::CT_AccessSpec, Puma::CT_BaseSpec, Puma::CT_AccessDecl, Puma::CT_UsingDecl, Puma::CT_Any, Puma::CT_AnyExtension, Puma::CT_AnyCondition, Puma::CT_GnuAsmSpec, Puma::CT_GnuAsmDef, Puma::CT_GnuAsmOperand, Puma::CT_GnuStatementExpr, Puma::CT_GnuTypeof, Puma::CT_GnuCaseStmt, and Puma::CT_AsmBlock.
|
inlinevirtual |
Get the semantic information of the node.
Reimplemented in Puma::CT_ExprList, Puma::CT_Call, Puma::CT_SimpleName, Puma::CT_QualName, Puma::CT_DeleteExpr, Puma::CT_NewExpr, Puma::CT_CmpdLiteral, Puma::CT_ConstructExpr, Puma::CT_NamedType, Puma::CT_ClassSpec, Puma::CT_TemplateParamDecl, Puma::CT_NonTypeParamDecl, Puma::CT_EnumDef, Puma::CT_Enumerator, Puma::CT_FctDef, Puma::CT_ArgDecl, Puma::CT_NamespaceDef, Puma::CT_NamespaceAliasDef, Puma::CT_InitDeclarator, Puma::CT_BitFieldDeclarator, Puma::CT_Condition, Puma::CT_ClassDef, and Puma::CT_MembInit.
|
inlinevirtual |
Get the scope opened by the node.
Reimplemented in Puma::CT_CmpdStmt, Puma::CT_TemplateParamList, Puma::CT_Program, Puma::CT_TemplateDecl, Puma::CT_Handler, Puma::CT_ArgDeclList, Puma::CT_ArgDeclSeq, Puma::CT_SwitchStmt, Puma::CT_IfStmt, Puma::CT_IfElseStmt, Puma::CT_WhileStmt, Puma::CT_ForStmt, Puma::CT_MembList, and Puma::CT_MembInitList.
|
inlinevirtual |
Get the semantic value of the node.
Reimplemented in Puma::CT_ExprList, Puma::CT_Expression, Puma::CT_String, Puma::CT_BracedExpr, Puma::CT_SimpleName, Puma::CT_QualName, Puma::CT_DesignatorSeq, Puma::CT_ArgDecl, Puma::CT_ArrayDeclarator, Puma::CT_AnyExtension, and Puma::CT_GnuTypeof.
|
inlineprotected |
Set the parent tree node.
parent | The new parent tree node. |
Set the parent tree node of the given tree node.
node | The tree node. |
parent | The new parent. |
Get the n-th son from given sons array.
Skips empty (NULL) array items.
sons | The sons array. |
len | Length of the sons array. |
n | Index of the son. |
|
inlinevirtual |
Get the n-th son.
n | The index of the son. |
Reimplemented in Puma::CT_StaticAssert, Puma::CT_DelayedParse, Puma::CT_List, Puma::CT_ImplicitCall, Puma::CT_Integer, Puma::CT_Character, Puma::CT_Float, Puma::CT_Bool, Puma::CT_BracedExpr, Puma::CT_PrivateName, Puma::CT_BinaryExpr, Puma::CT_MembPtrExpr, Puma::CT_UnaryExpr, Puma::CT_DeleteExpr, Puma::CT_NewExpr, Puma::CT_IfThenExpr, Puma::CT_CmpdLiteral, Puma::CT_ConstructExpr, Puma::CT_ThrowExpr, Puma::CT_IndexExpr, Puma::CT_CallExpr, Puma::CT_CastExpr, Puma::CT_StaticCast, Puma::CT_ImplicitCast, Puma::CT_TypeidExpr, Puma::CT_SizeofExpr, Puma::CT_AlignofExpr, Puma::CT_TypeTraitExpr, Puma::CT_OffsetofExpr, Puma::CT_IndexDesignator, Puma::CT_MembDesignator, Puma::CT_PrimDeclSpec, Puma::CT_NamedType, Puma::CT_ClassSpec, Puma::CT_ExceptionSpec, Puma::CT_ObjDecl, Puma::CT_TemplateDecl, Puma::CT_NonTypeParamDecl, Puma::CT_TypeParamDecl, Puma::CT_EnumDef, Puma::CT_Enumerator, Puma::CT_FctDef, Puma::CT_AsmDef, Puma::CT_Handler, Puma::CT_LinkageSpec, Puma::CT_ArgDecl, Puma::CT_NamespaceDef, Puma::CT_NamespaceAliasDef, Puma::CT_UsingDirective, Puma::CT_InitDeclarator, Puma::CT_BracedDeclarator, Puma::CT_ArrayDelimiter, Puma::CT_ArrayDeclarator, Puma::CT_FctDeclarator, Puma::CT_RefDeclarator, Puma::CT_PtrDeclarator, Puma::CT_MembPtrDeclarator, Puma::CT_BitFieldDeclarator, Puma::CT_LabelStmt, Puma::CT_DefaultStmt, Puma::CT_TryStmt, Puma::CT_CaseStmt, Puma::CT_ExprStmt, Puma::CT_DeclStmt, Puma::CT_SwitchStmt, Puma::CT_IfStmt, Puma::CT_IfElseStmt, Puma::CT_BreakStmt, Puma::CT_ContinueStmt, Puma::CT_GotoStmt, Puma::CT_ReturnStmt, Puma::CT_WhileStmt, Puma::CT_DoStmt, Puma::CT_ForStmt, Puma::CT_Condition, Puma::CT_ClassDef, Puma::CT_MembInit, Puma::CT_AccessSpec, Puma::CT_BaseSpec, Puma::CT_AccessDecl, Puma::CT_UsingDecl, Puma::CT_Any, Puma::CT_AnyExtension, Puma::CT_AnyCondition, Puma::CT_GnuAsmSpec, Puma::CT_GnuAsmDef, Puma::CT_GnuAsmOperand, Puma::CT_GnuStatementExpr, Puma::CT_GnuTypeof, Puma::CT_GnuCaseStmt, and Puma::CT_AsmBlock.
|
pure virtual |
Get the number of sons.
Implemented in Puma::CT_StaticAssert, Puma::CT_DelayedParse, Puma::CT_Error, Puma::CT_Token, Puma::CT_List, Puma::CT_Expression, Puma::CT_ImplicitCall, Puma::CT_Integer, Puma::CT_Character, Puma::CT_Float, Puma::CT_Bool, Puma::CT_BracedExpr, Puma::CT_PrivateName, Puma::CT_BinaryExpr, Puma::CT_MembPtrExpr, Puma::CT_UnaryExpr, Puma::CT_DeleteExpr, Puma::CT_NewExpr, Puma::CT_IfThenExpr, Puma::CT_CmpdLiteral, Puma::CT_ConstructExpr, Puma::CT_ThrowExpr, Puma::CT_IndexExpr, Puma::CT_CallExpr, Puma::CT_CastExpr, Puma::CT_StaticCast, Puma::CT_ImplicitCast, Puma::CT_TypeidExpr, Puma::CT_SizeofExpr, Puma::CT_AlignofExpr, Puma::CT_TypeTraitExpr, Puma::CT_OffsetofExpr, Puma::CT_IndexDesignator, Puma::CT_MembDesignator, Puma::CT_PrimDeclSpec, Puma::CT_NamedType, Puma::CT_ClassSpec, Puma::CT_ExceptionSpec, Puma::CT_ObjDecl, Puma::CT_TemplateDecl, Puma::CT_NonTypeParamDecl, Puma::CT_TypeParamDecl, Puma::CT_EnumDef, Puma::CT_Enumerator, Puma::CT_FctDef, Puma::CT_AsmDef, Puma::CT_Handler, Puma::CT_LinkageSpec, Puma::CT_ArgDecl, Puma::CT_NamespaceDef, Puma::CT_NamespaceAliasDef, Puma::CT_UsingDirective, Puma::CT_InitDeclarator, Puma::CT_BracedDeclarator, Puma::CT_ArrayDelimiter, Puma::CT_ArrayDeclarator, Puma::CT_FctDeclarator, Puma::CT_RefDeclarator, Puma::CT_PtrDeclarator, Puma::CT_MembPtrDeclarator, Puma::CT_BitFieldDeclarator, Puma::CT_LabelStmt, Puma::CT_DefaultStmt, Puma::CT_TryStmt, Puma::CT_CaseStmt, Puma::CT_ExprStmt, Puma::CT_DeclStmt, Puma::CT_SwitchStmt, Puma::CT_IfStmt, Puma::CT_IfElseStmt, Puma::CT_BreakStmt, Puma::CT_ContinueStmt, Puma::CT_GotoStmt, Puma::CT_ReturnStmt, Puma::CT_WhileStmt, Puma::CT_DoStmt, Puma::CT_ForStmt, Puma::CT_Condition, Puma::CT_ClassDef, Puma::CT_MembInit, Puma::CT_AccessSpec, Puma::CT_BaseSpec, Puma::CT_AccessDecl, Puma::CT_UsingDecl, Puma::CT_Any, Puma::CT_AnyExtension, Puma::CT_AnyCondition, Puma::CT_GnuAsmSpec, Puma::CT_GnuAsmDef, Puma::CT_GnuAsmOperand, Puma::CT_GnuStatementExpr, Puma::CT_GnuTypeof, Puma::CT_GnuLocalLabelStmt, Puma::CT_GnuCaseStmt, and Puma::CT_AsmBlock.
|
protected |
Get the number of sons in the given sons array.
Skips empty (NULL) array items.
sons | The sons array. |
len | Length of the sons array. |
|
virtual |
Get the first token of the syntactic construct represented by this sub-tree.
Reimplemented in Puma::CT_Token.
|
virtual |
Get the CT_Token node of the first token of the syntactic construct represented by this sub-tree.
Reimplemented in Puma::CT_Token.
|
inlinevirtual |
Get the semantic type of the node.
Reimplemented in Puma::CT_ExprList, Puma::CT_Expression, Puma::CT_String, Puma::CT_SimpleName, Puma::CT_QualName, Puma::CT_DesignatorSeq, Puma::CT_ArgDecl, Puma::CT_ArrayDeclarator, and Puma::CT_GnuTypeof.
|
inlinevirtual |
Get the calculated value of the expression.
Reimplemented in Puma::CT_ExprList, Puma::CT_Expression, Puma::CT_String, Puma::CT_SimpleName, Puma::CT_QualName, Puma::CT_DesignatorSeq, Puma::CT_ArgDecl, Puma::CT_ArrayDeclarator, and Puma::CT_AnyExtension.
|
static |
|
static |