00001 // Author: Markus Schordan 00002 // $Id: AstRestructure.h,v 1.2 2006/04/24 00:21:32 dquinlan Exp $ 00003 00004 #ifndef ASTRESTRUCTURE_H 00005 #define ASTRESTRUCTURE_H 00006 00007 #include "roseInternal.h" 00008 //#include "sage3.h" 00009 #include "rewrite.h" 00010 #include <set> 00011 #include <utility> 00012 00013 #if 0 00014 // This has been moved to the unparser... 00015 class AstUnparseAttribute : public AstAttribute 00016 { 00017 public: 00018 00019 // DQ (7/19/2008): I think we should not reuse the PreprocessingInfo::RelativePositionType 00020 // since it does not make sense to "replace" an IR node with a comment or CPP directive, I think. 00021 // typedef PreprocessingInfo::RelativePositionType RelativeLocation; 00022 enum RelativePositionType 00023 { 00024 defaultValue = 0, // let the zero value be an error value 00025 undef = 1, // Position of the directive is only going to be defined 00026 // when the preprocessing object is copied into the AST, 00027 // it remains undefined before that 00028 before = 2, // Directive goes before the correponding code segment 00029 after = 3, // Directive goes after the correponding code segment 00030 inside = 4, // Directive goes inside the correponding code segment (as in between "{" and "}" of an empty basic block) 00031 00032 // DQ (7/19/2008): Added additional fields so that we could use this enum type in the AstUnparseAttribute 00033 replace = 5, // Support for replacing the IR node in the unparsing of any associated subtree 00034 before_syntax = 6, // We still have to specify the syntax 00035 after_syntax = 7 // We still have to specify the syntax 00036 }; 00037 00038 RelativePositionType location; 00039 std::string unparseReplacement; 00040 std::vector< std::pair<std::string,RelativePositionType> > stringList; 00041 00042 AstUnparseAttribute(std::string s, RelativePositionType inputlocation ) 00043 : location(inputlocation), unparseReplacement(s) 00044 { 00045 // Add the string location pair to the list. 00046 stringList.push_back(std::pair<std::string,RelativePositionType>(s,inputlocation)); 00047 } 00048 virtual std::string toString() { return unparseReplacement; } 00049 }; 00050 #endif 00051 00052 /* 00053 class RestructureInhType : public AST_Rewrite::InheritedAttribute { 00054 public: 00055 RestructureInhType(SgNode* n) 00056 : AST_Rewrite::InheritedAttribute(n) {} 00057 RestructureInhType(const RestructureInhType & X ) 00058 : AST_Rewrite::InheritedAttribute(X) {} 00059 RestructureInhType ( const RestructureInhType& X, SgNode* astNode ) 00060 : AST_Rewrite::InheritedAttribute (X,astNode) {}; 00061 RestructureInhType & 00062 RestructureInhType::operator= ( const RestructureInhType & X ) { 00063 // Call the base class operator= 00064 AST_Rewrite::InheritedAttribute::operator=(X); 00065 return *this; 00066 } 00067 }; 00068 00069 class RestructureSynType : public AST_Rewrite::SynthesizedAttribute { 00070 public: 00071 RestructureSynType() {} 00072 RestructureSynType(SgNode* n):AST_Rewrite::SynthesizedAttribute (n) {} 00073 }; 00074 */ 00075 00076 class AstRestructure 00077 { 00078 public: 00079 AstRestructure(SgProject* project) {} 00080 AstRestructure(SgProject* project,std::string incheader) {} 00081 00082 00083 // replaces the AST with astNode as root node with the AST representing string s 00084 void immediateReplace(SgStatement* astNode,std::string s); 00085 00086 // attaches a string s to the AST such that when 'unparse' or 00087 // unparseToString or unparseToCompleteString is called, the string 00088 // 's' is unparsed instead of the subtree with node 'astNode' as 00089 // root. This function allows to replace parts of expressions! 00090 static void unparserReplace(SgExpression* astNode, std::string s); 00091 00092 // this replace is delayed until unlock of node astNode is called. 00093 void delayedReplace(SgNode* astNode,std::string s); 00094 void lock(SgNode* astNode); // used by abstract parser 00095 void unlock(SgNode* astNode); // used by abstract parser 00096 00097 private: 00098 SgProject* sageProject; 00099 SgNode* targetNode; 00100 std::string sourceFragment; 00101 std::string includeHeaders; // will become obsolete with new rewrite system 00102 00103 typedef std::set<SgNode*> Lock; 00104 Lock lockedNodes; 00105 typedef std::map<SgNode*,std::string> Schedule; 00106 typedef Schedule::value_type SchedulePair; 00107 Schedule scheduledReplacements; 00108 00109 // Functions required by the AST Rewrite Tree Traversal mechanism 00110 /* 00111 RestructureInhType 00112 evaluateRewriteInheritedAttribute (SgNode* astNode, 00113 RestructureInhType inheritedValue ); 00114 RestructureSynType 00115 evaluateRewriteSynthesizedAttribute (SgNode* astNode, 00116 RestructureInhType inheritedValue, 00117 SubTreeSynthesizedAttributes attributeList ); 00118 */ 00119 }; 00120 00121 #endif
1.4.7