diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2017-06-12 15:34:12 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-06-12 15:34:12 -0700 |
| commit | 7fc4c40b17f340800d6616e0bae111606cef18cc (patch) | |
| tree | e1c59d0b48397e8e33428e65a2e0f3c6925c65d9 /source/slang/preprocessor.cpp | |
| parent | ce90fec1c795eaafbd91d7b8a83501a57eeb1946 (diff) | |
| parent | 97fc943b476e2482bd1f99c9e76f0dfe8fdd36e0 (diff) | |
Merge pull request #4 from tfoleyNV/escaped-newlines
Escaped newlines
Diffstat (limited to 'source/slang/preprocessor.cpp')
| -rw-r--r-- | source/slang/preprocessor.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/source/slang/preprocessor.cpp b/source/slang/preprocessor.cpp index cdde2591d..60329c275 100644 --- a/source/slang/preprocessor.cpp +++ b/source/slang/preprocessor.cpp @@ -450,8 +450,35 @@ static PreprocessorMacro* LookupMacro(PreprocessorEnvironment* environment, Stri static PreprocessorEnvironment* GetCurrentEnvironment(Preprocessor* preprocessor) { + // The environment we will use for looking up a macro is assocaited + // with the current input stream (because it may include entries + // for macro arguments). + // + // We need to be careful, though, when we are at the end of an + // input stream (e.g., representing one argument), so that we + // don't use its environment. + PreprocessorInputStream* inputStream = preprocessor->inputStream; - return inputStream ? inputStream->environment : &preprocessor->globalEnv; + + for(;;) + { + // If there is no input stream that isn't at its end, + // then fall back to the global environment. + if (!inputStream) + return &preprocessor->globalEnv; + + // If the current input stream is at its end, then + // fall back to its parent stream. + if (inputStream->tokenReader.PeekTokenType() == TokenType::EndOfFile) + { + inputStream = inputStream->parent; + continue; + } + + // If we've found an active stream that isn't at its end, + // then use that for lookup. + return inputStream->environment; + } } static PreprocessorMacro* LookupMacro(Preprocessor* preprocessor, String const& name) |
