AstDOTGeneration.h

Go to the documentation of this file.
00001 // Author: Markus Schordan
00002 // $Id: AstDOTGeneration.h,v 1.4 2008/01/08 02:56:38 dquinlan Exp $
00003 
00004 #ifndef ASTDOTGENERATION_H
00005 #define ASTDOTGENERATION_H
00006 
00007 #include <set>
00008 #include "DOTGeneration.h"
00009 #include "roseInternal.h"
00010 //#include "sage3.h"
00011 
00012 class AstDOTGeneration : public DOTGeneration<SgNode*>
00013    {
00014      public:
00015           void generate(SgProject* node, traversalType tt=TOPDOWNBOTTOMUP, std::string filenamePostfix="");
00016           void generate(SgNode* node,  std::string filename, traversalType tt = TOPDOWNBOTTOMUP,std::string filenamePostfix = "");
00017           void generateInputFiles(SgProject* node, traversalType tt=TOPDOWNBOTTOMUP, std::string filenamePostfix="");
00018           void generateWithinFile(SgFile* node, traversalType tt=TOPDOWNBOTTOMUP, std::string filenamePostfix="");
00019 
00020           void writeIncidenceGraphToDOTFile(SgIncidenceDirectedGraph* graph,  const std::string& filename);
00021           void addAdditionalNodesAndEdges(SgNode* node);
00022 
00023      protected:
00024           virtual DOTInheritedAttribute evaluateInheritedAttribute(SgNode* node, DOTInheritedAttribute ia);
00025           virtual DOTSynthesizedAttribute evaluateSynthesizedAttribute(SgNode* node, DOTInheritedAttribute ia, SubTreeSynthesizedAttributes l);
00026 
00027           std::string additionalNodeInfo(SgNode* node);
00028 
00029        // DQ (11/1/2003) added mechanism to add node options (to add color, etc.)
00030           std::string additionalNodeOptions(SgNode* node);
00031 
00032        // DQ (3/5/2007) added mechanism to add edge options (to add color, etc.)
00033           std::string additionalEdgeInfo(SgNode* from, SgNode* to, std::string label);
00034 
00035        // DQ (3/5/2007) added mechanism to add edge options (to add color, etc.)
00036           std::string additionalEdgeOptions(SgNode* from, SgNode* to, std::string label);
00037 
00038        // DQ (7/27/2008): Added support to eliminate IR nodes in DOT graphs 
00039        // (to tailor the presentation of information about ASTs).
00040           bool commentOutNodeInGraph(SgNode* node);
00041    };
00042 
00043 
00044 namespace AstDOTGenerationExtended_Defaults
00045    {
00046      struct NamedExtraNodeInfo
00047         {
00048 #if 1
00049        // DQ (6/25/2011): Put the function definition into the source file (avoid function definitions in header files).
00050           std::string operator()(SgNode* node);
00051 #else
00052        // std::string AstDOTGenerationExtended_Defaults::NamedExtraNodeInfo::operator()(SgNode* node)
00053                 std::string operator()(SgNode* node)
00054                 {
00055                         std::ostringstream ss;
00056 
00057                         // add namespace name
00058                         if (SgNamespaceDeclarationStatement* n = isSgNamespaceDeclarationStatement(node))
00059                         {
00060                                 ss << n->get_qualified_name().str() << "\\n";
00061                         }
00062                         // add class name
00063                         if (SgClassDeclaration* n = isSgClassDeclaration(node))
00064                         {
00065                                 ss << n->get_qualified_name().str() << "\\n";
00066                         }
00067                         // add function name
00068                         if (SgFunctionDeclaration* n = isSgFunctionDeclaration(node))
00069                         {
00070                                 ss << n->get_qualified_name().str() << "\\n";
00071                         }
00072                         if (SgFunctionRefExp* n = isSgFunctionRefExp(node))
00073                         {
00074                                 SgFunctionDeclaration* decl = n->getAssociatedFunctionDeclaration();
00075                                 if (decl) // it's null if through a function pointer
00076                                 {
00077                                         ss << decl->get_qualified_name().str() << "\\n";
00078                                 }
00079                         }
00080                         // add variable name
00081                         if (SgInitializedName* n = isSgInitializedName(node))
00082                         {
00083                                 ss << n->get_qualified_name().str() << "\\n";
00084                         }
00085                         if (SgVarRefExp* n = isSgVarRefExp(node))
00086                         {
00087                                 SgVariableSymbol* sym = n->get_symbol();
00088                                 ss << sym->get_name().getString() << "\\n";
00089                         }
00090                         // add variable name
00091                         if (SgVariableSymbol* n = isSgVariableSymbol(node))
00092                         {
00093                                 ss << n->get_name().str() << "\\n";
00094                         }
00095 
00096                         return ss.str();
00097                 }
00098 #endif
00099         };
00100 
00101         struct AddressExtraNodeInfo
00102         {
00103                 std::string operator()(SgNode* node)
00104                 {
00105                         std::ostringstream ss;
00106 
00107                         ss << node << "\\n";
00108 
00109                         return ss.str();
00110                 }
00111         };
00112 
00113         struct ContainerSizeExtraNodeInfo
00114         {
00115                 std::string operator()(SgNode* node)
00116                 {
00117                         std::ostringstream ss;
00118                         // print number of max successors (= container size)
00119                         AstSuccessorsSelectors::SuccessorsContainer c;
00120                         AstSuccessorsSelectors::selectDefaultSuccessors(node,c);
00121                         ss << c.size() << "\\n";
00122 
00123                         return ss.str();
00124                 }
00125         };
00126 
00127         struct LValueExtraNodeInfo
00128         {
00129 #if 1
00130        // DQ (6/25/2011): Put the function definition into the source file (avoid function definitions in header files).
00131           std::string operator()(SgNode* node);
00132 #else
00133        // std::string AstDOTGenerationExtended_Defaults::LValueExtraNodeInfo::operator()(SgNode* node)
00134              std::string operator()(SgNode* node)
00135                 {
00136                         std::ostringstream ss;
00137 
00138                         // adds whether or not it is an l-value
00139                         if (SgExpression* n = isSgExpression(node))
00140                         {
00141                                 ss << (n->isLValue() ? "L-Value" : "!L-Value") << "\\n";
00142                         }
00143 
00144                         return ss.str();
00145                 }
00146 #endif
00147         };
00148 
00149         struct TypeExtraNodeInfo
00150         {
00151 #if 1
00152        // DQ (6/25/2011): Put the function definition into the source file (avoid function definitions in header files).
00153           std::string operator()(SgNode* node);
00154 #else
00155        // std::string AstDOTGenerationExtended_Defaults::TypeExtraNodeInfo::operator()(SgNode* node)
00156               std::string operator()(SgNode* node)
00157                 {
00158                         std::ostringstream ss;
00159 
00160                         if (SgExpression* n = isSgExpression(node))
00161                         {
00162                                 ss << n->get_type()->unparseToString() << "\\n";
00163                         }
00164 
00165                         return ss.str();
00166                 }
00167 #endif
00168         };
00169 
00170         struct DefaultExtraNodeInfo
00171         {
00172                 std::string operator()(SgNode* node)
00173                 {
00174                         ContainerSizeExtraNodeInfo cs;
00175                         NamedExtraNodeInfo name;
00176                         AddressExtraNodeInfo add;
00177                         return std::string("\\n") + cs(node) + name(node) + add(node);
00178                 }
00179         };
00180 
00181 
00182         struct DefaultExtraNodeOptions
00183         {
00184                 std::string operator()(SgNode* node)
00185                 {
00186                         return std::string();
00187                 }
00188         };
00189 
00190         struct DefaultExtraEdgeInfo
00191         {
00192                 std::string operator()(SgNode* from, SgNode* to, std::string label)
00193                 {
00194                         return std::string();
00195                 }
00196         };
00197 
00198         struct DefaultExtraEdgeOptions
00199         {
00200                 std::string operator()(SgNode* node, SgNode* to, std::string label)
00201                 {
00202                         return std::string();
00203                 }
00204         };
00205 }
00206 
00207 // King84 (14/7/2010) added mechanism to customize node options on demand
00208 // Note: aditionalEdgeInfo andadditionalEdgeOptions are inherited.
00209 // Note: EdgeInfo and EdgeOptions are not used because they come into play
00210 //       for functions in the base class which are not virtual.
00211 template <typename ExtraNodeInfo_t = AstDOTGenerationExtended_Defaults::DefaultExtraNodeInfo, 
00212           typename ExtraNodeOptions_t = AstDOTGenerationExtended_Defaults::DefaultExtraNodeOptions, 
00213           typename ExtraEdgeInfo_t = AstDOTGenerationExtended_Defaults::DefaultExtraEdgeInfo, 
00214           typename ExtraEdgeOptions_t = AstDOTGenerationExtended_Defaults::DefaultExtraEdgeOptions>
00215 class AstDOTGenerationExtended : public AstDOTGeneration
00216    {
00217      protected:
00218           ExtraNodeInfo_t eni;
00219           ExtraNodeOptions_t eno;
00220           ExtraEdgeInfo_t eei;
00221           ExtraEdgeOptions_t eeo;
00222      public:
00223           AstDOTGenerationExtended(ExtraNodeInfo_t eni_ = ExtraNodeInfo_t(), ExtraNodeOptions_t eno_ = ExtraNodeOptions_t(), ExtraEdgeInfo_t eei_ = ExtraEdgeInfo_t(), ExtraEdgeOptions_t eeo_ = ExtraEdgeOptions_t())
00224              : eni(eni_), eno(eno_), eei(eei_), eeo(eeo_)
00225              { }
00226        // virtual DOTInheritedAttribute evaluateInheritedAttribute(SgNode* node, DOTInheritedAttribute ia);
00227           virtual DOTSynthesizedAttribute evaluateSynthesizedAttribute(SgNode* node, DOTInheritedAttribute ia, SubTreeSynthesizedAttributes l);
00228    };
00229 
00230 #endif
00231 

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