[clang-tools-extra] fd299a7 - [clangd] Remove the IncludeStructure::isSelfContained API.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 13 04:42:02 PDT 2023


Author: Haojian Wu
Date: 2023-03-13T12:37:38+01:00
New Revision: fd299a7880ae80911001590242e2cbdb55f24a37

URL: https://github.com/llvm/llvm-project/commit/fd299a7880ae80911001590242e2cbdb55f24a37
DIFF: https://github.com/llvm/llvm-project/commit/fd299a7880ae80911001590242e2cbdb55f24a37.diff

LOG: [clangd] Remove the IncludeStructure::isSelfContained API.

This API was merely used in the old unused-include implementation, with
the removal, this API is not used anymore.

Differential Revision: https://reviews.llvm.org/D145917

Added: 
    

Modified: 
    clang-tools-extra/clangd/Headers.cpp
    clang-tools-extra/clangd/Headers.h
    clang-tools-extra/clangd/unittests/HeadersTests.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/Headers.cpp b/clang-tools-extra/clangd/Headers.cpp
index 35525a73a2fe..8a71f0ece17c 100644
--- a/clang-tools-extra/clangd/Headers.cpp
+++ b/clang-tools-extra/clangd/Headers.cpp
@@ -105,17 +105,6 @@ class IncludeStructure::RecordHeaders : public PPCallbacks {
       --Level;
       if (PrevFID == BuiltinFile)
         InBuiltinFile = false;
-      // At file exit time HeaderSearchInfo is valid and can be used to
-      // determine whether the file was a self-contained header or not.
-      if (const FileEntry *FE = SM.getFileEntryForID(PrevFID)) {
-        // isSelfContainedHeader only returns true once the full header-guard
-        // structure has been seen, i.e. when exiting the *outer* copy of the
-        // file. So last result wins.
-        if (tooling::isSelfContainedHeader(FE, SM, HeaderInfo))
-          Out->NonSelfContained.erase(*Out->getID(FE));
-        else
-          Out->NonSelfContained.insert(*Out->getID(FE));
-      }
       break;
     }
     case PPCallbacks::RenameFile:

diff  --git a/clang-tools-extra/clangd/Headers.h b/clang-tools-extra/clangd/Headers.h
index 8abea21a98e0..f6aeab1dbfd3 100644
--- a/clang-tools-extra/clangd/Headers.h
+++ b/clang-tools-extra/clangd/Headers.h
@@ -150,10 +150,6 @@ class IncludeStructure {
     return RealPathNames[static_cast<unsigned>(ID)];
   }
 
-  bool isSelfContained(HeaderID ID) const {
-    return !NonSelfContained.contains(ID);
-  }
-
   // Return all transitively reachable files.
   llvm::ArrayRef<std::string> allHeaders() const { return RealPathNames; }
 
@@ -196,9 +192,6 @@ class IncludeStructure {
   // and RealPathName and UniqueID are not preserved in
   // the preamble.
   llvm::DenseMap<llvm::sys::fs::UniqueID, HeaderID> UIDToIndex;
-  // Contains HeaderIDs of all non self-contained entries in the
-  // IncludeStructure.
-  llvm::DenseSet<HeaderID> NonSelfContained;
 
   // Maps written includes to indices in MainFileInclude for easier lookup by
   // spelling.

diff  --git a/clang-tools-extra/clangd/unittests/HeadersTests.cpp b/clang-tools-extra/clangd/unittests/HeadersTests.cpp
index 728b06db684d..8c0eae6bb3cc 100644
--- a/clang-tools-extra/clangd/unittests/HeadersTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HeadersTests.cpp
@@ -402,48 +402,6 @@ TEST_F(HeadersTest, PresumedLocations) {
               Contains(AllOf(includeLine(2), written("<a.h>"))));
 }
 
-TEST_F(HeadersTest, SelfContainedHeaders) {
-  // Including through non-builtin file has no effects.
-  FS.Files[MainFile] = R"cpp(
-#include "includeguarded.h"
-#include "nonguarded.h"
-#include "pp_depend.h"
-#include "pragmaguarded.h"
-#include "recursive.h"
-)cpp";
-  FS.Files["pragmaguarded.h"] = R"cpp(
-#pragma once
-)cpp";
-  FS.Files["includeguarded.h"] = R"cpp(
-#ifndef INCLUDE_GUARDED_H
-#define INCLUDE_GUARDED_H
-void foo();
-#endif // INCLUDE_GUARDED_H
-)cpp";
-  FS.Files["nonguarded.h"] = R"cpp(
-)cpp";
-  FS.Files["pp_depend.h"] = R"cpp(
-  #ifndef REQUIRED_PP_DIRECTIVE
-  # error You have to have PP directive set to include this one!
-  #endif
-)cpp";
-  FS.Files["recursive.h"] = R"cpp(
-  #ifndef RECURSIVE_H
-  #define RECURSIVE_H
-
-  #include "recursive.h"
-
-  #endif // RECURSIVE_H
-)cpp";
-
-  auto Includes = collectIncludes();
-  EXPECT_TRUE(Includes.isSelfContained(getID("pragmaguarded.h", Includes)));
-  EXPECT_TRUE(Includes.isSelfContained(getID("includeguarded.h", Includes)));
-  EXPECT_TRUE(Includes.isSelfContained(getID("recursive.h", Includes)));
-  EXPECT_FALSE(Includes.isSelfContained(getID("nonguarded.h", Includes)));
-  EXPECT_FALSE(Includes.isSelfContained(getID("pp_depend.h", Includes)));
-}
-
 } // namespace
 } // namespace clangd
 } // namespace clang


        


More information about the cfe-commits mailing list