ROSE 0.11.145.147
sageCopy.h
1#ifndef ROSE_sageCopy_H
2#define ROSE_sageCopy_H
3
4#include <map>
5#include <vector>
6
26 {
27 public:
28 // STL map type
29 typedef std::map<const SgNode*,SgNode*> copiedNodeMapType;
30
31 private:
32 // DQ (10/8/2007): Added support for the depth to be kept track of in the AST copy mechansim.
34 int depth;
35
36 // This is mostly used for SgSymbol IR nodes (but will likely be used for other IR nodes in the future.
38 copiedNodeMapType copiedNodeMap;
39
40 public:
41
42 // STL map iterator type
43 typedef copiedNodeMapType::iterator copiedNodeMapTypeIterator;
44
45 virtual SgNode *copyAst( const SgNode *n ) = 0;
46
47 // Default constructor (required to initialize the depth
48 SgCopyHelp() : depth(0) {}
49
50 // Defined the virtual destructor
51 virtual ~SgCopyHelp() {}
52
53 // DQ (10/8/2007): Access functions for the depth (inlined for performance).
54 int get_depth() { return depth; }
55 void incrementDepth() { depth++; }
56 void decrementDepth() { depth--; }
57 copiedNodeMapType & get_copiedNodeMap() { return copiedNodeMap; }
58
59 // Reset the state saved
60 void clearState() { depth = 0; copiedNodeMap.clear(); }
61
62 // Added things that generate symbols to the state (could be SgDeclarationStatement or SgInitializedName objects).
63 void insertCopiedNodePair( const SgNode* key, SgNode* value );
64
65 };
66
67
72 {
73 public:
74 SgNode *copyAst( const SgNode *n ) { return const_cast<SgNode *>(n); }
75 };
76
77
85class ROSE_DLL_API SgTreeCopy : public SgCopyHelp
86 {
87 public:
88 SgNode *copyAst( const SgNode *n );
89 };
90
91// PC (8/3/2006): Support for subnode capturing
98template <class CopyType>
99class SgCapturingCopy : public CopyType
100 {
101 protected:
102 std::vector<SgNode *> origList;
103 std::vector<SgNode *> copyList;
104 public:
105 SgCapturingCopy( std::vector<SgNode *> origList, const CopyType &base = CopyType() )
106 // : origList(origList), CopyType(base)
107 : CopyType(base), origList(origList), copyList(origList.size())
108 { }
109 virtual ~SgCapturingCopy() { }
110 SgNode *copyAst( const SgNode *n )
111 {
112 SgNode *newNode = CopyType::copyAst(n);
113 int listSize = origList.size();
114 for (int i = 0; i < listSize; i++)
115 {
116 if (origList[i] == n)
117 {
118 copyList[i] = newNode;
119 }
120 }
121 return newNode;
122 }
123 const std::vector<SgNode *> &get_copyList()
124 {
125 return copyList;
126 }
127 };
128
129#endif
Supporting template class for "capturing" copies of the AST.
Definition sageCopy.h:100
Supporting class from copy mechanism within ROSE.
Definition sageCopy.h:26
This class represents the base class for all IR nodes within Sage III.
Supporting class for "Shallow" copies of the AST. This class supports only shallow copies of the AST.
Definition sageCopy.h:72
Supporting class for "Deep" copies of the AST.
Definition sageCopy.h:86