ROSE  0.9.6a
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sageInterface.h
Go to the documentation of this file.
1 #ifndef ROSE_SAGE_INTERFACE
2 #define ROSE_SAGE_INTERFACE
3 
4 #include "sage3basic.hhh"
5 #include <stdint.h>
6 #include <utility>
7 
8 #if 0 // FMZ(07/07/2010): the argument "nextErrorCode" should be call-by-reference
9 SgFile* determineFileType ( std::vector<std::string> argv, int nextErrorCode, SgProject* project );
10 #else
11 SgFile* determineFileType ( std::vector<std::string> argv, int& nextErrorCode, SgProject* project );
12 #endif
13 
14 #ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
15 #include "rewrite.h"
16 #endif
17 
18 // DQ (7/20/2008): Added support for unparsing abitrary strings in the unparser.
19 #include "astUnparseAttribute.h"
20 #include <set>
21 
22 #ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
23 #include "LivenessAnalysis.h"
24 #include "abstract_handle.h"
25 #include "ClassHierarchyGraph.h"
26 #endif
27 
28 // DQ (8/19/2004): Moved from ROSE/src/midend/astRewriteMechanism/rewrite.h
30 ROSE_DLL_API std::string getVariantName (VariantT v);
31 
32 // DQ (12/9/2004): Qing, Rich and Dan have decided to start this namespace within ROSE
33 // This namespace is specific to interface functions that operate on the Sage III AST.
34 // The name was chosen so as not to conflict with other classes within ROSE.
35 // This will become the future home of many interface functions which operate on
36 // the AST and which are generally useful to users. As a namespace multiple files can be used
37 // to represent the compete interface and different developers may contribute interface
38 // functions easily.
39 
40 // Constructor handling: (We have sageBuilder.h now for this purpose, Liao 2/1/2008)
41 // We could add simpler layers of support for construction of IR nodes by
42 // hiding many details in "makeSg***()" functions. Such functions would
43 // return pointers to the associated Sg*** objects and would be able to hide
44 // many IR specific details, including:
45 // memory handling
46 // optional parameter settings not often required
47 // use of Sg_File_Info objects (and setting them as transformations)
48 //
49 // namespace AST_Interface (this name is taken already by some of Qing's work :-)
50 
52 #define TRANS_FILE Sg_File_Info::generateDefaultFileInfoForTransformationNode()
53 
54 //------------------------------------------------------------------------
84 namespace SageInterface
85  {
86  // DQ (4/3/2014): Added general AST support seperate from the AST.
87 
88  // Container and API for analysis information that is outside of the AST and as a result
89  // prevents frequent modification of the IR.
91  {
92  // DQ (4/3/2014): This stores all associated declarations as a map of sets.
93  // the key to the map is the first nondefining declaration and the elements of the set are
94  // all of the associated declarations (including the defining declaration).
95 
96  private:
98  std::map<SgDeclarationStatement*,std::set<SgDeclarationStatement*>* > declarationMap;
99 
100  public:
102  const std::set<SgDeclarationStatement*>* getDeclarations(SgDeclarationStatement* decl);
103 
104  std::map<SgDeclarationStatement*,std::set<SgDeclarationStatement*>* > & getDeclarationMap();
105 
107 
108  };
109 
110  // DQ (4/3/2014): This constucts a data structure that holds analysis information about
111  // the AST that is seperate from the AST. This is intended to be a general mechanism
112  // to support analysis information without constantly modifing the IR.
114 
115 
116 
118 ROSE_DLL_API extern int gensym_counter;
119 
120 // tps : 28 Oct 2008 - support for finding the main interpretation
122 
125 
128 
130  void addMessageStatement( SgStatement* stmt, std::string message );
131 
134  {
135  private:
136  std::string name;
137  public:
138  UniqueNameAttribute(std::string n="") {name =n; };
139  void set_name (std::string n) {name = n;};
140  std::string get_name () {return name;};
141  };
142 
143 // DQ (3/2/2009): Added support for collectiong an merging the referenced symbols in the outlined
144 // function into the list used to edit the outlined code subtree to fixup references (from symbols
145 // in the original file to the symbols in the newer separate file).
146 // typedef rose_hash::unordered_map<SgNode*, SgNode*, hash_nodeptr> ReplacementMapType;
147 // void supplementReplacementSymbolMap ( const ReplacementMapTraversal::ReplacementMapType & inputReplacementMap );
148 
149 // CH (4/9/2010): Use boost::hash instead
150 //#ifdef _MSC_VER
151 #if 0
152 inline size_t hash_value(SgNode* t) {return (size_t)t;}
153 #endif
154 
156  {
157 // CH (4/9/2010): Use boost::hash instead
158 //#ifndef _MSC_VER
159 #if 0
160  //rose_hash::hash<char*> hasher;
161 #endif
162  public:
163  size_t operator()(SgNode* node) const
164  {
165 // CH (4/9/2010): Use boost::hash instead
166 //#ifdef _MSC_VER
167  #if 0
168  return (size_t) hash_value(node);
169  #else
170  return (size_t) node;
171  #endif
172  }
173  };
174 
175 #ifndef SWIG
176 // DQ (3/10/2013): This appears to be a problem for the SWIG interface (undefined reference at link-time).
177  void supplementReplacementSymbolMap ( rose_hash::unordered_map<SgNode*, SgNode*, hash_nodeptr> & inputReplacementMap );
178 #endif
179 
180  //------------------------------------------------------------------------
182 
185  // Liao 1/22/2008, used for get symbols for generating variable reference nodes
186  // ! Find a variable symbol in current and ancestor scopes for a given name
188 
189 // DQ (8/21/2013): Modified to make newest function parameters be default arguments.
190 // 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.
192 // SgSymbol *lookupSymbolInParentScopes (const SgName & name, SgScopeStatement *currentScope=NULL);
193 // SgSymbol *lookupSymbolInParentScopes (const SgName & name, SgScopeStatement *currentScope, SgTemplateParameterPtrList* templateParameterList, SgTemplateArgumentPtrList* templateArgumentList);
194  ROSE_DLL_API SgSymbol *lookupSymbolInParentScopes (const SgName & name, SgScopeStatement *currentScope = NULL, SgTemplateParameterPtrList* templateParameterList = NULL, SgTemplateArgumentPtrList* templateArgumentList = NULL);
195 
196  // DQ (11/24/2007): Functions moved from the Fortran support so that they could be called from within astPostProcessing.
198  ROSE_DLL_API SgFunctionSymbol *lookupFunctionSymbolInParentScopes (const SgName & functionName, SgScopeStatement *currentScope=NULL);
199 
200  // Liao, 1/24/2008, find exact match for a function
203  const SgType* t,
204  SgScopeStatement *currentScope=NULL);
205 
206 // DQ (8/21/2013): Modified to make newest function parameters be default arguments.
207 // 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.
208 // DQ (5/7/2011): Added support for SgClassSymbol (used in name qualification support).
209 // SgClassSymbol* lookupClassSymbolInParentScopes (const SgName & name, SgScopeStatement *currentScope = NULL);
210  ROSE_DLL_API SgClassSymbol* lookupClassSymbolInParentScopes (const SgName & name, SgScopeStatement *currentScope = NULL, SgTemplateArgumentPtrList* templateArgumentList = NULL);
212 
213 #if 0
214  // DQ (8/13/2013): This function does not make since any more, now that we have make the symbol
215  // table handling more precise and we have to provide template parameters for any template lookup.
216  // We also have to know if we want to lookup template classes, template functions, or template
217  // member functions (since each have specific requirements).
218  SgTemplateSymbol* lookupTemplateSymbolInParentScopes (const SgName & name, SgScopeStatement *currentScope = NULL);
219 #endif
220 #if 0
221 // DQ (8/13/2013): I am not sure if we want this functions in place of lookupTemplateSymbolInParentScopes.
222 // Where these are called we might not know enough information about the template parameters or function
223 // types, for example.
224  SgTemplateClassSymbol* lookupTemplateClassSymbolInParentScopes (const SgName & name, SgScopeStatement *currentScope = NULL, SgTemplateParameterPtrList* templateParameterList = NULL, SgTemplateArgumentPtrList* templateArgumentList = NULL);
225  SgTemplateFunctionSymbol* lookupTemplateFunctionSymbolInParentScopes (const SgName & name, SgScopeStatement *currentScope = NULL, SgTemplateParameterPtrList* templateParameterList = NULL);
226  SgTemplateMemberFunctionSymbol* lookupTemplateMemberFunctionSymbolInParentScopes (const SgName & name, SgScopeStatement *currentScope = NULL, SgTemplateParameterPtrList* templateParameterList = NULL);
227 #endif
228 
229 // DQ (8/21/2013): Modified to make some of the newest function parameters be default arguments.
230 // DQ (8/13/2013): I am not sure if we want this functions in place of lookupTemplateSymbolInParentScopes.
232 
235 
236 // DQ (7/17/2011): Added function from cxx branch that I need here for the Java support.
237 // SgClassSymbol* lookupClassSymbolInParentScopes (const SgName & name, SgScopeStatement *cscope);
238 
247  // DQ (12/9/2004): Moved this function (by Alin Jula) from being a member of SgInitializedName
248  // to this location where it can be a part of the interface for the Sage III AST.
249  ROSE_DLL_API int set_name (SgInitializedName * initializedNameNode, SgName new_name);
250 
254 
255  // DQ (6/27/2005):
261 
263  {
264  public:
265  void visit (SgNode * node);
266  };
272  // DQ (9/28/2005):
273  void rebuildSymbolTable (SgScopeStatement * scope);
274 
277  void clearUnusedVariableSymbols (SgNode* root = NULL);
278 
279  // DQ (3/1/2009):
281  void fixupReferencesToSymbols( const SgScopeStatement* this_scope, SgScopeStatement* copy_scope, SgCopyHelp & help );
282 
284 
285  //------------------------------------------------------------------------
287 
294  // DQ (9/21/2005): General function for extracting the name of declarations (when they have names)
295  std::string get_name (const SgNode * node);
296 
301  // DQ (6/13/2005): General function for extracting the name of declarations (when they have names)
302  std::string get_name (const SgStatement * stmt);
303 
308  std::string get_name (const SgExpression * expr);
309 
314  // DQ (6/13/2005): General function for extracting the name of declarations (when they have names)
315  std::string get_name (const SgDeclarationStatement * declaration);
316 
321  // DQ (6/13/2005): General function for extracting the name of declarations (when they have names)
322  std::string get_name (const SgScopeStatement * scope);
323 
328  // DQ (2/11/2007): Added this function to make debugging support more complete (useful for symbol table debugging support).
329  std::string get_name (const SgSymbol * symbol);
330 
335  std::string get_name (const SgType * type);
336 
337 
340  std::string get_name (const SgSupport * node);
341 
342 
345  std::string get_name (const SgLocatedNodeSupport * node);
346 
349  std::string get_name ( const SgC_PreprocessorDirectiveStatement* directive );
350 
353  std::string get_name ( const SgToken* token );
354 
356 
357  //------------------------------------------------------------------------
359 
364  // DQ (6/21/2005): Get the default destructor from the class declaration
366  classDeclaration);
367 
370  // DQ (6/22/2005): Get the default constructor from the class declaration
372  classDeclaration);
375  // DQ (8/27/2005):
377  * memberFunctionDeclaration);
378 
383  // DQ (9/17/2005):
386  (SgTemplateInstantiationMemberFunctionDecl * memberFunctionInstantiation);
387 
389  bool isStructDeclaration(SgNode * node);
391  bool isUnionDeclaration(SgNode * node);
392  #if 0
393  // DQ (8/28/2005): This is already a member function of the SgFunctionDeclaration
394  // (so that it can handle template functions and member functions)
395 
399  // DQ (8/27/2005):
400  bool isTemplateMemberFunction (SgTemplateInstantiationMemberFunctionDecl *
401  memberFunctionDeclaration);
402  #endif
403 
405 
406  //------------------------------------------------------------------------
408 
412  // DQ (2/12/2012): Added some diagnostic support.
414  void whereAmI(SgNode* node);
415 
417  std::string extractPragmaKeyword(const SgPragmaDeclaration *);
418 
423  // DQ (8/27/2005):
424  bool isOverloaded (SgFunctionDeclaration * functionDeclaration);
425 
426 // DQ (2/14/2012): Added support function used for variable declarations in conditionals.
428  void initializeIfStmt(SgIfStmt *ifstmt, SgStatement* conditional, SgStatement * true_body, SgStatement * false_body);
429 
431  void initializeSwitchStatement(SgSwitchStatement* switchStatement,SgStatement *item_selector,SgStatement *body);
432 
434  void initializeWhileStatement(SgWhileStmt* whileStatement, SgStatement * condition, SgStatement *body, SgStatement *else_body);
435 
438 
440  ROSE_DLL_API bool isMain (const SgNode* node);
441  // DQ (6/22/2005):
452  std::string generateUniqueName ( const SgNode * node, bool ignoreDifferenceBetweenDefiningAndNondefiningDeclarations);
453 
456  std::string generateUniqueVariableName(SgScopeStatement* scope, std::string baseName = "temp");
457 
458  // DQ (8/10/2010): Added const to first parameter.
459  // DQ (3/10/2007):
461  std::string declarationPositionString (const SgDeclarationStatement * declaration);
462 
463  // DQ (1/20/2007):
465  ROSE_DLL_API std::string generateProjectName (const SgProject * project, bool supressSuffix = false );
466 
470 
473 
475  void addVarRefExpFromArrayDimInfo(SgNode * astNode, Rose_STL_Container<SgNode *>& NodeList_t);
476 
477  // DQ (10/6/2006): Added support for faster mangled name generation (caching avoids recomputation).
481 #ifndef SWIG
482 // DQ (3/10/2013): This appears to be a problem for the SWIG interface (undefined reference at link-time).
483  void clearMangledNameCache (SgGlobal * globalScope);
484  void resetMangledNameCache (SgGlobal * globalScope);
485 #endif
486 
487  std::string getMangledNameFromCache (SgNode * astNode);
488  std::string addMangledNameToCache (SgNode * astNode, const std::string & mangledName);
489 
491 
495 
496  // DQ (10/14/2006): This function tests the AST to see if for a non-defining declaration, the
497  // bool declarationPreceedsDefinition ( SgClassDeclaration* classNonDefiningDeclaration, SgClassDeclaration* classDefiningDeclaration );
499  bool declarationPreceedsDefinition (SgDeclarationStatement *nonDefiningDeclaration, SgDeclarationStatement *definingDeclaration);
500 
501  // DQ (10/19/2006): Function calls have interesting context dependent rules to determine if
502  // they are output with a global qualifier or not. Were this is true we have to avoid global
503  // qualifiers, since the function's scope has not been defined. This is an example of where
504  // qualification of function names in function calls are context dependent; an interesting
505  // example of where the C++ language is not friendly to source-to-source processing :-).
507 
512  ROSE_DLL_API std::vector < SgNode * >astIntersection (SgNode * original, SgNode * copy, SgCopyHelp * help = NULL);
513 
515  ROSE_DLL_API SgNode* deepCopyNode (const SgNode* subtree);
516 
518  template <typename NodeType>
519  NodeType* deepCopy (const NodeType* subtree) {
520  return dynamic_cast<NodeType*>(deepCopyNode(subtree));
521  }
522 
525 
528 
529 // from VarSym.cc in src/midend/astOutlining/src/ASTtools
532 
535 
538 
541 
543 ROSE_DLL_API bool isCallToParticularFunction(const std::string& qualifiedName, size_t arity, SgExpression* e);
544 
547 
550 
553 
556 
560  public:
561  virtual ~StatementGenerator() {};
562  virtual SgStatement* generate(SgExpression* where_to_write_answer) = 0;
563 };
564 
568  bool isAssignmentStatement(SgNode* _s, SgExpression** lhs=NULL, SgExpression** rhs=NULL, bool* readlhs=NULL);
569 
572 
574 ROSE_DLL_API AbstractHandle::abstract_handle* buildAbstractHandle(SgNode*);
575 
577 ROSE_DLL_API SgNode* getSgNodeFromAbstractHandleString(const std::string& input_string);
578 
580 ROSE_DLL_API void dumpInfo(SgNode* node, std::string desc="");
581 
583 ROSE_DLL_API std::vector<SgDeclarationStatement*>
584 sortSgNodeListBasedOnAppearanceOrderInSource(const std::vector<SgDeclarationStatement*>& nodevec);
585 
586 // DQ (4/13/2013): We need these to support the unparing of operators defined by operator syntax or member function names.
588 // bool isPrefixOperator( const SgMemberFunctionRefExp* memberFunctionRefExp );
589 bool isPrefixOperator( SgExpression* exp );
590 
592 bool isPrefixOperatorName( const SgName & functionName );
593 
595 bool isPostfixOperator( SgExpression* exp );
596 
598 bool isIndexOperator( SgExpression* exp );
599 
601 
602 //------------------------------------------------------------------------
604 
608 // std::string version(); // utility_functions.h, version number
611  ROSE_DLL_API bool is_C_language ();
631 
632 //------------------------------------------------------------------------
634 
638  // DQ (10/5/2006): Added support for faster (non-quadratic) computation of unique
639  // labels for scopes in a function (as required for name mangling).
645  void resetScopeNumbers (SgFunctionDefinition * functionDeclaration);
646 
647  // DQ (10/5/2006): Added support for faster (non-quadratic) computation of unique
648  // labels for scopes in a function (as required for name mangling).
657  void clearScopeNumbers (SgFunctionDefinition * functionDefinition);
658 
659 
662 // SgNamespaceDefinitionStatement * getEnclosingNamespaceScope (SgNode * node);
663 
664  bool isPrototypeInScope (SgScopeStatement * scope,
665  SgFunctionDeclaration * functionDeclaration,
666  SgDeclarationStatement * startingAtDeclaration);
667 
669  bool ROSE_DLL_API isAncestor(SgNode* node1, SgNode* node2);
671 //------------------------------------------------------------------------
673 
677  void dumpPreprocInfo (SgLocatedNode* locatedNode);
679 
681 ROSE_DLL_API PreprocessingInfo* insertHeader(const std::string& filename, PreprocessingInfo::RelativePositionType position=PreprocessingInfo::after, bool isSystemHeader=false, SgScopeStatement* scope=NULL);
682 
685 
688  PreprocessingInfo::RelativePositionType dst_position=PreprocessingInfo::undef, bool usePrepend= false);
689 
690 
693 
696 
699  const std::string & text,
701 
705 
706 
707 //------------------------------------------------------------------------
709 
712  ROSE_DLL_API PreprocessingInfo* attachComment(SgLocatedNode* target, const std::string & content,
716 
717 // DQ (11/25/2009): Added matching support for adding comments to SgAsm nodes.
718 // Build and attach comment
719 // void attachComment(SgAsmStatement* target, const std::string & content );
720 
721 // DQ (7/20/2008): I am not clear were I should put this function, candidates include: SgLocatedNode or SgInterface
723  ROSE_DLL_API void addTextForUnparser ( SgNode* astNode, std::string s, AstUnparseAttribute::RelativePositionType inputlocation );
724 
725 
726 
727 // ************************************************************************
728 // Newer versions of now depricated functions
729 // ************************************************************************
730 
731 // DQ (5/1/2012): This function queries the SageBuilder::SourcePositionClassification mode (stored in the SageBuilder
732 // interface) and used the specified mode to initialize the source position data (Sg_File_Info objects). This
733 // function is the only function that should be called directly (though in a namespace we can't define permissions).
735  void setSourcePosition(SgNode* node);
736 
737 // A better name might be "setSourcePositionForSubTree"
740 
741 // DQ (5/1/2012): New function with improved name (still preserving the previous interface).
742 // This function is not required once the new mechanism defining a source position mode is complete (shortly).
744 // void setSourcePositionAtRootAndAllChildrenAsTransformation(SgNode *root);
745 // void setSourcePositionAtRootAndAllChildrenAsDefault(SgNode *root);
746 
747 // Removed to force use of the API and permit flexability in the lower level implementation.
749 // void setSourcePositionToDefault( SgLocatedNode* locatedNode );
750  template<class T> void setSourcePositionToDefault( T* node );
751 
754 
755 // DQ (5/1/2012): Newly renamed function (previous name preserved for backward compatability).
757 
758 // ************************************************************************
759 
760 
761 
762 // ************************************************************************
763 // Older deprecated functions
764 // ************************************************************************
765  // Liao, 1/8/2007, set file info. for a whole subtree as transformation generated
768 
771 
774 
777 
779 // ROSE_DLL_API void setSourcePosition (SgLocatedNode * locatedNode);
780 // ************************************************************************
781 
783 
784 
785 //------------------------------------------------------------------------
787 
791 // from src/midend/astInlining/typeTraits.h
792 // src/midend/astUtil/astInterface/AstInterface.h
793 
796 
797 
804 
807 
810 
812 ROSE_DLL_API bool isAssignable(SgType* type);
813 
814 #ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
815 ROSE_DLL_API bool isPureVirtualClass(SgType* type, const ClassHierarchyWrapper& classHierarchy);
819 #endif
820 
823 
826 
829 
832 
839 
841 /* const char* p = "aa"; is not treated as having a const type. It is a pointer to const char.
842  * Similarly, neither for const int b[10]; or const int & c =10;
843  * The standard says, "A compound type is not cv-qualified by the cv-qualifiers (if any) of
844 the types from which it is compounded. Any cv-qualifiers applied to an array type affect the array element type, not the array type".
845  */
847 
850 
853 
856 
858 
861 
866 
869 
871 ROSE_DLL_API std::string mangleType(SgType* type);
872 
874 ROSE_DLL_API std::string mangleScalarType(SgType* type);
875 
878 
881 
884 
887 
890 
891 
908 std::vector<SgExpression*>
909 get_C_array_dimensions(const SgArrayType& arrtype);
910 
931 std::vector<SgExpression*>
932 get_C_array_dimensions(const SgArrayType& arrtype, const SgVarRefExp& varref);
933 
937 std::vector<SgExpression*>
938 get_C_array_dimensions(const SgArrayType& arrtype, SgInitializedName& initname);
939 
940 
942 ROSE_DLL_API bool isArrayReference(SgExpression* ref, SgExpression** arrayNameExp=NULL, std::vector<SgExpression*>** subscripts=NULL);
943 
944 
946 
955 ROSE_DLL_API bool hasUpcSharedType(SgType* t, SgModifierType ** mod_type_out = NULL );
956 
958 
961 ROSE_DLL_API bool isUpcSharedType(SgType* t, SgModifierType ** mod_type_out = NULL);
962 
965 
968 
971 
974 
977 
980 
983 
986 
988 ROSE_DLL_API SgType* lookupNamedTypeInParentScopes(const std::string& type_name, SgScopeStatement* scope=NULL);
989 
991 
992 //------------------------------------------------------------------------
994 
998 // by Jeremiah
1008 
1014 
1017 
1020 ROSE_DLL_API bool isLoopIndexVariable(SgInitializedName* ivar, SgNode* subtree_root);
1021 
1024 
1026 
1029 
1032 
1036 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);
1037 
1039 ROSE_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*/);
1040 
1043 
1046 
1048 ROSE_DLL_API void setLoopStride(SgNode* loop, SgExpression* stride);
1049 
1050 
1053 
1066 
1069 
1071 ROSE_DLL_API bool loopUnrolling(SgForStatement* loop, size_t unrolling_factor);
1072 
1074 ROSE_DLL_API bool loopInterchange(SgForStatement* loop, size_t depth, size_t lexicoOrder);
1075 
1077 ROSE_DLL_API bool loopTiling(SgForStatement* loopNest, size_t targetLevel, size_t tileSize);
1078 
1079 //Winnie Loop Collapsing
1080 SgExprListExp * loopCollapsing(SgForStatement* target_loop, size_t collapsing_factor);
1081 
1083 
1084 //------------------------------------------------------------------------
1086 
1090 template <typename NodeType>
1092 std::vector<NodeType*> querySubTree(SgNode* top, VariantT variant = (VariantT)NodeType::static_variant)
1093 {
1094  Rose_STL_Container<SgNode*> nodes = NodeQuery::querySubTree(top,variant);
1095  std::vector<NodeType*> result(nodes.size(), NULL);
1096  int count = 0;
1097  for (Rose_STL_Container<SgNode*>::const_iterator i = nodes.begin();
1098  i != nodes.end(); ++i, ++count) {
1099  NodeType* node = dynamic_cast<NodeType*>(*i);
1100  ROSE_ASSERT (node);
1101  result[count] = node;
1102  }
1103  return result;
1104 }
1109  std::vector < SgFile * >generateFileList ();
1110 
1113 
1115 template <typename NodeType>
1116 static std::vector<NodeType*> getSgNodeListFromMemoryPool()
1117 {
1118  // This function uses a memory pool traversal specific to the SgFile IR nodes
1119  class MyTraversal : public ROSE_VisitTraversal
1120  {
1121  public:
1122  std::vector<NodeType*> resultlist;
1123  void visit ( SgNode* node)
1124  {
1125  NodeType* result = dynamic_cast<NodeType* > (node);
1126  ROSE_ASSERT(result!= NULL);
1127  if (result!= NULL)
1128  {
1129  resultlist.push_back(result);
1130  }
1131  };
1132  virtual ~MyTraversal() {}
1133  };
1134 
1135  MyTraversal my_traversal;
1136  NodeType::visitRepresentativeNode(my_traversal);
1137  return my_traversal.resultlist;
1138 }
1139 
1140 
1144 
1147 
1148  //midend/programTransformation/partialRedundancyElimination/pre.h
1150 std::vector<SgVariableSymbol*> getSymbolsUsedInExpression(SgExpression* expr);
1151 
1153 
1158 std::vector<SgBreakStmt*> findBreakStmts(SgStatement* code, const std::string& fortranLabel = "");
1159 
1161 
1166  std::vector<SgContinueStmt*> findContinueStmts(SgStatement* code, const std::string& fortranLabel = "");
1167  std::vector<SgGotoStatement*> findGotoStmts(SgStatement* scope, SgLabelStatement* l);
1168  std::vector<SgStatement*> getSwitchCases(SgSwitchStatement* sw);
1169 
1171  template <typename T>
1172  T* findDeclarationStatement(SgNode* root, std::string name, SgScopeStatement* scope, bool isDefining)
1173  {
1174  bool found = false;
1175  if (!root) return 0;
1176  T* decl = dynamic_cast<T*>(root);
1177  if (decl!=NULL)
1178  {
1179  if (scope)
1180  {
1181  if ((decl->get_scope() == scope)&&
1182  (decl->search_for_symbol_from_symbol_table()->get_name()==name))
1183  {
1184  found = true;
1185  }
1186  }
1187  else // Liao 2/9/2010. We should allow NULL scope
1188  {
1189  if(decl->search_for_symbol_from_symbol_table()->get_name()==name)
1190  {
1191  found = true;
1192  }
1193  }
1194  }
1195 
1196  if (found)
1197  {
1198  if (isDefining)
1199  {
1200  ROSE_ASSERT (decl->get_definingDeclaration() != NULL);
1201  return dynamic_cast<T*> (decl->get_definingDeclaration());
1202  }
1203  else
1204  return decl;
1205  }
1206 
1207  std::vector<SgNode*> children = root->get_traversalSuccessorContainer();
1208  for (std::vector<SgNode*>::const_iterator i = children.begin();
1209  i != children.end(); ++i)
1210  {
1211  T* target= findDeclarationStatement<T> (*i,name, scope, isDefining);
1212  if (target)
1213  return target;
1214  }
1215  return 0;
1216  }
1218  SgFunctionDeclaration* findFunctionDeclaration(SgNode* root, std::string name, SgScopeStatement* scope, bool isDefining);
1219 
1220 #if 0 //TODO
1221  // 1. preorder traversal from current SgNode till find next SgNode of type V_SgXXX
1222  // until reach the end node
1223  SgNode* getNextSgNode( const SgNode* astSourceNode, VariantT=V_SgNode, SgNode* astEndNode=NULL);
1224 
1225  // 2. return all nodes of type VariantT following the source node
1226  std::vector<SgNode*> getAllNextSgNode( const SgNode* astSourceNode, VariantT=V_SgNode, SgNode* astEndNode=NULL);
1227 #endif
1228 
1230 
1231 //------------------------------------------------------------------------
1233 
1236 // remember to put const to all arguments.
1237 
1238 
1253 template <typename NodeType>
1254 NodeType* getEnclosingNode(const SgNode* astNode, const bool includingSelf = false)
1255  {
1256 #if 1
1257  // DQ (10/20/2012): This is the older version of this implementation. Until I am sure that
1258  // the newer version (below) is what we want to use I will resolve this conflict by keeping
1259  // the previousl version in place.
1260 
1261  if (NULL == astNode)
1262  {
1263  return NULL;
1264  }
1265 
1266  if ( (includingSelf ) && (dynamic_cast<const NodeType*>(astNode)) )
1267  {
1268  return const_cast<NodeType*>(dynamic_cast<const NodeType*> (astNode));
1269  }
1270 
1271  // DQ (3/5/2012): Check for reference to self...
1272  ROSE_ASSERT(astNode->get_parent() != astNode);
1273 
1274  SgNode* parent = astNode->get_parent();
1275 
1276  // DQ (3/5/2012): Check for loops that will cause infinite loops.
1277  SgNode* previouslySeenParent = parent;
1278  bool foundCycle = false;
1279  while ( (foundCycle == false) && (parent != NULL) && (!dynamic_cast<const NodeType*>(parent)) )
1280  {
1281  ROSE_ASSERT(parent->get_parent() != parent);
1282 #if 0
1283  printf ("In getEnclosingNode(): parent = %p = %s \n",parent,parent->class_name().c_str());
1284 #endif
1285  parent = parent->get_parent();
1286 
1287  // DQ (3/5/2012): Check for loops that will cause infinite loops.
1288  // ROSE_ASSERT(parent != previouslySeenParent);
1289  if (parent == previouslySeenParent)
1290  {
1291  foundCycle = true;
1292  }
1293  }
1294 
1295 #if 0
1296  printf ("previouslySeenParent = %p = %s \n",previouslySeenParent,previouslySeenParent->class_name().c_str());
1297 #endif
1298 
1299  parent = previouslySeenParent;
1300 
1301  SgDeclarationStatement* declarationStatement = isSgDeclarationStatement(parent);
1302  if (declarationStatement != NULL)
1303  {
1304 #if 0
1305  printf ("Found a SgDeclarationStatement \n");
1306 #endif
1307  SgDeclarationStatement* definingDeclaration = declarationStatement->get_definingDeclaration();
1308  SgDeclarationStatement* firstNondefiningDeclaration = declarationStatement->get_firstNondefiningDeclaration();
1309 
1310 #if 0
1311  printf (" --- declarationStatement = %p \n",declarationStatement);
1312  printf (" --- definingDeclaration = %p \n",definingDeclaration);
1313  if (definingDeclaration != NULL && definingDeclaration->get_parent() != NULL)
1314  printf (" --- definingDeclaration ->get_parent() = %p = %s \n",definingDeclaration->get_parent(),definingDeclaration->get_parent()->class_name().c_str());
1315  printf (" --- firstNondefiningDeclaration = %p \n",firstNondefiningDeclaration);
1316  if (firstNondefiningDeclaration != NULL && firstNondefiningDeclaration->get_parent() != NULL)
1317  printf (" --- firstNondefiningDeclaration ->get_parent() = %p = %s \n",firstNondefiningDeclaration->get_parent(),firstNondefiningDeclaration->get_parent()->class_name().c_str());
1318 #endif
1319  if (definingDeclaration != NULL && declarationStatement != firstNondefiningDeclaration)
1320  {
1321 #if 0
1322  printf ("Found a nondefining declaration so use the non-defining declaration instead \n");
1323 #endif
1324  // DQ (10/19/2012): Use the defining declaration instead.
1325  // parent = firstNondefiningDeclaration;
1326  parent = definingDeclaration;
1327  }
1328  }
1329 
1330 #if 0
1331  printf ("reset: previouslySeenParent = %p = %s \n",previouslySeenParent,previouslySeenParent->class_name().c_str());
1332 #endif
1333 
1334  // DQ (10/19/2012): This branch is just to document the cycle that was previously detected, it is for
1335  // debugging only. Thus it ony make sense for it to be executed when "(foundCycle == true)". However,
1336  // this will have to be revisited later since it appears clear that it is a problem for the binary analysis
1337  // work when it is visited for this case. Since the cycle is detected, but there is no assertion on the
1338  // cycle, we don't exit when a cycle is identified (which is the point of the code below).
1339  // Note also that I have fixed the code (above and below) to only chase pointers through defining
1340  // declarations (where they exist), this is important since non-defining declarations can be almost
1341  // anywhere (and thus chasing them can make it appear that there are cycles where there are none
1342  // (I think); test2012_234.C demonstrates an example of this.
1343  // DQ (10/9/2012): Robb has suggested this change to fix the binary analysis work.
1344  // if (foundCycle == true)
1345  if (foundCycle == false)
1346  {
1347 
1348 
1349  while ( (parent != NULL) && (!dynamic_cast<const NodeType*>(parent)) )
1350  {
1351  ROSE_ASSERT(parent->get_parent() != parent);
1352 #if 0
1353  printf ("In getEnclosingNode() (2nd try): parent = %p = %s \n",parent,parent->class_name().c_str());
1354  if (parent->get_file_info() != NULL)
1355  parent->get_file_info()->display("In getEnclosingNode() (2nd try): debug");
1356 #endif
1357  SgDeclarationStatement* declarationStatement = isSgDeclarationStatement(parent);
1358  if (declarationStatement != NULL)
1359  {
1360 #if 0
1361  printf ("Found a SgDeclarationStatement \n");
1362 #endif
1363  SgDeclarationStatement* definingDeclaration = declarationStatement->get_definingDeclaration();
1364  SgDeclarationStatement* firstNondefiningDeclaration = declarationStatement->get_firstNondefiningDeclaration();
1365 #if 0
1366  printf (" --- declarationStatement = %p = %s \n",declarationStatement,(declarationStatement != NULL) ? declarationStatement->class_name().c_str() : "null");
1367 
1368  printf (" --- definingDeclaration = %p \n",definingDeclaration);
1369  if (definingDeclaration != NULL && definingDeclaration->get_parent() != NULL)
1370  printf (" --- definingDeclaration ->get_parent() = %p = %s \n",definingDeclaration->get_parent(),definingDeclaration->get_parent()->class_name().c_str());
1371 
1372  printf (" --- firstNondefiningDeclaration = %p \n",firstNondefiningDeclaration);
1373  if (firstNondefiningDeclaration != NULL && firstNondefiningDeclaration->get_parent() != NULL)
1374  printf (" --- firstNondefiningDeclaration ->get_parent() = %p = %s \n",firstNondefiningDeclaration->get_parent(),firstNondefiningDeclaration->get_parent()->class_name().c_str());
1375 #endif
1376  if (definingDeclaration != NULL && declarationStatement != firstNondefiningDeclaration)
1377  {
1378 #if 0
1379  printf ("Found a nondefining declaration so use the firstNondefining declaration instead \n");
1380 #endif
1381  // DQ (10/19/2012): Use the defining declaration instead.
1382  // parent = firstNondefiningDeclaration;
1383  parent = definingDeclaration;
1384  }
1385  }
1386 
1387  parent = parent->get_parent();
1388 
1389 #if 1
1390  // DQ (3/5/2012): Check for loops that will cause infinite loops.
1391  ROSE_ASSERT(parent != previouslySeenParent);
1392 #else
1393  printf ("WARNING::WARNING::WARNING commented out assertion for parent != previouslySeenParent \n");
1394  if (parent == previouslySeenParent)
1395  break;
1396 #endif
1397  }
1398  }
1399 
1400  return const_cast<NodeType*>(dynamic_cast<const NodeType*> (parent));
1401 #else
1402  // DQ (10/20/2012): Using Robb's newer version with my modification to use the definingDeclaration rather than firstNondefiningDeclaration (below).
1403 
1404  // Find the parent of specified type, but watch out for cycles in the ancestry (which would cause an infinite loop).
1405  // Cast away const because isSg* functions aren't defined for const node pointers; and our return is not const.
1406  SgNode *node = const_cast<SgNode*>(!astNode || includingSelf ? astNode : astNode->get_parent());
1407  std::set<const SgNode*> seen; // nodes we've seen, in order to detect cycles
1408  while (node) {
1409  if (NodeType *found = dynamic_cast<NodeType*>(node))
1410  return found;
1411 
1412  // FIXME: Cycle detection could be moved elsewhere so we don't need to do it on every call. [RPM 2012-10-09]
1413  ROSE_ASSERT(seen.insert(node).second);
1414 
1415  // Traverse to parent (declaration statements are a special case)
1416  if (SgDeclarationStatement *declarationStatement = isSgDeclarationStatement(node)) {
1417  SgDeclarationStatement *definingDeclaration = declarationStatement->get_definingDeclaration();
1418  SgDeclarationStatement *firstNondefiningDeclaration = declarationStatement->get_firstNondefiningDeclaration();
1419  if (definingDeclaration && firstNondefiningDeclaration && declarationStatement != firstNondefiningDeclaration) {
1420  // DQ (10/19/2012): Use the defining declaration instead.
1421  // node = firstNondefiningDeclaration;
1422  node = definingDeclaration;
1423  }
1424  } else {
1425  node = node->get_parent();
1426  }
1427  }
1428  return NULL;
1429 #endif
1430  }
1431 
1433  ROSE_DLL_API SgSourceFile* getEnclosingSourceFile(SgNode* n, const bool includingSelf=false);
1434 
1436  ROSE_DLL_API SgScopeStatement* getScope(const SgNode* astNode);
1437 
1439  ROSE_DLL_API SgScopeStatement* getEnclosingScope(SgNode* n, const bool includingSelf=false);
1440 
1442  ROSE_DLL_API SgGlobal* getGlobalScope( const SgNode* astNode);
1443 
1444 
1446  ROSE_DLL_API SgFunctionDefinition* getEnclosingProcedure(SgNode* n, const bool includingSelf=false);
1447 
1448  ROSE_DLL_API SgFunctionDefinition* getEnclosingFunctionDefinition(SgNode* astNode, const bool includingSelf=false);
1449 
1452 
1455 
1457  ROSE_DLL_API SgScopeStatement* findEnclosingLoop(SgStatement* s, const std::string& fortranLabel = "", bool stopOnSwitches = false);
1458 
1460  ROSE_DLL_API SgFunctionDeclaration * getEnclosingFunctionDeclaration (SgNode * astNode, const bool includingSelf=false);
1461  //roseSupport/utility_functions.h
1464 
1467 
1469  ROSE_DLL_API SgClassDefinition* getEnclosingClassDefinition(SgNode* astnode, const bool includingSelf=false);
1470 
1471 // TODO
1472 #if 0
1473  SgNode * getEnclosingSgNode(SgNode* source,VariantT, SgNode* endNode=NULL);
1474  std::vector<SgNode *> getAllEnclosingSgNode(SgNode* source,VariantT, SgNode* endNode=NULL);
1475  SgVariableDeclaration* findVariableDeclaratin( const string& varname)
1476 
1477  SgClassDeclaration* getEnclosingClassDeclaration( const SgNode* astNode);
1478 
1479  // e.g. for some expression, find its parent statement
1480  SgStatement* getEnclosingStatement(const SgNode* astNode);
1481 
1482  SgSwitchStatement* getEnclosingSwitch(SgStatement* s);
1483  SgModuleStatement* getEnclosingModuleStatement( const SgNode* astNode);
1484 
1485  // used to build a variable reference for compiler generated code in current scope
1486  SgSymbol * findReachingDefinition (SgScopeStatement* startScope, SgName &name);
1487 #endif
1488 
1489 
1490 //------------------------------------------------------------------------
1492 
1495  // Liao, 1/9/2008
1500 
1505 
1507  ROSE_DLL_API SgStatement* getFirstStatement(SgScopeStatement *scope,bool includingCompilerGenerated=false);
1510 
1513 
1516 #if 0 //TODO
1517  // preorder traversal from current SgNode till find next SgNode of type V_SgXXX
1518  SgNode* getNextSgNode( const SgNode* currentNode, VariantT=V_SgNode);
1519 #endif
1520 
1521 
1522 //------------------------------------------------------------------------
1524 
1527  ROSE_DLL_API bool isEqualToIntConst(SgExpression* e, int value);
1529 
1531 
1535 
1538 
1540 
1541 //------------------------------------------------------------------------
1543 
1549 // DQ (2/24/2009): Simple function to delete an AST subtree (used in outlining).
1551 ROSE_DLL_API void deleteAST(SgNode* node);
1552 
1555 
1556 // DQ (2/25/2009): Added new function to support outliner.
1558 ROSE_DLL_API void moveStatementsBetweenBlocks ( SgBasicBlock* sourceBlock, SgBasicBlock* targetBlock );
1559 
1560 
1562 ROSE_DLL_API void appendStatement(SgStatement *stmt, SgScopeStatement* scope=NULL);
1563 
1565 ROSE_DLL_API void appendStatementList(const std::vector<SgStatement*>& stmt, SgScopeStatement* scope=NULL);
1566 
1567 // DQ (2/6/2009): Added function to support outlining into separate file.
1569 ROSE_DLL_API void appendStatementWithDependentDeclaration( SgDeclarationStatement* decl, SgGlobal* scope, SgStatement* original_statement, bool excludeHeaderFiles );
1570 
1574 
1577 ROSE_DLL_API void prependStatementList(const std::vector<SgStatement*>& stmt, SgScopeStatement* scope=NULL);
1578 
1583 
1585 ROSE_DLL_API void insertStatement(SgStatement *targetStmt, SgStatement* newStmt, bool insertBefore= true, bool autoMovePreprocessingInfo = true);
1586 
1588 //target's scope
1589 ROSE_DLL_API void insertStatementList(SgStatement *targetStmt, const std::vector<SgStatement*>& newStmts, bool insertBefore= true);
1590 
1592 ROSE_DLL_API void insertStatementBefore(SgStatement *targetStmt, SgStatement* newStmt, bool autoMovePreprocessingInfo = true);
1593 
1595 ROSE_DLL_API void insertStatementListBefore(SgStatement *targetStmt, const std::vector<SgStatement*>& newStmts);
1596 
1598 ROSE_DLL_API void insertStatementAfter(SgStatement *targetStmt, SgStatement* newStmt, bool autoMovePreprocessingInfo = true);
1599 
1601 ROSE_DLL_API void insertStatementListAfter(SgStatement *targetStmt, const std::vector<SgStatement*>& newStmt);
1602 
1605 
1607 ROSE_DLL_API void insertStatementAfterLastDeclaration(std::vector<SgStatement*> stmt_list, SgScopeStatement* scope);
1608 
1610 // then the statement is inserted at the end of the scope.
1612  bool movePreprocessingInfo=true);
1613 
1615 //then the new statements are inserted at the end of the scope.
1616 ROSE_DLL_API void insertStatementListBeforeFirstNonDeclaration(const std::vector<SgStatement*> &newStmts,
1617  SgScopeStatement *scope);
1618 
1620 ROSE_DLL_API void removeStatement(SgStatement* stmt, bool autoRelocatePreprocessingInfo = true);
1621 
1623 ROSE_DLL_API void deepDelete(SgNode* root);
1624 
1626 ROSE_DLL_API void replaceStatement(SgStatement* oldStmt, SgStatement* newStmt, bool movePreprocessinInfo = false);
1627 
1629 ROSE_DLL_API SgNode* replaceWithPattern (SgNode * anchor, SgNode* new_pattern);
1630 
1641 std::pair<SgVariableDeclaration*, SgExpression* > createTempVariableForExpression(SgExpression* expression,
1642  SgScopeStatement* scope, bool initializeInDeclaration, SgAssignOp** reEvaluate = NULL);
1643 
1644 /* This function creates a temporary variable for a given expression in the given scope
1645  This is different from SageInterface::createTempVariableForExpression in that it does not
1646  try to be smart to create pointers to reference types and so on. The tempt is initialized to expression.
1647  The caller is responsible for setting the parent of SgVariableDeclaration since buildVariableDeclaration
1648  may not set_parent() when the scope stack is empty. See programTransformation/extractFunctionArgumentsNormalization/ExtractFunctionArguments.C for sample usage.
1649  @param expression Expression which will be replaced by a variable
1650  @param scope scope in which the temporary variable will be generated
1651 */
1652 
1653 std::pair<SgVariableDeclaration*, SgExpression*> createTempVariableAndReferenceForExpression
1654  (SgExpression* expression, SgScopeStatement* scope);
1655 
1657 
1664 
1667 
1669 ROSE_DLL_API void appendExpressionList(SgExprListExp *, const std::vector<SgExpression*>&);
1670 
1672 // void setParameterList(SgFunctionDeclaration *func,SgFunctionParameterList *paralist);
1673 template <class actualFunction>
1674 ROSE_DLL_API void setParameterList(actualFunction *func,SgFunctionParameterList *paralist);
1675 
1676 # if 1
1677  // DQ (11/25/2011): Moved to the header file so that it could be seen as a template function.
1678 
1679  // TODO consider the difference between C++ and Fortran
1680  // fixup the scope of arguments,no symbols for nondefining function declaration's arguments
1681 template <class actualFunction>
1682 void
1683 // SageInterface::setParameterList(SgFunctionDeclaration * func,SgFunctionParameterList * paralist)
1684 setParameterList(actualFunction* func, SgFunctionParameterList* paralist)
1685  {
1686  // DQ (11/25/2011): Modified this to be a templated function so that we can handle both
1687  // SgFunctionDeclaration and SgTemplateFunctionDeclaration (and their associated member
1688  // function derived classes).
1689 
1690  ROSE_ASSERT(func != NULL);
1691  ROSE_ASSERT(paralist != NULL);
1692 
1693 #if 0
1694  // At this point we don't have cerr and endl defined, so comment this code out.
1695  // Warn to users if a paralist is being shared
1696  if (paralist->get_parent() !=NULL)
1697  {
1698  cerr << "Waring! Setting a used SgFunctionParameterList to function: "
1699  << (func->get_name()).getString()<<endl
1700  << " Sharing parameter lists can corrupt symbol tables!"<<endl
1701  << " Please use deepCopy() to get an exclusive parameter list for each function declaration!"<<endl;
1702  // ROSE_ASSERT(false);
1703  }
1704 #endif
1705 
1706  // Liao,2/5/2008 constructor of SgFunctionDeclaration will automatically generate SgFunctionParameterList, so be cautious when set new paralist!!
1707  if (func->get_parameterList() != NULL)
1708  {
1709  if (func->get_parameterList() != paralist)
1710  {
1711  delete func->get_parameterList();
1712  }
1713  }
1714 
1715  func->set_parameterList(paralist);
1716  paralist->set_parent(func);
1717 
1718  // DQ (5/15/2012): Need to set the declptr in each SgInitializedName IR node.
1719  // This is needed to support the AST Copy mechanism (at least). The files: test2005_150.C,
1720  // test2012_81.C and testcode2012_82.C demonstrate this problem.
1721  SgInitializedNamePtrList & args = paralist->get_args();
1722  for (SgInitializedNamePtrList::iterator i = args.begin(); i != args.end(); i++)
1723  {
1724  (*i)->set_declptr(func);
1725  }
1726  }
1727 #endif
1728 
1730 ROSE_DLL_API void setPragma(SgPragmaDeclaration* decl, SgPragma *pragma);
1731 
1733 ROSE_DLL_API void replaceExpression(SgExpression* oldExp, SgExpression* newExp, bool keepOldExp=false);
1734 
1742 
1744 ROSE_DLL_API void setOperand(SgExpression* target, SgExpression* operand);
1745 
1748 
1751 
1754 
1755 // DQ (1/25/2010): Added support for directories
1757 ROSE_DLL_API void moveToSubdirectory ( std::string directoryName, SgFile* file );
1758 
1760 ROSE_DLL_API SgStatement* findSurroundingStatementFromSameFile(SgStatement* targetStmt, bool & surroundingStatementPreceedsTargetStatement);
1761 
1763 ROSE_DLL_API void moveCommentsToNewStatement(SgStatement* sourceStatement, const std::vector<int> & indexList, SgStatement* targetStatement, bool surroundingStatementPreceedsTargetStatement);
1764 
1766 //------------------------------------------------------------------------
1768 
1775 
1782 
1784 
1789 
1791 void fixStructDeclaration(SgClassDeclaration* structDecl, SgScopeStatement* scope);
1794 
1797 
1798 
1800 void fixLabelStatement(SgLabelStatement* label_stmt, SgScopeStatement* scope);
1801 
1803 void setFortranNumericLabel(SgStatement* stmt, int label_value);
1804 
1807 
1810 
1813 
1815 void fixStatement(SgStatement* stmt, SgScopeStatement* scope);
1817 
1819 
1825 
1826 //------------------------------------------------------------------------
1828 
1832 ROSE_DLL_API bool
1834 collectReadWriteRefs(SgStatement* stmt, std::vector<SgNode*>& readRefs, std::vector<SgNode*>& writeRefs, bool useCachedDefUse=false);
1835 
1837 ROSE_DLL_API bool collectReadWriteVariables(SgStatement* stmt, std::set<SgInitializedName*>& readVars, std::set<SgInitializedName*>& writeVars);
1838 
1840 ROSE_DLL_API void collectReadOnlyVariables(SgStatement* stmt, std::set<SgInitializedName*>& readOnlyVars);
1841 
1843 ROSE_DLL_API void collectReadOnlySymbols(SgStatement* stmt, std::set<SgVariableSymbol*>& readOnlySymbols);
1844 
1847 
1849 ROSE_DLL_API void collectUseByAddressVariableRefs (const SgStatement* s, std::set<SgVarRefExp* >& varSetB);
1850 
1851 #ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
1854 
1856 ROSE_DLL_API void getLiveVariables(LivenessAnalysis * liv, SgForStatement* loop, std::set<SgInitializedName*>& liveIns, std::set<SgInitializedName*> & liveOuts);
1857 #endif
1858 
1860 ROSE_DLL_API void ReductionRecognition(SgForStatement* loop, std::set< std::pair <SgInitializedName*, VariantT> > & results);
1861 
1863 
1865 
1867 
1870 
1873 
1876 
1879 
1881 
1888  ROSE_DLL_API SgAssignInitializer* splitExpression(SgExpression* from, std::string newName = "");
1889 
1892 
1895 
1898 
1901 
1904 
1907 
1910 
1913 
1916 
1919 
1922 
1925 
1928 
1931 
1932 
1935 bool isBodyStatement (SgStatement* s);
1936 
1938 void changeAllBodiesToBlocks(SgNode* top);
1939 
1942 
1945 
1946 #if 0
1947 
1950 SgLocatedNode* ensureBasicBlockAsParent(SgStatement* s);
1951 #endif
1952 
1955 unsigned long long getIntegerConstantValue(SgValueExp* expr);
1956 
1958 std::vector<SgDeclarationStatement*> getDependentDeclarations (SgStatement* stmt );
1959 
1960 
1963 
1965 SgCommaOpExp *insertAfterUsingCommaOp (SgExpression* new_exp, SgExpression* anchor_exp, SgStatement** temp_decl = NULL, SgVarRefExp** temp_ref = NULL);
1966 
1967 
1997 std::pair<SgStatement*, SgInitializedName*>
1998 wrapFunction(SgFunctionDeclaration& definingDeclaration, SgName newName);
1999 
2005 template <class NameGen>
2006 std::pair<SgStatement*, SgInitializedName*>
2007 wrapFunction(SgFunctionDeclaration& definingDeclaration, NameGen nameGen)
2008 {
2009  return wrapFunction(definingDeclaration, nameGen(definingDeclaration.get_name()));
2010 }
2011 
2015 
2016 
2018 
2019 // DQ (6/7/2012): Unclear where this function should go...
2020  bool hasTemplateSyntax( const SgName & name );
2021 
2022 
2023 #if 0
2024 
2025 //------------------------AST dump, stringify-----------------------------
2026 //------------------------------------------------------------------------
2027  std::string buildOperatorString ( SgNode* astNode ); //transformationSupport.h
2028 
2029  // do we need these?
2030  std::string dump_node(const SgNode* astNode);
2031  std::string dump_tree(const SgNode* astNode);
2032 
2033  // or a friendly version of unparseToString(), as a memeber function
2034  std::string SgNode::toString(bool asSubTree=true); // dump node or subtree
2035 
2036 //----------------------------AST comparison------------------------------
2037 //------------------------------------------------------------------------
2038 // How to get generic functions for comparison?
2039  bool isNodeEqual(SgNode* node1, SgNode* node2); //?
2040  bool isTreeEqual(SgNode* tree1, SgNode* tree2);
2041 
2043  bool expressionTreeEqual(SgExpression*, SgExpression*);
2045  bool expressionTreeEqualStar(const SgExpressionPtrList&,
2046  const SgExpressionPtrList&);
2047 
2048 //----------------------AST verfication/repair----------------------------
2049 //------------------------------------------------------------------------
2050 // sanity check of AST subtree, any suggestions?
2051 // TODO
2052  verifySgNode(SgNode* node, bool subTree=true);
2053  //src/midend/astDiagnostics/AstConsistencyTests.h
2054  // AstTests::runAllTests(SgProject * )
2055 
2056  //src/midend/astUtil/astInterface/AstInterface.h.C
2057  //FixSgProject(SgProject &project)
2058  //FixSgTree(SgNode* r)
2059 
2060  //src/frontend/SageIII/astPostProcessing
2061  //AstPostProcessing(SgNode * node)
2062 
2063 //--------------------------AST modification------------------------------
2064 //------------------------------------------------------------------------
2065 // any operations changing AST tree, including
2066 // insert, copy, delete(remove), replace
2067 
2068  // insert before or after some point, argument list is consistent with LowLevelRewrite
2069  void insertAst(SgNode* targetPosition, SgNode* newNode, bool insertBefore=true);
2070 
2071  // previous examples
2072  //void myStatementInsert(SgStatement* target,...)
2073  // void AstInterfaceBase::InsertStmt(AstNodePtr const & orig, AstNodePtr const &n, bool insertbefore, bool extractfromBasicBlock)
2074 
2075  // copy
2076  // copy children of one basic block to another basic block
2077  //void appendStatementCopy (const SgBasicBlock* a, SgBasicBlock* b);
2078  void copyStatements (const SgBasicBlock* src, SgBasicBlock* dst);
2079 
2080  // delete (remove) a node or a whole subtree
2081  void removeSgNode(SgNode* targetNode); // need this?
2082  void removeSgNodeTree(SgNode* subtree); // need this?
2083 
2084  void removeStatement( SgStatement* targetStmt);
2085 
2086  //Move = delete + insert
2087  void moveAst (SgNode* src, SgNode* target); // need this?
2088  // similar to
2089  void moveStatements (SgBasicBlock* src, SgBasicBlock* target);
2090 
2091  // replace= delete old + insert new (via building or copying)
2092 
2093 // DQ (1/25/2010): This does not appear to exist as a definition anywhere in ROSE.
2094 // void replaceAst(SgNode* oldNode, SgNode* newNode);
2095 
2096  //void replaceChild(SgNode* parent, SgNode* from, SgNode* to);
2097  //bool AstInterface::ReplaceAst( const AstNodePtr& orig, const AstNodePtr& n)
2098 
2099 //--------------------------AST transformations---------------------------
2100 //------------------------------------------------------------------------
2101 // Advanced AST modifications through basic AST modifications
2102 // Might not be included in AST utitlity list, but listed here for the record.
2103 
2104  // extract statements/content from a scope
2105  void flattenBlocks(SgNode* n);
2106 
2107  //src/midend/astInlining/inlinerSupport.h
2108  void renameVariables(SgNode* n);
2109  void renameLabels(SgNode* n, SgFunctionDefinition* enclosingFunctionDefinition);
2110 
2111  void simpleCopyAndConstantPropagation(SgNode* top);
2112  void changeAllMembersToPublic(SgNode* n);
2113 
2114  void removeVariableDeclaration(SgInitializedName* initname);
2115 
2117  SgAssignOp* convertInitializerIntoAssignment(SgAssignInitializer* init);
2118 
2123  void pushTestIntoBody(LoopStatement* loopStmt);
2124 
2125  //programTransformation/finiteDifferencing/finiteDifferencing.h
2127  void moveForDeclaredVariables(SgNode* root);
2128 
2129 //------------------------ Is/Has functions ------------------------------
2130 //------------------------------------------------------------------------
2131 // misc. boolean functions
2132 // some of them could moved to SgXXX class as a member function
2133 
2134  bool isOverloaded (SgFunctionDeclaration * functionDeclaration);
2135 
2136  bool isSwitchCond (const SgStatement* s);
2137  bool isIfCond (const SgStatement* s);
2138  bool isWhileCond (const SgStatement* s);
2139  bool isStdNamespace (const SgScopeStatement* scope);
2140  bool isTemplateInst (const SgDeclarationStatement* decl);
2141 
2142 
2143  bool isCtor (const SgFunctionDeclaration* func);
2144  bool isDtor (const SgFunctionDeclaration* func);
2145 
2146  // src/midend/astInlining/typeTraits.h
2147  bool hasTrivialDestructor(SgType* t);
2150 
2151  // generic ones, or move to the SgXXX class as a member function
2152 
2153  bool isConst(SgNode* node); // const type, variable, function, etc.
2154  // .... and more
2155 
2156  bool isConstType (const SgType* type);
2157  bool isConstFunction (const SgFunctionDeclaration* decl);
2158 
2159 
2160  bool isMemberVariable(const SgInitializedName & var);
2161  //bool isMemberVariable(const SgNode& in);
2162 
2163  bool isPrototypeInScope (SgScopeStatement * scope,
2164  SgFunctionDeclaration * functionDeclaration,
2165  SgDeclarationStatement * startingAtDeclaration);
2166 
2167  bool MayRedefined(SgExpression* expr, SgNode* root);
2168  // bool isPotentiallyModified(SgExpression* expr, SgNode* root); // inlinderSupport.h
2169  bool hasAddressTaken(SgExpression* expr, SgNode* root);
2170 
2171  //src/midend/astInlining/inlinerSupport.C
2172  // can also classified as topdown search
2173  bool containsVariableReference(SgNode* root, SgInitializedName* var);
2174 
2175  bool isDeclarationOf(SgVariableDeclaration* decl, SgInitializedName* var);
2176  bool isPotentiallyModifiedDuringLifeOf(SgBasicBlock* sc,
2177  SgInitializedName* toCheck,
2178  SgInitializedName* lifetime)
2179  //src/midend/programTransformation/partialRedundancyElimination/pre.h
2180  bool anyOfListPotentiallyModifiedIn(const std::vector<SgVariableSymbol*>& syms, SgNode* n);
2181 
2182 //------------------------ loop handling ---------------------------------
2183 //------------------------------------------------------------------------
2184  //get and set loop control expressions
2185  // 0: init expr, 1: condition expr, 2: stride expr
2186 
2187  SgExpression* getForLoopTripleValues(int valuetype,SgForStatement* forstmt );
2188  int setForLoopTripleValues(int valuetype,SgForStatement* forstmt, SgExpression* exp);
2189 
2190  bool isLoopIndexVarRef(SgForStatement* forstmt, SgVarRefExp *varref);
2191  SgInitializedName * getLoopIndexVar(SgForStatement* forstmt);
2192 
2193 //------------------------expressions-------------------------------------
2194 //------------------------------------------------------------------------
2195  //src/midend/programTransformation/partialRedundancyElimination/pre.h
2196  int countComputationsOfExpressionIn(SgExpression* expr, SgNode* root);
2197 
2198  //src/midend/astInlining/replaceExpressionWithStatement.h
2199  void replaceAssignmentStmtWithStatement(SgExprStatement* from, StatementGenerator* to);
2200 
2202  StatementGenerator* to);
2203  SgExpression* getRootOfExpression(SgExpression* n);
2204 
2205 //--------------------------preprocessing info. -------------------------
2206 //------------------------------------------------------------------------
2208  void cutPreprocInfo (SgBasicBlock* b,
2210  AttachedPreprocessingInfoType& save_buf);
2212  void pastePreprocInfoFront (AttachedPreprocessingInfoType& save_buf,
2213  SgStatement* s);
2215  void pastePreprocInfoBack (AttachedPreprocessingInfoType& save_buf,
2216  SgStatement* s);
2217 
2223  // a generic one for all
2225  void moveBeforePreprocInfo (SgStatement* src, SgStatement* dest);
2226  void moveInsidePreprocInfo (SgBasicBlock* src, SgBasicBlock* dest);
2227  void moveAfterPreprocInfo (SgStatement* src, SgStatement* dest);
2228 
2229 //--------------------------------operator--------------------------------
2230 //------------------------------------------------------------------------
2231  from transformationSupport.h, not sure if they should be included here
2232  /* return enum code for SAGE operators */
2233  operatorCodeType classifyOverloadedOperator(); // transformationSupport.h
2234 
2240  std::string stringifyOperator (std::string name);
2241 
2242 //--------------------------------macro ----------------------------------
2243 //------------------------------------------------------------------------
2244  std::string buildMacro ( std::string s ); //transformationSupport.h
2245 
2246 //--------------------------------access functions---------------------------
2247 //----------------------------------get/set sth.-----------------------------
2248 // several categories:
2249 * get/set a direct child/grandchild node or fields
2250 * get/set a property flag value
2251 * get a descendent child node using preorder searching
2252 * get an ancestor node using bottomup/reverse searching
2253 
2254  // SgName or string?
2255  std::string getFunctionName (SgFunctionCallExp* functionCallExp);
2256  std::string getFunctionTypeName ( SgFunctionCallExp* functionCallExpression );
2257 
2258  // do we need them anymore? or existing member functions are enought?
2259  // a generic one:
2260  std::string get_name (const SgNode* node);
2261  std::string get_name (const SgDeclarationStatement * declaration);
2262 
2263  // get/set some property: should moved to SgXXX as an inherent memeber function?
2264  // access modifier
2265  void setExtern (SgFunctionDeclartion*)
2266  void clearExtern()
2267 
2268  // similarly for other declarations and other properties
2270  void setPublic()
2271  void setPrivate()
2272 
2273 #endif
2274 
2275 // DQ (1/23/2013): Added support for generated a set of source sequence entries.
2276  std::set<unsigned int> collectSourceSequenceNumbers( SgNode* astNode );
2277 
2278 //--------------------------------Type Traits (C++)---------------------------
2279  bool HasNoThrowAssign(const SgType * const inputType);
2280  bool HasNoThrowCopy(const SgType * const inputType);
2281  bool HasNoThrowConstructor(const SgType * const inputType);
2282  bool HasTrivialAssign(const SgType * const inputType);
2283  bool HasTrivialCopy(const SgType * const inputType);
2284  bool HasTrivialConstructor(const SgType * const inputType);
2285  bool HasTrivialDestructor(const SgType * const inputType);
2286  bool HasVirtualDestructor(const SgType * const inputType);
2287  bool IsBaseOf(const SgType * const inputBaseType, const SgType * const inputDerivedType);
2288  bool IsAbstract(const SgType * const inputType);
2289  bool IsClass(const SgType * const inputType);
2290  bool IsEmpty(const SgType * const inputType);
2291  bool IsEnum(const SgType * const inputType);
2292  bool IsPod(const SgType * const inputType);
2293  bool IsPolymorphic(const SgType * const inputType);
2294  bool IsStandardLayout(const SgType * const inputType);
2295  bool IsLiteralType(const SgType * const inputType);
2296  bool IsTrivial(const SgType * const inputType);
2297  bool IsUnion(const SgType * const inputType);
2298  SgType * UnderlyingType(SgType *type);
2299 
2300 // DQ (3/2/2014): Added a new interface function (used in the snippet insertion support).
2302 
2303 // DQ (3/4/2014): Added support for testing two trees for equivalents using the AST iterators.
2304  bool isStructurallyEquivalentAST( SgNode* tree1, SgNode* tree2 );
2305 
2306 //--------------------------------Java interface functions ---------------------
2307 //#ifdef ROSE_BUILD_JAVA_LANGUAGE_SUPPORT
2308  std::string getTempDirectory(SgProject *project);
2309  void destroyTempDirectory(std::string);
2310  SgFile *processFile(SgProject *, std::string, bool unparse = false);
2311  std::string preprocessPackage(SgProject *, std::string);
2312  std::string preprocessImport(SgProject *, std::string);
2313  SgFile* preprocessCompilationUnit(SgProject *, std::string, std::string, bool unparse = true);
2315  SgClassDefinition *findOrInsertJavaPackage(SgProject *, std::string, bool create_directory = false);
2316  SgClassDeclaration *findOrImportJavaClass(SgProject *, SgClassDefinition *package_definition, std::string);
2317  SgClassDeclaration *findOrImportJavaClass(SgProject *, std::string, std::string);
2321 //#endif // ROSE_BUILD_JAVA_LANGUAGE_SUPPORT
2322 
2323 }// end of namespace
2324 
2325 #endif