ROSE 0.11.145.317
SgNode.h
1
2#ifndef ROSE_SgNode_H
3#define ROSE_SgNode_H
4#include <RoseFirst.h>
5#include <Cxx_GrammarDeclarations.h>
6
7
8
9/* #line 1 "/workspace/src/ROSETTA/Grammar/grammarClassDeclarationMacros.macro" */
10
11// WARNING -- GENERATED CODE -- DO NOT MODIFY THIS CODE -- WARNING!
12// This code is automatically generated for each
13// terminal and non-terminal within the defined
14// grammar. There is a simple way to change the
15// code to fix bugs etc. See the ROSE README file
16// for directions.
17
18// tps: (02/22/2010): Adding DLL export requirements
19#include "rosedll.h"
20
21// predeclarations for SgNode
22
23/* #line 24 "../../../src/frontend/SageIII//SgNode.h" */
24/* #line 2 "/workspace/src/ROSETTA/Grammar/Node.code" */
25
26
27#include <ROSE_DEPRECATED.h>
28#include <semaphore.h>
29#include <rosePublicConfig.h>
30#include "setup.h"
31// #include "Map.h"
32#include <sageContainer.h>
33#include <boost/format.hpp>
34
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>
42#endif
43
44#include <Sawyer/CommandLine.h>
45#include <Sawyer/Interval.h>
46#include <Sawyer/IntervalSet.h>
47
48#include "processSupport.h"
49#define __builtin_constant_p(exp) (0)
50
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> // deprecated
57#include <Rose/BinaryAnalysis/RegisterDescriptor.h>
58#include <Rose/BinaryAnalysis/InstructionMap.h>
59#include <ROSE_NELMTS.h>
60#endif
61
62#include <Rose/Constants.h>
63#include <sageHash.h>
64#include <sageTraversal.h>
65#include <sageRti.h>
66#include <sageCopy.h>
67#include <sageMemory.h>
68#include <Cxx_GrammarVariants.h>
69#include <Cxx_GrammarStorageClasses.h>
70#include <virtualCFG.h>
71
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; } } }
74
75#ifdef ROSE_ENABLE_BINARY_ANALYSIS
76// Version numbers for SgAsm* nodes. Used for backward compatibility. */
77BOOST_CLASS_VERSION(SgAsmInstruction, 1);
78#endif
79
82class AstAttribute;
85
86// DQ (3/18/2006): Forward declarations of classes used to control and tailor the code generation.
87class UnparseDelegate;
88class UnparseFormatHelp;
89
90// DQ (4/32/2006): g++ 4.0.2 requires a forward declaration for this (a friend class declaration is not sufficient!)
91class AstSpecificDataManagingClassStorageClass;
92
93
94
95/* #line 13 "/workspace/src/ROSETTA/Grammar/grammarClassDeclarationMacros.macro after subst for $PREDECLARATIONS" */
96
97/* #line 14 "/workspace/src/ROSETTA/Grammar/grammarClassDeclarationMacros.macro" */
98
99#if 1
100// Class Definition for SgNode
101class ROSE_DLL_API SgNode
102 {
103 public:
104
105
106/* #line 107 "../../../src/frontend/SageIII//SgNode.h" */
107
108 virtual SgNode* copy ( SgCopyHelp& help) const;
109// Start of memberFunctionString
110/* #line 1 "/workspace/src/ROSETTA/Grammar/Common.code" */
111
112// *** COMMON CODE SECTION BEGINS HERE ***
113
114 public:
115
116 // DQ (3/25/3006): I put this back in because it had the logic for where the copy function required
117 // and not required which is required to match the other aspects of the copy mechanism code generation.
118 // Specifically it is a problem to declare the copy function everywhere because it is not implemented
119 // for the SgSymbol IR nodes. I'm not clear why it is not implemented for these IR nodes.
120 /* \brief Copies AST (whole subtree, depending on the SgCopyHelp class */
121 // virtual SgNode* copy ( const SgCopyHelp & help) const;
122
124 virtual std::string class_name() const;
125
127 virtual VariantT variantT() const; // MS: new variant used in tree traversal
128
130 // King84 (2010.08.16): Moved this to an enum to save space, since it's only used at compiler-time anyway.
131 // static const VariantT static_variant = V_SgNode;
132 enum { static_variant = V_SgNode };
133
134 /* the generated cast function */
136 ROSE_DLL_API friend SgNode* isSgNode( SgNode * s );
137
139 ROSE_DLL_API friend const SgNode* isSgNode( const SgNode * s );
140
141 // ******************************************
142 // * Memory Pool / New / Delete
143 // ******************************************
144
145 public:
147 static const unsigned pool_size; //
149 static std::vector<unsigned char *> pools; //
151 static SgNode * next_node; //
152
154 static unsigned long initializeStorageClassArray(SgNodeStorageClass *); //
155
157 static void clearMemoryPool(); //
158 static void deleteMemoryPool(); //
159
161 static void extendMemoryPoolForFileIO(); //
162
164 static SgNode * getPointerFromGlobalIndex(unsigned long); //
166 static SgNode * getPointerFromGlobalIndex(AstSpecificDataManagingClass *, unsigned long); //
167
169 static unsigned long getNumberOfValidNodesAndSetGlobalIndexInFreepointer(unsigned long); //
171 static void resetValidFreepointers(); //
173 static unsigned long getNumberOfLastValidPointer(); //
174
175
176#if defined(INLINE_FUNCTIONS)
178 inline void *operator new (size_t size);
179#else
181 void *operator new (size_t size);
182#endif
184 void operator delete (void* pointer, size_t size);
185
186 // DQ (4/5/2007): This is not the correct operator that we want, but appears to be required to compile ROSE with ROSE.
187 void operator delete (void* pointer)
188 {
189 // This is the generated delete operator...
190 SgNode::operator delete (pointer,sizeof(SgNode));
191 }
192
194 static size_t numberOfNodes();
195
197 static size_t memoryUsage();
198
199 // End of scope which started in IR nodes specific code
200 /* */
201
202 /* name Internal Functions
203 \brief Internal functions ... incomplete-documentation
204
205 These functions have been made public as part of the design, but they are suggested for internal use
206 or by particularly knowledgeable users for specialized tools or applications.
207
208 \internal We could not make these private because they are required by user for special purposes. And
209 it would be unwieldy to have many of the internal classes in ROSE be explicitly defined as friends.
210
211 */
212
213 // MS: 02/12/02 container of pointers to AST successor nodes used in the traversal
214 // overridden in every class by *generated* implementation
216 virtual std::vector<SgNode*> get_traversalSuccessorContainer() const;
217 // MS: 06/28/02 container of names of variables or container indices
218 // used used in the traversal to access AST successor nodes
219 // overridden in every class by *generated* implementation
222 virtual std::vector<std::string> get_traversalSuccessorNamesContainer() const;
223
224 // GB (09/25/2007): Functions for index-based access to traversal successors; these are hopefully a lot faster
225 // than all the vector copies. The implementation for these functions is generated for each class.
227 virtual size_t get_numberOfTraversalSuccessors() const;
229 virtual SgNode *get_traversalSuccessorByIndex(size_t idx) const;
231 virtual size_t get_childIndex(SgNode *child) const;
232
233#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
234 // MS: 08/16/2002 method for generating RTI information
236 virtual RTIReturnType roseRTI();
237#endif
238 /* */
239
240
241
242 /* name Deprecated Functions
243 \brief Deprecated functions ... incomplete-documentation
244
245 These functions have been deprecated from use.
246 */
247 /* */
248
250 virtual const char* sage_class_name() const ROSE_DEPRECATED_FUNCTION;
251
252 // JJW (10/16/2008): Changed to a single function in Node.code, and put
253 // getVariant() in #if 0 block to prevent confusing Doxygen
254#if 0
256 virtual int variant() const ROSE_DEPRECATED_FUNCTION;
258 // virtual int getVariant() const ROSE_DEPRECATED_FUNCTION;
259#endif
260 /* */
261
262
263
264
265 public:
266 /* name Traversal Support Functions
267 \brief Traversal support functions ... incomplete-documentation
268
269 These functions have been made public as part of the design, but they are suggested for internal use
270 or by particularly knowledgable users for specialized tools or applications.
271 */
272 /* */
273
274 // DQ (11/26/2005): Support for visitor pattern mechanims
275 // (inferior to ROSE traversal mechanism, experimental).
279
280 /* DXN (08/09/2010): support for the classic visitor pattern done in GoF */
282 virtual void accept (ROSE_VisitorPattern & visitor);
283
284 // DQ (12/26/2005): Support for traversal based on the memory pool
288
292
293 // DQ (2/9/2006): Added to support traversal over single representative of each IR node
294 // This traversal helps support internal tools that call static member functions.
295 // note: this function operates on the memory pools.
299 /* */
300
301 public:
302 /* NodeId support functions */
304 static SgNode* getNodeByNodeId(VariantT variantT, size_t poolIdx, size_t itemIdx);
307 static SgNode* getNodeByNodeIdInternal(size_t poolIdx, size_t itemIdx);
310 static std::string getNodeIdString(SgNode* sgnode);
311 static std::string getNodeIdStringInternal(SgNode* sgnode);
312
313 public:
314 /* name Memory Allocation Functions
315 \brief Memory allocations functions ... incomplete-documentation
316
317 These functions have been made public as part of the design, but they are suggested for internal use
318 or by particularly knowledgable users for specialized tools or applications.
319 */
320 /* */
321
332 virtual bool isInMemoryPool();
333
345
346 // DQ (4/30/2006): Modified to be a const function.
361 virtual std::vector<std::pair<SgNode*,std::string> > returnDataMemberPointers() const;
362
373
385 virtual long getChildIndex( SgNode* childNode ) const;
386
387 // DQ (9/2/2015): Since this function is generated by ROSETTA, we can't define the
388 // comment here (changed to be a C style comment and not be a doxygen comment).
389 /* \brief Constructor for use by AST File I/O Mechanism
390
391 This constructor permits the IR node to be rebuilt from the contiguously arranged data in memory
392 which obtained via fast binary file I/O from disk.
393 */
394 // SgNode( SgNodeStorageClass& source );
395
396
397
398
399
400 // JH (10/24/2005): methods added to support the ast file IO
401 private:
402
403 /* name AST Memory Allocation Support Functions
404 \brief Memory allocations support....
405
406 These functions handle the low leve support of the memory allocation scheme which permits IR nodes to be allocated
407 in large contiguous blocks to reduce memory fragmentation, improve performance, support specialized access (AST traversals),
408 and support the AST File I/O Mechanism.
409 */
410 /* */
411
412 /* JH (10/24/2005): Two typedefs. The TestType notes the type every pointer is cast to before
413 we compare them. Since I had several problems with this, I decided to make a typdef to ensure
414 that I use the same type everywhere, if any changes are made. THe second one declares the type
415 (actually unsigned long) where teh pointer address gets converted to. On 64 bit platforms this
416 might got changed, but unfortunatly, the return types are still unsigned longs. There exists
417 a correspinding one in the AST_FILE_IO class!
418 */
419 // DQ (9/2/2015): This typedef is no longer used, we can't define the
420 // comment here (changed to be a C style comment and not be a doxygen comment).
421 /* \brief Typedef used for low level memory access.
422 */
423 // typedef unsigned char* TestType;
424
425 // DQ (9/2/2015): This typedef is no longer used, we can't define the
426 // comment here (changed to be a C style comment and not be a doxygen comment).
427 /* \brief Typedef used to hold memory addresses as values.
428 */
429 // typedef unsigned long AddressType;
430
431
432
433 // necessary, to have direct access to the p_freepointer and the private methods !
435 friend class AST_FILE_IO;
436
438 friend class SgNodeStorageClass;
439
441 friend class AstSpecificDataManagingClass;
442
444 friend class AstSpecificDataManagingClassStorageClass;
445 public:
447 SgNode( const SgNodeStorageClass& source );
448
449 // private: // JJW hack
450 /*
451 name AST Memory Allocation Support Variables
452 Memory allocations support variables
453
454 These variables handle the low level support of the memory allocation scheme which permits IR nodes to be allocated
455 in large contiguous blocks to reduce memory fragmentation, improve performance, support specialized access (AST traversals),
456 and support the AST File I/O Mechanism.
457 */
458 /* */
459
460 public:
461
462 // DQ (11/21/2009): Added function to add new Regular Expression attributes and return pointer
463 // to current node (so that it will work cleanly with build functions to specify patterns).
464 // virtual SgNode* addRegExpAttribute();
471
472#ifndef _MSC_VER
473// Rasmussen (04/17/2019): Support for ATerms has been deprecated as it is no longer needed
474// and likely never fully implemented nor tested. Files remain in the src tree but are no
475// longer built.
476#define BUILD_ATERM_SUPPORT 0
477 #if BUILD_ATERM_SUPPORT
478 #ifdef ROSE_USE_ROSE_ATERM_SUPPORT
479 // DQ (10/4/2014): Adding ATerm support to ROSE.
489 // Rasmussen (1/7/2019): Added to kill warning messages of overridden virtual function
490 virtual ATerm generate_ATerm();
491
493 virtual void generate_ATerm_Annotation(ATerm & term);
494 #endif
495 #endif // BUILD_ATERM_SUPPORT
496#endif
497 // These can't be virtual functions since we don't yet know what IR node to build (until we have read the aterm).
498 // virtual generate_AST(ATerm & term);
499 // virtual void read_ATerm_Annotation(ATerm & term);
500
501// *** COMMON CODE SECTION ENDS HERE ***
502
503
504// End of memberFunctionString
505// Start of memberFunctionString
506/* #line 73 "/workspace/src/ROSETTA/Grammar/Node.code" */
507
508 public:
509
516 void set_isModified( bool isModified );
517
522 void set_containsTransformation( bool containsTransformation );
523
524
530 bool get_isModified() const;
531
537
538#if 0
539 // DQ (5/2/2021): I think we need a flag to record when a transformation is contained directly in the current file.
544 void set_containsTransformationRelativeToNodeFile( bool containsTransformationRelativeToNodeFile );
545
550 bool get_containsTransformationRelativeToNodeFile() const;
551#endif
553 void set_parent ( SgNode* parent );
554
557
558 // DQ (3/4/2022): Added access function for p_parent for debugging.
561
563 bool isChild ( SgNode* node ) const;
564
565 // DQ (4/4/2006): Added optional parameter to customize unparsing
567 // virtual std::string unparseToString(SgUnparse_Info* info = NULL) const;
568 // Jeremiah (11/9/2007): The default value is not recognized by gdb.
569 virtual std::string unparseToString(SgUnparse_Info* info) const;
570
571 // DQ (9/6/2010): Move this to the source file (we want to eliminate function definitions in header files).
572 // The existence of this function addresses a bug in gdb (see comment from Jeremiah (11/9/2007) above).
573 // inline std::string unparseToString() const { return this->unparseToString(NULL); }
574 std::string unparseToString() const;
575
578
587 static std::vector<std::string> buildCommandLineToSubstituteTransformationFile( const std::vector<std::string>& argv, std::string newFileName );
588
589 // JJW (10/16/2008): Replace variant() by variantT() and a cast (the
590 // numbers are the same, but the enumerator names are different)
591 int variant() const ROSE_DEPRECATED_FUNCTION {return (int)this->variantT();}
592
593 // AS (10/22/2007): build function to return class hierachy subtree of a VariantT
594 static std::vector<VariantT> getClassHierarchySubTreeFunction( VariantT v);
595 static void getClassHierarchySubTreeFunction( VariantT v, std::vector<VariantT>&);
596
602 bool get_isVisited () const ROSE_DEPRECATED_FUNCTION;
603
608 void set_isVisited ( bool isVisited ) ROSE_DEPRECATED_FUNCTION;
609
614 static std::map<SgNode*,std::string> & get_globalMangledNameMap();
615
618 static void clearGlobalMangledNameMap();
619
625 static std::map<std::string, uint64_t> & get_shortMangledNameCache();
626
627
633 // DQ (8/11/2025): Adding support for unordered maps for name qualification.
634 // static std::map<SgNode*,std::string> & get_globalQualifiedNameMapForNames();
635 static SgUnorderedMapNodeToString & get_globalQualifiedNameMapForNames();
636
642 // DQ (8/11/2025): Adding support for unordered maps for name qualification.
643 // static void set_globalQualifiedNameMapForNames ( const std::map<SgNode*,std::string> & X );
644 static void set_globalQualifiedNameMapForNames ( const SgUnorderedMapNodeToString & X );
645
652 // DQ (8/11/2025): Adding support for unordered maps for name qualification.
653 // static std::map<SgNode*,std::string> & get_globalQualifiedNameMapForTypes();
654 static SgUnorderedMapNodeToString & get_globalQualifiedNameMapForTypes();
655
662 // DQ (8/11/2025): Adding support for unordered maps for name qualification.
663 // static void set_globalQualifiedNameMapForTypes ( const std::map<SgNode*,std::string> & X );
664 static void set_globalQualifiedNameMapForTypes ( const SgUnorderedMapNodeToString & X );
665
666 // DQ (3/13/2019): Added name qualification support for references to types than can embed many types.
673 // DQ (8/11/2025): Adding support for unordered maps for name qualification.
674 // static std::map<SgNode*,std::map<SgNode*,std::string> > & get_globalQualifiedNameMapForMapsOfTypes();
675 static std::map<SgNode*,SgUnorderedMapNodeToString> & get_globalQualifiedNameMapForMapsOfTypes();
676
677 // DQ (3/13/2019): Added name qualification support for references to types than can embed many types.
684 // DQ (8/11/2025): Adding support for unordered maps for name qualification.
685 // static void set_globalQualifiedNameMapForMapsOfTypes ( const std::map<SgNode*,std::map<SgNode*,std::string> > & X );
686 static void set_globalQualifiedNameMapForMapsOfTypes ( const std::map<SgNode*,SgUnorderedMapNodeToString> & X );
687
697 // DQ (8/11/2025): Adding support for unordered maps for name qualification.
698 // static std::map<SgNode*,std::string> & get_globalQualifiedNameMapForTemplateHeaders();
699 static SgUnorderedMapNodeToString & get_globalQualifiedNameMapForTemplateHeaders();
700
705 // static void set_globalQualifiedNameMapForTemplateHeaders ( const std::map<SgNode*,std::string> & X );
706 static void set_globalQualifiedNameMapForTemplateHeaders ( const SgUnorderedMapNodeToString & X );
707
714 static SgUnorderedMapNodeToString& get_globalTypeNameMap();
715
721 static void set_globalTypeNameMap ( const SgUnorderedMapNodeToString& X );
722
723 /* name Persistant Attribute Mechanism
724
725 This is the persistant attribute mechanism for attaching attributed to IR nodes across
726 multiple passes. Note that these attributes are persistant in that they are preserved
727 if the AST is written out to a file and read in from a file. However, virtual function
728 in the user-defined class derived from the AstAttribute must be defined for the attribute
729 to be defined across the boundary of File I/O (simple pack and unpack functions). More
730 sophisticated mechanisms are available within the AstAttributeMechanism object
731 (e.g iterating though attributes, etc; get_attributeMechanism() is available if direct
732 access is required, however mostly only internal tools use this lower level support).
733
734 \internal This used to be a public data member, but has been changed to be a protected
735 pointer instead. The functional interface of the AstAttributeMechanism is presevered
736 but some of the names and the syntax for calling the interface have changed. The
737 pointer to the AstAttributeMechanism is now generated by ROSETTA.
738 */
739 /* */
741 virtual void addNewAttribute(std::string s,AstAttribute* a);
743 virtual AstAttribute* getAttribute(std::string s) const;
745 virtual void updateAttribute(std::string s,AstAttribute* a); // formerly called: replace in AstAttributeMechanism
750 virtual void setAttribute(std::string s,AstAttribute* a);
752 virtual void removeAttribute(std::string s);
754 virtual bool attributeExists(std::string s) const;
756 virtual int numberOfAttributes() const;
757
765 virtual AstAttributeMechanism* get_attributeMechanism() const;
772 virtual void set_attributeMechanism(AstAttributeMechanism* a);
773 /* */
774
775#if ALT_FIXUP_COPY
776 /* name AST Copy Support Functions
777
778 Support for IR node specific fixup of copy operation.
779 This function helps reset scopes and build untraversed parts of the
780 AST that are difficult to have be constructed using the automatically
781 generated copy functions.
782
783 \implementation These functions are used internally inside the AST copy mechanism.
784 The public interface for this functionality is given below this section.
785 */
786 /* */
787 virtual void fixupCopy_scopes (SgNode* copy, SgCopyHelp & help) const;
788 virtual void fixupCopy_symbols (SgNode* copy, SgCopyHelp & help) const;
789 virtual void fixupCopy_references (SgNode* copy, SgCopyHelp & help) const;
790 /* */
791#else
792 virtual void fixupCopy(SgNode* copy, SgCopyHelp & help) const;
793#endif
794
795 /* name Source Position Information
796 \brief Support for source code position information of all IR nodes.
797
798 These are the virtual function definitions, they are overloaded for SgLocatedNode
799 and a few of the SgSupport IR nodes.
800 */
801 /* */
810 virtual Sg_File_Info* get_file_info(void) const { return nullptr; }
811
815 virtual Sg_File_Info* get_startOfConstruct(void) const {return nullptr;}
816
820 virtual Sg_File_Info* get_endOfConstruct(void) const { return nullptr; }
821 /* */
822
823 /* name Control flow graph public functions
824
825 These functions return control flow graph nodes for various positions
826 around a construct. */
827 /* */
828
829#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
834#endif
835
836#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
837 /* name Control flow graph view helper functions
838
839 These functions are used internally inside the control flow graph
840 view code. The public interface for this functionality is given
841 below this section. */
842 /* */
843
845 virtual unsigned int cfgIndexForEnd() const;
846
849 virtual bool cfgIsIndexInteresting(unsigned int index) const;
850
852 virtual unsigned int cfgFindChildIndex(SgNode* n);
853
855 virtual unsigned int cfgFindNextChildIndex(SgNode* n);
856
858 virtual std::vector<VirtualCFG::CFGEdge> cfgOutEdges(unsigned int index = false);
859
861 virtual std::vector<VirtualCFG::CFGEdge> cfgInEdges(unsigned int index = false);
862#endif
863 /* */
864
865 // DQ (1/31/2006): These must be built to be static access member functions (so they can't be built by ROSETTA).
866 /* name Function Type Information
867 Support for global view of function types used in ROSE.
868 */
869 /* */
873 static void set_globalFunctionTypeTable(SgFunctionTypeTable* globalFunctionTypeTable);
874 /* */
875
876 // DQ (7/22/2010): Added seperate type table to support construction of unique types.
880 static void set_globalTypeTable(SgTypeTable* globalTypeTable);
881
882 protected:
883 static std::vector<std::tuple<unsigned char*, unsigned, VariantT>> all_pools;
884 public:
885 static VariantT variantFromPool(SgNode const * n);
886
887 /* \brief Mangled name cache for improved performance of mangled name generation
888 This mangle name caching is implemented to support better performance.
889 */
890 // static std::map<SgNode*,std::string> & get_globalMangledNameMap();
891
899
908
909 protected:
910
918
919 private:
920 // Make the copy constructor private (to avoid it being used)
921 /* We have to make the copy constructor available so that the SgUnparse_Info
922 copy constructor can access it, I'm not clear if this is a good idea.
923 */
924 // SgNode(const SgNode &); /* private so it can't be used. */
925
927 SgNode & operator= (const SgNode &) = delete;
928
929public:
943 template<class T>
944 static typename std::enable_if<std::is_base_of<SgNode, T>::value, T*>::type
946 auto node = new T;
947 node->set_parent(parent);
948 return node;
949 }
950
960 template<class T>
961 T* initParentPointer(T *child, SgNode *parent) {
962 ASSERT_not_null(parent);
963 if (child) {
964#ifndef NDEBUG
965 auto toString = [](SgNode *node) {
966 if (node) {
967 return (boost::format("(%s*)%p") % node->class_name() % node).str();
968 } else {
969 return std::string("nullptr");
970 }
971 };
972
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()));
977#endif
978 child->set_parent(this);
979 }
980 return child;
981 }
982
1019 template<class T>
1020 typename std::enable_if<
1021 std::is_pointer<T>::value,
1022 void>::type
1023 changeChildPointer(T& edge, T const& child) {
1024#ifndef NDEBUG
1025 auto toString = [](SgNode *node) {
1026 if (node) {
1027 return (boost::format("(%s*)%p") % node->class_name() % node).str();
1028 } else {
1029 return std::string("nullptr");
1030 }
1031 };
1032#endif
1033
1034 if (child != edge) {
1035 // If there is an old child, check that it has the correct parent and then remove it.
1036 if (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);
1042 edge = nullptr;
1043 }
1044
1045 // If there is a new child, check its parent pointer and then insert it.
1046 if (child) {
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);
1052 edge = child;
1053 }
1054 }
1055 }
1056
1057 // This gets called for non-pointers, which is the situation for nodes that are only lists of other nodes. We're currently
1058 // not checking them because the ROSETTA-generated API has too many ways to get around this check, most of which make it
1059 // impossible to enforce constraints regarding the parent/child consistency. For example:
1060 //
1061 // node->children().clear(); // removes a whole bunch of children but doesn't clear their parent pointers
1062 // node->children()[i] = child; // changes the ith child, but doesn't clear the previous ith child's parent pointer
1063 // for (auto &tmp: node->children()) tmp = nullptr; // changes each child but doesn't clear parent pointers
1064 // ad nausiam...
1065 template<class T>
1066 typename std::enable_if<
1067 !std::is_pointer<T>::value,
1068 void>::type
1069 changeChildPointer(T& edge, T const& child) {
1070 edge = child;
1071 }
1075private:
1076 // This is called by the debugSerializationBegin and debugSerializationEnd that are in turn called at the beginning and end of
1077 // each AST node's serialization function. The implementation below uses two counters: classSerializationDepth shared by all
1078 // instances of this class, and objectSerializationDepth_ which is a per-instance counter. The relationship of these two
1079 // counters can tell us how deeply nested these recursive calls are, and which of those recursion levels are due to traversing
1080 // through the base classes versus traversing through data members. In the output, we use one character of indentation per
1081 // recursion level, with spaces (' ') representing recursion due to data members and dots ('.') representing recursion due to
1082 // base classes.
1083#if 0
1084 // Debugging version
1085 size_t objectSerializationDepth_ = 0; // incremented as we traverse through base classes
1086 void debugSerializationHelper(const char *className, bool isBegin) {
1087 static size_t classSerializationDepth = 0; // incremented by both base classes and data members
1088 if (isBegin) {
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_;
1095 } else {
1096 ASSERT_require2(classSerializationDepth > 0, className);
1097 ASSERT_require2(objectSerializationDepth_ > 0, className);
1098 --classSerializationDepth;
1099 --objectSerializationDepth_;
1100 }
1101 }
1102#else
1103 // Production version
1104 void debugSerializationHelper(const char*, bool) {}
1105#endif
1106
1107protected:
1137 virtual void destructorHelper() {}
1138
1139protected:
1147 virtual void debugSerializationBegin(const char *className) {
1148 debugSerializationHelper(className, true);
1149 }
1150 virtual void debugSerializationEnd(const char *className) {
1151 debugSerializationHelper(className, false);
1152 }
1155 public:
1156
1157
1158
1159// End of memberFunctionString
1160
1161
1162
1163
1164 public:
1165 SgNode* get_freepointer() const;
1166 void set_freepointer(SgNode* freepointer);
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178 public:
1179 virtual ~SgNode();
1180
1181
1182 public:
1183 SgNode();
1184
1185 protected:
1186// Start of memberFunctionString
1187SgNode* p_parent;
1188
1189// End of memberFunctionString
1190// Start of memberFunctionString
1191bool p_isModified;
1192
1193// End of memberFunctionString
1194// Start of memberFunctionString
1195bool p_containsTransformation;
1196
1197// End of memberFunctionString
1198// Start of memberFunctionString
1199SgNode* p_freepointer;
1200
1201// End of memberFunctionString
1202// Start of memberFunctionString
1203static SgFunctionTypeTable* p_globalFunctionTypeTable;
1204
1205// End of memberFunctionString
1206// Start of memberFunctionString
1207static SgTypeTable* p_globalTypeTable;
1208
1209// End of memberFunctionString
1210// Start of memberFunctionString
1211static std::map<SgNode*,std::string> p_globalMangledNameMap;
1212
1213// End of memberFunctionString
1214// Start of memberFunctionString
1215static std::map<std::string, uint64_t> p_shortMangledNameCache;
1216
1217// End of memberFunctionString
1218// Start of memberFunctionString
1219static std::unordered_map<SgNode*,std::string> p_globalQualifiedNameMapForNames;
1220
1221// End of memberFunctionString
1222// Start of memberFunctionString
1223static std::unordered_map<SgNode*,std::string> p_globalQualifiedNameMapForTypes;
1224
1225// End of memberFunctionString
1226// Start of memberFunctionString
1227static std::unordered_map<SgNode*,std::string> p_globalQualifiedNameMapForTemplateHeaders;
1228
1229// End of memberFunctionString
1230// Start of memberFunctionString
1231static std::unordered_map<SgNode*,std::string> p_globalTypeNameMap;
1232
1233// End of memberFunctionString
1234// Start of memberFunctionString
1235static std::map<SgNode*,std::unordered_map<SgNode*,std::string> > p_globalQualifiedNameMapForMapsOfTypes;
1236
1237// End of memberFunctionString
1238
1242 friend struct Rose::Traits::generated::describe_field_t<SgNode, bool,&SgNode::p_containsTransformation>;
1244
1245/* #line 21 "/workspace/src/ROSETTA/Grammar/grammarClassDeclarationMacros.macro" */
1246
1247
1248 };
1249#endif
1250
1251// postdeclarations for SgNode
1252
1253/* #line 1254 "../../../src/frontend/SageIII//SgNode.h" */
1254
1255/* #line 27 "/workspace/src/ROSETTA/Grammar/grammarClassDeclarationMacros.macro after subst for $POSTDECLARATIONS" */
1256
1257/* #line 28 "/workspace/src/ROSETTA/Grammar/grammarClassDeclarationMacros.macro" */
1258
1259
1260/* #line 1261 "../../../src/frontend/SageIII//SgNode.h" */
1261
1262#endif // ROSE_SgNode_H
1263
Class holding static data and functions supporting File I/O.
Definition AST_FILE_IO.h:19
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.
Definition sageCopy.h:26
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...
Definition SgNode.h:815
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...
Definition SgNode.h:820
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.
Definition SgNode.h:1150
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.
Definition SgNode.h:1023
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.
Definition SgNode.h:1147
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.
Definition SgNode.h:945
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...
Definition SgNode.h:810
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.
Definition SgNode.h:1069
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.
Definition SgNode.h:961
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.
Definition SgNode.h:1137
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.
Definition virtualCFG.h:70
The ROSE library.
void copy(const Word *src, const BitRange &srcRange, Word *dst, const BitRange &dstRange)
Copy some bits.