/src/CMake/Source/cmCachePatternTable.cxx
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
2 | | file LICENSE.rst or https://cmake.org/licensing for details. */ |
3 | | |
4 | | // Built-in cache variable documentation pattern table. |
5 | | // |
6 | | // This file is hand-maintained. Each entry's Pattern is a literal template |
7 | | // string containing one or more angle-bracketed placeholders (``<LANG>``, |
8 | | // ``<CONFIG>``, ``<PackageName>``, ``<PROJECT-NAME>``, ``<an-attribute>``, |
9 | | // ``<NNNN>``, ``<n>``). The Summary is a one-line tooltip installed as |
10 | | // the ``HELPSTRING`` of cache variables created via |
11 | | // ``cmake -D <var>=<value>`` whose name matches the template under the |
12 | | // lexical classes defined below and for which no exact-match entry exists |
13 | | // in ``cmCacheDocumentationTable``. |
14 | | // |
15 | | // The pattern table is consulted only on the miss path of the exact-match |
16 | | // ``cmCacheDocumentationTable::Get`` lookup; exact entries always win. |
17 | | // |
18 | | // Maintenance discipline: |
19 | | // * Adding a new pattern: hand-write one entry below in the canonical |
20 | | // ordering ``(numPlaceholders ASC, totalLiteralLen DESC, Pattern ASC)`` |
21 | | // and make sure that, with ``<`` and ``>`` stripped, the pattern |
22 | | // names an existing ``Help/variable/<NAME>.rst`` file. The |
23 | | // ``testPatternTableOrdered`` regression test in |
24 | | // ``Tests/CMakeLib`` verifies the canonical ordering; the |
25 | | // ``CacheVarHelpCoverage`` lint verifies the structural-parity |
26 | | // invariant. |
27 | | // * Per-language or per-configuration restrictions documented in the |
28 | | // corresponding ``.rst`` file must be reproduced in the Summary |
29 | | // prose (the matcher is intentionally permissive; restrictions live |
30 | | // in the tooltip). |
31 | | // * Summaries must be single-line printable ASCII, no embedded |
32 | | // double quotes, no embedded newlines, and ``<= 200`` characters |
33 | | // (so that ``cmake-gui`` / ``ccmake`` render them legibly). The |
34 | | // ``testPatternTableFieldsValid`` regression test enforces all of |
35 | | // these. |
36 | | // |
37 | | // Matcher semantics: lazy + lookahead-anchored, single pass, no |
38 | | // backtracking. For each placeholder, the matcher consumes the minimum |
39 | | // class-valid prefix of the input that lets the next literal anchor |
40 | | // match at the cursor. The fixed-length classes ``<NNNN>`` and |
41 | | // ``<n>`` consume exactly four or one ASCII digits respectively. |
42 | | // Full-input consumption is required at the end. First fully-matching |
43 | | // entry in ``kPatterns[]`` wins. |
44 | | |
45 | | #include "cmCachePatternTable.h" |
46 | | |
47 | | #include <cstddef> |
48 | | #include <iterator> |
49 | | #include <string> |
50 | | |
51 | | #include <cm/string_view> |
52 | | #include <cmext/string_view> |
53 | | |
54 | | #include "cmCacheDocumentationTable.h" |
55 | | |
56 | | namespace { |
57 | | |
58 | | using cmCachePatternTable::Entry; |
59 | | |
60 | | // The Entry layout below (two lines per row, ``{ "PATTERN",\n "summary" |
61 | | // },``) is intentional: it keeps the table easy to diff, review, and hand-edit |
62 | | // against the corresponding Help/variable/*.rst manuals. clang-format is |
63 | | // suppressed across the array so contributors can update one Summary |
64 | | // without the formatter reflowing every neighbor. |
65 | | // |
66 | | // Section headers ``// === N-placeholder, ... (K-literal-char bucket) ===`` |
67 | | // are organizational signposts that mirror the canonical ordering invariant |
68 | | // enforced by ``testPatternTableOrdered``: |
69 | | // |
70 | | // (numPlaceholders ASC, totalLiteralLen DESC, Pattern ASC) |
71 | | // |
72 | | // where ``totalLiteralLen`` is the byte count of the pattern after every |
73 | | // ``<...>`` placeholder has been stripped. Examples: |
74 | | // |
75 | | // ``CMAKE_<LANG>_COMPILER_LAUNCHER`` -> ``CMAKE__COMPILER_LAUNCHER`` (24) |
76 | | // ``CMAKE_<LANG>_CLANG_TIDY`` -> ``CMAKE__CLANG_TIDY`` (17) |
77 | | // ``CMAKE_<LANG>_FLAGS`` -> ``CMAKE__FLAGS`` (12) |
78 | | // |
79 | | // Ordering literals DESC within a placeholder-count band is what makes |
80 | | // ``Match()``'s first-match-wins linear scan correct: a more-anchored |
81 | | // pattern (e.g. ``CMAKE_<LANG>_FLAGS_<CONFIG>_INIT``, literal=18) must |
82 | | // shadow a less-anchored one (``CMAKE_<LANG>_FLAGS_<CONFIG>``, literal=13) |
83 | | // so a lookup of ``CMAKE_CXX_FLAGS_DEBUG_INIT`` resolves to the former |
84 | | // rather than lazily binding ``CONFIG`` to ``DEBUG_INIT`` against the |
85 | | // latter. Contributors adding a new entry: place it in the bucket whose |
86 | | // literal-count matches yours, and update or add a new ``=== ... ===`` |
87 | | // header if your literal-count is novel. The unit test catches mistakes. |
88 | | /* clang-format off */ |
89 | | Entry const kPatterns[] = { |
90 | | |
91 | | // === 1-placeholder, (37-literal-char bucket) === |
92 | | { "CMAKE_FRAMEWORK_MULTI_CONFIG_POSTFIX_<CONFIG>"_s, |
93 | | "Default framework filename postfix under configuration <CONFIG>."_s }, |
94 | | |
95 | | // === 1-placeholder, (35-literal-char bucket) === |
96 | | { "CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY_<CONFIG>"_s, |
97 | | "Initializes COMPILE_PDB_OUTPUT_DIRECTORY_<CONFIG> target property."_s }, |
98 | | { "CMAKE_INTERPROCEDURAL_OPTIMIZATION_<CONFIG>"_s, |
99 | | "Initializes INTERPROCEDURAL_OPTIMIZATION_<CONFIG> target property."_s }, |
100 | | { "CMAKE_LINK_LIBRARY_USING_<FEATURE>_SUPPORTED"_s, |
101 | | "Set to TRUE if <FEATURE> is supported regardless of linker language."_s }, |
102 | | |
103 | | // === 1-placeholder, (34-literal-char bucket) === |
104 | | { "CMAKE_<LANG>_CLANG_TIDY_EXPORT_FIXES_DIR"_s, |
105 | | "Default value for the <LANG>_CLANG_TIDY_EXPORT_FIXES_DIR target property; directory where clang-tidy writes suggested fix .yaml files. Applies only when <LANG> is C, CXX, OBJC, or OBJCXX."_s }, |
106 | | |
107 | | // === 1-placeholder, (33-literal-char bucket) === |
108 | | { "CMAKE_LINK_GROUP_USING_<FEATURE>_SUPPORTED"_s, |
109 | | "Specifies if <FEATURE> is supported regardless of link language."_s }, |
110 | | |
111 | | // === 1-placeholder, (31-literal-char bucket) === |
112 | | { "CMAKE_ARCHIVE_OUTPUT_DIRECTORY_<CONFIG>"_s, |
113 | | "Initializes ARCHIVE_OUTPUT_DIRECTORY_<CONFIG> target property."_s }, |
114 | | { "CMAKE_LIBRARY_OUTPUT_DIRECTORY_<CONFIG>"_s, |
115 | | "Initializes LIBRARY_OUTPUT_DIRECTORY_<CONFIG> target property."_s }, |
116 | | { "CMAKE_RUNTIME_OUTPUT_DIRECTORY_<CONFIG>"_s, |
117 | | "Initializes RUNTIME_OUTPUT_DIRECTORY_<CONFIG> target property."_s }, |
118 | | { "CMAKE_USER_MAKE_RULES_OVERRIDE_<LANG>"_s, |
119 | | "Specify a CMake file that overrides platform information for <LANG>"_s }, |
120 | | |
121 | | // === 1-placeholder, (30-literal-char bucket) === |
122 | | { "CMAKE_LINK_LIBRARY_<FEATURE>_ATTRIBUTES"_s, |
123 | | "Defines behavior and attributes of the specified link library <FEATURE>."_s }, |
124 | | |
125 | | // === 1-placeholder, (29-literal-char bucket) === |
126 | | { "CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE_BEFORE"_s, |
127 | | "Path to a CMake language file included as the first step of any project() command call matching <PROJECT-NAME>. Intended for injecting custom code into project builds without modifying the source."_s }, |
128 | | |
129 | | // === 1-placeholder, (27-literal-char bucket) === |
130 | | { "CMAKE_<LANG>_INCLUDE_WHAT_YOU_USE"_s, |
131 | | "Default value for the <LANG>_INCLUDE_WHAT_YOU_USE target property; names an include-what-you-use command (and arguments) run alongside compilation. Applies only when <LANG> is C or CXX."_s }, |
132 | | { "CMAKE_DISABLE_FIND_PACKAGE_<PackageName>"_s, |
133 | | "Set to TRUE to disable calls to find_package(<PackageName>); the call returns as if the package were not found, even when REQUIRED was specified."_s }, |
134 | | { "CMAKE_PDB_OUTPUT_DIRECTORY_<CONFIG>"_s, |
135 | | "Initializes PDB_OUTPUT_DIRECTORY_<CONFIG> target property."_s }, |
136 | | { "CMAKE_REQUIRE_FIND_PACKAGE_<PackageName>"_s, |
137 | | "Set to TRUE to make every call to find_package(<PackageName>) behave as if REQUIRED were specified, causing CMake to fail when the package is not found."_s }, |
138 | | |
139 | | // === 1-placeholder, (26-literal-char bucket) === |
140 | | { "CMAKE_MAP_IMPORTED_CONFIG_<CONFIG>"_s, |
141 | | "Initializes MAP_IMPORTED_CONFIG_<CONFIG> target property."_s }, |
142 | | { "CMAKE_MODULE_LINKER_FLAGS_<CONFIG>"_s, |
143 | | "Flags used by the linker when creating a module library for the <CONFIG> configuration. Appended after the configuration-independent CMAKE_MODULE_LINKER_FLAGS."_s }, |
144 | | { "CMAKE_SHARED_LINKER_FLAGS_<CONFIG>"_s, |
145 | | "Flags used by the linker when creating a shared library for the <CONFIG> configuration. Appended after the configuration-independent CMAKE_SHARED_LINKER_FLAGS."_s }, |
146 | | { "CMAKE_STATIC_LINKER_FLAGS_<CONFIG>"_s, |
147 | | "Flags used by the static-library archiver when creating a static library for the <CONFIG> configuration. Appended after the configuration-independent CMAKE_STATIC_LINKER_FLAGS."_s }, |
148 | | |
149 | | // === 1-placeholder, (25-literal-char bucket) === |
150 | | { "CMAKE_LINK_LIBRARY_USING_<FEATURE>"_s, |
151 | | "Defines how to link a library for <FEATURE>."_s }, |
152 | | |
153 | | // === 1-placeholder, (24-literal-char bucket) === |
154 | | { "CMAKE_<LANG>_COMPILER_LAUNCHER"_s, |
155 | | "Default value for the <LANG>_COMPILER_LAUNCHER target property; launcher tool prepended to every <LANG> compile command. Applies only when <LANG> is C, CXX, Fortran, HIP, ISPC, OBJC, OBJCXX, or CUDA."_s }, |
156 | | { "CMAKE_<LANG>_STANDARD_REQUIRED"_s, |
157 | | "Default value for the <LANG>_STANDARD_REQUIRED target property when a target is created. If TRUE, the requested language standard must be supported by the compiler."_s }, |
158 | | { "CMAKE_<LANG>_VISIBILITY_PRESET"_s, |
159 | | "Default value for the <LANG>_VISIBILITY_PRESET target property when a target is created. Controls the default symbol visibility (default, hidden, protected, internal) for <LANG> code."_s }, |
160 | | { "CMAKE_POLICY_DEFAULT_CMP<NNNN>"_s, |
161 | | "Default for CMake Policy CMP<NNNN> when otherwise left unset. Set to OLD or NEW to externally control the policy for projects that have not set it via cmake_minimum_required or cmake_policy."_s }, |
162 | | { "CMAKE_POLICY_WARNING_CMP<NNNN>"_s, |
163 | | "Explicitly enable or disable the warning when CMake Policy CMP<NNNN> has not been set explicitly. Meaningful only for the policies that do not warn by default."_s }, |
164 | | |
165 | | // === 1-placeholder, (23-literal-char bucket) === |
166 | | { "CMAKE_EXE_LINKER_FLAGS_<CONFIG>"_s, |
167 | | "Flags used by the linker when creating an executable for the <CONFIG> configuration. Appended after the configuration-independent CMAKE_EXE_LINKER_FLAGS."_s }, |
168 | | { "CMAKE_LINK_GROUP_USING_<FEATURE>"_s, |
169 | | "Defines how to link a group of libraries for <FEATURE>."_s }, |
170 | | |
171 | | // === 1-placeholder, (22-literal-char bucket) === |
172 | | { "CMAKE_<LANG>_LINKER_LAUNCHER"_s, |
173 | | "Default value for the <LANG>_LINKER_LAUNCHER target property; names a launcher tool prepended to every <LANG> link command. Applies only when <LANG> is C, CXX, OBJC, OBJCXX, or CUDA."_s }, |
174 | | { "CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE"_s, |
175 | | "Path to a CMake language file included as the last step of any project() command call matching <PROJECT-NAME>. Intended for injecting custom code without modifying the project source."_s }, |
176 | | { "CMAKE_XCODE_ATTRIBUTE_<an-attribute>"_s, |
177 | | "Tells the Xcode generator to set <an-attribute> to the given value in the generated Xcode project. Ignored on other generators. Low-level escape hatch for Xcode-specific settings."_s }, |
178 | | |
179 | | // === 1-placeholder, (20-literal-char bucket) === |
180 | | { "CMAKE_<LANG>_HOST_COMPILER"_s, |
181 | | "Host compiler executable for CUDA or HIP code compilation"_s }, |
182 | | |
183 | | // === 1-placeholder, (17-literal-char bucket) === |
184 | | { "CMAKE_<LANG>_CLANG_TIDY"_s, |
185 | | "Default value for the <LANG>_CLANG_TIDY target property; names a clang-tidy command (with arguments) run alongside compilation. Applies only when <LANG> is C, CXX, OBJC, or OBJCXX."_s }, |
186 | | { "CMAKE_<LANG>_EXTENSIONS"_s, |
187 | | "Default value for the <LANG>_EXTENSIONS target property when a target is created. Controls whether compiler-specific extensions to the language standard are enabled."_s }, |
188 | | { "CMAKE_<LANG>_FLAGS_INIT"_s, |
189 | | "Toolchain-file hook initializing CMAKE_<LANG>_FLAGS the first time the build tree is configured for <LANG>. Set in toolchain or platform files; user projects should set CMAKE_<LANG>_FLAGS instead."_s }, |
190 | | { "CMAKE_<LANG>_LINK_FLAGS"_s, |
191 | | "Language-wide flags for <LANG> used when linking for all configurations. Passed to every compiler invocation that drives linking. Per-config CMAKE_<LANG>_LINK_FLAGS_<CONFIG> are appended on top."_s }, |
192 | | { "CMAKE_<LANG>_PVS_STUDIO"_s, |
193 | | "Default value for the <LANG>_PVS_STUDIO target property; names a pvs-studio-analyzer command (with arguments) run alongside compilation. Applies only when <LANG> is C or CXX."_s }, |
194 | | |
195 | | // === 1-placeholder, (15-literal-char bucket) === |
196 | | { "CMAKE_<LANG>_COMPILER"_s, |
197 | | "Full path to the compiler used for language <LANG>. Set by CMake during compiler detection on the first configure; users may override on the command line to select a specific toolchain."_s }, |
198 | | { "CMAKE_<LANG>_CPPCHECK"_s, |
199 | | "Default value for the <LANG>_CPPCHECK target property; names a cppcheck command (with arguments) run alongside compilation. Applies only when <LANG> is C or CXX."_s }, |
200 | | { "CMAKE_<LANG>_STANDARD"_s, |
201 | | "Default value for the <LANG>_STANDARD target property when a target is created. Applies to <LANG> = C, CXX, CUDA, HIP, OBJC, OBJCXX. See cmake-compile-features(7)."_s }, |
202 | | |
203 | | // === 1-placeholder, (14-literal-char bucket) === |
204 | | { "CMAKE_<CONFIG>_POSTFIX"_s, |
205 | | "Default filename postfix for libraries under configuration <CONFIG>."_s }, |
206 | | { "CMAKE_<LANG>_CPPLINT"_s, |
207 | | "Default value for the <LANG>_CPPLINT target property; names a cpplint command (with arguments) run alongside compilation. Applies only when <LANG> is C or CXX."_s }, |
208 | | |
209 | | // === 1-placeholder, (13-literal-char bucket) === |
210 | | { "CMAKE_<LANG>_ICSTAT"_s, |
211 | | "Default value for the <LANG>_ICSTAT target property; names an icstat static-analysis command (with arguments) run alongside compilation. Applies only when <LANG> is C or CXX."_s }, |
212 | | |
213 | | // === 1-placeholder, (12-literal-char bucket) === |
214 | | { "CMAKE_<LANG>_FLAGS"_s, |
215 | | "Language-wide compiler flags for <LANG>. Initialized from the language-specific environment variable (CFLAGS, CXXFLAGS, FFLAGS, etc.) the first time the language is enabled."_s }, |
216 | | { "CMAKE_MATCH_<n>"_s, |
217 | | "Capture group <n> matched by the most recent regular expression (groups 0 through 9). Group 0 is the entire match; groups 1 through 9 are the parenthesized subexpressions."_s }, |
218 | | |
219 | | // === 1-placeholder, (11-literal-char bucket) === |
220 | | { "<PROJECT-NAME>_BINARY_DIR"_s, |
221 | | "Top-level binary directory for the named project. Created by the project() command with the given <PROJECT-NAME>; useful when add_subdirectory is used to connect several projects."_s }, |
222 | | { "<PROJECT-NAME>_SOURCE_DIR"_s, |
223 | | "Top-level source directory for the named project. Created by the project() command with the given <PROJECT-NAME>; useful when add_subdirectory is used to connect several projects."_s }, |
224 | | |
225 | | // === 1-placeholder, (8-literal-char bucket) === |
226 | | { "<PROJECT-NAME>_VERSION"_s, |
227 | | "Value given to the VERSION option of the most recent project() command with project name <PROJECT-NAME>, if any. Component values live in <PROJECT-NAME>_VERSION_{MAJOR,MINOR,PATCH,TWEAK}."_s }, |
228 | | |
229 | | // === 1-placeholder, (5-literal-char bucket) === |
230 | | { "<PackageName>_ROOT"_s, |
231 | | "Initial search prefix(es) for find_package(<PackageName>); covers both the mixed-case form (CMP0074, e.g. Foo_ROOT) and the upper-case form (CMP0144, e.g. FOO_ROOT)."_s }, |
232 | | |
233 | | // === 2-placeholder, (36-literal-char bucket) === |
234 | | { "CMAKE_<LANG>_LINK_LIBRARY_USING_<FEATURE>_SUPPORTED"_s, |
235 | | "Set to TRUE if <FEATURE> is supported for linker language <LANG>."_s }, |
236 | | |
237 | | // === 2-placeholder, (34-literal-char bucket) === |
238 | | { "CMAKE_<LANG>_LINK_GROUP_USING_<FEATURE>_SUPPORTED"_s, |
239 | | "Specifies if <FEATURE> is supported for link language <LANG>."_s }, |
240 | | |
241 | | // === 2-placeholder, (31-literal-char bucket) === |
242 | | { "CMAKE_<LANG>_LINK_LIBRARY_<FEATURE>_ATTRIBUTES"_s, |
243 | | "Defines semantics of link library <FEATURE> for language <LANG>."_s }, |
244 | | |
245 | | // === 2-placeholder, (26-literal-char bucket) === |
246 | | { "CMAKE_<LANG>_LINK_LIBRARY_USING_<FEATURE>"_s, |
247 | | "Defines how to link a library for <FEATURE>."_s }, |
248 | | |
249 | | // === 2-placeholder, (24-literal-char bucket) === |
250 | | { "CMAKE_<LANG>_LINK_GROUP_USING_<FEATURE>"_s, |
251 | | "Defines how to link a group of libraries for <FEATURE>."_s }, |
252 | | |
253 | | // === 2-placeholder, (20-literal-char bucket) === |
254 | | { "CMAKE_<LANG>_USING_LINKER_<TYPE>"_s, |
255 | | "Defines how to specify the <TYPE> linker for the link step."_s }, |
256 | | |
257 | | // === 2-placeholder, (18-literal-char bucket) === |
258 | | { "CMAKE_<LANG>_FLAGS_<CONFIG>_INIT"_s, |
259 | | "Toolchain-file hook initializing CMAKE_<LANG>_FLAGS_<CONFIG> the first time the build tree is configured for language <LANG>. Intended for toolchain or platform files."_s }, |
260 | | { "CMAKE_<LANG>_LINK_FLAGS_<CONFIG>"_s, |
261 | | "Language-wide flags for <LANG> used when linking for the <CONFIG> configuration. Passed to every compiler invocation that drives linking. Appended after CMAKE_<LANG>_LINK_FLAGS."_s }, |
262 | | |
263 | | // === 2-placeholder, (13-literal-char bucket) === |
264 | | { "CMAKE_<LANG>_FLAGS_<CONFIG>"_s, |
265 | | "Language-wide flags for <LANG> used when building for the <CONFIG> configuration. Appended after CMAKE_<LANG>_FLAGS on both compile and link invocations."_s }, |
266 | | }; |
267 | | /* clang-format on */ |
268 | | |
269 | | // --------------------------------------------------------------------------- |
270 | | // Character classes used by the matcher. |
271 | | // --------------------------------------------------------------------------- |
272 | | |
273 | | constexpr bool IsAsciiAlpha(char c) |
274 | 0 | { |
275 | 0 | return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'); |
276 | 0 | } |
277 | | |
278 | | constexpr bool IsAsciiDigit(char c) |
279 | 0 | { |
280 | 0 | return c >= '0' && c <= '9'; |
281 | 0 | } |
282 | | |
283 | | // Identifier: ``[A-Za-z][A-Za-z0-9_]*`` -- start vs. continuation. |
284 | | constexpr bool IsIdentStart(char c) |
285 | 0 | { |
286 | 0 | return IsAsciiAlpha(c); |
287 | 0 | } |
288 | | constexpr bool IsIdentCont(char c) |
289 | 0 | { |
290 | 0 | return IsAsciiAlpha(c) || IsAsciiDigit(c) || c == '_'; |
291 | 0 | } |
292 | | |
293 | | // Identifier-with-hyphen: ``[A-Za-z][A-Za-z0-9_-]*`` -- start vs. |
294 | | // continuation. |
295 | | constexpr bool IsIdentHyphenStart(char c) |
296 | 0 | { |
297 | 0 | return IsAsciiAlpha(c); |
298 | 0 | } |
299 | | constexpr bool IsIdentHyphenCont(char c) |
300 | 0 | { |
301 | 0 | return IsAsciiAlpha(c) || IsAsciiDigit(c) || c == '_' || c == '-'; |
302 | 0 | } |
303 | | |
304 | | // --------------------------------------------------------------------------- |
305 | | // Placeholder dispatch. |
306 | | // --------------------------------------------------------------------------- |
307 | | |
308 | | enum class PlaceholderClass |
309 | | { |
310 | | Ident, // <LANG>, <CONFIG>, <PackageName> |
311 | | IdentHyphen, // <PROJECT-NAME>, <an-attribute> |
312 | | FourDigit, // <NNNN> |
313 | | OneDigit, // <n> |
314 | | Unknown, // malformed pattern entry |
315 | | }; |
316 | | |
317 | | PlaceholderClass ClassOf(cm::string_view placeholder) |
318 | 0 | { |
319 | | // ``placeholder`` includes the surrounding angle brackets, e.g. "<LANG>". |
320 | | // ``<FEATURE>`` and ``<TYPE>`` are documented as identifiers by their |
321 | | // RSTs (e.g. WEAK / WHOLE_ARCHIVE for FEATURE in |
322 | | // Help/variable/CMAKE_LINK_LIBRARY_USING_FEATURE.rst and LLD / MOLD |
323 | | // for TYPE in Help/variable/CMAKE_LANG_USING_LINKER_TYPE.rst), so they |
324 | | // share the ``Ident`` lexical class with <LANG>/<CONFIG>/<PackageName>. |
325 | | // Without this clause the eleven pattern entries that use these two |
326 | | // placeholders would never match any input (regression guarded by |
327 | | // testEveryPatternReachable in Tests/CMakeLib). |
328 | 0 | if (placeholder == "<LANG>" || placeholder == "<CONFIG>" || |
329 | 0 | placeholder == "<PackageName>" || placeholder == "<FEATURE>" || |
330 | 0 | placeholder == "<TYPE>") { |
331 | 0 | return PlaceholderClass::Ident; |
332 | 0 | } |
333 | 0 | if (placeholder == "<PROJECT-NAME>" || placeholder == "<an-attribute>") { |
334 | 0 | return PlaceholderClass::IdentHyphen; |
335 | 0 | } |
336 | 0 | if (placeholder == "<NNNN>") { |
337 | 0 | return PlaceholderClass::FourDigit; |
338 | 0 | } |
339 | 0 | if (placeholder == "<n>") { |
340 | 0 | return PlaceholderClass::OneDigit; |
341 | 0 | } |
342 | 0 | return PlaceholderClass::Unknown; |
343 | 0 | } |
344 | | |
345 | | bool ClassAllowsStart(PlaceholderClass cls, char c) |
346 | 0 | { |
347 | 0 | switch (cls) { |
348 | 0 | case PlaceholderClass::Ident: |
349 | 0 | return IsIdentStart(c); |
350 | 0 | case PlaceholderClass::IdentHyphen: |
351 | 0 | return IsIdentHyphenStart(c); |
352 | 0 | case PlaceholderClass::FourDigit: |
353 | 0 | case PlaceholderClass::OneDigit: |
354 | 0 | return IsAsciiDigit(c); |
355 | 0 | case PlaceholderClass::Unknown: |
356 | 0 | break; |
357 | 0 | } |
358 | 0 | return false; |
359 | 0 | } |
360 | | |
361 | | bool ClassAllowsCont(PlaceholderClass cls, char c) |
362 | 0 | { |
363 | 0 | switch (cls) { |
364 | 0 | case PlaceholderClass::Ident: |
365 | 0 | return IsIdentCont(c); |
366 | 0 | case PlaceholderClass::IdentHyphen: |
367 | 0 | return IsIdentHyphenCont(c); |
368 | 0 | case PlaceholderClass::FourDigit: |
369 | 0 | case PlaceholderClass::OneDigit: |
370 | 0 | return IsAsciiDigit(c); |
371 | 0 | case PlaceholderClass::Unknown: |
372 | 0 | break; |
373 | 0 | } |
374 | 0 | return false; |
375 | 0 | } |
376 | | |
377 | | // --------------------------------------------------------------------------- |
378 | | // Helpers. |
379 | | // --------------------------------------------------------------------------- |
380 | | |
381 | | bool LiteralMatches(cm::string_view input, std::size_t pos, |
382 | | cm::string_view literal) |
383 | 0 | { |
384 | 0 | return input.size() - pos >= literal.size() && |
385 | 0 | input.compare(pos, literal.size(), literal) == 0; |
386 | 0 | } |
387 | | |
388 | | // Try to match ``pattern`` against ``input`` end-to-end under the |
389 | | // lazy + lookahead-anchored semantics documented at the top of this file. |
390 | | // Returns true on full-consumption match; false otherwise. |
391 | | bool TryMatch(cm::string_view pattern, cm::string_view input) |
392 | 0 | { |
393 | 0 | std::size_t pi = 0; |
394 | 0 | std::size_t ii = 0; |
395 | |
|
396 | 0 | while (pi < pattern.size()) { |
397 | 0 | if (pattern[pi] != '<') { |
398 | | // Literal segment: walk until next '<' or end of pattern. |
399 | 0 | std::size_t literal_end = pi; |
400 | 0 | while (literal_end < pattern.size() && pattern[literal_end] != '<') { |
401 | 0 | ++literal_end; |
402 | 0 | } |
403 | 0 | cm::string_view const lit = pattern.substr(pi, literal_end - pi); |
404 | 0 | if (!LiteralMatches(input, ii, lit)) { |
405 | 0 | return false; |
406 | 0 | } |
407 | 0 | pi = literal_end; |
408 | 0 | ii += lit.size(); |
409 | 0 | continue; |
410 | 0 | } |
411 | | |
412 | | // Placeholder segment: find the closing '>'. |
413 | 0 | std::size_t const close = pattern.find('>', pi); |
414 | 0 | if (close == cm::string_view::npos) { |
415 | 0 | return false; // malformed pattern; matched by no input |
416 | 0 | } |
417 | 0 | cm::string_view const ph = pattern.substr(pi, close - pi + 1); |
418 | 0 | PlaceholderClass const cls = ClassOf(ph); |
419 | 0 | if (cls == PlaceholderClass::Unknown) { |
420 | 0 | return false; // unknown placeholder class; rejected by unit test too |
421 | 0 | } |
422 | | |
423 | | // Locate the next anchor literal that follows this placeholder. An |
424 | | // empty anchor means the placeholder is the last segment in the |
425 | | // pattern (must consume to end-of-input) or that it is followed |
426 | | // immediately by another placeholder (adjacent placeholders are |
427 | | // forbidden -- testPatternTableFieldsValid rejects them at table |
428 | | // build time, so we treat the case defensively here). |
429 | 0 | std::size_t const after_ph = close + 1; |
430 | 0 | std::size_t anchor_end = after_ph; |
431 | 0 | while (anchor_end < pattern.size() && pattern[anchor_end] != '<') { |
432 | 0 | ++anchor_end; |
433 | 0 | } |
434 | 0 | cm::string_view const anchor = |
435 | 0 | pattern.substr(after_ph, anchor_end - after_ph); |
436 | 0 | bool const consume_to_eoi = |
437 | 0 | anchor.empty() && (anchor_end == pattern.size()); |
438 | 0 | if (anchor.empty() && !consume_to_eoi) { |
439 | 0 | return false; // adjacent placeholders are not supported |
440 | 0 | } |
441 | | |
442 | | // Fixed-length classes consume exactly that many digits, then anchor. |
443 | 0 | if (cls == PlaceholderClass::FourDigit || |
444 | 0 | cls == PlaceholderClass::OneDigit) { |
445 | 0 | std::size_t const fixed_len = |
446 | 0 | (cls == PlaceholderClass::FourDigit) ? 4u : 1u; |
447 | 0 | if (input.size() - ii < fixed_len) { |
448 | 0 | return false; |
449 | 0 | } |
450 | 0 | for (std::size_t k = 0; k < fixed_len; ++k) { |
451 | 0 | if (!IsAsciiDigit(input[ii + k])) { |
452 | 0 | return false; |
453 | 0 | } |
454 | 0 | } |
455 | 0 | std::size_t const cur = ii + fixed_len; |
456 | 0 | if (consume_to_eoi) { |
457 | 0 | if (cur != input.size()) { |
458 | 0 | return false; |
459 | 0 | } |
460 | 0 | ii = cur; |
461 | 0 | } else { |
462 | 0 | if (!LiteralMatches(input, cur, anchor)) { |
463 | 0 | return false; |
464 | 0 | } |
465 | 0 | ii = cur + anchor.size(); |
466 | 0 | } |
467 | 0 | pi = anchor_end; |
468 | 0 | continue; |
469 | 0 | } |
470 | | |
471 | | // Variable-length classes: placeholder is non-empty; consume lazily, |
472 | | // stopping at the first cursor position where the anchor matches (or |
473 | | // at end-of-input when there is no trailing literal anchor). |
474 | 0 | if (ii >= input.size()) { |
475 | 0 | return false; |
476 | 0 | } |
477 | 0 | if (!ClassAllowsStart(cls, input[ii])) { |
478 | 0 | return false; |
479 | 0 | } |
480 | 0 | std::size_t cur = ii + 1; // consumed first char |
481 | 0 | if (consume_to_eoi) { |
482 | 0 | while (cur < input.size()) { |
483 | 0 | if (!ClassAllowsCont(cls, input[cur])) { |
484 | 0 | return false; |
485 | 0 | } |
486 | 0 | ++cur; |
487 | 0 | } |
488 | 0 | ii = cur; |
489 | 0 | } else { |
490 | 0 | while (true) { |
491 | 0 | if (LiteralMatches(input, cur, anchor)) { |
492 | 0 | break; |
493 | 0 | } |
494 | 0 | if (cur >= input.size()) { |
495 | 0 | return false; |
496 | 0 | } |
497 | 0 | if (!ClassAllowsCont(cls, input[cur])) { |
498 | 0 | return false; |
499 | 0 | } |
500 | 0 | ++cur; |
501 | 0 | } |
502 | 0 | ii = cur + anchor.size(); |
503 | 0 | } |
504 | 0 | pi = anchor_end; |
505 | 0 | } |
506 | | |
507 | 0 | return ii == input.size(); |
508 | 0 | } |
509 | | |
510 | | } // namespace |
511 | | |
512 | | cmCacheDocumentationTable::LookupResult cmCachePatternTable::Match( |
513 | | cm::string_view varName) |
514 | 0 | { |
515 | 0 | for (auto const& entry : kPatterns) { |
516 | 0 | if (TryMatch(entry.Pattern, varName)) { |
517 | 0 | return { entry.Summary }; |
518 | 0 | } |
519 | 0 | } |
520 | 0 | return {}; |
521 | 0 | } |
522 | | |
523 | | cmCachePatternTable::Entry const* cmCachePatternTable::EntriesBegin() |
524 | 0 | { |
525 | 0 | return std::begin(kPatterns); |
526 | 0 | } |
527 | | |
528 | | cmCachePatternTable::Entry const* cmCachePatternTable::EntriesEnd() |
529 | 0 | { |
530 | 0 | return std::end(kPatterns); |
531 | 0 | } |
532 | | |
533 | | std::size_t cmCachePatternTable::EntriesSize() |
534 | 0 | { |
535 | 0 | return static_cast<std::size_t>(std::end(kPatterns) - std::begin(kPatterns)); |
536 | 0 | } |