Skip to content

AstInterface

provides an abstract interface to access/modify AST nodes.

Synopsis

Declared in <src/midend/astUtil/astInterface/AstInterface.h>

class AstInterface;

Types

Name
CopyScope

Type Aliases

Name
Ast
AstList
AstNodeList
AstNodePtr
AstTypeList
CopyBindings

Enums

Name
OperatorEnum
TraversalOrderType
TraversalVisitType

Member Functions

Name Description
AstInterface
AstInterface(AstInterfaceImpl* __impl); [constructor]
Construct from AstInterfaceImpl
~AstInterface
~AstInterface(); [destructor]
Destructor
AttachObserver
void AttachObserver(AstObserver* ob);
BlockAppendStmt
void BlockAppendStmt( AstNodePtr& b, AstNodePtr const& s, bool flatten_s = false);
BlockPrependStmt
void BlockPrependStmt( AstNodePtr& b, AstNodePtr const& s);
CopyAstTree
AstNodePtr CopyAstTree( AstNodePtr const& n, CopyBindings* copies = nullptr);
CopyNewVarDecls
void CopyNewVarDecls(AstNodePtr const& nblock);
CreateAllocateArray
AstNodePtr CreateAllocateArray( AstNodePtr const& arr, AstNodeType const& elemtype, AstList const& indexsize);
CreateAssignment
AstNodePtr CreateAssignment( AstNodePtr const& lhs, AstNodePtr const& rhs);
CreateBinaryOP
AstNodePtr CreateBinaryOP( OperatorEnum op, AstNodePtr const& a0, AstNodePtr const& a2);
CreateBlock
AstNodePtr CreateBlock(AstNodePtr const& orig = AST_NULL);
CreateConstant
AstNodePtr CreateConstant( std::string const& valtype, std::string const& val);
CreateDeleteArray
AstNodePtr CreateDeleteArray(AstNodePtr const& arr);
CreateFieldRef
AstNodePtr CreateFieldRef( std::string name1, std::string name2);
CreateFunctionCall
AstNodePtr CreateFunctionCall( AstNodePtr const& func, AstList::const_iterator args_begin, AstList::const_iterator args_end);
CreateIf
AstNodePtr CreateIf( AstNodePtr const& __cond, AstNodePtr const& __if_stmt, AstNodePtr const& __else_stmt = AST_NULL) const;
Creates if-else-statement, or if-statement (if __else_stmt is null).
CreateLoop
AstNodePtr CreateLoop( AstNodePtr const& ivar, AstNodePtr const& lb, AstNodePtr const& ub, AstNodePtr const& step, AstNodePtr const& stmts, bool negativeStep);
CreateMethodRef
AstNodePtr CreateMethodRef( std::string classname, std::string fieldname, bool createIfNotFound);
CreateUnaryOP
AstNodePtr CreateUnaryOP( OperatorEnum op, AstNodePtr const& arg);
CreateVarRef
AstNodePtr CreateVarRef( std::string varname, AstNodePtr const& declLoc = AST_NULL);
DetachObserver
void DetachObserver(AstObserver* ob);
FreeAstTree
void FreeAstTree(AstNodePtr const& n);
GetArrayBound
bool GetArrayBound( AstNodePtr const& arrayname, int dim, int& lb, int& ub);
GetArrayType
AstNodeType GetArrayType( AstNodeType const& base, AstList const& indexsize);
GetCopySource
AstNodePtr GetCopySource(AstNodePtr const& n) const;
GetFunctionCallSideEffect
bool GetFunctionCallSideEffect( AstNodePtr const& fc, CollectObject<AstNodePtr>& collectmod, CollectObject<AstNodePtr>& collectread);
GetFunctionDefinition
AstNodePtr GetFunctionDefinition( AstNodePtr const& n, std::string* name = 0);
GetNextStmt
AstNodePtr GetNextStmt(AstNodePtr const& s);
GetParent
AstNodePtr GetParent(AstNodePtr const& n);
GetParentBlock
AstNodePtr GetParentBlock(AstNodePtr const& __n);
Returns the enclosing block.
GetParentStatement
AstNodePtr GetParentStatement(AstNodePtr const& __n);
Returns the enclosing statement.
GetPointerType
AstNodeType GetPointerType(AstNodeType const& base);
GetPrevStmt
AstNodePtr GetPrevStmt(AstNodePtr const& s);
GetRoot
AstNodePtr GetRoot() const;
GetType
AstNodeType GetType(std::string const& name);
InsertAnnot
void InsertAnnot( AstNodePtr const& n, std::string const& annot, bool before = true);
InsertStmt
void InsertStmt( AstNodePtr const& orig, AstNodePtr const& n, bool before = true, bool extractFromBlock = false);
IsAliasingDecl
bool IsAliasingDecl( AstNodePtr const& exp, AstList* vars = 0, AstList* aliases = 0);
Check if exp declares a set of variables to be aliased to non-local storages, represented by the returned global_signatures.
IsBinaryOp
bool IsBinaryOp( AstNodePtr const& exp, OperatorEnum* opr = 0, AstNodePtr* opd1 = 0, AstNodePtr* opd2 = 0);
IsCompatibleType
bool IsCompatibleType( AstNodeType const& t1, AstNodeType const& t2);
IsConstInt
bool IsConstInt( AstNodePtr const& exp, int* value = 0);
IsConstant
bool IsConstant( AstNodePtr const& exp, std::string* valtype = 0, std::string* value = 0);
Check whether (exp) is a constant value of type int, float, string, etc.
IsDecls
bool IsDecls(AstNodePtr const& s);
IsExecutableStmt
bool IsExecutableStmt(AstNodePtr const& s);
IsFunctionCall
bool IsFunctionCall( AstNodePtr const& s, AstNodePtr* f = 0, AstList* args = 0, AstList* outargs = 0, AstTypeList* paramtypes = 0, AstNodeType* returntype = 0);
Returns true iff s is a function call, false otherwise. But also attempts to extract a bunch of info about the call.
IsFunctionType
bool IsFunctionType( AstNodeType const& t, AstTypeList* paramtypes = 0);
IsGoto
bool IsGoto( AstNodePtr const& s, AstNodePtr* dest = 0);
Check whether (s) is a jump (goto, return, continue, break, etc) stmt; if yes, grab the jump destination in 'dest'
IsGotoAfter
bool IsGotoAfter(AstNodePtr const& s);
IsGotoBefore
bool IsGotoBefore(AstNodePtr const& s);
IsLabelStatement
bool IsLabelStatement(AstNodePtr const& s);
IsMax
bool IsMax(AstNodePtr const& exp);
IsMin
bool IsMin(AstNodePtr const& exp);
IsPointerType
bool IsPointerType(AstNodeType const& t);
IsPostTestLoop
bool IsPostTestLoop(AstNodePtr const& s);
IsScalarType
bool IsScalarType(AstNodeType const& t);
IsUnaryOp
bool IsUnaryOp( AstNodePtr const& exp, OperatorEnum* op = 0, AstNodePtr* opd = 0);
NewVar
std::string NewVar( AstNodeType const& t, std::string const& name = "", bool makeunique = false, bool delayInsert = true, AstNodePtr const& declLoc = AST_NULL, AstNodePtr const& init = AST_NULL, AstNodePtr* createdSymbol = nullptr);
RemoveStmt
bool RemoveStmt(AstNodePtr const& n);
ReplaceAst
bool ReplaceAst( AstNodePtr const& orig, AstNodePtr const& n);
SetParent
void SetParent( AstNodePtr const& n, AstNodePtr const& p);
SetRoot
void SetRoot(AstNodePtr const& root);
getNULL
AstNodePtr getNULL() const;
get_fileInfo
bool get_fileInfo( AstNodePtr const& n, std::string* fname = 0, int* lineno = 0);
get_impl
AstInterfaceImpl* get_impl();

