ROSE 0.11.145.147
AstAttributeMechanism.h
1#ifndef ROSE_AstAttributeMechanism_H
2#define ROSE_AstAttributeMechanism_H
3
4#include "rosedll.h"
5#include <Sawyer/Attribute.h>
6#include <list>
7#include <set>
8
9class SgNode;
10class SgNamedType;
14
36class ROSE_DLL_API AstAttribute {
37public:
47
102
104 class ROSE_DLL_API AttributeEdgeInfo {
105 public:
106 SgNode* fromNode;
107 SgNode* toNode;
108 std::string label;
109 std::string options;
110
111 AttributeEdgeInfo(SgNode* fromNode, SgNode* toNode, std::string label, std::string options)
112 : fromNode(fromNode), toNode(toNode), label(label), options(options) {}
113
115 fromNode = NULL;
116 toNode = NULL;
117 };
118 };
119
121 class ROSE_DLL_API AttributeNodeInfo {
122 public:
123 SgNode* nodePtr;
124 std::string label;
125 std::string options;
126
127 AttributeNodeInfo(SgNode* nodePtr, std::string label, std::string options)
128 : nodePtr(nodePtr), label(label), options(options) {}
129
131 };
132
133public:
134 AstAttribute() {}
135 virtual ~AstAttribute() {}
136
146 virtual AstAttribute* constructor() const {
147 return new AstAttribute; // it doesn't make much sense to instantiate this type!
148 }
149
162 virtual AstAttribute* copy() const {
163 return NULL; // attribute will not be copied when the containing obj is copied
164 }
165
166 // DO NOT DOCUMENT! The original implementation used a non-const copy constructor and many subclasses that implemented a
167 // copy constructor didn't use C++11's "override" word as a defensive measure. Since we don't have access to all those
168 // subclasses, we must continue to support the non-const version. Subclasses should only have to implement one or the
169 // other, not both.
170 virtual AstAttribute* copy() {
171 return const_cast<const AstAttribute*>(this)->copy();
172 }
173
182 virtual std::string attribute_class_name() const {
183 return "AstAttribute"; // almost certainly not the right dynamic type name!
184 }
185
191 virtual std::string toString();
192
196 virtual int packed_size();
197 virtual char* packed_data();
198 virtual void unpacked_data( int size, char* data );
204 virtual std::string additionalNodeOptions();
205 virtual std::vector<AttributeEdgeInfo> additionalEdgeInfo();
206 virtual std::vector<AttributeNodeInfo> additionalNodeInfo();
212 virtual bool commentOutNodeInGraph();
213};
214
215
249class ROSE_DLL_API AstAttributeMechanism {
250 // Use containment because we want to keep the original API.
252
253public:
258
268 assignFrom(other);
269 }
270
283
293
301 bool exists(const std::string &name) const;
302
319 void set(const std::string &name, AstAttribute *value);
320
331 bool add(const std::string &name, AstAttribute *value);
332
343 bool replace(const std::string &name, AstAttribute *value);
344
358 AstAttribute* operator[](const std::string &name) const;
359
369 void remove(const std::string &name);
370
372 typedef std::set<std::string> AttributeIdentifiers;
373
388
396 size_t size() const;
397
398private:
399 // Called by copy constructor and assignment.
400 void assignFrom(const AstAttributeMechanism &other);
401};
402
403
404
411class ROSE_DLL_API MetricAttribute: public AstAttribute {
412protected:
413 bool is_derived_;
414 double value_;
415
416public:
418 : is_derived_(false), value_(0) {}
419
420 MetricAttribute(double value, bool is_derived=false)
421 : is_derived_(is_derived), value_(value) {}
422
423 virtual AstAttribute* copy() const override;
424 virtual std::string attribute_class_name() const override;
425
426 virtual bool isDerived() const { return is_derived_; }
427 virtual double getValue() const { return value_; }
428 virtual void setValue(double newVal) { value_ = newVal; }
429
430 virtual std::string toString() override;
431
432 virtual int packed_size() override;
433 virtual char* packed_data() override;
434 virtual void unpacked_data(int size, char* data) override;
435
436 MetricAttribute& operator+=(const MetricAttribute &other);
437 MetricAttribute& operator-=(const MetricAttribute &other);
438 MetricAttribute& operator*=(const MetricAttribute &other);
439 MetricAttribute& operator/=(const MetricAttribute &other);
440};
441
442
449template<class T>
450class ROSE_DLL_API AstValueAttribute: public AstAttribute {
451public:
453 typedef T Value;
454private:
455 Value value_;
456public:
459
461 explicit AstValueAttribute(const T &value): value_(value) {}
462
464 AstValueAttribute(const AstValueAttribute &other): value_(other.value_) {}
465
466 virtual AstAttribute* copy() const override { return new AstValueAttribute(*this); }
467 virtual std::string attribute_class_name() const override { return "AstValueAttribute"; }
468
472 const T& get() const { return value_; }
473 T& get() { return value_; }
477 void set(const T& value) { value_ = value; }
478};
479
480// DQ (11/21/2009): Added new kind of attribute for handling regex trees.
484class ROSE_DLL_API AstRegExAttribute: public AstAttribute {
485public:
486 std::string expression;
487
489
490 explicit AstRegExAttribute(const std::string & s)
491 : expression(s) {}
492
493 virtual AstAttribute* copy() const override {
494 return new AstRegExAttribute(*this);
495 }
496
497 virtual std::string attribute_class_name() const override {
498 return "AstRegExAttribute";
499 }
500};
501
502
503// PC (10/21/2012): Added new kind of attribute for handling regex trees.
507class ROSE_DLL_API AstSgNodeAttribute: public AstValueAttribute<SgNode*> {
508public:
510 AstSgNodeAttribute(): Super(NULL) {}
511 explicit AstSgNodeAttribute(SgNode *value): Super(value) {}
512 AstSgNodeAttribute(const AstSgNodeAttribute &other): Super(other) {}
513 virtual AstAttribute* copy() const override { return new AstSgNodeAttribute(*this); }
514 virtual std::string attribute_class_name() const override { return "AstSgNodeAttribute"; }
515 SgNode* getNode() { return get(); }
516 void setNode(SgNode *node) { set(node); }
517};
518
519class ROSE_DLL_API AstSgNodeListAttribute: public AstValueAttribute<std::vector<SgNode*> > {
520public:
523 explicit AstSgNodeListAttribute(std::vector<SgNode *> &value): Super(value) {}
525 virtual AstAttribute* copy() const override { return new AstSgNodeListAttribute(*this); }
526 virtual std::string attribute_class_name() const override { return "AstSgNodeListAttribute"; }
527 std::vector<SgNode*> &getNodeList() { return get(); }
528 void addNode(SgNode *n) { get().push_back(n); }
529 void setNode(SgNode*, int);
530 SgNode *getNode(int);
531 int size() { return get().size(); }
532};
533
534class ROSE_DLL_API AstIntAttribute : public AstValueAttribute<int> {
535public:
537 AstIntAttribute(): Super(0) {}
538 explicit AstIntAttribute(int value): Super(value) {}
539 AstIntAttribute(const AstIntAttribute &other): Super(other) {}
540 virtual AstAttribute* copy() const override { return new AstIntAttribute(*this); }
541 virtual std::string attribute_class_name() const override { return "AstIntAttribute"; }
542 int getValue() { return get(); }
543};
544
545class ROSE_DLL_API AstParameterizedTypeAttribute: public AstAttribute {
546 SgNamedType *genericType;
547 std::list<SgJavaParameterizedType *> parameterizedTypes;
548
549public:
551 : genericType(NULL) {}
552
553 explicit AstParameterizedTypeAttribute(SgNamedType *genericType);
554
556 : genericType(other.genericType), parameterizedTypes(other.parameterizedTypes) {}
557
558 virtual AstAttribute* copy() const override {
559 return new AstParameterizedTypeAttribute(*this);
560 }
561
562 virtual std::string attribute_class_name() const override {
563 return "AstParameterizedTypeAttribute";
564 }
565
566 bool argumentsMatch(SgTemplateParameterList *type_arg_list, std::vector<SgTemplateParameter *> *new_args);
567
568 SgJavaParameterizedType *findOrInsertParameterizedType(std::vector<SgTemplateParameter *> *new_args);
569};
570
571#endif
Stores named attributes in Sage IR nodes.
bool replace(const std::string &name, AstAttribute *value)
Insert a new value if the attribute already exists.
bool exists(const std::string &name) const
Test for attribute existence.
void remove(const std::string &name)
Erases the specified attribute.
size_t size() const
Number of attributes stored.
bool add(const std::string &name, AstAttribute *value)
Insert a new value if the attribute doesn't already exist.
AstAttribute * operator[](const std::string &name) const
Get an attribute value.
~AstAttributeMechanism()
Destructor.
void set(const std::string &name, AstAttribute *value)
Insert an attribute.
AttributeIdentifiers getAttributeIdentifiers() const
List of stored attribute names.
AstAttributeMechanism & operator=(const AstAttributeMechanism &other)
Assignment operator.
AstAttributeMechanism()
Default constructor.
AstAttributeMechanism(const AstAttributeMechanism &other)
Copy constructor.
std::set< std::string > AttributeIdentifiers
Set of attribute names.
Support for attibutes to specify edges in the dot graphs.
Support for adding nodes to DOT graphs.
Base class for all IR node attribute values.
virtual char * packed_data()
Packing support.
virtual int packed_size()
Packing support.
virtual std::string toString()
Convert an attribute to a string.
virtual std::vector< AttributeNodeInfo > additionalNodeInfo()
DOT support.
virtual void unpacked_data(int size, char *data)
Packing support.
virtual std::string additionalNodeOptions()
DOT support.
virtual std::vector< AttributeEdgeInfo > additionalEdgeInfo()
DOT support.
virtual AstAttribute * constructor() const
Virtual default constructor.
virtual OwnershipPolicy getOwnershipPolicy() const
Who owns this attribute.
virtual std::string attribute_class_name() const
Attribute class name.
OwnershipPolicy
Who owns this attribute.
@ NO_OWNERSHIP
Attributes are always leaked.
@ CUSTOM_OWNERSHIP
Subclass defines ownership policy.
@ CONTAINER_OWNERSHIP
Container owns attribute.
virtual bool commentOutNodeInGraph()
Eliminate IR nodes in DOT graphs.
virtual AstAttribute * copy() const
Virtual copy constructor.
virtual std::string attribute_class_name() const override
Attribute class name.
virtual AstAttribute * copy() const override
Virtual copy constructor.
virtual AstAttribute * copy() const override
Virtual copy constructor.
virtual std::string attribute_class_name() const override
Attribute class name.
Attribute containing a regex expression as a string.
virtual std::string attribute_class_name() const override
Attribute class name.
virtual AstAttribute * copy() const override
Virtual copy constructor.
Attribute storing an SgNode.
virtual std::string attribute_class_name() const override
Attribute class name.
virtual AstAttribute * copy() const override
Virtual copy constructor.
virtual std::string attribute_class_name() const override
Attribute class name.
virtual AstAttribute * copy() const override
Virtual copy constructor.
IR node attribute that stores a copyable value.
T Value
Type of value this wrapper holds.
AstValueAttribute(const T &value)
Constructs an attribute containing a specified value.
T & get()
Return the stored value by reference.
virtual AstAttribute * copy() const override
Virtual copy constructor.
virtual std::string attribute_class_name() const override
Attribute class name.
AstValueAttribute()
Default constructor.
void set(const T &value)
Assign a new value.
const T & get() const
Return the stored value by reference.
AstValueAttribute(const AstValueAttribute &other)
Copy constructor.
Attribute corresponding to a metric.
virtual void unpacked_data(int size, char *data) override
Packing support.
virtual int packed_size() override
Packing support.
virtual AstAttribute * copy() const override
Virtual copy constructor.
virtual std::string toString() override
Convert an attribute to a string.
virtual std::string attribute_class_name() const override
Attribute class name.
virtual char * packed_data() override
Packing support.
API and storage for attributes.
Definition Attribute.h:215
This class represents the base class for all IR nodes within Sage III.
void set(Word *words, const BitRange &where)
Set some bits.
bool get(const Word *words, size_t idx)
Return a single bit.
void setValue(Word *words, const BitRange &where, bool value)
Set or clear some bits.