ROSE 0.11.145.147
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
21template <class InheritedAttributeType, class SynthesizedAttributeType>
23 : public SgTreeTraversal< std::vector<InheritedAttributeType> *, std::vector<SynthesizedAttributeType> *>
24{
25public:
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
44 TraversalPtrList &get_traversalPtrListRef();
45
46protected:
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
60private:
61 typename TraversalPtrList::iterator tBegin, tEnd;
62 typename TraversalPtrList::size_type numberOfTraversals;
63};
64
65template <class InheritedAttributeType, class SynthesizedAttributeType>
67 : public AstTopDownBottomUpProcessing<std::vector<InheritedAttributeType> *, std::vector<SynthesizedAttributeType> *>
68{
69public:
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
88 TraversalPtrList &get_traversalPtrListRef();
89
90protected:
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
104private:
105 typename TraversalPtrList::iterator tBegin, tEnd;
106 typename TraversalPtrList::size_type numberOfTraversals;
107};
108
109template <class InheritedAttributeType>
111 : public AstTopDownProcessing<std::vector<InheritedAttributeType> *>
112{
113public:
116 typedef std::vector<TraversalPtr> TraversalPtrList;
117 typedef std::vector<InheritedAttributeType> InheritedAttributeTypeList;
118
122 AstCombinedTopDownProcessing(const TraversalPtrList &);
123
129 TraversalPtrList &get_traversalPtrListRef();
130
131protected:
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
141private:
142 typename TraversalPtrList::iterator tBegin, tEnd;
143 typename TraversalPtrList::size_type numberOfTraversals;
144};
145
146template <class SynthesizedAttributeType>
148 : public AstBottomUpProcessing<std::vector<SynthesizedAttributeType> *>
149{
150public:
153 typedef std::vector<TraversalPtr> TraversalPtrList;
154 typedef std::vector<SynthesizedAttributeType> SynthesizedAttributeTypeList;
156 typedef typename Superclass::SynthesizedAttributesList SynthesizedAttributesList;
157
161 AstCombinedBottomUpProcessing(const TraversalPtrList &);
162
168 TraversalPtrList &get_traversalPtrListRef();
169
170protected:
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
180private:
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
Attribute Evaluator for synthesized attributes.
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....
AstCombinedBottomUpProcessing(const TraversalPtrList &)
constructor that makes an internal copy of an existing list of traversals
virtual void atTraversalStart()
Function called at the start of the traversal, before any node is visited; override if necessary,...
AstCombinedBottomUpProcessing()
default constructor
TraversalPtrList & get_traversalPtrListRef()
function for obtaining a reference to the internal list of traversals, you can use this for any conta...
TraversalPtrList & get_traversalPtrListRef()
function for obtaining a reference to the internal list of traversals, you can use this for any conta...
virtual InheritedAttributeTypeList * evaluateInheritedAttribute(SgNode *astNode, InheritedAttributeTypeList *inheritedValues)
pure virtual function which must be implemented to compute the inherited attribute at a node
AstCombinedTopDownBottomUpProcessing(const TraversalPtrList &)
constructor that makes an internal copy of an existing list of traversals
void addTraversal(TraversalPtr)
simple function for adding a traversal to the internal list
virtual void atTraversalStart()
Function called at the start of the traversal, before any node is visited; override if necessary,...
virtual SynthesizedAttributeTypeList * evaluateSynthesizedAttribute(SgNode *astNode, InheritedAttributeTypeList *inheritedValues, SynthesizedAttributesList synthesizedAttributes)
pure virtual function which must be implemented to compute the synthesized attribute at a node.
virtual InheritedAttributeTypeList * evaluateInheritedAttribute(SgNode *astNode, InheritedAttributeTypeList *inheritedValues)
pure virtual function which must be implemented to compute the inherited attribute at a node
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, zou can use this for any conta...
AstCombinedTopDownProcessing()
default constructor
void addTraversal(TraversalPtr)
simple function for adding a traversal to the internal list
AstCombinedTopDownProcessing(const TraversalPtrList &)
constructor that makes an internal copy of an existing list of traversals
Attribute Evaluator for inherited and synthesized attributes.
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...
SgCombinedTreeTraversal()
default constructor
SgCombinedTreeTraversal(const TraversalPtrList &)
constructor that makes an internal copy of an existing list of traversals
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.
This class is temporary. Do not use.