1 #ifndef ROSE_EditDistance_LinearEditDistance_H
2 #define ROSE_EditDistance_LinearEditDistance_H
4 #include <EditDistance/Levenshtein.h>
7 namespace EditDistance {
38 namespace LinearEditDistance {
45 unsigned first_, second_;
49 ASSERT_not_null(node);
52 second_ = insn->get_anyKind();
64 return first_==other.first_ && second_==other.second_;
70 template<
class NodeType>
72 std::vector<NodeType> &nodes_;
74 size_t minDepth_, maxDepth_;
77 NodeSelector(std::vector<NodeType> &nodes ,
SgFile *containingFile,
size_t minDepth,
size_t maxDepth)
78 : nodes_(nodes), containingFile_(containingFile), minDepth_(minDepth), maxDepth_(maxDepth) {
79 ASSERT_require(minDepth <= maxDepth);
84 bool isSelected = (depth >= minDepth_ && depth <= maxDepth_ &&
85 (!containingFile_ || (nodeInfo && nodeInfo->isSameFile(containingFile_))));
87 nodes_.push_back(NodeType(node));
103 template<
typename NodeType = Node>
106 std::vector<NodeType> nodes1_, nodes2_;
123 return setTree(ast1_=ast, file, minDepth, maxDepth, nodes1_);
126 return setTree(ast2_=ast, file, minDepth, maxDepth, nodes2_);
144 return compute(target, targetFile);
170 size_t n = std::max(nodes1_.size(), nodes2_.size());
171 return n ? 1.0 * cost_ / n : 1.0 * cost_;
176 Analysis& setTree(
SgNode *ast,
SgFile *file,
size_t minDepth,
size_t maxDepth, std::vector<NodeType> &nodes ) {
179 nodeSelector.traverse(ast, 0);
double relativeCost() const
Relative edit distance.
Analysis & setTree2(SgNode *ast, SgFile *file=NULL, size_t minDepth=0, size_t maxDepth=size_t(-1))
Associate an AST with this analysis.
This class represents a source file for a project (which may contian many source files and or directo...
Base class for machine instructions.
This class represents the location of the code associated with the IR node in the original source cod...
virtual Sg_File_Info * get_file_info(void) const
File information containing filename, line number, column number, and if the SgNode is a part of a ne...
size_t levenshteinDistance(const std::vector< T > &src, const std::vector< T > &tgt)
Levenshtein edit distance.
Analysis & compute()
Compute edit distance.
Main namespace for the ROSE library.
virtual VariantT variantT() const
returns new style SageIII enum values
Node(SgNode *node)
Construct a list node from an AST node.
This class represents the base class for all IR nodes within Sage III.
Analysis & setTree1(SgNode *ast, SgFile *file=NULL, size_t minDepth=0, size_t maxDepth=size_t(-1))
Associate an AST with this analysis.
bool operator==(const Node &other) const
Test two list nodes for equality.
Sawyer::Nothing evaluateSynthesizedAttribute(SgNode *, size_t depth, SubTreeSynthesizedAttributes) override
pure virtual function which must be implemented to compute the synthesized attribute at a node...
size_t evaluateInheritedAttribute(SgNode *node, size_t depth) override
pure virtual function which must be implemented to compute the inherited attribute at a node ...
Analysis & compute(SgNode *source, SgNode *target, SgFile *sourceFile=NULL, SgFile *targetFile=NULL)
Compute edit distance.
Analysis()
Constructs an analysis object with no associated trees.
Analysis & compute(SgNode *target, SgFile *targetFile=NULL)
Compute edit distance.
Type for comparing two AST nodes.
size_t cost() const
Edit distance.