ROSE  0.9.6a
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
support.h
Go to the documentation of this file.
1 /******************************************
2  * Category: DFA
3  * DefUse Analysis Declaration
4  * created by tps in Feb 2007
5  *****************************************/
6 
7 #ifndef __DFAnalysis_support_HXX_LOADED__
8 #define __DFAnalysis_support_HXX_LOADED__
9 //#include "rose.h"
10 #include <string>
11 
12 // A set of utility functions
13 class Support {
14  public:
15 
16  /**********************************************************
17  * Convert anything to a string
18  *********************************************************/
19  template<typename T>
20  std::string ToString(T t) {
21  std::ostringstream myStream; //creates an ostringstream object
22  myStream << t << std::flush;
23  return(myStream.str()); //returns the string form of the stringstream object
24  }
25 
26  /**********************************************************
27  * Resolve Boolean Value to String
28  *********************************************************/
29  std::string resBool(bool val) {
30  if (val)
31  return "true";
32  return "false";
33  }
34 
35  /**********************************************************
36  * Check if an element is contained in a vector
37  *********************************************************/
38  template <typename T>
39  bool isContainedinVector(T filterNode, std::vector<T> worklist) {
40  bool contained = false;
41  for (typename std::vector<T >::const_iterator l = worklist.begin(); l != worklist.end(); ++l) {
42  T aNode = *l;
43  if (aNode == filterNode)
44  contained = true;
45  }
46  return contained;
47  }
48 
49 
50 
51  /* *****************************************
52  * retrieve a sepcific name for functionNodes
53  * must be the same for all retrievals, so that
54  * analyses work.
55  * *****************************************/
56 #if 1
57  // DQ (6/25/2011): Moved function definition to source file (function definitions should not be in the header files).
58  std::string getAppName(SgFunctionDeclaration* functionDeclaration);
59 #else
60  // std::string Support::getAppName(SgFunctionDeclaration* functionDeclaration);
61  ::std::string getAppName(SgFunctionDeclaration* functionDeclaration) {
62  std::string nodeNameApp = "";
63  std::vector<SgNode*> children = functionDeclaration->get_parameterList()->get_traversalSuccessorContainer();
64  for (unsigned int i=0; i< children.size(); i++) {
65  SgInitializedName* initName = (SgInitializedName*)children[i];
66  nodeNameApp = nodeNameApp + ""+initName->get_type()->unparseToString();
67  if (i!=(children.size()-1))
68  nodeNameApp = nodeNameApp + ", ";
69  // yed can not handle & signs.. replacing
70  while (nodeNameApp.find("&")!=std::string::npos) {
71  int pos = nodeNameApp.find("&");
72  nodeNameApp.replace(pos,1,"?");
73  }
74  }
75  std::string retVal = "("+nodeNameApp+")"; //+"-"+NodeToString(functionDeclaration);
76  return retVal;
77  }
78 #endif
79 
80  std::string getFileNameString(std::string src) {
81  return src;
82  }
83 
84 #if 1
85  // DQ (6/25/2011): Moved function definition to source file (function definitions should not be in the header files).
86  std::string getFullName(SgFunctionDefinition* functionDef);
87 #else
88 // std::string Support::getFullName(SgFunctionDefinition* functionDef);
89  std::string getFullName(SgFunctionDefinition* functionDef) {
90  SgFunctionDeclaration* functionDeclaration = functionDef->get_declaration();
91  ::std::string fullName = functionDeclaration->get_qualified_name().str();
92 
93  if ((fullName.find("std::") != std::string::npos) ||
94  (fullName.find("__") != std::string::npos) ||
95  (fullName.find("operator") != std::string::npos)
96  ) return ""; // Explicitly ignore all nodes in the ::std namespace
97 
98  std::string filename = getFileNameString(functionDeclaration->get_file_info()->get_filename());
99  if ((filename.find("/usr/") != std::string::npos)
100  ) return ""; // Explicitly ignore all nodes in the ::std namespace
101  fullName = fullName+getAppName(functionDeclaration);
102  return fullName;
103  }
104 #endif
105 };
106 
107 #endif