ROSE 0.11.145.281
sageInterface.h
1#ifndef ROSE_SAGE_INTERFACE
2#define ROSE_SAGE_INTERFACE
3
4#include "sage3basic.hhh"
5#include <stdint.h>
6#include <utility>
7
8#include "rosePublicConfig.h" // for ROSE_BUILD_JAVA_LANGUAGE_SUPPORT
9#include "OmpAttribute.h"
10
11#include <string>
12#include <iostream>
13#include <sstream>
14
15#if 0 // FMZ(07/07/2010): the argument "nextErrorCode" should be call-by-reference
16SgFile* determineFileType ( std::vector<std::string> argv, int nextErrorCode, SgProject* project );
17#else
18SgFile* determineFileType ( std::vector<std::string> argv, int& nextErrorCode, SgProject* project );
19#endif
20
21#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
22#include "rewrite.h"
23#endif
24
25// DQ (7/20/2008): Added support for unparsing abitrary strings in the unparser.
26#include "astUnparseAttribute.h"
27#include <set>
28
29#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
30#include "LivenessAnalysis.h"
31#include "abstract_handle.h"
32#include "ClassHierarchyGraph.h"
33#endif
34
35// DQ (6/7/2010): Change the return type to size_t to support larger number of IR nodes
36// using values that overflow signed values of int.
37// DQ (1/2/2006): Support for computing the total number of IR nodes in use within an AST
38// computation is done based on the memory pools (so it is exact).
39// int numberOfNodes();
40// int memoryUsage();
41ROSE_DLL_API size_t numberOfNodes();
42ROSE_DLL_API size_t memoryUsage();
43
44// DQ: This function is used by the SgNode object to connect the unparser (in ROSE) to the AST.
45ROSE_DLL_API std::string globalUnparseToString ( const SgNode* astNode, SgUnparse_Info* inputUnparseInfoPointer = nullptr );
46
47// DQ: These functions are used by soem specific STL containers to connect the unparser (in ROSE) to the AST (mostly for name qualification).
48// DQ (9/13/2014): Added support for more general unparsing of STL containers of IR nodes (at least these).
49ROSE_DLL_API std::string globalUnparseToString ( const SgTemplateParameterPtrList* templateParameterList, SgUnparse_Info* inputUnparseInfoPointer = nullptr );
50ROSE_DLL_API std::string globalUnparseToString ( const SgTemplateArgumentPtrList* templateArgumentList, SgUnparse_Info* inputUnparseInfoPointer = nullptr );
51
52// DQ (8/19/2004): Moved from ROSE/src/midend/astRewriteMechanism/rewrite.h
54ROSE_DLL_API std::string getVariantName (VariantT v);
55
56// DQ (12/9/2004): Qing, Rich and Dan have decided to start this namespace within ROSE
57// This namespace is specific to interface functions that operate on the Sage III AST.
58// The name was chosen so as not to conflict with other classes within ROSE.
59// This will become the future home of many interface functions which operate on
60// the AST and which are generally useful to users. As a namespace multiple files can be used
61// to represent the compete interface and different developers may contribute interface
62// functions easily.
63
64// Constructor handling: (We have sageBuilder.h now for this purpose, Liao 2/1/2008)
65// We could add simpler layers of support for construction of IR nodes by
66// hiding many details in "makeSg***()" functions. Such functions would
67// return pointers to the associated Sg*** objects and would be able to hide
68// many IR specific details, including:
69// memory handling
70// optional parameter settings not often required
71// use of Sg_File_Info objects (and setting them as transformations)
72//
73// namespace AST_Interface (this name is taken already by some of Qing's work :-)
74
76#define TRANS_FILE Sg_File_Info::generateDefaultFileInfoForTransformationNode()
77
78
84namespace SageInterface
85 {
86 // Liao 6/22/2016: keep records of loop init-stmt normalization, later help undo it to support autoPar.
88 {
89 // a lookup table to check if a for loop has been normalized for its c99-style init-stmt
90 std::map <SgForStatement* , bool > forLoopInitNormalizationTable;
91 // Detailed record about the original declaration (1st in the pair) and the normalization generated new declaration (2nd in the pair)
92 std::map <SgForStatement* , std::pair<SgVariableDeclaration*, SgVariableDeclaration*> > forLoopInitNormalizationRecord;
93 } ;
94
95 ROSE_DLL_API extern Transformation_Record trans_records;
96
97 // DQ (4/3/2014): Added general AST support separate from the AST.
98
99 // Container and API for analysis information that is outside of the AST and as a result
100 // prevents frequent modification of the IR.
102 {
103 // DQ (4/3/2014): This stores all associated declarations as a map of sets.
104 // the key to the map is the first nondefining declaration and the elements of the set are
105 // all of the associated declarations (including the defining declaration).
106
107 private:
109 std::map<SgDeclarationStatement*,std::set<SgDeclarationStatement*>* > declarationMap;
110
111 public:
112 void addDeclaration(SgDeclarationStatement* decl);
113 const std::set<SgDeclarationStatement*>* getDeclarations(SgDeclarationStatement* decl);
114
115 std::map<SgDeclarationStatement*,std::set<SgDeclarationStatement*>* > & getDeclarationMap();
116
117 bool isLocatedInDefiningScope(SgDeclarationStatement* decl);
118
119 };
120
121 // DQ (4/3/2014): This constructs a data structure that holds analysis information about
122 // the AST that is separate from the AST. This is intended to be a general mechanism
123 // to support analysis information without constantly modifying the IR.
124 DeclarationSets* buildDeclarationSets(SgNode*);
125
127ROSE_DLL_API extern int gensym_counter;
128
129#ifdef ROSE_ENABLE_BINARY_ANALYSIS
131SgAsmInterpretation* getMainInterpretation(SgAsmGenericFile* file);
132
134uint64_t getAsmConstant(SgAsmValueExpression* e);
135
137int64_t getAsmSignedConstant(SgAsmValueExpression *e);
138#endif
139
141 void addMessageStatement( SgStatement* stmt, std::string message );
142
145 {
146 private:
147 std::string name;
148 public:
149 UniqueNameAttribute(std::string n="") {name =n; };
150 void set_name (std::string n) {name = n;};
151 std::string get_name () {return name;};
152 };
153
154 //------------------------------------------------------------------------
156
160// DQ (8/5/2020): the "using namespace" directive will not hide existing visability of symbols in resolving visability.
161// So we need to test if a symbol is visible exclusing matching alises due to using direectives before we can decide to
162// persue name space qualification. This is best demonstrated by Cxx_tests/test2020_18.C, test2020_19.C, test2020_20.C,
163// and test2020_21.C.
164 ROSE_DLL_API SgSymbol *lookupSymbolInParentScopesIgnoringAliasSymbols (const SgName & name, SgScopeStatement *currentScope = NULL, SgTemplateParameterPtrList* templateParameterList = NULL, SgTemplateArgumentPtrList* templateArgumentList = NULL);
165
166// DQ (8/21/2013): Modified to make newest function parameters be default arguments.
167// DQ (8/16/2013): For now we want to remove the use of default parameters and add the support for template parameters and template arguments.
169// SgSymbol *lookupSymbolInParentScopes (const SgName & name, SgScopeStatement *currentScope=NULL);
170// SgSymbol *lookupSymbolInParentScopes (const SgName & name, SgScopeStatement *currentScope, SgTemplateParameterPtrList* templateParameterList, SgTemplateArgumentPtrList* templateArgumentList);
171 ROSE_DLL_API SgSymbol *lookupSymbolInParentScopes (const SgName & name, SgScopeStatement *currentScope = NULL, SgTemplateParameterPtrList* templateParameterList = NULL, SgTemplateArgumentPtrList* templateArgumentList = NULL);
172
173 // Liao 1/22/2008, used for get symbols for generating variable reference nodes
174 // ! Find a variable symbol in current and ancestor scopes for a given name
175 ROSE_DLL_API SgVariableSymbol *lookupVariableSymbolInParentScopes (const SgName & name, SgScopeStatement *currentScope=NULL);
176
177 // DQ (11/24/2007): Functions moved from the Fortran support so that they could be called from within astPostProcessing.
179 ROSE_DLL_API SgFunctionSymbol *lookupFunctionSymbolInParentScopes (const SgName & functionName, SgScopeStatement *currentScope=NULL);
180
181 // Liao, 1/24/2008, find exact match for a function
183 ROSE_DLL_API SgFunctionSymbol *lookupFunctionSymbolInParentScopes (const SgName & functionName,
184 const SgType* t,
185 SgScopeStatement *currentScope=NULL);
186
187 ROSE_DLL_API SgFunctionSymbol *lookupTemplateFunctionSymbolInParentScopes (const SgName & functionName, SgFunctionType * ftype, SgTemplateParameterPtrList * tplparams, SgScopeStatement *currentScope=NULL);
188 ROSE_DLL_API SgFunctionSymbol *lookupTemplateMemberFunctionSymbolInParentScopes (const SgName & functionName, SgFunctionType * ftype, SgTemplateParameterPtrList * tplparams, SgScopeStatement *currentScope=NULL);
189
190 ROSE_DLL_API SgTemplateVariableSymbol * lookupTemplateVariableSymbolInParentScopes (const SgName & name, SgTemplateParameterPtrList * tplparams, SgTemplateArgumentPtrList* tplargs, SgScopeStatement *currentScope=NULL);
191
192
193// DQ (8/21/2013): Modified to make newest function parameters be default arguments.
194// DQ (8/16/2013): For now we want to remove the use of default parameters and add the support for template parameters and template arguments.
195// DQ (5/7/2011): Added support for SgClassSymbol (used in name qualification support).
196// SgClassSymbol* lookupClassSymbolInParentScopes (const SgName & name, SgScopeStatement *currentScope = NULL);
197 ROSE_DLL_API SgClassSymbol* lookupClassSymbolInParentScopes (const SgName & name, SgScopeStatement *currentScope = NULL, SgTemplateArgumentPtrList* templateArgumentList = NULL);
198 ROSE_DLL_API SgTypedefSymbol* lookupTypedefSymbolInParentScopes (const SgName & name, SgScopeStatement *currentScope = NULL);
199
200 ROSE_DLL_API SgNonrealSymbol* lookupNonrealSymbolInParentScopes (const SgName & name, SgScopeStatement *currentScope = NULL, SgTemplateParameterPtrList* templateParameterList = NULL, SgTemplateArgumentPtrList* templateArgumentList = NULL);
201#if 0
202 // DQ (8/13/2013): This function does not make since any more, now that we have made the symbol
203 // table handling more precise and we have to provide template parameters for any template lookup.
204 // We also have to know if we want to lookup template classes, template functions, or template
205 // member functions (since each have specific requirements).
206 SgTemplateSymbol* lookupTemplateSymbolInParentScopes (const SgName & name, SgScopeStatement *currentScope = NULL);
207#endif
208#if 0
209// DQ (8/13/2013): I am not sure if we want this functions in place of lookupTemplateSymbolInParentScopes.
210// Where these are called we might not know enough information about the template parameters or function
211// types, for example.
212 SgTemplateClassSymbol* lookupTemplateClassSymbolInParentScopes (const SgName & name, SgScopeStatement *currentScope = NULL, SgTemplateParameterPtrList* templateParameterList = NULL, SgTemplateArgumentPtrList* templateArgumentList = NULL);
213 SgTemplateFunctionSymbol* lookupTemplateFunctionSymbolInParentScopes (const SgName & name, SgScopeStatement *currentScope = NULL, SgTemplateParameterPtrList* templateParameterList = NULL);
214 SgTemplateMemberFunctionSymbol* lookupTemplateMemberFunctionSymbolInParentScopes (const SgName & name, SgScopeStatement *currentScope = NULL, SgTemplateParameterPtrList* templateParameterList = NULL);
215#endif
216
217// DQ (8/21/2013): Modified to make some of the newest function parameters be default arguments.
218// DQ (8/13/2013): I am not sure if we want this functions in place of lookupTemplateSymbolInParentScopes.
219 ROSE_DLL_API SgTemplateClassSymbol* lookupTemplateClassSymbolInParentScopes (const SgName & name, SgTemplateParameterPtrList* templateParameterList, SgTemplateArgumentPtrList* templateArgumentList, SgScopeStatement *cscope = NULL);
220
221 ROSE_DLL_API SgEnumSymbol* lookupEnumSymbolInParentScopes (const SgName & name, SgScopeStatement *currentScope = NULL);
222 ROSE_DLL_API SgNamespaceSymbol* lookupNamespaceSymbolInParentScopes(const SgName & name, SgScopeStatement *currentScope = NULL);
223
224// DQ (7/17/2011): Added function from cxx branch that I need here for the Java support.
225// SgClassSymbol* lookupClassSymbolInParentScopes (const SgName & name, SgScopeStatement *cscope);
226
235 // DQ (12/9/2004): Moved this function (by Alin Jula) from being a member of SgInitializedName
236 // to this location where it can be a part of the interface for the Sage III AST.
237 ROSE_DLL_API int set_name (SgInitializedName * initializedNameNode, SgName new_name);
238
242
243 // DQ (6/27/2005):
248 ROSE_DLL_API void outputLocalSymbolTables (SgNode * node);
249
251 {
252 public:
253 void visit (SgNode * node);
254 };
260 // DQ (9/28/2005):
262
265 void clearUnusedVariableSymbols (SgNode* root = NULL);
266
267 // DQ (3/1/2009):
269 void fixupReferencesToSymbols( const SgScopeStatement* this_scope, SgScopeStatement* copy_scope, SgCopyHelp & help );
270
272
273 //------------------------------------------------------------------------
275
282 // DQ (9/21/2005): General function for extracting the name of declarations (when they have names)
283 std::string get_name (const SgNode * node);
284
289 // DQ (6/13/2005): General function for extracting the name of declarations (when they have names)
290 std::string get_name (const SgStatement * stmt);
291
296 std::string get_name (const SgExpression * expr);
297
302 // DQ (6/13/2005): General function for extracting the name of declarations (when they have names)
303 std::string get_name (const SgDeclarationStatement * declaration);
304
309 // DQ (6/13/2005): General function for extracting the name of declarations (when they have names)
310 std::string get_name (const SgScopeStatement * scope);
311
316 // DQ (2/11/2007): Added this function to make debugging support more complete (useful for symbol table debugging support).
317 std::string get_name (const SgSymbol * symbol);
318
323 std::string get_name (const SgType * type);
324
325
328 std::string get_name (const SgSupport * node);
329
330
333 std::string get_name (const SgLocatedNodeSupport * node);
334
337 std::string get_name ( const SgC_PreprocessorDirectiveStatement* directive );
338
341 std::string get_name ( const SgToken* token );
342
343 // PP (11/22/2021): General function for extracting the type of declarations (when they declare types)
348
349
350 // DQ (3/20/2016): Added to refactor some of the DSL infrastructure support.
360
363 extern std::map<std::string,int> local_name_collision_map;
364 extern std::map<std::string,SgNode*> local_name_to_node_map;
365 extern std::map<SgNode*,std::string> local_node_to_name_map;
366
370
374
376
377 //------------------------------------------------------------------------
379
384 // DQ (6/21/2005): Get the default destructor from the class declaration
386
389 // DQ (6/22/2005): Get the default constructor from the class declaration
393 // DQ (8/27/2005):
394 ROSE_DLL_API bool templateDefinitionIsInClass (SgTemplateInstantiationMemberFunctionDecl* memberFunctionDeclaration);
395
400 // DQ (9/17/2005):
402
404 ROSE_DLL_API bool isStructDeclaration(SgNode * node);
406 ROSE_DLL_API bool isUnionDeclaration(SgNode * node);
407
408#if 0
409 // DQ (8/28/2005): This is already a member function of the SgFunctionDeclaration
410 // (so that it can handle template functions and member functions)
411
415 // DQ (8/27/2005):
416 bool isTemplateMemberFunction (SgTemplateInstantiationMemberFunctionDecl* memberFunctionDeclaration);
417#endif
418
419 // DQ (11/9/2020): Added function to support adding a default constructor definition to a class
420 // if it does not have a default constructor, but has any other constructor that would prevend
421 // a compiler generated default constructor from being generated by the compiler.
422 // Note the physical_file_id is so that it can be marked to be unparsed when header file unparsing is active.
423 ROSE_DLL_API bool addDefaultConstructorIfRequired ( SgClassType* classType, int physical_file_id = Sg_File_Info::TRANSFORMATION_FILE_ID );
424
426
427 //------------------------------------------------------------------------
429
435
437 void saveToPDF(SgNode* node, std::string filename);
438 void saveToPDF(SgNode* node); // enable calling from gdb
439
441 void printAST (SgNode* node);
442
444 void printAST (SgNode* node, const char* filename);
445
447 void printAST2TextFile (SgNode* node, const char* filename, bool printType=true);
448
450 void printAST2TextFile (SgNode* node, std::string filename, bool printType=true);
451
452 // DQ (2/12/2012): Added some diagnostic support.
454 void whereAmI(SgNode* node);
455
457 std::string extractPragmaKeyword(const SgPragmaDeclaration *);
458
460 ROSE_DLL_API bool isOmpStatement(SgNode* );
463 // DQ (8/27/2005):
464 bool isOverloaded (SgFunctionDeclaration * functionDeclaration);
465
466// DQ (2/14/2012): Added support function used for variable declarations in conditionals.
468 void initializeIfStmt(SgIfStmt *ifstmt, SgStatement* conditional, SgStatement * true_body, SgStatement * false_body);
469
471 void initializeSwitchStatement(SgSwitchStatement* switchStatement,SgStatement *item_selector,SgStatement *body);
472
474 void initializeWhileStatement(SgWhileStmt* whileStatement, SgStatement * condition, SgStatement *body, SgStatement *else_body);
475
478
480 ROSE_DLL_API bool isMain (const SgNode* node);
481 // DQ (6/22/2005):
492 std::string generateUniqueName ( const SgNode * node, bool ignoreDifferenceBetweenDefiningAndNondefiningDeclarations);
493
496 std::string generateUniqueVariableName(SgScopeStatement* scope, std::string baseName = "temp");
497
498 // DQ (8/10/2010): Added const to first parameter.
499 // DQ (3/10/2007):
501 std::string declarationPositionString (const SgDeclarationStatement * declaration);
502
503 // DQ (1/20/2007):
505 ROSE_DLL_API std::string generateProjectName (const SgProject * project, bool supressSuffix = false );
506
510
513
515 void addVarRefExpFromArrayDimInfo(SgNode * astNode, Rose_STL_Container<SgNode *>& NodeList_t);
516
517 // DQ (10/6/2006): Added support for faster mangled name generation (caching avoids recomputation).
521#ifndef SWIG
522// DQ (3/10/2013): This appears to be a problem for the SWIG interface (undefined reference at link-time).
523 void clearMangledNameCache (SgGlobal * globalScope);
524 void resetMangledNameCache (SgGlobal * globalScope);
525#endif
526
527 std::string getMangledNameFromCache (SgNode * astNode);
528 std::string addMangledNameToCache (SgNode * astNode, const std::string & mangledName);
529
531
535
536 // DQ (10/14/2006): This function tests the AST to see if for a non-defining declaration, the
537 // bool declarationPreceedsDefinition ( SgClassDeclaration* classNonDefiningDeclaration, SgClassDeclaration* classDefiningDeclaration );
539 bool declarationPreceedsDefinition (SgDeclarationStatement *nonDefiningDeclaration, SgDeclarationStatement *definingDeclaration);
540
541 // DQ (10/19/2006): Function calls have interesting context dependent rules to determine if
542 // they are output with a global qualifier or not. Were this is true we have to avoid global
543 // qualifiers, since the function's scope has not been defined. This is an example of where
544 // qualification of function names in function calls are context dependent; an interesting
545 // example of where the C++ language is not friendly to source-to-source processing :-).
547
552 ROSE_DLL_API std::vector < SgNode * >astIntersection (SgNode * original, SgNode * copy, SgCopyHelp * help = NULL);
553
555 ROSE_DLL_API SgNode* deepCopyNode (const SgNode* subtree);
556
558 template <typename NodeType>
559 NodeType* deepCopy (const NodeType* subtree) {
560 return dynamic_cast<NodeType*>(deepCopyNode(subtree));
561 }
562
564 ROSE_DLL_API SgExpression* copyExpression(SgExpression* e);
565
567 ROSE_DLL_API SgStatement* copyStatement(SgStatement* s);
568
569// from VarSym.cc in src/midend/astOutlining/src/ASTtools
572
575
577ROSE_DLL_API void myRemoveStatement(SgStatement* stmt);
578
580ROSE_DLL_API bool isConstantTrue(SgExpression* e);
581
583ROSE_DLL_API bool isConstantFalse(SgExpression* e);
584
586ROSE_DLL_API bool isCallToParticularFunction(const std::string& qualifiedName, size_t arity, SgExpression* e);
587
589bool ROSE_DLL_API isStatic(SgDeclarationStatement* stmt);
590
592ROSE_DLL_API void setStatic(SgDeclarationStatement* stmt);
593
595ROSE_DLL_API bool isExtern(SgDeclarationStatement* stmt);
596
598ROSE_DLL_API void setExtern(SgDeclarationStatement* stmt);
599
601ROSE_DLL_API bool ROSE_DLL_API isMutable(SgInitializedName* name);
602
604ROSE_DLL_API bool ROSE_DLL_API isJovialOutParam(SgInitializedName* name);
605
607ROSE_DLL_API std::vector<SgInitializedName*> getInParameters(const SgInitializedNamePtrList &params);
608
610ROSE_DLL_API std::vector<SgInitializedName*> getOutParameters(const SgInitializedNamePtrList &params);
611
615 public:
616 virtual ~StatementGenerator() {};
617 virtual SgStatement* generate(SgExpression* where_to_write_answer) = 0;
618};
619
623ROSE_DLL_API bool isAssignmentStatement(SgNode* _s, SgExpression** lhs=NULL, SgExpression** rhs=NULL, bool* readlhs=NULL);
624
626ROSE_DLL_API SgInitializedName* convertRefToInitializedName(SgNode* current, bool coarseGrain=true);
627
630
632ROSE_DLL_API SgNode* getSgNodeFromAbstractHandleString(const std::string& input_string);
633
635ROSE_DLL_API void dumpInfo(SgNode* node, std::string desc="");
636
638ROSE_DLL_API std::vector<SgDeclarationStatement*>
639sortSgNodeListBasedOnAppearanceOrderInSource(const std::vector<SgDeclarationStatement*>& nodevec);
640
641// DQ (4/13/2013): We need these to support the unparing of operators defined by operator syntax or member function names.
643// bool isPrefixOperator( const SgMemberFunctionRefExp* memberFunctionRefExp );
644ROSE_DLL_API bool isPrefixOperator( SgExpression* exp );
645
647ROSE_DLL_API bool isPrefixOperatorName( const SgName & functionName );
648
650ROSE_DLL_API bool isPostfixOperator( SgExpression* exp );
651
653ROSE_DLL_API bool isIndexOperator( SgExpression* exp );
654
655// DQ (1/10/2014): Adding more general support for token based unparsing.
657ROSE_DLL_API SgStatement* lastStatementOfScopeWithTokenInfo (SgScopeStatement* scope, std::map<SgNode*,TokenStreamSequenceToNodeMapping*> & tokenStreamSequenceMap);
658
659// DQ (8/12/2020): Check the access permissions of all defining and nodefining declarations.
660ROSE_DLL_API void checkAccessPermissions ( SgNode* );
661
662// DQ (8/14/2020): Check the symbol tables for specific scopes (debugging support).
663ROSE_DLL_API void checkSymbolTables ( SgNode* );
664
665// DQ (11/9/2020): Added support for makring IR nodes and subtrees of the AST to be unparsed (physical_file_id
666// is required when unparsing header files is true or support multiple files and shared IR nodes).
667ROSE_DLL_API void markSubtreeToBeUnparsed(SgNode* root, int physical_file_id);
668ROSE_DLL_API void markNodeToBeUnparsed(SgNode* node, int physical_file_id);
669
670// DQ (7/8/2021): This is a tree traversal based version of this marking of a subtree which allows special handling of cast expressions.
671// Basically, cast expression should not be marked as transformations.
672ROSE_DLL_API void markSubtreeToBeUnparsedTreeTraversal(SgNode* root, int physical_file_id);
673
674// DQ (7/12/2021): Debugging code to locate specific node marked as a transforamtion in the AST.
675// Debugging the outliner.
676 ROSE_DLL_API bool findFirstSgCastExpMarkedAsTransformation(SgNode* n, const std::string & s);
677
679
680//------------------------------------------------------------------------
682
686// DQ (11/25/2020): Add support to set this as a specific language kind file (there is at least one language kind file processed by ROSE).
687// The value of 0 allows the old implementation to be tested, and the value of 1 allows the new optimized implementation to be tested.
688// However to get all of the functions to be inlined, we have to recompile all of ROSE.
689#define INLINE_OPTIMIZED_IS_LANGUAGE_KIND_FUNCTIONS 1
690
691// std::string version(); // utility_functions.h, version number
694#if INLINE_OPTIMIZED_IS_LANGUAGE_KIND_FUNCTIONS
695 ROSE_DLL_API inline bool is_Ada_language () { return Rose::is_Ada_language; }
696 ROSE_DLL_API inline bool is_C_language () { return Rose::is_C_language; }
697 ROSE_DLL_API inline bool is_OpenMP_language () { return Rose::is_OpenMP_language; }
698 ROSE_DLL_API inline bool is_UPC_language () { return Rose::is_UPC_language; }
699 ROSE_DLL_API inline bool is_UPC_dynamic_threads() { return Rose::is_UPC_dynamic_threads; }
700 ROSE_DLL_API inline bool is_C99_language () { return Rose::is_C99_language; }
701 ROSE_DLL_API inline bool is_Cxx_language () { return Rose::is_Cxx_language; }
702 ROSE_DLL_API inline bool is_Java_language () { return Rose::is_Java_language; }
703 ROSE_DLL_API inline bool is_Jovial_language () { return Rose::is_Jovial_language; }
704 ROSE_DLL_API inline bool is_Jvm_language () { return Rose::is_Jvm_language; }
705 ROSE_DLL_API inline bool is_Fortran_language () { return Rose::is_Fortran_language; }
706 ROSE_DLL_API inline bool is_CAF_language () { return Rose::is_CAF_language; }
707 ROSE_DLL_API inline bool is_PHP_language() { return Rose::is_PHP_language; }
708 ROSE_DLL_API inline bool is_Python_language() { return Rose::is_Python_language; }
709 ROSE_DLL_API inline bool is_Cuda_language() { return Rose::is_Cuda_language; }
710 ROSE_DLL_API inline bool is_OpenCL_language() { return Rose::is_OpenCL_language; }
711 ROSE_DLL_API inline bool is_binary_executable() { return Rose::is_binary_executable; }
712#else
713 ROSE_DLL_API bool is_Ada_language ();
714 ROSE_DLL_API bool is_C_language ();
715 ROSE_DLL_API bool is_OpenMP_language ();
716 ROSE_DLL_API bool is_UPC_language ();
718 ROSE_DLL_API bool is_UPC_dynamic_threads();
719 ROSE_DLL_API bool is_C99_language ();
720 ROSE_DLL_API bool is_Cxx_language ();
721 ROSE_DLL_API bool is_Java_language ();
722 ROSE_DLL_API bool is_Jovial_language ();
723 ROSE_DLL_API bool is_Jvm_language ();
724 ROSE_DLL_API bool is_Fortran_language ();
725 ROSE_DLL_API bool is_CAF_language ();
726 ROSE_DLL_API bool is_PHP_language();
727 ROSE_DLL_API bool is_Python_language();
728 ROSE_DLL_API bool is_Cuda_language();
729 ROSE_DLL_API bool is_OpenCL_language();
730 ROSE_DLL_API bool is_binary_executable();
731#endif
732
733 ROSE_DLL_API bool is_mixed_C_and_Cxx_language ();
734 ROSE_DLL_API bool is_mixed_Fortran_and_C_language ();
735 ROSE_DLL_API bool is_mixed_Fortran_and_Cxx_language ();
736 ROSE_DLL_API bool is_mixed_Fortran_and_C_and_Cxx_language ();
737
738 ROSE_DLL_API bool is_language_case_insensitive ();
740
742
743//------------------------------------------------------------------------
745
749 // DQ (10/5/2006): Added support for faster (non-quadratic) computation of unique
750 // labels for scopes in a function (as required for name mangling).
756 void resetScopeNumbers (SgFunctionDefinition * functionDeclaration);
757
758 // DQ (10/5/2006): Added support for faster (non-quadratic) computation of unique
759 // labels for scopes in a function (as required for name mangling).
768 void clearScopeNumbers (SgFunctionDefinition * functionDefinition);
769
770
773// SgNamespaceDefinitionStatement * getEnclosingNamespaceScope (SgNode * node);
774
776 SgFunctionDeclaration * functionDeclaration,
777 SgDeclarationStatement * startingAtDeclaration);
778
780 bool ROSE_DLL_API isAncestor(SgNode* node1, SgNode* node2);
782//------------------------------------------------------------------------
784
789 void dumpPreprocInfo (SgLocatedNode* locatedNode);
790
792ROSE_DLL_API PreprocessingInfo * findHeader(SgSourceFile * source_file, const std::string & header_file_name, bool isSystemHeader);
793
795ROSE_DLL_API PreprocessingInfo * insertHeader(SgSourceFile * source_file, const std::string & header_file_name, bool isSystemHeader, bool asLastHeader);
796
798ROSE_DLL_API void insertHeader (SgStatement* stmt, PreprocessingInfo* newheader, bool asLastHeader);
799
801ROSE_DLL_API PreprocessingInfo * insertHeader(SgSourceFile * source_file, const std::string & header_file_name, bool isSystemHeader = false, PreprocessingInfo::RelativePositionType position = PreprocessingInfo::before);
802
804ROSE_DLL_API PreprocessingInfo* insertHeader(const std::string& filename, PreprocessingInfo::RelativePositionType position=PreprocessingInfo::after, bool isSystemHeader=false, SgScopeStatement* scope=NULL);
805
807ROSE_DLL_API void moveUpPreprocessingInfo (SgStatement* stmt_dst, SgStatement* stmt_src, PreprocessingInfo::RelativePositionType src_position=PreprocessingInfo::undef, PreprocessingInfo::RelativePositionType dst_position=PreprocessingInfo::undef, bool usePrepend= false);
808
810ROSE_DLL_API void movePreprocessingInfo (SgStatement* stmt_src, SgStatement* stmt_dst, PreprocessingInfo::RelativePositionType src_position=PreprocessingInfo::undef,
811 PreprocessingInfo::RelativePositionType dst_position=PreprocessingInfo::undef, bool usePrepend= false);
812
813
815ROSE_DLL_API void cutPreprocessingInfo (SgLocatedNode* src_node, PreprocessingInfo::RelativePositionType pos, AttachedPreprocessingInfoType& save_buf);
816
818ROSE_DLL_API void pastePreprocessingInfo (SgLocatedNode* dst_node, PreprocessingInfo::RelativePositionType pos, AttachedPreprocessingInfoType& saved_buf);
819
822 const std::string & text,
823 PreprocessingInfo::RelativePositionType position=PreprocessingInfo::before);
824
828
831 SgSourceFile * source_file,
832 const std::string & content,
833 PreprocessingInfo::DirectiveType directive_type = PreprocessingInfo::C_StyleComment,
834 PreprocessingInfo::RelativePositionType position = PreprocessingInfo::before
835);
836
838 ROSE_DLL_API PreprocessingInfo* attachComment(SgLocatedNode* target, const std::string & content,
839 PreprocessingInfo::RelativePositionType position=PreprocessingInfo::before,
840 PreprocessingInfo::DirectiveType dtype= PreprocessingInfo::CpreprocessorUnknownDeclaration);
841
842// DQ (7/20/2008): I am not clear were I should put this function, candidates include: SgLocatedNode or SgInterface
844 ROSE_DLL_API void addTextForUnparser ( SgNode* astNode, std::string s, AstUnparseAttribute::RelativePositionType inputlocation );
845
850void guardNode(SgLocatedNode * target, std::string guard);
851
852/* \brief move inner danglling #endif .. #if | #ifdef| #ifndef to be after lnode
853 This is needed when we remove a target statement with internal statements.
854 Some of the internal statements may have a dangling #endif #if, #ifdef #ifndef.
855 We need to move them to be attached to after position of lnode.
856 Then we can safely remove or replace lnode (often a statement)
857*/
859
860/* \brief scanning subtree from lnode, find and erase any NULL PreprocessingInfo pointers
861 The unparser expects PreprocessingInfo pointers are not NULL.
862 We may introduce NULL pointers after moving some preprocessing info. from one place to another.
863*/
864
865ROSE_DLL_API int eraseNullPreprocessingInfo (SgLocatedNode* lnode);
866
867
868/* \brief For each comment, we store its container, idx within the container,
869 and depth level of the located node within AST from a selected root
870*/
872 AttachedPreprocessingInfoType* container; // the associated container
873 int index; // idx of the comment within the container
874 int depth; // starting from 0 : the root node of the selected root of the sub-tree
875};
876
877/* \brief Recursively walk a subtree rooted at current node, extract PreprocessingInfo pointers to a list
878 The list preserves the orginal order in which each preprocessing info shows up in the source code.
879 This function is needed since naive walking of a subtree may generate out-of-order list of preprocessing info.
880 We have to consider collecting the before, inside locations first, and the after location last using a recursion function.
881*/
882ROSE_DLL_API void preOrderCollectPreprocessingInfo(SgNode* current, std::vector<PreprocessingInfo*>& infoList, int depth);
883
885
886
887//------------------------------------------------------------------------
889
893// ************************************************************************
894// Newer versions of now depricated functions
895// ************************************************************************
896
897// DQ (5/1/2012): This function queries the SageBuilder::SourcePositionClassification mode (stored in the SageBuilder
898// interface) and used the specified mode to initialize the source position data (Sg_File_Info objects). This
899// function is the only function that should be called directly (though in a namespace we can't define permissions).
901 ROSE_DLL_API void setSourcePosition(SgNode* node);
902
903// A better name might be "setSourcePositionForSubTree"
905 ROSE_DLL_API void setSourcePositionAtRootAndAllChildren(SgNode *root);
906
909
910// DQ (5/1/2012): Newly renamed function (previous name preserved for backward compatability).
912
913// ************************************************************************
914
915
916
917// ************************************************************************
918// Older deprecated functions
919// ************************************************************************
920 // Liao, 1/8/2007, set file info. for a whole subtree as transformation generated
922 ROSE_DLL_API void setOneSourcePositionForTransformation(SgNode *node);
923
925 ROSE_DLL_API void setOneSourcePositionNull(SgNode *node);
926
928 ROSE_DLL_API void setSourcePositionForTransformation (SgNode * root);
929
931// ROSE_DLL_API void setSourcePositionForTransformation_memoryPool();
932
934 ROSE_DLL_API bool insideSystemHeader (SgLocatedNode* node);
935
936// DQ (2/27/2021): Adding support to detect if a SgLocatedNode is located in a header file.
938 ROSE_DLL_API bool insideHeader (SgLocatedNode* node);
939
941// ROSE_DLL_API void setSourcePosition (SgLocatedNode * locatedNode);
942// ************************************************************************
943
945
946
947//------------------------------------------------------------------------
949
953// from src/midend/astInlining/typeTraits.h
954// src/midend/astUtil/astInterface/AstInterface.h
955
958
959
963ROSE_DLL_API bool isStrictIntegerType(SgType* t);
966
968ROSE_DLL_API bool isDefaultConstructible(SgType* type);
969
971ROSE_DLL_API bool isCopyConstructible(SgType* type);
972
974ROSE_DLL_API bool isAssignable(SgType* type);
975
976#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
980ROSE_DLL_API bool isPureVirtualClass(SgType* type, const ClassHierarchyWrapper& classHierarchy);
981#endif
982
984ROSE_DLL_API bool hasTrivialDestructor(SgType* t);
985
987ROSE_DLL_API bool isNonconstReference(SgType* t);
988
990ROSE_DLL_API bool isReferenceType(SgType* t);
991
993ROSE_DLL_API bool isPointerType(SgType* t);
994
1000ROSE_DLL_API bool isPointerToNonConstType(SgType* type);
1001
1003/* const char* p = "aa"; is not treated as having a const type. It is a pointer to const char.
1004 * Similarly, neither for const int b[10]; or const int & c =10;
1005 * The standard says, "A compound type is not cv-qualified by the cv-qualifiers (if any) of
1006the types from which it is compounded. Any cv-qualifiers applied to an array type affect the array element type, not the array type".
1007 */
1008ROSE_DLL_API bool isConstType(SgType* t);
1009
1012
1014ROSE_DLL_API bool isVolatileType(SgType* t);
1015
1017ROSE_DLL_API bool isRestrictType(SgType* t);
1018
1020
1022ROSE_DLL_API bool isScalarType(SgType* t);
1023
1027ROSE_DLL_API bool isStrictIntegerType(SgType* t);
1028
1030ROSE_DLL_API bool isStructType(SgType* t);
1031
1033ROSE_DLL_API std::string mangleType(SgType* type);
1034
1036ROSE_DLL_API std::string mangleScalarType(SgType* type);
1037
1039ROSE_DLL_API std::string mangleModifierType(SgModifierType* type);
1040
1042ROSE_DLL_API size_t getArrayElementCount(SgArrayType* t);
1043
1045ROSE_DLL_API int getDimensionCount(SgType* t);
1046
1049
1051ROSE_DLL_API SgType* getElementType(SgType* t);
1052
1053
1070std::vector<SgExpression*>
1071get_C_array_dimensions(const SgArrayType& arrtype);
1072
1093std::vector<SgExpression*>
1094get_C_array_dimensions(const SgArrayType& arrtype, const SgVarRefExp& varref);
1095
1099std::vector<SgExpression*>
1100get_C_array_dimensions(const SgArrayType& arrtype, SgInitializedName& initname);
1101
1102
1104ROSE_DLL_API bool isArrayReference(SgExpression* ref, SgExpression** arrayNameExp=NULL, std::vector<SgExpression*>** subscripts=NULL);
1105
1106
1108ROSE_DLL_API int collectVariableReferencesInArrayTypes (SgLocatedNode* root, Rose_STL_Container<SgNode*> & currentVarRefList);
1110
1119ROSE_DLL_API bool hasUpcSharedType(SgType* t, SgModifierType ** mod_type_out = NULL );
1120
1122
1125ROSE_DLL_API bool isUpcSharedType(SgType* t, SgModifierType ** mod_type_out = NULL);
1126
1128ROSE_DLL_API bool isUpcSharedModifierType (SgModifierType* mod_type);
1129
1131ROSE_DLL_API bool isUpcSharedArrayType (SgArrayType* array_type);
1132
1134ROSE_DLL_API bool isUpcStrictSharedModifierType(SgModifierType* mode_type);
1135
1137ROSE_DLL_API size_t getUpcSharedBlockSize(SgModifierType* mod_type);
1138
1140ROSE_DLL_API size_t getUpcSharedBlockSize(SgType* t);
1141
1143ROSE_DLL_API bool isUpcPhaseLessSharedType (SgType* t);
1144
1146ROSE_DLL_API bool isUpcPrivateToSharedType(SgType* t);
1147
1150
1152ROSE_DLL_API SgType* lookupNamedTypeInParentScopes(const std::string& type_name, SgScopeStatement* scope=NULL);
1153
1154// DQ (7/22/2014): Added support for comparing expression types in actual arguments with those expected from the formal function parameter types.
1156ROSE_DLL_API SgType* getAssociatedTypeFromFunctionTypeList(SgExpression* actual_argument_expression);
1157
1159ROSE_DLL_API bool templateArgumentEquivalence(SgTemplateArgument * arg1, SgTemplateArgument * arg2);
1160
1162ROSE_DLL_API bool templateArgumentListEquivalence(const SgTemplateArgumentPtrList & list1, const SgTemplateArgumentPtrList & list2);
1163
1165ROSE_DLL_API bool isEquivalentType (const SgType* lhs, const SgType* rhs);
1166
1168ROSE_DLL_API SgFunctionType* findFunctionType (SgType* return_type, SgFunctionParameterTypeList* typeList);
1169
1172ROSE_DLL_API bool isEquivalentFunctionType (const SgFunctionType* lhs, const SgFunctionType* rhs);
1173
1175
1176//------------------------------------------------------------------------
1178
1182// by Jeremiah
1191ROSE_DLL_API void addStepToLoopBody(SgScopeStatement* loopStmt, SgStatement* step);
1192
1194ROSE_DLL_API void convertForToWhile(SgForStatement* f);
1195ROSE_DLL_API void convertAllForsToWhiles(SgNode* top);
1197ROSE_DLL_API void changeContinuesToGotos(SgStatement* stmt, SgLabelStatement* label);
1198
1200ROSE_DLL_API SgInitializedName* getLoopIndexVariable(SgNode* loop);
1201
1204ROSE_DLL_API bool isLoopIndexVariable(SgInitializedName* ivar, SgNode* subtree_root);
1205
1207
1211ROSE_DLL_API bool hasMultipleInitStatmentsOrExpressions (SgForStatement* for_loop);
1212
1214ROSE_DLL_API SgStatement* getLoopBody(SgScopeStatement* loop);
1215
1216ROSE_DLL_API void setLoopBody(SgScopeStatement* loop, SgStatement* body);
1217
1219ROSE_DLL_API SgStatement* getLoopCondition(SgScopeStatement* loop);
1220
1222ROSE_DLL_API void setLoopCondition(SgScopeStatement* loop, SgStatement* cond);
1223
1227ROSE_DLL_API bool isCanonicalForLoop(SgNode* loop, SgInitializedName** ivar=NULL, SgExpression** lb=NULL, SgExpression** ub=NULL, SgExpression** step=NULL, SgStatement** body=NULL, bool *hasIncrementalIterationSpace = NULL, bool* isInclusiveUpperBound = NULL);
1228
1230ROSE_DLL_API bool isCanonicalDoLoop(SgFortranDo* loop,SgInitializedName** ivar/*=NULL*/, SgExpression** lb/*=NULL*/, SgExpression** ub/*=NULL*/, SgExpression** step/*=NULL*/, SgStatement** body/*=NULL*/, bool *hasIncrementalIterationSpace/*= NULL*/, bool* isInclusiveUpperBound/*=NULL*/);
1231
1233ROSE_DLL_API void setLoopLowerBound(SgNode* loop, SgExpression* lb);
1234
1236ROSE_DLL_API void setLoopUpperBound(SgNode* loop, SgExpression* ub);
1237
1239ROSE_DLL_API void setLoopStride(SgNode* loop, SgExpression* stride);
1240
1241
1243ROSE_DLL_API bool normalizeForLoopInitDeclaration(SgForStatement* loop);
1244
1246ROSE_DLL_API bool unnormalizeForLoopInitDeclaration(SgForStatement* loop);
1247
1271ROSE_DLL_API bool normalizeCaseAndDefaultBlocks (SgSwitchStatement* switchStmt);
1272
1284ROSE_DLL_API bool forLoopNormalization(SgForStatement* loop, bool foldConstant = true);
1285
1289ROSE_DLL_API bool normalizeForLoopTest(SgForStatement* loop);
1290ROSE_DLL_API bool normalizeForLoopIncrement(SgForStatement* loop);
1291
1293ROSE_DLL_API bool doLoopNormalization(SgFortranDo* loop);
1294
1296ROSE_DLL_API bool loopUnrolling(SgForStatement* loop, size_t unrolling_factor);
1297
1299ROSE_DLL_API bool loopInterchange(SgForStatement* loop, size_t depth, size_t lexicoOrder);
1300
1302ROSE_DLL_API bool loopTiling(SgForStatement* loopNest, size_t targetLevel, size_t tileSize);
1303
1304//Winnie Loop Collapsing
1305SgExprListExp * loopCollapsing(SgForStatement* target_loop, size_t collapsing_factor);
1306
1308 SgForStatement * for_loop,
1309 SgVariableSymbol * & iterator,
1310 SgExpression * & lower_bound,
1311 SgExpression * & upper_bound,
1312 SgExpression * & stride
1313);
1314
1316
1317//------------------------------------------------------------------------
1319
1324template <typename NodeType>
1325std::vector<NodeType*> querySubTree(SgNode* top, VariantT variant = (VariantT)NodeType::static_variant)
1326 {
1327#if 0
1328 printf ("Top of SageInterface::querySubTree() \n");
1329#endif
1330
1331 Rose_STL_Container<SgNode*> nodes = NodeQuery::querySubTree(top,variant);
1332 std::vector<NodeType*> result(nodes.size(), NULL);
1333 int count = 0;
1334#if 0
1335 printf ("In SageInterface::querySubTree(): before initialization loop \n");
1336#endif
1337
1338 for (Rose_STL_Container<SgNode*>::const_iterator i = nodes.begin(); i != nodes.end(); ++i, ++count)
1339 {
1340#if 0
1341 printf ("In SageInterface::querySubTree(): in loop: count = %d \n",count);
1342#endif
1343 NodeType* node = dynamic_cast<NodeType*>(*i);
1344 ROSE_ASSERT (node);
1345 result[count] = node;
1346 }
1347#if 0
1348 printf ("Leaving SageInterface::querySubTree(): after initialization loop \n");
1349#endif
1350
1351 return result;
1352 }
1357 std::vector < SgFile * >generateFileList ();
1358
1363ROSE_DLL_API SgProject * getProject();
1364
1366 SgProject * getProject(const SgNode * node);
1367
1369template <typename NodeType>
1370static std::vector<NodeType*> getSgNodeListFromMemoryPool()
1371{
1372 // This function uses a memory pool traversal specific to the SgFile IR nodes
1373 class MyTraversal : public ROSE_VisitTraversal
1374 {
1375 public:
1376 std::vector<NodeType*> resultlist;
1377 void visit ( SgNode* node)
1378 {
1379 NodeType* result = dynamic_cast<NodeType* > (node);
1380 ROSE_ASSERT(result!= NULL);
1381 if (result!= NULL)
1382 {
1383 resultlist.push_back(result);
1384 }
1385 };
1386 virtual ~MyTraversal() {}
1387 };
1388
1389 MyTraversal my_traversal;
1390 NodeType::traverseMemoryPoolNodes(my_traversal);
1391 return my_traversal.resultlist;
1392}
1393
1394
1396void serialize(SgNode* node, std::string& prefix, bool hasRemaining, std::ostringstream& out, std::string& edgeLabel);
1397
1398// A special node in the AST text dump
1399template<typename T>
1400void serialize_list(T& plist, std::string T_name, std::string& prefix, bool hasRemaining, std::ostringstream& out, std::string& edgeLabel)
1401{
1402 out<<prefix;
1403 out<< (hasRemaining?"|---": "|___");
1404
1405// out<<"+"<<edgeLabel<<"+>";
1406 out<<" "<<edgeLabel<<" ->";
1407 // print address and type name
1408 //out<<"@"<<&plist<<" "<< typeid(T).name()<<" "; // mangled names are hard to read
1409 out<<"@"<<&plist<<" "<< T_name<<" ";
1410
1411 out<<std::endl;
1412
1413 int last_non_null_child_idx =-1;
1414 for (int i = (int) (plist.size())-1; i>=0; i--)
1415 {
1416 if (plist[i])
1417 {
1418 last_non_null_child_idx = i;
1419 break;
1420 }
1421 }
1422
1423 for (size_t i=0; i< plist.size(); i++ )
1424 {
1425 bool n_hasRemaining=false;
1426 if ((int)i< last_non_null_child_idx) n_hasRemaining = true;
1427 std::string suffix= hasRemaining? "| " : " ";
1428 std::string n_prefix = prefix+suffix;
1429 std::string n_edge_label="";
1430 if (plist[i])
1431 serialize (plist[i], n_prefix, n_hasRemaining, out,n_edge_label);
1432 }
1433}
1434
1435
1438ROSE_DLL_API SgFunctionDeclaration* findMain(SgNode* currentNode);
1439
1441SgStatement* findLastDeclarationStatement(SgScopeStatement * scope, bool includePragma = false);
1442
1443 //midend/programTransformation/partialRedundancyElimination/pre.h
1445std::vector<SgVariableSymbol*> getSymbolsUsedInExpression(SgExpression* expr);
1446
1448
1453std::vector<SgBreakStmt*> findBreakStmts(SgStatement* code, const std::string& fortranLabel = "");
1454
1456
1461std::vector<SgContinueStmt*> findContinueStmts(SgStatement* code, const std::string& fortranLabel = "");
1462std::vector<SgGotoStatement*> findGotoStmts(SgStatement* scope, SgLabelStatement* l);
1463std::vector<SgStatement*> getSwitchCases(SgSwitchStatement* sw);
1464
1466void collectVarRefs(SgLocatedNode* root, std::vector<SgVarRefExp* >& result);
1467
1469template <typename T>
1470T* findDeclarationStatement(SgNode* root, std::string name, SgScopeStatement* scope, bool isDefining)
1471 {
1472 bool found = false;
1473
1474#if 0
1475 printf ("In findDeclarationStatement(): root = %p \n",root);
1476 printf ("In findDeclarationStatement(): name = %s \n",name.c_str());
1477 printf ("In findDeclarationStatement(): scope = %p \n",scope);
1478 printf ("In findDeclarationStatement(): isDefining = %s \n",isDefining ? "true" : "false");
1479#endif
1480
1481 // Do we really want a NULL pointer to be acceptable input to this function?
1482 // Maybe we should have an assertion that it is non-null?
1483 if (!root) return NULL;
1484
1485 T* decl = dynamic_cast<T*>(root);
1486
1487#if 0
1488 printf ("In findDeclarationStatement(): decl = %p \n",decl);
1489#endif
1490
1491 if (decl != NULL)
1492 {
1493 if (scope)
1494 {
1495 if ((decl->get_scope() == scope) && (decl->search_for_symbol_from_symbol_table()->get_name() == name))
1496 {
1497 found = true;
1498 }
1499 }
1500 else // Liao 2/9/2010. We should allow NULL scope
1501 {
1502#if 0
1503 // DQ (12/6/2016): Include this into the debugging code to aboid compiler warning about unused variable.
1504 SgSymbol* symbol = decl->search_for_symbol_from_symbol_table();
1505 printf ("In findDeclarationStatement(): decl->search_for_symbol_from_symbol_table() = %p \n",symbol);
1506 printf ("In findDeclarationStatement(): decl->search_for_symbol_from_symbol_table()->get_name() = %s \n",symbol->get_name().str());
1507#endif
1508 if (decl->search_for_symbol_from_symbol_table()->get_name() == name)
1509 {
1510 found = true;
1511 }
1512 }
1513 }
1514
1515 if (found)
1516 {
1517 if (isDefining)
1518 {
1519#if 0
1520 printf ("In findDeclarationStatement(): decl->get_firstNondefiningDeclaration() = %p \n",decl->get_firstNondefiningDeclaration());
1521 printf ("In findDeclarationStatement(): decl->get_definingDeclaration() = %p \n",decl->get_definingDeclaration());
1522#endif
1523 ROSE_ASSERT (decl->get_definingDeclaration() != NULL);
1524#if 0
1525 printf ("In findDeclarationStatement(): returing decl->get_definingDeclaration() = %p \n",decl->get_definingDeclaration());
1526#endif
1527 return dynamic_cast<T*> (decl->get_definingDeclaration());
1528 }
1529 else
1530 {
1531#if 0
1532 printf ("In findDeclarationStatement(): returing decl = %p \n",decl);
1533#endif
1534 return decl;
1535 }
1536 }
1537
1538 std::vector<SgNode*> children = root->get_traversalSuccessorContainer();
1539
1540#if 0
1541 printf ("In findDeclarationStatement(): children.size() = %zu \n",children.size());
1542#endif
1543
1544 // DQ (4/10/2016): Note that if we are searching for a function member that has it's defining
1545 // declaration defined outside of the class then it will not be found in the child list.
1546 for (std::vector<SgNode*>::const_iterator i = children.begin(); i != children.end(); ++i)
1547 {
1548 T* target = findDeclarationStatement<T> (*i,name,scope,isDefining);
1549
1550 if (target)
1551 {
1552 return target;
1553 }
1554 }
1555
1556 return NULL;
1557 }
1559 SgFunctionDeclaration* findFunctionDeclaration(SgNode* root, std::string name, SgScopeStatement* scope, bool isDefining);
1560
1561#if 0 //TODO
1562 // 1. preorder traversal from current SgNode till find next SgNode of type V_SgXXX
1563 // until reach the end node
1564 SgNode* getNextSgNode( const SgNode* astSourceNode, VariantT=V_SgNode, SgNode* astEndNode=NULL);
1565
1566 // 2. return all nodes of type VariantT following the source node
1567 std::vector<SgNode*> getAllNextSgNode( const SgNode* astSourceNode, VariantT=V_SgNode, SgNode* astEndNode=NULL);
1568#endif
1569
1571
1572//------------------------------------------------------------------------
1574
1577// remember to put const to all arguments.
1578
1579
1594template <typename NodeType>
1595NodeType* getEnclosingNode(const SgNode* astNode, const bool includingSelf = false)
1596 {
1597#define DEBUG_GET_ENCLOSING_NODE 0
1598
1599#if 1 /* TOP_LEVEL_IF */
1600 // DQ (12/31/2019): This version does not detect a cycle that Robb's version detects in processing Cxx11_tests/test2016_23.C.
1601 // This will have to be investigated seperately from the issue I am working on currently.
1602
1603 // DQ (10/20/2012): This is the older version of this implementation. Until I am sure that
1604 // the newer version (below) is what we want to use I will resolve this conflict by keeping
1605 // the previous version in place.
1606
1607 if (nullptr == astNode)
1608 {
1609 return nullptr;
1610 }
1611
1612 if ( (includingSelf ) && (dynamic_cast<const NodeType*>(astNode)) )
1613 {
1614 return const_cast<NodeType*>(dynamic_cast<const NodeType*> (astNode));
1615 }
1616
1617 // DQ (3/5/2012): Check for reference to self...
1618 ROSE_ASSERT(astNode->get_parent() != astNode);
1619
1620 SgNode* parent = astNode->get_parent();
1621
1622 // DQ (3/5/2012): Check for loops that will cause infinite loops.
1623 SgNode* previouslySeenParent = parent;
1624 bool foundCycle = false;
1625 int counter = 0;
1626
1627#if DEBUG_GET_ENCLOSING_NODE
1628 printf ("In getEnclosingNode(): previouslySeenParent = %p = %s \n",previouslySeenParent,previouslySeenParent->class_name().c_str());
1629#endif
1630
1631 while ( (foundCycle == false) && (parent != nullptr) && (!dynamic_cast<const NodeType*>(parent)) )
1632 {
1633 ROSE_ASSERT(parent->get_parent() != parent);
1634
1635#if DEBUG_GET_ENCLOSING_NODE
1636 printf (" --- parent = %p = %s \n",parent,parent->class_name().c_str());
1637 printf (" --- --- parent->get_parent() = %p = %s \n",parent->get_parent(),parent->get_parent()->class_name().c_str());
1638#endif
1639
1640#if 1
1641 // DQ (1/8/2020): ROSE-82 (on RZ) This limit needs to be larger and increasing it to 500 was enough
1642 // for a specific code with a long chain of if-then-else nesting, So to make this sufficent for more
1643 // general code we have increased the lomit to 100,000. Note that 50 was not enough for real code,
1644 // but was enough for our regression tests.
1645 // DQ (12/30/2019): This is added to support detection of infinite loops over parent pointers.
1646 // if (counter >= 500)
1647 if (counter >= 100000)
1648 {
1649 printf ("Exiting: In getEnclosingNode(): loop limit exceeded: counter = %d \n",counter);
1650 ROSE_ABORT();
1651 }
1652#endif
1653 parent = parent->get_parent();
1654
1655 // DQ (3/5/2012): Check for loops that will cause infinite loops.
1656 // ROSE_ASSERT(parent != previouslySeenParent);
1657 if (parent == previouslySeenParent)
1658 {
1659 foundCycle = true;
1660 }
1661 counter++;
1662
1663 }
1664
1665#if DEBUG_GET_ENCLOSING_NODE
1666 printf ("previouslySeenParent = %p = %s \n",previouslySeenParent,previouslySeenParent->class_name().c_str());
1667#endif
1668
1669 parent = previouslySeenParent;
1670
1671 SgDeclarationStatement* declarationStatement = isSgDeclarationStatement(parent);
1672 if (declarationStatement != nullptr)
1673 {
1674#if 0
1675 printf ("Found a SgDeclarationStatement \n");
1676#endif
1677 SgDeclarationStatement* definingDeclaration = declarationStatement->get_definingDeclaration();
1678 SgDeclarationStatement* firstNondefiningDeclaration = declarationStatement->get_firstNondefiningDeclaration();
1679
1680#if 0
1681 printf (" --- declarationStatement = %p \n",declarationStatement);
1682 printf (" --- definingDeclaration = %p \n",definingDeclaration);
1683 if (definingDeclaration != NULL && definingDeclaration->get_parent() != NULL)
1684 printf (" --- definingDeclaration ->get_parent() = %p = %s \n",definingDeclaration->get_parent(),definingDeclaration->get_parent()->class_name().c_str());
1685 printf (" --- firstNondefiningDeclaration = %p \n",firstNondefiningDeclaration);
1686 if (firstNondefiningDeclaration != NULL && firstNondefiningDeclaration->get_parent() != NULL)
1687 printf (" --- firstNondefiningDeclaration ->get_parent() = %p = %s \n",firstNondefiningDeclaration->get_parent(),firstNondefiningDeclaration->get_parent()->class_name().c_str());
1688#endif
1689 if (definingDeclaration != nullptr && declarationStatement != firstNondefiningDeclaration)
1690 {
1691#if 0
1692 printf ("Found a nondefining declaration so use the non-defining declaration instead \n");
1693#endif
1694 // DQ (10/19/2012): Use the defining declaration instead.
1695 // parent = firstNondefiningDeclaration;
1696 parent = definingDeclaration;
1697 }
1698 }
1699
1700#if 0
1701 printf ("reset: previouslySeenParent = %p = %s \n",previouslySeenParent,previouslySeenParent->class_name().c_str());
1702#endif
1703
1704 // DQ (10/19/2012): This branch is just to document the cycle that was previously detected, it is for
1705 // debugging only. Thus it ony make sense for it to be executed when "(foundCycle == true)". However,
1706 // this will have to be revisited later since it appears clear that it is a problem for the binary analysis
1707 // work when it is visited for this case. Since the cycle is detected, but there is no assertion on the
1708 // cycle, we don't exit when a cycle is identified (which is the point of the code below).
1709 // Note also that I have fixed the code (above and below) to only chase pointers through defining
1710 // declarations (where they exist), this is important since non-defining declarations can be almost
1711 // anywhere (and thus chasing them can make it appear that there are cycles where there are none
1712 // (I think); test2012_234.C demonstrates an example of this.
1713 // DQ (10/9/2012): Robb has suggested this change to fix the binary analysis work.
1714 // if (foundCycle == true)
1715 if (foundCycle == false)
1716 {
1717
1718
1719 while ( (parent != nullptr) && (!dynamic_cast<const NodeType*>(parent)) )
1720 {
1721 ROSE_ASSERT(parent->get_parent() != parent);
1722#if 0
1723 printf ("In getEnclosingNode() (2nd try): parent = %p = %s \n",parent,parent->class_name().c_str());
1724 if (parent->get_file_info() != NULL)
1725 parent->get_file_info()->display("In getEnclosingNode() (2nd try): debug");
1726#endif
1727 SgDeclarationStatement* declarationStatement = isSgDeclarationStatement(parent);
1728 if (declarationStatement != nullptr)
1729 {
1730#if DEBUG_GET_ENCLOSING_NODE
1731 printf ("Found a SgDeclarationStatement \n");
1732#endif
1733 SgDeclarationStatement* definingDeclaration = declarationStatement->get_definingDeclaration();
1734 SgDeclarationStatement* firstNondefiningDeclaration = declarationStatement->get_firstNondefiningDeclaration();
1735 if (definingDeclaration != nullptr && declarationStatement != firstNondefiningDeclaration)
1736 {
1737#if 0
1738 printf ("Found a nondefining declaration so use the firstNondefining declaration instead \n");
1739#endif
1740 // DQ (10/19/2012): Use the defining declaration instead.
1741 // parent = firstNondefiningDeclaration;
1742 parent = definingDeclaration;
1743 }
1744 }
1745
1746 parent = parent->get_parent();
1747
1748#if 1
1749 // DQ (3/5/2012): Check for loops that will cause infinite loops.
1750 ROSE_ASSERT(parent != previouslySeenParent);
1751#else
1752 printf ("WARNING::WARNING::WARNING commented out assertion for parent != previouslySeenParent \n");
1753 if (parent == previouslySeenParent)
1754 break;
1755#endif
1756 }
1757 }
1758
1759 return const_cast<NodeType*>(dynamic_cast<const NodeType*> (parent));
1760#else /* TOP_LEVEL_IF */
1761 // DQ (10/20/2012): Using Robb's newer version with my modification to use the definingDeclaration rather than firstNondefiningDeclaration (below).
1762
1763 // Find the parent of specified type, but watch out for cycles in the ancestry (which would cause an infinite loop).
1764 // Cast away const because isSg* functions aren't defined for const node pointers; and our return is not const.
1765 SgNode *node = const_cast<SgNode*>(!astNode || includingSelf ? astNode : astNode->get_parent());
1766 std::set<const SgNode*> seen; // nodes we've seen, in order to detect cycles
1767 while (node) {
1768 if (NodeType *found = dynamic_cast<NodeType*>(node))
1769 return found;
1770
1771 // FIXME: Cycle detection could be moved elsewhere so we don't need to do it on every call. [RPM 2012-10-09]
1772 // DQ (12/30/2019): Provide more detail in error message.
1773 if (seen.insert(node).second == false)
1774 {
1775 printf ("Error: node is already in set and defines a cycle: node = %p = %s \n",node,node->class_name().c_str());
1776 std::set<const SgNode*>::const_iterator i = seen.begin();
1777 while (i != seen.end())
1778 {
1779 const SgNode* element = *i;
1780 printf (" --- seen element: element = %p = %s \n",element,element->class_name().c_str());
1781 i++;
1782 }
1783
1784 printf ("Exiting after error! \n");
1785 ROSE_ABORT();
1786 }
1787 // ROSE_ASSERT(seen.insert(node).second);
1788
1789 // Traverse to parent (declaration statements are a special case)
1790 if (SgDeclarationStatement *declarationStatement = isSgDeclarationStatement(node)) {
1791 SgDeclarationStatement *definingDeclaration = declarationStatement->get_definingDeclaration();
1792 SgDeclarationStatement *firstNondefiningDeclaration = declarationStatement->get_firstNondefiningDeclaration();
1793 if (definingDeclaration && firstNondefiningDeclaration && declarationStatement != firstNondefiningDeclaration) {
1794 // DQ (10/19/2012): Use the defining declaration instead.
1795 // node = firstNondefiningDeclaration;
1796 node = definingDeclaration;
1797 }
1798 } else {
1799 node = node->get_parent();
1800 }
1801 }
1802 return NULL;
1803#endif /* TOP_LEVEL_IF */
1804 }
1805
1807 ROSE_DLL_API SgSourceFile* getEnclosingSourceFile(SgNode* n, const bool includingSelf=false);
1808
1810 ROSE_DLL_API SgScopeStatement* getScope(const SgNode* astNode);
1811
1813 ROSE_DLL_API SgScopeStatement* getEnclosingScope(SgNode* n, const bool includingSelf=false);
1814
1816 ROSE_DLL_API SgGlobal* getGlobalScope( const SgNode* astNode);
1817
1818 // DQ (12/7/2020): This is supporting the recognition of functions in header files from two different AST.
1820 ROSE_DLL_API bool hasSameGlobalScope ( SgStatement* statement_1, SgStatement* statement_2 );
1821
1823 ROSE_DLL_API SgFunctionDefinition* getEnclosingProcedure(SgNode* n, const bool includingSelf=false);
1824
1825 ROSE_DLL_API SgFunctionDefinition* getEnclosingFunctionDefinition(SgNode* astNode, const bool includingSelf=false);
1826
1828 ROSE_DLL_API SgStatement* getEnclosingStatement(SgNode* n);
1829
1832
1835
1837 ROSE_DLL_API SgScopeStatement* findEnclosingLoop(SgStatement* s, const std::string& fortranLabel = "", bool stopOnSwitches = false);
1838
1840 ROSE_DLL_API SgFunctionDeclaration * getEnclosingFunctionDeclaration (SgNode * astNode, const bool includingSelf=false);
1841 //roseSupport/utility_functions.h
1843 ROSE_DLL_API SgFile* getEnclosingFileNode (SgNode* astNode );
1844
1847
1849 ROSE_DLL_API SgClassDefinition* getEnclosingClassDefinition(SgNode* astnode, const bool includingSelf=false);
1850
1852 ROSE_DLL_API SgClassDeclaration* getEnclosingClassDeclaration( SgNode* astNode );
1853
1854 // DQ (2/7/2019): Adding support for name qualification of variable references associated with SgPointerMemberType function parameters.
1856 ROSE_DLL_API SgExprListExp* getEnclosingExprListExp(SgNode* astNode, const bool includingSelf = false);
1857
1858 // DQ (2/7/2019): Need a function to return when an expression is in an expression subtree.
1859 // This is part of index evaluation ofr expressions in function argument lists, but likely usefule elsewhere as well.
1860 ROSE_DLL_API bool isInSubTree(SgExpression* subtree, SgExpression* exp);
1861
1862 // DQ (2/7/2019): Need a function to return the SgFunctionDeclaration from a SgFunctionCallExp.
1863 ROSE_DLL_API SgFunctionDeclaration* getFunctionDeclaration ( SgFunctionCallExp* functionCallExp );
1864
1865 // DQ (2/17/2019): Generalizing this support for SgVarRefExp and SgMemberFunctionRefExp nodes.
1866 // DQ (2/8/2019): Adding support for detecting when to use added name qualification for pointer-to-member expressions.
1867 ROSE_DLL_API bool isDataMemberReference(SgVarRefExp* varRefExp);
1868 // ROSE_DLL_API bool isAddressTaken(SgVarRefExp* varRefExp);
1869 ROSE_DLL_API bool isAddressTaken(SgExpression* refExp);
1870
1871 // DQ (2/17/2019): Adding support for detecting when to use added name qualification for membr function references.
1872 ROSE_DLL_API bool isMemberFunctionMemberReference(SgMemberFunctionRefExp* memberFunctionRefExp);
1873
1874 // DQ (2/15/2019): Adding support for detecting which class a member reference is being made from.
1875 // ROSE_DLL_API SgClassType* getClassTypeForDataMemberReference(SgVarRefExp* varRefExp);
1876 // ROSE_DLL_API std::list<SgClassType*> getClassTypeChainForDataMemberReference(SgVarRefExp* varRefExp);
1877 ROSE_DLL_API std::list<SgClassType*> getClassTypeChainForMemberReference(SgExpression* refExp);
1878
1879 ROSE_DLL_API std::set<SgNode*> getFrontendSpecificNodes();
1880
1881 // DQ (2/17/2019): Display the shared nodes in the AST for debugging.
1882 ROSE_DLL_API void outputSharedNodes( SgNode* node );
1883
1884 // DQ (10/31/2020): Added function to help debug edits to statements in scopes.
1885 ROSE_DLL_API void displayScope(SgScopeStatement* scope);
1886
1887// TODO
1888#if 0
1889 SgNode * getEnclosingSgNode(SgNode* source,VariantT, SgNode* endNode=NULL);
1890 std::vector<SgNode *> getAllEnclosingSgNode(SgNode* source,VariantT, SgNode* endNode=NULL);
1891 SgVariableDeclaration* findVariableDeclaratin( const string& varname)
1892
1894
1895 // e.g. for some expression, find its parent statement
1896 SgStatement* getEnclosingStatement(const SgNode* astNode);
1897
1898 SgSwitchStatement* getEnclosingSwitch(SgStatement* s);
1899 SgModuleStatement* getEnclosingModuleStatement( const SgNode* astNode);
1900
1901 // used to build a variable reference for compiler generated code in current scope
1902 SgSymbol * findReachingDefinition (SgScopeStatement* startScope, SgName &name);
1903#endif
1905
1906//------------------------------------------------------------------------
1908
1911 // Liao, 1/9/2008
1915 ROSE_DLL_API SgGlobal * getFirstGlobalScope(SgProject *project);
1916
1920 ROSE_DLL_API SgStatement* getLastStatement(SgScopeStatement *scope);
1921
1923 ROSE_DLL_API SgStatement* getFirstStatement(SgScopeStatement *scope,bool includingCompilerGenerated=false);
1926
1928 ROSE_DLL_API SgStatement* getNextStatement(SgStatement * currentStmt);
1929
1931 ROSE_DLL_API SgStatement* getPreviousStatement(SgStatement * currentStmt, bool climbOutScope = true);
1932#if 0 //TODO
1933 // preorder traversal from current SgNode till find next SgNode of type V_SgXXX
1934 SgNode* getNextSgNode( const SgNode* currentNode, VariantT=V_SgNode);
1935#endif
1936
1937 // DQ (11/15/2018): Adding support for traversals over the include file tree.
1939 ROSE_DLL_API void listHeaderFiles ( SgIncludeFile* includeFile );
1940
1941 // DQ (5/9/2021): Adding support for detection of statements in a scope that must be unparsed.
1946 ROSE_DLL_API bool scopeHasStatementsFromSameFile(SgScopeStatement* scope);
1947
1949
1950//------------------------------------------------------------------------
1952
1956 ROSE_DLL_API bool isEqualToIntConst(SgExpression* e, int value);
1957
1959
1962 ROSE_DLL_API bool isSameFunction(SgFunctionDeclaration* func1, SgFunctionDeclaration* func2);
1963
1965 ROSE_DLL_API bool isLastStatement(SgStatement* stmt);
1966
1968
1969//------------------------------------------------------------------------
1971
1977#if 1
1979 {
1980 // DQ (11/19/2020): We need to expand the use of this to cover deffered transformations of common SageInterface transformations (e.g. replaceStatement).
1981 // So I needed to move this out of being specific to the outliner and make it more generally data structure in the SageInterface.
1982
1983 // DQ (11/15/2020): Need to add the concept of deffered transformation to cover replaceStatement operations.
1984
1985 // DQ (8/7/2019): Store data required to support defering the transformation to insert the outlined function prototypes
1986 // into class declaration (when this is required to support the outlined function's access to protected or private data members).
1987 // This is part of an optimization to support the optimization of header file unparsing (limiting the overhead of supporting any
1988 // header file to just focus on the few (typically one) header file that would have to be unparsed.
1989
1990 enum TransformationKind
1991 {
1992 // DQ (11/22/2020): Might need to also add SageInterface::addDefaultConstructorIfRequired() and SageStatement::insert_statment()
1993 // to support the processStatements.C transforamtions to pre-process the AST (return expressions and variable initializations).
1994 e_error,
1995 e_default,
1996 e_outliner,
1997 e_replaceStatement,
1998 e_removeStatement,
1999 e_replaceDefiningFunctionDeclarationWithFunctionPrototype,
2000 e_last
2001 };
2002
2003 TransformationKind deferredTransformationKind;
2004
2005 // DQ (12/12/2020): Adding a string label so that we can name the different kinds of transformations.
2006 // E.g. moving pattern matched function from header file to dynamic library, vs. replacing function
2007 // definitions in the dynamic library file with function prototypes.
2008 std::string transformationLabel;
2009
2010 // Remove sets statementToRemove, replace sets statementToRemove and StatementToAdd.
2011 SgStatement* statementToRemove;
2012 SgStatement* statementToAdd;
2013
2014 SgClassDefinition* class_definition;
2015 SgDeclarationStatement* target_class_member;
2016 SgDeclarationStatement* new_function_prototype;
2017
2018 typedef std::set<SgClassDefinition *> ClassDefSet_t;
2019 ClassDefSet_t targetClasses;
2020
2021 typedef std::vector<SgFunctionDeclaration *> FuncDeclList_t;
2022 FuncDeclList_t targetFriends;
2023
2024 // DQ (2/28/2021): Adding support for outlining where it involves building up pre-transformations.
2025 // For example, in the code segregation, we build a conditiona around the interval of statements
2026 // that we are outlining. This conditional is used to overwrite the first statement in the interval
2027 // list. Because we don't want to transform the AST until after the outlining, we need so save the
2028 // whole interval so that we, after the outlining, remove the statements in the interval after that
2029 // first statement.
2030 typedef std::vector<SgStatement*> IntervalType;
2031 IntervalType statementInterval;
2032 SgStatement* locationToOverwriteWithTransformation;
2033 SgStatement* transformationToOverwriteFirstStatementInInterval;
2034 SgBasicBlock* blockOfStatementsToOutline;
2035
2036 // DQ (12/5/2019): Added ROSE_DLL_API prefix for Windows support (too all of these functions).
2037 ROSE_DLL_API DeferredTransformation();
2038 ROSE_DLL_API DeferredTransformation(SgClassDefinition* class_definition, SgDeclarationStatement* target_class_member, SgDeclarationStatement* new_function_prototype);
2039 ROSE_DLL_API DeferredTransformation (const DeferredTransformation& X);
2040 ROSE_DLL_API ~DeferredTransformation (void);
2041
2043
2044 // DQ (11/20/20): static function to generate specialized version of deferred transformation object.
2046 static ROSE_DLL_API DeferredTransformation replaceStatement(SgStatement* oldStmt, SgStatement* newStmt, bool movePreprocessinInfo = false);
2047
2048 static ROSE_DLL_API std::string outputDeferredTransformationKind(const TransformationKind & kind);
2049 ROSE_DLL_API void display ( std::string label ) const;
2050
2051 };
2052#endif
2053
2054
2055// DQ (2/24/2009): Simple function to delete an AST subtree (used in outlining).
2057ROSE_DLL_API void deleteAST(SgNode* node);
2058
2059// DQ (2/13/2022): Adding support to delete the whole AST (every SgNode).
2060ROSE_DLL_API void deleteAllNodes();
2061
2062// DQ (3/5/2022): Adding support to check AST for invalid poionters.
2063ROSE_DLL_API void checkSgNodePointers();
2064
2067
2068// DQ (2/25/2009): Added new function to support outliner.
2070ROSE_DLL_API void moveStatementsBetweenBlocks ( SgBasicBlock* sourceBlock, SgBasicBlock* targetBlock );
2071
2073ROSE_DLL_API void moveStatementsBetweenBlocks ( SgAdaPackageSpec * sourceBlock, SgNamespaceDefinitionStatement* targetBlock );
2074
2076ROSE_DLL_API void moveStatementsBetweenBlocks ( SgAdaPackageBody* sourceBlock, SgNamespaceDefinitionStatement* targetBlock );
2077
2080
2082ROSE_DLL_API bool isLambdaFunction (SgFunctionDeclaration* func);
2083
2085ROSE_DLL_API bool isLambdaCapturedVariable (SgVarRefExp* varRef);
2086
2087
2089ROSE_DLL_API void moveVariableDeclaration(SgVariableDeclaration* decl, SgScopeStatement* target_scope);
2091ROSE_DLL_API void appendStatement(SgStatement *stmt, SgScopeStatement* scope=NULL);
2092
2094ROSE_DLL_API void appendStatement(SgStatement *stmt, SgForInitStatement* for_init_stmt);
2095
2097ROSE_DLL_API void appendStatementList(const std::vector<SgStatement*>& stmt, SgScopeStatement* scope=NULL);
2098
2099// DQ (2/6/2009): Added function to support outlining into separate file.
2101ROSE_DLL_API void appendStatementWithDependentDeclaration( SgDeclarationStatement* decl, SgGlobal* scope, SgStatement* original_statement, bool excludeHeaderFiles );
2102
2105ROSE_DLL_API void prependStatement(SgStatement *stmt, SgScopeStatement* scope=NULL);
2106
2108ROSE_DLL_API void prependStatement(SgStatement *stmt, SgForInitStatement* for_init_stmt);
2109
2112ROSE_DLL_API void prependStatementList(const std::vector<SgStatement*>& stmt, SgScopeStatement* scope=NULL);
2113
2117ROSE_DLL_API bool hasSimpleChildrenList (SgScopeStatement* scope);
2118
2120ROSE_DLL_API void insertStatement(SgStatement *targetStmt, SgStatement* newStmt, bool insertBefore= true, bool autoMovePreprocessingInfo = true);
2121
2123//target's scope
2124ROSE_DLL_API void insertStatementList(SgStatement *targetStmt, const std::vector<SgStatement*>& newStmts, bool insertBefore= true);
2125
2127ROSE_DLL_API void insertStatementBefore(SgStatement *targetStmt, SgStatement* newStmt, bool autoMovePreprocessingInfo = true);
2128
2130ROSE_DLL_API void insertStatementListBefore(SgStatement *targetStmt, const std::vector<SgStatement*>& newStmts);
2131
2133ROSE_DLL_API void insertStatementAfter(SgStatement *targetStmt, SgStatement* newStmt, bool autoMovePreprocessingInfo = true);
2134
2136ROSE_DLL_API void insertStatementListAfter(SgStatement *targetStmt, const std::vector<SgStatement*>& newStmt);
2137
2140
2142ROSE_DLL_API void insertStatementAfterLastDeclaration(std::vector<SgStatement*> stmt_list, SgScopeStatement* scope);
2143
2145// then the statement is inserted at the end of the scope.
2147 bool movePreprocessingInfo=true);
2148
2150//then the new statements are inserted at the end of the scope.
2151ROSE_DLL_API void insertStatementListBeforeFirstNonDeclaration(const std::vector<SgStatement*> &newStmts, SgScopeStatement *scope);
2152
2153// DQ (11/21/2018): We need to sometimes insert something after the last statement of the collection from rose_edg_required_macros_and_functions.h.
2154ROSE_DLL_API SgStatement* lastFrontEndSpecificStatement( SgGlobal* globalScope );
2155
2157ROSE_DLL_API void removeStatement(SgStatement* stmt, bool autoRelocatePreprocessingInfo = true);
2158
2160ROSE_DLL_API void deepDelete(SgNode* root);
2161
2163ROSE_DLL_API void replaceStatement(SgStatement* oldStmt, SgStatement* newStmt, bool movePreprocessinInfo = false);
2164
2166ROSE_DLL_API SgNode* replaceWithPattern (SgNode * anchor, SgNode* new_pattern);
2167
2169// Essentially replace variable a with b.
2170ROSE_DLL_API void replaceVariableReferences(SgVariableSymbol* old_sym, SgVariableSymbol* new_sym, SgScopeStatement * scope );
2171
2172// DQ (11/12/2018): Adding test to avoid issues that we can't test for in the unparsing of header files using the token based unparsing.
2176ROSE_DLL_API bool statementCanBeTransformed(SgStatement* stmt);
2177
2178
2189std::pair<SgVariableDeclaration*, SgExpression* > createTempVariableForExpression(SgExpression* expression,
2190 SgScopeStatement* scope, bool initializeInDeclaration, SgAssignOp** reEvaluate = NULL);
2191
2192/* This function creates a temporary variable for a given expression in the given scope
2193 This is different from SageInterface::createTempVariableForExpression in that it does not
2194 try to be smart to create pointers to reference types and so on. The tempt is initialized to expression.
2195 The caller is responsible for setting the parent of SgVariableDeclaration since buildVariableDeclaration
2196 may not set_parent() when the scope stack is empty. See programTransformation/extractFunctionArgumentsNormalization/ExtractFunctionArguments.C for sample usage.
2197 @param expression Expression which will be replaced by a variable
2198 @param scope scope in which the temporary variable will be generated
2199*/
2200
2201std::pair<SgVariableDeclaration*, SgExpression*> createTempVariableAndReferenceForExpression
2202 (SgExpression* expression, SgScopeStatement* scope);
2203
2205
2212
2214ROSE_DLL_API void appendExpression(SgExprListExp *, SgExpression*);
2215
2217ROSE_DLL_API void appendExpressionList(SgExprListExp *, const std::vector<SgExpression*>&);
2218
2220template <class actualFunction>
2221void setParameterList(actualFunction *func,SgFunctionParameterList *paralist) {
2222
2223 // TODO consider the difference between C++ and Fortran
2224 // fixup the scope of arguments,no symbols for nondefining function declaration's arguments
2225
2226 // DQ (11/25/2011): templated function so that we can handle both
2227 // SgFunctionDeclaration and SgTemplateFunctionDeclaration (and their associated member
2228 // function derived classes).
2229
2230 ROSE_ASSERT(func != NULL);
2231 ROSE_ASSERT(paralist != NULL);
2232
2233#if 0
2234 // At this point we don't have cerr and endl defined, so comment this code out.
2235 // Warn to users if a paralist is being shared
2236 if (paralist->get_parent() !=NULL)
2237 {
2238 cerr << "Waring! Setting a used SgFunctionParameterList to function: "
2239 << (func->get_name()).getString()<<endl
2240 << " Sharing parameter lists can corrupt symbol tables!"<<endl
2241 << " Please use deepCopy() to get an exclusive parameter list for each function declaration!"<<endl;
2242 // ROSE_ASSERT(false);
2243 }
2244#endif
2245
2246 // Liao,2/5/2008 constructor of SgFunctionDeclaration will automatically generate SgFunctionParameterList, so be cautious when set new paralist!!
2247 if (func->get_parameterList() != NULL)
2248 {
2249 if (func->get_parameterList() != paralist)
2250 {
2251 delete func->get_parameterList();
2252 }
2253 }
2254
2255 func->set_parameterList(paralist);
2256 paralist->set_parent(func);
2257
2259 {
2260 // Ada stores variable declarations in the function parameter scope (for functions)
2261 // and in a discriminantScope (for discriminated declarations).
2262 // ==> just make sure that these are set.
2263 SgInitializedNamePtrList& args = paralist->get_args();
2264 for (SgInitializedNamePtrList::iterator i = args.begin(); i != args.end(); ++i)
2265 {
2266 ROSE_ASSERT(*i && isSgVariableDeclaration((*i)->get_declptr()));
2267 }
2268 }
2269 else
2270 {
2271 // DQ (5/15/2012): Need to set the declptr in each SgInitializedName IR node.
2272 // This is needed to support the AST Copy mechanism (at least). The files: test2005_150.C,
2273 // test2012_81.C and testcode2012_82.C demonstrate this problem.
2274 SgInitializedNamePtrList & args = paralist->get_args();
2275 for (SgInitializedNamePtrList::iterator i = args.begin(); i != args.end(); i++)
2276 {
2277 (*i)->set_declptr(func);
2278 }
2279 }
2280 }
2281
2283ROSE_DLL_API void setPragma(SgPragmaDeclaration* decl, SgPragma *pragma);
2284
2286ROSE_DLL_API void replaceExpression(SgExpression* oldExp, SgExpression* newExp, bool keepOldExp=false);
2287
2289ROSE_DLL_API void replaceExpressionWithStatement(SgExpression* from,
2293ROSE_DLL_API void replaceSubexpressionWithStatement(SgExpression* from,
2295
2297ROSE_DLL_API void setOperand(SgExpression* target, SgExpression* operand);
2298
2300ROSE_DLL_API void setLhsOperand(SgExpression* target, SgExpression* lhs);
2301
2303ROSE_DLL_API void setRhsOperand(SgExpression* target, SgExpression* rhs);
2304
2306ROSE_DLL_API void removeAllOriginalExpressionTrees(SgNode* top);
2307
2308// DQ (1/25/2010): Added support for directories
2310ROSE_DLL_API void moveToSubdirectory ( std::string directoryName, SgFile* file );
2311
2313ROSE_DLL_API SgStatement* findSurroundingStatementFromSameFile(SgStatement* targetStmt, bool & surroundingStatementPreceedsTargetStatement);
2314
2316ROSE_DLL_API void moveCommentsToNewStatement(SgStatement* sourceStatement, const std::vector<int> & indexList, SgStatement* destinationStatement, bool destinationStatementPreceedsSourceStatement);
2317
2318// DQ (7/19/2015): This is required to support general unparsing of template instantations for the GNU g++
2319// compiler which does not permit name qualification to be used to support the expression of the namespace
2320// where a template instantiatoon would be places. Such name qualification would also sometimes require
2321// global qualification which is also not allowed by the GNU g++ compiler. These issues appear to be
2322// specific to the GNU compiler versions, at least versions 4.4 through 4.8.
2324ROSE_DLL_API void moveDeclarationToAssociatedNamespace ( SgDeclarationStatement* declarationStatement );
2325
2326ROSE_DLL_API bool isTemplateInstantiationNode(SgNode* node);
2327
2328// DQ (5/23/2021): Added function to support test for template declaration (commented out, not required).
2329// ROSE_DLL_API bool isTemplateDeclarationNode(SgNode* node);
2330
2332
2333// DQ (12/1/2015): Adding support for fixup internal data struuctures that have references to statements (e.g. macro expansions).
2334ROSE_DLL_API void resetInternalMapsForTargetStatement(SgStatement* sourceStatement);
2335
2336// DQ (6/7/2019): Add support for transforming function definitions to function prototypes in a subtree.
2337// We might have to make this specific to a file (only traversing the functions in that file).
2346
2347// DQ (11/10/2019): Lower level support for convertFunctionDefinitionsToFunctionPrototypes().
2348// DQ (10/27/2020): Need to return the generated function prototype (incase we want to mark it for output or template unparsing from the AST).
2349// ROSE_DLL_API void replaceDefiningFunctionDeclarationWithFunctionPrototype ( SgFunctionDeclaration* functionDeclaration );
2350// ROSE_DLL_API SgDeclarationStatement* replaceDefiningFunctionDeclarationWithFunctionPrototype ( SgFunctionDeclaration* functionDeclaration );
2352ROSE_DLL_API std::vector<SgFunctionDeclaration*> generateFunctionDefinitionsList(SgNode* node);
2353
2354// DQ (10/29/2020): build a function prototype for all but member functions outside of the class (except for template instantiations).
2355// The reason why member functions outside of the class are an exception is because they can not be used except in a class and there
2356// would already be one present for the code to compile.
2357ROSE_DLL_API SgFunctionDeclaration* buildFunctionPrototype ( SgFunctionDeclaration* functionDeclaration );
2358
2359
2361//------------------------------------------------------------------------
2363
2371
2376ROSE_DLL_API int fixVariableReferences(SgNode* root, bool cleanUnusedSymbol=true);
2377
2379
2383ROSE_DLL_API void fixVariableDeclaration(SgVariableDeclaration* varDecl, SgScopeStatement* scope);
2384
2386ROSE_DLL_API void fixStructDeclaration(SgClassDeclaration* structDecl, SgScopeStatement* scope);
2388ROSE_DLL_API void fixClassDeclaration(SgClassDeclaration* classDecl, SgScopeStatement* scope);
2389
2391ROSE_DLL_API void fixNamespaceDeclaration(SgNamespaceDeclarationStatement* structDecl, SgScopeStatement* scope);
2392
2393
2395ROSE_DLL_API void fixLabelStatement(SgLabelStatement* label_stmt, SgScopeStatement* scope);
2396
2398ROSE_DLL_API void setFortranNumericLabel(SgStatement* stmt, int label_value,
2399 SgLabelSymbol::label_type_enum label_type=SgLabelSymbol::e_start_label_type,
2400 SgScopeStatement* label_scope=NULL);
2401
2403ROSE_DLL_API int suggestNextNumericLabel(SgFunctionDefinition* func_def);
2404
2406ROSE_DLL_API void fixFunctionDeclaration(SgFunctionDeclaration* stmt, SgScopeStatement* scope);
2407
2409ROSE_DLL_API void fixTemplateDeclaration(SgTemplateDeclaration* stmt, SgScopeStatement* scope);
2410
2412ROSE_DLL_API void fixStatement(SgStatement* stmt, SgScopeStatement* scope);
2413
2414// DQ (6/11/2015): This reports the statements that are marked as transformed (used to debug the token-based unparsing).
2416ROSE_DLL_API std::set<SgStatement*> collectTransformedStatements( SgNode* node );
2417
2419ROSE_DLL_API std::set<SgStatement*> collectModifiedStatements( SgNode* node );
2420
2422ROSE_DLL_API std::set<SgLocatedNode*> collectModifiedLocatedNodes( SgNode* node );
2423
2424// DQ (6/5/2019): Use the previously constructed set (above) to reset the IR nodes to be marked as isModified.
2426ROSE_DLL_API void resetModifiedLocatedNodes(const std::set<SgLocatedNode*> & modifiedNodeSet);
2427
2428
2429// DQ (10/23/2018): Report nodes that are marked as modified.
2430ROSE_DLL_API void reportModifiedStatements(const std::string & label, SgNode* node);
2431
2432// DQ (6/21/2021): Report nodes that are marked as modified.
2433ROSE_DLL_API void reportModifiedLocatedNodes( const std::string & label, SgNode* node );
2434
2435// DQ (3/22/2019): Translate CPP directives from attached preprocessor information to CPP Directive Declaration IR nodes.
2436ROSE_DLL_API void translateToUseCppDeclarations( SgNode* n );
2437
2438ROSE_DLL_API void translateScopeToUseCppDeclarations( SgScopeStatement* scope );
2439
2440ROSE_DLL_API std::vector<SgC_PreprocessorDirectiveStatement*> translateStatementToUseCppDeclarations( SgStatement* statement, SgScopeStatement* scope);
2441ROSE_DLL_API void printOutComments ( SgLocatedNode* locatedNode );
2442ROSE_DLL_API bool skipTranslateToUseCppDeclaration( PreprocessingInfo* currentPreprocessingInfo );
2443
2444// DQ (12/2/2019): Debugging support.
2445ROSE_DLL_API void outputFileIds( SgNode* node );
2446
2447
2449
2451
2457
2458//------------------------------------------------------------------------
2460
2465ROSE_DLL_API bool
2466collectReadWriteRefs(SgStatement* stmt, std::vector<SgNode*>& readRefs, std::vector<SgNode*>& writeRefs, bool useCachedDefUse=false);
2467
2469ROSE_DLL_API bool collectReadWriteVariables(SgStatement* stmt, std::set<SgInitializedName*>& readVars, std::set<SgInitializedName*>& writeVars, bool coarseGrain=true);
2470
2472ROSE_DLL_API void collectReadOnlyVariables(SgStatement* stmt, std::set<SgInitializedName*>& readOnlyVars, bool coarseGrain=true);
2473
2475ROSE_DLL_API void collectReadOnlySymbols(SgStatement* stmt, std::set<SgVariableSymbol*>& readOnlySymbols, bool coarseGrain=true);
2476
2478ROSE_DLL_API bool isUseByAddressVariableRef(SgVarRefExp* ref);
2479
2481ROSE_DLL_API void collectUseByAddressVariableRefs (const SgStatement* s, std::set<SgVarRefExp* >& varSetB);
2482
2483#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
2485ROSE_DLL_API LivenessAnalysis * call_liveness_analysis(SgProject* project, bool debug=false);
2486
2488ROSE_DLL_API void getLiveVariables(LivenessAnalysis * liv, SgForStatement* loop, std::set<SgInitializedName*>& liveIns, std::set<SgInitializedName*> & liveOuts);
2489#endif
2490
2492ROSE_DLL_API void ReductionRecognition(SgForStatement* loop, std::set< std::pair <SgInitializedName*, OmpSupport::omp_construct_enum> > & results);
2493
2495
2496ROSE_DLL_API void constantFolding(SgNode* r);
2497
2499
2501ROSE_DLL_API int instrumentEndOfFunction(SgFunctionDeclaration * func, SgStatement* s);
2502
2504ROSE_DLL_API void removeJumpsToNextStatement(SgNode*);
2505
2507ROSE_DLL_API void removeUnusedLabels(SgNode* top, bool keepChild =false);
2508
2510ROSE_DLL_API std::set<SgLabelStatement*> findUnusedLabels (SgNode* top);
2511
2513ROSE_DLL_API void removeConsecutiveLabels(SgNode* top);
2514
2516
2522ROSE_DLL_API bool mergeDeclarationAndAssignment (SgVariableDeclaration* decl, SgExprStatement* assign_stmt, bool removeAssignStmt = true);
2523
2524
2526ROSE_DLL_API bool mergeAssignmentWithDeclaration (SgExprStatement* assign_stmt, SgVariableDeclaration* decl, bool removeAssignStmt = true);
2527
2529
2532ROSE_DLL_API bool mergeDeclarationWithAssignment (SgVariableDeclaration* decl, SgExprStatement* assign_stmt);
2533
2535
2540
2542ROSE_DLL_API int splitVariableDeclaration (SgScopeStatement* scope, bool topLevelOnly = true);
2543
2545
2552 ROSE_DLL_API SgAssignInitializer* splitExpression(SgExpression* from, std::string newName = "");
2553
2555ROSE_DLL_API void splitExpressionIntoBasicBlock(SgExpression* expr);
2556
2558ROSE_DLL_API void removeLabeledGotos(SgNode* top);
2559
2561ROSE_DLL_API void changeBreakStatementsToGotos(SgStatement* loopOrSwitch);
2562
2565
2568
2571
2574
2577
2580
2583
2586
2588ROSE_DLL_API SgBasicBlock* ensureBasicBlockAsFalseBodyOfIf(SgIfStmt* ifs, bool createEmptyBody = true);
2589
2592
2595
2596// DQ (1/18/2015): This is added to support better quality token-based unparsing.
2598ROSE_DLL_API void cleanupNontransformedBasicBlockNode();
2599
2600// DQ (1/18/2015): This is added to support better quality token-based unparsing.
2602ROSE_DLL_API void recordNormalizations(SgStatement* s);
2603
2605ROSE_DLL_API int normalizeArrowExpWithAddressOfLeftOperand(SgNode* root, bool transformationGeneratedOnly=true);
2606
2607
2611
2613void changeAllBodiesToBlocks(SgNode* top, bool createEmptyBody = true);
2614
2615// The same as changeAllBodiesToBlocks(SgNode* top). Phased out.
2616//void changeAllLoopBodiesToBlocks(SgNode* top);
2617
2620
2621#if 0
2625SgLocatedNode* ensureBasicBlockAsParent(SgStatement* s);
2626#endif
2627
2630unsigned long long getIntegerConstantValue(SgValueExp* expr);
2631
2633std::vector<SgDeclarationStatement*> getDependentDeclarations (SgStatement* stmt );
2634
2635
2638
2640SgCommaOpExp *insertAfterUsingCommaOp (SgExpression* new_exp, SgExpression* anchor_exp, SgStatement** temp_decl = NULL, SgVarRefExp** temp_ref = NULL);
2641
2642
2672std::pair<SgStatement*, SgInitializedName*>
2673wrapFunction(SgFunctionDeclaration& definingDeclaration, SgName newName);
2674
2680template <class NameGen>
2681std::pair<SgStatement*, SgInitializedName*>
2682wrapFunction(SgFunctionDeclaration& definingDeclaration, NameGen nameGen)
2683{
2684 return wrapFunction(definingDeclaration, nameGen(definingDeclaration.get_name()));
2685}
2686
2690
2691
2693
2694// DQ (6/7/2012): Unclear where this function should go...
2695 bool hasTemplateSyntax( const SgName & name );
2696
2697#if 0
2698
2699//------------------------AST dump, stringify-----------------------------
2700//------------------------------------------------------------------------
2701 std::string buildOperatorString ( SgNode* astNode ); //transformationSupport.h
2702
2703 // do we need these?
2704 std::string dump_node(const SgNode* astNode);
2705 std::string dump_tree(const SgNode* astNode);
2706
2707 // or a friendly version of unparseToString(), as a memeber function
2708 std::string SgNode::toString(bool asSubTree=true); // dump node or subtree
2709
2710//----------------------------AST comparison------------------------------
2711//------------------------------------------------------------------------
2712// How to get generic functions for comparison?
2713 bool isNodeEqual(SgNode* node1, SgNode* node2); //?
2714 bool isTreeEqual(SgNode* tree1, SgNode* tree2);
2715
2717 bool expressionTreeEqual(SgExpression*, SgExpression*);
2719 bool expressionTreeEqualStar(const SgExpressionPtrList&,
2720 const SgExpressionPtrList&);
2721
2722//----------------------AST verfication/repair----------------------------
2723//------------------------------------------------------------------------
2724// sanity check of AST subtree, any suggestions?
2725// TODO
2726 verifySgNode(SgNode* node, bool subTree=true);
2727 //src/midend/astDiagnostics/AstConsistencyTests.h
2728 // AstTests::runAllTests(SgProject * )
2729
2730 //src/midend/astUtil/astInterface/AstInterface.h.C
2731 //FixSgProject(SgProject &project)
2732 //FixSgTree(SgNode* r)
2733
2734 //src/frontend/SageIII/astPostProcessing
2735 //AstPostProcessing(SgNode * node)
2736
2737//--------------------------AST modification------------------------------
2738//------------------------------------------------------------------------
2739// any operations changing AST tree, including
2740// insert, copy, delete(remove), replace
2741
2742 // insert before or after some point, argument list is consistent with LowLevelRewrite
2743 void insertAst(SgNode* targetPosition, SgNode* newNode, bool insertBefore=true);
2744
2745 // previous examples
2746 //void myStatementInsert(SgStatement* target,...)
2747 // void AstInterfaceBase::InsertStmt(AstNodePtr const & orig, AstNodePtr const &n, bool insertbefore, bool extractfromBasicBlock)
2748
2749 // copy
2750 // copy children of one basic block to another basic block
2751 //void appendStatementCopy (const SgBasicBlock* a, SgBasicBlock* b);
2752 void copyStatements (const SgBasicBlock* src, SgBasicBlock* dst);
2753
2754 // delete (remove) a node or a whole subtree
2755 void removeSgNode(SgNode* targetNode); // need this?
2756 void removeSgNodeTree(SgNode* subtree); // need this?
2757
2758 void removeStatement( SgStatement* targetStmt);
2759
2760 //Move = delete + insert
2761 void moveAst (SgNode* src, SgNode* target); // need this?
2762 // similar to
2763 void moveStatements (SgBasicBlock* src, SgBasicBlock* target);
2764
2765 // replace= delete old + insert new (via building or copying)
2766
2767// DQ (1/25/2010): This does not appear to exist as a definition anywhere in ROSE.
2768// void replaceAst(SgNode* oldNode, SgNode* newNode);
2769
2770 //void replaceChild(SgNode* parent, SgNode* from, SgNode* to);
2771 //bool AstInterface::ReplaceAst( const AstNodePtr& orig, const AstNodePtr& n)
2772
2773//--------------------------AST transformations---------------------------
2774//------------------------------------------------------------------------
2775// Advanced AST modifications through basic AST modifications
2776// Might not be included in AST utitlity list, but listed here for the record.
2777
2778 // extract statements/content from a scope
2779 void flattenBlocks(SgNode* n);
2780
2781 //src/midend/astInlining/inlinerSupport.h
2782 void renameVariables(SgNode* n);
2783 void renameLabels(SgNode* n, SgFunctionDefinition* enclosingFunctionDefinition);
2784
2785 void simpleCopyAndConstantPropagation(SgNode* top);
2786 void changeAllMembersToPublic(SgNode* n);
2787
2788 void removeVariableDeclaration(SgInitializedName* initname);
2789
2791 SgAssignOp* convertInitializerIntoAssignment(SgAssignInitializer* init);
2792
2797 void pushTestIntoBody(LoopStatement* loopStmt);
2798
2799 //programTransformation/finiteDifferencing/finiteDifferencing.h
2801 void moveForDeclaredVariables(SgNode* root);
2802
2803//------------------------ Is/Has functions ------------------------------
2804//------------------------------------------------------------------------
2805// misc. boolean functions
2806// some of them could moved to SgXXX class as a member function
2807
2808 bool isOverloaded (SgFunctionDeclaration * functionDeclaration);
2809
2810 bool isSwitchCond (const SgStatement* s);
2811 bool isIfCond (const SgStatement* s);
2812 bool isWhileCond (const SgStatement* s);
2813 bool isStdNamespace (const SgScopeStatement* scope);
2814 bool isTemplateInst (const SgDeclarationStatement* decl);
2815
2816
2817 bool isCtor (const SgFunctionDeclaration* func);
2818 bool isDtor (const SgFunctionDeclaration* func);
2819
2820 // src/midend/astInlining/typeTraits.h
2822 ROSE_DLL_API bool isNonconstReference(SgType* t);
2823 ROSE_DLL_API bool isReferenceType(SgType* t);
2824
2825 // generic ones, or move to the SgXXX class as a member function
2826
2827 bool isConst(SgNode* node); // const type, variable, function, etc.
2828 // .... and more
2829
2830 bool isConstType (const SgType* type);
2831 bool isConstFunction (const SgFunctionDeclaration* decl);
2832
2833
2834 bool isMemberVariable(const SgInitializedName & var);
2835 //bool isMemberVariable(const SgNode& in);
2836
2838 SgFunctionDeclaration * functionDeclaration,
2839 SgDeclarationStatement * startingAtDeclaration);
2840
2841 bool MayRedefined(SgExpression* expr, SgNode* root);
2842 // bool isPotentiallyModified(SgExpression* expr, SgNode* root); // inlinderSupport.h
2843 bool hasAddressTaken(SgExpression* expr, SgNode* root);
2844
2845 //src/midend/astInlining/inlinerSupport.C
2846 // can also classified as topdown search
2847 bool containsVariableReference(SgNode* root, SgInitializedName* var);
2848
2849 bool isDeclarationOf(SgVariableDeclaration* decl, SgInitializedName* var);
2850 bool isPotentiallyModifiedDuringLifeOf(SgBasicBlock* sc,
2851 SgInitializedName* toCheck,
2852 SgInitializedName* lifetime)
2853 //src/midend/programTransformation/partialRedundancyElimination/pre.h
2854 bool anyOfListPotentiallyModifiedIn(const std::vector<SgVariableSymbol*>& syms, SgNode* n);
2855
2856//------------------------ loop handling ---------------------------------
2857//------------------------------------------------------------------------
2858 //get and set loop control expressions
2859 // 0: init expr, 1: condition expr, 2: stride expr
2860
2861 SgExpression* getForLoopTripleValues(int valuetype,SgForStatement* forstmt );
2862 int setForLoopTripleValues(int valuetype,SgForStatement* forstmt, SgExpression* exp);
2863
2864 bool isLoopIndexVarRef(SgForStatement* forstmt, SgVarRefExp *varref);
2865 SgInitializedName * getLoopIndexVar(SgForStatement* forstmt);
2866
2867//------------------------expressions-------------------------------------
2868//------------------------------------------------------------------------
2869 //src/midend/programTransformation/partialRedundancyElimination/pre.h
2870 int countComputationsOfExpressionIn(SgExpression* expr, SgNode* root);
2871
2872 //src/midend/astInlining/replaceExpressionWithStatement.h
2873 void replaceAssignmentStmtWithStatement(SgExprStatement* from, StatementGenerator* to);
2874
2876 StatementGenerator* to);
2877 SgExpression* getRootOfExpression(SgExpression* n);
2878
2879//--------------------------preprocessing info. -------------------------
2880//------------------------------------------------------------------------
2882 void cutPreprocInfo (SgBasicBlock* b,
2884 AttachedPreprocessingInfoType& save_buf);
2886 void pastePreprocInfoFront (AttachedPreprocessingInfoType& save_buf,
2887 SgStatement* s);
2889 void pastePreprocInfoBack (AttachedPreprocessingInfoType& save_buf,
2890 SgStatement* s);
2891
2897 // a generic one for all
2899 void moveBeforePreprocInfo (SgStatement* src, SgStatement* dest);
2900 void moveInsidePreprocInfo (SgBasicBlock* src, SgBasicBlock* dest);
2901 void moveAfterPreprocInfo (SgStatement* src, SgStatement* dest);
2902
2903//--------------------------------operator--------------------------------
2904//------------------------------------------------------------------------
2905 from transformationSupport.h, not sure if they should be included here
2906 /* return enum code for SAGE operators */
2907 operatorCodeType classifyOverloadedOperator(); // transformationSupport.h
2908
2914 std::string stringifyOperator (std::string name);
2915
2916//--------------------------------macro ----------------------------------
2917//------------------------------------------------------------------------
2918 std::string buildMacro ( std::string s ); //transformationSupport.h
2919
2920//--------------------------------access functions---------------------------
2921//----------------------------------get/set sth.-----------------------------
2922// several categories:
2923* get/set a direct child/grandchild node or fields
2924* get/set a property flag value
2925* get a descendent child node using preorder searching
2926* get an ancestor node using bottomup/reverse searching
2927
2928 // SgName or string?
2929 std::string getFunctionName (SgFunctionCallExp* functionCallExp);
2930 std::string getFunctionTypeName ( SgFunctionCallExp* functionCallExpression );
2931
2932 // do we need them anymore? or existing member functions are enought?
2933 // a generic one:
2934 std::string get_name (const SgNode* node);
2935 std::string get_name (const SgDeclarationStatement * declaration);
2936
2937 // get/set some property: should moved to SgXXX as an inherent memeber function?
2938 // access modifier
2939 void setExtern (SgFunctionDeclartion*)
2940 void clearExtern()
2941
2942 // similarly for other declarations and other properties
2944 void setPublic()
2945 void setPrivate()
2946
2947#endif
2948
2949// DQ (1/23/2013): Added support for generated a set of source sequence entries.
2950 std::set<unsigned int> collectSourceSequenceNumbers( SgNode* astNode );
2951
2952//--------------------------------Type Traits (C++)---------------------------
2953 bool HasNoThrowAssign(const SgType * const inputType);
2954 bool HasNoThrowCopy(const SgType * const inputType);
2955 bool HasNoThrowConstructor(const SgType * const inputType);
2956 bool HasTrivialAssign(const SgType * const inputType);
2957 bool HasTrivialCopy(const SgType * const inputType);
2958 bool HasTrivialConstructor(const SgType * const inputType);
2959 bool HasTrivialDestructor(const SgType * const inputType);
2960 bool HasVirtualDestructor(const SgType * const inputType);
2961 bool IsBaseOf(const SgType * const inputBaseType, const SgType * const inputDerivedType);
2962 bool IsAbstract(const SgType * const inputType);
2964 bool IsClass(const SgType * const inputType);
2965 bool IsEmpty(const SgType * const inputType);
2966 bool IsEnum(const SgType * const inputType);
2967 bool IsPod(const SgType * const inputType);
2968 bool IsPolymorphic(const SgType * const inputType);
2969 bool IsStandardLayout(const SgType * const inputType);
2970 bool IsLiteralType(const SgType * const inputType);
2971 bool IsTrivial(const SgType * const inputType);
2972 bool IsUnion(const SgType * const inputType);
2974
2975// DQ (3/2/2014): Added a new interface function (used in the snippet insertion support).
2976// void supportForInitializedNameLists ( SgScopeStatement* scope, SgInitializedNamePtrList & variableList );
2977
2978// DQ (3/4/2014): Added support for testing two trees for equivalents using the AST iterators.
2979 bool isStructurallyEquivalentAST( SgNode* tree1, SgNode* tree2 );
2980
2981// JP (10/14/24): Moved code to evaluate a const integer expression (like in array size definitions) to SageInterface
2984 size_t value_;
2985 bool hasValue_;
2986 };
2989
2990// JP (9/17/14): Added function to test whether two SgType* are equivalent or not
2991 bool checkTypesAreEqual(SgType *typeA, SgType *typeB);
2992
2993//--------------------------------Java interface functions ---------------------
2994#ifdef ROSE_BUILD_JAVA_LANGUAGE_SUPPORT
2995 ROSE_DLL_API std::string getTempDirectory(SgProject *project);
2996 ROSE_DLL_API void destroyTempDirectory(std::string);
2997 ROSE_DLL_API SgFile *processFile(SgProject *, std::string, bool unparse = false);
2998 ROSE_DLL_API std::string preprocessPackage(SgProject *, std::string);
2999 ROSE_DLL_API std::string preprocessImport(SgProject *, std::string);
3000 ROSE_DLL_API SgFile* preprocessCompilationUnit(SgProject *, std::string, std::string, bool unparse = true);
3001 ROSE_DLL_API SgClassDefinition *findJavaPackage(SgScopeStatement *, std::string);
3002 ROSE_DLL_API SgClassDefinition *findOrInsertJavaPackage(SgProject *, std::string, bool create_directory = false);
3003 ROSE_DLL_API SgClassDeclaration *findOrImportJavaClass(SgProject *, SgClassDefinition *package_definition, std::string);
3004 ROSE_DLL_API SgClassDeclaration *findOrImportJavaClass(SgProject *, std::string, std::string);
3008#endif // ROSE_BUILD_JAVA_LANGUAGE_SUPPORT
3009
3010
3011
3012// DQ (8/31/2016): Making this a template function so that we can have it work with user defined filters.
3014
3020template < class T >
3022 {
3023 // DQ (9/1/2016): This function is called in the Call graph generation to avoid filtering out EDG normalized
3024 // function template instnatiations (which come from normalized template functions and member functions).
3025 // Note that because of the EDG normailzation the membr function is moved outside of the class, and
3026 // thus marked as compiler generated. However the template instantiations are always marked as compiler
3027 // generated (if not specializations) and so we want to include a template instantiation that is marked
3028 // as compiler generated, but is from a template declaration that satisfyied a specific user defined filter.
3029 // The complexity of this detection is isolated here, but knowing that it must be called is more complex.
3030 // This function is call in the CG.C file of tests/nonsmoke/functional/roseTests/programAnalysisTests/testCallGraphAnalysis.
3031
3032 bool retval = false;
3033
3034#define DEBUG_TEMPLATE_NORMALIZATION_DETECTION 0
3035
3036#if DEBUG_TEMPLATE_NORMALIZATION_DETECTION
3037 printf ("In isNormalizedTemplateInstantiation(): function = %p = %s = %s \n",function,function->class_name().c_str(),function->get_name().str());
3038#endif
3039
3040 // Test for this to be a template instantation (in which case it was marked as
3041 // compiler generated but we may want to allow it to be used in the call graph,
3042 // if it's template was a part was defined in the current directory).
3043 SgTemplateInstantiationFunctionDecl* templateInstantiationFunction = isSgTemplateInstantiationFunctionDecl(function);
3044 SgTemplateInstantiationMemberFunctionDecl* templateInstantiationMemberFunction = isSgTemplateInstantiationMemberFunctionDecl(function);
3045
3046 if (templateInstantiationFunction != NULL)
3047 {
3048 // When the defining function has been normalized by EDG, only the non-defining declaration will have a source position.
3049 templateInstantiationFunction = isSgTemplateInstantiationFunctionDecl(templateInstantiationFunction->get_firstNondefiningDeclaration());
3050 SgTemplateFunctionDeclaration* templateFunctionDeclaration = templateInstantiationFunction->get_templateDeclaration();
3051 if (templateFunctionDeclaration != NULL)
3052 {
3053 retval = filter->operator()(templateFunctionDeclaration);
3054 }
3055 else
3056 {
3057 // Assume false.
3058 }
3059
3060#if DEBUG_TEMPLATE_NORMALIZATION_DETECTION
3061 printf (" --- case of templateInstantiationFunction: retval = %s \n",retval ? "true" : "false");
3062#endif
3063 }
3064 else
3065 {
3066 if (templateInstantiationMemberFunction != NULL)
3067 {
3068 // When the defining function has been normalized by EDG, only the non-defining declaration will have a source position.
3069 templateInstantiationMemberFunction = isSgTemplateInstantiationMemberFunctionDecl(templateInstantiationMemberFunction->get_firstNondefiningDeclaration());
3070 SgTemplateMemberFunctionDeclaration* templateMemberFunctionDeclaration = templateInstantiationMemberFunction->get_templateDeclaration();
3071 if (templateMemberFunctionDeclaration != NULL)
3072 {
3073 retval = filter->operator()(templateMemberFunctionDeclaration);
3074 }
3075 else
3076 {
3077 // Assume false.
3078 }
3079
3080#if DEBUG_TEMPLATE_NORMALIZATION_DETECTION
3081 printf (" --- case of templateInstantiationMemberFunction: retval = %s \n",retval ? "true" : "false");
3082#endif
3083 }
3084 }
3085
3086 return retval;
3087 }
3088
3089void detectCycleInType(SgType * type, const std::string & from);
3090
3091// DQ (7/14/2020): Debugging support.
3092void checkForInitializers( SgNode* node );
3093
3094void clearSharedGlobalScopes(SgProject * project);
3095
3096}// end of namespace
3097
3098
3099
3100#endif
3101
to specify a construct using a specifier Can be used alone or with parent handles when relative speci...
Base class for all IR node attribute values.
Class for traversing the AST.
For preprocessing information including source comments, include , if, define, etc.
RelativePositionType
MK: Enum type to store if the directive goes before or after the corresponding line of source code.
void visit(SgNode *node)
this method is called at every traversed node.
Interface for creating a statement whose computation writes its answer into a given variable.
A persistent attribute to represent a unique name for an expression.
Base class for binary files.
Represents an interpretation of a binary container.
Base class for values.
This class represents the rhs of a variable declaration which includes an optional assignment (e....
This class represents the concept of a block (not a basic block from control flow analysis).
This class represents the concept of a C and C++ case option (used within a switch statement).
This class represents the concept of a catch within a try-catch construct used in C++ exception handl...
This class represents the concept of a class declaration statement. It includes the concept of an ins...
This class represents the concept of a class definition in C++.
This class represents the concept of a class name within the compiler.
Supporting class from copy mechanism within ROSE.
Definition sageCopy.h:26
This class represents the concept of a declaration statement.
SgDeclarationStatement * get_definingDeclaration() const
This is an access function for the SgDeclarationStatement::p_definingDeclaration data member (see tha...
SgDeclarationStatement * get_firstNondefiningDeclaration() const
This is an access function for the SgDeclarationStatement::p_firstNondefiningDeclaration data member ...
This class represents the concept of a C or C++ default case within a switch statement.
This class represents the concept of a do-while statement.
This class represents the concept of a C and C++ expression list.
This class represents the concept of a C or C++ statement which contains a expression.
This class represents the notion of an expression. Expressions are derived from SgLocatedNodes,...
This class represents a source file for a project (which may contian many source files and or directo...
This class represents the variable declaration or variable initialization withn a for loop.
This class represents the concept of a for loop.
This class represents the concept of a C++ function call (which is an expression).
This class represents the concept of a function declaration statement.
virtual std::string class_name() const override
returns a string representing the class name
This class represents the concept of a scope in C++ (e.g. global scope, fuction scope,...
This class represents the concept of a declaration list.
const SgInitializedNamePtrList & get_args() const
Access function for p_args.
This class represents a type for all functions.
This class represents the concept of a namespace definition.
This class represents the concept of an "if" construct.
This class represents the notion of a declared variable.
This class represents the notion of an initializer for a variable declaration or expression in a func...
This class represents the concept of a C or C++ label statement.
label_type_enum
Type of label used (fortran only)
This class represents the notion of an expression or statement which has a position within the source...
This class represents the concept of a member function declaration statement.
This class represents the member function being called and must be assembled in the SgFunctionCall wi...
This class represents strings within the IR nodes.
This class represents the concept of a C++ namespace declaration.
This class represents the concept of a namespace definition.
This class represents the concept of a namespace name within the compiler.
This class represents the base class for all IR nodes within Sage III.
SgNode * get_parent() const
Access function for parent node.
virtual std::vector< SgNode * > get_traversalSuccessorContainer() const
container of pointers to AST successor nodes used in the traversal overridden in every class by gener...
void set_parent(SgNode *parent)
All nodes in the AST contain a reference to a parent node.
virtual std::string class_name() const
returns a string representing the class name
virtual Sg_File_Info * get_file_info(void) const
File information containing filename, line number, column number, and if the SgNode is a part of a ne...
This class represents the concept of a C Assembler statement (untested).
This class represents a source project, with a list of SgFile objects and global information about th...
This class represents the concept of a scope in C++ (e.g. global scope, fuction scope,...
This class represents the notion of a statement.
This class represents the base class of a numbr of IR nodes that don't otherwise fit into the existin...
This class represents the concept of a switch.
This class represents the concept of a name within the compiler.
virtual SgName get_name() const =0
Access function for getting name from declarations or types internally.
This class represents template argument within the use of a template to build an instantiation.
This class represents the concept of a template declaration.
This class represents the concept of an instantiation of function template.
SgTemplateFunctionDeclaration * get_templateDeclaration() const
Returns pointer to SgTemplateDeclaration from which instantiation is generated.
This class represents the concept of an instantiation of member function template or a member functio...
SgTemplateMemberFunctionDeclaration * get_templateDeclaration() const
Returns pointer to SgTemplateDeclaration from which instantiation is generated.
This class represents the base class for all types.
This class represents the notion of an value (expression value).
This class represents the variable refernece in expressions.
This class represents the concept of a C or C++ variable declaration.
This class represents the concept of a variable name within the compiler (a shared container for the ...
This class represents the concept of a do-while statement.
void serialize(std::ostream &output, Graph &graph)
Serialize a graph into a stream of bytes.
Functions that are useful when operating on the AST.
Definition sageBuilder.h:25
ROSE_DLL_API void checkSgNodePointers()
Function to delete AST subtree's nodes only, users must take care of any dangling pointers,...
ROSE_DLL_API bool isLastStatement(SgStatement *stmt)
Check if a statement is the last statement within its closed scope.
ROSE_DLL_API bool isUnionDeclaration(SgNode *node)
Check if a SgNode is a declaration for a union.
ROSE_DLL_API void translateScopeToUseCppDeclarations(SgScopeStatement *scope)
Connect variable reference to the right variable symbols when feasible, return the number of referenc...
void initializeIfStmt(SgIfStmt *ifstmt, SgStatement *conditional, SgStatement *true_body, SgStatement *false_body)
Support function used for variable declarations in conditionals.
ROSE_DLL_API void deepDelete(SgNode *root)
Deep delete a sub AST tree. It uses postorder traversal to delete each child node....
void annotateExpressionsWithUniqueNames(SgProject *project)
Generate unique names for expressions and attach the names as persistent attributes ("UniqueNameAttri...
ROSE_DLL_API bool hasMultipleInitStatmentsOrExpressions(SgForStatement *for_loop)
Check if a for loop uses C99 style initialization statement with multiple expressions like for (int i...
ROSE_DLL_API void fixNamespaceDeclaration(SgNamespaceDeclarationStatement *structDecl, SgScopeStatement *scope)
Fix symbols, parent and scope pointers. Used internally within appendStatment(), insertStatement() et...
ROSE_DLL_API void deleteExpressionTreeWithOriginalExpressionSubtrees(SgNode *root)
Special purpose function for deleting AST expression tress containing valid original expression trees...
void setSourcePositionAsTransformation(SgNode *node)
DQ (5/1/2012): New function with improved name.
ROSE_DLL_API void insertStatementList(SgStatement *targetStmt, const std::vector< SgStatement * > &newStmts, bool insertBefore=true)
Insert a list of statements before or after the target statement within the.
void whereAmI(SgNode *node)
Diagnostic function for tracing back through the parent list to understand at runtime where in the AS...
ROSE_DLL_API bool isUpcSharedModifierType(SgModifierType *mod_type)
Check if a modifier type is a UPC shared type.
ROSE_DLL_API SgStatement * getLastStatement(SgScopeStatement *scope)
get the last statement within a scope, return NULL if it does not exit
ROSE_DLL_API void addStepToLoopBody(SgScopeStatement *loopStmt, SgStatement *step)
Add a step statement to the end of a loop body Add a new label to the end of the loop,...
ROSE_DLL_API bool is_UPC_dynamic_threads()
ROSE_DLL_API SgFunctionDeclaration * getFunctionDeclaration(SgFunctionCallExp *functionCallExp)
Find a node by type using upward traversal.
ROSE_DLL_API bool is_mixed_Fortran_and_C_language()
ROSE_DLL_API void addTextForUnparser(SgNode *astNode, std::string s, AstUnparseAttribute::RelativePositionType inputlocation)
Add a string to be unparsed to support code generation for back-end specific tools or compilers.
ROSE_DLL_API std::string getTempDirectory(SgProject *project)
Create a temporary directory if it does not yet exist and return its name.
ROSE_DLL_API void displayScope(SgScopeStatement *scope)
Find a node by type using upward traversal.
ROSE_DLL_API bool is_Jovial_language()
bool IsTrivial(const SgType *const inputType)
Collect all read and write references within stmt, which can be a function, a scope statement,...
ROSE_DLL_API SgMemberFunctionDeclaration * findJavaMain(SgClassDefinition *)
Find a main method in a Java class.
ROSE_DLL_API bool is_Cxx_language()
void resetScopeNumbers(SgFunctionDefinition *functionDeclaration)
Assigns unique numbers to each SgScopeStatement of a function.
ROSE_DLL_API SgFunctionDeclaration * replaceDefiningFunctionDeclarationWithFunctionPrototype(SgFunctionDeclaration *functionDeclaration)
Function to delete AST subtree's nodes only, users must take care of any dangling pointers,...
ROSE_DLL_API bool hasSameGlobalScope(SgStatement *statement_1, SgStatement *statement_2)
This is supporting the recognition of functions in header files from two different ASTs.
SgCommaOpExp * insertBeforeUsingCommaOp(SgExpression *new_exp, SgExpression *anchor_exp)
Insert an expression (new_exp )before another expression (anchor_exp) has possible side effects,...
ROSE_DLL_API void fixFunctionDeclaration(SgFunctionDeclaration *stmt, SgScopeStatement *scope)
Fix the symbol table and set scope (only if scope in declaration is not already set).
ROSE_DLL_API std::string preprocessImport(SgProject *, std::string)
Using the import_string parameter, create a file with the relevant import statement; translate the fi...
ROSE_DLL_API bool collectReadWriteRefs(SgStatement *stmt, std::vector< SgNode * > &readRefs, std::vector< SgNode * > &writeRefs, bool useCachedDefUse=false)
Collect all read and write references within stmt, which can be a function, a scope statement,...
ROSE_DLL_API void prependStatementList(const std::vector< SgStatement * > &stmt, SgScopeStatement *scope=NULL)
prepend a list of statements to the beginning of the current scope, handling side effects as appropri...
ROSE_DLL_API SgInitializer * getInitializerOfExpression(SgExpression *n)
Get the initializer containing an expression if it is within an initializer.
ROSE_DLL_API std::vector< SgInitializedName * > getInParameters(const SgInitializedNamePtrList &params)
Get a vector of Jovial input parameters from the function parameter list (may work for Fortran in the...
ROSE_DLL_API bool language_may_contain_nondeclarations_in_scope()
ROSE_DLL_API std::set< SgStatement * > collectTransformedStatements(SgNode *node)
This collects the statements that are marked as transformed (useful in debugging).
ROSE_DLL_API void cleanupNontransformedBasicBlockNode()
Remove unused basic block IR nodes added as part of normalization.
ROSE_DLL_API bool skipTranslateToUseCppDeclaration(PreprocessingInfo *currentPreprocessingInfo)
Connect variable reference to the right variable symbols when feasible, return the number of referenc...
ROSE_DLL_API AbstractHandle::abstract_handle * buildAbstractHandle(SgNode *)
Build an abstract handle from an AST node, reuse previously built handle when possible.
ROSE_DLL_API void insertStatementListBefore(SgStatement *targetStmt, const std::vector< SgStatement * > &newStmts)
Insert a list of statements before a target statement.
ROSE_DLL_API void fixStructDeclaration(SgClassDeclaration *structDecl, SgScopeStatement *scope)
Fix symbols, parent and scope pointers. Used internally within appendStatment(), insertStatement() et...
void recursivePrintCurrentAndParent(SgNode *n)
Recursively print current and parent nodes. used within gdb to probe the context of a node.
ROSE_DLL_API void appendExpressionList(SgExprListExp *, const std::vector< SgExpression * > &)
Append an expression list to a SgExprListExp, set the parent pointers also.
ROSE_DLL_API bool isUpcSharedArrayType(SgArrayType *array_type)
Check if an array type is a UPC shared type. ROSE AST represents a UPC shared array as regular array ...
ROSE_DLL_API void collectReadOnlySymbols(SgStatement *stmt, std::set< SgVariableSymbol * > &readOnlySymbols, bool coarseGrain=true)
Collect read only variable symbols within a statement. The statement can be either of a function,...
bool isOverloaded(SgFunctionDeclaration *functionDeclaration)
Return true if function is overloaded.
ROSE_DLL_API int set_name(SgInitializedName *initializedNameNode, SgName new_name)
set_name of symbol in symbol table.
ROSE_DLL_API SgClassDefinition * findOrInsertJavaPackage(SgProject *, std::string, bool create_directory=false)
Process a qualified package name, if needed, and return its package definition.
ROSE_DLL_API SgClassDeclaration * findOrImportJavaClass(SgProject *, SgClassDefinition *package_definition, std::string)
If the class_name already exists in the scope, return it.
ROSE_DLL_API SgVariableSymbol * getFirstVarSym(SgVariableDeclaration *decl)
Get the variable symbol for the first initialized name of a declaration stmt.
ROSE_DLL_API bool templateArgumentEquivalence(SgTemplateArgument *arg1, SgTemplateArgument *arg2)
Verify that 2 SgTemplateArgument are equivalent (same type, same expression, or same template declara...
ROSE_DLL_API SgFunctionDeclaration * findFirstDefiningFunctionDecl(SgScopeStatement *scope)
Find the first defining function declaration statement in a scope.
ROSE_DLL_API bool is_Jvm_language()
void addMessageStatement(SgStatement *stmt, std::string message)
Function to add "C" style comment to statement.
ROSE_DLL_API bool isLoopIndexVariable(SgInitializedName *ivar, SgNode *subtree_root)
Check if a SgInitializedName is used as a loop index within a AST subtree This function will use a bo...
SgInitializedName & getFirstVariable(SgVariableDeclaration &vardecl)
convenience function that returns the first initialized name in a list of variable declarations.
void initializeSwitchStatement(SgSwitchStatement *switchStatement, SgStatement *item_selector, SgStatement *body)
Support function used for variable declarations in conditionals.
SgExprListExp * loopCollapsing(SgForStatement *target_loop, size_t collapsing_factor)
Add a step statement to the end of a loop body Add a new label to the end of the loop,...
ROSE_DLL_API void fixStatement(SgStatement *stmt, SgScopeStatement *scope)
A wrapper containing fixes (fixVariableDeclaration(),fixStructDeclaration(), fixLabelStatement(),...
ROSE_DLL_API SgStatement * copyStatement(SgStatement *s)
Deep copy a statement.
ROSE_DLL_API int eraseNullPreprocessingInfo(SgLocatedNode *lnode)
Dumps a located node's preprocessing information.
ROSE_DLL_API bool isCanonicalDoLoop(SgFortranDo *loop, SgInitializedName **ivar, SgExpression **lb, SgExpression **ub, SgExpression **step, SgStatement **body, bool *hasIncrementalIterationSpace, bool *isInclusiveUpperBound)
Check if a Fortran Do loop has a complete canonical form: Do I=1, 10, 1.
SgCommaOpExp * insertAfterUsingCommaOp(SgExpression *new_exp, SgExpression *anchor_exp, SgStatement **temp_decl=NULL, SgVarRefExp **temp_ref=NULL)
Insert an expression (new_exp ) after another expression (anchor_exp) has possible side effects,...
ROSE_DLL_API SgTemplateVariableSymbol * lookupTemplateVariableSymbolInParentScopes(const SgName &name, SgTemplateParameterPtrList *tplparams, SgTemplateArgumentPtrList *tplargs, SgScopeStatement *currentScope=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
ROSE_DLL_API void moveUpPreprocessingInfo(SgStatement *stmt_dst, SgStatement *stmt_src, PreprocessingInfo::RelativePositionType src_position=PreprocessingInfo::undef, PreprocessingInfo::RelativePositionType dst_position=PreprocessingInfo::undef, bool usePrepend=false)
Identical to movePreprocessingInfo(), except for the stale name and confusing order of parameters....
ROSE_DLL_API SgStatement * lastStatementOfScopeWithTokenInfo(SgScopeStatement *scope, std::map< SgNode *, TokenStreamSequenceToNodeMapping * > &tokenStreamSequenceMap)
Used to support token unparsing (when the output the trailing token sequence).
ROSE_DLL_API bool isPureVirtualClass(SgType *type, const ClassHierarchyWrapper &classHierarchy)
Check if a class type is a pure virtual class.
ROSE_DLL_API void cutPreprocessingInfo(SgLocatedNode *src_node, PreprocessingInfo::RelativePositionType pos, AttachedPreprocessingInfoType &save_buf)
Cut preprocessing information from a source node and save it into a buffer. Used in combination of pa...
ROSE_DLL_API bool normalizeForLoopTest(SgForStatement *loop)
Normalize a for loop's test expression i<x is normalized to i<= (x-1) and i>x is normalized to i>= (x...
bool declarationPreceedsDefinition(SgDeclarationStatement *nonDefiningDeclaration, SgDeclarationStatement *definingDeclaration)
Check if a defining declaration comes before of after the non-defining declaration.
ROSE_DLL_API bool isSameFunction(SgFunctionDeclaration *func1, SgFunctionDeclaration *func2)
Check if two function declarations refer to the same one. Two function declarations are the same when...
std::vector< SgVariableSymbol * > getSymbolsUsedInExpression(SgExpression *expr)
Find referenced symbols within an expression.
ROSE_DLL_API bool isUpcSharedType(SgType *t, SgModifierType **mod_type_out=NULL)
Check if a type is a UPC shared type, including shared array, shared pointers etc....
ROSE_DLL_API bool isStructDeclaration(SgNode *node)
Check if a SgNode is a declaration for a structure.
ROSE_DLL_API void moveVariableDeclaration(SgVariableDeclaration *decl, SgScopeStatement *target_scope)
Move a variable declaration to a new scope, handle symbol, special scopes like For loop,...
bool IsUnion(const SgType *const inputType)
Collect all read and write references within stmt, which can be a function, a scope statement,...
ROSE_DLL_API std::string preprocessPackage(SgProject *, std::string)
Using the package_name, create a file with a package statement, translate it in order to load the pac...
ROSE_DLL_API void setOneSourcePositionForTransformation(SgNode *root)
Set current node's source position as transformation generated.
NodeType * deepCopy(const NodeType *subtree)
A template function for deep copying a subtree. It is also used to create deepcopy functions with spe...
ROSE_DLL_API size_t getUpcSharedBlockSize(SgModifierType *mod_type)
Get the block size of a UPC shared modifier type.
bool HasTrivialCopy(const SgType *const inputType)
Collect all read and write references within stmt, which can be a function, a scope statement,...
void clearMangledNameCache(SgGlobal *globalScope)
Support for faster mangled name generation (caching avoids recomputation).
std::vector< SgStatement * > getSwitchCases(SgSwitchStatement *sw)
Query a subtree to get all nodes of a given type, with an appropriate downcast.
ROSE_DLL_API bool isScalarType(SgType *t)
Is this a scalar type?
ROSE_DLL_API void changeBreakStatementsToGotos(SgStatement *loopOrSwitch)
If the given statement contains any break statements in its body, add a new label below the statement...
ROSE_DLL_API SgFunctionDefinition * getEnclosingFunctionDefinition(SgNode *astNode, const bool includingSelf=false)
Find a node by type using upward traversal.
ROSE_DLL_API bool is_CAF_language()
ROSE_DLL_API void printOutComments(SgLocatedNode *locatedNode)
Connect variable reference to the right variable symbols when feasible, return the number of referenc...
ROSE_DLL_API void ReductionRecognition(SgForStatement *loop, std::set< std::pair< SgInitializedName *, OmpSupport::omp_construct_enum > > &results)
Recognize and collect reduction variables and operations within a C/C++ loop, following OpenMP 3....
std::string declarationPositionString(const SgDeclarationStatement *declaration)
Generate a unique string from the source file position information.
ROSE_DLL_API bool loopUnrolling(SgForStatement *loop, size_t unrolling_factor)
Unroll a target loop with a specified unrolling factor. It handles steps larger than 1 and adds a fri...
ROSE_DLL_API void setLoopCondition(SgScopeStatement *loop, SgStatement *cond)
Set the condition statement of a loop, including While-loop, For-loop, and Do-While-loop.
bool ROSE_DLL_API isStatic(SgDeclarationStatement *stmt)
Check if a declaration has a "static' modifier.
PreprocessingInfo * attachComment(SgSourceFile *source_file, const std::string &content, PreprocessingInfo::DirectiveType directive_type=PreprocessingInfo::C_StyleComment, PreprocessingInfo::RelativePositionType position=PreprocessingInfo::before)
Build and attach comment onto the global scope of a source file.
ROSE_DLL_API bool hasTrivialDestructor(SgType *t)
Does a type have a trivial (built-in) destructor?
ROSE_DLL_API SgClassDefinition * getEnclosingClassDefinition(SgNode *astnode, const bool includingSelf=false)
Get the closest class definition enclosing the specified AST node,.
ROSE_DLL_API bool mergeDeclarationAndAssignment(SgVariableDeclaration *decl, SgExprStatement *assign_stmt, bool removeAssignStmt=true)
Merge a variable assignment statement into a matching variable declaration statement....
ROSE_DLL_API void checkAccessPermissions(SgNode *)
Recursively print current and parent nodes. used within gdb to probe the context of a node.
ROSE_DLL_API std::vector< SgFunctionDeclaration * > generateFunctionDefinitionsList(SgNode *node)
Function to delete AST subtree's nodes only, users must take care of any dangling pointers,...
ROSE_DLL_API void replaceMacroCallsWithExpandedStrings(SgPragmaDeclaration *target)
Check if a pragma declaration node has macro calls attached, if yes, replace macro calls within the p...
std::string generateUniqueNameForUseAsIdentifier(SgDeclarationStatement *declaration)
Generate a useful name to support construction of identifiers from declarations.
ROSE_DLL_API bool isRestrictType(SgType *t)
Is this a restrict type?
ROSE_DLL_API std::string generateProjectName(const SgProject *project, bool supressSuffix=false)
Added mechanism to generate project name from list of file names.
ROSE_DLL_API void resetInternalMapsForTargetStatement(SgStatement *sourceStatement)
Reset internal data structures used for token-based unparsing and macro summaries based on modificati...
ROSE_DLL_API bool is_Cuda_language()
ROSE_DLL_API bool isLambdaCapturedVariable(SgVarRefExp *varRef)
check if a variable reference is this->a[i] inside of a lambda function
bool isTemplateInstantiationFromTemplateDeclarationSatisfyingFilter(SgFunctionDeclaration *function, T *filter)
This function detects template instantiations that are relevant when filters are used.
ROSE_DLL_API int instrumentEndOfFunction(SgFunctionDeclaration *func, SgStatement *s)
Instrument(Add a statement, often a function call) into a function right before the return points,...
NodeType * getEnclosingNode(const SgNode *astNode, const bool includingSelf=false)
Find a node by type using upward traversal.
ROSE_DLL_API SgInitializedName * getFirstInitializedName(SgVariableDeclaration *decl)
Get the first initialized name of a declaration statement.
void setSourcePositionPointersToNull(SgNode *node)
Set the source code positon for the current (input) node.
ROSE_DLL_API SgBasicBlock * ensureBasicBlockAsBodyOfDoWhile(SgDoWhileStmt *ws)
Check if the body of a 'do .. while' statement is a SgBasicBlock, create one if not.
ROSE_DLL_API void reportModifiedStatements(const std::string &label, SgNode *node)
Connect variable reference to the right variable symbols when feasible, return the number of referenc...
ROSE_DLL_API std::vector< SgInitializedName * > getOutParameters(const SgInitializedNamePtrList &params)
Get a vector of Jovial output parameters from the function parameter list (may work for Fortran in th...
ROSE_DLL_API void setSourcePositionForTransformation(SgNode *root)
Recursively set source position info(Sg_File_Info) as transformation generated.
ROSE_DLL_API SgGlobal * getGlobalScope(const SgNode *astNode)
Traverse back through a node's parents to find the enclosing global scope.
ROSE_DLL_API void insertStatementListAfter(SgStatement *targetStmt, const std::vector< SgStatement * > &newStmt)
Insert a list of statements after a target statement.
ROSE_DLL_API bool isMain(const SgNode *node)
Check if a SgNode is a main() function declaration.
std::map< std::string, int > local_name_collision_map
Global map of name collisions to support generateUniqueNameForUseAsIdentifier() function.
ROSE_DLL_API void fixClassDeclaration(SgClassDeclaration *classDecl, SgScopeStatement *scope)
Fix symbols, parent and scope pointers. Used internally within appendStatment(), insertStatement() et...
ROSE_DLL_API int collectVariableReferencesInArrayTypes(SgLocatedNode *root, Rose_STL_Container< SgNode * > &currentVarRefList)
Collect variable references in array types. The default NodeQuery::querySubTree() will miss variables...
SgBasicBlock * ensureBasicBlockAsBodyOfCaseOption(SgCaseOptionStmt *cs)
Check if the body of a 'case option' statement is a SgBasicBlock, create one if not.
void checkForInitializers(SgNode *node)
Collect all read and write references within stmt, which can be a function, a scope statement,...
ROSE_DLL_API void removeUnusedLabels(SgNode *top, bool keepChild=false)
Remove labels which are not targets of any goto statements: its child statement is also removed by de...
ROSE_DLL_API SgProject * getProject()
Get the current SgProject IR Node.
ROSE_DLL_API SgBasicBlock * ensureBasicBlockAsBodyOfUpcForAll(SgUpcForAllStatement *fs)
Check if the body of a 'upc_forall' statement is a SgBasicBlock, create one if not.
ROSE_DLL_API SgClassDeclaration * getEnclosingClassDeclaration(SgNode *astNode)
Get the closest class declaration enclosing the specified AST node,.
ROSE_DLL_API void insertStatement(SgStatement *targetStmt, SgStatement *newStmt, bool insertBefore=true, bool autoMovePreprocessingInfo=true)
Insert a statement before or after the target statement within the target's scope....
ROSE_DLL_API void listHeaderFiles(SgIncludeFile *includeFile)
return path prefix for subtree of include files.
ROSE_DLL_API void markSubtreeToBeUnparsedTreeTraversal(SgNode *root, int physical_file_id)
Recursively print current and parent nodes. used within gdb to probe the context of a node.
void saveToPDF(SgNode *node, std::string filename)
Save AST into a pdf file. Start from a node to find its enclosing file node. The entire file's AST wi...
ROSE_DLL_API bool normalizeForLoopInitDeclaration(SgForStatement *loop)
Normalize loop init stmt by promoting the single variable declaration statement outside of the for lo...
void detectCycleInType(SgType *type, const std::string &from)
Collect all read and write references within stmt, which can be a function, a scope statement,...
ROSE_DLL_API void deleteAST(SgNode *node)
Function to delete AST subtree's nodes only, users must take care of any dangling pointers,...
ROSE_DLL_API bool statementCanBeTransformed(SgStatement *stmt)
If header file unparsing and token-based unparsing are used, then some statements in header files use...
ROSE_DLL_API SgStatement * getNextStatement(SgStatement *currentStmt)
Get next statement within the same scope of current statement.
ROSE_DLL_API std::string mangleScalarType(SgType *type)
Generate mangled scalar type names according to Itanium C++ ABI, the input type should pass isScalarT...
ROSE_DLL_API std::set< SgLabelStatement * > findUnusedLabels(SgNode *top)
Find unused labels which are not targets of any goto statements.
bool HasTrivialConstructor(const SgType *const inputType)
Collect all read and write references within stmt, which can be a function, a scope statement,...
ROSE_DLL_API void setExtern(SgDeclarationStatement *stmt)
Set a declaration as extern.
ROSE_DLL_API void deleteAllNodes()
Function to delete AST subtree's nodes only, users must take care of any dangling pointers,...
ROSE_DLL_API bool templateArgumentListEquivalence(const SgTemplateArgumentPtrList &list1, const SgTemplateArgumentPtrList &list2)
Verify that 2 SgTemplateArgumentPtrList are equivalent.
ROSE_DLL_API LivenessAnalysis * call_liveness_analysis(SgProject *project, bool debug=false)
Call liveness analysis on an entire project.
ROSE_DLL_API void reportModifiedLocatedNodes(const std::string &label, SgNode *node)
Connect variable reference to the right variable symbols when feasible, return the number of referenc...
ROSE_DLL_API void fixTemplateDeclaration(SgTemplateDeclaration *stmt, SgScopeStatement *scope)
Fix the symbol table and set scope (only if scope in declaration is not already set).
SgType * getBoolType(SgNode *n)
Get the right bool type according to C or C++ language input.
void clearSharedGlobalScopes(SgProject *project)
Collect all read and write references within stmt, which can be a function, a scope statement,...
void initializeWhileStatement(SgWhileStmt *whileStatement, SgStatement *condition, SgStatement *body, SgStatement *else_body)
Support function used for variable declarations in conditionals.
ROSE_DLL_API void setSourcePosition(SgNode *node)
Set the source code positon for the current (input) node.
ROSE_DLL_API void setPragma(SgPragmaDeclaration *decl, SgPragma *pragma)
Set a pragma of a pragma declaration. handle memory release for preexisting pragma,...
ROSE_DLL_API void insertStatementListBeforeFirstNonDeclaration(const std::vector< SgStatement * > &newStmts, SgScopeStatement *scope)
Insert statements before the first non-declaration statement in a scope. If the scope has no non-decl...
ROSE_DLL_API bool isPostfixOperator(SgExpression *exp)
Is an overloaded operator a postfix operator. (e.g. ).
ROSE_DLL_API SgStatement * findSurroundingStatementFromSameFile(SgStatement *targetStmt, bool &surroundingStatementPreceedsTargetStatement)
Supporting function to comment relocation in insertStatement() and removeStatement().
SgNamespaceDefinitionStatement * enclosingNamespaceScope(SgDeclarationStatement *declaration)
Find the enclosing namespace of a declaration.
ROSE_DLL_API SgStatement * getLoopBody(SgScopeStatement *loop)
Routines to get and set the body of a loop.
ROSE_DLL_API bool is_mixed_C_and_Cxx_language()
bool isStructurallyEquivalentAST(SgNode *tree1, SgNode *tree2)
Collect all read and write references within stmt, which can be a function, a scope statement,...
ROSE_DLL_API PreprocessingInfo * insertHeader(SgSourceFile *source_file, const std::string &header_file_name, bool isSystemHeader, bool asLastHeader)
Insert #include "filename" or #include <filename> (system header) onto the global scope of a source f...
void printAST2TextFile(SgNode *node, const char *filename, bool printType=true)
Pretty print AST horizontally, output to a specified text file. If printType is set to false,...
ROSE_DLL_API SgFunctionSymbol * lookupTemplateFunctionSymbolInParentScopes(const SgName &functionName, SgFunctionType *ftype, SgTemplateParameterPtrList *tplparams, SgScopeStatement *currentScope=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
bool HasNoThrowCopy(const SgType *const inputType)
Collect all read and write references within stmt, which can be a function, a scope statement,...
ROSE_DLL_API bool is_language_case_insensitive()
ROSE_DLL_API void replaceStatement(SgStatement *oldStmt, SgStatement *newStmt, bool movePreprocessinInfo=false)
Replace a statement with another. Move preprocessing information from oldStmt to newStmt if requested...
ROSE_DLL_API void recordNormalizations(SgStatement *s)
Record where normalization have been done so that we can preform denormalizations as required for the...
ROSE_DLL_API bool loopInterchange(SgForStatement *loop, size_t depth, size_t lexicoOrder)
Interchange/permutate a n-level perfectly-nested loop rooted at 'loop' using a lexicographical order ...
void printAST(SgNode *node)
Pretty print AST horizontally, output to std output.
ROSE_DLL_API SgFunctionSymbol * lookupTemplateMemberFunctionSymbolInParentScopes(const SgName &functionName, SgFunctionType *ftype, SgTemplateParameterPtrList *tplparams, SgScopeStatement *currentScope=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
ROSE_DLL_API bool is_PHP_language()
ROSE_DLL_API bool isEqualToIntConst(SgExpression *e, int value)
Check if a SgIntVal node has a given value.
ROSE_DLL_API void insertStatementBeforeFirstNonDeclaration(SgStatement *newStmt, SgScopeStatement *scope, bool movePreprocessingInfo=true)
Insert a statement before the first non-declaration statement in a scope. If the scope has no non-dec...
ROSE_DLL_API SgFunctionSymbol * lookupFunctionSymbolInParentScopes(const SgName &functionName, SgScopeStatement *currentScope=NULL)
look up the first matched function symbol in parent scopes given only a function name,...
ROSE_DLL_API void appendStatementWithDependentDeclaration(SgDeclarationStatement *decl, SgGlobal *scope, SgStatement *original_statement, bool excludeHeaderFiles)
Append a copy ('decl') of a function ('original_statement') into a 'scope', include any referenced de...
ROSE_DLL_API bool insideHeader(SgLocatedNode *node)
Check if a node is from a header file.
ROSE_DLL_API void markSubtreeToBeUnparsed(SgNode *root, int physical_file_id)
Recursively print current and parent nodes. used within gdb to probe the context of a node.
ROSE_DLL_API bool isDataMemberReference(SgVarRefExp *varRefExp)
Find a node by type using upward traversal.
ROSE_DLL_API bool collectReadWriteVariables(SgStatement *stmt, std::set< SgInitializedName * > &readVars, std::set< SgInitializedName * > &writeVars, bool coarseGrain=true)
Collect unique variables which are read or written within a statement. Note that a variable can be bo...
ROSE_DLL_API void constantFolding(SgNode *r)
Constant folding an AST subtree rooted at 'r' (replacing its children with their constant values,...
std::vector< SgBreakStmt * > findBreakStmts(SgStatement *code, const std::string &fortranLabel="")
Find break statements inside a particular statement, stopping at nested loops or switches.
ROSE_DLL_API SgFile * getEnclosingFileNode(SgNode *astNode)
get the SgFile node from current node
ROSE_DLL_API void setStatic(SgDeclarationStatement *stmt)
Set a declaration as static.
ROSE_DLL_API bool doLoopNormalization(SgFortranDo *loop)
Normalize a Fortran Do loop. Make the default increment expression (1) explicit.
ROSE_DLL_API SgFile * preprocessCompilationUnit(SgProject *, std::string, std::string, bool unparse=true)
Using the file_content string, create a file with the content in question; build its AST and add it t...
ROSE_DLL_API void removeLabeledGotos(SgNode *top)
Remove labeled goto statements.
std::map< SgNode *, std::string > local_node_to_name_map
Global map of name collisions to support generateUniqueNameForUseAsIdentifier() function.
std::vector< SgGotoStatement * > findGotoStmts(SgStatement *scope, SgLabelStatement *l)
Query a subtree to get all nodes of a given type, with an appropriate downcast.
ROSE_DLL_API bool mergeDeclarationWithAssignment(SgVariableDeclaration *decl, SgExprStatement *assign_stmt)
Merge a declaration statement into a matching followed variable assignment. Callers should make sure ...
ROSE_DLL_API bool isAssignmentStatement(SgNode *_s, SgExpression **lhs=NULL, SgExpression **rhs=NULL, bool *readlhs=NULL)
Check if a SgNode _s is an assignment statement (any of =,+=,-=,&=,/=, ^=, etc)
ROSE_DLL_API bool normalizeCaseAndDefaultBlocks(SgSwitchStatement *switchStmt)
Normalize the structure of case and default blocks within a switch statement.
ROSE_DLL_API void outputSharedNodes(SgNode *node)
Find a node by type using upward traversal.
bool ROSE_DLL_API isAncestor(SgNode *node1, SgNode *node2)
check if node1 is a strict ancestor of node 2. (a node is not considered its own ancestor)
ROSE_DLL_API SgScopeStatement * getEnclosingScope(SgNode *n, const bool includingSelf=false)
Get the enclosing scope from a node n.
ROSE_DLL_API bool isAssignable(SgType *type)
Is a type assignable? This may not quite work properly.
ROSE_DLL_API SgNonrealSymbol * lookupNonrealSymbolInParentScopes(const SgName &name, SgScopeStatement *currentScope=NULL, SgTemplateParameterPtrList *templateParameterList=NULL, SgTemplateArgumentPtrList *templateArgumentList=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
ROSE_DLL_API SgSwitchStatement * findEnclosingSwitch(SgStatement *s)
Find the closest switch outside a given statement (normally used for case and default statements)
ROSE_DLL_API SgType * getElementType(SgType *t)
Get the element type of an array, pointer or string, or NULL if not applicable. This function only ch...
ROSE_DLL_API void removeAllOriginalExpressionTrees(SgNode *top)
Set original expression trees to NULL for SgValueExp or SgCastExp expressions, so you can change the ...
ROSE_DLL_API std::vector< SgNode * > astIntersection(SgNode *original, SgNode *copy, SgCopyHelp *help=NULL)
Compute the intersection set for two ASTs.
ROSE_DLL_API bool isPrefixOperator(SgExpression *exp)
Is an overloaded operator a prefix operator (e.g. address operator X * operator&(),...
ROSE_DLL_API void setLhsOperand(SgExpression *target, SgExpression *lhs)
set left hand operand for binary expressions, transparently downcasting target expressions when neces...
ROSE_DLL_API std::vector< SgC_PreprocessorDirectiveStatement * > translateStatementToUseCppDeclarations(SgStatement *statement, SgScopeStatement *scope)
Connect variable reference to the right variable symbols when feasible, return the number of referenc...
ROSE_DLL_API int suggestNextNumericLabel(SgFunctionDefinition *func_def)
Suggest next usable (non-conflicting) numeric label value for a Fortran function definition scope.
ROSE_DLL_API std::set< SgStatement * > collectModifiedStatements(SgNode *node)
This collects the statements that are marked as modified (a flag automatically set by all set_* gener...
ROSE_DLL_API SgFunctionDeclaration * getEnclosingFunctionDeclaration(SgNode *astNode, const bool includingSelf=false)
Find the enclosing function declaration, including its derived instances like isSgProcedureHeaderStat...
SgFunctionDeclaration * findFunctionDeclaration(SgNode *root, std::string name, SgScopeStatement *scope, bool isDefining)
Topdown traverse a subtree from root to find the first function declaration matching the given name,...
ROSE_DLL_API bool isPrefixOperatorName(const SgName &functionName)
Check for proper names of possible prefix operators (used in isPrefixOperator()).
ROSE_DLL_API void setLoopStride(SgNode *loop, SgExpression *stride)
Set the stride(step) of a loop 's incremental expression, regardless the expression types (i+=s; i= i...
T * findDeclarationStatement(SgNode *root, std::string name, SgScopeStatement *scope, bool isDefining)
Topdown traverse a subtree from root to find the first declaration given its name,...
ROSE_DLL_API bool isInSubTree(SgExpression *subtree, SgExpression *exp)
Find a node by type using upward traversal.
ROSE_DLL_API bool forLoopNormalization(SgForStatement *loop, bool foldConstant=true)
Normalize a for loop, return true if successful.
unsigned long long getIntegerConstantValue(SgValueExp *expr)
Get the constant value from a constant integer expression; abort on everything else.
ROSE_DLL_API bool is_UPC_language()
ROSE_DLL_API void checkSymbolTables(SgNode *)
Recursively print current and parent nodes. used within gdb to probe the context of a node.
ROSE_DLL_API void updateDefiningNondefiningLinks(SgFunctionDeclaration *func, SgScopeStatement *scope)
Update defining and nondefining links due to a newly introduced function declaration....
ROSE_DLL_API SgNode * deepCopyNode(const SgNode *subtree)
Deep copy an arbitrary subtree.
SgBasicBlock * ensureBasicBlockAsBodyOfDefaultOption(SgDefaultOptionStmt *cs)
Check if the body of a 'default option' statement is a SgBasicBlock, create one if not.
ROSE_DLL_API void getLiveVariables(LivenessAnalysis *liv, SgForStatement *loop, std::set< SgInitializedName * > &liveIns, std::set< SgInitializedName * > &liveOuts)
get liveIn and liveOut variables for a for loop from liveness analysis result liv.
ROSE_DLL_API void resetModifiedLocatedNodes(const std::set< SgLocatedNode * > &modifiedNodeSet)
Use the set of IR nodes and set the isModified flag in each IR node to true.
ROSE_DLL_API SgNode * replaceWithPattern(SgNode *anchor, SgNode *new_pattern)
Replace an anchor node with a specified pattern subtree with optional SgVariantExpression....
ROSE_DLL_API bool ROSE_DLL_API isJovialOutParam(SgInitializedName *name)
True if a parameter name is a Jovial output parameter.
ROSE_DLL_API void moveForStatementIncrementIntoBody(SgForStatement *f)
Add a step statement to the end of a loop body Add a new label to the end of the loop,...
ROSE_DLL_API bool hasUpcSharedType(SgType *t, SgModifierType **mod_type_out=NULL)
Has a UPC shared type of any kinds (shared-to-shared, private-to-shared, shared-to-private,...
ROSE_DLL_API SgBasicBlock * ensureBasicBlockAsBodyOfOmpBodyStmt(SgOmpBodyStatement *ompbodyStmt)
Check if the body of a SgOmpBodyStatement is a SgBasicBlock, create one if not.
ROSE_DLL_API bool is_Python_language()
ROSE_DLL_API bool is_mixed_Fortran_and_Cxx_language()
ROSE_DLL_API SgStatement * getLoopCondition(SgScopeStatement *loop)
Routines to get the condition of a loop. It recognize While-loop, For-loop, and Do-While-loop.
ROSE_DLL_API SgEnumSymbol * lookupEnumSymbolInParentScopes(const SgName &name, SgScopeStatement *currentScope=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
bool IsAbstract(const SgType *const inputType)
Collect all read and write references within stmt, which can be a function, a scope statement,...
std::pair< SgVariableDeclaration *, SgExpression * > createTempVariableAndReferenceForExpression(SgExpression *expression, SgScopeStatement *scope)
Function to delete AST subtree's nodes only, users must take care of any dangling pointers,...
ROSE_DLL_API SgTypedefSymbol * lookupTypedefSymbolInParentScopes(const SgName &name, SgScopeStatement *currentScope=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
ROSE_DLL_API SgBasicBlock * ensureBasicBlockAsBodyOfWhile(SgWhileStmt *ws)
Check if the body of a 'while' statement is a SgBasicBlock, create one if not.
ROSE_DLL_API SgBasicBlock * ensureBasicBlockAsBodyOfFor(SgForStatement *fs)
Check if the body of a 'for' statement is a SgBasicBlock, create one if not.
ROSE_DLL_API PreprocessingInfo * attachArbitraryText(SgLocatedNode *target, const std::string &text, PreprocessingInfo::RelativePositionType position=PreprocessingInfo::before)
Attach an arbitrary string to a located node. A workaround to insert irregular statements or vendor-s...
ROSE_DLL_API void markNodeToBeUnparsed(SgNode *node, int physical_file_id)
Recursively print current and parent nodes. used within gdb to probe the context of a node.
ROSE_DLL_API bool isConstantTrue(SgExpression *e)
Check if a bool or int constant expression evaluates to be a true value.
std::map< std::string, SgNode * > local_name_to_node_map
Global map of name collisions to support generateUniqueNameForUseAsIdentifier() function.
ROSE_DLL_API bool is_binary_executable()
void changeAllBodiesToBlocks(SgNode *top, bool createEmptyBody=true)
Fix up ifs, loops, while, switch, Catch, OmpBodyStatement, etc. to have blocks as body components....
void dumpPreprocInfo(SgLocatedNode *locatedNode)
Dumps a located node's preprocessing information.
void fixupReferencesToSymbols(const SgScopeStatement *this_scope, SgScopeStatement *copy_scope, SgCopyHelp &help)
All the symbol table references in the copied AST need to be reset after rebuilding the copied scope'...
std::vector< NodeType * > querySubTree(SgNode *top, VariantT variant=(VariantT) NodeType::static_variant)
Query a subtree to get all nodes of a given type, with an appropriate downcast.
ROSE_DLL_API void moveDeclarationToAssociatedNamespace(SgDeclarationStatement *declarationStatement)
Relocate the declaration to be explicitly represented in its associated namespace (required for some ...
ROSE_DLL_API bool isCanonicalForLoop(SgNode *loop, SgInitializedName **ivar=NULL, SgExpression **lb=NULL, SgExpression **ub=NULL, SgExpression **step=NULL, SgStatement **body=NULL, bool *hasIncrementalIterationSpace=NULL, bool *isInclusiveUpperBound=NULL)
Check if a for-loop has a canonical form, return loop index, bounds, step, and body if requested.
ROSE_DLL_API bool isArrayReference(SgExpression *ref, SgExpression **arrayNameExp=NULL, std::vector< SgExpression * > **subscripts=NULL)
Check if an expression is an array access (SgPntrArrRefExp). If so, return its name expression and su...
ROSE_DLL_API void insertStatementAfterLastDeclaration(SgStatement *stmt, SgScopeStatement *scope)
Insert a statement after the last declaration within a scope. The statement will be prepended to the ...
bool HasNoThrowConstructor(const SgType *const inputType)
Collect all read and write references within stmt, which can be a function, a scope statement,...
ROSE_DLL_API void destroyTempDirectory(std::string)
Use the system command to remove a temporary directory and all its containing files.
void serialize_list(T &plist, std::string T_name, std::string &prefix, bool hasRemaining, std::ostringstream &out, std::string &edgeLabel)
Query a subtree to get all nodes of a given type, with an appropriate downcast.
void resetMangledNameCache(SgGlobal *globalScope)
Recursively print current and parent nodes. used within gdb to probe the context of a node.
ROSE_DLL_API SgType * getAssociatedTypeFromFunctionTypeList(SgExpression *actual_argument_expression)
Get the type of the associated argument expression from the function type.
ROSE_DLL_API SgTemplateInstantiationMemberFunctionDecl * buildForwardFunctionDeclaration(SgTemplateInstantiationMemberFunctionDecl *memberFunctionInstantiation)
Generate a non-defining (forward) declaration from a defining function declaration.
ROSE_DLL_API bool is_Fortran_language()
ROSE_DLL_API bool isDefaultConstructible(SgType *type)
Is a type default constructible? This may not quite work properly.
ROSE_DLL_API SgVariableSymbol * lookupVariableSymbolInParentScopes(const SgName &name, SgScopeStatement *currentScope=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
bool IsEnum(const SgType *const inputType)
Collect all read and write references within stmt, which can be a function, a scope statement,...
ROSE_DLL_API void outputFileIds(SgNode *node)
Connect variable reference to the right variable symbols when feasible, return the number of referenc...
ROSE_DLL_API SgExprStatement * splitVariableDeclaration(SgVariableDeclaration *decl)
Split a variable declaration with an rhs assignment into two statements: a declaration and an assignm...
ROSE_DLL_API SgStatement * getFirstStatement(SgScopeStatement *scope, bool includingCompilerGenerated=false)
Get the first statement within a scope, return NULL if it does not exist. Skip compiler-generated sta...
ROSE_DLL_API SgNamespaceSymbol * lookupNamespaceSymbolInParentScopes(const SgName &name, SgScopeStatement *currentScope=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
ROSE_DLL_API bool isExtern(SgDeclarationStatement *stmt)
Check if a declaration has an "extern" modifier.
std::string extractPragmaKeyword(const SgPragmaDeclaration *)
Extract a SgPragmaDeclaration's leading keyword . For example "#pragma omp parallel" has a keyword of...
ROSE_DLL_API SgTemplateClassSymbol * lookupTemplateClassSymbolInParentScopes(const SgName &name, SgTemplateParameterPtrList *templateParameterList, SgTemplateArgumentPtrList *templateArgumentList, SgScopeStatement *cscope=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
ROSE_DLL_API bool isEquivalentFunctionType(const SgFunctionType *lhs, const SgFunctionType *rhs)
Test if two types are equivalent SgFunctionType nodes.
ROSE_DLL_API void setLoopLowerBound(SgNode *loop, SgExpression *lb)
Set the lower bound of a loop header for (i=lb; ...)
bool IsStandardLayout(const SgType *const inputType)
Collect all read and write references within stmt, which can be a function, a scope statement,...
bool HasVirtualDestructor(const SgType *const inputType)
Collect all read and write references within stmt, which can be a function, a scope statement,...
bool HasTrivialAssign(const SgType *const inputType)
Collect all read and write references within stmt, which can be a function, a scope statement,...
ROSE_DLL_API bool isUpcPhaseLessSharedType(SgType *t)
Is UPC phase-less shared type? Phase-less means block size of the first SgModifierType with UPC infor...
void guardNode(SgLocatedNode *target, std::string guard)
Add preproccessor guard around a given node.
bool checkTypesAreEqual(SgType *typeA, SgType *typeB)
Collect all read and write references within stmt, which can be a function, a scope statement,...
ROSE_DLL_API bool isReferenceType(SgType *t)
Is this type a const or non-const reference type? (Handles typedefs correctly)
ROSE_DLL_API void moveCommentsToNewStatement(SgStatement *sourceStatement, const std::vector< int > &indexList, SgStatement *destinationStatement, bool destinationStatementPreceedsSourceStatement)
Relocate comments and CPP directives from one statement to another.
ROSE_DLL_API SgStatement * getEnclosingStatement(SgNode *n)
Find the closest enclosing statement, including the given node.
ROSE_DLL_API void translateToUseCppDeclarations(SgNode *n)
Connect variable reference to the right variable symbols when feasible, return the number of referenc...
ROSE_DLL_API void changeContinuesToGotos(SgStatement *stmt, SgLabelStatement *label)
Change continue statements in a given block of code to gotos to a label.
void outputGlobalFunctionTypeSymbolTable()
Output function type symbols in global function type symbol table.
ROSE_DLL_API SgScopeStatement * findEnclosingLoop(SgStatement *s, const std::string &fortranLabel="", bool stopOnSwitches=false)
Find the closest loop outside the given statement; if fortranLabel is not empty, the Fortran label of...
std::pair< SgVariableDeclaration *, SgExpression * > createTempVariableForExpression(SgExpression *expression, SgScopeStatement *scope, bool initializeInDeclaration, SgAssignOp **reEvaluate=NULL)
Given an expression, generates a temporary variable whose initializer optionally evaluates that expre...
bool isBodyStatement(SgStatement *s)
Check if a statement is a (true or false) body of a container-like parent, such as For,...
bool functionCallExpressionPreceedsDeclarationWhichAssociatesScope(SgFunctionCallExp *functionCall)
Recursively print current and parent nodes. used within gdb to probe the context of a node.
ROSE_DLL_API void convertAllForsToWhiles(SgNode *top)
Add a step statement to the end of a loop body Add a new label to the end of the loop,...
SgType * UnderlyingType(SgType *type)
Collect all read and write references within stmt, which can be a function, a scope statement,...
ROSE_DLL_API bool isConstantFalse(SgExpression *e)
Check if a bool or int constant expression evaluates to be a false value.
ROSE_DLL_API void outputLocalSymbolTables(SgNode *node)
Output the local symbol tables.
ROSE_DLL_API void preOrderCollectPreprocessingInfo(SgNode *current, std::vector< PreprocessingInfo * > &infoList, int depth)
Dumps a located node's preprocessing information.
ROSE_DLL_API SgMemberFunctionDeclaration * getDefaultDestructor(SgClassDeclaration *classDeclaration)
Get the default destructor from the class declaration.
void collectVarRefs(SgLocatedNode *root, std::vector< SgVarRefExp * > &result)
Collect all variable references in a subtree.
ROSE_DLL_API void setOperand(SgExpression *target, SgExpression *operand)
Set operands for expressions with single operand, such as unary expressions. handle file info,...
ROSE_DLL_API SgMemberFunctionDeclaration * getDefaultConstructor(SgClassDeclaration *classDeclaration)
Get the default constructor from the class declaration.
ROSE_DLL_API SgInitializedName * getLoopIndexVariable(SgNode *loop)
Return the loop index variable for a for loop.
ROSE_DLL_API size_t getArrayElementCount(SgArrayType *t)
Calculate the number of elements of an array type: dim1* dim2*... , assume element count is 1 for int...
ROSE_DLL_API SgAssignInitializer * splitExpression(SgExpression *from, std::string newName="")
Replace an expression with a temporary variable and an assignment statement.
ROSE_DLL_API void replaceVariableReferences(SgVariableSymbol *old_sym, SgVariableSymbol *new_sym, SgScopeStatement *scope)
Replace all variable references to an old symbol in a scope to being references to a new symbol.
ROSE_DLL_API bool isNonconstReference(SgType *t)
Is this type a non-constant reference type? (Handles typedefs correctly)
ROSE_DLL_API bool is_OpenCL_language()
bool IsBaseOf(const SgType *const inputBaseType, const SgType *const inputDerivedType)
Collect all read and write references within stmt, which can be a function, a scope statement,...
ROSE_DLL_API bool normalizeForLoopIncrement(SgForStatement *loop)
Add a step statement to the end of a loop body Add a new label to the end of the loop,...
ROSE_DLL_API SgVariableSymbol * appendArg(SgFunctionParameterList *, SgInitializedName *)
Append an argument to SgFunctionParameterList, transparently set parent,scope, and symbols for argume...
ROSE_DLL_API bool unnormalizeForLoopInitDeclaration(SgForStatement *loop)
Undo the normalization of for loop's C99 init declaration. Previous record of normalization is used t...
ROSE_DLL_API SgStatement * getPreviousStatement(SgStatement *currentStmt, bool climbOutScope=true)
Get previous statement of the current statement. It may return a previous statement of a parent scope...
bool IsPolymorphic(const SgType *const inputType)
Collect all read and write references within stmt, which can be a function, a scope statement,...
ROSE_DLL_API void removeJumpsToNextStatement(SgNode *)
Remove jumps whose label is immediately after the jump. Used to clean up inlined code fragments.
bool isPrototypeInScope(SgScopeStatement *scope, SgFunctionDeclaration *functionDeclaration, SgDeclarationStatement *startingAtDeclaration)
Assigns unique numbers to each SgScopeStatement of a function.
ROSE_DLL_API int moveUpInnerDanglingIfEndifDirective(SgLocatedNode *lnode)
Extract sequences like " #endif #endif ... #if | #ifdef| #ifndef" buried inside subtree of lnode.
SgDeclarationStatement * getNonInstantiatonDeclarationForClass(SgTemplateInstantiationMemberFunctionDecl *memberFunctionInstantiation)
Recursively print current and parent nodes. used within gdb to probe the context of a node.
ROSE_DLL_API bool isConstType(SgType *t)
Is this a const type?
SgFunctionDeclaration * getDeclarationOfNamedFunction(SgExpression *func)
Given a SgExpression that represents a named function (or bound member function), return the mentione...
ROSE_DLL_API bool is_C99_language()
ROSE_DLL_API bool addDefaultConstructorIfRequired(SgClassType *classType, int physical_file_id=Sg_File_Info::TRANSFORMATION_FILE_ID)
Get the default destructor from the class declaration.
ROSE_DLL_API bool isUpcArrayWithThreads(SgArrayType *t)
Is a UPC array with dimension of X*THREADS.
ROSE_DLL_API void movePreprocessingInfo(SgStatement *stmt_src, SgStatement *stmt_dst, PreprocessingInfo::RelativePositionType src_position=PreprocessingInfo::undef, PreprocessingInfo::RelativePositionType dst_position=PreprocessingInfo::undef, bool usePrepend=false)
Move preprocessing information of stmt_src to stmt_dst, Only move preprocessing information from the ...
ROSE_DLL_API int fixVariableReferences(SgNode *root, bool cleanUnusedSymbol=true)
Connect variable reference to the right variable symbols when feasible, return the number of referenc...
ROSE_DLL_API bool isUseByAddressVariableRef(SgVarRefExp *ref)
Check if a variable reference is used by its address: including &a expression and foo(a) when type2 f...
struct const_int_expr_t evaluateConstIntegerExpression(SgExpression *expr)
The function tries to evaluate const integer expressions (such as are used in array dimension sizes)....
ROSE_DLL_API int getDimensionCount(SgType *t)
Get the number of dimensions of an array type.
ROSE_DLL_API SgBasicBlock * ensureBasicBlockAsTrueBodyOfIf(SgIfStmt *ifs)
Check if the true body of a 'if' statement is a SgBasicBlock, create one if not.
ROSE_DLL_API void replaceExpression(SgExpression *oldExp, SgExpression *newExp, bool keepOldExp=false)
Replace an expression with another, used for variable reference substitution and others....
ROSE_DLL_API SgBasicBlock * ensureBasicBlockAsFalseBodyOfIf(SgIfStmt *ifs, bool createEmptyBody=true)
Check if the false body of a 'if' statement is a SgBasicBlock, create one if not when the flag is tru...
ROSE_DLL_API SgExprListExp * getEnclosingExprListExp(SgNode *astNode, const bool includingSelf=false)
Get the enclosing SgExprListExp (used as part of function argument index evaluation in subexpressions...
ROSE_DLL_API void appendStatement(SgStatement *stmt, SgScopeStatement *scope=NULL)
Append a statement to the end of the current scope, handle side effect of appending statements,...
ROSE_DLL_API SgFunctionDeclaration * buildFunctionPrototype(SgFunctionDeclaration *functionDeclaration)
Function to delete AST subtree's nodes only, users must take care of any dangling pointers,...
void addVarRefExpFromArrayDimInfo(SgNode *astNode, Rose_STL_Container< SgNode * > &NodeList_t)
Find all SgPntrArrRefExp under astNode, then add SgVarRefExp (if any) of SgPntrArrRefExp's dim_info i...
ROSE_DLL_API bool loopTiling(SgForStatement *loopNest, size_t targetLevel, size_t tileSize)
Tile the n-level (starting from 1) loop of a perfectly nested loop nest using tiling size s.
std::string generateUniqueName(const SgNode *node, bool ignoreDifferenceBetweenDefiningAndNondefiningDeclarations)
Generate unique name from C and C++ constructs. The name may contain space.
ROSE_DLL_API SgGlobal * getFirstGlobalScope(SgProject *project)
return the first global scope under current project
ROSE_DLL_API void setOneSourcePositionNull(SgNode *node)
Set current node's source position as NULL.
ROSE_DLL_API void setRhsOperand(SgExpression *target, SgExpression *rhs)
set left hand operand for binary expression
std::pair< SgStatement *, SgInitializedName * > wrapFunction(SgFunctionDeclaration &definingDeclaration, SgName newName)
moves the body of a function f to a new function f; f's body is replaced with code that forwards the ...
ROSE_DLL_API bool is_mixed_Fortran_and_C_and_Cxx_language()
ROSE_DLL_API bool isUpcStrictSharedModifierType(SgModifierType *mode_type)
Check if a shared UPC type is strict memory consistency or not. Return false if it is relaxed....
ROSE_DLL_API bool isVolatileType(SgType *t)
Is this a volatile type?
void clearUnusedVariableSymbols(SgNode *root=NULL)
Clear those variable symbols with unknown type (together with initialized names) which are also not r...
ROSE_DLL_API void fixVariableDeclaration(SgVariableDeclaration *varDecl, SgScopeStatement *scope)
Patch up symbol, scope, and parent information when a SgVariableDeclaration's scope is known.
ROSE_DLL_API SgSymbol * lookupSymbolInParentScopesIgnoringAliasSymbols(const SgName &name, SgScopeStatement *currentScope=NULL, SgTemplateParameterPtrList *templateParameterList=NULL, SgTemplateArgumentPtrList *templateArgumentList=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
std::string generateUniqueVariableName(SgScopeStatement *scope, std::string baseName="temp")
Generate a name like temp# that is unique in the current scope and any parent and children scopes.
ROSE_DLL_API int gensym_counter
An internal counter for generating unique SgName.
ROSE_DLL_API void splitExpressionIntoBasicBlock(SgExpression *expr)
Split long expressions into blocks of statements.
void reset_name_collision_map()
Reset map variables used to support generateUniqueNameForUseAsIdentifier() function.
ROSE_DLL_API SgFunctionDefinition * getEnclosingProcedure(SgNode *n, const bool includingSelf=false)
Find the function definition.
std::vector< SgExpression * > get_C_array_dimensions(const SgArrayType &arrtype)
returns the array dimensions in an array as defined for arrtype
ROSE_DLL_API void replaceSubexpressionWithStatement(SgExpression *from, SageInterface::StatementGenerator *to)
Similar to replaceExpressionWithStatement, but with more restrictions.
ROSE_DLL_API SgType * getFirstVarType(SgVariableDeclaration *decl)
Get the data type of the first initialized name of a declaration statement.
ROSE_DLL_API void wrapAllTemplateInstantiationsInAssociatedNamespaces(SgProject *root)
Function to delete AST subtree's nodes only, users must take care of any dangling pointers,...
std::string get_name(const SgNode *node)
Generate a useful name to describe the SgNode.
ROSE_DLL_API void setLoopUpperBound(SgNode *loop, SgExpression *ub)
Set the upper bound of a loop header,regardless the condition expression type. for (i=lb; i op up,...
ROSE_DLL_API bool isMemberFunctionMemberReference(SgMemberFunctionRefExp *memberFunctionRefExp)
Find a node by type using upward traversal.
ROSE_DLL_API SgClassDefinition * findJavaPackage(SgScopeStatement *, std::string)
Look for a qualified package name in the given scope and return its package definition.
ROSE_DLL_API bool isOmpStatement(SgNode *)
Check if a node is SgOmp*Statement.
ROSE_DLL_API bool is_Ada_language()
std::string addMangledNameToCache(SgNode *astNode, const std::string &mangledName)
Recursively print current and parent nodes. used within gdb to probe the context of a node.
ROSE_DLL_API bool isPointerType(SgType *t)
Is this type a pointer type? (Handles typedefs correctly)
ROSE_DLL_API bool is_C_language()
ROSE_DLL_API std::list< SgClassType * > getClassTypeChainForMemberReference(SgExpression *refExp)
Find a node by type using upward traversal.
ROSE_DLL_API void collectUseByAddressVariableRefs(const SgStatement *s, std::set< SgVarRefExp * > &varSetB)
Collect variable references involving use by address: including &a expression and foo(a) when type2 f...
std::vector< SgContinueStmt * > findContinueStmts(SgStatement *code, const std::string &fortranLabel="")
Find all continue statements inside a particular statement, stopping at nested loops.
std::string getMangledNameFromCache(SgNode *astNode)
Recursively print current and parent nodes. used within gdb to probe the context of a node.
ROSE_DLL_API std::vector< SgDeclarationStatement * > sortSgNodeListBasedOnAppearanceOrderInSource(const std::vector< SgDeclarationStatement * > &nodevec)
Reorder a list of declaration statements based on their appearance order in source files.
ROSE_DLL_API std::set< SgLocatedNode * > collectModifiedLocatedNodes(SgNode *node)
This collects the SgLocatedNodes that are marked as modified (a flag automatically set by all set_* g...
SgExpression * forallMaskExpression(SgForAllStatement *stmt)
Get the mask expression from the header of a SgForAllStatement.
void clearScopeNumbers(SgFunctionDefinition *functionDefinition)
Clears the cache of scope,integer pairs for the input function.
ROSE_DLL_API SgInitializedName * convertRefToInitializedName(SgNode *current, bool coarseGrain=true)
Variable references can be introduced by SgVarRef, SgPntrArrRefExp, SgInitializedName,...
bool IsClass(const SgType *const inputType)
strip off typedef and modifer types, then check if a type is a class type, excluding union type.
ROSE_DLL_API SgNode * getSgNodeFromAbstractHandleString(const std::string &input_string)
Obtain a matching SgNode from an abstract handle string.
ROSE_DLL_API void moveStatementsBetweenBlocks(SgBasicBlock *sourceBlock, SgBasicBlock *targetBlock)
Move statements in first block to the second block (preserves order and rebuilds the symbol table).
ROSE_DLL_API bool templateDefinitionIsInClass(SgTemplateInstantiationMemberFunctionDecl *memberFunctionDeclaration)
Return true if template definition is in the class, false if outside of class.
ROSE_DLL_API void fixLabelStatement(SgLabelStatement *label_stmt, SgScopeStatement *scope)
Fix symbol table for SgLabelStatement. Used Internally when the label is built without knowing its ta...
ROSE_DLL_API void replaceExpressionWithStatement(SgExpression *from, SageInterface::StatementGenerator *to)
Replace a given expression with a list of statements produced by a generator.
ROSE_DLL_API void convertForToWhile(SgForStatement *f)
Add a step statement to the end of a loop body Add a new label to the end of the loop,...
SgType * removeConst(SgType *t)
Remove const (if present) from a type. stripType() cannot do this because it removes all modifiers.
ROSE_DLL_API void insertStatementBefore(SgStatement *targetStmt, SgStatement *newStmt, bool autoMovePreprocessingInfo=true)
Insert a statement before a target statement.
ROSE_DLL_API bool findFirstSgCastExpMarkedAsTransformation(SgNode *n, const std::string &s)
Recursively print current and parent nodes. used within gdb to probe the context of a node.
ROSE_DLL_API void dumpInfo(SgNode *node, std::string desc="")
Dump information about a SgNode for debugging.
ROSE_DLL_API void convertFunctionDefinitionsToFunctionPrototypes(SgNode *node)
XXX This function operates on the new file used to support outlined function definitions....
ROSE_DLL_API void appendStatementList(const std::vector< SgStatement * > &stmt, SgScopeStatement *scope=NULL)
Append a list of statements to the end of the current scope, handle side effect of appending statemen...
SgNamedType * getDeclaredType(const SgDeclarationStatement *declaration)
Returns the type introduced by a declaration.
ROSE_DLL_API bool isIndexOperator(SgExpression *exp)
Is an overloaded operator an index operator (also referred to as call or subscript operators)....
ROSE_DLL_API std::string mangleType(SgType *type)
Generate a mangled string for a given type based on Itanium C++ ABI.
ROSE_DLL_API SgBasicBlock * ensureBasicBlockAsBodyOfCatch(SgCatchOptionStmt *cos)
Check if the body of a 'catch' statement is a SgBasicBlock, create one if not.
std::vector< SgFile * > generateFileList()
Returns STL vector of SgFile IR node pointers.
ROSE_DLL_API int normalizeArrowExpWithAddressOfLeftOperand(SgNode *root, bool transformationGeneratedOnly=true)
Convert all code within root matching the patern of (&left)->right, and translate them into left....
bool IsPod(const SgType *const inputType)
Collect all read and write references within stmt, which can be a function, a scope statement,...
bool hasTemplateSyntax(const SgName &name)
Collect all read and write references within stmt, which can be a function, a scope statement,...
ROSE_DLL_API void moveToSubdirectory(std::string directoryName, SgFile *file)
Move file to be generated in a subdirectory (will be generated by the unparser).
ROSE_DLL_API bool isAddressTaken(SgExpression *refExp)
Find a node by type using upward traversal.
ROSE_DLL_API bool hasSimpleChildrenList(SgScopeStatement *scope)
Check if a scope statement has a simple children statement list so insert additional statements under...
ROSE_DLL_API SgFunctionDeclaration * findMain(SgNode *currentNode)
top-down traversal from current node to find the main() function declaration
ROSE_DLL_API SgClassSymbol * lookupClassSymbolInParentScopes(const SgName &name, SgScopeStatement *currentScope=NULL, SgTemplateArgumentPtrList *templateArgumentList=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
ROSE_DLL_API void removeConsecutiveLabels(SgNode *top)
Remove consecutive labels.
ROSE_DLL_API void setLoopBody(SgScopeStatement *loop, SgStatement *body)
Add a step statement to the end of a loop body Add a new label to the end of the loop,...
bool getForLoopInformations(SgForStatement *for_loop, SgVariableSymbol *&iterator, SgExpression *&lower_bound, SgExpression *&upper_bound, SgExpression *&stride)
ROSE_DLL_API void appendExpression(SgExprListExp *, SgExpression *)
Append an expression to a SgExprListExp, set the parent pointer also.
ROSE_DLL_API bool isLambdaFunction(SgFunctionDeclaration *func)
Check if a function declaration is a C++11 lambda function.
ROSE_DLL_API SgBasicBlock * ensureBasicBlockAsBodyOfSwitch(SgSwitchStatement *ws)
Check if the body of a 'switch' statement is a SgBasicBlock, create one if not.
ROSE_DLL_API void prependStatement(SgStatement *stmt, SgScopeStatement *scope=NULL)
Prepend a statement to the beginning of the current scope, handling side effects as appropriate.
ROSE_DLL_API bool isStructType(SgType *t)
Check if a type is a struct type (a special SgClassType in ROSE). Typedef and modifier types are not ...
ROSE_DLL_API bool isCallToParticularFunction(SgFunctionDeclaration *decl, SgExpression *e)
Recursively print current and parent nodes. used within gdb to probe the context of a node.
ROSE_DLL_API bool ROSE_DLL_API isMutable(SgInitializedName *name)
True if an SgInitializedName is "mutable' (has storage modifier set)
ROSE_DLL_API bool isCopyConstructible(SgType *type)
Is a type copy constructible? This may not quite work properly.
ROSE_DLL_API SgVariableSymbol * prependArg(SgFunctionParameterList *, SgInitializedName *)
Prepend an argument to SgFunctionParameterList.
ROSE_DLL_API bool isPointerToNonConstType(SgType *type)
Is this a pointer to a non-const type? Note that this function will return true for const pointers po...
ROSE_DLL_API void setSourcePositionAtRootAndAllChildren(SgNode *root)
Set the source code positon for the subtree (including the root).
ROSE_DLL_API SgExpression * copyExpression(SgExpression *e)
Deep copy an expression.
void setParameterList(actualFunction *func, SgFunctionParameterList *paralist)
Set parameter list for a function declaration, considering existing parameter list etc.
SgStatement * findLastDeclarationStatement(SgScopeStatement *scope, bool includePragma=false)
Find the last declaration statement within a scope (if any). This is often useful to decide where to ...
ROSE_DLL_API bool insideSystemHeader(SgLocatedNode *node)
Set source position info(Sg_File_Info) as transformation generated for all SgNodes in memory pool.
std::vector< SgDeclarationStatement * > getDependentDeclarations(SgStatement *stmt)
Get a statement's dependent declarations which declares the types used in the statement....
SgBasicBlock * makeSingleStatementBodyToBlock(SgStatement *singleStmt)
Make a single statement body to be a basic block. Its parent is if, while, catch, or upc_forall etc.
void computeUniqueNameForUseAsIdentifier(SgNode *astNode)
Traversal to set the global map of names to node and node to names.collisions to support generateUniq...
ROSE_DLL_API void collectReadOnlyVariables(SgStatement *stmt, std::set< SgInitializedName * > &readOnlyVars, bool coarseGrain=true)
Collect read only variables within a statement. The statement can be either of a function,...
std::string generateUniqueNameForUseAsIdentifier_support(SgDeclarationStatement *declaration)
Global map of name collisions to support generateUniqueNameForUseAsIdentifier() function.
ROSE_DLL_API PreprocessingInfo * findHeader(SgSourceFile *source_file, const std::string &header_file_name, bool isSystemHeader)
Find the preprocessingInfo node representing #include <header.h> or #include "header....
bool IsLiteralType(const SgType *const inputType)
Collect all read and write references within stmt, which can be a function, a scope statement,...
ROSE_DLL_API void myRemoveStatement(SgStatement *stmt)
A special purpose statement removal function, originally from inlinerSupport.h, Need Jeremiah's atten...
bool IsEmpty(const SgType *const inputType)
Collect all read and write references within stmt, which can be a function, a scope statement,...
ROSE_DLL_API SgScopeStatement * getScope(const SgNode *astNode)
Get the closest scope from astNode. Return astNode if it is already a scope.
ROSE_DLL_API bool isStrictIntegerType(SgType *t)
Check if a type is an integral type, only allowing signed/unsigned short, int, long,...
ROSE_DLL_API bool is_Java_language()
ROSE_DLL_API void insertStatementAfter(SgStatement *targetStmt, SgStatement *newStmt, bool autoMovePreprocessingInfo=true)
Insert a statement after a target statement, Move around preprocessing info automatically by default.
ROSE_DLL_API bool isEquivalentType(const SgType *lhs, const SgType *rhs)
Test for equivalence of types independent of access permissions (private or protected modes for membe...
ROSE_DLL_API bool isTemplateInstantiationNode(SgNode *node)
Function to delete AST subtree's nodes only, users must take care of any dangling pointers,...
ROSE_DLL_API void removeStatement(SgStatement *stmt, bool autoRelocatePreprocessingInfo=true)
Remove a statement from its attach point of the AST. Automatically keep its associated preprocessing ...
ROSE_DLL_API SgOmpClauseBodyStatement * findEnclosingOmpClauseBodyStatement(SgStatement *s)
Find enclosing OpenMP clause body statement from s. If s is already one, return it directly.
ROSE_DLL_API bool scopeHasStatementsFromSameFile(SgScopeStatement *scope)
This function supports the token-based unparsing when used with unparsing of header files to know whe...
ROSE_DLL_API std::string mangleModifierType(SgModifierType *type)
Generated mangled modifier types, include const, volatile,according to Itanium C++ ABI,...
ROSE_DLL_API SgSourceFile * getEnclosingSourceFile(SgNode *n, const bool includingSelf=false)
Find enclosing source file node.
void rebuildSymbolTable(SgScopeStatement *scope)
Regenerate the symbol table.
ROSE_DLL_API SgSymbol * lookupSymbolInParentScopes(const SgName &name, SgScopeStatement *currentScope=NULL, SgTemplateParameterPtrList *templateParameterList=NULL, SgTemplateArgumentPtrList *templateArgumentList=NULL)
Find a symbol in current and ancestor scopes for a given variable name, starting from top of ScopeSta...
void setBaseTypeDefiningDeclaration(SgVariableDeclaration *var_decl, SgDeclarationStatement *base_decl)
a better version for SgVariableDeclaration::set_baseTypeDefininingDeclaration(), handling all side ef...
bool HasNoThrowAssign(const SgType *const inputType)
Collect all read and write references within stmt, which can be a function, a scope statement,...
ROSE_DLL_API void pastePreprocessingInfo(SgLocatedNode *dst_node, PreprocessingInfo::RelativePositionType pos, AttachedPreprocessingInfoType &saved_buf)
Paste preprocessing information from a buffer to a destination node. Used in combination of cutPrepro...
bool HasTrivialDestructor(const SgType *const inputType)
Collect all read and write references within stmt, which can be a function, a scope statement,...
ROSE_DLL_API SgType * getArrayElementType(SgType *t)
Get the element type of an array. It recursively find the base type for multi-dimension array types.
ROSE_DLL_API SgStatement * lastFrontEndSpecificStatement(SgGlobal *globalScope)
Function to delete AST subtree's nodes only, users must take care of any dangling pointers,...
ROSE_DLL_API SgFunctionType * findFunctionType(SgType *return_type, SgFunctionParameterTypeList *typeList)
Find the function type matching a function signature plus a given return type.
ROSE_DLL_API bool isUpcPrivateToSharedType(SgType *t)
Is a UPC private-to-shared pointer? SgPointerType comes first compared to SgModifierType with UPC inf...
std::set< unsigned int > collectSourceSequenceNumbers(SgNode *astNode)
Collect all read and write references within stmt, which can be a function, a scope statement,...
ROSE_DLL_API bool is_OpenMP_language()
ROSE_DLL_API std::set< SgNode * > getFrontendSpecificNodes()
Find a node by type using upward traversal.
ROSE_DLL_API bool mergeAssignmentWithDeclaration(SgExprStatement *assign_stmt, SgVariableDeclaration *decl, bool removeAssignStmt=true)
Merge an assignment into its upstream declaration statement. Callers should make sure the merge is se...
ROSE_DLL_API void setFortranNumericLabel(SgStatement *stmt, int label_value, SgLabelSymbol::label_type_enum label_type=SgLabelSymbol::e_start_label_type, SgScopeStatement *label_scope=NULL)
Set a numerical label for a Fortran statement. The statement should have a enclosing function definit...
ROSE_DLL_API SgType * lookupNamedTypeInParentScopes(const std::string &type_name, SgScopeStatement *scope=NULL)
Lookup a named type based on its name, bottomup searching from a specified scope. Note name collison ...
ROSE_DLL_API SgFile * processFile(SgProject *, std::string, bool unparse=false)
Invoke JavaRose to translate a given file and put the resulting AST in the global space of the projec...
static ROSE_DLL_API DeferredTransformation replaceDefiningFunctionDeclarationWithFunctionPrototype(SgFunctionDeclaration *functionDeclaration)
operator=()
ROSE_DLL_API ~DeferredTransformation(void)
Copy constructor.
ROSE_DLL_API DeferredTransformation & operator=(const DeferredTransformation &X)
Shallow; does not delete fields.