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"
73 : editType(editType), sourceNode(sourceNode), targetNode(targetNode), cost(cost) {}
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;
Insert a node from another tree.
Delete a node from this tree.
double cost() const
Total cost for making one tree the same shape as the other.
This class represents a source file for a project (which may contian many source files and or directo...
double relativeCost() const
Relative cost.
Analysis & setTree2(SgNode *ast, SgFile *file=NULL)
Change one tree or the other.
std::pair< SgNode *, SgNode * > trees() const
The two trees that were compared.
double deletionCost() const
Property: deletion cost.
Analysis & substitutionPredicate(SubstitutionPredicate *predicate)
Property: substitution predicate.
EditType editType
Type of operation performed.
virtual bool operator()(SgNode *source, SgNode *target)=0
Returns true if target can be substituted for source.
SubstitutionPredicate * substitutionPredicate() const
Property: substitution predicate.
double insertionCost() const
Property: insertion cost.
Main namespace for the ROSE library.
Analysis & insertionCost(double weight)
Property: insertion cost.
Edits edits() const
Edit operations to make one path look like another.
Analysis object for tree edit distance.
Base class for substitution prediates.
Analysis()
Construct an analysis with default values.
const std::vector< SgNode * > & targetTreeNodes() const
List of nodes in the trees.
EditType
Type of edit operation.
This class represents the base class for all IR nodes within Sage III.
void emitGraphViz(std::ostream &) const
Emit a GraphViz file.
Analysis & clear()
Forget calculated results.
std::pair< size_t, size_t > graphSize() const
Number of vertices and edges in the graph.
SgNode * targetNode
Node in target tree for replacement or insertion.
Substitute a node; same as an insert-delete pair.
double substitutionCost() const
Property: substitution cost.
Analysis & deletionCost(double weight)
Property: deletion cost.
Analysis & compute()
Compute tree edit distances.
const std::vector< SgNode * > & sourceTreeNodes() const
List of nodes in the trees.
SgNode * sourceNode
Node in source tree to be replaced or deleted.
Analysis & setTree1(SgNode *ast, SgFile *file=NULL)
Change one tree or the other.
double cost
Cost for this operation.
std::vector< Edit > Edits
List of edit operations.
Analysis & substitutionCost(double weight)
Property: substitution cost.