5#include <Cxx_GrammarDeclarations.h>
27#include <ROSE_DEPRECATED.h>
29#include <rosePublicConfig.h>
32#include <boost/format.hpp>
34#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
35#include <boost/serialization/access.hpp>
36#include <boost/serialization/base_object.hpp>
37#include <boost/serialization/map.hpp>
38#include <boost/serialization/set.hpp>
39#include <boost/serialization/vector.hpp>
40#include <boost/serialization/version.hpp>
43#include <Sawyer/CommandLine.h>
44#include <Sawyer/Interval.h>
45#include <Sawyer/IntervalSet.h>
47#include "processSupport.h"
48#define __builtin_constant_p(exp) (0)
50#ifdef ROSE_ENABLE_BINARY_ANALYSIS
51#include <Rose/BinaryAnalysis/AddressSet.h>
52#include <Rose/BinaryAnalysis/RelativeVirtualAddress.h>
53#include <Rose/BinaryAnalysis/AddressInterval.h>
54#include <Rose/BinaryAnalysis/AddressIntervalSet.h>
55#include <rose_extent.h>
56#include <Rose/BinaryAnalysis/RegisterDescriptor.h>
57#include <Rose/BinaryAnalysis/InstructionMap.h>
58#include <ROSE_NELMTS.h>
61#include <Rose/Constants.h>
63#include <sageTraversal.h>
66#include <sageMemory.h>
67#include <Cxx_GrammarVariants.h>
68#include <Cxx_GrammarStorageClasses.h>
69#include <virtualCFG.h>
71namespace Rose {
namespace Traits {
namespace generated {
template <
typename NodeT>
struct describe_node_t; } } }
72namespace Rose {
namespace Traits {
namespace generated {
template <
typename NodeT,
typename FieldT, FieldT NodeT::* fld_ptr>
struct describe_field_t; } } }
74#ifdef ROSE_ENABLE_BINARY_ANALYSIS
87class UnparseFormatHelp;
90class AstSpecificDataManagingClassStorageClass;
131 enum { static_variant = V_SgNode };
146 static const unsigned pool_size;
148 static std::vector<unsigned char *> pools;
150 static SgNode * next_node;
153 static unsigned long initializeStorageClassArray(SgNodeStorageClass *);
156 static void clearMemoryPool();
157 static void deleteMemoryPool();
160 static void extendMemoryPoolForFileIO();
163 static SgNode * getPointerFromGlobalIndex(
unsigned long);
165 static SgNode * getPointerFromGlobalIndex(AstSpecificDataManagingClass *,
unsigned long);
168 static unsigned long getNumberOfValidNodesAndSetGlobalIndexInFreepointer(
unsigned long);
170 static void resetValidFreepointers();
172 static unsigned long getNumberOfLastValidPointer();
175#if defined(INLINE_FUNCTIONS)
177 inline void *
operator new (
size_t size);
180 void *
operator new (
size_t size);
183 void operator delete (
void* pointer,
size_t size);
186 void operator delete (
void* pointer)
189 SgNode::operator
delete (pointer,
sizeof(
SgNode));
232#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
255 virtual int variant() const ROSE_DEPRECATED_FUNCTION;
310 static std::string getNodeIdStringInternal(
SgNode* sgnode);
437 friend class SgNodeStorageClass;
440 friend class AstSpecificDataManagingClass;
443 friend class AstSpecificDataManagingClassStorageClass;
446 SgNode(
const SgNodeStorageClass& source );
475#define BUILD_ATERM_SUPPORT 0
476 #if BUILD_ATERM_SUPPORT
477 #ifdef ROSE_USE_ROSE_ATERM_SUPPORT
489 virtual ATerm generate_ATerm();
492 virtual void generate_ATerm_Annotation(ATerm & term);
543 void set_containsTransformationRelativeToNodeFile(
bool containsTransformationRelativeToNodeFile );
549 bool get_containsTransformationRelativeToNodeFile()
const;
573 std::string unparseToString()
const;
590 int variant() const ROSE_DEPRECATED_FUNCTION {
return (
int)this->variantT();}
593 static std::vector<VariantT> getClassHierarchySubTreeFunction( VariantT v);
594 static void getClassHierarchySubTreeFunction( VariantT v, std::vector<VariantT>&);
607 void set_isVisited (
bool isVisited ) ROSE_DEPRECATED_FUNCTION;
613 static std::map<
SgNode*,std::
string> & get_globalMangledNameMap();
617 static
void clearGlobalMangledNameMap();
624 static std::map<std::
string, uint64_t> & get_shortMangledNameCache();
632 static std::map<
SgNode*,std::
string> & get_globalQualifiedNameMapForNames();
639 static
void set_globalQualifiedNameMapForNames ( const std::map<
SgNode*,std::
string> & X );
647 static std::map<
SgNode*,std::
string> & get_globalQualifiedNameMapForTypes();
655 static
void set_globalQualifiedNameMapForTypes ( const std::map<
SgNode*,std::
string> & X );
664 static std::map<
SgNode*,std::map<
SgNode*,std::
string> > & get_globalQualifiedNameMapForMapsOfTypes();
673 static
void set_globalQualifiedNameMapForMapsOfTypes ( const std::map<
SgNode*,std::map<
SgNode*,std::
string> > & X );
684 static std::map<
SgNode*,std::
string> & get_globalQualifiedNameMapForTemplateHeaders();
690 static
void set_globalQualifiedNameMapForTemplateHeaders ( const std::map<
SgNode*,std::
string> & X );
698 static std::map<
SgNode*,std::
string> & get_globalTypeNameMap();
705 static
void set_globalTypeNameMap ( const std::map<
SgNode*,std::
string> & X );
736 virtual
void removeAttribute(std::
string s);
738 virtual
bool attributeExists(std::
string s) const;
740 virtual
int numberOfAttributes() const;
813#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
820#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
842 virtual std::vector<VirtualCFG::CFGEdge>
cfgOutEdges(
unsigned int index =
false);
845 virtual std::vector<VirtualCFG::CFGEdge>
cfgInEdges(
unsigned int index =
false);
867 static std::vector<std::tuple<unsigned char*, unsigned, VariantT>> all_pools;
869 static VariantT variantFromPool(
SgNode const * n);
928 static typename std::enable_if<std::is_base_of<SgNode, T>::value, T*>::type
931 node->set_parent(parent);
946 ASSERT_not_null(parent);
949 auto toString = [](
SgNode *node) {
951 return (boost::format(
"(%s*)%p") % node->class_name() % node).str();
953 return std::string(
"nullptr");
957 ASSERT_require2(child->get_parent() ==
nullptr,
958 "child " + toString(child) +
959 " cannot be inserted into " + toString(parent) +
960 " because it is already a child of " + toString(child->get_parent()));
962 child->set_parent(
this);
1004 typename std::enable_if<
1005 std::is_pointer<T>::value,
1009 auto toString = [](
SgNode *node) {
1011 return (boost::format(
"(%s*)%p") % node->class_name() % node).str();
1013 return std::string(
"nullptr");
1018 if (child != edge) {
1021 ASSERT_require2(edge->get_parent() ==
this,
1022 "node " + toString(edge) +
1023 " is a child of " + toString(
this) +
1024 " but has wrong parent " + toString(edge->get_parent()));
1025 edge->set_parent(
nullptr);
1031 ASSERT_require2(child->get_parent() ==
nullptr,
1032 "node " + toString(child) +
1033 " is to be a child of " + toString(
this) +
1034 " but is already a child of " + toString(child->get_parent()));
1035 child->set_parent(
this);
1050 typename std::enable_if<
1051 !std::is_pointer<T>::value,
1069 size_t objectSerializationDepth_ = 0;
1070 void debugSerializationHelper(
const char *className,
bool isBegin) {
1071 static size_t classSerializationDepth = 0;
1073 ASSERT_require(classSerializationDepth >= objectSerializationDepth_);
1074 const size_t memberTraversalDepth = classSerializationDepth - objectSerializationDepth_;
1075 std::cerr <<
"serializing: " <<std::string(memberTraversalDepth,
' ') <<std::string(objectSerializationDepth_,
'.')
1076 <<className <<
" " <<
this <<
"\n";
1077 ++classSerializationDepth;
1078 ++objectSerializationDepth_;
1080 ASSERT_require2(classSerializationDepth > 0, className);
1081 ASSERT_require2(objectSerializationDepth_ > 0, className);
1082 --classSerializationDepth;
1083 --objectSerializationDepth_;
1088 void debugSerializationHelper(
const char*,
bool) {}
1132 debugSerializationHelper(className,
true);
1135 debugSerializationHelper(className,
false);
1149 SgNode* get_freepointer()
const;
1150 void set_freepointer(
SgNode* freepointer);
1179bool p_containsTransformation;
1195static std::map<SgNode*,std::string> p_globalMangledNameMap;
1199static std::map<std::string, uint64_t> p_shortMangledNameCache;
1203static std::map<SgNode*,std::string> p_globalQualifiedNameMapForNames;
1207static std::map<SgNode*,std::string> p_globalQualifiedNameMapForTypes;
1211static std::map<SgNode*,std::string> p_globalQualifiedNameMapForTemplateHeaders;
1215static std::map<SgNode*,std::string> p_globalTypeNameMap;
1219static 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 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 size_t get_numberOfTraversalSuccessors() const
return number of children in the traversal successor list
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< std::string > get_traversalSuccessorNamesContainer() const
container of names of variables or container indices used used in the traversal to access AST success...
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
virtual size_t get_childIndex(SgNode *child) const
index-based access to traversal successors by child node
SgNode * get_parent() const
Access function for parent node.
virtual std::vector< SgNode * > get_traversalSuccessorContainer() const
container of pointers to AST successor nodes used in the traversal overridden in every class by gener...
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 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.
virtual SgNode * get_traversalSuccessorByIndex(size_t idx) const
index-based access to traversal successors by index number
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.
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.