ROSE  0.9.6a
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AstRestructure.h
Go to the documentation of this file.
1 // Author: Markus Schordan
2 // $Id: AstRestructure.h,v 1.2 2006/04/24 00:21:32 dquinlan Exp $
3 
4 #ifndef ASTRESTRUCTURE_H
5 #define ASTRESTRUCTURE_H
6 
7 #include "roseInternal.h"
8 //#include "sage3.h"
9 #include "rewrite.h"
10 #include <set>
11 #include <utility>
12 
13 #if 0
14 // This has been moved to the unparser...
15 class AstUnparseAttribute : public AstAttribute
16  {
17  public:
18 
19  // DQ (7/19/2008): I think we should not reuse the PreprocessingInfo::RelativePositionType
20  // since it does not make sense to "replace" an IR node with a comment or CPP directive, I think.
21  // typedef PreprocessingInfo::RelativePositionType RelativeLocation;
22  enum RelativePositionType
23  {
24  defaultValue = 0, // let the zero value be an error value
25  undef = 1, // Position of the directive is only going to be defined
26  // when the preprocessing object is copied into the AST,
27  // it remains undefined before that
28  before = 2, // Directive goes before the correponding code segment
29  after = 3, // Directive goes after the correponding code segment
30  inside = 4, // Directive goes inside the correponding code segment (as in between "{" and "}" of an empty basic block)
31 
32  // DQ (7/19/2008): Added additional fields so that we could use this enum type in the AstUnparseAttribute
33  replace = 5, // Support for replacing the IR node in the unparsing of any associated subtree
34  before_syntax = 6, // We still have to specify the syntax
35  after_syntax = 7 // We still have to specify the syntax
36  };
37 
38  RelativePositionType location;
39  std::string unparseReplacement;
40  std::vector< std::pair<std::string,RelativePositionType> > stringList;
41 
42  AstUnparseAttribute(std::string s, RelativePositionType inputlocation )
43  : location(inputlocation), unparseReplacement(s)
44  {
45  // Add the string location pair to the list.
46  stringList.push_back(std::pair<std::string,RelativePositionType>(s,inputlocation));
47  }
48  virtual std::string toString() { return unparseReplacement; }
49  };
50 #endif
51 
52 /*
53 class RestructureInhType : public AST_Rewrite::InheritedAttribute {
54 public:
55  RestructureInhType(SgNode* n)
56  : AST_Rewrite::InheritedAttribute(n) {}
57  RestructureInhType(const RestructureInhType & X )
58  : AST_Rewrite::InheritedAttribute(X) {}
59  RestructureInhType ( const RestructureInhType& X, SgNode* astNode )
60  : AST_Rewrite::InheritedAttribute (X,astNode) {};
61  RestructureInhType &
62  RestructureInhType::operator= ( const RestructureInhType & X ) {
63  // Call the base class operator=
64  AST_Rewrite::InheritedAttribute::operator=(X);
65  return *this;
66  }
67 };
68 
69 class RestructureSynType : public AST_Rewrite::SynthesizedAttribute {
70 public:
71  RestructureSynType() {}
72  RestructureSynType(SgNode* n):AST_Rewrite::SynthesizedAttribute (n) {}
73 };
74 */
75 
77  {
78  public:
80  AstRestructure(SgProject* project,std::string incheader) {}
81 
82 
83  // replaces the AST with astNode as root node with the AST representing string s
84  void immediateReplace(SgStatement* astNode,std::string s);
85 
86  // attaches a string s to the AST such that when 'unparse' or
87  // unparseToString or unparseToCompleteString is called, the string
88  // 's' is unparsed instead of the subtree with node 'astNode' as
89  // root. This function allows to replace parts of expressions!
90  static void unparserReplace(SgExpression* astNode, std::string s);
91 
92  // this replace is delayed until unlock of node astNode is called.
93  void delayedReplace(SgNode* astNode,std::string s);
94  void lock(SgNode* astNode); // used by abstract parser
95  void unlock(SgNode* astNode); // used by abstract parser
96 
97  private:
100  std::string sourceFragment;
101  std::string includeHeaders; // will become obsolete with new rewrite system
102 
103  typedef std::set<SgNode*> Lock;
105  typedef std::map<SgNode*,std::string> Schedule;
106  typedef Schedule::value_type SchedulePair;
108 
109  // Functions required by the AST Rewrite Tree Traversal mechanism
110  /*
111  RestructureInhType
112  evaluateRewriteInheritedAttribute (SgNode* astNode,
113  RestructureInhType inheritedValue );
114  RestructureSynType
115  evaluateRewriteSynthesizedAttribute (SgNode* astNode,
116  RestructureInhType inheritedValue,
117  SubTreeSynthesizedAttributes attributeList );
118  */
119 };
120 
121 #endif