-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathargument_parser.h
More file actions
125 lines (101 loc) · 5.48 KB
/
Copy pathargument_parser.h
File metadata and controls
125 lines (101 loc) · 5.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#pragma once
#include <cstdint>
#include <string>
#include <kota/deco/option.h>
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
namespace clice {
namespace option {
enum ID : unsigned {
OPT_INVALID = 0,
#define OPTION(PREFIXES_OFFSET, \
NAME_OFFSET, \
ID, \
KIND, \
GROUP, \
ALIAS, \
ALIAS_ARGS, \
FLAGS, \
VISIBILITY, \
PARAM, \
HELP, \
HELP_TEXTS, \
META_VAR, \
VALUES) \
OPT_##ID,
#include "clang/Driver/Options.inc"
#undef OPTION
};
enum DriverClass : unsigned {
DefaultVis = 1u << 0,
CLOption = 1u << 1,
CC1Option = 1u << 2,
CC1AsOption = 1u << 3,
FlangOption = 1u << 4,
FC1Option = 1u << 5,
DXCOption = 1u << 6,
};
const kota::option::OptTable& table();
} // namespace option
/// Check if an option is a codegen-only flag that doesn't affect frontend
/// semantics (parsing, diagnostics, code completion). These are pure
/// backend/linker concerns irrelevant to an LSP server.
///
/// Note: options that DO affect semantics are intentionally kept:
/// -fno-exceptions, -fno-rtti, -std=*, -march=*, -fsanitize=*, -O*, -W*
///
/// Defined out-of-line in argument_parser.cpp (needs clang driver option IDs).
bool is_codegen_option(unsigned id);
/// Options that are completely irrelevant to an LSP and should be discarded
/// (input/output, PCH building, dependency scan, C++ modules).
bool is_discarded_option(unsigned id);
/// User-content options that go into the per-file patch rather than the
/// shared canonical command: -I, -D, -U, -include, -isystem, -iquote, -idirafter.
bool is_user_content_option(unsigned id);
/// Subset of user-content options that are include-path flags
/// (-I, -isystem, -iquote, -idirafter) — used for path absolutization.
bool is_include_path_option(unsigned id);
/// Check if this is the -Xclang pass-through option.
bool is_xclang_option(unsigned id);
/// Diagnostics-presentation options (-W*, -R*, -pedantic*, -w): they affect
/// which warnings are emitted but never the token stream produced by
/// preprocessing.
bool is_diagnostics_option(unsigned id);
/// Which subset of a compile command matters when deriving a cache key.
enum class ArgsProfile : std::uint8_t {
/// Options that can influence preprocessing: include paths, macros,
/// language dialect and target (predefined macros). Computed
/// subtractively as Frontend minus diagnostics-presentation options,
/// because nearly every language option can define a feature macro —
/// over-inclusion only costs sharing, under-inclusion costs correctness.
Preprocessing,
/// All frontend-semantic options: preprocessing + language + warnings.
/// Excludes codegen-only options and options clice manages itself.
Frontend,
/// Every recognized option, including codegen and inputs.
Full,
};
/// Render the subset of `args` selected by `profile` into a stable string
/// suitable for hashing (fragments are NUL-separated). This is a pure
/// filter: the relative order of kept options is preserved because it is
/// semantically significant (-I/-D ordering). args[0] must be the driver;
/// it is always kept since it affects language defaults. Arguments that
/// fail to parse are kept verbatim — over-keying is safe, under-keying is
/// not.
std::string canonicalize(llvm::ArrayRef<std::string> args, ArgsProfile profile);
/// Get the resource directory for clang builtin headers. Computed once
/// from the current executable path using Driver::GetResourcesPath.
llvm::StringRef resource_dir();
/// Format an argument list as a human-readable string: "[arg1 arg2 ...]".
std::string print_argv(llvm::ArrayRef<const char*> args);
/// Return the visibility mask to exclude MSVC cl.exe-style options (/U, /D,
/// /I, etc.) unless the driver is cl.exe. This prevents Unix absolute paths
/// like /Users/... from being misparsed as /U sers/... on macOS/Linux.
/// Defined out-of-line in argument_parser.cpp (needs ClangVisibility enum).
unsigned default_visibility(llvm::StringRef driver);
/// Check if a filename has a C/C++/ObjC/CUDA/etc. extension accepted by clang.
/// Returns false for .rc (Windows resource), .asm, .def, and other non-C-family files.
/// Defined out-of-line in argument_parser.cpp (needs clang::driver::types).
bool is_c_family_file(llvm::StringRef filename);
} // namespace clice