File indexing completed on 2026-05-10 08:36:56
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef LLVM_CLANG_LEX_DEPENDENCYDIRECTIVESSCANNER_H
0018 #define LLVM_CLANG_LEX_DEPENDENCYDIRECTIVESSCANNER_H
0019
0020 #include "clang/Basic/SourceLocation.h"
0021 #include "llvm/ADT/ArrayRef.h"
0022
0023 namespace clang {
0024
0025 namespace tok {
0026 enum TokenKind : unsigned short;
0027 }
0028
0029 class DiagnosticsEngine;
0030
0031 namespace dependency_directives_scan {
0032
0033
0034 struct Token {
0035
0036 unsigned Offset;
0037 unsigned Length;
0038 tok::TokenKind Kind;
0039 unsigned short Flags;
0040
0041 Token(unsigned Offset, unsigned Length, tok::TokenKind Kind,
0042 unsigned short Flags)
0043 : Offset(Offset), Length(Length), Kind(Kind), Flags(Flags) {}
0044
0045 unsigned getEnd() const { return Offset + Length; }
0046
0047 bool is(tok::TokenKind K) const { return Kind == K; }
0048 bool isNot(tok::TokenKind K) const { return Kind != K; }
0049 bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const {
0050 return is(K1) || is(K2);
0051 }
0052 template <typename... Ts> bool isOneOf(tok::TokenKind K1, Ts... Ks) const {
0053 return is(K1) || isOneOf(Ks...);
0054 }
0055 };
0056
0057
0058
0059 enum DirectiveKind : uint8_t {
0060 pp_none,
0061 pp_include,
0062 pp___include_macros,
0063 pp_define,
0064 pp_undef,
0065 pp_import,
0066 pp_pragma_import,
0067 pp_pragma_once,
0068 pp_pragma_push_macro,
0069 pp_pragma_pop_macro,
0070 pp_pragma_include_alias,
0071 pp_pragma_system_header,
0072 pp_include_next,
0073 pp_if,
0074 pp_ifdef,
0075 pp_ifndef,
0076 pp_elif,
0077 pp_elifdef,
0078 pp_elifndef,
0079 pp_else,
0080 pp_endif,
0081 decl_at_import,
0082 cxx_module_decl,
0083 cxx_import_decl,
0084 cxx_export_module_decl,
0085 cxx_export_import_decl,
0086
0087
0088 tokens_present_before_eof,
0089 pp_eof,
0090 };
0091
0092
0093
0094
0095 struct Directive {
0096 ArrayRef<Token> Tokens;
0097
0098
0099 DirectiveKind Kind = pp_none;
0100
0101 Directive() = default;
0102 Directive(DirectiveKind K, ArrayRef<Token> Tokens)
0103 : Tokens(Tokens), Kind(K) {}
0104 };
0105
0106 }
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117 bool scanSourceForDependencyDirectives(
0118 StringRef Input, SmallVectorImpl<dependency_directives_scan::Token> &Tokens,
0119 SmallVectorImpl<dependency_directives_scan::Directive> &Directives,
0120 DiagnosticsEngine *Diags = nullptr,
0121 SourceLocation InputSourceLoc = SourceLocation());
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133 void printDependencyDirectivesAsSource(
0134 StringRef Source,
0135 ArrayRef<dependency_directives_scan::Directive> Directives,
0136 llvm::raw_ostream &OS);
0137
0138 }
0139
0140 #endif