3 #define _SAGEGENERIC_H 1
16 #if __cplusplus >= 201103L
17 #include <type_traits>
27 #define WITH_BINARY_NODES 0
28 #define WITH_UNTYPED_NODES 0
35 #define SG_UNEXPECTED_NODE(X) (sg::unexpected_node(X, __FILE__, __LINE__))
36 #define SG_DEREF(X) (sg::deref(X, __FILE__, __LINE__))
37 #define SG_ASSERT_TYPE(SAGENODE, N) (sg::assert_sage_type<SAGENODE>(N, __FILE__, __LINE__))
38 #define SG_ERROR_IF(COND, MSG) (sg::report_error_if(COND, MSG, __FILE__, __LINE__))
49 void unused(
const T&) {}
52 template <
class T1,
class T2>
58 template <
class T1,
class T2>
61 typedef const T2 type;
68 template <
class T,
class E>
83 void report_error(std::string desc,
const char* file = 0,
size_t ln = 0)
87 const std::string at(
" at ");
88 const std::string sep(
" : ");
89 const std::string num(conv<std::string>(ln));
91 desc = desc + at + file + sep + num;
94 std::cerr << desc << std::endl;
95 throw std::logic_error(desc);
99 void report_error_if(
bool iserror,
const std::string& desc,
const char* file = 0,
size_t ln = 0)
101 if (!iserror)
return;
103 report_error(desc, file, ln);
108 T& deref(T* ptr,
const char* file = 0,
size_t ln = 0)
110 report_error_if(!ptr,
"null dereference ", file, ln);
115 void unexpected_node(
const SgNode& n,
const char* file = 0,
size_t ln = 0)
117 static const std::string msg =
"unexpected node-type: ";
119 report_error(msg +
typeid(n).name(), file, ln);
132 template <
class _ReturnType>
135 typedef _ReturnType ReturnType;
147 operator ReturnType()
const {
return res; }
158 template <
class SageNode>
160 SageNode& assume_sage_type(
SgNode& n)
162 return static_cast<SageNode&
>(n);
167 template <
class SageNode>
169 const SageNode& assume_sage_type(
const SgNode& n)
171 return static_cast<const SageNode&
>(n);
174 #define GEN_VISIT(X) \
175 void visit(X * n) { rv.handle(*n); }
177 template <
class RoseVisitor>
181 #if __cplusplus >= 201103L
184 : rv(std::move(rosevisitor))
245 #if WITH_BINARY_NODES
246 GEN_VISIT(SgAsmA64AtOperand)
247 GEN_VISIT(SgAsmA64BarrierOperand)
248 GEN_VISIT(SgAsmA64CImmediateOperand)
249 GEN_VISIT(SgAsmA64Instruction)
250 GEN_VISIT(SgAsmA64PrefetchOperand)
251 GEN_VISIT(SgAsmA64SysMoveOperand)
273 GEN_VISIT(SgAsmCommonSubExpression)
360 GEN_VISIT(SgAsmElfEHFrameEntryFDList)
380 GEN_VISIT(SgAsmElfSymverDefinedAux)
410 GEN_VISIT(SgAsmGenericStrtab)
1074 #if WITH_BINARY_NODES
1096 #if __cplusplus >= 201103L
1097 template <
class RoseVisitor>
1099 typename std::remove_const<typename std::remove_reference<RoseVisitor>::type>::type
1100 _dispatch(RoseVisitor&& rv,
SgNode* n)
1102 typedef typename std::remove_reference<RoseVisitor>::type RoseVisitorNoref;
1103 typedef typename std::remove_const<RoseVisitorNoref>::type RoseHandler;
1108 std::is_lvalue_reference<RoseVisitor>()
1112 return std::move(vis).rv;
1115 template <
class RoseVisitor>
1118 _dispatch(
const RoseVisitor& rv,
SgNode* n)
1122 VisitDispatcher<RoseVisitor> vis(rv);
1198 #if __cplusplus >= 201103L
1199 template <
class RoseVisitor>
1201 typename std::remove_const<typename std::remove_reference<RoseVisitor>::type>::type
1202 dispatch(RoseVisitor&& rv,
SgNode* n)
1205 return _dispatch(std::forward<RoseVisitor>(rv), n);
1208 template <
class RoseVisitor>
1210 typename std::remove_const<typename std::remove_reference<RoseVisitor>::type>::type
1211 dispatch(RoseVisitor&& rv,
const SgNode* n)
1214 return _dispatch(std::forward<RoseVisitor>(rv), const_cast<SgNode*>(n));
1217 template <
class RoseVisitor>
1220 dispatch(
const RoseVisitor& rv,
SgNode* n)
1222 return _dispatch(rv, n);
1226 template <
class RoseVisitor>
1229 dispatch(
const RoseVisitor& rv,
const SgNode* n)
1231 return _dispatch(rv, const_cast<SgNode*>(n));
1244 template <
class SageNode>
1247 void handle(SageNode&) {}
1257 template <
class AncestorNode,
class QualSgNode>
1261 typedef std::pair<AncestorNode*, QualSgNode*> Pair;
1266 : Base(), res(NULL, NULL)
1273 void handle(QualSgNode& n) { res.second = n.get_parent(); }
1274 void handle(AncestorNode& n) { res.first = &n; }
1276 operator Pair()
const {
return res; }
1281 template <
class AncestorNode,
class QualSgNode>
1282 AncestorNode* _ancestor(QualSgNode& n)
1286 typename AncestorFinder::Pair res(NULL, n.get_parent());
1288 while (res.second != NULL)
1290 res = (
typename AncestorFinder::Pair) sg::dispatch(AncestorFinder(), res.second);
1307 template <
class AncestorNode>
1308 AncestorNode* ancestor(
SgNode* n)
1310 if (n == NULL)
return NULL;
1312 return _ancestor<AncestorNode>(*n);
1316 template <
class AncestorNode>
1317 const AncestorNode* ancestor(
const SgNode* n)
1319 if (n == NULL)
return NULL;
1321 return _ancestor<const AncestorNode>(*n);
1325 template <
class AncestorNode>
1326 AncestorNode& ancestor(
SgNode& n)
1328 AncestorNode* res = _ancestor<AncestorNode>(n);
1335 template <
class AncestorNode>
1336 const AncestorNode& ancestor(
const SgNode& n)
1338 const AncestorNode* res = _ancestor<const AncestorNode>(n);
1345 template <
class SageNode>
1346 struct TypeRecoveryHandler
1348 typedef typename ConstLike<SageNode, SgNode>::type SgBaseNode;
1350 TypeRecoveryHandler(
const char* f = 0,
size_t ln = 0)
1351 : res(NULL), loc(f), loc_ln(ln)
1354 #if __cplusplus >= 201103L
1355 TypeRecoveryHandler(TypeRecoveryHandler&&) =
default;
1357 TypeRecoveryHandler() =
delete;
1358 TypeRecoveryHandler(
const TypeRecoveryHandler&) =
delete;
1359 TypeRecoveryHandler& operator=(
const TypeRecoveryHandler&) =
delete;
1360 TypeRecoveryHandler& operator=(TypeRecoveryHandler&&) =
delete;
1362 operator SageNode* ()&& {
return res; }
1364 operator SageNode* () {
return res; }
1367 void handle(SgBaseNode& n) { unexpected_node(n, loc, loc_ln); }
1368 void handle(SageNode& n) { res = &n; }
1384 template <
class SageNode>
1385 SageNode* assert_sage_type(
SgNode* n,
const char* f = 0,
size_t ln = 0)
1387 return sg::dispatch(TypeRecoveryHandler<SageNode>(f, ln), n);
1390 template <
class SageNode>
1391 const SageNode* assert_sage_type(
const SgNode* n,
const char* f = 0,
size_t ln = 0)
1393 return sg::dispatch(TypeRecoveryHandler<const SageNode>(f, ln), n);
1396 template <
class SageNode>
1397 SageNode& assert_sage_type(
SgNode& n,
const char* f = 0,
size_t ln = 0)
1399 return *sg::dispatch(TypeRecoveryHandler<SageNode>(f, ln), &n);
1402 template <
class SageNode>
1403 const SageNode& assert_sage_type(
const SgNode& n,
const char* f = 0,
size_t ln = 0)
1405 return *sg::dispatch(TypeRecoveryHandler<const SageNode>(f, ln), &n);
1424 void swap_parent(
void*,
void*) {}
1433 template <
class SageNode,
class SageChild>
1434 void swap_child(SageNode& lhs, SageNode& rhs, SageChild* (SageNode::*getter) ()
const,
void (SageNode::*setter) (SageChild*))
1436 SageChild* lhs_child = (lhs.*getter)();
1437 SageChild* rhs_child = (rhs.*getter)();
1438 ROSE_ASSERT(lhs_child && rhs_child);
1440 (lhs.*setter)(rhs_child);
1441 (rhs.*setter)(lhs_child);
1443 swap_parent(lhs_child, rhs_child);
1449 template <
class SageNode>
1452 typedef void (*TransformHandlerFn)(SageNode*);
1460 void handle(SageNode& n) { fn(&n); }
1462 TransformHandlerFn fn;
1467 template <
class SageNode>
1470 createTraversalFunction(
void (* fn)(SageNode*))
1480 template <
class GVisitor>
1491 gvisitor = sg::dispatch(gvisitor, n);
1495 GVisitor visitor() {
return gvisitor; }
1511 forAllNodes(F fn,
SgNode* root, AstSimpleProcessing::Order order = postorder)
1515 TraversalClass<F> tt(fn);
1518 tt.traverse(root, order);
1519 return tt.visitor();
1522 template <
class SageNode>
1525 forAllNodes(
void (*fn)(SageNode*),
SgNode* root, AstSimpleProcessing::Order order = postorder)
1527 forAllNodes(createTransformExecutor(fn), root, order);
1530 #if !defined(NDEBUG)
1532 std::string nodeType(
const SgNode& n)
1534 return typeid(n).name();
1538 std::string nodeType(
const SgNode* n)
1540 if (n == NULL)
return "<null>";
1542 return nodeType(*n);
1546 template <
class GVisitor>
1549 #if __cplusplus >= 201103L
1552 : gvisitor(std::move(gv)), parent(p), cnt(0)
1557 : gvisitor(gv), parent(p), cnt(0)
1561 void operator()(
SgNode* n)
1568 std::cerr <<
"succ(" << nodeType(parent) <<
", " << cnt <<
") is null" << std::endl;
1573 #if __cplusplus >= 201103L
1574 if (n != NULL) gvisitor = sg::dispatch(std::move(gvisitor), n);
1576 if (n != NULL) gvisitor = sg::dispatch(gvisitor, n);
1580 #if __cplusplus >= 201103L
1581 operator GVisitor()&& {
return std::move(gvisitor); }
1583 operator GVisitor() {
return gvisitor; }
1592 template <
class GVisitor>
1595 dispatchHelper(GVisitor gv,
SgNode* parent = NULL)
1597 #if __cplusplus >= 201103L
1605 template <
class GVisitor>
1607 GVisitor traverseChildren(GVisitor gv,
SgNode& n)
1611 #if __cplusplus >= 201103L
1612 return std::for_each(successors.begin(), successors.end(), dispatchHelper(std::move(gv), &n));
1614 return std::for_each(successors.begin(), successors.end(), dispatchHelper(gv, &n));
1618 template <
class GVisitor>
1620 GVisitor traverseChildren(GVisitor gv,
SgNode* n)
1622 return traverseChildren(gv, sg::deref(n));
1625 template <
class SageParent,
class SageChild>
1626 void linkParentChild(SageParent& parent, SageChild& child,
void (SageParent::*setter)(SageChild*))
1628 (parent.*setter)(&child);
1629 child.set_parent(&parent);
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).
This class represents the concept of a C or C++ goto statement.
List of dynamic linking section entries.
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.
Expression that performs a post-increment operation.
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).
Expression that performs a post-decrement operation.
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.
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.
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).
Expression that divides the first operand by the second.
Hods a list of symbol version aux entries.
COFF symbol string table.
This class represents the concept of a C++ namespace alias declaration statement. ...
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.
This class represents a directory within a projects file structure of files and directories.
This class represents the notion of an value (expression value).
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.
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
List of ELF EH frame CI entries.
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...
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.
Expression that performs a pre-decrement operation.
This class represents the physical disequality (often called pointer disequality) operator for langua...
Expression that performs a pre-increment operation.
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.
This class represents the notion of a statement.
Base class for strings related to binary specimens.
This class represents the concept of a namespace definition.
This class represents the concept of a for loop.
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.
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 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.
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.
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 ...
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.
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.
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.