Commit Graph

110 Commits

Author SHA1 Message Date
Brad King
5ceed2bb28 Merge topic 'reduce-policy-eval-scope'
cb19a63499 cmConditionEvaluator: Reduce the scope of the CMP0064 evaluation

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !7287
2022-05-24 10:08:52 -04:00
Ben Boeckel
6ff03d463f clang-tidy: address google-readability-casting lints
At least those involving `static_cast`.
2022-05-24 09:09:43 -04:00
Alex Turbov
cb19a63499 cmConditionEvaluator: Reduce the scope of the CMP0064 evaluation
When evaluatig conditions, avoid testing CMP0064 unless it's really needed
(Cuz most of the time it doesn't)
2022-05-23 09:08:51 -04:00
Sean McBride
37859e3244 Source: Fix clang -Wimplicit-fallthrough warnings 2021-09-28 10:53:54 -04:00
Sean McBride
907d098838 Source: Fix clang -Wextra-semi warnings 2021-09-28 09:59:24 -04:00
Marc Chevrier
cc56dc7468 Rename cmProp in cmValue 2021-09-21 17:14:04 +02:00
Marc Chevrier
7e154ebd59 cmSystemTools::VersionCompare: use std::string for arguments 2021-09-17 11:58:46 +02:00
Alex Turbov
61b33c3f4e Fix: Regression in the cmConditionEvaluator::HandleLevel0
As reported in the BUG #22524, mismatched parenthesis reported differently
for `while()` and `if()`.

The problem was in the double loop (over "handlers" and the arguments),
where the outer loop didn't check the result of the running handler.
2021-08-09 21:05:09 +03:00
Marc Chevrier
e5cd39ca80 cmProp: refactoring: transform alias in class
To handle safely the values used by CMake variables and properties,
introduce the class cmProp as a replacement from the simple pointer
to std::string instance.
2021-08-08 16:19:08 +02:00
Alex Turbov
54a70b3988 Refactor: Move version compare op table out of the function
It's static data and never changed.
2021-08-03 10:55:47 -04:00
Alex Turbov
f37d6a3170 Refactor: Remove redundant checks for 0 and 1 literals
They are gonna be checked by `cmIsOn()` anyway.
2021-08-03 10:55:47 -04:00
Alex Turbov
00961a4782 Refactor: Copy exactly required count of args and avoid pop_back() 2021-08-03 10:55:47 -04:00
Alex Turbov
2a72cad9be Style: Better names of local vars for IN_LIST handler 2021-08-03 10:55:47 -04:00
Alex Turbov
0dd7795706 Refactor: Extract the logic of testing for special variable to func
Introduce `looksLikeSpecialVariable`. It makes `if()` blocks readable.
2021-08-03 10:55:47 -04:00
Alex Turbov
866b0595f6 Refactor: Introduce cmArgumentList container class
The `cmArgumentList` has been turned into a class (forward declared in
the header). It inherits from the `std::list` (yeah, but we don't intend
to store polymorphic classes in it). In addition to the standard methods,
now it's possible to move `HandlePredicate` (renamed to `ReduceOneArg`)
and `HandleBinaryOp` (renamed to `ReduceTwoArgs`) as its members.

Additionally, iterators managements (`IncrementArguments`) have been
refactored into two separate classes mimicking iterators. This also
allows having a uniform `for` loop and concentrates the logic of
iterators advancing in it instead of the loop's body. The arguments
processing algorithms operate with "windows" over a collection of
arguments. Hence there are two kinds of "iteration windows" -- allowing
to observe 2 or 3 elements per loop iteration. These iteration "windows"
also passed to reducers.
2021-08-03 10:55:47 -04:00
Alex Turbov
51d9194a96 Refactor: Reduce one more condition checking on handling math compare 2021-08-03 10:55:46 -04:00
Alex Turbov
46810235e3 Refactor: Avoid ifelse if → … for compare operators
When trying to match one of compare operator key inside `if()` condition,
remember the index of matched operator. Later this index used to
select the operation to perform instead of strings compare again.
2021-08-03 10:55:46 -04:00
Alex Turbov
17af3baddd Refactor: Set const to cmConditionEvaluator::IsKeyword parameters 2021-08-03 10:55:46 -04:00
Alex Turbov
2b916606c5 Refactor: No need to move iterators after match
A handler's loop of all levels gonna restart after calls to
`HandlePredcate` or `HandleBinaryOp`... And the first action in the
loop is to setup iterators. So, no need to move 'em inside the
functions. Also, no need to pass iterators by reference.

Also, reorder parameters of both functions so iterators
followed after a reference to the newArgs container.
2021-08-03 10:55:46 -04:00
Alex Turbov
97d6bbcc01 Refactor: Replace std::to_string w/ more specialized bool2string 2021-08-03 10:55:46 -04:00
Alex Turbov
9721ab416f Refactor: Reorder MATCHES handler from top below to the fail-fast 2021-08-03 10:55:46 -04:00
Alex Turbov
d4d44e86f6 Refactor: Reduce variables scope in HandleLevel2 2021-08-03 10:55:46 -04:00
Alex Turbov
cc6cdacc18 Refactor: Simplify boolean to string result assignments 2021-08-03 10:55:46 -04:00
Alex Turbov
e3c1dbe18b Refactor: Replace if block w/ boolean expression
Signed-off-by: Alex Turbov <i.zaufi@gmail.com>
2021-08-03 10:55:45 -04:00
Alex Turbov
047f8321a0 Refactor: Avoid redundant operator<< on printing messages
Signed-off-by: Alex Turbov <i.zaufi@gmail.com>
2021-08-03 10:55:45 -04:00
Alex Turbov
4de2a4a46d Refactor: Opt-out do+while loops and reduce nesting level in handlers
Signed-off-by: Alex Turbov <i.zaufi@gmail.com>
2021-08-03 10:55:45 -04:00
Alex Turbov
78fcbb20cd Refactor: Remove reducible flag from handleLevelN() functions
The indicator that smth has been done is the `newArgs` size get
differ after an iteration.

Signed-off-by: Alex Turbov <i.zaufi@gmail.com>
2021-08-03 10:55:45 -04:00
Alex Turbov
b0d6596399 Refactor: Make cmConditionEvaluator::IsTrue a bit more compact
Signed-off-by: Alex Turbov <i.zaufi@gmail.com>
2021-08-03 10:55:30 -04:00
Alex Turbov
18bd6c98ea Refactor: Generalize policy checking in HandleLevel1
Also, move OLD policy checking out of the loop to evaluate it once.
2021-07-26 23:40:18 +03:00
Alex Turbov
8bc4a740d6 Refactor: When handle predicates, there is no need to check 2nd arg
Introduce an overload for `IncrementArguments()` w/ one iterator
and use it in the handler level 1.
2021-07-26 23:40:18 +03:00
Alex Turbov
9946ff6848 Refactor: Initialize args vector from iterators instead of copy
Signed-off-by: Alex Turbov <i.zaufi@gmail.com>
2021-07-26 23:40:18 +03:00
Alex Turbov
bf2fe90372 Refactor: Speedup predicates and binary operation
Before predicates and binary ops reducers use series of `if ()` blocks
to match the keywords. However, if matched the currect `arg` get replaced
with evaluation result, so further `if (<match-another-keyword>)`
is just wasting time/resources.

This patch introduce a chain of `if` → `else if` → ..., so after
first match the loop restarts w/ the next argument.
2021-07-26 23:40:18 +03:00
Alex Turbov
7bec39dc10 Style: Add empty lines to increase readability
Signed-off-by: Alex Turbov <i.zaufi@gmail.com>
2021-07-26 23:40:18 +03:00
Alex Turbov
314538703a Refactor: Deduplicate code for AND and OR handling in if() command
Signed-off-by: Alex Turbov <i.zaufi@gmail.com>
2021-07-26 23:40:18 +03:00
Alex Turbov
95fc27cedd Refactor: Rewrite parenthesis scanner to avoid ifs
Signed-off-by: Alex Turbov <i.zaufi@gmail.com>
2021-07-26 23:40:18 +03:00
Alex Turbov
135c37bdd7 Refactor: Make HandleBinaryOp and HandlePredicate free functions 2021-07-26 23:40:18 +03:00
Alex Turbov
498c8c7773 Refactor: More auto and constness
Signed-off-by: Alex Turbov <i.zaufi@gmail.com>
2021-07-26 23:40:18 +03:00
Alex Turbov
961df6cde6 Refactor: Make IncrementArguments() the free function
Signed-off-by: Alex Turbov <i.zaufi@gmail.com>
2021-07-26 23:40:18 +03:00
Alex Turbov
0f65d0cd83 Refactor: Turn the innter while loop in HandleLevelN() into for
Signed-off-by: Alex Turbov <i.zaufi@gmail.com>
2021-07-26 23:40:18 +03:00
Alex Turbov
24cbfb8d96 Refactor: Turn reducible flag into boolean
Signed-off-by: Alex Turbov <i.zaufi@gmail.com>
2021-07-26 23:40:18 +03:00
Alex Turbov
c26f15c66d Refactor: Use cm::string_view for static const literals
Signed-off-by: Alex Turbov <i.zaufi@gmail.com>
2021-07-26 23:40:14 +03:00
Alex Turbov
fab3890025 Refactor: Opt-out if stataments to select 1st param
... for some calls to `cmExpandedCommandArgument`.

Signed-off-by: Alex Turbov <i.zaufi@gmail.com>
2021-07-26 21:20:27 +03:00
Alex Turbov
4b4e603075 Refactor: Add constness
Signed-off-by: Alex Turbov <i.zaufi@gmail.com>
2021-07-26 21:20:18 +03:00
Alex Turbov
bebb3a1f5a Refactor: Use anonymous namespace instead of static keyword for consts
Signed-off-by: Alex Turbov <i.zaufi@gmail.com>
2021-07-26 21:20:05 +03:00
Brad King
ec1b6157cb Update CMake code using KWSys to account for Status return values
KWSys as of 2021-04-14 changed the return type of `SystemTools`
operations from `bool` to `Status`.  Update our call sites.
This may improve error reporting accuracy in a few places.
2021-04-14 13:14:09 -04:00
Oleksandr Koval
209daa20b2 Code style: add missed explicit 'this->'
CMake uses explicit 'this->' style. Using custom clang-tidy check we can
detect and fix places where 'this->' was missed.
2021-01-05 14:32:36 +02:00
Brad King
e456dae669 cmConditionEvaluator: Remove extra copy of execution context
The execution context passed to the constructor always matches the top
of the backtrace, so the former can be removed in favor of using only
the latter.
2020-09-28 09:49:08 -04:00
vvs31415
dae5fe8b8f cmConditionEvaluator: More use of cmProp 2020-09-08 12:19:34 -04:00
vvs31415
4bc1486cd3 cmConditionEvaluator: Avoid comparing pointers 2020-09-04 13:39:27 -04:00
Vitaly Stakhovsky
11425041f0 cmMakefile::GetDefinition: return cmProp 2020-09-02 07:27:32 -04:00