This is an archive of the discontinued LLVM Phabricator instance.

[pseudo] Strip directives from a token stream
ClosedPublic

Authored by sammccall on Apr 6 2022, 12:36 PM.

Details

Summary

This includes only the taken branch of conditional sections.
The API allows for producing a stream for a particular PP branch, which
will be used later for the secondary GLR parses of not-taken branches.

Diff Detail

Event Timeline

sammccall created this revision.Apr 6 2022, 12:36 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 6 2022, 12:36 PM
sammccall requested review of this revision.Apr 6 2022, 12:36 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 6 2022, 12:36 PM
hokein added inline comments.Apr 8 2022, 2:40 AM
clang-tools-extra/pseudo/lib/DirectiveTree.cpp
373

return, otherwise we we hit the unreachable code below.

clang-tools-extra/pseudo/tool/ClangPseudo.cpp
40

preprocess seems a little confusing (the name reminds me of the traditional preprocessor process where comments are stripped, but not in our case here). may be strip-directives but it doesn't reflect the conditional-#if token work, but I think it is fine.

This flag is a feature-control flag for print-source and print-tokens, can we group three of them together?

hokein accepted this revision.May 3 2022, 1:45 PM

would be nice to land it in some of form.

clang-tools-extra/pseudo/unittests/DirectiveTreeTest.cpp
316

nit: cover #include as well?

This revision is now accepted and ready to land.May 3 2022, 1:45 PM
sammccall marked 2 inline comments as done.May 6 2022, 3:07 AM
sammccall added inline comments.
clang-tools-extra/pseudo/lib/DirectiveTree.cpp
373

That's deliberate, K_Empty is invalid.

clang-tools-extra/pseudo/tool/ClangPseudo.cpp
40

may be strip-directives but it doesn't reflect the conditional-#if token work, but I think it is fine

Agreed, renamed it.

This flag is a feature-control flag for print-source and print-tokens, can we group three of them together?

It's not really, it also affects the GLR parser etc.
Generally I think we should try to make the flags in this tool more orthogonal rather than clustering them by effects. Thematically it's more closely related to -print-directive-tree.

sammccall updated this revision to Diff 427581.May 6 2022, 3:11 AM
sammccall marked an inline comment as done.

rebase
add include to testcase
rename preprocess => strip-includes, and testcase
move print directivetree test to strip-includes.c
fix tests to not cook before parsing directivetree

This revision was landed with ongoing or failed builds.May 6 2022, 3:15 AM
This revision was automatically updated to reflect the committed changes.