From a176a935da472c09a676b9e5d426a9ce69657d3a Mon Sep 17 00:00:00 2001 From: LibretroAdmin Date: Sun, 31 Jul 2022 16:37:49 +0200 Subject: [PATCH] (glslang) Further simplifications of InfoSink - get rid of message() and prefix() - we want simple string concatenation/addition instead of all these layers --- .../glslang/glslang/Include/InfoSink.h | 17 ------ .../MachineIndependent/ParseContextBase.cpp | 53 +++++++++---------- .../glslang/MachineIndependent/ParseHelper.h | 3 -- .../glslang/MachineIndependent/Scan.cpp | 5 +- .../glslang/MachineIndependent/ShaderLang.cpp | 4 +- .../glslang/MachineIndependent/Versions.cpp | 24 +++++++-- .../glslang/MachineIndependent/intermOut.cpp | 5 +- .../MachineIndependent/linkValidate.cpp | 12 ++--- deps/glslang/glslang/hlsl/hlslScanContext.cpp | 5 +- 9 files changed, 65 insertions(+), 63 deletions(-) diff --git a/deps/glslang/glslang/glslang/Include/InfoSink.h b/deps/glslang/glslang/glslang/Include/InfoSink.h index 89de84042e..8a7747d025 100644 --- a/deps/glslang/glslang/glslang/Include/InfoSink.h +++ b/deps/glslang/glslang/glslang/Include/InfoSink.h @@ -76,17 +76,6 @@ public: TInfoSinkBase& operator<<(const TString& t) { append(t); return *this; } TInfoSinkBase& operator+(const char* s) { append(s); return *this; } const char* c_str() const { return sink.c_str(); } - void prefix(TPrefixType message) { - switch(message) { - case EPrefixNone: break; - case EPrefixWarning: append("WARNING: "); break; - case EPrefixError: append("ERROR: "); break; - case EPrefixInternalError: append("INTERNAL ERROR: "); break; - case EPrefixUnimplemented: append("UNIMPLEMENTED: "); break; - case EPrefixNote: append("NOTE: "); break; - default: append("UNKNOWN ERROR: "); break; - } - } void location(const TSourceLoc& loc) { char locText[24]; snprintf(locText, 24, ":%d", loc.line); @@ -94,12 +83,6 @@ public: append(locText); append(": "); } - void message(TPrefixType message, const char* s, const TSourceLoc& loc) { - prefix(message); - location(loc); - append(s); - append("\n"); - } void append(const char* s); diff --git a/deps/glslang/glslang/glslang/MachineIndependent/ParseContextBase.cpp b/deps/glslang/glslang/glslang/MachineIndependent/ParseContextBase.cpp index bfa9de4dff..37810279c6 100644 --- a/deps/glslang/glslang/glslang/MachineIndependent/ParseContextBase.cpp +++ b/deps/glslang/glslang/glslang/MachineIndependent/ParseContextBase.cpp @@ -44,29 +44,6 @@ extern int yyparse(glslang::TParseContext*); namespace glslang { -// -// Used to output syntax, parsing, and semantic errors. -// - -void TParseContextBase::outputMessage(const TSourceLoc& loc, const char* szReason, - const char* szToken, - const char* szExtraInfoFormat, - TPrefixType prefix, va_list args) -{ - const int maxSize = MaxTokenLength + 200; - char szExtraInfo[maxSize]; - - safe_vsprintf(szExtraInfo, maxSize, szExtraInfoFormat, args); - - infoSink.info.prefix(prefix); - infoSink.info.location(loc); - infoSink.info << "'" << szToken << "' : " << szReason << " " << szExtraInfo << "\n"; - - if (prefix == EPrefixError) { - ++numErrors; - } -} - void C_DECL TParseContextBase::error(const TSourceLoc& loc, const char* szReason, const char* szToken, const char* szExtraInfoFormat, ...) { @@ -74,7 +51,13 @@ void C_DECL TParseContextBase::error(const TSourceLoc& loc, const char* szReason return; va_list args; va_start(args, szExtraInfoFormat); - outputMessage(loc, szReason, szToken, szExtraInfoFormat, EPrefixError, args); + const int maxSize = MaxTokenLength + 200; + char szExtraInfo[maxSize]; + safe_vsprintf(szExtraInfo, maxSize, szExtraInfoFormat, args); + infoSink.info.append("ERROR: "); + infoSink.info.location(loc); + infoSink.info << "'" << szToken << "' : " << szReason << " " << szExtraInfo << "\n"; + ++numErrors; va_end(args); if ((messages & EShMsgCascadingErrors) == 0) @@ -88,7 +71,12 @@ void C_DECL TParseContextBase::warn(const TSourceLoc& loc, const char* szReason, return; va_list args; va_start(args, szExtraInfoFormat); - outputMessage(loc, szReason, szToken, szExtraInfoFormat, EPrefixWarning, args); + const int maxSize = MaxTokenLength + 200; + char szExtraInfo[maxSize]; + safe_vsprintf(szExtraInfo, maxSize, szExtraInfoFormat, args); + infoSink.info.append("WARNING: "); + infoSink.info.location(loc); + infoSink.info << "'" << szToken << "' : " << szReason << " " << szExtraInfo << "\n"; va_end(args); } @@ -97,7 +85,13 @@ void C_DECL TParseContextBase::ppError(const TSourceLoc& loc, const char* szReas { va_list args; va_start(args, szExtraInfoFormat); - outputMessage(loc, szReason, szToken, szExtraInfoFormat, EPrefixError, args); + const int maxSize = MaxTokenLength + 200; + char szExtraInfo[maxSize]; + safe_vsprintf(szExtraInfo, maxSize, szExtraInfoFormat, args); + infoSink.info.append("ERROR: "); + infoSink.info.location(loc); + infoSink.info << "'" << szToken << "' : " << szReason << " " << szExtraInfo << "\n"; + ++numErrors; va_end(args); if ((messages & EShMsgCascadingErrors) == 0) @@ -109,7 +103,12 @@ void C_DECL TParseContextBase::ppWarn(const TSourceLoc& loc, const char* szReaso { va_list args; va_start(args, szExtraInfoFormat); - outputMessage(loc, szReason, szToken, szExtraInfoFormat, EPrefixWarning, args); + const int maxSize = MaxTokenLength + 200; + char szExtraInfo[maxSize]; + safe_vsprintf(szExtraInfo, maxSize, szExtraInfoFormat, args); + infoSink.info.append("WARNING: "); + infoSink.info.location(loc); + infoSink.info << "'" << szToken << "' : " << szReason << " " << szExtraInfo << "\n"; va_end(args); } diff --git a/deps/glslang/glslang/glslang/MachineIndependent/ParseHelper.h b/deps/glslang/glslang/glslang/MachineIndependent/ParseHelper.h index dd8e30d20e..5ff84ebf2f 100644 --- a/deps/glslang/glslang/glslang/MachineIndependent/ParseHelper.h +++ b/deps/glslang/glslang/glslang/MachineIndependent/ParseHelper.h @@ -220,9 +220,6 @@ protected: virtual const char* getGlobalUniformBlockName() const { return ""; } virtual void setUniformBlockDefaults(TType&) const { } virtual void finalizeGlobalUniformBlockLayout(TVariable&) { } - virtual void outputMessage(const TSourceLoc&, const char* szReason, const char* szToken, - const char* szExtraInfoFormat, TPrefixType prefix, - va_list args); virtual void trackLinkage(TSymbol& symbol); virtual void makeEditable(TSymbol*&); virtual TVariable* getEditableVariable(const char* name); diff --git a/deps/glslang/glslang/glslang/MachineIndependent/Scan.cpp b/deps/glslang/glslang/glslang/MachineIndependent/Scan.cpp index 0464f965fd..c65e63225f 100755 --- a/deps/glslang/glslang/glslang/MachineIndependent/Scan.cpp +++ b/deps/glslang/glslang/glslang/MachineIndependent/Scan.cpp @@ -1506,7 +1506,10 @@ int TScanContext::tokenizeIdentifier() } default: - _parseContext.infoSink.info.message(EPrefixInternalError, "Unknown glslang keyword", loc); + _parseContext.infoSink.info.append("INTERNAL ERROR: "); + _parseContext.infoSink.info.location(loc); + _parseContext.infoSink.info.append("Unknown glslang keyword"); + _parseContext.infoSink.info.append("\n"); return 0; } } diff --git a/deps/glslang/glslang/glslang/MachineIndependent/ShaderLang.cpp b/deps/glslang/glslang/glslang/MachineIndependent/ShaderLang.cpp index 937442e0e9..15dbfb3066 100644 --- a/deps/glslang/glslang/glslang/MachineIndependent/ShaderLang.cpp +++ b/deps/glslang/glslang/glslang/MachineIndependent/ShaderLang.cpp @@ -1101,7 +1101,7 @@ struct DoPreprocessing { bool success = true; if (_parseContext.getNumErrors() > 0) { success = false; - _parseContext.infoSink.info.prefix(EPrefixError); + _parseContext.infoSink.info.append("ERROR: "); _parseContext.infoSink.info << _parseContext.getNumErrors() << " compilation errors. No code generated.\n\n"; } return success; @@ -1132,7 +1132,7 @@ struct DoFullParse{ else success = intermediate.postProcess(intermediate.getTreeRoot(), _parseContext.getLanguage()); } else if (! success) { - _parseContext.infoSink.info.prefix(EPrefixError); + _parseContext.infoSink.info.append("ERROR: "); _parseContext.infoSink.info << _parseContext.getNumErrors() << " compilation errors. No code generated.\n\n"; } diff --git a/deps/glslang/glslang/glslang/MachineIndependent/Versions.cpp b/deps/glslang/glslang/glslang/MachineIndependent/Versions.cpp index 46c75eb8a9..1e2989930f 100755 --- a/deps/glslang/glslang/glslang/MachineIndependent/Versions.cpp +++ b/deps/glslang/glslang/glslang/MachineIndependent/Versions.cpp @@ -510,7 +510,10 @@ void TParseVersions::profileRequires(const TSourceLoc& loc, int profileMask, int for (int i = 0; i < numExtensions; ++i) { switch (getExtensionBehavior(extensions[i])) { case EBhWarn: - infoSink.info.message(EPrefixWarning, ("extension " + TString(extensions[i]) + " is being used for " + featureDesc).c_str(), loc); + infoSink.info.append("WARNING: "); + infoSink.info.location(loc); + infoSink.info.append(("extension " + TString(extensions[i]) + " is being used for " + featureDesc).c_str()); + infoSink.info.append("\n"); // fall through case EBhRequire: case EBhEnable: @@ -562,8 +565,13 @@ void TParseVersions::checkDeprecated(const TSourceLoc& loc, int profileMask, int if (forwardCompatible) error(loc, "deprecated, may be removed in future release", featureDesc, ""); else if (! suppressWarnings()) - infoSink.info.message(EPrefixWarning, (TString(featureDesc) + " deprecated in version " + - String(depVersion) + "; may be removed in future release").c_str(), loc); + { + infoSink.info.append("WARNING: "); + infoSink.info.location(loc); + infoSink.info.append((TString(featureDesc) + " deprecated in version " + + String(depVersion) + "; may be removed in future release").c_str()); + infoSink.info.append("\n"); + } } } } @@ -605,11 +613,17 @@ bool TParseVersions::checkExtensionsRequested(const TSourceLoc& loc, int numExte for (int i = 0; i < numExtensions; ++i) { TExtensionBehavior behavior = getExtensionBehavior(extensions[i]); if (behavior == EBhDisable && relaxedErrors()) { - infoSink.info.message(EPrefixWarning, "The following extension must be enabled to use this feature:", loc); + infoSink.info.append("WARNING: "); + infoSink.info.location(loc); + infoSink.info.append("The following extension must be enabled to use this feature:"); + infoSink.info.append("\n"); behavior = EBhWarn; } if (behavior == EBhWarn) { - infoSink.info.message(EPrefixWarning, ("extension " + TString(extensions[i]) + " is being used for " + featureDesc).c_str(), loc); + infoSink.info.append("WARNING: "); + infoSink.info.location(loc); + infoSink.info.append(("extension " + TString(extensions[i]) + " is being used for " + featureDesc).c_str()); + infoSink.info.append("\n"); warned = true; } } diff --git a/deps/glslang/glslang/glslang/MachineIndependent/intermOut.cpp b/deps/glslang/glslang/glslang/MachineIndependent/intermOut.cpp index 9c73ca12a7..75b066d02c 100755 --- a/deps/glslang/glslang/glslang/MachineIndependent/intermOut.cpp +++ b/deps/glslang/glslang/glslang/MachineIndependent/intermOut.cpp @@ -1251,7 +1251,10 @@ static void OutputConstantUnion(TInfoSink& out, const TIntermTyped* node, const } break; default: - out.info.message(EPrefixInternalError, "Unknown constant", node->getLoc()); + out.info.append("INTERNAL ERROR: "); + out.info.location(node->getLoc()); + out.info.append("Unknown constant"); + out.info.append("\n"); break; } } diff --git a/deps/glslang/glslang/glslang/MachineIndependent/linkValidate.cpp b/deps/glslang/glslang/glslang/MachineIndependent/linkValidate.cpp index c540ae6477..c15ae067df 100644 --- a/deps/glslang/glslang/glslang/MachineIndependent/linkValidate.cpp +++ b/deps/glslang/glslang/glslang/MachineIndependent/linkValidate.cpp @@ -55,7 +55,7 @@ namespace glslang { // void TIntermediate::error(TInfoSink& infoSink, const char* message) { - infoSink.info.prefix(EPrefixError); + infoSink.info.append("ERROR: "); infoSink.info << "Linking " << StageName(language) << " stage: " << message << "\n"; ++numErrors; @@ -64,7 +64,7 @@ void TIntermediate::error(TInfoSink& infoSink, const char* message) // Link-time warning. void TIntermediate::warn(TInfoSink& infoSink, const char* message) { - infoSink.info.prefix(EPrefixWarning); + infoSink.info.append("WARNING: "); infoSink.info << "Linking " << StageName(language) << " stage: " << message << "\n"; } @@ -435,7 +435,7 @@ void TIntermediate::finalCheck(TInfoSink& infoSink, bool keepUncalled) // compile-time or link-time error to have different values specified for the stride for the same buffer." if (xfbBuffers[b].stride != TQualifier::layoutXfbStrideEnd && xfbBuffers[b].implicitStride > xfbBuffers[b].stride) { error(infoSink, "xfb_stride is too small to hold all buffer entries:"); - infoSink.info.prefix(EPrefixError); + infoSink.info.append("ERROR: "); infoSink.info << " xfb_buffer " << (unsigned int)b << ", xfb_stride " << xfbBuffers[b].stride << ", minimum stride needed: " << xfbBuffers[b].implicitStride << "\n"; } if (xfbBuffers[b].stride == TQualifier::layoutXfbStrideEnd) @@ -446,11 +446,11 @@ void TIntermediate::finalCheck(TInfoSink& infoSink, bool keepUncalled) // multiple of 4, or a compile-time or link-time error results." if (xfbBuffers[b].containsDouble && ! IsMultipleOfPow2(xfbBuffers[b].stride, 8)) { error(infoSink, "xfb_stride must be multiple of 8 for buffer holding a double:"); - infoSink.info.prefix(EPrefixError); + infoSink.info.append("ERROR: "); infoSink.info << " xfb_buffer " << (unsigned int)b << ", xfb_stride " << xfbBuffers[b].stride << "\n"; } else if (! IsMultipleOfPow2(xfbBuffers[b].stride, 4)) { error(infoSink, "xfb_stride must be multiple of 4:"); - infoSink.info.prefix(EPrefixError); + infoSink.info.append("ERROR: "); infoSink.info << " xfb_buffer " << (unsigned int)b << ", xfb_stride " << xfbBuffers[b].stride << "\n"; } @@ -458,7 +458,7 @@ void TIntermediate::finalCheck(TInfoSink& infoSink, bool keepUncalled) // implementation-dependent constant gl_MaxTransformFeedbackInterleavedComponents." if (xfbBuffers[b].stride > (unsigned int)(4 * resources.maxTransformFeedbackInterleavedComponents)) { error(infoSink, "xfb_stride is too large:"); - infoSink.info.prefix(EPrefixError); + infoSink.info.append("ERROR: "); infoSink.info << " xfb_buffer " << (unsigned int)b << ", components (1/4 stride) needed are " << xfbBuffers[b].stride/4 << ", gl_MaxTransformFeedbackInterleavedComponents is " << resources.maxTransformFeedbackInterleavedComponents << "\n"; } } diff --git a/deps/glslang/glslang/hlsl/hlslScanContext.cpp b/deps/glslang/glslang/hlsl/hlslScanContext.cpp index 4414eb7aa8..08eb625b04 100755 --- a/deps/glslang/glslang/hlsl/hlslScanContext.cpp +++ b/deps/glslang/glslang/hlsl/hlslScanContext.cpp @@ -855,7 +855,10 @@ EHlslTokenClass HlslScanContext::tokenizeIdentifier() return keyword; default: - _parseContext.infoSink.info.message(EPrefixInternalError, "Unknown glslang keyword", loc); + _parseContext.infoSink.info.append("INTERNAL ERROR: "); + _parseContext.infoSink.info.location(loc); + _parseContext.infoSink.info.append("Unknown glslang keyword"); + _parseContext.infoSink.info.append("\n"); return EHTokNone; } }