ROSE  0.9.9.139
atermSupport.h
1 
2 // Put non-generated Aterm support code here.
3 
4 // #include "rosePublicConfig.h"
5 
6 // #include "aterm1.h"
7 // #include "aterm2.h"
8 
9 #define LAZY_WRAPPING_MACRO false
10 
11 namespace AtermSupport
12  {
13  // DQ (10/5/2014): This is the part of the latest version of ATerm support (now generated by ROSETTA).
14 #if 0
15  class AtermToNodeConverter
16  {
17  public:
18  // std::map<std::string, std::list<LinkUpdater*> > idUpdates;
19 
20  // map<string, SgNode*> targetLocations;
21  std::map<std::string, SgScopeStatement*> translationScopeMap;
22  std::map<std::string, SgType*> translationTypeMap;
23  std::map<std::string, SgDeclarationStatement*> translationDeclarationMap;
24  std::map<std::string, SgInitializedName*> translationInitializedNameMap;
25 
26  void updateScopeMap (std::string key, SgScopeStatement* scope);
27  SgScopeStatement* lookupScope (std::string key);
28 
29  void updateDeclarationMap (std::string key, SgDeclarationStatement* scope);
30  SgDeclarationStatement* lookupDeclaration (std::string key);
31 
32  void updateTypeMap (std::string key, SgType* scope);
33  SgType* lookupType (std::string key);
34 
35  void updateInitializedNameMap (std::string key, SgInitializedName* scope);
36  SgInitializedName* lookupInitializedName (std::string key);
37 
38  SgNode* convertAtermToNode(ATerm term);
39 
40  private:
41  template <class TranslationMap, class TranslationMapElement>
42  void updateMap_support (std::string key, TranslationMap & translationMap, TranslationMapElement* node);
43 
44  template <class TranslationMap, class TranslationMapElement>
45  TranslationMapElement* lookupMap_support (std::string key, TranslationMap & tranlationMap);
46  };
47 #else
48  extern std::map<std::string, SgNode*> translationNodeMap;
49 
50  extern std::map<std::string, SgScopeStatement*> translationScopeMap;
51  extern std::map<std::string, SgType*> translationTypeMap;
52  extern std::map<std::string, SgDeclarationStatement*> translationDeclarationMap;
53  extern std::map<std::string, SgInitializedName*> translationInitializedNameMap;
54 #endif
55 
56  void initializeTypeSystem();
57 
58  std::string aterm_type_name( ATerm term );
59 
60  std::string uniqueId(SgNode* n);
61 
62  // This supports generation of strings from addresses (mostly so that the SgAsm support will compile).
63  // I don't think that Aterms have a data type for unsigned 64-bit integers.
64  std::string uniqueId(uint64_t n);
65 
66  // This supports generation of strings from rose_rva_t (so that the SgAsm support will compile).
67  // I don't think it is clear how to implement this function (but we can worry about the binary analysis
68  // use of Aterms later).
69  std::string uniqueId(const rose_rva_t & n);
70 
71  ATerm convertFileInfoToAterm(Sg_File_Info* fi);
72  Sg_File_Info* getAtermFileInfo(ATerm term, std::string annotationName);
73 
74  ATerm convertVectorToAterm(const std::vector<ATerm>& v, int start, int len);
75 
76  template <typename Iter>
77  ATerm convertRangeToAterm(Iter b, Iter e);
78 
79  template <typename Iter>
80  ATerm convertSgNodeRangeToAterm(Iter b, Iter e);
81 
82  std::string getShortVariantName(VariantT var);
83 
84  ATerm getTraversalChildrenAsAterm(SgNode* n);
85 
86  ATerm convertNodeToAterm(SgNode* n);
87 
88  ATerm getAtermAnnotation(ATerm term, char* annotation_name );
89 
90  // Function for reading aterms and converting them to ROSE AST IR nodes.
91  SgNode* generate_AST(ATerm & term);
92 
93  // Generate a list of aterms from the input aterm.
94  std::vector<ATerm> getAtermList(ATerm ls);
95 
96  std::string getAtermStringAttribute(ATerm term, const std::string & annotationName );
97  int getAtermIntegerAttribute(ATerm term, const std::string & annotationName );
98 
99  // DQ (10/8/2014): I don't think we need these (Aterm type system is not rich enough to justify these).
100  // int getAtermEnumAttribute(ATerm term, const std::string & annotationName );
101  // std::string getAtermNodeNameAttribute(ATerm term, const std::string & annotationName );
102 
103  // This function is special in that it accesses (internal) maps to lookup the SgNode
104  // using a sting that is saved as an annotation in the aterm and then as a key into the map.
105  // Note that this should work where we see declarations before they are referenced, but
106  // will likely have to be fixed up after the translation where this rule is relaxed in C++
107  // classes (which may refer to constructs before they are declared (and is always an issue)).
108  SgNode* getAtermNodeAttribute(ATerm term, const std::string & annotationName );
109 
110  SgType* getAtermTypeNodeAttribute (ATerm term, const std::string & annotationName );
111  SgScopeStatement* getAtermScopeNodeAttribute (ATerm term, const std::string & annotationName );
112 
113  // Not as clear how to implement this since it is difficult to inspect the class hierarhy in ROSETTA.
114  SgDeclarationStatement* getAtermDeclarationNodeAttribute (ATerm term, const std::string & annotationName );
115 
116  }
117 
118 
119 #ifdef ROSE_USE_ROSE_ATERM_SUPPORT
120 
121 template <typename Iter>
122 ATerm
123 AtermSupport::convertRangeToAterm(Iter b, Iter e)
124  {
125  ATermList ls = ATmakeList0();
126  for (; b != e; ++b)
127  {
128  ls = ATappend(ls, *b);
129  }
130 
131  return ATmake("<term>", ls);
132  }
133 
134 template <typename Iter>
135 ATerm AtermSupport::convertSgNodeRangeToAterm(Iter b, Iter e)
136  {
137  bool lazyWrapping = LAZY_WRAPPING_MACRO;
138 
139  ROSE_ASSERT(lazyWrapping == false);
140 
141  if ( (b != e) && (*b != NULL) )
142  {
143 #if 0
144  SgNode* parent = (*b)->get_parent();
145  if (parent == NULL)
146  {
147  printf ("warning: parent == NULL: *b = %p = %s \n",*b,(*b)->class_name().c_str());
148  }
149 #endif
150  // ROSE_ASSERT(parent != NULL);
151 #if 0
152  printf ("In AtermSupport::convertSgNodeRangeToAterm(): Building an ATerm list for (*b)->get_parent() = %p = %s \n",parent,(parent != NULL) ? parent->class_name().c_str() : "NULL");
153 #endif
154  }
155  else
156  {
157 #if 0
158  printf ("In AtermSupport::convertSgNodeRangeToAterm(): Building an empty list \n");
159 #endif
160  }
161 
162  ATermList ls = ATmakeList0();
163  for (; b != e; ++b)
164  {
165  ATerm child_term = NULL;
166  if (lazyWrapping == true)
167  {
168  child_term = ATmake("lazyWrap(<str>)","lazyWrap");
169  }
170  else
171  {
172 #if 0
173  printf ("In AtermSupport::convertSgNodeRangeToAterm(): Calling convertNodeToAterm() *b = %p = %s\n",*b,(*b != NULL) ? (*b)->class_name().c_str() : "NULL");
174 #endif
175  child_term = convertNodeToAterm(*b);
176 
177 #if 0
178  // I think we are generating invalid aterms in some cases.
179  int atermKind = ATgetType(child_term);
180  printf ("In AtermSupport::convertSgNodeRangeToAterm(): child_term: atermKind = %d = %s \n",atermKind,aterm_type_name(child_term).c_str());
181 #endif
182 #if 0
183  printf ("In AtermSupport::convertSgNodeRangeToAterm(): DONE: Calling convertNodeToAterm() *b = %p = %s \n",*b,(*b != NULL) ? (*b)->class_name().c_str() : "NULL");
184 #endif
185 #if 0
186  cout << "In AtermSupport::convertSgNodeRangeToAterm(): DONE: output child_term: -> " << ATwriteToString(child_term) << endl;
187 #endif
188  }
189 
190 #if 0
191  printf ("In AtermSupport::convertSgNodeRangeToAterm(): Calling ATappend() \n");
192 #endif
193  // ls = ATappend(ls,convertNodeToAterm(*b));
194  ls = ATappend(ls,child_term);
195 
196 #if 0
197  // I think we are generating invalid aterms in some cases.
198  int atermKind = ATgetType(ls);
199  // printf ("In AtermSupport::convertSgNodeRangeToAterm(): ATappend(): atermKind = %d = %s \n",atermKind,aterm_type_name(ls).c_str());
200  printf ("In AtermSupport::convertSgNodeRangeToAterm(): ATappend(): atermKind = %d \n",atermKind);
201 #endif
202 #if 0
203  printf ("In AtermSupport::convertSgNodeRangeToAterm(): DONE: Calling ATappend() \n");
204 #endif
205  }
206 
207 #if 0
208  printf ("In AtermSupport::convertSgNodeRangeToAterm(): building aterm to return \n");
209 #endif
210 
211  // return ATmake("<term>", ls);
212  ATerm returnTerm = ATmake("<term>", ls);
213 
214 #if 0
215  // I think we are generating invalid aterms in some cases.
216  int atermKind = ATgetType(returnTerm);
217  printf ("In AtermSupport::convertSgNodeRangeToAterm(): atermKind = %d = %s \n",atermKind,aterm_type_name(returnTerm).c_str());
218 #endif
219 #if 0
220  printf ("In AtermSupport::convertSgNodeRangeToAterm(): returnTerm = %p ls = %p \n",returnTerm,ls);
221 #endif
222 #if 0
223  cout << "AtermSupport::convertSgNodeRangeToAterm(): returning the aterm -> " << ATwriteToString(returnTerm) << endl;
224 #endif
225 
226  return returnTerm;
227  }
228 
229 // endif for ROSE_USE_ROSE_ATERM_SUPPORT
230 #endif
231 
This class represents the concept of a scope in C++ (e.g. global scope, fuction scope, etc.).
This class represents the base class for all types.
This class represents the location of the code associated with the IR node in the original source cod...
This class represents the notion of a declared variable.
This class represents the base class for all IR nodes within Sage III.
Definition: Cxx_Grammar.h:8322
A relative virtual address optionally associated with a SgAsmSection.
Definition: Cxx_Grammar.h:6819
virtual std::string class_name() const
returns a string representing the class name
SgNode * get_parent() const
Access function for parent node.
This class represents the concept of a declaration statement.