ROSE 0.11.145.147
AstRestructure.h
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...
15class 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;
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/*
53class RestructureInhType : public AST_Rewrite::InheritedAttribute {
54public:
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
69class RestructureSynType : public AST_Rewrite::SynthesizedAttribute {
70public:
71 RestructureSynType() {}
72 RestructureSynType(SgNode* n):AST_Rewrite::SynthesizedAttribute (n) {}
73};
74*/
75
77 {
78 public:
80 AstRestructure(SgProject*, 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:
98#if 0 // [Robb Matzke 2021-03-17]: unused
99 SgProject* sageProject;
100 SgNode* targetNode;
101#endif
102 std::string sourceFragment;
103 std::string includeHeaders; // will become obsolete with new rewrite system
104
105 typedef std::set<SgNode*> Lock;
106 Lock lockedNodes;
107 typedef std::map<SgNode*,std::string> Schedule;
108 typedef Schedule::value_type SchedulePair;
109 Schedule scheduledReplacements;
110
111 // Functions required by the AST Rewrite Tree Traversal mechanism
112 /*
113 RestructureInhType
114 evaluateRewriteInheritedAttribute (SgNode* astNode,
115 RestructureInhType inheritedValue );
116 RestructureSynType
117 evaluateRewriteSynthesizedAttribute (SgNode* astNode,
118 RestructureInhType inheritedValue,
119 SubTreeSynthesizedAttributes attributeList );
120 */
121};
122
123#endif
Base class for all IR node attribute values.
virtual std::string toString()
Convert an attribute to a string.
This class represents the notion of an expression. Expressions are derived from SgLocatedNodes,...
This class represents the base class for all IR nodes within Sage III.
This class represents a source project, with a list of SgFile objects and global information about th...
This class represents the notion of a statement.
const char * RelativePositionType(int64_t)
Convert AstUnparseAttribute::RelativePositionType enum constant to a string.