5#include <Cxx_GrammarDeclarations.h>
27#include <ROSE_DEPRECATED.h>
29#include <rosePublicConfig.h>
32#include <boost/format.hpp>
33#include <boost/serialization/access.hpp>
34#include <boost/serialization/base_object.hpp>
35#include <boost/serialization/map.hpp>
36#include <boost/serialization/set.hpp>
37#include <boost/serialization/vector.hpp>
38#include <boost/serialization/version.hpp>
39#include <Sawyer/CommandLine.h>
40#include <Sawyer/Interval.h>
41#include <Sawyer/IntervalSet.h>
43#include "processSupport.h"
44#define __builtin_constant_p(exp) (0)
46#ifdef ROSE_ENABLE_BINARY_ANALYSIS
47#include <Rose/BinaryAnalysis/AddressSet.h>
48#include <Rose/BinaryAnalysis/RelativeVirtualAddress.h>
49#include <Rose/BinaryAnalysis/AddressInterval.h>
50#include <Rose/BinaryAnalysis/AddressIntervalSet.h>
51#include <rose_extent.h>
52#include <Rose/BinaryAnalysis/RegisterDescriptor.h>
53#include <Rose/BinaryAnalysis/InstructionMap.h>
54#include <ROSE_NELMTS.h>
57#include <Rose/Constants.h>
59#include <sageTraversal.h>
62#include <sageMemory.h>
63#include <Cxx_GrammarVariants.h>
64#include <Cxx_GrammarStorageClasses.h>
65#include <virtualCFG.h>
67namespace Rose {
namespace Traits {
namespace generated {
template <
typename NodeT>
struct describe_node_t; } } }
68namespace Rose {
namespace Traits {
namespace generated {
template <
typename NodeT,
typename FieldT, FieldT NodeT::* fld_ptr>
struct describe_field_t; } } }
70#ifdef ROSE_ENABLE_BINARY_ANALYSIS
83class UnparseFormatHelp;
86class AstSpecificDataManagingClassStorageClass;
127 enum { static_variant = V_SgNode };
142 static const unsigned pool_size;
144 static std::vector<unsigned char *> pools;
146 static SgNode * next_node;
149 static unsigned long initializeStorageClassArray(SgNodeStorageClass *);
152 static void clearMemoryPool();
153 static void deleteMemoryPool();
156 static void extendMemoryPoolForFileIO();
159 static SgNode * getPointerFromGlobalIndex(
unsigned long);
161 static SgNode * getPointerFromGlobalIndex(AstSpecificDataManagingClass *,
unsigned long);
164 static unsigned long getNumberOfValidNodesAndSetGlobalIndexInFreepointer(
unsigned long);
166 static void resetValidFreepointers();
168 static unsigned long getNumberOfLastValidPointer();
171#if defined(INLINE_FUNCTIONS)
173 inline void *
operator new (
size_t size);
176 void *
operator new (
size_t size);
179 void operator delete (
void* pointer,
size_t size);
182 void operator delete (
void* pointer)
185 SgNode::operator
delete (pointer,
sizeof(
SgNode));
228#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
251 virtual int variant() const ROSE_DEPRECATED_FUNCTION;
306 static std::string getNodeIdStringInternal(
SgNode* sgnode);
433 friend class SgNodeStorageClass;
436 friend class AstSpecificDataManagingClass;
439 friend class AstSpecificDataManagingClassStorageClass;
442 SgNode(
const SgNodeStorageClass& source );
471#define BUILD_ATERM_SUPPORT 0
472 #if BUILD_ATERM_SUPPORT
473 #ifdef ROSE_USE_ROSE_ATERM_SUPPORT
485 virtual ATerm generate_ATerm();
488 virtual void generate_ATerm_Annotation(ATerm & term);
539 void set_containsTransformationRelativeToNodeFile(
bool containsTransformationRelativeToNodeFile );
545 bool get_containsTransformationRelativeToNodeFile()
const;
569 std::string unparseToString()
const;
586 int variant() const ROSE_DEPRECATED_FUNCTION {
return (
int)this->variantT();}
589 static std::vector<VariantT> getClassHierarchySubTreeFunction( VariantT v);
590 static void getClassHierarchySubTreeFunction( VariantT v, std::vector<VariantT>&);
603 void set_isVisited (
bool isVisited ) ROSE_DEPRECATED_FUNCTION;
609 static std::map<
SgNode*,std::
string> & get_globalMangledNameMap();
613 static
void clearGlobalMangledNameMap();
620 static std::map<std::
string, uint64_t> & get_shortMangledNameCache();
628 static std::map<
SgNode*,std::
string> & get_globalQualifiedNameMapForNames();
635 static
void set_globalQualifiedNameMapForNames ( const std::map<
SgNode*,std::
string> & X );
643 static std::map<
SgNode*,std::
string> & get_globalQualifiedNameMapForTypes();
651 static
void set_globalQualifiedNameMapForTypes ( const std::map<
SgNode*,std::
string> & X );
660 static std::map<
SgNode*,std::map<
SgNode*,std::
string> > & get_globalQualifiedNameMapForMapsOfTypes();
669 static
void set_globalQualifiedNameMapForMapsOfTypes ( const std::map<
SgNode*,std::map<
SgNode*,std::
string> > & X );
680 static std::map<
SgNode*,std::
string> & get_globalQualifiedNameMapForTemplateHeaders();
686 static
void set_globalQualifiedNameMapForTemplateHeaders ( const std::map<
SgNode*,std::
string> & X );
694 static std::map<
SgNode*,std::
string> & get_globalTypeNameMap();
701 static
void set_globalTypeNameMap ( const std::map<
SgNode*,std::
string> & X );
732 virtual
void removeAttribute(std::
string s);
734 virtual
bool attributeExists(std::
string s) const;
736 virtual
int numberOfAttributes() const;
809#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
816#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
838 virtual std::vector<VirtualCFG::CFGEdge>
cfgOutEdges(
unsigned int index =
false);
841 virtual std::vector<VirtualCFG::CFGEdge>
cfgInEdges(
unsigned int index =
false);
863 static std::vector<std::tuple<unsigned char*, unsigned, VariantT>> all_pools;
865 static VariantT variantFromPool(
SgNode const * n);
924 static typename std::enable_if<std::is_base_of<SgNode, T>::value, T*>::type
927 node->set_parent(parent);
942 ASSERT_not_null(parent);
945 auto toString = [](
SgNode *node) {
947 return (boost::format(
"(%s*)%p") % node->class_name() % node).str();
949 return std::string(
"nullptr");
953 ASSERT_require2(child->get_parent() ==
nullptr,
954 "child " + toString(child) +
955 " cannot be inserted into " + toString(parent) +
956 " because it is already a child of " + toString(child->get_parent()));
958 child->set_parent(
this);
1000 typename std::enable_if<
1001 std::is_pointer<T>::value,
1005 auto toString = [](
SgNode *node) {
1007 return (boost::format(
"(%s*)%p") % node->class_name() % node).str();
1009 return std::string(
"nullptr");
1014 if (child != edge) {
1017 ASSERT_require2(edge->get_parent() ==
this,
1018 "node " + toString(edge) +
1019 " is a child of " + toString(
this) +
1020 " but has wrong parent " + toString(edge->get_parent()));
1021 edge->set_parent(
nullptr);
1027 ASSERT_require2(child->get_parent() ==
nullptr,
1028 "node " + toString(child) +
1029 " is to be a child of " + toString(
this) +
1030 " but is already a child of " + toString(child->get_parent()));
1031 child->set_parent(
this);
1046 typename std::enable_if<
1047 !std::is_pointer<T>::value,
1065 size_t objectSerializationDepth_ = 0;
1066 void debugSerializationHelper(
const char *className,
bool isBegin) {
1067 static size_t classSerializationDepth = 0;
1069 ASSERT_require(classSerializationDepth >= objectSerializationDepth_);
1070 const size_t memberTraversalDepth = classSerializationDepth - objectSerializationDepth_;
1071 std::cerr <<
"serializing: " <<std::string(memberTraversalDepth,
' ') <<std::string(objectSerializationDepth_,
'.')
1072 <<className <<
" " <<
this <<
"\n";
1073 ++classSerializationDepth;
1074 ++objectSerializationDepth_;
1076 ASSERT_require2(classSerializationDepth > 0, className);
1077 ASSERT_require2(objectSerializationDepth_ > 0, className);
1078 --classSerializationDepth;
1079 --objectSerializationDepth_;
1084 void debugSerializationHelper(
const char*,
bool) {}
1128 debugSerializationHelper(className,
true);
1131 debugSerializationHelper(className,
false);
1145 SgNode* get_freepointer()
const;
1146 void set_freepointer(
SgNode* freepointer);
1175bool p_containsTransformation;
1191static std::map<SgNode*,std::string> p_globalMangledNameMap;
1195static std::map<std::string, uint64_t> p_shortMangledNameCache;
1199static std::map<SgNode*,std::string> p_globalQualifiedNameMapForNames;
1203static std::map<SgNode*,std::string> p_globalQualifiedNameMapForTypes;
1207static std::map<SgNode*,std::string> p_globalQualifiedNameMapForTemplateHeaders;
1211static std::map<SgNode*,std::string> p_globalTypeNameMap;
1215static std::map<SgNode*,std::map<SgNode*,std::string> > p_globalQualifiedNameMapForMapsOfTypes;
Class holding static data and functions supporting File I/O.
Stores named attributes in Sage IR nodes.
Base class for all IR node attribute values.
Attribute containing a regex expression as a string.
For preprocessing information including source comments, include , if, define, etc.
Base class for machine instructions.
Supporting class from copy mechanism within ROSE.
This class represents the function type table (stores all function types so that they can be shared i...
This class represents the base class for all IR nodes within Sage III.
std::string unparseToCompleteString()
This function unparses the AST node (including comments and white space)
SgNode * p_parent
This is the pointer to the parent IR node in the AST.
virtual Sg_File_Info * get_startOfConstruct(void) const
New function interface for Sg_File_Info data stores starting location of contruct (typically the open...
virtual size_t get_numberOfTraversalSuccessors()
return number of children in the traversal successor list
virtual VariantT variantT() const
returns new style SageIII enum values
ROSE_DLL_API friend const SgNode * isSgNode(const SgNode *s)
Casts pointer from base class to derived class (for const pointers)
static SgTypeTable * get_globalTypeTable()
Access function for symbol table specific to non-function types.
virtual RTIReturnType roseRTI()
return C++ Runtime-Time-Information
virtual Sg_File_Info * get_endOfConstruct(void) const
New function interface for Sg_File_Info data stores ending location of contruct (typically the closin...
virtual std::vector< std::string > get_traversalSuccessorNamesContainer()
container of names of variables or container indices used used in the traversal to access AST success...
bool get_containsTransformation() const
Acess function for containsTransformation flag.
virtual std::vector< VirtualCFG::CFGEdge > cfgInEdges(unsigned int index=false)
Find the in edges of a CFG node – internal version.
void set_isModified(bool isModified)
All nodes in the AST contain a isModified flag used to track changes to the AST.
virtual std::vector< SgNode * > get_traversalSuccessorContainer()
container of pointers to AST successor nodes used in the traversal overridden in every class by gener...
virtual void debugSerializationEnd(const char *className)
Called by generated serializers.
SgNode(const SgNodeStorageClass &source)
IR node constructor to support AST File I/O.
static std::string getNodeIdString(SgNode *sgnode)
compute the NodeId for a particular SgNode*.
virtual bool isInMemoryPool()
FOR INTERNAL USE This is used in internal tests to verify that all IR nodes are allocated from the he...
VirtualCFG::CFGNode cfgForEnd()
Returns the CFG node for just after this AST node.
std::enable_if< std::is_pointer< T >::value, void >::type changeChildPointer(T &edge, T const &child)
Set a child edge in a tree to point to a specific child.
void set_parent(SgNode *parent)
All nodes in the AST contain a reference to a parent node.
virtual void processDataMemberReferenceToPointers(ReferenceToPointerHandler *)
FOR INTERNAL USE Processes pairs of references to SgNode* and strings for use in AST tools
SgNode * get_parent() const
Access function for parent node.
bool isChild(SgNode *node) const
Query function for if the input IR nodes is a child of the current IR node.
virtual std::string class_name() const
returns a string representing the class name
int numberOfNodesInSubtree()
Computes the number of nodes in the defined subtree of the AST.
virtual long getChildIndex(SgNode *childNode) const
FOR INTERNAL USE Returns a unique index value for the childNode in the list of children at this IR no...
VirtualCFG::CFGNode cfgForBeginning()
Returns the CFG node for just before this AST node.
virtual std::string unparseToString(SgUnparse_Info *info) const
This function unparses the AST node (excluding comments and unnecessary white space)
virtual unsigned int cfgFindChildIndex(SgNode *n)
Find the index of n in this node's CFG children.
virtual size_t get_childIndex(SgNode *child)
index-based access to traversal successors by child node
virtual void debugSerializationBegin(const char *className)
Called by generated serializers.
static void set_globalTypeTable(SgTypeTable *globalTypeTable)
Access function for symbol table specific to non-function types.
static std::vector< std::string > buildCommandLineToSubstituteTransformationFile(const std::vector< std::string > &argv, std::string newFileName)
Command line support for this compilation The command line is saved as a static variable so that it w...
virtual unsigned int cfgIndexForEnd() const
Determine the CFG index for the end of this construct.
static std::enable_if< std::is_base_of< SgNode, T >::value, T * >::type createAndParent(SgNode *parent)
Allocate and return a new node after setting its parent.
static void visitRepresentativeNode(ROSE_VisitTraversal &visit)
FOR INTERNAL USE Support for type-based traversal.
virtual void checkDataMemberPointersIfInMemoryPool()
FOR INTERNAL USE This is used in internal tests to verify that all IR nodes are allocated from the he...
static size_t numberOfNodes()
Returns the total number of IR nodes of this type.
bool get_isModified() const
Acess function for isModified flag.
ROSE_DLL_API friend SgNode * isSgNode(SgNode *s)
Casts pointer from base class to derived class.
int depthOfSubtree()
Computes the depth of the current defined subtree of the AST.
static SgFunctionTypeTable * get_globalFunctionTypeTable()
Access function for symbol table specific to function types.
virtual void accept(ROSE_VisitorPattern &visitor)
support for the classic visitor pattern done in GoF
virtual Sg_File_Info * get_file_info(void) const
File information containing filename, line number, column number, and if the SgNode is a part of a ne...
virtual std::vector< VirtualCFG::CFGEdge > cfgOutEdges(unsigned int index=false)
Find the out edges of a CFG node – internal version.
virtual SgNode * get_traversalSuccessorByIndex(size_t idx)
index-based access to traversal successors by index number
static void traverseMemoryPoolVisitorPattern(ROSE_VisitorPattern &visitor)
FOR INTERNAL USE Support for visitor pattern.
std::enable_if<!std::is_pointer< T >::value, void >::type changeChildPointer(T &edge, T const &child)
Set a child edge in a tree to point to a specific child.
void executeVisitorMemberFunction(ROSE_VisitorPattern &visitor)
FOR INTERNAL USE Support for visitor pattern.
static SgNode * getNodeByNodeId(VariantT variantT, size_t poolIdx, size_t itemIdx)
Find a node by its variant type, pool index, and item index.
virtual unsigned int cfgFindNextChildIndex(SgNode *n)
Find the index just after n in this node's CFG children.
static size_t memoryUsage()
Returns the size in bytes of the total memory allocated for all IR nodes of this type.
static void traverseMemoryPoolNodes(ROSE_VisitTraversal &visit)
FOR INTERNAL USE Support for visitor pattern over all IR nodes by type of IR node.
virtual void post_construction_initialization()
Final initialization for constructors This function is called at the end of generated constructors to...
T * initParentPointer(T *child, SgNode *parent)
Generated for tree edge data member initializations.
virtual std::vector< std::pair< SgNode *, std::string > > returnDataMemberPointers() const
FOR INTERNAL USE Returns STL vector of pairs of SgNode* and strings for use in AST tools
static void set_globalFunctionTypeTable(SgFunctionTypeTable *globalFunctionTypeTable)
Access function for symbol table specific to function types.
virtual const char * sage_class_name() const
void set_containsTransformation(bool containsTransformation)
Many nodes can hide other AST nodes and we need to track when outer nodes contain modified nodes even...
bool p_isModified
Records if IR node has been modified (data members reset).
bool get_isVisited() const
DOCS IN HEADER: Access function for p_isVisited flag used previously by the AST traversals.
static SgNode * getNodeByNodeIdInternal(size_t poolIdx, size_t itemIdx)
FOR INTERNAL USE Find an SgNode from its memory pool and location therin.
SgNode * p_freepointer
This is the pointer to the chain of previously freed objects.
virtual bool cfgIsIndexInteresting(unsigned int index) const
Determine whether a particular CFG node index is "interesting" for this kind of node.
SgNode * addRegExpAttribute(std::string s, AstRegExAttribute *a)
Support for AST matching using regular expression.
SgNode * get_raw_parent() const
Access function for direct access to uncomputed value of parent node.
virtual void destructorHelper()
This gets called by all Rosebud-generated destructors.
This class represents the location of the code associated with the IR node in the original source cod...
A node in the control flow graph.
void copy(const Word *src, const BitRange &srcRange, Word *dst, const BitRange &dstRange)
Copy some bits.