ROSE 0.11.145.247
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 <boost/format.hpp>
33
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>
41#endif
42
43#include <Sawyer/CommandLine.h>
44#include <Sawyer/Interval.h>
45#include <Sawyer/IntervalSet.h>
46
47#include "processSupport.h"
48#define __builtin_constant_p(exp) (0)
49
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> // deprecated
56#include <Rose/BinaryAnalysis/RegisterDescriptor.h>
57#include <Rose/BinaryAnalysis/InstructionMap.h>
58#include <ROSE_NELMTS.h>
59#endif
60
61#include <Rose/Constants.h>
62#include <sageHash.h>
63#include <sageTraversal.h>
64#include <sageRti.h>
65#include <sageCopy.h>
66#include <sageMemory.h>
67#include <Cxx_GrammarVariants.h>
68#include <Cxx_GrammarStorageClasses.h>
69#include <virtualCFG.h>
70
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; } } }
73
74#ifdef ROSE_ENABLE_BINARY_ANALYSIS
75// Version numbers for SgAsm* nodes. Used for backward compatibility. */
76BOOST_CLASS_VERSION(SgAsmInstruction, 1);
77#endif
78
81class AstAttribute;
84
85// DQ (3/18/2006): Forward declarations of classes used to control and tailor the code generation.
86class UnparseDelegate;
87class UnparseFormatHelp;
88
89// DQ (4/32/2006): g++ 4.0.2 requires a forward declaration for this (a friend class declaration is not sufficient!)
90class AstSpecificDataManagingClassStorageClass;
91
92
93
94/* #line 13 "/workspace/src/ROSETTA/Grammar/grammarClassDeclarationMacros.macro after subst for $PREDECLARATIONS" */
95
96/* #line 14 "/workspace/src/ROSETTA/Grammar/grammarClassDeclarationMacros.macro" */
97
98#if 1
99// Class Definition for SgNode
100class ROSE_DLL_API SgNode
101 {
102 public:
103
104
105/* #line 106 "../../../src/frontend/SageIII//SgNode.h" */
106
107 virtual SgNode* copy ( SgCopyHelp& help) const;
108// Start of memberFunctionString
109/* #line 1 "/workspace/src/ROSETTA/Grammar/Common.code" */
110
111// *** COMMON CODE SECTION BEGINS HERE ***
112
113 public:
114
115 // DQ (3/25/3006): I put this back in because it had the logic for where the copy function required
116 // and not required which is required to match the other aspects of the copy mechanism code generation.
117 // Specifically it is a problem to declare the copy function everywhere because it is not implemented
118 // for the SgSymbol IR nodes. I'm not clear why it is not implemented for these IR nodes.
119 /* \brief Copies AST (whole subtree, depending on the SgCopyHelp class */
120 // virtual SgNode* copy ( const SgCopyHelp & help) const;
121
123 virtual std::string class_name() const;
124
126 virtual VariantT variantT() const; // MS: new variant used in tree traversal
127
129 // King84 (2010.08.16): Moved this to an enum to save space, since it's only used at compiler-time anyway.
130 // static const VariantT static_variant = V_SgNode;
131 enum { static_variant = V_SgNode };
132
133 /* the generated cast function */
135 ROSE_DLL_API friend SgNode* isSgNode( SgNode * s );
136
138 ROSE_DLL_API friend const SgNode* isSgNode( const SgNode * s );
139
140 // ******************************************
141 // * Memory Pool / New / Delete
142 // ******************************************
143
144 public:
146 static const unsigned pool_size; //
148 static std::vector<unsigned char *> pools; //
150 static SgNode * next_node; //
151
153 static unsigned long initializeStorageClassArray(SgNodeStorageClass *); //
154
156 static void clearMemoryPool(); //
157 static void deleteMemoryPool(); //
158
160 static void extendMemoryPoolForFileIO(); //
161
163 static SgNode * getPointerFromGlobalIndex(unsigned long); //
165 static SgNode * getPointerFromGlobalIndex(AstSpecificDataManagingClass *, unsigned long); //
166
168 static unsigned long getNumberOfValidNodesAndSetGlobalIndexInFreepointer(unsigned long); //
170 static void resetValidFreepointers(); //
172 static unsigned long getNumberOfLastValidPointer(); //
173
174
175#if defined(INLINE_FUNCTIONS)
177 inline void *operator new (size_t size);
178#else
180 void *operator new (size_t size);
181#endif
183 void operator delete (void* pointer, size_t size);
184
185 // DQ (4/5/2007): This is not the correct operator that we want, but appears to be required to compile ROSE with ROSE.
186 void operator delete (void* pointer)
187 {
188 // This is the generated delete operator...
189 SgNode::operator delete (pointer,sizeof(SgNode));
190 }
191
193 static size_t numberOfNodes();
194
196 static size_t memoryUsage();
197
198 // End of scope which started in IR nodes specific code
199 /* */
200
201 /* name Internal Functions
202 \brief Internal functions ... incomplete-documentation
203
204 These functions have been made public as part of the design, but they are suggested for internal use
205 or by particularly knowledgeable users for specialized tools or applications.
206
207 \internal We could not make these private because they are required by user for special purposes. And
208 it would be unwieldy to have many of the internal classes in ROSE be explicitly defined as friends.
209
210 */
211
212 // MS: 02/12/02 container of pointers to AST successor nodes used in the traversal
213 // overridden in every class by *generated* implementation
215 virtual std::vector<SgNode*> get_traversalSuccessorContainer() const;
216 // MS: 06/28/02 container of names of variables or container indices
217 // used used in the traversal to access AST successor nodes
218 // overridden in every class by *generated* implementation
221 virtual std::vector<std::string> get_traversalSuccessorNamesContainer() const;
222
223 // GB (09/25/2007): Functions for index-based access to traversal successors; these are hopefully a lot faster
224 // than all the vector copies. The implementation for these functions is generated for each class.
226 virtual size_t get_numberOfTraversalSuccessors() const;
228 virtual SgNode *get_traversalSuccessorByIndex(size_t idx) const;
230 virtual size_t get_childIndex(SgNode *child) const;
231
232#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
233 // MS: 08/16/2002 method for generating RTI information
235 virtual RTIReturnType roseRTI();
236#endif
237 /* */
238
239
240
241 /* name Deprecated Functions
242 \brief Deprecated functions ... incomplete-documentation
243
244 These functions have been deprecated from use.
245 */
246 /* */
247
249 virtual const char* sage_class_name() const ROSE_DEPRECATED_FUNCTION;
250
251 // JJW (10/16/2008): Changed to a single function in Node.code, and put
252 // getVariant() in #if 0 block to prevent confusing Doxygen
253#if 0
255 virtual int variant() const ROSE_DEPRECATED_FUNCTION;
257 // virtual int getVariant() const ROSE_DEPRECATED_FUNCTION;
258#endif
259 /* */
260
261
262
263
264 public:
265 /* name Traversal Support Functions
266 \brief Traversal support functions ... incomplete-documentation
267
268 These functions have been made public as part of the design, but they are suggested for internal use
269 or by particularly knowledgable users for specialized tools or applications.
270 */
271 /* */
272
273 // DQ (11/26/2005): Support for visitor pattern mechanims
274 // (inferior to ROSE traversal mechanism, experimental).
278
279 /* DXN (08/09/2010): support for the classic visitor pattern done in GoF */
281 virtual void accept (ROSE_VisitorPattern & visitor);
282
283 // DQ (12/26/2005): Support for traversal based on the memory pool
287
291
292 // DQ (2/9/2006): Added to support traversal over single representative of each IR node
293 // This traversal helps support internal tools that call static member functions.
294 // note: this function operates on the memory pools.
298 /* */
299
300 public:
301 /* NodeId support functions */
303 static SgNode* getNodeByNodeId(VariantT variantT, size_t poolIdx, size_t itemIdx);
306 static SgNode* getNodeByNodeIdInternal(size_t poolIdx, size_t itemIdx);
309 static std::string getNodeIdString(SgNode* sgnode);
310 static std::string getNodeIdStringInternal(SgNode* sgnode);
311
312 public:
313 /* name Memory Allocation Functions
314 \brief Memory allocations functions ... incomplete-documentation
315
316 These functions have been made public as part of the design, but they are suggested for internal use
317 or by particularly knowledgable users for specialized tools or applications.
318 */
319 /* */
320
331 virtual bool isInMemoryPool();
332
344
345 // DQ (4/30/2006): Modified to be a const function.
360 virtual std::vector<std::pair<SgNode*,std::string> > returnDataMemberPointers() const;
361
372
384 virtual long getChildIndex( SgNode* childNode ) const;
385
386 // DQ (9/2/2015): Since this function is generated by ROSETTA, we can't define the
387 // comment here (changed to be a C style comment and not be a doxygen comment).
388 /* \brief Constructor for use by AST File I/O Mechanism
389
390 This constructor permits the IR node to be rebuilt from the contiguously arranged data in memory
391 which obtained via fast binary file I/O from disk.
392 */
393 // SgNode( SgNodeStorageClass& source );
394
395
396
397
398
399 // JH (10/24/2005): methods added to support the ast file IO
400 private:
401
402 /* name AST Memory Allocation Support Functions
403 \brief Memory allocations support....
404
405 These functions handle the low leve support of the memory allocation scheme which permits IR nodes to be allocated
406 in large contiguous blocks to reduce memory fragmentation, improve performance, support specialized access (AST traversals),
407 and support the AST File I/O Mechanism.
408 */
409 /* */
410
411 /* JH (10/24/2005): Two typedefs. The TestType notes the type every pointer is cast to before
412 we compare them. Since I had several problems with this, I decided to make a typdef to ensure
413 that I use the same type everywhere, if any changes are made. THe second one declares the type
414 (actually unsigned long) where teh pointer address gets converted to. On 64 bit platforms this
415 might got changed, but unfortunatly, the return types are still unsigned longs. There exists
416 a correspinding one in the AST_FILE_IO class!
417 */
418 // DQ (9/2/2015): This typedef is no longer used, we can't define the
419 // comment here (changed to be a C style comment and not be a doxygen comment).
420 /* \brief Typedef used for low level memory access.
421 */
422 // typedef unsigned char* TestType;
423
424 // DQ (9/2/2015): This typedef is no longer used, we can't define the
425 // comment here (changed to be a C style comment and not be a doxygen comment).
426 /* \brief Typedef used to hold memory addresses as values.
427 */
428 // typedef unsigned long AddressType;
429
430
431
432 // necessary, to have direct access to the p_freepointer and the private methods !
434 friend class AST_FILE_IO;
435
437 friend class SgNodeStorageClass;
438
440 friend class AstSpecificDataManagingClass;
441
443 friend class AstSpecificDataManagingClassStorageClass;
444 public:
446 SgNode( const SgNodeStorageClass& source );
447
448 // private: // JJW hack
449 /*
450 name AST Memory Allocation Support Variables
451 Memory allocations support variables
452
453 These variables handle the low level support of the memory allocation scheme which permits IR nodes to be allocated
454 in large contiguous blocks to reduce memory fragmentation, improve performance, support specialized access (AST traversals),
455 and support the AST File I/O Mechanism.
456 */
457 /* */
458
459 public:
460
461 // DQ (11/21/2009): Added function to add new Regular Expression attributes and return pointer
462 // to current node (so that it will work cleanly with build functions to specify patterns).
463 // virtual SgNode* addRegExpAttribute();
470
471#ifndef _MSC_VER
472// Rasmussen (04/17/2019): Support for ATerms has been deprecated as it is no longer needed
473// and likely never fully implemented nor tested. Files remain in the src tree but are no
474// longer built.
475#define BUILD_ATERM_SUPPORT 0
476 #if BUILD_ATERM_SUPPORT
477 #ifdef ROSE_USE_ROSE_ATERM_SUPPORT
478 // DQ (10/4/2014): Adding ATerm support to ROSE.
488 // Rasmussen (1/7/2019): Added to kill warning messages of overridden virtual function
489 virtual ATerm generate_ATerm();
490
492 virtual void generate_ATerm_Annotation(ATerm & term);
493 #endif
494 #endif // BUILD_ATERM_SUPPORT
495#endif
496 // These can't be virtual functions since we don't yet know what IR node to build (until we have read the aterm).
497 // virtual generate_AST(ATerm & term);
498 // virtual void read_ATerm_Annotation(ATerm & term);
499
500// *** COMMON CODE SECTION ENDS HERE ***
501
502
503// End of memberFunctionString
504// Start of memberFunctionString
505/* #line 72 "/workspace/src/ROSETTA/Grammar/Node.code" */
506
507 public:
508
515 void set_isModified( bool isModified );
516
521 void set_containsTransformation( bool containsTransformation );
522
523
529 bool get_isModified() const;
530
536
537#if 0
538 // DQ (5/2/2021): I think we need a flag to record when a transformation is contained directly in the current file.
543 void set_containsTransformationRelativeToNodeFile( bool containsTransformationRelativeToNodeFile );
544
549 bool get_containsTransformationRelativeToNodeFile() const;
550#endif
552 void set_parent ( SgNode* parent );
553
556
557 // DQ (3/4/2022): Added access function for p_parent for debugging.
560
562 bool isChild ( SgNode* node ) const;
563
564 // DQ (4/4/2006): Added optional parameter to customize unparsing
566 // virtual std::string unparseToString(SgUnparse_Info* info = NULL) const;
567 // Jeremiah (11/9/2007): The default value is not recognized by gdb.
568 virtual std::string unparseToString(SgUnparse_Info* info) const;
569
570 // DQ (9/6/2010): Move this to the source file (we want to eliminate function definitions in header files).
571 // The existence of this function addresses a bug in gdb (see comment from Jeremiah (11/9/2007) above).
572 // inline std::string unparseToString() const { return this->unparseToString(NULL); }
573 std::string unparseToString() const;
574
577
586 static std::vector<std::string> buildCommandLineToSubstituteTransformationFile( const std::vector<std::string>& argv, std::string newFileName );
587
588 // JJW (10/16/2008): Replace variant() by variantT() and a cast (the
589 // numbers are the same, but the enumerator names are different)
590 int variant() const ROSE_DEPRECATED_FUNCTION {return (int)this->variantT();}
591
592 // AS (10/22/2007): build function to return class hierachy subtree of a VariantT
593 static std::vector<VariantT> getClassHierarchySubTreeFunction( VariantT v);
594 static void getClassHierarchySubTreeFunction( VariantT v, std::vector<VariantT>&);
595
601 bool get_isVisited () const ROSE_DEPRECATED_FUNCTION;
602
607 void set_isVisited ( bool isVisited ) ROSE_DEPRECATED_FUNCTION;
608
613 static std::map<SgNode*,std::string> & get_globalMangledNameMap();
614
617 static void clearGlobalMangledNameMap();
618
624 static std::map<std::string, uint64_t> & get_shortMangledNameCache();
625
626
632 static std::map<SgNode*,std::string> & get_globalQualifiedNameMapForNames();
633
639 static void set_globalQualifiedNameMapForNames ( const std::map<SgNode*,std::string> & X );
640
647 static std::map<SgNode*,std::string> & get_globalQualifiedNameMapForTypes();
648
655 static void set_globalQualifiedNameMapForTypes ( const std::map<SgNode*,std::string> & X );
656
657 // DQ (3/13/2019): Added name qualification support for references to types than can embed many types.
664 static std::map<SgNode*,std::map<SgNode*,std::string> > & get_globalQualifiedNameMapForMapsOfTypes();
665
666 // DQ (3/13/2019): Added name qualification support for references to types than can embed many types.
673 static void set_globalQualifiedNameMapForMapsOfTypes ( const std::map<SgNode*,std::map<SgNode*,std::string> > & X );
674
684 static std::map<SgNode*,std::string> & get_globalQualifiedNameMapForTemplateHeaders();
685
690 static void set_globalQualifiedNameMapForTemplateHeaders ( const std::map<SgNode*,std::string> & X );
691
698 static std::map<SgNode*,std::string> & get_globalTypeNameMap();
699
705 static void set_globalTypeNameMap ( const std::map<SgNode*,std::string> & X );
706
707 /* name Persistant Attribute Mechanism
708
709 This is the persistant attribute mechanism for attaching attributed to IR nodes across
710 multiple passes. Note that these attributes are persistant in that they are preserved
711 if the AST is written out to a file and read in from a file. However, virtual function
712 in the user-defined class derived from the AstAttribute must be defined for the attribute
713 to be defined across the boundary of File I/O (simple pack and unpack functions). More
714 sophisticated mechanisms are available within the AstAttributeMechanism object
715 (e.g iterating though attributes, etc; get_attributeMechanism() is available if direct
716 access is required, however mostly only internal tools use this lower level support).
717
718 \internal This used to be a public data member, but has been changed to be a protected
719 pointer instead. The functional interface of the AstAttributeMechanism is presevered
720 but some of the names and the syntax for calling the interface have changed. The
721 pointer to the AstAttributeMechanism is now generated by ROSETTA.
722 */
723 /* */
725 virtual void addNewAttribute(std::string s,AstAttribute* a);
727 virtual AstAttribute* getAttribute(std::string s) const;
729 virtual void updateAttribute(std::string s,AstAttribute* a); // formerly called: replace in AstAttributeMechanism
734 virtual void setAttribute(std::string s,AstAttribute* a);
736 virtual void removeAttribute(std::string s);
738 virtual bool attributeExists(std::string s) const;
740 virtual int numberOfAttributes() const;
741
749 virtual AstAttributeMechanism* get_attributeMechanism() const;
756 virtual void set_attributeMechanism(AstAttributeMechanism* a);
757 /* */
758
759#if ALT_FIXUP_COPY
760 /* name AST Copy Support Functions
761
762 Support for IR node specific fixup of copy operation.
763 This function helps reset scopes and build untraversed parts of the
764 AST that are difficult to have be constructed using the automatically
765 generated copy functions.
766
767 \implementation These functions are used internally inside the AST copy mechanism.
768 The public interface for this functionality is given below this section.
769 */
770 /* */
771 virtual void fixupCopy_scopes (SgNode* copy, SgCopyHelp & help) const;
772 virtual void fixupCopy_symbols (SgNode* copy, SgCopyHelp & help) const;
773 virtual void fixupCopy_references (SgNode* copy, SgCopyHelp & help) const;
774 /* */
775#else
776 virtual void fixupCopy(SgNode* copy, SgCopyHelp & help) const;
777#endif
778
779 /* name Source Position Information
780 \brief Support for source code position information of all IR nodes.
781
782 These are the virtual function definitions, they are overloaded for SgLocatedNode
783 and a few of the SgSupport IR nodes.
784 */
785 /* */
794 virtual Sg_File_Info* get_file_info(void) const { return nullptr; }
795
799 virtual Sg_File_Info* get_startOfConstruct(void) const {return nullptr;}
800
804 virtual Sg_File_Info* get_endOfConstruct(void) const { return nullptr; }
805 /* */
806
807 /* name Control flow graph public functions
808
809 These functions return control flow graph nodes for various positions
810 around a construct. */
811 /* */
812
813#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
818#endif
819
820#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
821 /* name Control flow graph view helper functions
822
823 These functions are used internally inside the control flow graph
824 view code. The public interface for this functionality is given
825 below this section. */
826 /* */
827
829 virtual unsigned int cfgIndexForEnd() const;
830
833 virtual bool cfgIsIndexInteresting(unsigned int index) const;
834
836 virtual unsigned int cfgFindChildIndex(SgNode* n);
837
839 virtual unsigned int cfgFindNextChildIndex(SgNode* n);
840
842 virtual std::vector<VirtualCFG::CFGEdge> cfgOutEdges(unsigned int index = false);
843
845 virtual std::vector<VirtualCFG::CFGEdge> cfgInEdges(unsigned int index = false);
846#endif
847 /* */
848
849 // DQ (1/31/2006): These must be built to be static access member functions (so they can't be built by ROSETTA).
850 /* name Function Type Information
851 Support for global view of function types used in ROSE.
852 */
853 /* */
857 static void set_globalFunctionTypeTable(SgFunctionTypeTable* globalFunctionTypeTable);
858 /* */
859
860 // DQ (7/22/2010): Added seperate type table to support construction of unique types.
864 static void set_globalTypeTable(SgTypeTable* globalTypeTable);
865
866 protected:
867 static std::vector<std::tuple<unsigned char*, unsigned, VariantT>> all_pools;
868 public:
869 static VariantT variantFromPool(SgNode const * n);
870
871 /* \brief Mangled name cache for improved performance of mangled name generation
872 This mangle name caching is implemented to support better performance.
873 */
874 // static std::map<SgNode*,std::string> & get_globalMangledNameMap();
875
883
892
893 protected:
894
902
903 private:
904 // Make the copy constructor private (to avoid it being used)
905 /* We have to make the copy constructor available so that the SgUnparse_Info
906 copy constructor can access it, I'm not clear if this is a good idea.
907 */
908 // SgNode(const SgNode &); /* private so it can't be used. */
909
911 SgNode & operator= (const SgNode &) = delete;
912
913public:
927 template<class T>
928 static typename std::enable_if<std::is_base_of<SgNode, T>::value, T*>::type
930 auto node = new T;
931 node->set_parent(parent);
932 return node;
933 }
934
944 template<class T>
945 T* initParentPointer(T *child, SgNode *parent) {
946 ASSERT_not_null(parent);
947 if (child) {
948#ifndef NDEBUG
949 auto toString = [](SgNode *node) {
950 if (node) {
951 return (boost::format("(%s*)%p") % node->class_name() % node).str();
952 } else {
953 return std::string("nullptr");
954 }
955 };
956
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()));
961#endif
962 child->set_parent(this);
963 }
964 return child;
965 }
966
1003 template<class T>
1004 typename std::enable_if<
1005 std::is_pointer<T>::value,
1006 void>::type
1007 changeChildPointer(T& edge, T const& child) {
1008#ifndef NDEBUG
1009 auto toString = [](SgNode *node) {
1010 if (node) {
1011 return (boost::format("(%s*)%p") % node->class_name() % node).str();
1012 } else {
1013 return std::string("nullptr");
1014 }
1015 };
1016#endif
1017
1018 if (child != edge) {
1019 // If there is an old child, check that it has the correct parent and then remove it.
1020 if (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);
1026 edge = nullptr;
1027 }
1028
1029 // If there is a new child, check its parent pointer and then insert it.
1030 if (child) {
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);
1036 edge = child;
1037 }
1038 }
1039 }
1040
1041 // This gets called for non-pointers, which is the situation for nodes that are only lists of other nodes. We're currently
1042 // not checking them because the ROSETTA-generated API has too many ways to get around this check, most of which make it
1043 // impossible to enforce constraints regarding the parent/child consistency. For example:
1044 //
1045 // node->children().clear(); // removes a whole bunch of children but doesn't clear their parent pointers
1046 // node->children()[i] = child; // changes the ith child, but doesn't clear the previous ith child's parent pointer
1047 // for (auto &tmp: node->children()) tmp = nullptr; // changes each child but doesn't clear parent pointers
1048 // ad nausiam...
1049 template<class T>
1050 typename std::enable_if<
1051 !std::is_pointer<T>::value,
1052 void>::type
1053 changeChildPointer(T& edge, T const& child) {
1054 edge = child;
1055 }
1059private:
1060 // This is called by the debugSerializationBegin and debugSerializationEnd that are in turn called at the beginning and end of
1061 // each AST node's serialization function. The implementation below uses two counters: classSerializationDepth shared by all
1062 // instances of this class, and objectSerializationDepth_ which is a per-instance counter. The relationship of these two
1063 // counters can tell us how deeply nested these recursive calls are, and which of those recursion levels are due to traversing
1064 // through the base classes versus traversing through data members. In the output, we use one character of indentation per
1065 // recursion level, with spaces (' ') representing recursion due to data members and dots ('.') representing recursion due to
1066 // base classes.
1067#if 0
1068 // Debugging version
1069 size_t objectSerializationDepth_ = 0; // incremented as we traverse through base classes
1070 void debugSerializationHelper(const char *className, bool isBegin) {
1071 static size_t classSerializationDepth = 0; // incremented by both base classes and data members
1072 if (isBegin) {
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_;
1079 } else {
1080 ASSERT_require2(classSerializationDepth > 0, className);
1081 ASSERT_require2(objectSerializationDepth_ > 0, className);
1082 --classSerializationDepth;
1083 --objectSerializationDepth_;
1084 }
1085 }
1086#else
1087 // Production version
1088 void debugSerializationHelper(const char*, bool) {}
1089#endif
1090
1091protected:
1121 virtual void destructorHelper() {}
1122
1123protected:
1131 virtual void debugSerializationBegin(const char *className) {
1132 debugSerializationHelper(className, true);
1133 }
1134 virtual void debugSerializationEnd(const char *className) {
1135 debugSerializationHelper(className, false);
1136 }
1139 public:
1140
1141
1142
1143// End of memberFunctionString
1144
1145
1146
1147
1148 public:
1149 SgNode* get_freepointer() const;
1150 void set_freepointer(SgNode* freepointer);
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162 public:
1163 virtual ~SgNode();
1164
1165
1166 public:
1167 SgNode();
1168
1169 protected:
1170// Start of memberFunctionString
1171SgNode* p_parent;
1172
1173// End of memberFunctionString
1174// Start of memberFunctionString
1175bool p_isModified;
1176
1177// End of memberFunctionString
1178// Start of memberFunctionString
1179bool p_containsTransformation;
1180
1181// End of memberFunctionString
1182// Start of memberFunctionString
1183SgNode* p_freepointer;
1184
1185// End of memberFunctionString
1186// Start of memberFunctionString
1187static SgFunctionTypeTable* p_globalFunctionTypeTable;
1188
1189// End of memberFunctionString
1190// Start of memberFunctionString
1191static SgTypeTable* p_globalTypeTable;
1192
1193// End of memberFunctionString
1194// Start of memberFunctionString
1195static std::map<SgNode*,std::string> p_globalMangledNameMap;
1196
1197// End of memberFunctionString
1198// Start of memberFunctionString
1199static std::map<std::string, uint64_t> p_shortMangledNameCache;
1200
1201// End of memberFunctionString
1202// Start of memberFunctionString
1203static std::map<SgNode*,std::string> p_globalQualifiedNameMapForNames;
1204
1205// End of memberFunctionString
1206// Start of memberFunctionString
1207static std::map<SgNode*,std::string> p_globalQualifiedNameMapForTypes;
1208
1209// End of memberFunctionString
1210// Start of memberFunctionString
1211static std::map<SgNode*,std::string> p_globalQualifiedNameMapForTemplateHeaders;
1212
1213// End of memberFunctionString
1214// Start of memberFunctionString
1215static std::map<SgNode*,std::string> p_globalTypeNameMap;
1216
1217// End of memberFunctionString
1218// Start of memberFunctionString
1219static std::map<SgNode*,std::map<SgNode*,std::string> > p_globalQualifiedNameMapForMapsOfTypes;
1220
1221// End of memberFunctionString
1222
1226 friend struct Rose::Traits::generated::describe_field_t<SgNode, bool,&SgNode::p_containsTransformation>;
1228
1229/* #line 21 "/workspace/src/ROSETTA/Grammar/grammarClassDeclarationMacros.macro" */
1230
1231
1232 };
1233#endif
1234
1235// postdeclarations for SgNode
1236
1237/* #line 1238 "../../../src/frontend/SageIII//SgNode.h" */
1238
1239/* #line 27 "/workspace/src/ROSETTA/Grammar/grammarClassDeclarationMacros.macro after subst for $POSTDECLARATIONS" */
1240
1241/* #line 28 "/workspace/src/ROSETTA/Grammar/grammarClassDeclarationMacros.macro" */
1242
1243
1244/* #line 1245 "../../../src/frontend/SageIII//SgNode.h" */
1245
1246#endif // ROSE_SgNode_H
1247
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:799
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:804
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:1134
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:1007
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:1131
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:929
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:794
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:1053
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:945
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:1121
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.