[all-commits] [llvm/llvm-project] af89e4: [pseudo] Add crude heuristics to choose taken prep...

Sam McCall via All-commits all-commits at lists.llvm.org
Wed Apr 6 08:23:00 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: af89e4792d23779969c70284dcf6cfafa411637c
      https://github.com/llvm/llvm-project/commit/af89e4792d23779969c70284dcf6cfafa411637c
  Author: Sam McCall <sam.mccall at gmail.com>
  Date:   2022-04-06 (Wed, 06 Apr 2022)

  Changed paths:
    M clang-tools-extra/pseudo/include/clang-pseudo/DirectiveMap.h
    M clang-tools-extra/pseudo/include/clang-pseudo/Token.h
    M clang-tools-extra/pseudo/lib/DirectiveMap.cpp
    M clang-tools-extra/pseudo/test/lex.c
    M clang-tools-extra/pseudo/tool/ClangPseudo.cpp
    M clang-tools-extra/pseudo/unittests/DirectiveMapTest.cpp

  Log Message:
  -----------
  [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




More information about the All-commits mailing list