5#include <Cxx_GrammarDeclarations.h>
27#include <ROSE_DEPRECATED.h>
29#include <rosePublicConfig.h>
32#include <sageContainer.h>
33#include <boost/format.hpp>
35#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
36#include <boost/serialization/access.hpp>
37#include <boost/serialization/base_object.hpp>
38#include <boost/serialization/map.hpp>
39#include <boost/serialization/set.hpp>
40#include <boost/serialization/vector.hpp>
41#include <boost/serialization/version.hpp>
44#include <Sawyer/CommandLine.h>
45#include <Sawyer/Interval.h>
46#include <Sawyer/IntervalSet.h>
48#include "processSupport.h"
49#define __builtin_constant_p(exp) (0)
51#ifdef ROSE_ENABLE_BINARY_ANALYSIS
52#include <Rose/BinaryAnalysis/AddressSet.h>
53#include <Rose/BinaryAnalysis/RelativeVirtualAddress.h>
54#include <Rose/BinaryAnalysis/AddressInterval.h>
55#include <Rose/BinaryAnalysis/AddressIntervalSet.h>
56#include <rose_extent.h>
57#include <Rose/BinaryAnalysis/RegisterDescriptor.h>
58#include <Rose/BinaryAnalysis/InstructionMap.h>
59#include <ROSE_NELMTS.h>
62#include <Rose/Constants.h>
64#include <sageTraversal.h>
67#include <sageMemory.h>
68#include <Cxx_GrammarVariants.h>
69#include <Cxx_GrammarStorageClasses.h>
70#include <virtualCFG.h>
72namespace Rose {
namespace Traits {
namespace generated {
template <
typename NodeT>
struct describe_node_t; } } }
73namespace Rose {
namespace Traits {
namespace generated {
template <
typename NodeT,
typename FieldT, FieldT NodeT::* fld_ptr>
struct describe_field_t; } } }
75#ifdef ROSE_ENABLE_BINARY_ANALYSIS
88class UnparseFormatHelp;
91class AstSpecificDataManagingClassStorageClass;
132 enum { static_variant = V_SgNode };
147 static const unsigned pool_size;
149 static std::vector<unsigned char *> pools;
151 static SgNode * next_node;
154 static unsigned long initializeStorageClassArray(SgNodeStorageClass *);
157 static void clearMemoryPool();
158 static void deleteMemoryPool();
161 static void extendMemoryPoolForFileIO();
164 static SgNode * getPointerFromGlobalIndex(
unsigned long);
166 static SgNode * getPointerFromGlobalIndex(AstSpecificDataManagingClass *,
unsigned long);
169 static unsigned long getNumberOfValidNodesAndSetGlobalIndexInFreepointer(
unsigned long);
171 static void resetValidFreepointers();
173 static unsigned long getNumberOfLastValidPointer();
176#if defined(INLINE_FUNCTIONS)
178 inline void *
operator new (
size_t size);
181 void *
operator new (
size_t size);
184 void operator delete (
void* pointer,
size_t size);
187 void operator delete (
void* pointer)
190 SgNode::operator
delete (pointer,
sizeof(
SgNode));
233#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
256 virtual int variant() const ROSE_DEPRECATED_FUNCTION;
311 static std::string getNodeIdStringInternal(
SgNode* sgnode);
438 friend class SgNodeStorageClass;
441 friend class AstSpecificDataManagingClass;
444 friend class AstSpecificDataManagingClassStorageClass;
447 SgNode(
const SgNodeStorageClass& source );
476#define BUILD_ATERM_SUPPORT 0
477 #if BUILD_ATERM_SUPPORT
478 #ifdef ROSE_USE_ROSE_ATERM_SUPPORT
490 virtual ATerm generate_ATerm();
493 virtual void generate_ATerm_Annotation(ATerm & term);
544 void set_containsTransformationRelativeToNodeFile(
bool containsTransformationRelativeToNodeFile );
550 bool get_containsTransformationRelativeToNodeFile()
const;
574 std::string unparseToString()
const;
591 int variant() const ROSE_DEPRECATED_FUNCTION {
return (
int)this->variantT();}
594 static std::vector<VariantT> getClassHierarchySubTreeFunction( VariantT v);
595 static void getClassHierarchySubTreeFunction( VariantT v, std::vector<VariantT>&);
608 void set_isVisited (
bool isVisited ) ROSE_DEPRECATED_FUNCTION;
614 static std::map<
SgNode*,std::
string> & get_globalMangledNameMap();
618 static
void clearGlobalMangledNameMap();
625 static std::map<std::
string, uint64_t> & get_shortMangledNameCache();
635 static SgUnorderedMapNodeToString & get_globalQualifiedNameMapForNames();
644 static
void set_globalQualifiedNameMapForNames ( const SgUnorderedMapNodeToString & X );
654 static SgUnorderedMapNodeToString & get_globalQualifiedNameMapForTypes();
664 static
void set_globalQualifiedNameMapForTypes ( const SgUnorderedMapNodeToString & X );
675 static std::map<
SgNode*,SgUnorderedMapNodeToString> & get_globalQualifiedNameMapForMapsOfTypes();
686 static
void set_globalQualifiedNameMapForMapsOfTypes ( const std::map<
SgNode*,SgUnorderedMapNodeToString> & X );
699 static SgUnorderedMapNodeToString & get_globalQualifiedNameMapForTemplateHeaders();
706 static
void set_globalQualifiedNameMapForTemplateHeaders ( const SgUnorderedMapNodeToString & X );
714 static SgUnorderedMapNodeToString& get_globalTypeNameMap();
721 static
void set_globalTypeNameMap ( const SgUnorderedMapNodeToString& X );
752 virtual
void removeAttribute(std::
string s);
754 virtual
bool attributeExists(std::
string s) const;
756 virtual
int numberOfAttributes() const;
829#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
836#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
858 virtual std::vector<VirtualCFG::CFGEdge>
cfgOutEdges(
unsigned int index =
false);
861 virtual std::vector<VirtualCFG::CFGEdge>
cfgInEdges(
unsigned int index =
false);
883 static std::vector<std::tuple<unsigned char*, unsigned, VariantT>> all_pools;
885 static VariantT variantFromPool(
SgNode const * n);
944 static typename std::enable_if<std::is_base_of<SgNode, T>::value, T*>::type
947 node->set_parent(parent);
962 ASSERT_not_null(parent);
965 auto toString = [](
SgNode *node) {
967 return (boost::format(
"(%s*)%p") % node->class_name() % node).str();
969 return std::string(
"nullptr");
973 ASSERT_require2(child->get_parent() ==
nullptr,
974 "child " + toString(child) +
975 " cannot be inserted into " + toString(parent) +
976 " because it is already a child of " + toString(child->get_parent()));
978 child->set_parent(
this);
1020 typename std::enable_if<
1021 std::is_pointer<T>::value,
1025 auto toString = [](
SgNode *node) {
1027 return (boost::format(
"(%s*)%p") % node->class_name() % node).str();
1029 return std::string(
"nullptr");
1034 if (child != edge) {
1037 ASSERT_require2(edge->get_parent() ==
this,
1038 "node " + toString(edge) +
1039 " is a child of " + toString(
this) +
1040 " but has wrong parent " + toString(edge->get_parent()));
1041 edge->set_parent(
nullptr);
1047 ASSERT_require2(child->get_parent() ==
nullptr,
1048 "node " + toString(child) +
1049 " is to be a child of " + toString(
this) +
1050 " but is already a child of " + toString(child->get_parent()));
1051 child->set_parent(
this);
1066 typename std::enable_if<
1067 !std::is_pointer<T>::value,
1085 size_t objectSerializationDepth_ = 0;
1086 void debugSerializationHelper(
const char *className,
bool isBegin) {
1087 static size_t classSerializationDepth = 0;
1089 ASSERT_require(classSerializationDepth >= objectSerializationDepth_);
1090 const size_t memberTraversalDepth = classSerializationDepth - objectSerializationDepth_;
1091 std::cerr <<
"serializing: " <<std::string(memberTraversalDepth,
' ') <<std::string(objectSerializationDepth_,
'.')
1092 <<className <<
" " <<
this <<
"\n";
1093 ++classSerializationDepth;
1094 ++objectSerializationDepth_;
1096 ASSERT_require2(classSerializationDepth > 0, className);
1097 ASSERT_require2(objectSerializationDepth_ > 0, className);
1098 --classSerializationDepth;
1099 --objectSerializationDepth_;
1104 void debugSerializationHelper(
const char*,
bool) {}
1148 debugSerializationHelper(className,
true);
1151 debugSerializationHelper(className,
false);
1165 SgNode* get_freepointer()
const;
1166 void set_freepointer(
SgNode* freepointer);
1195bool p_containsTransformation;
1211static std::map<SgNode*,std::string> p_globalMangledNameMap;
1215static std::map<std::string, uint64_t> p_shortMangledNameCache;
1219static std::unordered_map<SgNode*,std::string> p_globalQualifiedNameMapForNames;
1223static std::unordered_map<SgNode*,std::string> p_globalQualifiedNameMapForTypes;
1227static std::unordered_map<SgNode*,std::string> p_globalQualifiedNameMapForTemplateHeaders;
1231static std::unordered_map<SgNode*,std::string> p_globalTypeNameMap;
1235static std::map<SgNode*,std::unordered_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.