From 13444545a9f73d18409cf330043adb7d307c88dc Mon Sep 17 00:00:00 2001 From: Jeff Bolz Date: Mon, 9 Mar 2020 21:09:18 -0500 Subject: [PATCH] disable escape sequences for #line and #error --- Test/baseResults/hlsl.pp.line4.frag.out | 4 ++-- glslang/MachineIndependent/preprocessor/Pp.cpp | 4 ++++ glslang/MachineIndependent/preprocessor/PpContext.cpp | 3 ++- glslang/MachineIndependent/preprocessor/PpContext.h | 1 + glslang/MachineIndependent/preprocessor/PpScanner.cpp | 2 +- 5 files changed, 10 insertions(+), 4 deletions(-) mode change 100755 => 100644 glslang/MachineIndependent/preprocessor/PpContext.cpp diff --git a/Test/baseResults/hlsl.pp.line4.frag.out b/Test/baseResults/hlsl.pp.line4.frag.out index c5c9839..1ddb98b 100644 --- a/Test/baseResults/hlsl.pp.line4.frag.out +++ b/Test/baseResults/hlsl.pp.line4.frag.out @@ -9,8 +9,8 @@ hlsl.pp.line4.frag EntryPoint Fragment 5 "MainPs" 70 74 ExecutionMode 5 OriginUpperLeft 1: String "hlsl.pp.line4.frag" - 17: String "C:\Users\Greg\shaders\line\foo4.frag" - 32: String "C:\Users\Greg\shaders\line\u1.h" + 17: String "C:\\Users\\Greg\\shaders\\line\\foo4.frag" + 32: String "C:\\Users\\Greg\\shaders\\line\\u1.h" Source HLSL 500 1 "// OpModuleProcessed auto-map-locations // OpModuleProcessed auto-map-bindings // OpModuleProcessed entry-point MainPs diff --git a/glslang/MachineIndependent/preprocessor/Pp.cpp b/glslang/MachineIndependent/preprocessor/Pp.cpp index 057a8e7..ec39356 100644 --- a/glslang/MachineIndependent/preprocessor/Pp.cpp +++ b/glslang/MachineIndependent/preprocessor/Pp.cpp @@ -722,7 +722,9 @@ int TPpContext::CPPline(TPpToken* ppToken) const char* sourceName = nullptr; // Optional source file name. bool lineErr = false; bool fileErr = false; + disableEscapeSequences = true; token = eval(token, MIN_PRECEDENCE, false, lineRes, lineErr, ppToken); + disableEscapeSequences = false; if (! lineErr) { lineToken = lineRes; if (token == '\n') @@ -765,7 +767,9 @@ int TPpContext::CPPline(TPpToken* ppToken) // Handle #error int TPpContext::CPPerror(TPpToken* ppToken) { + disableEscapeSequences = true; int token = scanToken(ppToken); + disableEscapeSequences = false; std::string message; TSourceLoc loc = ppToken->loc; diff --git a/glslang/MachineIndependent/preprocessor/PpContext.cpp b/glslang/MachineIndependent/preprocessor/PpContext.cpp old mode 100755 new mode 100644 index cc003a8..1363ce2 --- a/glslang/MachineIndependent/preprocessor/PpContext.cpp +++ b/glslang/MachineIndependent/preprocessor/PpContext.cpp @@ -87,7 +87,8 @@ namespace glslang { TPpContext::TPpContext(TParseContextBase& pc, const std::string& rootFileName, TShader::Includer& inclr) : preamble(0), strings(0), previous_token('\n'), parseContext(pc), includer(inclr), inComment(false), rootFileName(rootFileName), - currentSourceFile(rootFileName) + currentSourceFile(rootFileName), + disableEscapeSequences(false) { ifdepth = 0; for (elsetracker = 0; elsetracker < maxIfNesting; elsetracker++) diff --git a/glslang/MachineIndependent/preprocessor/PpContext.h b/glslang/MachineIndependent/preprocessor/PpContext.h index 8470e17..a60fc75 100644 --- a/glslang/MachineIndependent/preprocessor/PpContext.h +++ b/glslang/MachineIndependent/preprocessor/PpContext.h @@ -695,6 +695,7 @@ protected: std::string currentSourceFile; std::istringstream strtodStream; + bool disableEscapeSequences; }; } // end namespace glslang diff --git a/glslang/MachineIndependent/preprocessor/PpScanner.cpp b/glslang/MachineIndependent/preprocessor/PpScanner.cpp index 2758cd2..6cdadec 100644 --- a/glslang/MachineIndependent/preprocessor/PpScanner.cpp +++ b/glslang/MachineIndependent/preprocessor/PpScanner.cpp @@ -1030,7 +1030,7 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken) ch = getch(); while (ch != '"' && ch != '\n' && ch != EndOfInput) { if (len < MaxTokenLength) { - if (ch == '\\') { + if (ch == '\\' && !pp->disableEscapeSequences) { int nextCh = getch(); switch (nextCh) { case '\'': ch = 0x27; break; -- 2.7.4