rtiHelpers.h

Go to the documentation of this file.
00001 #ifndef ROSE_RTIHELPERS_H
00002 #define ROSE_RTIHELPERS_H
00003 
00004 #include <string>
00005 #include <vector>
00006 #include <list>
00007 #include <set>
00008 #include <sstream>
00009 #include <iomanip>
00010 #include <boost/lexical_cast.hpp>
00011 
00012 
00013 // Helpful functions for Cxx_GrammarRTI.C
00014 // Probably should not be included anywhere else
00015 
00016 #if ROSE_USE_VALGRIND
00017 #include <valgrind/valgrind.h>
00018 #include <valgrind/memcheck.h>
00019 #include <stdio.h>
00020 static void doUninitializedFieldCheck(const char* fieldName, void* fieldPointer, size_t fieldSize, void* wholeObject, const char* className) {
00021   if (VALGRIND_CHECK_READABLE(fieldPointer, fieldSize)) {
00022     fprintf(stderr, "Warning: uninitialized field p_%s of object %p of class %s\n", fieldName, wholeObject, className);
00023   }
00024 }
00025 #endif
00026 
00027 template <typename T>
00028 static std::string toStringForRTI(const T& x) {
00029   std::ostringstream ss;
00030   ss << x;
00031   return ss.str();
00032 }
00033 
00034 template <typename T>
00035 static std::string toStringForRTI(const std::vector<T>& x) {
00036   std::ostringstream ss;
00037   ss << "[";
00038   for (typename std::vector<T>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << (*i);}
00039   ss << "]";
00040   return ss.str();
00041 }
00042 
00043 // DQ (8/8/2008): Added support for type used in binary file format support.
00044 template <typename T>
00045 static std::string toStringForRTI(const std::vector<std::pair<T,T> >& x) {
00046   std::ostringstream ss;
00047   ss << "[";
00048   for (typename std::vector<std::pair<T,T> >::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
00049   ss << "]";
00050   return ss.str();
00051 }
00052 
00053 static std::string toStringForRTI(const ExtentMap &x)
00054 {
00055     std::ostringstream ss;
00056     ss << "[";
00057     for (ExtentMap::const_iterator i=x.begin(); i!=x.end(); ++i) {
00058         if (i!=x.begin())
00059             ss << ", ";
00060         ss << i->first << "->" << i->second;
00061     }
00062     ss <<"]";
00063     return ss.str();
00064 }
00065 
00066 // DQ (8/29/2008): Added the support for the Robb's SgSharedVector class.
00067 template <typename T>
00068 static std::string toStringForRTI(const SgSharedVector<T>& x)
00069    {
00070      std::ostringstream ss;
00071      ss << "[";
00072 
00073      printf ("Warning: SgSharedVector iterator support is not finished! \n");
00074      // ROSE_ASSERT(false);
00075 
00076   // for (typename std::vector<T>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << (*i);}
00077 
00078      ss << "]";
00079      return ss.str();
00080    }
00081 
00082 static std::string toStringForRTI(const std::vector<bool>& x) {
00083   std::ostringstream ss;
00084   ss << "[";
00085   for (std::vector<bool>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << (*i ? "T" : "F");}
00086   ss << "]";
00087   return ss.str();
00088 }
00089 
00090 template <typename T>
00091 static std::string toStringForRTI(const std::list<T>& x) {
00092   std::ostringstream ss;
00093   ss << "[";
00094   for (typename std::list<T>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << (*i);}
00095   ss << "]";
00096   return ss.str();
00097 }
00098 
00099 template <typename T>
00100 static std::string toStringForRTI(const std::set<T>& x) {
00101   std::ostringstream ss;
00102   ss << "[";
00103   for (typename std::set<T>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << (*i);}
00104   ss << "]";
00105   return ss.str();
00106 }
00107 
00108 template <typename K, typename V>
00109 static std::string toStringForRTI(const std::map<K, V>& x) {
00110   std::ostringstream ss;
00111   ss << "[";
00112   for (typename std::map<K, V>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
00113   ss << "]";
00114   return ss.str();
00115 }
00116 
00117 // negara1 (06/27/2011): Added support for the map of including files (field p_preprocessorDirectivesAndCommentsList)
00118 template <typename K>
00119 static std::string toStringForRTI(const std::map<K, std::set<PreprocessingInfo*> >& x) {
00120   std::ostringstream ss;
00121   ss << "[";
00122   for (typename std::map<K, std::set<PreprocessingInfo*> >::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << toStringForRTI(i->second);}
00123   ss << "]";
00124   return ss.str();
00125 }
00126 
00127 // DQ (4/30/2009): Added new support for std::multimap.
00128 template <typename K, typename V>
00129 static std::string toStringForRTI(const std::multimap<K, V>& x) {
00130   std::ostringstream ss;
00131   ss << "[";
00132   for (typename std::multimap<K, V>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
00133   ss << "]";
00134   return ss.str();
00135 }
00136 
00137 #if 0
00138 static std::string toStringForRTI(const std::map<std::pair<int,std::pair<int,int> >, uint64_t > & x) {
00139   std::ostringstream ss;
00140   ss << "[";
00141 // for (std::vector<bool>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << (*i ? "T" : "F");}
00142   ss << "]";
00143   return ss.str();
00144 }
00145 #endif
00146 
00147 #if 0
00148 static std::string toStringForRTI(const std::map<uint64_t ,std::pair<int,std::pair<int,int> > > & x) {
00149   std::ostringstream ss;
00150   ss << "[";
00151 // for (std::vector<bool>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << (*i ? "T" : "F");}
00152   ss << "]";
00153   return ss.str();
00154 }
00155 #endif
00156 
00157 #if 1
00158 // #if !OLD_GRAPH_NODES
00159 //#ifdef ROSE_USE_NEW_GRAPH_NODES
00160 // DQ (8/18/2008): Added support for new Graph IR node.
00161 
00162 #ifdef ROSE_USING_GRAPH_IR_NODES_FOR_BACKWARD_COMPATABILITY
00163 // static std::string toStringForRTI(const SgGraphNodeDirectedGraphEdgeMultimapPtrList & x)
00164 static std::string toStringForRTI(const rose_graph_node_edge_hash_multimap & x)
00165 {
00166   std::ostringstream ss;
00167   ss << "[";
00168 // for (SgGraphNodeUndirectedGraphEdgeMultimapPtrList::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
00169   ss << "]";
00170   return ss.str();
00171 }
00172 #endif
00173 
00174 static std::string toStringForRTI(const rose_graph_integer_node_hash_map & x)
00175 {
00176   std::ostringstream ss;
00177   ss << "[";
00178 // for (SgGraphNodeUndirectedGraphEdgeMultimapPtrList::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
00179   ss << "]";
00180   return ss.str();
00181 }
00182 
00183 static std::string toStringForRTI(const rose_graph_integer_edge_hash_map & x)
00184 {
00185   std::ostringstream ss;
00186   ss << "[";
00187 // for (SgGraphNodeUndirectedGraphEdgeMultimapPtrList::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
00188   ss << "]";
00189   return ss.str();
00190 }
00191 
00192 static std::string toStringForRTI(const rose_graph_integer_edge_hash_multimap & x)
00193 {
00194   std::ostringstream ss;
00195   ss << "[";
00196 // for (SgGraphNodeUndirectedGraphEdgeMultimapPtrList::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
00197   ss << "]";
00198   return ss.str();
00199 }
00200 
00201 static std::string toStringForRTI(const rose_graph_string_integer_hash_multimap & x)
00202 {
00203   std::ostringstream ss;
00204   ss << "[";
00205 // for (rose_graph_string_integer_hash_multimap::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
00206   ss << "]";
00207   return ss.str();
00208 }
00209 
00210 static std::string toStringForRTI(const rose_graph_integerpair_edge_hash_multimap & x)
00211 {
00212   std::ostringstream ss;
00213   ss << "[";
00214 // for (rose_graph_string_integer_hash_multimap::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
00215   ss << "]";
00216   return ss.str();
00217 }
00218 
00219 #if 0
00220 // DQ (4/30/2009): Removed these in favor of the hash_multimap using the SgGraphEdge class.
00221 static std::string toStringForRTI(const rose_undirected_graph_hash_multimap & x)
00222 {
00223   std::ostringstream ss;
00224   ss << "[";
00225 // for (SgGraphNodeUndirectedGraphEdgeMultimapPtrList::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
00226   ss << "]";
00227   return ss.str();
00228 }
00229 #endif
00230 
00231 #if 0
00232 // DQ (4/30/2009): Removed these in favor of the hash_multimap using the SgGraphEdge class.
00233 static std::string toStringForRTI(const rose_directed_graph_hash_multimap & x)
00234 {
00235   std::ostringstream ss;
00236   ss << "[";
00237 // for (SgGraphNodeDirectedGraphEdgeMultimapPtrList::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
00238   ss << "]";
00239   return ss.str();
00240 }
00241 #endif
00242 
00243 #ifdef ROSE_USING_GRAPH_IR_NODES_FOR_BACKWARD_COMPATABILITY
00244 // DQ (8/18/2008): Added support for new Graph IR node.
00245 // static std::string toStringForRTI(const SgStringGraphNodeMapPtrList & x)
00246 static std::string toStringForRTI(const rose_graph_hash_multimap & x)
00247 {
00248   std::ostringstream ss;
00249   ss << "[";
00250 // for (SgStringGraphNodeMapPtrList::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
00251   ss << "]";
00252   return ss.str();
00253 }
00254 #endif
00255 
00256 #if 0
00257 // DQ (5/1/2009): This is no longer used and is replaced by an implementation using a hash_map.
00258 // DQ (8/18/2008): Added support for new Graph IR node.
00259 // static std::string toStringForRTI(const SgIntegerGraphNodeMapPtrList & x)
00260 static std::string toStringForRTI(const std::map<int, SgGraphNode*> & x)
00261 {
00262   std::ostringstream ss;
00263   ss << "[";
00264 // for (SgIntegerGraphNodeMapPtrList::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
00265   for (std::map<int, SgGraphNode*>::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
00266   ss << "]";
00267   return ss.str();
00268 }
00269 #endif
00270 
00271 #if 0
00272 // DQ (4/25/2009): This is now redundant...
00273 // DQ (8/18/2008): Added support for new Graph IR node.
00274 // static std::string toStringForRTI(const SgGraphNodeUndirectedGraphEdgeMultimapPtrList & x)
00275 static std::string toStringForRTI(const rose_undirected_graph_hash_multimap & x)
00276 {
00277   std::ostringstream ss;
00278   ss << "[";
00279 // for (SgGraphNodeUndirectedGraphEdgeMultimapPtrList::const_iterator i = x.begin(); i != x.end(); ++i) {if (i != x.begin()) ss << ", "; ss << i->first << "->" << i->second;}
00280   ss << "]";
00281   return ss.str();
00282 }
00283 #endif
00284 #endif
00285 //#endif
00286 // end condition new_graph
00287 
00288 static std::string toStringForRTI(const SgAccessModifier& m) {
00289   return m.displayString();
00290 }
00291 
00292 static std::string toStringForRTI(const SgUPC_AccessModifier& m) {
00293   return m.displayString();
00294 }
00295 
00296 static std::string toStringForRTI(const SgConstVolatileModifier& m) {
00297   return m.displayString();
00298 }
00299 
00300 static std::string toStringForRTI(const SgElaboratedTypeModifier& m) {
00301   return m.displayString();
00302 }
00303 
00304 static std::string toStringForRTI(const SgTypeModifier& m) {
00305   return m.displayString();
00306 }
00307 
00308 static std::string toStringForRTI(const SgStorageModifier& m) {
00309   return m.displayString();
00310 }
00311 
00312 static std::string toStringForRTI(const SgDeclarationModifier& m) {
00313   return m.displayString();
00314 }
00315 
00316 static std::string toStringForRTI(const SgFunctionModifier& m) {
00317   return m.displayString();
00318 }
00319 
00320 static std::string toStringForRTI(const SgSpecialFunctionModifier& m) {
00321   return m.displayString();
00322 }
00323 
00324 static std::string toStringForRTI(const SgName& n) {
00325   return n.getString();
00326 }
00327 
00328 static std::string toStringForRTI(const SgFunctionModifier::opencl_work_group_size_t & x) {
00329   std::ostringstream os;
00330   os << " ( " << x.x << ", "  << x.y << ", " << x.z << " ) ";
00331   return os.str();
00332 }
00333 
00334 #if 0
00335 // None of these seem to be used
00336 
00337 template <typename Sym>
00338 static std::string toStringForRTISymbol(Sym* sym) {
00339   std::ostringstream ss;
00340   ss << sym;
00341   if (sym) {
00342     ss << ": varsym " << sym->get_name().str() << " declared at 0x" << std::hex << (sym->get_declaration());
00343   }
00344   return ss.str();
00345 }
00346 
00347 static std::string toStringForRTI(SgVariableSymbol* sym) {return toStringForRTISymbol(sym);}
00348 static std::string toStringForRTI(SgFunctionSymbol* sym) {return toStringForRTISymbol(sym);}
00349 static std::string toStringForRTI(SgMemberFunctionSymbol* sym) {return toStringForRTISymbol(sym);}
00350 
00351 static std::string toStringForRTI(const SgSymbolTable&) {return "<no output operator defined for this type>";}
00352 static std::string toStringForRTI(const SgSymbolHashBase::iterator&) {return "<no output operator defined for this type>";}
00353 #endif
00354 
00355 void doRTI(const char* fieldNameBase, void* fieldPtr, size_t fieldSize, void* thisPtr, const char* className, const char* typeString, const char* fieldName, const std::string& fieldContents, RTIMemberData& memberData);
00356 
00357 #endif // ROSE_RTIHELPERS_H

Generated on Sat May 19 00:53:07 2012 for ROSE by  doxygen 1.4.7