ROSE  0.11.145.0
AstCombinedProcessing.h
1 // Author: Gergo Barany
2 // $Id: AstCombinedProcessing.h,v 1.1 2008/01/08 02:56:38 dquinlan Exp $
3 
4 // Classes for combining traversals. These allow you to evaluate the effects
5 // of multiple traversals (that do not modify the AST structure) in a single
6 // traversal. Each of the AstCombined*Processing classes is a subtype of the
7 // appropriate Ast*Processing class and contains a list of pointers to such
8 // traversals. Note that there are some restrictions on the types of
9 // traversals that can be grouped together: attributes must all be of the same
10 // pointer type (which may be a pointer to some common superclass).
11 
12 // Do not assume that the traversals' visit functions are executed in any
13 // particular order. Do not introduce any other type of dependency between
14 // your traversals. In particular, do not modify the AST.
15 
16 #ifndef ASTCOMBINEDPROCESSING_H
17 #define ASTCOMBINEDPROCESSING_H
18 
19 #include "AstProcessing.h"
20 
21 template <class InheritedAttributeType, class SynthesizedAttributeType>
23  : public SgTreeTraversal< std::vector<InheritedAttributeType> *, std::vector<SynthesizedAttributeType> *>
24 {
25 public:
27  typedef TraversalType *TraversalPtr;
28  typedef std::vector<TraversalPtr> TraversalPtrList;
29  typedef std::vector<InheritedAttributeType> InheritedAttributeTypeList;
30  typedef std::vector<SynthesizedAttributeType> SynthesizedAttributeTypeList;
31  typedef SgTreeTraversal<std::vector<InheritedAttributeType> *, std::vector<SynthesizedAttributeType> *> Superclass;
33 
37  SgCombinedTreeTraversal(const TraversalPtrList &);
38 
40  void addTraversal(TraversalPtr);
44  TraversalPtrList &get_traversalPtrListRef();
45 
46 protected:
47  virtual InheritedAttributeTypeList *evaluateInheritedAttribute(
48  SgNode *astNode,
49  InheritedAttributeTypeList *inheritedValues);
50  virtual SynthesizedAttributeTypeList *evaluateSynthesizedAttribute(
51  SgNode *astNode,
52  InheritedAttributeTypeList *inheritedValues,
53  SynthesizedAttributesList synthesizedAttributes);
54  virtual SynthesizedAttributeTypeList *defaultSynthesizedAttribute(InheritedAttributeTypeList *);
55  virtual void atTraversalStart();
56  virtual void atTraversalEnd();
57 
58  TraversalPtrList traversals;
59 
60 private:
61  typename TraversalPtrList::iterator tBegin, tEnd;
62  typename TraversalPtrList::size_type numberOfTraversals;
63 };
64 
65 template <class InheritedAttributeType, class SynthesizedAttributeType>
67  : public AstTopDownBottomUpProcessing<std::vector<InheritedAttributeType> *, std::vector<SynthesizedAttributeType> *>
68 {
69 public:
71  typedef TraversalType *TraversalPtr;
72  typedef std::vector<TraversalPtr> TraversalPtrList;
73  typedef std::vector<InheritedAttributeType> InheritedAttributeTypeList;
74  typedef std::vector<SynthesizedAttributeType> SynthesizedAttributeTypeList;
75  typedef AstTopDownBottomUpProcessing<std::vector<InheritedAttributeType> *, std::vector<SynthesizedAttributeType> *> Superclass;
76  typedef typename Superclass::SynthesizedAttributesList SynthesizedAttributesList;
77 
81  AstCombinedTopDownBottomUpProcessing(const TraversalPtrList &);
82 
84  void addTraversal(TraversalPtr);
88  TraversalPtrList &get_traversalPtrListRef();
89 
90 protected:
91  virtual InheritedAttributeTypeList *evaluateInheritedAttribute(
92  SgNode *astNode,
93  InheritedAttributeTypeList *inheritedValues);
94  virtual SynthesizedAttributeTypeList *evaluateSynthesizedAttribute(
95  SgNode *astNode,
96  InheritedAttributeTypeList *inheritedValues,
97  SynthesizedAttributesList synthesizedAttributes);
98  virtual SynthesizedAttributeTypeList *defaultSynthesizedAttribute(InheritedAttributeTypeList *);
99  virtual void atTraversalStart();
100  virtual void atTraversalEnd();
101 
102  TraversalPtrList traversals;
103 
104 private:
105  typename TraversalPtrList::iterator tBegin, tEnd;
106  typename TraversalPtrList::size_type numberOfTraversals;
107 };
108 
109 template <class InheritedAttributeType>
111  : public AstTopDownProcessing<std::vector<InheritedAttributeType> *>
112 {
113 public:
115  typedef TraversalType *TraversalPtr;
116  typedef std::vector<TraversalPtr> TraversalPtrList;
117  typedef std::vector<InheritedAttributeType> InheritedAttributeTypeList;
118 
122  AstCombinedTopDownProcessing(const TraversalPtrList &);
123 
125  void addTraversal(TraversalPtr);
129  TraversalPtrList &get_traversalPtrListRef();
130 
131 protected:
132  virtual InheritedAttributeTypeList *evaluateInheritedAttribute(
133  SgNode *astNode,
134  InheritedAttributeTypeList *inheritedValues);
135  virtual void atTraversalStart();
136  virtual void atTraversalEnd();
137  virtual void destroyInheritedValue(SgNode*, InheritedAttributeTypeList *);
138 
139  TraversalPtrList traversals;
140 
141 private:
142  typename TraversalPtrList::iterator tBegin, tEnd;
143  typename TraversalPtrList::size_type numberOfTraversals;
144 };
145 
146 template <class SynthesizedAttributeType>
148  : public AstBottomUpProcessing<std::vector<SynthesizedAttributeType> *>
149 {
150 public:
152  typedef TraversalType *TraversalPtr;
153  typedef std::vector<TraversalPtr> TraversalPtrList;
154  typedef std::vector<SynthesizedAttributeType> SynthesizedAttributeTypeList;
156  typedef typename Superclass::SynthesizedAttributesList SynthesizedAttributesList;
157 
161  AstCombinedBottomUpProcessing(const TraversalPtrList &);
162 
164  void addTraversal(TraversalPtr);
168  TraversalPtrList &get_traversalPtrListRef();
169 
170 protected:
171  virtual SynthesizedAttributeTypeList *evaluateSynthesizedAttribute(
172  SgNode *astNode,
173  SynthesizedAttributesList synthesizedAttributes);
174  virtual SynthesizedAttributeTypeList *defaultSynthesizedAttribute();
175  virtual void atTraversalStart();
176  virtual void atTraversalEnd();
177 
178  TraversalPtrList traversals;
179 
180 private:
181  typename TraversalPtrList::iterator tBegin, tEnd;
182  typename TraversalPtrList::size_type numberOfTraversals;
183 };
184 
185 #include "AstCombinedProcessingImpl.h"
186 
187 #include "AstCombinedSimpleProcessing.h"
188 
189 #endif
This class is temporary. Do not use.
Definition: AstProcessing.h:97
Attribute Evaluator for synthesized attributes.
void addTraversal(TraversalPtr)
simple function for adding a traversal to the internal list
void addTraversal(TraversalPtr)
simple function for adding a traversal to the internal list
virtual SynthesizedAttributeTypeList * defaultSynthesizedAttribute()
Allows to provide a default value for a synthesized attribute of primitive type (e.g.
virtual void atTraversalStart()
Function called at the start of the traversal, before any node is visited; override if necessary...
Attribute Evaluator for inherited attributes.
TraversalPtrList & get_traversalPtrListRef()
function for obtaining a reference to the internal list of traversals, you can use this for any conta...
virtual void atTraversalStart()
Function called at the start of the traversal, before any node is visited; override if necessary...
TraversalPtrList & get_traversalPtrListRef()
function for obtaining a reference to the internal list of traversals, you can use this for any conta...
AstCombinedTopDownBottomUpProcessing()
default constructor
virtual InheritedAttributeTypeList * evaluateInheritedAttribute(SgNode *astNode, InheritedAttributeTypeList *inheritedValues)
pure virtual function which must be implemented to compute the inherited attribute at a node ...
void addTraversal(TraversalPtr)
simple function for adding a traversal to the internal list
This class represents the base class for all IR nodes within Sage III.
Definition: Cxx_Grammar.h:9846
void addTraversal(TraversalPtr)
simple function for adding a traversal to the internal list
AstCombinedTopDownProcessing()
default constructor
AstCombinedBottomUpProcessing()
default constructor
virtual void atTraversalStart()
Function called at the start of the traversal, before any node is visited; override if necessary...
TraversalPtrList & get_traversalPtrListRef()
function for obtaining a reference to the internal list of traversals, you can use this for any conta...
SgCombinedTreeTraversal()
default constructor
TraversalPtrList & get_traversalPtrListRef()
function for obtaining a reference to the internal list of traversals, zou can use this for any conta...
Attribute Evaluator for inherited and synthesized attributes.
virtual InheritedAttributeTypeList * evaluateInheritedAttribute(SgNode *astNode, InheritedAttributeTypeList *inheritedValues)
pure virtual function which must be implemented to compute the inherited attribute at a node ...