AstAttributeMechanism.h

Go to the documentation of this file.
00001 // Author: Markus Schordan
00002 // $Id: AstAttributeMechanism.h,v 1.3 2006/04/24 00:21:32 dquinlan Exp $
00003 
00004 #ifndef ASTATTRIBUTEMECHANISM_H
00005 #define ASTATTRIBUTEMECHANISM_H
00006 
00007 #include "AttributeMechanism.h"
00008 
00009 class SgNode;
00010 
00011 class AstAttribute
00012    {
00013   // This class contains no data and is to be used as a based class (typically, but not required)
00014   // to support under-defined attributes to be attached to AST IR nodes.
00015 
00016      public:
00017 
00018       // DQ (7/4/2008): Added support for attibutes to specify edges in the dot graphs.
00019           class AttributeEdgeInfo
00020              {
00021                public:
00022                     SgNode* fromNode;
00023                     SgNode* toNode;
00024                     std::string label;
00025                     std::string options;
00026 
00027                     AttributeEdgeInfo (SgNode* fromNode, SgNode* toNode, std::string label, std::string options )
00028                        : fromNode(fromNode), toNode(toNode), label(label), options(options)
00029                        {
00030                        }
00031 
00032                    ~AttributeEdgeInfo () { fromNode = NULL; toNode = NULL; };
00033              };
00034 
00035        // DQ (7/5/2008): Added support for adding nodes to DOT graphs
00036           class AttributeNodeInfo
00037              {
00038                public:
00039                     SgNode* nodePtr;
00040                     std::string label;
00041                     std::string options;
00042 
00043                     AttributeNodeInfo (SgNode* nodePtr, std::string label, std::string options )
00044                        : nodePtr(nodePtr), label(label), options(options)
00045                        {
00046                        }
00047 
00048                    ~AttributeNodeInfo () {};
00049              };
00050 #if 1
00051           AstAttribute();
00052           virtual ~AstAttribute();
00057           virtual std::string toString();
00058 
00059        // JH (12/21/2005): Adding Methods for storing the Ast Attribute data
00060           AstAttribute* constructor();
00061           std::string attribute_class_name();
00062 
00063        // Packing support (by JH)
00064           virtual int packed_size();
00065           virtual char* packed_data();
00066           virtual void unpacked_data( int size, char* data );
00067 
00068        // DQ (7/4/2008): Added DOT support.
00069           virtual std::string additionalNodeOptions();
00070        // virtual std::string additionalEdgeInfo();
00071 
00072        // virtual std::vector<std::pair<SgNode*,SgNode*> > additionalEdgeInfo();
00073           virtual std::vector<AttributeEdgeInfo> additionalEdgeInfo();
00074           virtual std::vector<AttributeNodeInfo> additionalNodeInfo();
00075 
00076        // DQ (7/27/2008): The support for deep copies of attributes on AST IR
00077        // node requires a virtual copy function that can be overwritten.
00078        // This acts just like a virtual constructor (same concept).
00079           virtual AstAttribute* copy();
00080 
00081        // DQ (7/27/2008): Added support to eliminate IR nodes in DOT graphs
00082        // (to tailor the presentation of information about ASTs).
00083           virtual bool commentOutNodeInGraph();
00084 #else
00085           AstAttribute() {}
00086           virtual ~AstAttribute() {}
00091           virtual std::string toString() { return ""; }
00092 
00093        // JH (12/21/2005): Adding Methods for storing the Ast Attribute data
00094           AstAttribute* constructor() { return new AstAttribute(); }
00095           std::string attribute_class_name() { return "AstAttribute"; }
00096 
00097        // Packing support (by JH)
00098           virtual int packed_size() { return 0; }
00099           virtual char* packed_data() { return NULL; }
00100           virtual void unpacked_data( int size, char* data ) {}
00101 
00102        // DQ (7/4/2008): Added DOT support.
00103           virtual std::string additionalNodeOptions() { return ""; }
00104        // virtual std::string additionalEdgeInfo()    { return ""; }
00105 
00106        // virtual std::vector<std::pair<SgNode*,SgNode*> > additionalEdgeInfo();
00107           virtual std::vector<AttributeEdgeInfo> additionalEdgeInfo() { std::vector<AttributeEdgeInfo> v; return v; }
00108           virtual std::vector<AttributeNodeInfo> additionalNodeInfo() { std::vector<AttributeNodeInfo> v; return v; }
00109 
00110        // DQ (7/27/2008): The support for deep copies of attributes on AST IR
00111        // node requires a virtual copy function that can be overwritten.
00112        // This acts just like a virtual constructor (same concept).
00113           virtual AstAttribute* copy() { return new AstAttribute(*this); }
00114 
00115        // DQ (7/27/2008): Added support to eliminate IR nodes in DOT graphs
00116        // (to tailor the presentation of information about ASTs).
00117           virtual bool commentOutNodeInGraph() { return false; }
00118 #endif
00119 
00120    };
00121 
00122 
00134 class MetricAttribute : public AstAttribute
00135 {
00136     public:
00137         MetricAttribute();
00138         MetricAttribute(double value, bool is_derived=false);
00139 
00140         MetricAttribute& operator+= (const MetricAttribute & other);
00141         MetricAttribute& operator-= (const MetricAttribute & other);
00142         MetricAttribute& operator*= (const MetricAttribute & other);
00143         MetricAttribute& operator/= (const MetricAttribute & other);
00144 
00145         virtual AstAttribute* constructor();
00146         virtual AstAttribute* copy();
00147 
00148         virtual std::string attribute_class_name();
00149 
00150         virtual int   packed_size();
00151         virtual char* packed_data();
00152         virtual void  unpacked_data( int size, char* data );
00153 
00154         virtual bool        isDerived() const;
00155         virtual double      getValue()  const;
00156         virtual void        setValue(double newVal);
00157         virtual std::string toString();
00158 
00159     protected:
00160         bool   is_derived_;
00161         double value_;
00162 };
00163 
00164 
00165 // DQ (6/28/2008):
00166 // Since this is implemented using AttributeMechanism which is derived from
00167 // std::map<Key,Value>, "Value" is a template parameter for "AstAttribute*"
00168 // And so the copy constructor will copy the pointer.  This is OK, but it
00169 // means that the AstAttribute objects are shared.  Alternatively, a copy
00170 // constructor implemented in this class could be implemented to support
00171 // deep copies.  This might be a good idea.
00172 class AstAttributeMechanism : public AttributeMechanism<std::string,AstAttribute*>
00173    {
00174      public:
00175        // DQ (7/27/2008): Build a copy constructor that will do a deep copy
00176        // instead of calling the default copy constructor.
00177           AstAttributeMechanism ( const AstAttributeMechanism & X );
00178 
00179        // DQ (7/27/2008): Because we add an explicit copy constructor we
00180        // now need an explicit default constructor.
00181           AstAttributeMechanism ();
00182    };
00183 
00184 
00185 // DQ (11/21/2009): Added new kind of attribute for handling regex trees.
00192 class AstRegExAttribute : public AstAttribute
00193    {
00194      public:
00195           std::string expression;
00196 
00197           AstRegExAttribute();
00198           AstRegExAttribute(const std::string & s);
00199    };
00200 
00201 #endif

Generated on Tue Jan 31 05:31:19 2012 for ROSE by  doxygen 1.4.7