clang
20.0.0git
include
clang
Lex
HeaderSearch.h
Go to the documentation of this file.
1
//===- HeaderSearch.h - Resolve Header File Locations -----------*- 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
// This file defines the HeaderSearch interface.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef LLVM_CLANG_LEX_HEADERSEARCH_H
14
#define LLVM_CLANG_LEX_HEADERSEARCH_H
15
16
#include "
clang/Basic/SourceLocation.h
"
17
#include "
clang/Basic/SourceManager.h
"
18
#include "
clang/Lex/DirectoryLookup.h
"
19
#include "
clang/Lex/ExternalPreprocessorSource.h
"
20
#include "
clang/Lex/HeaderMap.h
"
21
#include "
clang/Lex/ModuleMap.h
"
22
#include "llvm/ADT/ArrayRef.h"
23
#include "llvm/ADT/DenseMap.h"
24
#include "llvm/ADT/SmallString.h"
25
#include "llvm/ADT/StringMap.h"
26
#include "llvm/ADT/StringRef.h"
27
#include "llvm/ADT/StringSet.h"
28
#include "llvm/Support/Allocator.h"
29
#include <cassert>
30
#include <cstddef>
31
#include <memory>
32
#include <string>
33
#include <utility>
34
#include <vector>
35
36
namespace
llvm
{
37
38
class
Triple;
39
40
}
// namespace llvm
41
42
namespace
clang
{
43
44
class
DiagnosticsEngine;
45
class
DirectoryEntry;
46
class
ExternalPreprocessorSource;
47
class
FileEntry;
48
class
FileManager;
49
class
HeaderSearch
;
50
class
HeaderSearchOptions;
51
class
IdentifierInfo;
52
class
LangOptions;
53
class
Module
;
54
class
Preprocessor;
55
class
TargetInfo;
56
57
/// The preprocessor keeps track of this information for each
58
/// file that is \#included.
59
struct
HeaderFileInfo
{
60
// TODO: Whether the file was included is not a property of the file itself.
61
// It's a preprocessor state, move it there.
62
/// True if this file has been included (or imported) **locally**.
63
LLVM_PREFERRED_TYPE(
bool
)
64
unsigned
IsLocallyIncluded
: 1;
65
66
// TODO: Whether the file was imported is not a property of the file itself.
67
// It's a preprocessor state, move it there.
68
/// True if this is a \#import'd file.
69
LLVM_PREFERRED_TYPE(
bool
)
70
unsigned
isImport
: 1;
71
72
/// True if this is a \#pragma once file.
73
LLVM_PREFERRED_TYPE(
bool
)
74
unsigned
isPragmaOnce
: 1;
75
76
/// Keep track of whether this is a system header, and if so,
77
/// whether it is C++ clean or not. This can be set by the include paths or
78
/// by \#pragma gcc system_header. This is an instance of
79
/// SrcMgr::CharacteristicKind.
80
LLVM_PREFERRED_TYPE(SrcMgr::CharacteristicKind)
81
unsigned
DirInfo
: 3;
82
83
/// Whether this header file info was supplied by an external source,
84
/// and has not changed since.
85
LLVM_PREFERRED_TYPE(
bool
)
86
unsigned
External
: 1;
87
88
/// Whether this header is part of and built with a module. i.e. it is listed
89
/// in a module map, and is not `excluded` or `textual`. (same meaning as
90
/// `ModuleMap::isModular()`).
91
LLVM_PREFERRED_TYPE(
bool
)
92
unsigned
isModuleHeader
: 1;
93
94
/// Whether this header is a `textual header` in a module. If a header is
95
/// textual in one module and normal in another module, this bit will not be
96
/// set, only `isModuleHeader`.
97
LLVM_PREFERRED_TYPE(
bool
)
98
unsigned
isTextualModuleHeader
: 1;
99
100
/// Whether this header is part of the module that we are building, even if it
101
/// doesn't build with the module. i.e. this will include `excluded` and
102
/// `textual` headers as well as normal headers.
103
LLVM_PREFERRED_TYPE(
bool
)
104
unsigned
isCompilingModuleHeader
: 1;
105
106
/// Whether this structure is considered to already have been
107
/// "resolved", meaning that it was loaded from the external source.
108
LLVM_PREFERRED_TYPE(
bool
)
109
unsigned
Resolved
: 1;
110
111
/// Whether this file has been looked up as a header.
112
LLVM_PREFERRED_TYPE(
bool
)
113
unsigned
IsValid
: 1;
114
115
/// If this file has a \#ifndef XXX (or equivalent) guard that
116
/// protects the entire contents of the file, this is the identifier
117
/// for the macro that controls whether or not it has any effect.
118
///
119
/// Note: Most clients should use getControllingMacro() to access
120
/// the controlling macro of this header, since
121
/// getControllingMacro() is able to load a controlling macro from
122
/// external storage.
123
LazyIdentifierInfoPtr
LazyControllingMacro
;
124
125
HeaderFileInfo
()
126
:
IsLocallyIncluded
(
false
),
isImport
(
false
),
isPragmaOnce
(
false
),
127
DirInfo
(SrcMgr::C_User),
External
(
false
),
isModuleHeader
(
false
),
128
isTextualModuleHeader
(
false
),
isCompilingModuleHeader
(
false
),
129
Resolved
(
false
),
IsValid
(
false
) {}
130
131
/// Retrieve the controlling macro for this header file, if
132
/// any.
133
const
IdentifierInfo
*
134
getControllingMacro
(
ExternalPreprocessorSource
*
External
);
135
136
/// Update the module membership bits based on the header role.
137
///
138
/// isModuleHeader will potentially be set, but not cleared.
139
/// isTextualModuleHeader will be set or cleared based on the role update.
140
void
mergeModuleMembership
(
ModuleMap::ModuleHeaderRole
Role);
141
};
142
143
static_assert
(
sizeof
(HeaderFileInfo) <= 16);