00001 #ifndef ROSE_SAGE_INTERFACE
00002 #define ROSE_SAGE_INTERFACE
00003
00004 #include "sage3basic.hhh"
00005 #include <stdint.h>
00006 #include <utility>
00007
00008 #if 0 // FMZ(07/07/2010): the argument "nextErrorCode" should be call-by-reference
00009 SgFile* determineFileType ( std::vector<std::string> argv, int nextErrorCode, SgProject* project );
00010 #else
00011 SgFile* determineFileType ( std::vector<std::string> argv, int& nextErrorCode, SgProject* project );
00012 #endif
00013
00014 #ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
00015 #include "rewrite.h"
00016 #endif
00017
00018
00019 #include "astUnparseAttribute.h"
00020 #include <set>
00021
00022 #ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
00023 #include "LivenessAnalysis.h"
00024 #include "abstract_handle.h"
00025 #include "ClassHierarchyGraph.h"
00026 #endif
00027
00028
00030 std::string getVariantName (VariantT v);
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00052 #define TRANS_FILE Sg_File_Info::generateDefaultFileInfoForTransformationNode()
00053
00054
00084 namespace SageInterface
00085 {
00087 extern int gensym_counter;
00088
00089
00090 SgAsmInterpretation* getMainInterpretation(SgAsmGenericFile* file);
00091
00093 uint64_t getAsmConstant(SgAsmValueExpression* e);
00094
00096 int64_t getAsmSignedConstant(SgAsmValueExpression *e);
00097
00099 void addMessageStatement( SgStatement* stmt, std::string message );
00100
00102 class UniqueNameAttribute : public AstAttribute
00103 {
00104 private:
00105 std::string name;
00106 public:
00107 UniqueNameAttribute(std::string n="") {name =n; };
00108 void set_name (std::string n) {name = n;};
00109 std::string get_name () {return name;};
00110 };
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 #if 0
00121 inline size_t hash_value(SgNode* t) {return (size_t)t;}
00122 #endif
00123
00124 struct hash_nodeptr
00125 {
00126
00127
00128 #if 0
00129
00130 #endif
00131 public:
00132 size_t operator()(SgNode* node) const
00133 {
00134
00135
00136 #if 0
00137 return (size_t) hash_value(node);
00138 #else
00139 return (size_t) node;
00140 #endif
00141 }
00142 };
00143
00144 void supplementReplacementSymbolMap ( rose_hash::unordered_map<SgNode*, SgNode*, hash_nodeptr> & inputReplacementMap );
00145
00146
00148
00151
00152
00153 SgVariableSymbol *lookupVariableSymbolInParentScopes (const SgName & name,
00154 SgScopeStatement *currentScope=NULL);
00156 SgSymbol *lookupSymbolInParentScopes (const SgName & name,
00157 SgScopeStatement *currentScope=NULL);
00158
00159
00161 SgFunctionSymbol *lookupFunctionSymbolInParentScopes (const SgName & functionName,
00162 SgScopeStatement *currentScope=NULL);
00163
00164
00166 SgFunctionSymbol *lookupFunctionSymbolInParentScopes (const SgName & functionName,
00167 const SgType* t,
00168 SgScopeStatement *currentScope=NULL);
00169
00170
00171 SgClassSymbol* lookupClassSymbolInParentScopes (const SgName & name, SgScopeStatement *currentScope = NULL);
00172 SgTypedefSymbol* lookupTypedefSymbolInParentScopes (const SgName & name, SgScopeStatement *currentScope = NULL);
00173 SgTemplateSymbol* lookupTemplateSymbolInParentScopes (const SgName & name, SgScopeStatement *currentScope = NULL);
00174 SgEnumSymbol* lookupEnumSymbolInParentScopes (const SgName & name, SgScopeStatement *currentScope = NULL);
00175 SgNamespaceSymbol* lookupNamespaceSymbolInParentScopes(const SgName & name, SgScopeStatement *currentScope = NULL);
00176
00177
00178
00179
00188
00189
00190 int set_name (SgInitializedName * initializedNameNode, SgName new_name);
00191
00194 void outputGlobalFunctionTypeSymbolTable ();
00195
00196
00201 void outputLocalSymbolTables (SgNode * node);
00202
00203 class OutputLocalSymbolTables:public AstSimpleProcessing
00204 {
00205 public:
00206 void visit (SgNode * node);
00207 };
00213
00214 void rebuildSymbolTable (SgScopeStatement * scope);
00215
00218 void clearUnusedVariableSymbols ();
00219
00220
00222 void fixupReferencesToSymbols( const SgScopeStatement* this_scope, SgScopeStatement* copy_scope, SgCopyHelp & help );
00223
00225
00226
00228
00235
00236 std::string get_name (const SgNode * node);
00237
00242
00243 std::string get_name (const SgStatement * stmt);
00244
00249 std::string get_name (const SgExpression * expr);
00250
00255
00256 std::string get_name (const SgDeclarationStatement * declaration);
00257
00262
00263 std::string get_name (const SgScopeStatement * scope);
00264
00269
00270 std::string get_name (const SgSymbol * symbol);
00271
00276 std::string get_name (const SgType * type);
00277
00278
00281 std::string get_name (const SgSupport * node);
00282
00283
00286 std::string get_name (const SgLocatedNodeSupport * node);
00287
00290 std::string get_name ( const SgC_PreprocessorDirectiveStatement* directive );
00291
00294 std::string get_name ( const SgToken* token );
00295
00297
00298
00300
00305
00306 SgMemberFunctionDeclaration *getDefaultDestructor (SgClassDeclaration *
00307 classDeclaration);
00308
00311
00312 SgMemberFunctionDeclaration *getDefaultConstructor (SgClassDeclaration *
00313 classDeclaration);
00316
00317 bool templateDefinitionIsInClass (SgTemplateInstantiationMemberFunctionDecl
00318 * memberFunctionDeclaration);
00319
00324
00325 SgTemplateInstantiationMemberFunctionDecl*
00326 buildForwardFunctionDeclaration
00327 (SgTemplateInstantiationMemberFunctionDecl * memberFunctionInstantiation);
00328
00330 bool isStructDeclaration(SgNode * node);
00331 #if 0
00332
00333
00334
00338
00339 bool isTemplateMemberFunction (SgTemplateInstantiationMemberFunctionDecl *
00340 memberFunctionDeclaration);
00341 #endif
00342
00344
00345
00347
00351
00352 bool isOmpStatement(SgNode* );
00355
00356 bool isOverloaded (SgFunctionDeclaration * functionDeclaration);
00357
00359 void annotateExpressionsWithUniqueNames (SgProject* project);
00360
00362 bool isMain (const SgNode* node);
00363
00374 std::string generateUniqueName ( const SgNode * node, bool ignoreDifferenceBetweenDefiningAndNondefiningDeclarations);
00375
00378 std::string generateUniqueVariableName(SgScopeStatement* scope, std::string baseName = "temp");
00379
00380
00381
00383 std::string declarationPositionString (const SgDeclarationStatement * declaration);
00384
00385
00387 std::string generateProjectName (const SgProject * project, bool supressSuffix = false );
00388
00391 SgFunctionDeclaration* getDeclarationOfNamedFunction(SgExpression* func);
00392
00394 SgExpression* forallMaskExpression(SgForAllStatement* stmt);
00395
00397 void addVarRefExpFromArrayDimInfo(SgNode * astNode, Rose_STL_Container<SgNode *>& NodeList_t);
00398
00399
00403 void clearMangledNameCache (SgGlobal * globalScope);
00404 void resetMangledNameCache (SgGlobal * globalScope);
00405 std::string getMangledNameFromCache (SgNode * astNode);
00406 std::string addMangledNameToCache (SgNode * astNode, const std::string & mangledName);
00407
00408 SgDeclarationStatement * getNonInstantiatonDeclarationForClass (SgTemplateInstantiationMemberFunctionDecl * memberFunctionInstantiation);
00409
00412 void setBaseTypeDefiningDeclaration(SgVariableDeclaration* var_decl, SgDeclarationStatement *base_decl);
00413
00414
00415
00417 bool declarationPreceedsDefinition (SgDeclarationStatement *nonDefiningDeclaration, SgDeclarationStatement *definingDeclaration);
00418
00419
00420
00421
00422
00423
00424 bool functionCallExpressionPreceedsDeclarationWhichAssociatesScope (SgFunctionCallExp * functionCall);
00425
00430 std::vector < SgNode * >astIntersection (SgNode * original, SgNode * copy, SgCopyHelp * help = NULL);
00431
00433 SgNode* deepCopyNode (const SgNode* subtree);
00434
00436 template <typename NodeType>
00437 NodeType* deepCopy (const NodeType* subtree) {
00438 return dynamic_cast<NodeType*>(deepCopyNode(subtree));
00439 }
00440
00442 SgExpression* copyExpression(SgExpression* e);
00443
00445 SgStatement* copyStatement(SgStatement* s);
00446
00447
00449 SgVariableSymbol* getFirstVarSym (SgVariableDeclaration* decl);
00450
00452 SgInitializedName* getFirstInitializedName (SgVariableDeclaration* decl);
00453
00455 void myRemoveStatement(SgStatement* stmt);
00456
00457 bool isConstantTrue(SgExpression* e);
00458 bool isConstantFalse(SgExpression* e);
00459
00460 bool isCallToParticularFunction(SgFunctionDeclaration* decl, SgExpression* e);
00461 bool isCallToParticularFunction(const std::string& qualifiedName, size_t arity, SgExpression* e);
00462
00464 bool isStatic(SgDeclarationStatement* stmt);
00465
00467 void setStatic(SgDeclarationStatement* stmt);
00468
00470 bool isExtern(SgDeclarationStatement* stmt);
00471
00473 void setExtern(SgDeclarationStatement* stmt);
00474
00477 class StatementGenerator {
00478 public:
00479 virtual ~StatementGenerator() {};
00480 virtual SgStatement* generate(SgExpression* where_to_write_answer) = 0;
00481 };
00482
00486 bool isAssignmentStatement(SgNode* _s, SgExpression** lhs=NULL, SgExpression** rhs=NULL, bool* readlhs=NULL);
00487
00489 SgInitializedName* convertRefToInitializedName(SgNode* current);
00490
00492 SgNode* getSgNodeFromAbstractHandleString(const std::string& input_string);
00493
00495 void dumpInfo(SgNode* node, std::string desc="");
00496
00498 std::vector<SgDeclarationStatement*>
00499 sortSgNodeListBasedOnAppearanceOrderInSource(const std::vector<SgDeclarationStatement*>& nodevec);
00500
00502
00503
00505
00509
00512 bool is_C_language ();
00513 bool is_OpenMP_language ();
00514 bool is_UPC_language ();
00516 bool is_UPC_dynamic_threads();
00517 bool is_C99_language ();
00518 bool is_Cxx_language ();
00519 bool is_Java_language ();
00520 bool is_Fortran_language ();
00521 bool is_CAF_language ();
00522 bool is_PHP_language();
00523 bool is_Python_language();
00524 bool is_Cuda_language();
00525 bool is_binary_executable();
00526 bool is_mixed_C_and_Cxx_language ();
00527 bool is_mixed_Fortran_and_C_language ();
00528 bool is_mixed_Fortran_and_Cxx_language ();
00529 bool is_mixed_Fortran_and_C_and_Cxx_language ();
00531
00532
00534
00538
00539
00545 void resetScopeNumbers (SgFunctionDefinition * functionDeclaration);
00546
00547
00548
00557 void clearScopeNumbers (SgFunctionDefinition * functionDefinition);
00558
00559
00561 SgNamespaceDefinitionStatement * enclosingNamespaceScope (SgDeclarationStatement * declaration);
00562
00563
00564 bool isPrototypeInScope (SgScopeStatement * scope,
00565 SgFunctionDeclaration * functionDeclaration,
00566 SgDeclarationStatement * startingAtDeclaration);
00567
00569 bool isAncestor(SgNode* node1, SgNode* node2);
00571
00573
00577
00578 void dumpPreprocInfo (SgLocatedNode* locatedNode);
00579
00581 PreprocessingInfo* insertHeader(const std::string& filename, PreprocessingInfo::RelativePositionType position=PreprocessingInfo::after, bool isSystemHeader=false, SgScopeStatement* scope=NULL);
00582
00584 void moveUpPreprocessingInfo (SgStatement* stmt_dst, SgStatement* stmt_src, PreprocessingInfo::RelativePositionType src_position=PreprocessingInfo::undef, PreprocessingInfo::RelativePositionType dst_position=PreprocessingInfo::undef, bool usePrepend= false);
00585
00587 void movePreprocessingInfo (SgStatement* stmt_src, SgStatement* stmt_dst, PreprocessingInfo::RelativePositionType src_position=PreprocessingInfo::undef,
00588 PreprocessingInfo::RelativePositionType dst_position=PreprocessingInfo::undef, bool usePrepend= false);
00589
00590
00592 void cutPreprocessingInfo (SgLocatedNode* src_node, PreprocessingInfo::RelativePositionType pos, AttachedPreprocessingInfoType& save_buf);
00593
00595 void pastePreprocessingInfo (SgLocatedNode* dst_node, PreprocessingInfo::RelativePositionType pos, AttachedPreprocessingInfoType& saved_buf);
00596
00598 PreprocessingInfo* attachArbitraryText(SgLocatedNode* target,
00599 const std::string & text,
00600 PreprocessingInfo::RelativePositionType position=PreprocessingInfo::before);
00601
00603 void replaceMacroCallsWithExpandedStrings(SgPragmaDeclaration* target);
00605
00606
00607
00609
00612
00613 PreprocessingInfo* attachComment(SgLocatedNode* target, const std::string & content,
00614 PreprocessingInfo::RelativePositionType position=PreprocessingInfo::before,
00615 PreprocessingInfo::DirectiveType dtype= PreprocessingInfo::CpreprocessorUnknownDeclaration);
00616
00617
00618
00619
00620
00621
00623 void addTextForUnparser ( SgNode* astNode, std::string s, AstUnparseAttribute::RelativePositionType inputlocation );
00624
00625
00626
00628 void setOneSourcePositionForTransformation(SgNode *node);
00629
00631 void setOneSourcePositionNull(SgNode *node);
00632
00634 void setSourcePositionForTransformation (SgNode * root);
00635
00637 void setSourcePositionForTransformation_memoryPool();
00638
00640 void setSourcePosition (SgLocatedNode * locatedNode);
00641
00643
00644
00645
00647
00651
00652
00653
00655 SgType* getBoolType(SgNode* n);
00656
00657
00661 bool isStrictIntegerType(SgType* t);
00663 SgType* getFirstVarType(SgVariableDeclaration* decl);
00664
00666 bool isDefaultConstructible(SgType* type);
00667
00669 bool isCopyConstructible(SgType* type);
00670
00672 bool isAssignable(SgType* type);
00673
00674 #ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
00678 bool isPureVirtualClass(SgType* type, const ClassHierarchyWrapper& classHierarchy);
00679 #endif
00680
00682 bool hasTrivialDestructor(SgType* t);
00683
00685 bool isNonconstReference(SgType* t);
00686
00688 bool isReferenceType(SgType* t);
00689
00691 bool isPointerType(SgType* t);
00692
00698 bool isPointerToNonConstType(SgType* type);
00699
00701
00702
00703
00704
00705
00706 bool isConstType(SgType* t);
00707
00709 SgType* removeConst(SgType* t);
00710
00712 bool isVolatileType(SgType* t);
00713
00715 bool isRestrictType(SgType* t);
00716
00718
00720 bool isScalarType(SgType* t);
00721
00725 bool isStrictIntegerType(SgType* t);
00726
00728 bool isStructType(SgType* t);
00729
00731 std::string mangleType(SgType* type);
00732
00734 std::string mangleScalarType(SgType* type);
00735
00737 std::string mangleModifierType(SgModifierType* type);
00738
00740 size_t getArrayElementCount(SgArrayType* t);
00741
00743 int getDimensionCount(SgType* t);
00744
00746 SgType* getArrayElementType(SgType* t);
00747
00749 SgType* getElementType(SgType* t);
00750
00752 bool isArrayReference(SgExpression* ref, SgExpression** arrayNameExp=NULL, std::vector<SgExpression*>** subscripts=NULL);
00753
00754
00756
00765 bool hasUpcSharedType(SgType* t, SgModifierType ** mod_type_out = NULL );
00766
00768
00771 bool isUpcSharedType(SgType* t, SgModifierType ** mod_type_out = NULL);
00772
00774 bool isUpcSharedModifierType (SgModifierType* mod_type);
00775
00777 bool isUpcSharedArrayType (SgArrayType* array_type);
00778
00780 bool isUpcStrictSharedModifierType(SgModifierType* mode_type);
00781
00783 size_t getUpcSharedBlockSize(SgModifierType* mod_type);
00784
00786 size_t getUpcSharedBlockSize(SgType* t);
00787
00789 bool isUpcPhaseLessSharedType (SgType* t);
00790
00792 bool isUpcPrivateToSharedType(SgType* t);
00793
00795 bool isUpcArrayWithThreads(SgArrayType* t);
00796
00798 SgType* lookupNamedTypeInParentScopes(const std::string& type_name, SgScopeStatement* scope=NULL);
00799
00801
00802
00804
00808
00817 void addStepToLoopBody(SgScopeStatement* loopStmt, SgStatement* step);
00818
00819 void moveForStatementIncrementIntoBody(SgForStatement* f);
00820 void convertForToWhile(SgForStatement* f);
00821 void convertAllForsToWhiles(SgNode* top);
00823 void changeContinuesToGotos(SgStatement* stmt, SgLabelStatement* label);
00824
00826 SgInitializedName* getLoopIndexVariable(SgNode* loop);
00827
00830 bool isLoopIndexVariable(SgInitializedName* ivar, SgNode* subtree_root);
00831
00833 SgStatement* getLoopBody(SgScopeStatement* loop);
00834
00835 void setLoopBody(SgScopeStatement* loop, SgStatement* body);
00836
00838 SgStatement* getLoopCondition(SgScopeStatement* loop);
00839
00841 void setLoopCondition(SgScopeStatement* loop, SgStatement* cond);
00842
00846 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);
00847
00849 bool isCanonicalDoLoop(SgFortranDo* loop,SgInitializedName** ivar, SgExpression** lb, SgExpression** ub, SgExpression** step, SgStatement** body, bool *hasIncrementalIterationSpace, bool* isInclusiveUpperBound);
00850
00852 void setLoopLowerBound(SgNode* loop, SgExpression* lb);
00853
00855 void setLoopUpperBound(SgNode* loop, SgExpression* ub);
00856
00858 void setLoopStride(SgNode* loop, SgExpression* stride);
00859
00860
00862 bool normalizeForLoopInitDeclaration(SgForStatement* loop);
00863
00875 bool forLoopNormalization(SgForStatement* loop);
00876
00878 bool doLoopNormalization(SgFortranDo* loop);
00879
00881 bool loopUnrolling(SgForStatement* loop, size_t unrolling_factor);
00882
00884 bool loopInterchange(SgForStatement* loop, size_t depth, size_t lexicoOrder);
00885
00887 bool loopTiling(SgForStatement* loopNest, size_t targetLevel, size_t tileSize);
00888
00890
00891
00893
00897
00898 template <typename NodeType>
00899 std::vector<NodeType*> querySubTree(SgNode* top, VariantT variant = (VariantT)NodeType::static_variant)
00900 {
00901 Rose_STL_Container<SgNode*> nodes = NodeQuery::querySubTree(top,variant);
00902 std::vector<NodeType*> result(nodes.size(), NULL);
00903 int count = 0;
00904 for (Rose_STL_Container<SgNode*>::const_iterator i = nodes.begin();
00905 i != nodes.end(); ++i, ++count) {
00906 NodeType* node = dynamic_cast<NodeType*>(*i);
00907 ROSE_ASSERT (node);
00908 result[count] = node;
00909 }
00910 return result;
00911 }
00916 std::vector < SgFile * >generateFileList ();
00917
00919 SgProject * getProject();
00920
00922 template <typename NodeType>
00923 static std::vector<NodeType*> getSgNodeListFromMemoryPool()
00924 {
00925
00926 class MyTraversal : public ROSE_VisitTraversal
00927 {
00928 public:
00929 std::vector<NodeType*> resultlist;
00930 void visit ( SgNode* node)
00931 {
00932 NodeType* result = dynamic_cast<NodeType* > (node);
00933 ROSE_ASSERT(result!= NULL);
00934 if (result!= NULL)
00935 {
00936 resultlist.push_back(result);
00937 }
00938 };
00939 virtual ~MyTraversal() {}
00940 };
00941
00942 MyTraversal my_traversal;
00943 NodeType::visitRepresentativeNode(my_traversal);
00944 return my_traversal.resultlist;
00945 }
00946
00947
00950 SgFunctionDeclaration* findMain(SgNode* currentNode);
00951
00953 SgStatement* findLastDeclarationStatement(SgScopeStatement * scope);
00954
00955
00957 std::vector<SgVariableSymbol*> getSymbolsUsedInExpression(SgExpression* expr);
00958
00960
00965 std::vector<SgBreakStmt*> findBreakStmts(SgStatement* code, const std::string& fortranLabel = "");
00966
00968
00973 std::vector<SgContinueStmt*> findContinueStmts(SgStatement* code, const std::string& fortranLabel = "");
00974 std::vector<SgGotoStatement*> findGotoStmts(SgStatement* scope, SgLabelStatement* l);
00975 std::vector<SgStatement*> getSwitchCases(SgSwitchStatement* sw);
00976
00978 template <typename T>
00979 T* findDeclarationStatement(SgNode* root, std::string name, SgScopeStatement* scope, bool isDefining)
00980 {
00981 if (!root) return 0;
00982 T* decl = dynamic_cast<T*>(root);
00983 if (decl!=NULL)
00984 {
00985 if (scope)
00986 {
00987 if ((decl->get_scope() == scope)&&
00988 (decl->search_for_symbol_from_symbol_table()->get_name()==name))
00989 return decl;
00990 }
00991 else
00992 {
00993 if(decl->search_for_symbol_from_symbol_table()->get_name()==name)
00994 return decl;
00995 }
00996 }
00997
00998 std::vector<SgNode*> children = root->get_traversalSuccessorContainer();
00999 for (std::vector<SgNode*>::const_iterator i = children.begin();
01000 i != children.end(); ++i)
01001 {
01002 T* target= findDeclarationStatement<T> (*i,name, scope, isDefining);
01003 if (target)
01004 return target;
01005 }
01006 return 0;
01007 }
01009 SgFunctionDeclaration* findFunctionDeclaration(SgNode* root, std::string name, SgScopeStatement* scope, bool isDefining);
01010
01011 #if 0 //TODO
01012
01013
01014 SgNode* getNextSgNode( const SgNode* astSourceNode, VariantT=V_SgNode, SgNode* astEndNode=NULL);
01015
01016
01017 std::vector<SgNode*> getAllNextSgNode( const SgNode* astSourceNode, VariantT=V_SgNode, SgNode* astEndNode=NULL);
01018 #endif
01019
01021
01022
01024
01027
01028
01029
01040 template <typename NodeType>
01041 NodeType* getEnclosingNode(const SgNode* astNode, const bool includingSelf=false)
01042 {
01043 if (NULL==astNode)
01044 return NULL;
01045 if ((includingSelf)&&(dynamic_cast<const NodeType*>(astNode)))
01046 return const_cast<NodeType*>(dynamic_cast<const NodeType*> (astNode));
01047
01048 SgNode* parent = astNode->get_parent();
01049 while ((parent!=NULL)&&(!dynamic_cast<const NodeType*>(parent)))
01050 parent = parent->get_parent();
01051
01052 return const_cast<NodeType*>(dynamic_cast<const NodeType*> (parent));
01053 }
01054
01056 SgScopeStatement* getScope(const SgNode* astNode);
01057
01059 SgGlobal* getGlobalScope( const SgNode* astNode);
01060
01061
01063 SgFunctionDefinition* getEnclosingProcedure(SgNode* n, const bool includingSelf=false);
01064
01065 SgFunctionDefinition* getEnclosingFunctionDefinition(SgNode* astNode, const bool includingSelf=false);
01066
01068 SgStatement* getEnclosingStatement(SgNode* n);
01069
01071 SgSwitchStatement* findEnclosingSwitch(SgStatement* s);
01072
01074 SgScopeStatement* findEnclosingLoop(SgStatement* s, const std::string& fortranLabel = "", bool stopOnSwitches = false);
01075
01077 SgFunctionDeclaration * getEnclosingFunctionDeclaration (SgNode * astNode, const bool includingSelf=false);
01078
01080 SgFile* getEnclosingFileNode (SgNode* astNode );
01081
01083 SgInitializer* getInitializerOfExpression(SgExpression* n);
01084
01086 SgClassDefinition* getEnclosingClassDefinition(SgNode* astnode, const bool includingSelf=false);
01087
01088
01089 #if 0
01090 SgNode * getEnclosingSgNode(SgNode* source,VariantT, SgNode* endNode=NULL);
01091 std::vector<SgNode *> getAllEnclosingSgNode(SgNode* source,VariantT, SgNode* endNode=NULL);
01092 SgVariableDeclaration* findVariableDeclaratin( const string& varname)
01093
01094 SgClassDeclaration* getEnclosingClassDeclaration( const SgNode* astNode);
01095
01096
01097 SgStatement* getEnclosingStatement(const SgNode* astNode);
01098
01099 SgSwitchStatement* getEnclosingSwitch(SgStatement* s);
01100 SgModuleStatement* getEnclosingModuleStatement( const SgNode* astNode);
01101
01102
01103 SgSymbol * findReachingDefinition (SgScopeStatement* startScope, SgName &name);
01104 #endif
01105
01106
01107
01109
01112
01116 SgGlobal * getFirstGlobalScope(SgProject *project);
01117
01121 SgStatement* getLastStatement(SgScopeStatement *scope);
01122
01124 SgStatement* getFirstStatement(SgScopeStatement *scope,bool includingCompilerGenerated=false);
01126 SgFunctionDeclaration* findFirstDefiningFunctionDecl(SgScopeStatement* scope);
01127
01129 SgStatement* getNextStatement(SgStatement * currentStmt);
01130
01132 SgStatement* getPreviousStatement(SgStatement * currentStmt);
01133 #if 0 //TODO
01134
01135 SgNode* getNextSgNode( const SgNode* currentNode, VariantT=V_SgNode);
01136 #endif
01137
01138
01139
01141
01144
01145 bool isEqualToIntConst(SgExpression* e, int value);
01146
01148
01151 bool isSameFunction(SgFunctionDeclaration* func1, SgFunctionDeclaration* func2);
01152
01154 bool isLastStatement(SgStatement* stmt);
01155
01157
01158
01160
01166
01168 void deleteAST(SgNode* node);
01169
01171 void deleteExpressionTreeWithOriginalExpressionSubtrees(SgNode* root);
01172
01173
01175 void moveStatementsBetweenBlocks ( SgBasicBlock* sourceBlock, SgBasicBlock* targetBlock );
01176
01177
01179 void appendStatement(SgStatement *stmt, SgScopeStatement* scope=NULL);
01180
01182 void appendStatementList(const std::vector<SgStatement*>& stmt, SgScopeStatement* scope=NULL);
01183
01184
01186 void appendStatementWithDependentDeclaration( SgDeclarationStatement* decl, SgGlobal* scope, SgStatement* original_statement, bool excludeHeaderFiles );
01187
01190 void prependStatement(SgStatement *stmt, SgScopeStatement* scope=NULL);
01191
01194 void prependStatementList(const std::vector<SgStatement*>& stmt, SgScopeStatement* scope=NULL);
01195
01199 bool hasSimpleChildrenList (SgScopeStatement* scope);
01200
01202 void insertStatement(SgStatement *targetStmt, SgStatement* newStmt, bool insertBefore= true, bool autoMovePreprocessingInfo = true);
01203
01205
01206 void insertStatementList(SgStatement *targetStmt, const std::vector<SgStatement*>& newStmts, bool insertBefore= true);
01207
01209 void insertStatementBefore(SgStatement *targetStmt, SgStatement* newStmt, bool autoMovePreprocessingInfo = true);
01210
01212 void insertStatementListBefore(SgStatement *targetStmt, const std::vector<SgStatement*>& newStmts);
01213
01215 void insertStatementAfter(SgStatement *targetStmt, SgStatement* newStmt, bool autoMovePreprocessingInfo = true);
01216
01218 void insertStatementListAfter(SgStatement *targetStmt, const std::vector<SgStatement*>& newStmt);
01219
01221 void insertStatementAfterLastDeclaration(SgStatement* stmt, SgScopeStatement* scope);
01222
01224 void insertStatementAfterLastDeclaration(std::vector<SgStatement*> stmt_list, SgScopeStatement* scope);
01225
01227 void removeStatement(SgStatement* stmt, bool autoRelocatePreprocessingInfo = true);
01228
01230 void deepDelete(SgNode* root);
01231
01233 void replaceStatement(SgStatement* oldStmt, SgStatement* newStmt, bool movePreprocessinInfo = false);
01234
01236 SgNode* replaceWithPattern (SgNode * anchor, SgNode* new_pattern);
01237
01248 std::pair<SgVariableDeclaration*, SgExpression* > createTempVariableForExpression(SgExpression* expression,
01249 SgScopeStatement* scope, bool initializeInDeclaration, SgAssignOp** reEvaluate = NULL);
01250
01252
01256 SgVariableSymbol* appendArg(SgFunctionParameterList *, SgInitializedName*);
01258 SgVariableSymbol* prependArg(SgFunctionParameterList *, SgInitializedName*);
01259
01261 void appendExpression(SgExprListExp *, SgExpression*);
01262
01264 void appendExpressionList(SgExprListExp *, const std::vector<SgExpression*>&);
01265
01267 void setParameterList(SgFunctionDeclaration *func,SgFunctionParameterList *paralist);
01268
01270 void setPragma(SgPragmaDeclaration* decl, SgPragma *pragma);
01271
01273 void replaceExpression(SgExpression* oldExp, SgExpression* newExp, bool keepOldExp=false);
01274
01276 void replaceExpressionWithStatement(SgExpression* from,
01277 SageInterface::StatementGenerator* to);
01280 void replaceSubexpressionWithStatement(SgExpression* from,
01281 SageInterface::StatementGenerator* to);
01282
01284 void setOperand(SgExpression* target, SgExpression* operand);
01285
01287 void setLhsOperand(SgExpression* target, SgExpression* lhs);
01288
01290 void setRhsOperand(SgExpression* target, SgExpression* rhs);
01291
01293 void removeAllOriginalExpressionTrees(SgNode* top);
01294
01295
01297 void moveToSubdirectory ( std::string directoryName, SgFile* file );
01298
01300 SgStatement* findSurroundingStatementFromSameFile(SgStatement* targetStmt, bool & surroundingStatementPreceedsTargetStatement);
01301
01303 void moveCommentsToNewStatement(SgStatement* sourceStatement, const std::vector<int> & indexList, SgStatement* targetStatement, bool surroundingStatementPreceedsTargetStatement);
01304
01306
01308
01315
01316
01321 int fixVariableReferences(SgNode* root);
01322
01324
01328 void fixVariableDeclaration(SgVariableDeclaration* varDecl, SgScopeStatement* scope);
01329
01331 void fixStructDeclaration(SgClassDeclaration* structDecl, SgScopeStatement* scope);
01333 void fixClassDeclaration(SgClassDeclaration* classDecl, SgScopeStatement* scope);
01334
01336 void fixNamespaceDeclaration(SgNamespaceDeclarationStatement* structDecl, SgScopeStatement* scope);
01337
01338
01340 void fixLabelStatement(SgLabelStatement* label_stmt, SgScopeStatement* scope);
01341
01343 void setFortranNumericLabel(SgStatement* stmt, int label_value);
01344
01346 int suggestNextNumericLabel(SgFunctionDefinition* func_def);
01347
01349 void fixStatement(SgStatement* stmt, SgScopeStatement* scope);
01351
01353
01358 void updateDefiningNondefiningLinks(SgFunctionDeclaration* func, SgScopeStatement* scope);
01359
01360
01362
01366
01367 bool
01368 collectReadWriteRefs(SgStatement* stmt, std::vector<SgNode*>& readRefs, std::vector<SgNode*>& writeRefs);
01369
01371 bool collectReadWriteVariables(SgStatement* stmt, std::set<SgInitializedName*>& readVars, std::set<SgInitializedName*>& writeVars);
01372
01374 void collectReadOnlyVariables(SgStatement* stmt, std::set<SgInitializedName*>& readOnlyVars);
01375
01377 void collectReadOnlySymbols(SgStatement* stmt, std::set<SgVariableSymbol*>& readOnlySymbols);
01378
01380 bool isUseByAddressVariableRef(SgVarRefExp* ref);
01381
01383 void collectUseByAddressVariableRefs (const SgStatement* s, std::set<SgVarRefExp* >& varSetB);
01384
01385 #ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
01387 LivenessAnalysis * call_liveness_analysis(SgProject* project, bool debug=false);
01388
01390 void getLiveVariables(LivenessAnalysis * liv, SgForStatement* loop, std::set<SgInitializedName*>& liveIns, std::set<SgInitializedName*> & liveOuts);
01391 #endif
01392
01394 void ReductionRecognition(SgForStatement* loop, std::set< std::pair <SgInitializedName*, VariantT> > & results);
01395
01397
01398 void constantFolding(SgNode* r);
01399
01401
01403 int instrumentEndOfFunction(SgFunctionDeclaration * func, SgStatement* s);
01404
01406 void removeJumpsToNextStatement(SgNode*);
01407
01409 void removeUnusedLabels(SgNode* top);
01410
01412 void removeConsecutiveLabels(SgNode* top);
01413
01415
01422 SgAssignInitializer* splitExpression(SgExpression* from, std::string newName = "");
01423
01425 void splitExpressionIntoBasicBlock(SgExpression* expr);
01426
01428 void removeLabeledGotos(SgNode* top);
01429
01431 void changeBreakStatementsToGotos(SgStatement* loopOrSwitch);
01432
01434 SgBasicBlock* ensureBasicBlockAsBodyOfFor(SgForStatement* fs);
01435
01437 SgBasicBlock* ensureBasicBlockAsBodyOfUpcForAll(SgUpcForAllStatement* fs);
01438
01440 SgBasicBlock* ensureBasicBlockAsBodyOfWhile(SgWhileStmt* ws);
01442 SgBasicBlock* ensureBasicBlockAsBodyOfDoWhile(SgDoWhileStmt* ws);
01444 SgBasicBlock* ensureBasicBlockAsBodyOfSwitch(SgSwitchStatement* ws);
01446 SgBasicBlock* ensureBasicBlockAsTrueBodyOfIf(SgIfStmt* ifs);
01448 SgBasicBlock* ensureBasicBlockAsFalseBodyOfIf(SgIfStmt* ifs);
01449 SgBasicBlock* ensureBasicBlockAsBodyOfCatch(SgCatchOptionStmt* cos);
01451 SgBasicBlock* ensureBasicBlockAsBodyOfOmpBodyStmt(SgOmpBodyStatement* ompbodyStmt);
01455 SgLocatedNode* ensureBasicBlockAsParent(SgStatement* s);
01456
01459 void changeAllLoopBodiesToBlocks(SgNode* top);
01460
01463 unsigned long long getIntegerConstantValue(SgValueExp* expr);
01464
01466 std::vector<SgDeclarationStatement*> getDependentDeclarations (SgStatement* stmt );
01467
01468
01470 SgCommaOpExp *insertBeforeUsingCommaOp (SgExpression* new_exp, SgExpression* anchor_exp);
01471
01473 SgCommaOpExp *insertAfterUsingCommaOp (SgExpression* new_exp, SgExpression* anchor_exp, SgStatement** temp_decl = NULL, SgVarRefExp** temp_ref = NULL);
01474
01475
01477
01478
01479 #if 0
01480
01481
01482
01483 std::string buildOperatorString ( SgNode* astNode );
01484
01485
01486 std::string dump_node(const SgNode* astNode);
01487 std::string dump_tree(const SgNode* astNode);
01488
01489
01490 std::string SgNode::toString(bool asSubTree=true);
01491
01492
01493
01494
01495 bool isNodeEqual(SgNode* node1, SgNode* node2);
01496 bool isTreeEqual(SgNode* tree1, SgNode* tree2);
01497
01499 bool expressionTreeEqual(SgExpression*, SgExpression*);
01501 bool expressionTreeEqualStar(const SgExpressionPtrList&,
01502 const SgExpressionPtrList&);
01503
01504
01505
01506
01507
01508 verifySgNode(SgNode* node, bool subTree=true);
01509
01510
01511
01512
01513
01514
01515
01516
01517
01518
01519
01520
01521
01522
01523
01524
01525 void insertAst(SgNode* targetPosition, SgNode* newNode, bool insertBefore=true);
01526
01527
01528
01529
01530
01531
01532
01533
01534 void copyStatements (const SgBasicBlock* src, SgBasicBlock* dst);
01535
01536
01537 void removeSgNode(SgNode* targetNode);
01538 void removeSgNodeTree(SgNode* subtree);
01539
01540 void removeStatement( SgStatement* targetStmt);
01541
01542
01543 void moveAst (SgNode* src, SgNode* target);
01544
01545 void moveStatements (SgBasicBlock* src, SgBasicBlock* target);
01546
01547
01548
01549
01550
01551
01552
01553
01554
01555
01556
01557
01558
01559
01560
01561 void flattenBlocks(SgNode* n);
01562
01563
01564 void renameVariables(SgNode* n);
01565 void renameLabels(SgNode* n, SgFunctionDefinition* enclosingFunctionDefinition);
01566
01567 void simpleCopyAndConstantPropagation(SgNode* top);
01568 void changeAllMembersToPublic(SgNode* n);
01569
01570 void removeVariableDeclaration(SgInitializedName* initname);
01571
01573 SgAssignOp* convertInitializerIntoAssignment(SgAssignInitializer* init);
01574
01579 void pushTestIntoBody(LoopStatement* loopStmt);
01580
01581
01583 void moveForDeclaredVariables(SgNode* root);
01584
01585
01586
01587
01588
01589
01590 bool isOverloaded (SgFunctionDeclaration * functionDeclaration);
01591
01592 bool isSwitchCond (const SgStatement* s);
01593 bool isIfCond (const SgStatement* s);
01594 bool isWhileCond (const SgStatement* s);
01595 bool isStdNamespace (const SgScopeStatement* scope);
01596 bool isTemplateInst (const SgDeclarationStatement* decl);
01597
01598
01599 bool isCtor (const SgFunctionDeclaration* func);
01600 bool isDtor (const SgFunctionDeclaration* func);
01601
01602
01603 bool hasTrivialDestructor(SgType* t);
01604 bool isNonconstReference(SgType* t);
01605 bool isReferenceType(SgType* t);
01606
01607
01608
01609 bool isConst(SgNode* node);
01610
01611
01612 bool isConstType (const SgType* type);
01613 bool isConstFunction (const SgFunctionDeclaration* decl);
01614
01615
01616 bool isMemberVariable(const SgInitializedName & var);
01617
01618
01619 bool isPrototypeInScope (SgScopeStatement * scope,
01620 SgFunctionDeclaration * functionDeclaration,
01621 SgDeclarationStatement * startingAtDeclaration);
01622
01623 bool MayRedefined(SgExpression* expr, SgNode* root);
01624
01625 bool hasAddressTaken(SgExpression* expr, SgNode* root);
01626
01627
01628
01629 bool containsVariableReference(SgNode* root, SgInitializedName* var);
01630
01631 bool isDeclarationOf(SgVariableDeclaration* decl, SgInitializedName* var);
01632 bool isPotentiallyModifiedDuringLifeOf(SgBasicBlock* sc,
01633 SgInitializedName* toCheck,
01634 SgInitializedName* lifetime)
01635
01636 bool anyOfListPotentiallyModifiedIn(const std::vector<SgVariableSymbol*>& syms, SgNode* n);
01637
01638
01639
01640
01641
01642
01643 SgExpression* getForLoopTripleValues(int valuetype,SgForStatement* forstmt );
01644 int setForLoopTripleValues(int valuetype,SgForStatement* forstmt, SgExpression* exp);
01645
01646 bool isLoopIndexVarRef(SgForStatement* forstmt, SgVarRefExp *varref);
01647 SgInitializedName * getLoopIndexVar(SgForStatement* forstmt);
01648
01649
01650
01651
01652 int countComputationsOfExpressionIn(SgExpression* expr, SgNode* root);
01653
01654
01655 void replaceAssignmentStmtWithStatement(SgExprStatement* from, StatementGenerator* to);
01656
01657 void replaceSubexpressionWithStatement(SgExpression* from,
01658 StatementGenerator* to);
01659 SgExpression* getRootOfExpression(SgExpression* n);
01660
01661
01662
01664 void cutPreprocInfo (SgBasicBlock* b,
01665 PreprocessingInfo::RelativePositionType pos,
01666 AttachedPreprocessingInfoType& save_buf);
01668 void pastePreprocInfoFront (AttachedPreprocessingInfoType& save_buf,
01669 SgStatement* s);
01671 void pastePreprocInfoBack (AttachedPreprocessingInfoType& save_buf,
01672 SgStatement* s);
01673
01679
01681 void moveBeforePreprocInfo (SgStatement* src, SgStatement* dest);
01682 void moveInsidePreprocInfo (SgBasicBlock* src, SgBasicBlock* dest);
01683 void moveAfterPreprocInfo (SgStatement* src, SgStatement* dest);
01684
01685
01686
01687 from transformationSupport.h, not sure if they should be included here
01688
01689 operatorCodeType classifyOverloadedOperator();
01690
01696 std::string stringifyOperator (std::string name);
01697
01698
01699
01700 std::string buildMacro ( std::string s );
01701
01702
01703
01704
01705 * get/set a direct child/grandchild node or fields
01706 * get/set a property flag value
01707 * get a descendent child node using preorder searching
01708 * get an ancestor node using bottomup/reverse searching
01709
01710
01711 std::string getFunctionName (SgFunctionCallExp* functionCallExp);
01712 std::string getFunctionTypeName ( SgFunctionCallExp* functionCallExpression );
01713
01714
01715
01716 std::string get_name (const SgNode* node);
01717 std::string get_name (const SgDeclarationStatement * declaration);
01718
01719
01720
01721 void setExtern (SgFunctionDeclartion*)
01722 void clearExtern()
01723
01724
01725 void setExtern (SgVariableDeclaration*)
01726 void setPublic()
01727 void setPrivate()
01728
01729
01730 #endif
01731 }
01732
01733 #endif