3 #define _SAGEGENERIC_H 1
14 #include <type_traits>
21 #define WITH_BINARY_NODES 0
22 #define WITH_UNTYPED_NODES 0
29 #define SG_UNEXPECTED_NODE(X) (sg::unexpected_node(X, __FILE__, __LINE__))
30 #define SG_DEREF(X) (sg::deref(X, __FILE__, __LINE__))
31 #define SG_ASSERT_TYPE(SAGENODE, N) (sg::assert_sage_type<SAGENODE>(N, __FILE__, __LINE__))
32 #define SG_ERROR_IF(COND, MSG) (sg::report_error_if(COND, MSG, __FILE__, __LINE__))
45 void unused(
const T&) {}
48 template <
class T1,
class T2>
54 template <
class T1,
class T2>
57 typedef const T2 type;
64 template <
class T,
class E>
81 void report_error(std::string desc,
const char* file =
nullptr,
size_t ln = 0);
84 void unexpected_node(
const SgNode& n,
const char* file =
nullptr,
size_t ln = 0);
89 void report_error_if(
bool iserror,
const std::string& desc,
const char* file =
nullptr,
size_t ln = 0)
93 report_error(desc, file, ln);
98 T&
deref(T* ptr,
const char* file = 0,
size_t ln = 0)
100 report_error_if(!ptr,
"assertion failed: null dereference ", file, ln);
116 template <
class _ReturnType>
119 typedef _ReturnType ReturnType;
131 operator ReturnType()
const {
return res; }
142 template <
class SageNode>
144 SageNode& assume_sage_type(
SgNode& n)
146 return static_cast<SageNode&
>(n);
151 template <
class SageNode>
153 const SageNode& assume_sage_type(
const SgNode& n)
155 return static_cast<const SageNode&
>(n);
158 #define GEN_VISIT(X) \
159 void visit(X * n) { rv.handle(*n); }
161 template <
class RoseVisitor>
166 : rv(std::move(rosevisitor))
848 #if WITH_BINARY_NODES
849 GEN_VISIT(SgAsmAarch64AtOperand)
850 GEN_VISIT(SgAsmAarch64BarrierOperand)
851 GEN_VISIT(SgAsmAarch64CImmediateOperand)
852 GEN_VISIT(SgAsmAarch64Instruction)
853 GEN_VISIT(SgAsmAarch64PrefetchOperand)
854 GEN_VISIT(SgAsmAarch64SysMoveOperand)
857 GEN_VISIT(SgAsmBinaryAddPostupdate)
858 GEN_VISIT(SgAsmBinaryAddPreupdate)
869 GEN_VISIT(SgAsmBinarySubtractPostupdate)
870 GEN_VISIT(SgAsmBinarySubtractPreupdate)
876 GEN_VISIT(SgAsmCommonSubExpression)
963 GEN_VISIT(SgAsmElfEHFrameEntryFDList)
983 GEN_VISIT(SgAsmElfSymverDefinedAux)
1159 template <
class RoseVisitor>
1161 typename std::remove_const<typename std::remove_reference<RoseVisitor>::type>::type
1162 _dispatch(RoseVisitor&& rv,
SgNode* n)
1164 typedef typename std::remove_reference<RoseVisitor>::type RoseVisitorNoref;
1165 typedef typename std::remove_const<RoseVisitorNoref>::type RoseHandler;
1170 std::is_lvalue_reference<RoseVisitor>()
1174 return std::move(vis).rv;
1246 template <
class RoseVisitor>
1248 typename std::remove_const<typename std::remove_reference<RoseVisitor>::type>::type
1252 return _dispatch(std::forward<RoseVisitor>(rv), n);
1255 template <
class RoseVisitor>
1257 typename std::remove_const<typename std::remove_reference<RoseVisitor>::type>::type
1261 return _dispatch(std::forward<RoseVisitor>(rv), const_cast<SgNode*>(n));
1273 template <
class SageNode>
1276 void handle(SageNode&) {}
1286 template <
class AncestorNode,
class QualSgNode>
1290 typedef std::pair<AncestorNode*, QualSgNode*> Pair;
1295 : Base(), res(NULL, NULL)
1302 void handle(QualSgNode& n) { res.second = n.get_parent(); }
1303 void handle(AncestorNode& n) { res.first = &n; }
1305 operator Pair()
const {
return res; }
1310 template <
class AncestorNode,
class QualSgNode>
1315 typename AncestorFinder::Pair res(NULL, n.get_parent());
1317 while (res.second != NULL)
1319 res = (
typename AncestorFinder::Pair)
sg::dispatch(AncestorFinder(), res.second);
1336 template <
class AncestorNode>
1339 if (n == NULL)
return NULL;
1341 return _ancestor<AncestorNode>(*n);
1345 template <
class AncestorNode>
1348 if (n == NULL)
return NULL;
1350 return _ancestor<const AncestorNode>(*n);
1354 template <
class AncestorNode>
1357 AncestorNode* res = _ancestor<AncestorNode>(n);
1364 template <
class AncestorNode>
1367 const AncestorNode* res = _ancestor<const AncestorNode>(n);
1374 template <
class SageNode>
1375 struct TypeRecoveryHandler
1377 typedef typename ConstLike<SageNode, SgNode>::type SgBaseNode;
1379 TypeRecoveryHandler(
const char* f = 0,
size_t ln = 0)
1380 : res(NULL), loc(f), loc_ln(ln)
1383 TypeRecoveryHandler(TypeRecoveryHandler&&) =
default;
1384 TypeRecoveryHandler& operator=(TypeRecoveryHandler&&) =
default;
1386 operator SageNode* ()&& {
return res; }
1388 void handle(SgBaseNode& n) { unexpected_node(n, loc, loc_ln); }
1389 void handle(SageNode& n) { res = &n; }
1396 TypeRecoveryHandler() =
delete;
1397 TypeRecoveryHandler(
const TypeRecoveryHandler&) =
delete;
1398 TypeRecoveryHandler& operator=(
const TypeRecoveryHandler&) =
delete;
1410 template <
class SageNode>
1413 return sg::dispatch(TypeRecoveryHandler<SageNode>(f, ln), n);
1416 template <
class SageNode>
1419 return sg::dispatch(TypeRecoveryHandler<const SageNode>(f, ln), n);
1422 template <
class SageNode>
1425 return *
sg::dispatch(TypeRecoveryHandler<SageNode>(f, ln), &n);
1428 template <
class SageNode>
1431 return *
sg::dispatch(TypeRecoveryHandler<const SageNode>(f, ln), &n);
1450 void swap_parent(
void*,
void*) {}
1459 template <
class SageNode,
class SageChild>
1460 void swap_child(SageNode& lhs, SageNode& rhs, SageChild* (SageNode::*getter) ()
const,
void (SageNode::*setter) (SageChild*))
1462 SageChild* lhs_child = (lhs.*getter)();
1463 SageChild* rhs_child = (rhs.*getter)();
1464 ROSE_ASSERT(lhs_child && rhs_child);
1466 (lhs.*setter)(rhs_child);
1467 (rhs.*setter)(lhs_child);
1469 swap_parent(lhs_child, rhs_child);
1475 template <
class SageNode>
1478 typedef void (*TransformHandlerFn)(SageNode*);
1486 void handle(SageNode& n) { fn(&n); }
1488 TransformHandlerFn fn;
1493 template <
class SageNode>
1496 createTraversalFunction(
void (* fn)(SageNode*))
1506 template <
class GVisitor>
1521 GVisitor visitor() {
return gvisitor; }
1537 forAllNodes(F fn,
SgNode* root, AstSimpleProcessing::Order order = postorder)
1541 TraversalClass<F> tt(fn);
1544 tt.traverse(root, order);
1545 return tt.visitor();
1548 template <
class SageNode>
1551 forAllNodes(
void (*fn)(SageNode*),
SgNode* root, AstSimpleProcessing::Order order = postorder)
1553 forAllNodes(createTransformExecutor(fn), root, order);
1556 #if !defined(NDEBUG)
1558 std::string nodeType(
const SgNode& n)
1560 return typeid(n).name();
1564 std::string nodeType(
const SgNode* n)
1566 if (n == NULL)
return "<null>";
1568 return nodeType(*n);
1572 template <
class GVisitor>
1577 : gvisitor(std::move(gv)), parent(p), cnt(0)
1580 void operator()(
SgNode* n)
1587 std::cerr <<
"succ(" << nodeType(parent) <<
", " << cnt <<
") is null" << std::endl;
1592 if (n != NULL) gvisitor =
sg::dispatch(std::move(gvisitor), n);
1595 operator GVisitor()&& {
return std::move(gvisitor); }
1603 template <
class GVisitor>
1606 dispatchHelper(GVisitor gv,
SgNode* parent = NULL)
1611 template <
class GVisitor>
1613 GVisitor traverseChildren(GVisitor gv,
SgNode& n)
1617 return std::for_each(successors.begin(), successors.end(), dispatchHelper(std::move(gv), &n));
1620 template <
class GVisitor>
1622 GVisitor traverseChildren(GVisitor gv,
SgNode* n)
1624 return traverseChildren(gv,
sg::deref(n));
1627 template <
class SageParent,
class SageChild>
1628 void linkParentChild(SageParent& parent, SageChild& child,
void (SageParent::*setter)(SageChild*))
1630 (parent.*setter)(&child);
1631 child.set_parent(&parent);
1637 template <
class SageNode>
1638 typename SageNode::base_node_type&
1641 template <
class SageNode>
1642 const typename SageNode::base_node_type&
1645 template <
class SageNode>
1646 typename SageNode::base_node_type*
1649 template <
class SageNode>
1650 const typename SageNode::base_node_type*
This class represents modifiers for SgDeclaration (declaration statements).
List of pointers to file sections.
This class represents the notion of an initializer for a variable declaration or expression in a func...
This class represents the concept of a scope in C++ (e.g. global scope, fuction scope, etc.).
The GNU symbol version definitions.
This class represents the concept of a C++ template instantiation directive.
This class represents the concept of an instantiation of member function template or a member functio...
This class represents the concept of a class declaration statement. It includes the concept of an ins...
This class represents the concept of a declaration list.
This class represents a boolean value (expression value).
One entry of the ELF symbol version needed table.
This class represents a OLD concept of the structure require for qualified names when they were in th...
This class represents the notion of an n-ary comparison operation. This node is intended for use with...
String associated with a binary file.
Expression that adds two operands.
This class represents the concept of an instantiated class template.
This class represents the notion of an value (expression value).
List of dynamic linking section entries.
This class represents the concept of a C or C++ goto statement.
Contiguous region of a file.
This class represents the concept of the dynamic execution of a string, file, or code object...
This class represents the concept of a C or C++ statement which contains a expression.
JVM ModuleMainClass attribute.
Expression representing a (no-op) unary plus operation.
Base class for references to a machine register.
This class represents the notion of a binary operator. It is derived from a SgExpression because oper...
Expression that performs a right rotate.
Auxiliary info for needed symbol version.
Base class for all binary analysis IR nodes.
This class represents a source file for a project (which may contian many source files and or directo...
List of entries for the ELF symbol version definition table.
This class represents the variable declaration or variable initialization withn a for loop...
One entry of an ELF relocation table.
This class represents the concept of a C++ sequence of catch statements.
This class represents the notion of a unary operator. It is derived from a SgExpression because opera...
This class represents the GNU extension "statement expression" (thus is non-standard C and C++)...
Class for traversing the AST.
This class represents the C++ throw expression (handled as a unary operator).
This class represents the rhs of a variable declaration which includes an optional assignment (e...
Portable Executable Import Section.
This class represents the concept of a C++ using directive.
AncestorNode * _ancestor(QualSgNode &n)
implements the ancestor search
This class represents the base class for all types.
List of binary interpretations.
Base class for machine instructions.
This class represents the concept of a do-while statement.
This class represents a Fortran pointer assignment. It is not some weird compound assignment operator...
This class represents the concept of a class name within the compiler.
This class represents the location of the code associated with the IR node in the original source cod...
This class represents the concept of an enum declaration.
CIL AssemblyProcessor node.
Base class for scalar types.
List of expression nodes.
This class represents the "this" operator (can be applied to any member data).
Expression that performs an arithmetic, sign-bit preserving right shift.
void set_parent(SgNode *parent)
All nodes in the AST contain a reference to a parent node.
This class represents a string type used for SgStringVal IR node.
This class represents the notion of an n-ary boolean operation. This node is intended for use with Py...
Expression that performs a logical, sign-bit non-preserving right shift.
This class represents the concept of a C style extern "C" declaration. But such information (linkage)...
This class represents the notion of a declared variable.
Strings stored in an ELF or PE container.
This class represents the concept of a member function declaration statement.
Expression that returns the remainder when dividing the first operand by the second.
This class represents the concept of a C and C++ case option (used within a switch statement)...
This class represents the concept of a function declaration statement.
Node to hold a list of symbol node pointers.
Base class for ELF file sections.
This class represents the concept of a C Assembler statement (untested).
This class represents the concept of a scope in C++ (e.g. global scope, fuction scope, etc.).
This class represents the notion of an n-ary operator. This node is intended for use with Python...
Expression representing truncation.
Base class for PE sections.
Represents a synthesized function.
This class represents the concept of a C and C++ expression list.
This class represents the "sizeof()" operator (applied to any type).
void swap_child(SageNode &lhs, SageNode &rhs, SageChild *(SageNode::*getter)() const, void(SageNode::*setter)(SageChild *))
swaps children (of equal kind) between two ancestor nodes of the same type
Expression that divides the first operand by the second.
CIL AssemblyRefProcessor node.
Hods a list of symbol version aux entries.
AncestorNode * ancestor(SgNode *n)
finds an ancestor node with a given type
COFF symbol string table.
This class represents the concept of a C++ namespace alias declaration statement. ...
Base class for CIL branch of binary analysis IR nodes.
This class is not used in ROSE, but is intended to represent a list of SgModifierTypes (similar to th...
This class represents the base class of a numbr of IR nodes that don't otherwise fit into the existin...
Entry in an ELF symbol version table.
Base class for string tables.
This class represents a directory within a projects file structure of files and directories.
This class represents the notion of an value (expression value).
Base class for CIL branch of binary analysis IR nodes.
ELF error handling frame entry frame description entry.
This class represents the concept of a C trinary conditional expression (e.g. "test ...
Represents an ELF relocation section.
Base class for CIL branch of binary analysis IR nodes.
This class represents the notion of an expression. Expressions are derived from SgLocatedNodes, since similar to statement, expressions have a concrete location within the user's source code.
One import directory per library.
void visit(SgNode *n)
this method is called at every traversed node.
GNU symbol version requirements table.
List of ELF relocation entries.
This class represents the notion of a break statement (typically used in a switch statment)...
List of AST file node pointers.
This class represents the concept of a name within the compiler.
ELF section containing dynamic linking information.
executes a functor for a specific node type
T & deref(T *ptr, const char *file=0, size_t ln=0)
dereferences an object (= checked dereference in debug mode)
List of ELF EH frame CI entries.
CIL GenericParamConstraint node.
Represents an ELF EH frame section.
One entry of an ELF notes table.
ELF string table section.
This class represents the concept of a class definition in C++.
This class represents strings within the IR nodes.
Reference to memory locations.
projects the constness of T1 on T2
This class is intended to be a wrapper around SgStatements, allowing them to exist in scopes that onl...
An ordered list of registers.
This class represents the concept of a contructor initializer list (used in constructor (member funct...
SageNode::base_node_type & asBaseType(SageNode &n)
returns the same node n upcasted to its base type
Expression represting negation.
List of pointers to other AST nodes.
Expression representing a machine register.
Base class for integer values.
This class represents the concept of a namespace name within the compiler.
This class represents the notion of a typedef declaration.
ELF file section containing symbols.
This class represents the notion of an value (expression value).
This class represents the base class for all IR nodes within Sage III.
List of operands for an instruction.
This class represents the concept of a catch within a try-catch construct used in C++ exception handl...
Base class for dynamically linked library information.
This class represents the notion of an value (expression value).
This class represents the concept of a variable name within the compiler (a shared container for the ...
This class represents a lambda expression.
This class represents the concept of an instantiation of function template.
This class represents the physical disequality (often called pointer disequality) operator for langua...
This class represents the "&" operator (applied to any lvalue).
A single imported object.
This class represents the conversion of an arbitrary expression to a string. This node is intended fo...
Represents one PowerPC machine instruction.
One entry from an ELF symbol version definition table.
Represents a single ELF symbol.
This class represents the base class of a number of IR nodes define modifiers within the C++ grammar...
This class represents the concept of a block (not a basic block from control flow analysis)...
This class represents the concept of a C++ namespace declaration.
This class represents a list display.
Base class for strings related to binary specimens.
This class represents the notion of a statement.
This class represents the concept of a namespace definition.
This class represents the concept of a for loop.
CIL MethodSemantics node.
Represents static data in an executable.
This class represents the physical equality (often called pointer equality) operator for languages th...
Base class for unary expressions.
Represents one Intel x86 machine instruction.
This class represents the concept of a C++ using declaration.
Base class for CIL branch of binary analysis IR nodes.
This class represents a C99 complex type.
Base class for statement-like subclasses.
This class represents a tuple display.
This class represents a type for all functions.
This class represents the concept of a namespace definition.
This class represents the numeric negation of a value. Not to be confused with SgSubtractOp.
This class represents the concept of a C Assembler statement (untested).
Represents one entry of a segment table.
This class represents the concept of a C or C++ default case within a switch statement.
Expression representing sign extending.
Base class for expressions.
This namespace contains template functions that operate on the ROSE AST.
This class represents a default type used for some IR nodes (see below).
This class represents the concept of an "if" construct.
virtual std::vector< SgNode * > get_traversalSuccessorContainer()
container of pointers to AST successor nodes used in the traversal overridden in every class by gener...
This class represents the concept of a template declaration.
Expression that performs a logical left shift operation.
List of pointers to other nodes.
This class represents the notion of an expression or statement which has a position within the source...
Expression that multiplies two operands.
This class represents template argument within the use of a template to build an instantiation.
Expression that performs a logical left shift operation filling low-order bits with one...
This class represents the variable refernece in expressions.
Represents one MIPS machine instruction.
Node to hold list of ELF note entries.
This class represents the concept of a do-while statement.
CIL CustomAttribute node.
This class represents a OLD concept of the structure require for qualified names when they were in th...
List of entries from a symbol version table.
List of SgAsmPERVASizePair AST nodes.
Expression representing unsigned extending.
Base class for binary types.
This class represents the definition (initialization) of a variable.
This class represents the concept of a class definition in C++.
This class represents the concept of a C++ call to the delete operator.
virtual void accept(ROSE_VisitorPattern &visitor)
support for the classic visitor pattern done in GoF
helper class for _ancestor
Registers accessed indirectly.
This class represents the concept of a C++ call to the new operator.
This class represents the concept of a C or C++ continue statement.
This class represents an object used to initialize the unparsing.
CIL ManifestResource node.
This class represents the member function being called and must be assembled in the SgFunctionCall wi...
This class represents modifiers specific to storage.
This class represents the symbol tables used in both SgScopeStatement and the SgFunctionTypeSymbolTab...
Expression that subtracts the second operand from the first.
SgNode * get_parent() const
Access function for parent node.
This class represents the function being called and must be assembled in the SgFunctionCall with the ...
std::remove_const< typename std::remove_reference< RoseVisitor >::type >::type dispatch(RoseVisitor &&rv, SgNode *n)
uncovers the type of SgNode and passes it to an function "handle" in RoseVisitor. ...
This class represents the concept of try statement within the try-catch support for exception handlin...
Base class for synthesized declarations.
This class represents the concept of a C Assembler statement.
This class represents the concept of a name and a type. It may be renamed in the future to SgTypeSymb...
This class represents a list of associated typedefs for the SgType IR nodes which reference this list...
One entry from the dynamic linking table.
This class represents a source project, with a list of SgFile objects and global information about th...
This class represents the concept of a 'global' stmt in Python.
This class represents the function type table (stores all function types so that they can be shared i...
This class represents a C99 complex type.
This class represents the concept of a C or C++ variable declaration.
This class represents the notion of an initializer for a variable declaration or expression in a func...
The ELF symbol version table.
Represents one entry in an ELF section table.
Represents an ELF segment table.
Strings stored in an ELF or PE container.
Represents an ELF section table.
SageNode * assert_sage_type(SgNode *n, const char *f=0, size_t ln=0)
asserts that n has type SageNode
A list of imported items.
Represents an interpretation of a binary container.
This class represents the concept of a C or C++ label statement.
List of symbol version needed entries.
This class is part of the older CC++ concept. It is not a part of C or C++ (this IR node is not used ...
This class represents the concept of a C++ function call (which is an expression).
Base class for binary files.
Base class for binary expressions.
Declaration-like nodes that encapsulate multiple instructions.
Base class for vector types.
This class was part of CC++ support from a long time ago.
Base class for constants.
List of symbol version aux entries.
This class represents the concept of a declaration statement.
List of SgAsmInstruction nodes.
This class represents the concept of a generic call expression.
This class represents the concept of a switch.
This class represents the concept of a C++ expression built from a class name.
Static representation of instruction semantics.
A list of PE Import Directories.
ELF error handling frame entry, common information entry.