ROSE 0.11.145.380
utility_functions.h
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"
7class 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).
13std::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
17std::string version_number();
18
20unsigned int rose_boost_version_id();
21
23std::string rose_boost_version_path();
24
25// DQ (7/3/2013): Added support to output pre-defined macro settings.
27void outputPredefinedMacros();
28
29
32// tps : Need to make this function (DLL) public
33ROSE_DLL_API SgProject* frontend ( int argc, char** argv, bool frontendConstantFolding)
34 ROSE_DEPRECATED("use frontend(int, char**, SgProject::constant_folding_enum)");
35ROSE_DLL_API SgProject* frontend ( const std::vector<std::string>& argv, bool frontendConstantFolding)
36 ROSE_DEPRECATED("use frontend(const std::vector<std::string>&, SgProject::constant_folding_enum)");
37
38ROSE_DLL_API SgProject* frontend ( int argc, char** argv, SgProject::constant_folding_enum = SgProject::e_original_expressions_only );
39ROSE_DLL_API SgProject* frontend ( const std::vector<std::string>& argv, SgProject::constant_folding_enum = SgProject::e_original_expressions_only );
41
42// DQ (4/17/2015): After discussion with Liao, Markus, and Pei-Hung, we have agreed that
43// we want to support multiple SgProject IR nodes. So in addition to the SgProject* frontend()
44// function we will in the future support:
45// 1) A SgProject member function "frontend()" that can be used to generate a new SgFile in
46// an existing SgProject.
47// 2) A SgBuilder function for building an empty SgProject (without files).
48// 3) We will remove the use of the SageInterface::getProject() (which asserts that there
49// is only one SgProject).
50
51// This builds a shell of a frontend SgProject with associated SgFile objects (but with empty
52// SgGlobal objects) supporting only commandline processing and requiring the frontend to be
53// called explicitly for each SgFile object. See tutorial/selectedFileTranslation.C for example.
54SgProject* frontendShell ( int argc, char** argv);
55ROSE_DLL_API SgProject* frontendShell ( const std::vector<std::string>& argv);
56
57// DQ (3/18/2006): Modified backend function interface to permit handling of user specified
58// objects to control the formatting of code generation and the use of alternative code generation
59// techniques (e.g. copy-based code generation).
60// int backend ( SgProject* project );
61//
62// WARNING: If a non-null unparseFormatHelp is specified then backend will unconditionally delete it. Therefore, the caller
63// must have allocated it on the heap or else strange errors will result.
64ROSE_DLL_API int backend ( SgProject* project, UnparseFormatHelp *unparseFormatHelp = NULL, UnparseDelegate* unparseDelegate = NULL );
65
66// DQ (8/24/2009): This backend calls the backend compiler using the original input source file list.
67// This is useful as a test code for testing ROSE for use on projects that target Compass or any
68// other analysis only tool using ROSE. Called in tests/nonsmoke/functional/testAnalysis.C for example.
69ROSE_DLL_API int backendCompilesUsingOriginalInputFile ( SgProject* project, bool compile_with_USE_ROSE_macro = false );
70
71// DQ (2/6/2010): This backend forces all code to be generated but still uses the backend vendor
72// compiler to compile the original code. This is a step between backendUsingOriginalInputFile(),
73// which does not generate code; and backend() which generated code and compiles it. The use of
74// this backend permits an intermediate test of robustness where the code that we generate might
75// be generated incorrectly (usually with missing name qualification as required for a specific
76// backend (vendor) compiler).
77ROSE_DLL_API int backendGeneratesSourceCodeButCompilesUsingOriginalInputFile ( SgProject* project );
78
79//QY: new back end that performs only source-to-source translations
80// of the original file. Furthermore, statements are copied from
81// the original file if they are not changed
82ROSE_DLL_API int copy_backend( SgProject* project, UnparseFormatHelp *unparseFormatHelp = NULL );
83
84// int globalBackendErrorCode = 0;
85// int backend ( const SgProject & project, int & errorCode = globalBackendErrorCode);
86// SgProject & frontend ( int argc, char * argv[] );
87
88ROSE_DLL_API void generatePDF ( const SgProject & project );
89
90// DQ (12/20/2018): Added option to exclude template instantiations which make the graphs smaller and tractable t manage for larger C++ applications.
91ROSE_DLL_API void generateDOT ( const SgProject & project, std::string filenamePostfix = "", bool excludeTemplateInstantiations = false );
92
93// DQ (9/22/2017): Adding support that is can work with any IR node, so that we can generated DOT files on untyped ASTs.
94// I prefer the API that takes a SgNode pointer.
95// ROSE_DLL_API void generateDOT ( SgNode* node, std::string baseFilename, std::string filenamePostfix = "" );
96ROSE_DLL_API void generateDOT ( SgNode* node, std::string filename );
97
98// DQ (9/1/2008): Added function to generate the compete AST when specificed with multiple files
99// on the command line. This is the older default behavior of generateDOT (from last year, or so).
100ROSE_DLL_API void generateDOT_withIncludes ( const SgProject & project, std::string filenamePostfix = "" );
101ROSE_DLL_API void generateDOTforMultipleFile ( const SgProject & project, std::string filenamePostfix = "" );
102
103// DQ (6/14/2007): Support for whole AST graphs output with attributes (types, symbols, all edges, etc.)
104// We define a default value for the maximum graph size (number of nodes).
105ROSE_DLL_API void generateAstGraph ( const SgProject* project, int maxSize = 2000, std::string filenameSuffix = "" );
106// void generateAstGraph ( const SgProject* project, int maxSize, std::string filenameSuffix = "", CustomMemoryPoolDOTGeneration::s_Filter_Flags* filter_flags = NULL)
107
108// output of EDG AST (useful for debugging connection to SAGE)
109//void pdfPrintAbstractSyntaxTreeEDG ( SgFile *file );
110// void generatePDFofEDG ( const SgProject & project );
111
112#ifndef SWIG
113
114//#include "rose.h"
115//#include "../midend/astProcessing/DOTGeneration.h"
116//#include "roseInternal.h"
117//#include "../midend/astProcessing/AstDotGeneration.h"
118//using namespace AstDOTGenerationExtended_Defaults;
119//#include "../midend/astProcessing/AstDOTGeneration.h"
120#include "AstDOTGeneration.h"
121
122template <typename ExtraNodeInfo_t = AstDOTGenerationExtended_Defaults::DefaultExtraNodeInfo, typename ExtraNodeOptions_t = AstDOTGenerationExtended_Defaults::DefaultExtraNodeOptions, typename ExtraEdgeInfo_t = AstDOTGenerationExtended_Defaults::DefaultExtraEdgeInfo, typename ExtraEdgeOptions_t = AstDOTGenerationExtended_Defaults::DefaultExtraEdgeOptions>
124//void
125//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() );
126
127template <typename ExtraNodeInfo_t = AstDOTGenerationExtended_Defaults::DefaultExtraNodeInfo, typename ExtraNodeOptions_t = AstDOTGenerationExtended_Defaults::DefaultExtraNodeOptions, typename ExtraEdgeInfo_t = AstDOTGenerationExtended_Defaults::DefaultExtraEdgeInfo, typename ExtraEdgeOptions_t = AstDOTGenerationExtended_Defaults::DefaultExtraEdgeOptions>
129
130template <typename ExtraNodeInfo_t = AstDOTGenerationExtended_Defaults::DefaultExtraNodeInfo, typename ExtraNodeOptions_t = AstDOTGenerationExtended_Defaults::DefaultExtraNodeOptions, typename ExtraEdgeInfo_t = AstDOTGenerationExtended_Defaults::DefaultExtraEdgeInfo, typename ExtraEdgeOptions_t = AstDOTGenerationExtended_Defaults::DefaultExtraEdgeOptions>
132
133// endif for ifndef SWIG
134#endif
135
136#ifndef SWIG
137// DQ (3/10/2013): Swig has a problem with:
138// src/roseSupport/utility_functions.h:138: Error: 'stripPathFromFileName' is multiply defined in the generated target language module in scope 'roseJNI'.
139// src/util/stringSupport/string_functions.h:221: Error: Previous declaration of 'stripPathFromFileName'
140// src/util/stringSupport/string_functions.h:223: Error: Previous declaration of 'getPathFromFileName'
141// So exclude this code below.
142
143namespace Rose
144 {
145 // This class serves as a catch all location for functions of general use within ROSE
146 // we have added variables that are set using command line parameters to avoid the use of
147 // global variables.
148
149 // DQ (3/6/2017): Adding ROSE options data structure to support frontend and backend options such as:
150 // 1) output of warnings from the EDG (or other) frontend.
151 // 2) output of notes from the EDG (or other) frontend.
152 // 3) output of warnings from the backend compiler.
153 // The reason for this options clas is to support tools that would want to suppress warnings from ROSE,
154 // and still also permit compilers that would be implemented using ROSE to have the full range of output
155 // from EDG (or other frontends) to control notes and warnings.
157 {
158 private:
159 bool frontend_notes;
160 bool frontend_warnings;
161 bool backend_notes;
162 bool backend_warnings;
163
164 public:
165 ROSE_DLL_API Options();
166 ROSE_DLL_API Options(const Options & X);
167 ROSE_DLL_API Options & operator= (const Options & X);
168
169 // Access functions for options API.
170 ROSE_DLL_API bool get_frontend_notes();
171 ROSE_DLL_API void set_frontend_notes(bool flag);
172 ROSE_DLL_API bool get_frontend_warnings();
173 ROSE_DLL_API void set_frontend_warnings(bool flag);
174 ROSE_DLL_API bool get_backend_notes();
175 ROSE_DLL_API void set_backend_notes(bool flag);
176 ROSE_DLL_API bool get_backend_warnings();
177 ROSE_DLL_API void set_backend_warnings(bool flag);
178 };
179
180 // Global variable (in this rose namespace) to permit multiple parts of ROSE to access consistant information on options.
181 ROSE_DLL_API extern Options global_options;
182
183 // DQ (8/10/2004): This was moved to the SgFile a long time ago and should not be used any more)
184 // DQ (8/11/2004): Need to put this back so that there is a global concept of verbosity for all of ROSE.
185 // static int roseVerboseLevel;
186
187 // These functions trim the header files from the unparsed output.
188 // static int isCutStart ( SgStatement *st );
189 // static int isCutEnd ( SgStatement *st );
190 // void ROSE_Unparse ( SgFile *f , std::ostream *of );
191
192 // This function helps isolate the details of the UNIX strcmp function
193 // static int isSameName ( const std::string& s1, const std::string& s2 );
194 int containsString ( const std::string& masterString, const std::string& targetString );
195
196 // DQ (9/5/2008): Try to remove these functions...
197 std::string getFileNameByTraversalBackToFileNode ( const SgNode* astNode );
198 // std::string getFileName ( const SgFile* file );
199
200 // DQ (5/25/2005): Removed from ROSE class (since they are redundant with other uses)
201 std::string getFileName ( SgLocatedNode* locatedNodePointer ) ROSE_DEPRECATED_FUNCTION;
202 int getLineNumber ( SgLocatedNode* locatedNodePointer ) ROSE_DEPRECATED_FUNCTION;
203 int getColumnNumber ( SgLocatedNode* locatedNodePointer ) ROSE_DEPRECATED_FUNCTION;
204 bool isPartOfTransformation( SgLocatedNode* locatedNodePointer ) ROSE_DEPRECATED_FUNCTION;
205
206 ROSE_DLL_API std::string getWorkingDirectory ();
207 ROSE_DLL_API std::string getSourceDirectory ( std::string fileNameWithPath );
208
209 std::string getFileNameWithoutPath ( SgStatement* statementPointer );
210 ROSE_DLL_API std::string utility_stripPathFromFileName ( const std::string& fileNameWithPath );
211
212 ROSE_DLL_API std::string getPathFromFileName ( std::string fileNameWithPath );
213
214 // DQ (9/8/2008): This is removed since it is redundant with the version in StringUtility.
215 // std::string stripFileSuffixFromFileName ( const std::string& fileNameWithSuffix ); //! get the name without the ".C"
216
217 // std::string getPragmaString ( SgStatement *stmt );
218 // std::string getPragmaString ( SgExpression *expr );
219
220 // SgPragma* getPragma ( SgExpression *expr );
221 // SgPragma* getPragma ( SgStatement *stmt );
222 // SgPragma* getPragma ( SgBinaryOp *binaryOperator );
223
224 // std::string identifyVariant ( int Code );
225
226 SgName concatenate ( const SgName & X, const SgName & Y );
227
228 ROSE_DLL_API void usage (int status);
229
230 void filterInputFile ( const std::string inputFileName, const std::string outputFileName );
231
233 SgStatement* getPreviousStatement ( SgStatement *targetStatement , bool climbOutScope = true);
234 SgStatement* getNextStatement ( SgStatement *targetStatement );
235
236 // DQ (9/27/2018): We need to build multiple maps, one for each file (to support token based unparsing for multiple files,
237 // such as what is required when using the unparsing header files feature).
238 // DQ (10/28/2013): Put the token sequence map here, it is set and accessed via member functions on the SgSourceFile IR node.
239 // extern std::map<SgNode*,TokenStreamSequenceToNodeMapping*> tokenSubsequenceMap;
240 extern std::map<int,std::map<SgNode*,TokenStreamSequenceToNodeMapping*>* > tokenSubsequenceMapOfMaps;
241
242 // DQ (1/19/2021): This is part of moving to a new map that uses the SgSourceFile pointer instead of the fild_id.
243 extern std::map<SgSourceFile*,std::map<SgNode*,TokenStreamSequenceToNodeMapping*>* > tokenSubsequenceMapOfMapsBySourceFile;
244
245 // DQ (5/27/2021): This is required for the token-based unparsing, specifically for knowing when to
246 // unparse the trailing whitespace at the end of the last statement in a scope to the end of the scope.
247 extern std::map<SgSourceFile*,std::map<SgScopeStatement*,std::pair<SgStatement*,SgStatement*> > > firstAndLastStatementsToUnparseInScopeMapBySourceFile;
248
249 // DQ (11/27/2013): Adding vector of nodes in the AST that defines the token unparsing AST frontier.
250 // extern std::vector<FrontierNode*> frontierNodes;
251 // extern std::map<SgStatement*,FrontierNode*> frontierNodes;
252 extern std::map<int,std::map<SgStatement*,FrontierNode*>*> frontierNodesMapOfMaps;
253
254 // DQ (11/27/2013): Adding adjacency information for the nodes in the token unparsing AST frontier.
255 // extern std::map<SgNode*,PreviousAndNextNodeData*> previousAndNextNodeMap;
256 extern std::map<int,std::map<SgNode*,PreviousAndNextNodeData*>*> previousAndNextNodeMapOfMaps;
257
258 // DQ (11/29/2013): Added to support access to multi-map of redundant mapping of frontier IR nodes to token subsequences.
259 // extern std::multimap<int,SgStatement*> redundantlyMappedTokensToStatementMultimap;
260 // extern std::set<int> redundantTokenEndingsSet;
261 extern std::map<int,std::multimap<int,SgStatement*>*> redundantlyMappedTokensToStatementMapOfMultimaps;
262 extern std::map<int,std::set<int>*> redundantTokenEndingsMapOfSets;
263
264 // DQ (11/20/2015): Provide a statement to use as a key in the token sequence map to get representative whitespace.
265 // extern std::map<SgScopeStatement*,SgStatement*> representativeWhitespaceStatementMap;
266 extern std::map<int,std::map<SgScopeStatement*,SgStatement*>*> representativeWhitespaceStatementMapOfMaps;
267
268 // DQ (11/30/2015): Provide a statement to use as a key in the macro expansion map to get info about macro expansions.
269 // extern std::map<SgStatement*,MacroExpansion*> macroExpansionMap;
270 extern std::map<int,std::map<SgStatement*,MacroExpansion*>*> macroExpansionMapOfMaps;
271
272 // DQ (10/29/2018): Build a map for the unparser to use to locate SgIncludeFile IR nodes.
273 extern std::map<std::string, SgIncludeFile*> includeFileMapForUnparsing;
274
275 // DQ (5/8/2021): Added support for source file (header file) specific scope-based reporting on containsTransformation information.
276 // This may or may not be required to be a multi-map.
277 // extern std::map<SgIncludeFile*,std::map<SgScopeStatement*,bool>*> containsTransformationMap;
278
279 // DQ (3/5/2017): Added general IR node specific message stream to support debugging message from the ROSE IR nodes.
280 extern Sawyer::Message::Facility ir_node_mlog;
281
282 void initDiagnostics();
283
284 // DQ (11/25/2020): These are the boolean variables that are computed in the function compute_language_kind()
285 // and inlined via the SageInterface::is_<language kind>_language() functions. This fixes a significant
286 // performacne bug that was identified by Matt Sottile. First indications of this problem were from HPCToolKit,
287 // when it reported that there were large ammounts of time spent in the memory pool traversals, but the results
288 // were not clear since we could not trace that to the SageInterface::is_<language kind>_language() functions
289 // directly. Matt was able to identify the root cause of the problem. It turns out the that the
290 // SageInterface::is_<language kind>_language() functions are implemented using a memory pool traversal of the
291 // SgSourceFile (and SgBinaryFile, when binary analysis is enabled at configure time). The new implementation
292 // supports these boolean values to be inlined via the SageInterface::is_<language kind>_language() functions.
293 // And the compute_language_kind() function is called from the:
294 // SgFile* determineFileType ( vector<string> argv, int & nextErrorCode, SgProject* project );
295 // contained in the sage_support.C file. This function is the single point at whcuh all of the SgFile IR nodes
296 // (including SgSourceFile, and SgBinaryFile) are generated.
297
298 // Note: the semantics is that there is at least one of the language kind files processed by ROSE, across all
299 // SgFile objects across all SgProject objects.
300 extern bool is_Ada_language;
301 extern bool is_C_language;
302 extern bool is_Cobol_language;
303 extern bool is_OpenMP_language;
304 extern bool is_UPC_language;
305 extern bool is_UPC_dynamic_threads;
306 extern bool is_C99_language;
307 extern bool is_Cxx_language;
308 extern bool is_Java_language;
309 extern bool is_Jvm_language;
310 extern bool is_Jovial_language;
311 extern bool is_Fortran_language;
312 extern bool is_CAF_language;
313 extern bool is_PHP_language;
314 extern bool is_Python_language;
315 extern bool is_Cuda_language;
316 extern bool is_OpenCL_language;
317 extern bool is_binary_executable;
318 };
319
320
321// endif for ifndef SWIG
322#endif
323
324#endif // ifndef UTILITY_FUNCTIONS_H
Collection of streams.
Definition Message.h:1606
This class represents the notion of an expression or statement which has a position within the source...
This class represents strings within the IR nodes.
This class represents the base class for all IR nodes within Sage III.
This class represents a source project, with a list of SgFile objects and global information about th...
This class represents the notion of a statement.
The ROSE library.
SgStatement * getPreviousStatement(SgStatement *targetStatement, bool climbOutScope=true)
Functions to move to SgStatement object in SAGE III later.
ROSE_DLL_API std::string getSourceDirectory(std::string fileNameWithPath)
get the current directory
ROSE_DLL_API std::string getPathFromFileName(std::string fileNameWithPath)
get the filename from the full filename
std::string getFileNameWithoutPath(SgStatement *statementPointer)
get the sourceDirectory directory
SgName concatenate(const SgName &X, const SgName &Y)
get the path from the full filename