ROSE  0.9.6a
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
utility_functions.h
Go to the documentation of this file.
1 // utility_functions.h -- header file for the ROSE Optimizing Preprocessor
2 
3 #ifndef UTILITY_FUNCTIONS_H
4 #define UTILITY_FUNCTIONS_H
5 
6 #include "Cxx_Grammar.h"
7 class UnparseDelegate;
8 
9 #define BACKEND_VERBOSE_LEVEL 2
10 
11 // DQ (11/1/2009): replaced "version()" with separate "version_number()" and "version_message()" functions.
12 // returns a string containing the current version message (includes the version number).
13 std::string version_message();
14 
15 // DQ (11/1/2009): replaced "version()" with separate "version_number()" and "version_message()" functions.
16 // returns a string containing the current version number
17 std::string version_number();
18 
20 std::string rose_scm_version_id();
21 
23 time_t rose_scm_version_date();
24 
25 // DQ (7/3/2013): Added support to output pre-defined macro settings.
28 
29 
30 // Simple interface for ROSE (error codes are in SgProject.frontendErrorCode(), backendErrorCode() )
31 // tps : Need to make this function (DLL) public
32 ROSE_DLL_API SgProject* frontend ( int argc, char** argv, bool frontendConstantFolding = false );
33 ROSE_DLL_API SgProject* frontend ( const std::vector<std::string>& argv, bool frontendConstantFolding = false );
34 
35 // This builds a shell of a frontend SgProject with associated SgFile objects (but with empty
36 // SgGlobal objects) supporting only commandline processing and requiring the frontend to be
37 // called explicitly for each SgFile object. See tutorial/selectedFileTranslation.C for example.
38 SgProject* frontendShell ( int argc, char** argv);
39 ROSE_DLL_API SgProject* frontendShell ( const std::vector<std::string>& argv);
40 
41 // DQ (3/18/2006): Modified backend function interface to permit handling of user specified
42 // objects to control the formatting of code generation and the use of alternative code generation
43 // techniques (e.g. copy-based code generation).
44 // int backend ( SgProject* project );
45 ROSE_DLL_API int backend ( SgProject* project, UnparseFormatHelp *unparseFormatHelp = NULL, UnparseDelegate* unparseDelagate = NULL );
46 
47 // DQ (8/24/2009): This backend calls the backend compiler using the original input source file list.
48 // This is useful as a test code for testing ROSE for use on projects that target Compass or any
49 // other analysis only tool using ROSE. Called in tests/testAnalysis.C for example.
50 ROSE_DLL_API int backendCompilesUsingOriginalInputFile ( SgProject* project, bool compile_with_USE_ROSE_macro = false );
51 
52 // DQ (2/6/2010): This backend forces all code to be generated but still uses the beakend vendor
53 // compiler to compile the original code. This is a step between backendUsingOriginalInputFile(),
54 // which does not generate code; and backend() which generated code and compiles it. The use of
55 // this backend permits an intermediate test of robustness where the code that we generate might
56 // be generated incorrectly (usually with missing name qualification as required for a specific
57 // backend (vendor) compiler).
59 
60 //QY: new back end that performs only source-to-source translations
61 // of the original file. Furthermore, statements are copied from
62 // the original file if they are not changed
63 ROSE_DLL_API int copy_backend( SgProject* project, UnparseFormatHelp *unparseFormatHelp = NULL );
64 
65 // int globalBackendErrorCode = 0;
66 // int backend ( const SgProject & project, int & errorCode = globalBackendErrorCode);
67 // SgProject & frontend ( int argc, char * argv[] );
68 
69 ROSE_DLL_API void generatePDF ( const SgProject & project );
70 ROSE_DLL_API void generateDOT ( const SgProject & project, std::string filenamePostfix = "" );
71 
72 // DQ (9/1/2008): Added function to generate the compete AST when specificed with multiple files
73 // on the command line. This is the older default behavior of generateDOT (from last year, or so).
74 ROSE_DLL_API void generateDOT_withIncludes ( const SgProject & project, std::string filenamePostfix = "" );
75 ROSE_DLL_API void generateDOTforMultipleFile ( const SgProject & project, std::string filenamePostfix = "" );
76 
77 // DQ (6/14/2007): Support for whole AST graphs output with attributes (types, symbols, all edges, etc.)
78 // We define a default value for the maximum graph size (number of nodes).
79 ROSE_DLL_API void generateAstGraph ( const SgProject* project, int maxSize = 2000, std::string filenameSuffix = "" );
80 // void generateAstGraph ( const SgProject* project, int maxSize, std::string filenameSuffix = "", CustomMemoryPoolDOTGeneration::s_Filter_Flags* filter_flags = NULL)
81 
82 // output of EDG AST (useful for debugging connection to SAGE)
83 //void pdfPrintAbstractSyntaxTreeEDG ( SgFile *file );
84 // void generatePDFofEDG ( const SgProject & project );
85 
86 #ifndef SWIG
87 
88 //#include "rose.h"
89 //#include "../midend/astProcessing/DOTGeneration.h"
90 //#include "roseInternal.h"
91 //#include "../midend/astProcessing/AstDotGeneration.h"
92 //using namespace AstDOTGenerationExtended_Defaults;
93 //#include "../midend/astProcessing/AstDOTGeneration.h"
94 #include "AstDOTGeneration.h"
95 
96 template <typename ExtraNodeInfo_t = AstDOTGenerationExtended_Defaults::DefaultExtraNodeInfo, typename ExtraNodeOptions_t = AstDOTGenerationExtended_Defaults::DefaultExtraNodeOptions, typename ExtraEdgeInfo_t = AstDOTGenerationExtended_Defaults::DefaultExtraEdgeInfo, typename ExtraEdgeOptions_t = AstDOTGenerationExtended_Defaults::DefaultExtraEdgeOptions>
98 //void
99 //generateDOTExtended ( const SgProject & project, std::string filenamePostfix = "", ExtraNodeInfo_t eni = AstDOTGenerationExtended_Defaults::DefaultExtraNodeInfo(), ExtraNodeOptions_t eno = AstDOTGenerationExtended_Defaults::DefaultExtraNodeOptions(), ExtraEdgeInfo_t eei = AstDOTGenerationExtended_Defaults::DefaultExtraEdgeInfo(), ExtraEdgeOptions_t eeo = AstDOTGenerationExtended_Defaults::DefaultExtraEdgeOptions() );
100 
101 template <typename ExtraNodeInfo_t = AstDOTGenerationExtended_Defaults::DefaultExtraNodeInfo, typename ExtraNodeOptions_t = AstDOTGenerationExtended_Defaults::DefaultExtraNodeOptions, typename ExtraEdgeInfo_t = AstDOTGenerationExtended_Defaults::DefaultExtraEdgeInfo, typename ExtraEdgeOptions_t = AstDOTGenerationExtended_Defaults::DefaultExtraEdgeOptions>
103 
104 template <typename ExtraNodeInfo_t = AstDOTGenerationExtended_Defaults::DefaultExtraNodeInfo, typename ExtraNodeOptions_t = AstDOTGenerationExtended_Defaults::DefaultExtraNodeOptions, typename ExtraEdgeInfo_t = AstDOTGenerationExtended_Defaults::DefaultExtraEdgeInfo, typename ExtraEdgeOptions_t = AstDOTGenerationExtended_Defaults::DefaultExtraEdgeOptions>
106 
107 // endif for ifndef SWIG
108 #endif
109 
110 #ifndef SWIG
111 // DQ (3/10/2013): Swig has a problem with:
112 // src/roseSupport/utility_functions.h:138: Error: 'stripPathFromFileName' is multiply defined in the generated target language module in scope 'roseJNI'.
113 // src/util/stringSupport/string_functions.h:221: Error: Previous declaration of 'stripPathFromFileName'
114 // src/util/stringSupport/string_functions.h:223: Error: Previous declaration of 'getPathFromFileName'
115 // So exclude this code below.
116 
117 namespace ROSE
118  {
119  // This class serves as a catch all location for functions of general use within ROSE
120  // we have added variables that are set using command line parameters to avoid the use of
121  // global variables.
122 
123  // DQ (8/10/2004): This was moved to the SgFile a long time ago and should not be used any more)
124  // DQ (8/11/2004): Need to put this back so that there is a global concept of verbosity for all of ROSE.
125  // static int roseVerboseLevel;
126 
127  // These functions trim the header files from the unparsed output.
128  // static int isCutStart ( SgStatement *st );
129  // static int isCutEnd ( SgStatement *st );
130  // void ROSE_Unparse ( SgFile *f , std::ostream *of );
131 
132  // This function helps isolate the details of the UNIX strcmp function
133  // static int isSameName ( const std::string& s1, const std::string& s2 );
134  int containsString ( const std::string& masterString, const std::string& targetString );
135 
136  // DQ (9/5/2008): Try to remove these functions...
137  std::string getFileNameByTraversalBackToFileNode ( const SgNode* astNode );
138  // std::string getFileName ( const SgFile* file );
139 
140  // DQ (5/25/2005): Removed from ROSE class (since they are redundant with other uses)
141  std::string getFileName ( SgLocatedNode* locatedNodePointer ) ROSE_DEPRECATED_FUNCTION;
142  int getLineNumber ( SgLocatedNode* locatedNodePointer ) ROSE_DEPRECATED_FUNCTION;
143  int getColumnNumber ( SgLocatedNode* locatedNodePointer ) ROSE_DEPRECATED_FUNCTION;
145 
146  ROSE_DLL_API std::string getWorkingDirectory ();
147  ROSE_DLL_API std::string getSourceDirectory ( std::string fileNameWithPath );
148 
149  std::string getFileNameWithoutPath ( SgStatement* statementPointer );
150  ROSE_DLL_API std::string stripPathFromFileName ( const std::string& fileNameWithPath );
151 
152  ROSE_DLL_API std::string getPathFromFileName ( std::string fileNameWithPath );
153 
154  // DQ (9/8/2008): This is removed since it is redundant with the version in StringUtility.
155  // std::string stripFileSuffixFromFileName ( const std::string& fileNameWithSuffix ); //! get the name without the ".C"
156 
157  // std::string getPragmaString ( SgStatement *stmt );
158  // std::string getPragmaString ( SgExpression *expr );
159 
160  // SgPragma* getPragma ( SgExpression *expr );
161  // SgPragma* getPragma ( SgStatement *stmt );
162  // SgPragma* getPragma ( SgBinaryOp *binaryOperator );
163 
164  // std::string identifyVariant ( int Code );
165 
166  SgName concatenate ( const SgName & X, const SgName & Y );
167 
168  ROSE_DLL_API void usage (int status);
169 
170  void filterInputFile ( const std::string inputFileName, const std::string outputFileName );
171 
173  SgStatement* getPreviousStatement ( SgStatement *targetStatement );
174  SgStatement* getNextStatement ( SgStatement *targetStatement );
175 
176  // DQ (10/28/2013): Put the token sequence map here, it is set and accessed via member functions on the SgSourceFile IR node.
177  extern std::map<SgNode*,TokenStreamSequenceToNodeMapping*> tokenSubsequenceMap;
178 
179  // DQ (11/27/2013): Adding vector of nodes in the AST that defines the token unparsing AST frontier.
180  // extern std::vector<FrontierNode*> frontierNodes;
181  extern std::map<SgStatement*,FrontierNode*> frontierNodes;
182 
183  // DQ (11/27/2013): Adding adjacency information for the nodes in the token unparsing AST frontier.
184  extern std::map<SgNode*,PreviousAndNextNodeData*> previousAndNextNodeMap;
185 
186  // DQ (11/29/2013): Added to support access to multi-map of redundant mapping of frontier IR nodes to token subsequences.
187  extern std::multimap<int,SgStatement*> redundantlyMappedTokensToStatementMultimap;
188  extern std::set<int> redundantTokenEndingsSet;
189  };
190 
191 
192 // endif for ifndef SWIG
193 #endif
194 
195 #endif // ifndef UTILITY_FUNCTIONS_H
196 
197 
198 
199 
200 
201 
202