coreboot-kgpe-d16/util/lint
Nico Huber f6b2baa3e8 util/kconfig_lint: Turn handle_expressions() into a parser
I wished there was a way to do this in smaller steps, but with
every line fixed an error somewhere else became visible. Here
is a (probably incomplete) list of the issues:

* Only one set of parentheses was supported. This is a hard
  to solve problem without a real parser (one solution is to
  use an recursive RE, see below).

* The precedence order was wrong. Might have been adapted just
  to give a positive result for the arbitrary state of the tree.

* Numbered match variables (e.g. $1, $2, etc.) are not local.
  Calling handle_expressions() recursively once with $1, then
  with $2, resulted in using the final $2 after the first
  recursive call (garbage, practically).

Also, symbol and expression parsing was mixed, making things
harder to follow.

To remedy the issues:

* Split handle_symbol() out. It is called with whitespace
  stripped, to keep the uglier REs in handle_expressions().

* Match balanced parentheses and quotes when splitting
  expressions. In this recursive RE

    /(\((?:[^\(\)]++|(?-1))*\))/

  the `(?-1)` references the outer-most group, thus the whole
  expression itself. So it matches a pair of parentheses with
  a mix of non-parentheses and the recursive rule itself inside.
  This allows us to:

* Order the expression matches according to their precedence
  rules. Now we can match `<expr> '||' <expr>` first as we should
  and everything else falls into its place.

* Remove the bail-out that silenced the undefined behavior.

Change-Id: Ibc1be79adc07792f0721f0dc08b50422b6da88a9
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/52067
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
2021-04-18 20:35:18 +00:00
..
check-style util: Fix up a few comments after the "file is part of the" removal 2020-05-11 17:11:50 +00:00
check_lint_tests lint/check_lint_tests: Fix obsolete paths 2020-03-02 15:05:32 +00:00
checkpatch.pl
checkpatch_json.py checkpatch_json: Mark robotic comments as robotic 2021-04-15 19:08:00 +00:00
const_structs.checkpatch
description.md
kconfig_lint util/kconfig_lint: Turn handle_expressions() into a parser 2021-04-18 20:35:18 +00:00
kconfig_lint_README
lint util: Update all shebangs to use /usr/bin/env 2021-01-25 08:57:40 +00:00
lint-000-license-headers util: Update all shebangs to use /usr/bin/env 2021-01-25 08:57:40 +00:00
lint-001-no-global-config-in-romstage util: Update all shebangs to use /usr/bin/env 2021-01-25 08:57:40 +00:00
lint-007-checkpatch lint: checkpatch: Only exclude specific src/vendorcode/ subdirectories 2021-04-06 16:04:41 +00:00
lint-008-kconfig util: Update all shebangs to use /usr/bin/env 2021-01-25 08:57:40 +00:00
lint-014-qualified-types util: Update all shebangs to use /usr/bin/env 2021-01-25 08:57:40 +00:00
lint-extended-007-checkpatch util: Update all shebangs to use /usr/bin/env 2021-01-25 08:57:40 +00:00
lint-extended-015-final-newlines util: Update all shebangs to use /usr/bin/env 2021-01-25 08:57:40 +00:00
lint-extended-020-signed-off-by util: Update all shebangs to use /usr/bin/env 2021-01-25 08:57:40 +00:00
lint-stable-000-license-headers util: Update all shebangs to use /usr/bin/env 2021-01-25 08:57:40 +00:00
lint-stable-003-whitespace util: Update all shebangs to use /usr/bin/env 2021-01-25 08:57:40 +00:00
lint-stable-004-style-labels util: Update all shebangs to use /usr/bin/env 2021-01-25 08:57:40 +00:00
lint-stable-005-board-status util: Update all shebangs to use /usr/bin/env 2021-01-25 08:57:40 +00:00
lint-stable-006-board-name util: Update all shebangs to use /usr/bin/env 2021-01-25 08:57:40 +00:00
lint-stable-008-kconfig util: Update all shebangs to use /usr/bin/env 2021-01-25 08:57:40 +00:00
lint-stable-009-old-licenses util: Update all shebangs to use /usr/bin/env 2021-01-25 08:57:40 +00:00
lint-stable-010-asm-syntax util: Update all shebangs to use /usr/bin/env 2021-01-25 08:57:40 +00:00
lint-stable-012-executable-bit util: Update all shebangs to use /usr/bin/env 2021-01-25 08:57:40 +00:00
lint-stable-013-site-local util: Update all shebangs to use /usr/bin/env 2021-01-25 08:57:40 +00:00
lint-stable-016-non-ascii util: Update all shebangs to use /usr/bin/env 2021-01-25 08:57:40 +00:00
lint-stable-017-configs util: Update all shebangs to use /usr/bin/env 2021-01-25 08:57:40 +00:00
lint-stable-018-symlinks util: Update all shebangs to use /usr/bin/env 2021-01-25 08:57:40 +00:00
lint-stable-019-header-files util: Update all shebangs to use /usr/bin/env 2021-01-25 08:57:40 +00:00
lint-stable-021-coreboot-lowercase util: Update all shebangs to use /usr/bin/env 2021-01-25 08:57:40 +00:00
lint-stable-022-clang-format util: Update all shebangs to use /usr/bin/env 2021-01-25 08:57:40 +00:00
lint-stable-023-filenames util: Update all shebangs to use /usr/bin/env 2021-01-25 08:57:40 +00:00
lint-stable-024-kconfig-no-subsystem util: Update all shebangs to use /usr/bin/env 2021-01-25 08:57:40 +00:00
lint-stable-026-line-endings util/lint: Check for windows line endings 2021-02-25 10:03:32 +00:00
lint-stable-027-maintainers-syntax lint: MAINTAINERS: check path matches to not only cover the directory 2021-04-13 14:29:43 +00:00
remccoms3.sed util: Update all shebangs to use /usr/bin/env 2021-01-25 08:57:40 +00:00
spelling.txt util/lint/spelling.txt: Disable pres 2021-01-17 16:49:00 +00:00