Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 0c78c57

Browse files
committed
Revert "[clang-diff] Move printing of matches and changes to clang-diff"
This reverts commit r311200, it was causing widespread build failures. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@311210 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent ee444f1 commit 0c78c57

File tree

5 files changed

+227
-247
lines changed

5 files changed

+227
-247
lines changed

include/clang/Tooling/ASTDiff/ASTDiff.h

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,37 @@
2525
namespace clang {
2626
namespace diff {
2727

28+
/// This represents a match between two nodes in the source and destination
29+
/// trees, meaning that they are likely to be related.
30+
struct Match {
31+
NodeId Src, Dst;
32+
};
33+
2834
enum ChangeKind {
29-
None,
30-
Delete, // (Src): delete node Src.
31-
Update, // (Src, Dst): update the value of node Src to match Dst.
32-
Insert, // (Src, Dst, Pos): insert Src as child of Dst at offset Pos.
33-
Move, // (Src, Dst, Pos): move Src to be a child of Dst at offset Pos.
34-
UpdateMove // Same as Move plus Update.
35+
Delete, // (Src): delete node Src.
36+
Update, // (Src, Dst): update the value of node Src to match Dst.
37+
Insert, // (Src, Dst, Pos): insert Src as child of Dst at offset Pos.
38+
Move // (Src, Dst, Pos): move Src to be a child of Dst at offset Pos.
39+
};
40+
41+
struct Change {
42+
ChangeKind Kind;
43+
NodeId Src, Dst;
44+
size_t Position;
45+
46+
Change(ChangeKind Kind, NodeId Src, NodeId Dst, size_t Position)
47+
: Kind(Kind), Src(Src), Dst(Dst), Position(Position) {}
48+
Change(ChangeKind Kind, NodeId Src) : Kind(Kind), Src(Src) {}
49+
Change(ChangeKind Kind, NodeId Src, NodeId Dst)
50+
: Kind(Kind), Src(Src), Dst(Dst) {}
3551
};
3652

3753
/// Represents a Clang AST node, alongside some additional information.
3854
struct Node {
3955
NodeId Parent, LeftMostDescendant, RightMostDescendant;
40-
int Depth, Height, Shift = 0;
56+
int Depth, Height;
4157
ast_type_traits::DynTypedNode ASTNode;
4258
SmallVector<NodeId, 4> Children;
43-
ChangeKind ChangeKind = None;
4459

4560
ast_type_traits::ASTNodeKind getType() const;
4661
StringRef getTypeLabel() const;
@@ -52,8 +67,15 @@ class ASTDiff {
5267
ASTDiff(SyntaxTree &Src, SyntaxTree &Dst, const ComparisonOptions &Options);
5368
~ASTDiff();
5469

55-
// Returns the ID of the node that is mapped to the given node in SourceTree.
56-
NodeId getMapped(const SyntaxTree &SourceTree, NodeId Id) const;
70+
// Returns a list of matches.
71+
std::vector<Match> getMatches();
72+
/// Returns an edit script.
73+
std::vector<Change> getChanges();
74+
75+
// Prints an edit action.
76+
void printChange(raw_ostream &OS, const Change &Chg) const;
77+
// Prints a match between two nodes.
78+
void printMatch(raw_ostream &OS, const Match &M) const;
5779

5880
class Impl;
5981

@@ -77,23 +99,16 @@ class SyntaxTree {
7799
const ASTContext &getASTContext() const;
78100
StringRef getFilename() const;
79101

80-
int getSize() const;
81-
NodeId getRootId() const;
82-
using PreorderIterator = NodeId;
83-
PreorderIterator begin() const;
84-
PreorderIterator end() const;
85-
86102
const Node &getNode(NodeId Id) const;
87-
int findPositionInParent(NodeId Id) const;
103+
NodeId getRootId() const;
88104

89105
// Returns the starting and ending offset of the node in its source file.
90106
std::pair<unsigned, unsigned> getSourceRangeOffsets(const Node &N) const;
91107

92108
/// Serialize the node attributes to a string representation. This should
93109
/// uniquely distinguish nodes of the same kind. Note that this function just
94110
/// returns a representation of the node value, not considering descendants.
95-
std::string getNodeValue(NodeId Id) const;
96-
std::string getNodeValue(const Node &Node) const;
111+
std::string getNodeValue(const DynTypedNode &DTN) const;
97112

98113
class Impl;
99114
std::unique_ptr<Impl> TreeImpl;
@@ -116,8 +131,8 @@ struct ComparisonOptions {
116131
bool EnableMatchingWithUnmatchableParents = false;
117132

118133
/// Returns false if the nodes should never be matched.
119-
bool isMatchingAllowed(const Node &N1, const Node &N2) const {
120-
return N1.getType().isSame(N2.getType());
134+
bool isMatchingAllowed(const DynTypedNode &N1, const DynTypedNode &N2) const {
135+
return N1.getNodeKind().isSame(N2.getNodeKind());
121136
}
122137
};
123138

include/clang/Tooling/ASTDiff/ASTDiffInternal.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ struct NodeId {
3636
operator int() const { return Id; }
3737
NodeId &operator++() { return ++Id, *this; }
3838
NodeId &operator--() { return --Id, *this; }
39-
// Support defining iterators on NodeId.
40-
NodeId &operator*() { return *this; }
4139

4240
bool isValid() const { return Id != InvalidNodeId; }
4341
bool isInvalid() const { return Id == InvalidNodeId; }

0 commit comments

Comments
 (0)