[pseudo] Add crude heuristics to choose taken preprocessor branches.
authorSam McCall <sam.mccall@gmail.com>
Mon, 7 Mar 2022 22:33:40 +0000 (23:33 +0100)
committerSam McCall <sam.mccall@gmail.com>
Wed, 6 Apr 2022 15:22:35 +0000 (17:22 +0200)
commitaf89e4792d23779969c70284dcf6cfafa411637c
tree8e24ff67089b78fadb925796bd99d01cea226d60
parentf4f1cf6c31beaf387ae73b0407b30b41438dafde
[pseudo] Add crude heuristics to choose taken preprocessor branches.

In files where different preprocessing paths are possible, our goal is to
choose a preprocessed token sequence which we can parse that pins down as much
of the grammatical structure as possible.
This forms the "primary parse", and the not-taken branches get parsed later,
and are constrained to be compatible with the primary parse.

Concretely:
  int x =
    #ifdef // TAKEN
      2 + 2 + 2 // determined during primary parse to be an expression
    #else
      2 // constrained to be an expression during a secondary parse
    #endif
    ;

Differential Revision: https://reviews.llvm.org/D121165
clang-tools-extra/pseudo/include/clang-pseudo/DirectiveMap.h
clang-tools-extra/pseudo/include/clang-pseudo/Token.h
clang-tools-extra/pseudo/lib/DirectiveMap.cpp
clang-tools-extra/pseudo/test/lex.c
clang-tools-extra/pseudo/tool/ClangPseudo.cpp
clang-tools-extra/pseudo/unittests/DirectiveMapTest.cpp