From: Lei Zhang Date: Sun, 5 Jul 2015 02:30:59 +0000 (-0400) Subject: Fix empty line handling in line directive callback. X-Git-Tag: upstream/0.1~476^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=46ea5396ef02fc022266966a000b90412a848595;p=platform%2Fupstream%2Fglslang.git Fix empty line handling in line directive callback. The current line number for the #line directive should be passed in as parameter to the line directive callback. Without it, we don't know how many empty lines we should output. --- diff --git a/Test/baseResults/preprocessor.line.frag.out b/Test/baseResults/preprocessor.line.frag.out index 2145b6f..3e2206f 100644 --- a/Test/baseResults/preprocessor.line.frag.out +++ b/Test/baseResults/preprocessor.line.frag.out @@ -1,5 +1,4 @@ #version 310 es - #line 1 2 #pragma something void main(){ } diff --git a/Test/baseResults/preprocessor.line.vert.out b/Test/baseResults/preprocessor.line.vert.out index 5d9709b..2bf0903 100644 --- a/Test/baseResults/preprocessor.line.vert.out +++ b/Test/baseResults/preprocessor.line.vert.out @@ -1,23 +1,39 @@ -#line 300 - -#line 2 - -#line 10 - -#line 2 - -#line 0 -#line 4 - -#line 8 - -void main(){ - gl_Position = vec4(10); -} -#line 8 4 - -#line 12 3 - -#line 1 - - +#line 300 + +#line 2 + + + + + +#line 10 + + +#line 2 + +#line 0 + + + +#line 4 + + + + + +#line 8 + +void main(){ + gl_Position = vec4(10); +} + +#line 8 4 + + + + +#line 12 3 + +#line 1 + + diff --git a/glslang/MachineIndependent/ParseHelper.cpp b/glslang/MachineIndependent/ParseHelper.cpp index 8527fd5..9a703ab 100644 --- a/glslang/MachineIndependent/ParseHelper.cpp +++ b/glslang/MachineIndependent/ParseHelper.cpp @@ -5254,10 +5254,10 @@ void TParseContext::notifyErrorDirective(int line, const char* error_message) } } -void TParseContext::notifyLineDirective(int line, bool has_source, int source) +void TParseContext::notifyLineDirective(int curLineNo, int newLineNo, bool hasSource, int sourceNum) { if (lineCallback) { - lineCallback(line, has_source, source); + lineCallback(curLineNo, newLineNo, hasSource, sourceNum); } } diff --git a/glslang/MachineIndependent/ParseHelper.h b/glslang/MachineIndependent/ParseHelper.h index ee8ff0a..5abad05 100644 --- a/glslang/MachineIndependent/ParseHelper.h +++ b/glslang/MachineIndependent/ParseHelper.h @@ -216,7 +216,7 @@ public: void notifyVersion(int line, int version, const char* type_string); void notifyErrorDirective(int line, const char* error_message); - void notifyLineDirective(int line, bool has_source, int source); + void notifyLineDirective(int curLineNo, int newLineNo, bool hasSource, int sourceNum); // The following are implemented in Versions.cpp to localize version/profile/stage/extensions control void initializeExtensionBehavior(); @@ -236,7 +236,7 @@ public: void setVersionCallback(const std::function& func) { versionCallback = func; } void setPragmaCallback(const std::function&)>& func) { pragmaCallback = func; } - void setLineCallback(const std::function& func) { lineCallback = func; } + void setLineCallback(const std::function& func) { lineCallback = func; } void setExtensionCallback(const std::function& func) { extensionCallback = func; } void setErrorCallback(const std::function& func) { errorCallback = func; } @@ -347,7 +347,7 @@ protected: // These, if set, will be called when a line, pragma ... is preprocessed. // They will be called with any parameters to the original directive. - std::function lineCallback; + std::function lineCallback; std::function&)> pragmaCallback; std::function versionCallback; std::function extensionCallback; diff --git a/glslang/MachineIndependent/ShaderLang.cpp b/glslang/MachineIndependent/ShaderLang.cpp index 10709c5..9898c75 100644 --- a/glslang/MachineIndependent/ShaderLang.cpp +++ b/glslang/MachineIndependent/ShaderLang.cpp @@ -639,12 +639,10 @@ struct DoPreprocessing { adjustLine(line); outputStream << "#extension " << extension << " : " << behavior; }); - parseContext.setLineCallback([&lastLine, &outputStream, &parseContext]( - int newLineNo, bool hasSource, int sourceNum) { + parseContext.setLineCallback([&adjustLine, &lastLine, &outputStream, &parseContext]( + int curLineNo, int newLineNo, bool hasSource, int sourceNum) { // SourceNum is the number of the source-string that is being parsed. - if (lastLine != -1) { - outputStream << std::endl; - } + adjustLine(curLineNo); outputStream << "#line " << newLineNo; if (hasSource) { outputStream << " " << sourceNum; diff --git a/glslang/MachineIndependent/preprocessor/Pp.cpp b/glslang/MachineIndependent/preprocessor/Pp.cpp index 84b4073..54cea32 100644 --- a/glslang/MachineIndependent/preprocessor/Pp.cpp +++ b/glslang/MachineIndependent/preprocessor/Pp.cpp @@ -624,6 +624,7 @@ int TPpContext::CPPline(TPpToken* ppToken) // "#line line source-string-number" int token = scanToken(ppToken); + const int directiveLoc = ppToken->loc.line; if (token == '\n') { parseContext.error(ppToken->loc, "must by followed by an integral literal", "#line", ""); return token; @@ -653,7 +654,7 @@ int TPpContext::CPPline(TPpToken* ppToken) } } if (!fileErr && !lineErr) { - parseContext.notifyLineDirective(lineToken, hasFile, fileRes); + parseContext.notifyLineDirective(directiveLoc, lineToken, hasFile, fileRes); } token = extraTokenCheck(lineAtom, ppToken, token);