Author: Sam McCall Date: 2022-10-25T19:01:59+02:00 New Revision: 3e067d4e59b73b0eaeda7c369d93a6e18f2cdde8
URL: https://github.com/llvm/llvm-project/commit/3e067d4e59b73b0eaeda7c369d93a6e18f2cdde8 DIFF: https://github.com/llvm/llvm-project/commit/3e067d4e59b73b0eaeda7c369d93a6e18f2cdde8.diff LOG: [include-cleaner] Move vocabulary types into separate header for layering. NFC Added: clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h Modified: clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h clang-tools-extra/include-cleaner/lib/Analysis.cpp clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h b/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h index 0c28119831988..42e619ef4c9bd 100644 --- a/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h +++ b/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h @@ -11,7 +11,8 @@ #ifndef CLANG_INCLUDE_CLEANER_ANALYSIS_H #define CLANG_INCLUDE_CLEANER_ANALYSIS_H -#include "clang/Tooling/Inclusions/StandardLibrary.h" +#include "clang-include-cleaner/Types.h" +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLFunctionalExtras.h" #include <variant> @@ -21,30 +22,6 @@ class Decl; class FileEntry; namespace include_cleaner { -/// An entity that can be referenced in the code. -struct Symbol { - Symbol(Decl &D) : Storage(&D) {} - Symbol(tooling::stdlib::Symbol S) : Storage(S) {} - -private: - // FIXME: Add support for macros. - std::variant<const Decl *, tooling::stdlib::Symbol> Storage; -}; - -/// Represents a file that provides some symbol. Might not be includeable, e.g. -/// built-in or main-file itself. -struct Header { - /// A physical (or logical, in case of a builtin) file. - Header(const FileEntry *FE) : Storage(FE) {} - /// A logical file representing a stdlib header. - Header(tooling::stdlib::Header H) : Storage(H) {} - - bool operator==(const Header &RHS) const { return Storage == RHS.Storage; } - -private: - // FIXME: Handle verbatim spellings. - std::variant<const FileEntry *, tooling::stdlib::Header> Storage; -}; /// A UsedSymbolCB is a callback invoked for each symbol reference seen. /// /// References occur at a particular location, refer to a single symbol, and diff --git a/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h b/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h new file mode 100644 index 0000000000000..45c819a9e0736 --- /dev/null +++ b/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h @@ -0,0 +1,63 @@ +//===--- Types.h - Data structures for used-symbol analysis -------- C++-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// Find referenced files is mostly a matter of translating: +// AST Node => declaration => source location => file +// +// clang has types for these (DynTypedNode, Decl, SourceLocation, FileID), but +// there are special cases: macros are not declarations, the concrete file where +// a standard library symbol was defined doesn't matter, etc. +// +// We define some slightly more abstract sum types to handle these cases while +// keeping the API clean. For example, Symbol may be a Decl AST node, a macro, +// or a recognized standard library symbol. +// +//===----------------------------------------------------------------------===// + +#ifndef CLANG_INCLUDE_CLEANER_RECORD_H +#define CLANG_INCLUDE_CLEANER_RECORD_H + +#include "clang/Tooling/Inclusions/StandardLibrary.h" +#include <memory> +#include <vector> + +namespace clang { +class Decl; +class FileEntry; +namespace include_cleaner { + +/// An entity that can be referenced in the code. +struct Symbol { + Symbol(Decl &D) : Storage(&D) {} + Symbol(tooling::stdlib::Symbol S) : Storage(S) {} + +private: + // FIXME: Add support for macros. + std::variant<const Decl *, tooling::stdlib::Symbol> Storage; +}; + +/// Represents a file that provides some symbol. Might not be includeable, e.g. +/// built-in or main-file itself. +struct Header { + /// A physical (or logical, in case of a builtin) file. + Header(const FileEntry *FE) : Storage(FE) {} + /// A logical file representing a stdlib header. + Header(tooling::stdlib::Header H) : Storage(H) {} + + bool operator==(const Header &RHS) const { return Storage == RHS.Storage; } + +private: + // FIXME: Handle verbatim spellings. + std::variant<const FileEntry *, tooling::stdlib::Header> Storage; +}; + +} // namespace include_cleaner +} // namespace clang + +#endif + diff --git a/clang-tools-extra/include-cleaner/lib/Analysis.cpp b/clang-tools-extra/include-cleaner/lib/Analysis.cpp index 72fac3c9c0084..6b34f81384f15 100644 --- a/clang-tools-extra/include-cleaner/lib/Analysis.cpp +++ b/clang-tools-extra/include-cleaner/lib/Analysis.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "clang-include-cleaner/Analysis.h" +#include "clang-include-cleaner/Types.h" #include "AnalysisInternal.h" #include "clang/AST/ASTContext.h" #include "clang/Basic/SourceManager.h" diff --git a/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp b/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp index ab3e38630faac..dd7cd9d53d7de 100644 --- a/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp +++ b/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "clang-include-cleaner/Analysis.h" +#include "clang-include-cleaner/Types.h" #include "clang/AST/ASTContext.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/SourceLocation.h" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits