1 #ifndef ROSE_EditDistance_TreeEditDistance_H 
    2 #define ROSE_EditDistance_TreeEditDistance_H 
    4 #include <Rose/Diagnostics.h> 
    6 #include <boost/graph/adjacency_list.hpp> 
    7 #include <boost/graph/graph_traits.hpp> 
   14 namespace EditDistance {                                
 
   45 namespace TreeEditDistance {
 
   48 #if defined(INSERT) || defined(DELETE) || defined(SUBSTITUTE) 
   50 #  pragma message("Undefining common words from the global namespace: INSERT DELETE SUBSTITUTE") 
   52 #  warning "Undefining common words from the global namespace: INSERT DELETE SUBSTITUTE" 
   74     void print(std::ostream&) 
const;
 
   78 typedef std::vector<Edit> 
Edits;
 
   97     typedef boost::property<boost::edge_weight_t, double> EdgeProperty;
 
   98     typedef boost::adjacency_list<boost::listS,         
 
  104     typedef boost::graph_traits<Graph>::vertex_descriptor 
Vertex;
 
  105     typedef std::pair<size_t, size_t> 
Edge;             
 
  107     double insertionCost_;                              
 
  108     double deletionCost_;                               
 
  109     double substitutionCost_;                           
 
  112     std::vector<SgNode*> nodes1_, nodes2_;              
 
  113     std::vector<size_t> depths1_, depths2_;             
 
  115     std::vector<double> totalCost_;                     
 
  116     std::vector<Vertex> predecessors_;                  
 
  122         : insertionCost_(1.0), deletionCost_(1.0), substitutionCost_(1.0), ast1_(NULL), ast2_(NULL),
 
  123           substitutionPredicate_(NULL)  {}
 
  130         ast1_ = ast2_ = NULL;
 
  131         nodes1_.clear(), nodes2_.clear();
 
  132         depths1_.clear(), depths2_.clear();
 
  134         totalCost_.clear(), predecessors_.clear();
 
  144         return insertionCost_;
 
  147         ASSERT_require(weight >= 0.0);
 
  148         insertionCost_ = weight;
 
  159         return deletionCost_;
 
  162         ASSERT_require(weight >= 0.0);
 
  163         deletionCost_ = weight;
 
  174         return substitutionCost_;
 
  177         ASSERT_require(weight >= 0.0);
 
  178         substitutionCost_ = weight;
 
  191         return substitutionPredicate_;
 
  194         substitutionPredicate_ = predicate;
 
  253     std::pair<SgNode*, SgNode*> 
trees()
 const {
 
  254         return std::make_pair(ast1_, ast2_);
 
  272     std::pair<size_t, size_t> 
graphSize() 
const;
 
 
@ DELETE
Delete a node from this tree.
 
@ INSERT
Insert a node from another tree.
 
Analysis object for tree edit distance.
 
virtual bool operator()(SgNode *source, SgNode *target)=0
Returns true if target can be substituted for source.
 
double insertionCost() const
Property: insertion cost.
 
double relativeCost() const
Relative cost.
 
Analysis & clear()
Forget calculated results.
 
Analysis & deletionCost(double weight)
Property: deletion cost.
 
std::pair< SgNode *, SgNode * > trees() const
The two trees that were compared.
 
This class represents a source file for a project (which may contian many source files and or directo...
 
Analysis & compute()
Compute tree edit distances.
 
EditType editType
Type of operation performed.
 
SgNode * sourceNode
Node in source tree to be replaced or deleted.
 
double deletionCost() const
Property: deletion cost.
 
double cost
Cost for this operation.
 
Edits edits() const
Edit operations to make one path look like another.
 
Analysis & setTree1(SgNode *ast, SgFile *file=NULL)
Change one tree or the other.
 
SgNode * targetNode
Node in target tree for replacement or insertion.
 
Analysis & substitutionCost(double weight)
Property: substitution cost.
 
Base class for substitution prediates.
 
double substitutionCost() const
Property: substitution cost.
 
void emitGraphViz(std::ostream &) const
Emit a GraphViz file.
 
const std::vector< SgNode * > & targetTreeNodes() const
List of nodes in the trees.
 
const std::vector< SgNode * > & sourceTreeNodes() const
List of nodes in the trees.
 
double cost() const
Total cost for making one tree the same shape as the other.
 
This class represents the base class for all IR nodes within Sage III.
 
Analysis & setTree2(SgNode *ast, SgFile *file=NULL)
Change one tree or the other.
 
Main namespace for the ROSE library.
 
Analysis & substitutionPredicate(SubstitutionPredicate *predicate)
Property: substitution predicate.
 
std::vector< Edit > Edits
List of edit operations.
 
@ SUBSTITUTE
Substitute a node; same as an insert-delete pair.
 
Analysis & insertionCost(double weight)
Property: insertion cost.
 
EditType
Type of edit operation.
 
std::pair< size_t, size_t > graphSize() const
Number of vertices and edges in the graph.
 
Analysis()
Construct an analysis with default values.
 
SubstitutionPredicate * substitutionPredicate() const
Property: substitution predicate.