summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-preprocessor.cpp
diff options
context:
space:
mode:
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);