18#include "llvm/ADT/PriorityQueue.h"
23#include <unordered_set>
36 Mapping(Mapping &&
Other) =
default;
37 Mapping &operator=(Mapping &&
Other) =
default;
39 Mapping(
size_t Size) {
40 SrcToDst = std::make_unique<NodeId[]>(Size);
41 DstToSrc = std::make_unique<NodeId[]>(Size);
44 void link(NodeId Src, NodeId Dst) {
45 SrcToDst[Src] = Dst, DstToSrc[Dst] = Src;
48 NodeId getDst(NodeId Src)
const {
return SrcToDst[Src]; }
49 NodeId getSrc(NodeId Dst)
const {
return DstToSrc[Dst]; }
50 bool hasSrc(NodeId Src)
const {
return getDst(Src).isValid(); }
51 bool hasDst(NodeId Dst)
const {
return getSrc(Dst).isValid(); }
54 std::unique_ptr<NodeId[]> SrcToDst, DstToSrc;
76 assert(&*Tree == &
T2 &&
"Invalid tree.");
88 bool haveSameParents(
const Mapping &M,
NodeId Id1,
NodeId Id2)
const;
92 void addOptimalMapping(Mapping &M,
NodeId Id1,
NodeId Id2)
const;
96 double getJaccardSimilarity(
const Mapping &M,
NodeId Id1,
NodeId Id2)
const;
99 NodeId findCandidate(
const Mapping &M,
NodeId Id1)
const;
102 Mapping matchTopDown()
const;
105 void matchBottomUp(Mapping &M)
const;
162 void setLeftMostDescendants();
178 if (!
SrcMgr.isInMainFile(SLoc))
181 if (SLoc !=
SrcMgr.getSpellingLoc(SLoc))
190 int Id = 0, Depth = 0;
192 SyntaxTree::Impl &Tree;
194 PreorderVisitor(SyntaxTree::Impl &Tree) : Tree(Tree) {}
196 template <
class T> std::tuple<NodeId, NodeId> PreTraverse(T *ASTNode) {
198 Tree.Nodes.emplace_back();
199 Node &N = Tree.getMutableNode(MyId);
203 assert(!N.ASTNode.getNodeKind().isNone() &&
204 "Expected nodes to have a valid kind.");
205 if (Parent.isValid()) {
206 Node &P = Tree.getMutableNode(Parent);
207 P.Children.push_back(MyId);
212 return std::make_tuple(MyId, Tree.getNode(MyId).Parent);
214 void PostTraverse(std::tuple<NodeId, NodeId> State) {
215 NodeId MyId, PreviousParent;
216 std::tie(MyId, PreviousParent) = State;
217 assert(MyId.isValid() &&
"Expecting to only traverse valid nodes.");
218 Parent = PreviousParent;
220 Node &N = Tree.getMutableNode(MyId);
221 N.RightMostDescendant = Id - 1;
222 assert(N.RightMostDescendant >= 0 &&
223 N.RightMostDescendant < Tree.getSize() &&
224 "Rightmost descendant must be a valid tree node.");
226 Tree.Leaves.push_back(MyId);
228 for (NodeId Child : N.Children)
229 N.Height = std::max(N.Height, 1 + Tree.getNode(Child).Height);
231 bool TraverseDecl(Decl *D) {
234 auto SavedState = PreTraverse(D);
236 PostTraverse(SavedState);
239 bool TraverseStmt(Stmt *S) {
240 if (
auto *E = dyn_cast_or_null<Expr>(S))
241 S = E->IgnoreImplicit();
244 auto SavedState = PreTraverse(S);
246 PostTraverse(SavedState);
249 bool TraverseType(QualType T,
bool TraverseQualifier =
true) {
return true; }
250 bool TraverseConstructorInitializer(CXXCtorInitializer *
Init) {
253 auto SavedState = PreTraverse(
Init);
255 PostTraverse(SavedState);
263 TypePP.AnonymousTagNameStyle =
269 PreorderVisitor PreorderWalker(*
this);
270 PreorderWalker.TraverseDecl(N);
276 PreorderVisitor PreorderWalker(*
this);
277 PreorderWalker.TraverseStmt(N);
283 std::vector<NodeId> Postorder;
288 Postorder.push_back(Id);
296 std::vector<NodeId> Ids;
299 while (Expanded < Ids.size())
301 Ids.push_back(Child);
305void SyntaxTree::Impl::initTree() {
306 setLeftMostDescendants();
308 PostorderIds.resize(
getSize());
309 std::function<void(NodeId)> PostorderTraverse = [&](NodeId Id) {
311 PostorderTraverse(Child);
312 PostorderIds[Id] = PostorderId;
319void SyntaxTree::Impl::setLeftMostDescendants() {
320 for (NodeId Leaf : Leaves) {
321 getMutableNode(Leaf).LeftMostDescendant = Leaf;
322 NodeId Parent, Cur = Leaf;
323 while ((Parent =
getNode(Cur).Parent).isValid() &&
326 getMutableNode(Cur).LeftMostDescendant = Leaf;
345 for (
size_t I = 0, E = Siblings.size(); I < E; ++I) {
348 if (Siblings[I] == Id) {
353 llvm_unreachable(
"Node not found in parent's children.");
362 std::string ContextPrefix;
365 if (
auto *Namespace = dyn_cast<NamespaceDecl>(Context))
366 ContextPrefix = Namespace->getQualifiedNameAsString();
367 else if (
auto *
Record = dyn_cast<RecordDecl>(Context))
368 ContextPrefix =
Record->getQualifiedNameAsString();
369 else if (
AST.getLangOpts().CPlusPlus11)
370 if (
auto *Tag = dyn_cast<TagDecl>(Context))
371 ContextPrefix = Tag->getQualifiedNameAsString();
375 if (!ContextPrefix.empty() && StringRef(Val).starts_with(ContextPrefix))
376 Val = Val.substr(ContextPrefix.size() + 1);
390 const auto &P = Parents[0];
391 if (
const auto *D = P.get<
Decl>())
400 if (
Init->isAnyMemberInitializer())
401 return std::string(
Init->getAnyMember()->getName());
402 if (
Init->isBaseInitializer())
404 if (
Init->isDelegatingInitializer())
405 return Init->getTypeSourceInfo()->getType().getAsString(TypePP);
406 llvm_unreachable(
"Unknown initializer type");
421 llvm_unreachable(
"Fatal: unhandled AST node.\n");
426 if (
auto *
V = dyn_cast<ValueDecl>(D))
428 if (
auto *N = dyn_cast<NamedDecl>(D))
430 if (
auto *T = dyn_cast<TypedefNameDecl>(D))
431 return Value + T->getUnderlyingType().getAsString(
TypePP) +
";";
432 if (
auto *T = dyn_cast<TypeDecl>(D)) {
438 if (
auto *
U = dyn_cast<UsingDirectiveDecl>(D))
439 return std::string(
U->getNominatedNamespace()->getName());
440 if (
auto *A = dyn_cast<AccessSpecDecl>(D)) {
449 if (
auto *
U = dyn_cast<UnaryOperator>(S))
451 if (
auto *B = dyn_cast<BinaryOperator>(S))
452 return std::string(B->getOpcodeStr());
453 if (
auto *M = dyn_cast<MemberExpr>(S))
455 if (
auto *I = dyn_cast<IntegerLiteral>(S)) {
457 I->getValue().toString(Str, 10,
false);
458 return std::string(Str);
460 if (
auto *F = dyn_cast<FloatingLiteral>(S)) {
462 F->getValue().toString(Str);
463 return std::string(Str);
465 if (
auto *D = dyn_cast<DeclRefExpr>(S))
467 if (
auto *String = dyn_cast<StringLiteral>(S))
468 return std::string(String->getString());
469 if (
auto *B = dyn_cast<CXXBoolLiteralExpr>(S))
470 return B->getValue() ?
"true" :
"false";
492 std::vector<NodeId> RootIds;
494 std::vector<SNodeId> LeftMostDescendants;
501 int NumLeaves = setLeftMostDescendants();
502 computeKeyRoots(NumLeaves);
504 int getSize()
const {
return RootIds.size(); }
506 assert(Id > 0 && Id <=
getSize() &&
"Invalid subtree node index.");
507 return RootIds[Id - 1];
513 assert(Id > 0 && Id <=
getSize() &&
"Invalid subtree node index.");
514 return LeftMostDescendants[Id - 1];
526 int setLeftMostDescendants() {
528 LeftMostDescendants.resize(getSize());
529 for (
int I = 0; I < getSize(); ++I) {
533 assert(I == Tree.
PostorderIds[getIdInRoot(SI)] - getPostorderOffset() &&
534 "Postorder traversal in subtree should correspond to traversal in "
535 "the root tree by a constant offset.");
537 getPostorderOffset());
541 void computeKeyRoots(
int Leaves) {
542 KeyRoots.resize(Leaves);
543 std::unordered_set<int> Visited;
545 for (SNodeId I(getSize()); I > 0; --I) {
546 SNodeId LeftDesc = getLeftMostDescendant(I);
547 if (Visited.count(LeftDesc))
549 assert(K >= 0 &&
"K should be non-negative");
551 Visited.insert(LeftDesc);
564 std::unique_ptr<std::unique_ptr<double[]>[]> TreeDist, ForestDist;
569 : DiffImpl(DiffImpl), S1(T1, Id1), S2(T2, Id2) {
570 TreeDist = std::make_unique<std::unique_ptr<double[]>[]>(
571 size_t(S1.getSize()) + 1);
572 ForestDist = std::make_unique<std::unique_ptr<double[]>[]>(
573 size_t(S1.getSize()) + 1);
574 for (
int I = 0, E = S1.getSize() + 1; I < E; ++I) {
575 TreeDist[I] = std::make_unique<double[]>(size_t(S2.getSize()) + 1);
576 ForestDist[I] = std::make_unique<double[]>(size_t(S2.getSize()) + 1);
581 std::vector<std::pair<NodeId, NodeId>> Matches;
582 std::vector<std::pair<SNodeId, SNodeId>> TreePairs;
586 bool RootNodePair =
true;
588 TreePairs.emplace_back(
SNodeId(S1.getSize()),
SNodeId(S2.getSize()));
590 while (!TreePairs.empty()) {
591 SNodeId LastRow, LastCol, FirstRow, FirstCol, Row, Col;
592 std::tie(LastRow, LastCol) = TreePairs.back();
593 TreePairs.pop_back();
596 computeForestDist(LastRow, LastCol);
599 RootNodePair =
false;
601 FirstRow = S1.getLeftMostDescendant(LastRow);
602 FirstCol = S2.getLeftMostDescendant(LastCol);
607 while (Row > FirstRow || Col > FirstCol) {
608 if (Row > FirstRow &&
609 ForestDist[Row - 1][Col] + 1 == ForestDist[Row][Col]) {
611 }
else if (Col > FirstCol &&
612 ForestDist[Row][Col - 1] + 1 == ForestDist[Row][Col]) {
615 SNodeId LMD1 = S1.getLeftMostDescendant(Row);
616 SNodeId LMD2 = S2.getLeftMostDescendant(Col);
617 if (LMD1 == S1.getLeftMostDescendant(LastRow) &&
618 LMD2 == S2.getLeftMostDescendant(LastCol)) {
619 NodeId Id1 = S1.getIdInRoot(Row);
620 NodeId Id2 = S2.getIdInRoot(Col);
621 assert(DiffImpl.isMatchingPossible(Id1, Id2) &&
622 "These nodes must not be matched.");
623 Matches.emplace_back(Id1, Id2);
627 TreePairs.emplace_back(Row, Col);
643 static constexpr double DeletionCost = 1;
644 static constexpr double InsertionCost = 1;
648 return std::numeric_limits<double>::max();
652 void computeTreeDist() {
655 computeForestDist(Id1, Id2);
658 void computeForestDist(SNodeId Id1, SNodeId Id2) {
659 assert(Id1 > 0 && Id2 > 0 &&
"Expecting offsets greater than 0.");
663 ForestDist[LMD1][LMD2] = 0;
664 for (SNodeId D1 = LMD1 + 1; D1 <= Id1; ++D1) {
665 ForestDist[D1][LMD2] = ForestDist[D1 - 1][LMD2] + DeletionCost;
666 for (SNodeId D2 = LMD2 + 1; D2 <= Id2; ++D2) {
667 ForestDist[LMD1][D2] = ForestDist[LMD1][D2 - 1] + InsertionCost;
670 if (DLMD1 == LMD1 && DLMD2 == LMD2) {
671 double UpdateCost = getUpdateCost(D1, D2);
673 std::min({ForestDist[D1 - 1][D2] + DeletionCost,
674 ForestDist[D1][D2 - 1] + InsertionCost,
675 ForestDist[D1 - 1][D2 - 1] + UpdateCost});
676 TreeDist[D1][D2] = ForestDist[D1][D2];
679 std::min({ForestDist[D1 - 1][D2] + DeletionCost,
680 ForestDist[D1][D2 - 1] + InsertionCost,
681 ForestDist[DLMD1][DLMD2] + TreeDist[D1][D2]});
694 if (ND->getDeclName().isIdentifier())
695 return ND->getQualifiedNameAsString();
702 if (ND->getDeclName().isIdentifier())
703 return ND->getName();
713 bool operator()(NodeId Id1, NodeId Id2)
const {
722 const SyntaxTree::Impl &Tree;
724 std::vector<NodeId> Container;
725 PriorityQueue<NodeId, std::vector<NodeId>, HeightLess> List;
728 PriorityList(
const SyntaxTree::Impl &Tree)
729 : Tree(Tree),
Cmp(Tree), List(
Cmp, Container) {}
731 void push(NodeId
id) { List.push(
id); }
733 std::vector<NodeId> pop() {
735 std::vector<NodeId>
Result;
738 while (peekMax() ==
Max) {
739 Result.push_back(List.top());
746 int peekMax()
const {
749 return Tree.getNode(List.top()).Height;
751 void open(NodeId Id) {
752 for (NodeId Child : Tree.getNode(Id).Children)
758bool ASTDiff::Impl::identical(NodeId Id1, NodeId Id2)
const {
759 const Node &N1 = T1.getNode(Id1);
760 const Node &N2 = T2.getNode(Id2);
761 if (N1.Children.size() != N2.Children.size() ||
762 !isMatchingPossible(Id1, Id2) ||
763 T1.getNodeValue(Id1) != T2.getNodeValue(Id2))
765 for (
size_t Id = 0, E = N1.Children.size(); Id < E; ++Id)
766 if (!identical(N1.Children[Id], N2.Children[Id]))
771bool ASTDiff::Impl::isMatchingPossible(NodeId Id1, NodeId Id2)
const {
772 return Options.isMatchingAllowed(T1.getNode(Id1), T2.getNode(Id2));
775bool ASTDiff::Impl::haveSameParents(
const Mapping &M, NodeId Id1,
777 NodeId P1 = T1.getNode(Id1).Parent;
778 NodeId P2 = T2.getNode(Id2).Parent;
779 return (P1.isInvalid() && P2.isInvalid()) ||
780 (P1.isValid() && P2.isValid() && M.getDst(P1) == P2);
783void ASTDiff::Impl::addOptimalMapping(Mapping &M, NodeId Id1,
785 if (std::max(T1.getNumberOfDescendants(Id1), T2.getNumberOfDescendants(Id2)) >
788 ZhangShashaMatcher Matcher(*
this, T1, T2, Id1, Id2);
789 std::vector<std::pair<NodeId, NodeId>>
R = Matcher.getMatchingNodes();
790 for (
const auto &Tuple : R) {
791 NodeId Src = Tuple.first;
792 NodeId Dst = Tuple.second;
793 if (!M.hasSrc(Src) && !M.hasDst(Dst))
798double ASTDiff::Impl::getJaccardSimilarity(
const Mapping &M, NodeId Id1,
800 int CommonDescendants = 0;
801 const Node &N1 = T1.getNode(Id1);
803 for (NodeId Src = Id1 + 1; Src <= N1.RightMostDescendant; ++Src) {
804 NodeId Dst = M.getDst(Src);
805 CommonDescendants +=
int(Dst.isValid() && T2.isInSubtree(Dst, Id2));
808 double Denominator = T1.getNumberOfDescendants(Id1) - 1 +
809 T2.getNumberOfDescendants(Id2) - 1 - CommonDescendants;
811 assert(Denominator >= 0 &&
"Expected non-negative denominator.");
812 if (Denominator == 0)
814 return CommonDescendants / Denominator;
817NodeId ASTDiff::Impl::findCandidate(
const Mapping &M, NodeId Id1)
const {
819 double HighestSimilarity = 0.0;
820 for (NodeId Id2 : T2) {
821 if (!isMatchingPossible(Id1, Id2))
825 double Similarity = getJaccardSimilarity(M, Id1, Id2);
826 if (Similarity >= Options.MinSimilarity && Similarity > HighestSimilarity) {
827 HighestSimilarity = Similarity;
834void ASTDiff::Impl::matchBottomUp(Mapping &M)
const {
836 for (NodeId Id1 : Postorder) {
837 if (Id1 == T1.getRootId() && !M.hasSrc(T1.getRootId()) &&
838 !M.hasDst(T2.getRootId())) {
839 if (isMatchingPossible(T1.getRootId(), T2.getRootId())) {
840 M.link(T1.getRootId(), T2.getRootId());
841 addOptimalMapping(M, T1.getRootId(), T2.getRootId());
845 bool Matched = M.hasSrc(Id1);
846 const Node &N1 = T1.getNode(Id1);
847 bool MatchedChildren = llvm::any_of(
848 N1.Children, [&](NodeId Child) { return M.hasSrc(Child); });
849 if (Matched || !MatchedChildren)
851 NodeId Id2 = findCandidate(M, Id1);
854 addOptimalMapping(M, Id1, Id2);
859Mapping ASTDiff::Impl::matchTopDown()
const {
863 Mapping M(T1.getSize() + T2.getSize());
865 L1.push(T1.getRootId());
866 L2.push(T2.getRootId());
869 while (std::min(Max1 = L1.peekMax(), Max2 = L2.peekMax()) >
872 for (NodeId Id : L1.pop())
877 for (NodeId Id : L2.pop())
881 std::vector<NodeId> H1, H2;
884 for (NodeId Id1 : H1) {
885 for (NodeId Id2 : H2) {
886 if (identical(Id1, Id2) && !M.hasSrc(Id1) && !M.hasDst(Id2)) {
887 for (
int I = 0, E = T1.getNumberOfDescendants(Id1); I < E; ++I)
888 M.link(Id1 + I, Id2 + I);
892 for (NodeId Id1 : H1) {
896 for (NodeId Id2 : H2) {
906 :
T1(
T1),
T2(
T2), Options(Options) {
913 if (Options.StopAfterTopDown)
920 if (!M.hasSrc(Id1)) {
921 T1.getMutableNode(Id1).Change =
Delete;
922 T1.getMutableNode(Id1).Shift -= 1;
926 if (!M.hasDst(Id2)) {
927 T2.getMutableNode(Id2).Change =
Insert;
928 T2.getMutableNode(Id2).Shift -= 1;
932 NodeId Id2 = M.getDst(Id1);
935 if (!haveSameParents(M, Id1, Id2) ||
936 T1.findPositionInParent(Id1,
true) !=
937 T2.findPositionInParent(Id2,
true)) {
938 T1.getMutableNode(Id1).Shift -= 1;
939 T2.getMutableNode(Id2).Shift -= 1;
943 NodeId Id1 = M.getSrc(Id2);
946 Node &N1 =
T1.getMutableNode(Id1);
947 Node &N2 =
T2.getMutableNode(Id2);
950 if (!haveSameParents(M, Id1, Id2) ||
951 T1.findPositionInParent(Id1,
true) !=
952 T2.findPositionInParent(Id2,
true)) {
955 if (
T1.getNodeValue(Id1) !=
T2.getNodeValue(Id2)) {
963 : DiffImpl(
std::make_unique<
Impl>(*T1.TreeImpl, *T2.TreeImpl, Options)) {}
968 return DiffImpl->getMapped(SourceTree.
TreeImpl, Id);
973 this, AST.getTranslationUnitDecl(), AST)) {}
991 return TreeImpl->findPositionInParent(Id);
994std::pair<unsigned, unsigned>
1002 if (ThisExpr->isImplicit())
1005 unsigned Begin =
SrcMgr.getFileOffset(
SrcMgr.getExpansionLoc(BeginLoc));
1006 unsigned End =
SrcMgr.getFileOffset(
SrcMgr.getExpansionLoc(EndLoc));
1007 return {Begin, End};
llvm::MachO::Record Record
static Expected< DynTypedNode > getNode(const ast_matchers::BoundNodes &Nodes, StringRef ID)
Defines the SourceManager interface.
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
DynTypedNodeList getParents(const NodeT &Node)
Forwards to get node parents from the ParentMapContext.
QualType getTypeDeclType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, const TypeDecl *Decl) const
Represents a C++ base or member initializer.
bool isWritten() const
Determine whether this initializer is explicitly written in the source code.
Represents the this expression in C++.
Represents a byte-granular source range.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Decl - This represents one declaration (or definition), e.g.
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
DeclContext * getDeclContext()
const T * get() const
Retrieve the stored node as type T.
static DynTypedNode create(const T &Node)
Creates a DynTypedNode from Node.
static StringRef getSourceText(CharSourceRange Range, const SourceManager &SM, const LangOptions &LangOpts, bool *Invalid=nullptr)
Returns a string for the source that the range encompasses.
static SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset, const SourceManager &SM, const LangOptions &LangOpts)
Computes the source location just past the end of the token at this source location.
This represents a decl that may have a name.
std::string getQualifiedNameAsString() const
A (possibly-)qualified type.
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
bool TraverseStmt(Stmt *S, DataRecursionQueue *Queue=nullptr)
Recursively visit a statement or expression, by dispatching to Traverse*() based on the argument's dy...
bool TraverseDecl(Decl *D)
Recursively visit a declaration, by dispatching to Traverse*Decl() based on the argument's dynamic ty...
bool TraverseConstructorInitializer(CXXCtorInitializer *Init)
Recursively visit a constructor initializer.
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
This class handles loading and caching of source files into memory.
A trivial tuple used to represent a source range.
Stmt - This represents one statement.
QualType getCanonicalTypeInternal() const
static StringRef getOpcodeStr(Opcode Op)
getOpcodeStr - Turn an Opcode enum value into the punctuation char it corresponds to,...
void computeChangeKinds(Mapping &M)
NodeId getMapped(const std::unique_ptr< SyntaxTree::Impl > &Tree, NodeId Id) const
Impl(SyntaxTree::Impl &T1, SyntaxTree::Impl &T2, const ComparisonOptions &Options)
friend class ZhangShashaMatcher
void computeMapping()
Matches nodes one-by-one based on their similarity.
ASTDiff(SyntaxTree &Src, SyntaxTree &Dst, const ComparisonOptions &Options)
NodeId getMapped(const SyntaxTree &SourceTree, NodeId Id) const
const Node & getNode(SNodeId Id) const
SNodeId getLeftMostDescendant(SNodeId Id) const
Subtree(const SyntaxTree::Impl &Tree, NodeId SubtreeRoot)
std::vector< SNodeId > KeyRoots
NodeId getPostorderOffset() const
Returns the postorder index of the leftmost descendant in the subtree.
NodeId getIdInRoot(SNodeId Id) const
std::string getNodeValue(SNodeId Id) const
Represents the AST of a TranslationUnit.
std::string getRelativeName(const NamedDecl *ND, const DeclContext *Context) const
int getNumberOfDescendants(NodeId Id) const
bool isValidNodeId(NodeId Id) const
std::vector< NodeId > Leaves
bool isInSubtree(NodeId Id, NodeId SubtreeRoot) const
PreorderIterator begin() const
std::vector< Node > Nodes
Nodes in preorder.
PreorderIterator end() const
int findPositionInParent(NodeId Id, bool Shifted=false) const
const Node & getNode(NodeId Id) const
std::string getStmtValue(const Stmt *S) const
std::vector< int > PostorderIds
std::string getNodeValue(NodeId Id) const
Impl(SyntaxTree *Parent, std::enable_if_t< std::is_base_of_v< Decl, T >, T > *Node, ASTContext &AST)
Impl(SyntaxTree *Parent, std::enable_if_t< std::is_base_of_v< Stmt, T >, T > *Node, ASTContext &AST)
std::string getDeclValue(const Decl *D) const
std::vector< NodeId > NodesBfs
Impl(SyntaxTree *Parent, ASTContext &AST)
Node & getMutableNode(NodeId Id)
SyntaxTree objects represent subtrees of the AST.
const Node & getNode(NodeId Id) const
int findPositionInParent(NodeId Id) const
const ASTContext & getASTContext() const
PreorderIterator begin() const
std::pair< unsigned, unsigned > getSourceRangeOffsets(const Node &N) const
SyntaxTree(ASTContext &AST)
Constructs a tree from a translation unit.
std::unique_ptr< Impl > TreeImpl
PreorderIterator end() const
std::string getNodeValue(NodeId Id) const
Serialize the node attributes to a string representation.
ZhangShashaMatcher(const ASTDiff::Impl &DiffImpl, const SyntaxTree::Impl &T1, const SyntaxTree::Impl &T2, NodeId Id1, NodeId Id2)
std::vector< std::pair< NodeId, NodeId > > getMatchingNodes()
Public enums and private classes that are part of the SourceManager implementation.
static bool isSpecializedNodeExcluded(const Decl *D)
static const DeclContext * getEnclosingDeclContext(ASTContext &AST, const Stmt *S)
static std::vector< NodeId > getSubtreePostorder(const SyntaxTree::Impl &Tree, NodeId Root)
DynTypedNode DynTypedNode
static std::vector< NodeId > getSubtreeBfs(const SyntaxTree::Impl &Tree, NodeId Root)
static bool isNodeExcluded(const SourceManager &SrcMgr, T *N)
static std::string getInitializerValue(const CXXCtorInitializer *Init, const PrintingPolicy &TypePP)
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.
@ Other
Other implicit parameter.
bool link(llvm::ArrayRef< const char * > args, llvm::raw_ostream &stdoutOS, llvm::raw_ostream &stderrOS, bool exitEarly, bool disableOutput)
Diagnostic wrappers for TextAPI types for error reporting.
int const char * function
Describes how types, statements, expressions, and declarations should be printed.
@ Plain
E.g., (anonymous enum)/(unnamed struct)/etc.
Within a tree, this identifies a node by its preorder offset.
Represents a Clang AST node, alongside some additional information.
NodeId RightMostDescendant
std::optional< std::string > getQualifiedIdentifier() const
std::optional< StringRef > getIdentifier() const
ASTNodeKind getType() const
NodeId LeftMostDescendant
StringRef getTypeLabel() const
SmallVector< NodeId, 4 > Children
Identifies a node in a subtree by its postorder offset, starting at 1.
SNodeId operator+(int Other) const