Static Member Functions

Name Description
AstToString
static std::string AstToString( AstNodePtr const& s, bool unparseClassName = true);
AstTypeToString
static std::string AstTypeToString(AstNodePtr const& s);
Output the type of the AstNodePtr.
CreateArrayAccess
static AstNodePtr CreateArrayAccess( AstNodePtr const& arr, AstNodePtr const& index);
CreateConstInt
static AstNodePtr CreateConstInt(int val);
GetBaseType
static AstNodeType GetBaseType(AstNodeType const& t1);
GetBaseTypeName
static std::string GetBaseTypeName(AstNodeType const& t);
GetBlockStmtList
static AstList GetBlockStmtList(AstNodePtr const& n);
GetChildrenList
static AstList GetChildrenList(AstNodePtr const& n);
GetExpressionType
static AstNodeType GetExpressionType(AstNodePtr const& s);
GetFunctionDefinitionFromDeclaration
static AstNodePtr GetFunctionDefinitionFromDeclaration(AstNodePtr const& decl);
GetGlobalUniqueName
static std::string GetGlobalUniqueName( AstNodePtr const& exp, std::string expname, bool do_not_add_file_name = false);
GetRuntimeDeclarationCondition
static AstNodePtr GetRuntimeDeclarationCondition(AstNodePtr const& s);
GetScopeName
static std::string GetScopeName(AstNodePtr const& scope);
GetTypeInfo
static void GetTypeInfo( AstNodeType const& t, std::string* name = 0, std::string* stripname = 0, bool use_global_unique_name = false);
GetTypeName
static std::string GetTypeName(AstNodeType const& t);
GetVarName
static std::string GetVarName( AstNodePtr const& exp, bool use_global_unique_name = false);
GetVariableSignature
static std::string GetVariableSignature(AstNodePtr const& variable);
Returns a string that uniquely identifies the given variable.
IsAddressOfOp
static bool IsAddressOfOp( AstNodePtr const& _s, AstNodePtr* ref = 0);
IsArrayAccess
static bool IsArrayAccess( AstNodePtr const& s, AstNodePtr* array = 0, AstList* index = 0);
IsAssignment
static bool IsAssignment( AstNodePtr const& s, AstNodePtr* lhs = 0, AstNodePtr* rhs = 0, bool* readlhs = 0);
IsBlock
static bool IsBlock(AstNodePtr const& exp);
IsExprStmt
static bool IsExprStmt( AstNodePtr const& n, AstNodePtr* exp = 0);
IsExpression
static bool IsExpression( AstNodePtr const& s, AstNodeType* exptype = 0, AstNodePtr* strip_exp = 0);
IsFortranLoop
static bool IsFortranLoop( AstNodePtr const& s, AstNodePtr* ivar = 0, AstNodePtr* lb = 0, AstNodePtr* ub = 0, AstNodePtr* step = 0, AstNodePtr* body = 0);
Check whether (s) is a Fortran-style loop in the form: for (ivar=lb;ivar<=ub;ivar+=step)
IsFunctionDefinition
static bool IsFunctionDefinition( AstNodePtr const& s, std::string* name = 0, AstList* params = 0, AstList* outpars = 0, AstNodePtr* body = 0, AstTypeList* paramtypes = 0, AstNodeType* returntype = 0, bool use_global_unique_name = false, bool skip_function_declaration = false);
IsIf
static bool IsIf( AstNodePtr const& s, AstNodePtr* cond = 0, AstNodePtr* truebody = 0, AstNodePtr* falsebody = 0);
IsIfWithKnownRuntimeBranch
static bool IsIfWithKnownRuntimeBranch( AstNodePtr const& s, AstNodePtr* body = nullptr, AstNodePtr* condition = nullptr);
IsLocalRef
static bool IsLocalRef( AstNodePtr const& ref, AstNodePtr const& scope, bool* has_ptr_deref = 0);
Returns whether the given ref reaches only local data within scope. if has_ptr_deref != 0, it is set to true if ref has pointer deref.
IsLoop
static bool IsLoop( AstNodePtr const& s, AstNodePtr* init = 0, AstNodePtr* cond = 0, AstNodePtr* incr = 0, AstNodePtr* body = 0);
IsMemoryAccess
static bool IsMemoryAccess( AstNodePtr const& s, AstNodeList* subrefs = 0);
IsMemoryAllocation
static bool IsMemoryAllocation( AstNodePtr const& s, AstNodeType* allocType = 0, AstNodePtr* init = 0, AstNodeList* dest = 0);
IsMemoryFree
static bool IsMemoryFree( AstNodePtr const& s, AstNodeType* freedType = 0, AstNodePtr* freedVariable = 0);
IsReturn
static bool IsReturn( AstNodePtr const& s, AstNodePtr* val = 0);
IsSameVarRef
static bool IsSameVarRef( AstNodePtr const& v1, AstNodePtr const& v2);
IsStatement
static bool IsStatement(AstNodePtr const& s);
IsVarRef
static bool IsVarRef( AstNodePtr const& exp, AstNodeType* vartype = 0, std::string* varname = 0, AstNodePtr* scope = 0, bool* defined_in_global = 0, bool use_global_unique_name = false, bool* has_ptr_deref = 0);
Check whether (exp) is a variable reference; If yes, return type, name, scope, and global/local etc.
IsVariableDecl
static bool IsVariableDecl( AstNodePtr const& exp, AstList* vars = 0, AstList* inits = 0);
SetFunctionNameMangling
static void SetFunctionNameMangling(std::function<std::string(SgFunctionDeclaration const*)> f);
SkipCasting
static SgNode* SkipCasting(SgNode* exp);
If there is a case, extract the operand and return it, otherwise return exp
getAstLocation
static std::string getAstLocation(AstNodePtr const& s);
toString
static std::string toString(OperatorEnum op);
unparseToString
static std::string unparseToString(AstNodePtr const& s);

Protected Data Members

Name
impl

Private Data Members

Name
copyScope

Derived Classes

Name Description
CPPAstInterface

Created with MrDocs