[PATCH] D39660: [clang-diff] Don't ignore nodes from other files

Johannes Altmanninger via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 5 11:46:45 PST 2017


johannes created this revision.
Herald added a subscriber: klimek.

https://reviews.llvm.org/D39660

Files:
  lib/Tooling/ASTDiff/ASTDiff.cpp
  test/Tooling/clang-diff-ast.cpp
  tools/clang-diff/ClangDiff.cpp


Index: tools/clang-diff/ClangDiff.cpp
===================================================================
--- tools/clang-diff/ClangDiff.cpp
+++ tools/clang-diff/ClangDiff.cpp
@@ -276,6 +276,10 @@
   char MyTag, OtherTag;
   diff::NodeId LeftId, RightId;
   diff::SyntaxTree &Tree = Node.getTree();
+  const SourceManager &SM = Tree.getASTContext().getSourceManager();
+  SourceLocation SLoc = Node.getSourceRange().getBegin();
+  if (SLoc.isValid() && !SM.isInMainFile(SLoc))
+    return Offset;
   const diff::Node *Target = Diff.getMapped(Node);
   diff::NodeId TargetId = Target ? Target->getId() : diff::NodeId();
   if (IsLeft) {
@@ -291,7 +295,6 @@
   }
   unsigned Begin, End;
   std::tie(Begin, End) = Node.getSourceRangeOffsets();
-  const SourceManager &SM = Tree.getASTContext().getSourceManager();
   auto Code = SM.getBuffer(SM.getMainFileID())->getBuffer();
   for (; Offset < Begin; ++Offset)
     printHtml(OS, Code[Offset]);
Index: test/Tooling/clang-diff-ast.cpp
===================================================================
--- test/Tooling/clang-diff-ast.cpp
+++ test/Tooling/clang-diff-ast.cpp
@@ -95,14 +95,14 @@
 #define GUARD
 // CHECK-NEXT: NamespaceDecl(93)
 namespace world {
-// nodes from other files are excluded, there should be no output here
+// CHECK-NEXT: NamespaceDecl
 #include "clang-diff-ast.cpp"
 }
-// CHECK-NEXT: FunctionDecl(94)
+// CHECK: FunctionDecl(197)
 void sentinel();
 #endif
 
-// CHECK: ClassTemplateDecl(97)
+// CHECK: ClassTemplateDecl(200)
 // CHECK-NEXT: TemplateTypeParmDecl
 // CHECK-NEXT: QualType
 // CHECK-NEXT: CXXRecordDecl
Index: lib/Tooling/ASTDiff/ASTDiff.cpp
===================================================================
--- lib/Tooling/ASTDiff/ASTDiff.cpp
+++ lib/Tooling/ASTDiff/ASTDiff.cpp
@@ -203,8 +203,7 @@
     return true;
   SourceLocation SLoc = N->getSourceRange().getBegin();
   if (SLoc.isValid()) {
-    // Ignore everything from other files.
-    if (!SM.isInMainFile(SLoc))
+    if (SM.isInSystemHeader(SLoc))
       return true;
     const Preprocessor &PP = AST.getPreprocessor();
     if (SLoc.isMacroID() && !PP.isAtStartOfMacroExpansion(SLoc))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39660.121653.patch
Type: text/x-patch
Size: 2146 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171105/51a28e8b/attachment.bin>


More information about the cfe-commits mailing list