Skip to content

Commit 3e067d4

Browse files
committed
[include-cleaner] Move vocabulary types into separate header for layering. NFC
1 parent 96482ee commit 3e067d4

File tree

4 files changed

+67
-25
lines changed

4 files changed

+67
-25
lines changed

clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
#ifndef CLANG_INCLUDE_CLEANER_ANALYSIS_H
1212
#define CLANG_INCLUDE_CLEANER_ANALYSIS_H
1313

14-
#include "clang/Tooling/Inclusions/StandardLibrary.h"
14+
#include "clang-include-cleaner/Types.h"
15+
#include "llvm/ADT/ArrayRef.h"
1516
#include "llvm/ADT/STLFunctionalExtras.h"
1617
#include <variant>
1718

@@ -21,30 +22,6 @@ class Decl;
2122
class FileEntry;
2223
namespace include_cleaner {
2324

24-
/// An entity that can be referenced in the code.
25-
struct Symbol {
26-
Symbol(Decl &D) : Storage(&D) {}
27-
Symbol(tooling::stdlib::Symbol S) : Storage(S) {}
28-
29-
private:
30-
// FIXME: Add support for macros.
31-
std::variant<const Decl *, tooling::stdlib::Symbol> Storage;
32-
};
33-
34-
/// Represents a file that provides some symbol. Might not be includeable, e.g.
35-
/// built-in or main-file itself.
36-
struct Header {
37-
/// A physical (or logical, in case of a builtin) file.
38-
Header(const FileEntry *FE) : Storage(FE) {}
39-
/// A logical file representing a stdlib header.
40-
Header(tooling::stdlib::Header H) : Storage(H) {}
41-
42-
bool operator==(const Header &RHS) const { return Storage == RHS.Storage; }
43-
44-
private:
45-
// FIXME: Handle verbatim spellings.
46-
std::variant<const FileEntry *, tooling::stdlib::Header> Storage;
47-
};
4825
/// A UsedSymbolCB is a callback invoked for each symbol reference seen.
4926
///
5027
/// References occur at a particular location, refer to a single symbol, and
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//===--- Types.h - Data structures for used-symbol analysis -------- C++-*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// Find referenced files is mostly a matter of translating:
10+
// AST Node => declaration => source location => file
11+
//
12+
// clang has types for these (DynTypedNode, Decl, SourceLocation, FileID), but
13+
// there are special cases: macros are not declarations, the concrete file where
14+
// a standard library symbol was defined doesn't matter, etc.
15+
//
16+
// We define some slightly more abstract sum types to handle these cases while
17+
// keeping the API clean. For example, Symbol may be a Decl AST node, a macro,
18+
// or a recognized standard library symbol.
19+
//
20+
//===----------------------------------------------------------------------===//
21+
22+
#ifndef CLANG_INCLUDE_CLEANER_RECORD_H
23+
#define CLANG_INCLUDE_CLEANER_RECORD_H
24+
25+
#include "clang/Tooling/Inclusions/StandardLibrary.h"
26+
#include <memory>
27+
#include <vector>
28+
29+
namespace clang {
30+
class Decl;
31+
class FileEntry;
32+
namespace include_cleaner {
33+
34+
/// An entity that can be referenced in the code.
35+
struct Symbol {
36+
Symbol(Decl &D) : Storage(&D) {}
37+
Symbol(tooling::stdlib::Symbol S) : Storage(S) {}
38+
39+
private:
40+
// FIXME: Add support for macros.
41+
std::variant<const Decl *, tooling::stdlib::Symbol> Storage;
42+
};
43+
44+
/// Represents a file that provides some symbol. Might not be includeable, e.g.
45+
/// built-in or main-file itself.
46+
struct Header {
47+
/// A physical (or logical, in case of a builtin) file.
48+
Header(const FileEntry *FE) : Storage(FE) {}
49+
/// A logical file representing a stdlib header.
50+
Header(tooling::stdlib::Header H) : Storage(H) {}
51+
52+
bool operator==(const Header &RHS) const { return Storage == RHS.Storage; }
53+
54+
private:
55+
// FIXME: Handle verbatim spellings.
56+
std::variant<const FileEntry *, tooling::stdlib::Header> Storage;
57+
};
58+
59+
} // namespace include_cleaner
60+
} // namespace clang
61+
62+
#endif
63+

clang-tools-extra/include-cleaner/lib/Analysis.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "clang-include-cleaner/Analysis.h"
10+
#include "clang-include-cleaner/Types.h"
1011
#include "AnalysisInternal.h"
1112
#include "clang/AST/ASTContext.h"
1213
#include "clang/Basic/SourceManager.h"

clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "clang-include-cleaner/Analysis.h"
10+
#include "clang-include-cleaner/Types.h"
1011
#include "clang/AST/ASTContext.h"
1112
#include "clang/Basic/FileManager.h"
1213
#include "clang/Basic/SourceLocation.h"

0 commit comments

Comments
 (0)