ROSE  0.9.6a
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AstAttributeMechanism.h
Go to the documentation of this file.
1 // Author: Markus Schordan
2 // $Id: AstAttributeMechanism.h,v 1.3 2006/04/24 00:21:32 dquinlan Exp $
3 
4 #ifndef ASTATTRIBUTEMECHANISM_H
5 #define ASTATTRIBUTEMECHANISM_H
6 
7 #include <list>
8 
9 #include "AttributeMechanism.h"
10 #include "rosedll.h"
11 
12 class SgNode;
13 class SgNamedType;
17 
19  {
20  // This class contains no data and is to be used as a based class (typically, but not required)
21  // to support under-defined attributes to be attached to AST IR nodes.
22 
23  public:
24 
25  // DQ (7/4/2008): Added support for attibutes to specify edges in the dot graphs.
27  {
28  public:
31  std::string label;
32  std::string options;
33 
34  AttributeEdgeInfo (SgNode* fromNode, SgNode* toNode, std::string label, std::string options )
35  : fromNode(fromNode), toNode(toNode), label(label), options(options)
36  {
37  }
38 
39  ~AttributeEdgeInfo () { fromNode = NULL; toNode = NULL; };
40  };
41 
42  // DQ (7/5/2008): Added support for adding nodes to DOT graphs
44  {
45  public:
47  std::string label;
48  std::string options;
49 
50  AttributeNodeInfo (SgNode* nodePtr, std::string label, std::string options )
51  : nodePtr(nodePtr), label(label), options(options)
52  {
53  }
54 
56  };
57 #if 1
58  AstAttribute();
59  virtual ~AstAttribute();
64  virtual std::string toString();
65 
66  // JH (12/21/2005): Adding Methods for storing the Ast Attribute data
67  AstAttribute* constructor();
68  std::string attribute_class_name();
69 
70  // Packing support (by JH)
71  virtual int packed_size();
72  virtual char* packed_data();
73  virtual void unpacked_data( int size, char* data );
74 
75  // DQ (7/4/2008): Added DOT support.
76  virtual std::string additionalNodeOptions();
77  // virtual std::string additionalEdgeInfo();
78 
79  // virtual std::vector<std::pair<SgNode*,SgNode*> > additionalEdgeInfo();
80  virtual std::vector<AttributeEdgeInfo> additionalEdgeInfo();
81  virtual std::vector<AttributeNodeInfo> additionalNodeInfo();
82 
83  // DQ (7/27/2008): The support for deep copies of attributes on AST IR
84  // node requires a virtual copy function that can be overwritten.
85  // This acts just like a virtual constructor (same concept).
86  virtual AstAttribute* copy();
87 
88  // DQ (7/27/2008): Added support to eliminate IR nodes in DOT graphs
89  // (to tailor the presentation of information about ASTs).
90  virtual bool commentOutNodeInGraph();
91 #else
92  AstAttribute() {}
93  virtual ~AstAttribute() {}
98  virtual std::string toString() { return ""; }
99 
100  // JH (12/21/2005): Adding Methods for storing the Ast Attribute data
101  AstAttribute* constructor() { return new AstAttribute(); }
102  std::string attribute_class_name() { return "AstAttribute"; }
103 
104  // Packing support (by JH)
105  virtual int packed_size() { return 0; }
106  virtual char* packed_data() { return NULL; }
107  virtual void unpacked_data( int size, char* data ) {}
108 
109  // DQ (7/4/2008): Added DOT support.
110  virtual std::string additionalNodeOptions() { return ""; }
111  // virtual std::string additionalEdgeInfo() { return ""; }
112 
113  // virtual std::vector<std::pair<SgNode*,SgNode*> > additionalEdgeInfo();
114  virtual std::vector<AttributeEdgeInfo> additionalEdgeInfo() { std::vector<AttributeEdgeInfo> v; return v; }
115  virtual std::vector<AttributeNodeInfo> additionalNodeInfo() { std::vector<AttributeNodeInfo> v; return v; }
116 
117  // DQ (7/27/2008): The support for deep copies of attributes on AST IR
118  // node requires a virtual copy function that can be overwritten.
119  // This acts just like a virtual constructor (same concept).
120  virtual AstAttribute* copy() { return new AstAttribute(*this); }
121 
122  // DQ (7/27/2008): Added support to eliminate IR nodes in DOT graphs
123  // (to tailor the presentation of information about ASTs).
124  virtual bool commentOutNodeInGraph() { return false; }
125 #endif
126 
127  };
128 
129 
142 {
143  public:
144  MetricAttribute();
145  MetricAttribute(double value, bool is_derived=false);
146 
151 
152  virtual AstAttribute* constructor();
153  virtual AstAttribute* copy();
154 
155  virtual std::string attribute_class_name();
156 
157  virtual int packed_size();
158  virtual char* packed_data();
159  virtual void unpacked_data( int size, char* data );
160 
161  virtual bool isDerived() const;
162  virtual double getValue() const;
163  virtual void setValue(double newVal);
164  virtual std::string toString();
165 
166  protected:
168  double value_;
169 };
170 
171 
172 // DQ (6/28/2008):
173 // Since this is implemented using AttributeMechanism which is derived from
174 // std::map<Key,Value>, "Value" is a template parameter for "AstAttribute*"
175 // And so the copy constructor will copy the pointer. This is OK, but it
176 // means that the AstAttribute objects are shared. Alternatively, a copy
177 // constructor implemented in this class could be implemented to support
178 // deep copies. This might be a good idea.
179 class AstAttributeMechanism : public AttributeMechanism<std::string,AstAttribute*>
180  {
181  public:
182  // DQ (7/27/2008): Build a copy constructor that will do a deep copy
183  // instead of calling the default copy constructor.
185 
186  // DQ (7/27/2008): Because we add an explicit copy constructor we
187  // now need an explicit default constructor.
189  };
190 
191 
192 // DQ (11/21/2009): Added new kind of attribute for handling regex trees.
200  {
201  public:
202  std::string expression;
203 
205  AstRegExAttribute(const std::string & s);
206  virtual AstAttribute* copy() /*override*/;
207  };
208 
209 // PC (10/21/2012): Added new kind of attribute for handling regex trees.
217  {
219 
220  public:
221  SgNode *getNode();
222  void setNode(SgNode *);
223 
226  virtual AstAttribute* copy() /*override*/;
227  };
228 
230  {
231  std::vector<SgNode *> nodeList;
232 
233  public:
234  std::vector<SgNode *> &getNodeList();
235  void addNode(SgNode *);
236  void setNode(SgNode *, int);
237  SgNode *getNode(int);
238  int size();
239 
241  AstSgNodeListAttribute(std::vector<SgNode *> &);
242 
243  virtual AstAttribute* copy() /*override*/;
244  };
245 
247  {
248  int value;
249 
250  public:
251  int getValue();
252 
253  AstIntAttribute(int value_);
254 
255  virtual AstAttribute* copy() /*override*/;
256  };
257 
259  private:
261  std::list<SgJavaParameterizedType *> parameterizedTypes;
262 
263  public:
265 
266  bool argumentsMatch(SgTemplateParameterList *type_arg_list, std::vector<SgTemplateParameter *> *new_args);
267  SgJavaParameterizedType *findOrInsertParameterizedType(std::vector<SgTemplateParameter *> *new_args);
268 
269  virtual AstAttribute* copy() /*override*/;
270 };
271 
272 
273 #endif