[PATCH] D34263: [preprocessor] When preprocessor option 'SingleFileParseMode' is enabled, parse all directive blocks if the condition uses undefined macros
Argyrios Kyrtzidis via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 19 09:39:18 PDT 2017
akyrtzi added a comment.
In https://reviews.llvm.org/D34263#783770, @voskresensky.vladimir wrote:
> What I find problematic in this patch is PPOpts->SingleFileParseMode checks.
> Let's suppose we implement what I mentioned above => how is it going to co-exist nicely? I think code will be less understandable with both: check of flag and call to PPCallbacks.
> What I propose is to move the logic from the PPOpts single flag into PPCallbacks. And from check of flag to query of PPCallbacks.
> Of course when you create PPCallbacks you can consult global SingleFileParseMode to create default implementation to answer "any symbol is defined", so you get your use-case easily handled, but it also gives others more flexibility.
There is a bit of misunderstanding on what this patch is doing, the patch is not about answering "any symbol is defined". See my cfe-dev email (http://lists.llvm.org/pipermail/cfe-dev/2017-June/054254.html) that provides some more context.
The patch is doing these 2 things:
- Keep track of whether a preprocessor directive condition used a symbol that was not resolved at all
- If above is true then make the preprocessor parse all directive blocks, not arbitrary choose one of them.
Here's an example to clarify the difference:
Say that you have this code:
#if TARGET_IOS
@interface A @end
#else
@interface B @end
#endif
1. Without any changes this will happen:
- TARGET_IOS is unresolved so it will be treated as `0`
- `#if` block will be skipped, `#else` will be parsed
- AST will contain `@interface B`
2. With adding a PPCallback that answers "any symbol is defined" (what you are proposing):
- TARGET_IOS is undefined but the PPCallback sets it to `1`
- `#if` block will be parsed, `#else` will be skipped
- AST will contain `@interface A`
3. With this patch and enabling `SingleFileParseMode`
- TARGET_IOS is unresolved
- Both `#if` and `#else` blocks will be parsed
- AST will contain both `@interface A` and `@interface B`
As you can see 2. and 3. above are not overlapping so they can "co-exist nicely" like this:
- TARGET_IOS is undefined, ask the PPCallback if it has a value for it or not
- If the callback provides a value then parse as 1. or 2. depending on the value
- If the callback cannot provide a specific value then parse as 3.
https://reviews.llvm.org/D34263
More information about the cfe-commits
mailing list