summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-preprocessor.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2023-07-31 15:40:29 -0400
committerGitHub <noreply@github.com>2023-07-31 15:40:29 -0400
commit5349241098076bead63f638daf2e4b9a9cb3e496 (patch)
treec3b1ea606d5ce41866e36b3df6ebb3c49265b406 /source/slang/slang-preprocessor.cpp
parent8bfdc39259d0a401a33d3be69b22c8dd9b576683 (diff)
Fix for #elif evaluation issue (#3038)
* A more way robust way to handle resource consumption might use multiple `kind`s on GLSL emit. * Improve method naming and some comments. * Small consistency fix. * Fix issue with #elif evaluation. * Add a test.
Diffstat (limited to 'source/slang/slang-preprocessor.cpp')
-rw-r--r--source/slang/slang-preprocessor.cpp41
1 files changed, 25 insertions, 16 deletions
diff --git a/source/slang/slang-preprocessor.cpp b/source/slang/slang-preprocessor.cpp
index 6e7ae7cfb..4cc9bd113 100644
--- a/source/slang/slang-preprocessor.cpp
+++ b/source/slang/slang-preprocessor.cpp
@@ -86,7 +86,7 @@ struct Conditional
/// The preprocessor should not skip tokens, and should not bother evaluating subsequent branch conditions.
During,
- /// Indicates that this conditional has laready seen the branch with a `true` condition
+ /// Indicates that this conditional has already seen the branch with a `true` condition
///
/// The preprocessor should skip tokens, and should not bother evaluating subsequent branch conditions.
After,
@@ -963,7 +963,7 @@ private:
InputFile* m_parent = nullptr;
/// The inner-most preprocessor conditional active for this file.
- Conditional* m_conditional = nullptr;
+ Conditional* m_conditional = nullptr;
/// The lexer input stream that unexpanded tokens will be read from
LexerInputStream* m_lexerStream;
@@ -2860,7 +2860,6 @@ static void HandleElifDirective(PreprocessorDirectiveContext* context)
//
// This is the behavior expected by at least one input program.
// We will eventually want to be pedantic about this.
- // even if t
switch(PeekRawTokenType(context))
{
case TokenType::EndOfFile:
@@ -2870,8 +2869,6 @@ static void HandleElifDirective(PreprocessorDirectiveContext* context)
return;
}
- PreprocessorExpressionValue value = _parseAndEvaluateExpression(context);
-
// if we aren't inside a conditional, then error
Conditional* conditional = inputFile->getInnerMostConditional();
if (!conditional)
@@ -2890,17 +2887,29 @@ static void HandleElifDirective(PreprocessorDirectiveContext* context)
switch (conditional->state)
{
- case Conditional::State::Before:
- if(value)
- conditional->state = Conditional::State::During;
- break;
-
- case Conditional::State::During:
- conditional->state = Conditional::State::After;
- break;
-
- default:
- break;
+ case Conditional::State::Before:
+ {
+ // Only evaluate the expression if we are in the before state.
+ const PreprocessorExpressionValue value = _parseAndEvaluateExpression(context);
+ if (value)
+ {
+ conditional->state = Conditional::State::During;
+ }
+ break;
+ }
+ case Conditional::State::During:
+ {
+ // Consume to end of line, ignoring expression
+ SkipToEndOfLine(context);
+ conditional->state = Conditional::State::After;
+ break;
+ }
+ default:
+ {
+ // Consume to end of line, ignoring expression
+ SkipToEndOfLine(context);
+ break;
+ }
}
updateLexerFlagsForConditionals(inputFile);