diff --git a/StandAlone/StandAlone.cpp b/StandAlone/StandAlone.cpp index 37313fd0..d133b594 100644 --- a/StandAlone/StandAlone.cpp +++ b/StandAlone/StandAlone.cpp @@ -582,7 +582,7 @@ void CompileAndLinkShaderUnits(std::vector compUnits) if (Options & EOptionOutputPreprocessed) { std::string str; - glslang::TShader::Includer includer; + glslang::TShader::ForbidIncluder includer; if (shader->preprocess(&Resources, defaultVersion, ENoProfile, false, false, messages, &str, includer)) { PutsIfNonEmpty(str.c_str()); diff --git a/glslang/MachineIndependent/ShaderLang.cpp b/glslang/MachineIndependent/ShaderLang.cpp index ac1156e4..321940a6 100644 --- a/glslang/MachineIndependent/ShaderLang.cpp +++ b/glslang/MachineIndependent/ShaderLang.cpp @@ -221,7 +221,7 @@ bool InitializeSymbolTable(const TString& builtIns, int version, EProfile profil language, infoSink, spvVersion, true, EShMsgDefault, true)); - TShader::Includer includer; + TShader::ForbidIncluder includer; TPpContext ppContext(*parseContext, "", includer); TScanContext scanContext(*parseContext); parseContext->setScanContext(&scanContext); @@ -1217,7 +1217,7 @@ int ShCompile( compiler->infoSink.debug.erase(); TIntermediate intermediate(compiler->getLanguage()); - TShader::Includer includer; + TShader::ForbidIncluder includer; bool success = CompileDeferred(compiler, shaderStrings, numStrings, inputLengths, nullptr, "", optLevel, resources, defaultVersion, ENoProfile, false, forwardCompatible, messages, intermediate, includer); diff --git a/glslang/MachineIndependent/preprocessor/Pp.cpp b/glslang/MachineIndependent/preprocessor/Pp.cpp index 411806f4..49c78ef8 100644 --- a/glslang/MachineIndependent/preprocessor/Pp.cpp +++ b/glslang/MachineIndependent/preprocessor/Pp.cpp @@ -576,12 +576,12 @@ int TPpContext::CPPifdef(int defined, TPpToken* ppToken) int TPpContext::CPPinclude(TPpToken* ppToken) { const TSourceLoc directiveLoc = ppToken->loc; - bool addLocalSearch = true; // to additionally include the extra "" paths + bool startWithLocalSearch = true; // to additionally include the extra "" paths int token = scanToken(ppToken); // handle -style #include if (token == '<') { - addLocalSearch = false; + startWithLocalSearch = false; token = scanHeaderName(ppToken, '>'); } // otherwise ppToken already has the header name and it was "header-name" style @@ -609,7 +609,7 @@ int TPpContext::CPPinclude(TPpToken* ppToken) // Find the inclusion, first look in "Local" ("") paths, if requested, // otherwise, only search the "System" (<>) paths. TShader::Includer::IncludeResult* res = nullptr; - if (addLocalSearch) + if (startWithLocalSearch) res = includer.includeLocal(filename.c_str(), currentSourceFile.c_str(), includeStack.size() + 1); if (! res || res->headerName.empty()) { includer.releaseInclude(res); diff --git a/glslang/Public/ShaderLang.h b/glslang/Public/ShaderLang.h index 4b3b1f60..60e539b4 100644 --- a/glslang/Public/ShaderLang.h +++ b/glslang/Public/ShaderLang.h @@ -360,9 +360,11 @@ public: // Resolves an inclusion request by name, current source name, // and include depth. // On success, returns an IncludeResult containing the resolved name - // and content of the include. On failure, returns an IncludeResult + // and content of the include. + // On failure, returns a nullptr, or an IncludeResult // with an empty string for the headerName and error details in the - // header field. The Includer retains ownership of the contents + // header field. + // The Includer retains ownership of the contents // of the returned IncludeResult value, and those contents must // remain valid until the releaseInclude method is called on that // IncludeResult object. @@ -385,14 +387,20 @@ public: // Signals that the parser will no longer use the contents of the // specified IncludeResult. - virtual void releaseInclude(IncludeResult* result) { } + virtual void releaseInclude(IncludeResult*) = 0; virtual ~Includer() {} }; + // Fail all Includer searches + class ForbidIncluder : public Includer { + public: + virtual void releaseInclude(IncludeResult*) override { } + }; + bool parse(const TBuiltInResource* res, int defaultVersion, EProfile defaultProfile, bool forceDefaultVersionAndProfile, bool forwardCompatible, EShMessages messages) { - TShader::Includer includer; + TShader::ForbidIncluder includer; return parse(res, defaultVersion, defaultProfile, forceDefaultVersionAndProfile, forwardCompatible, messages, includer); } diff --git a/gtests/TestFixture.h b/gtests/TestFixture.h index ea377141..6f4afc66 100644 --- a/gtests/TestFixture.h +++ b/gtests/TestFixture.h @@ -521,7 +521,7 @@ public: glslang::TShader shader(EShLangVertex); shader.setStringsWithLengths(&shaderStrings, &shaderLengths, 1); std::string ppShader; - glslang::TShader::Includer includer; + glslang::TShader::ForbidIncluder includer; const bool success = shader.preprocess( &glslang::DefaultTBuiltInResource, defaultVersion, defaultProfile, forceVersionProfile, isForwardCompatible, (EShMessages)(EShMsgOnlyPreprocessor | EShMsgCascadingErrors),