diff options
| author | Yong He <yonghe@outlook.com> | 2024-02-20 12:24:00 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-20 12:24:00 -0800 |
| commit | 4d20fd329956ac89408b1628a8291fea01bc9a6d (patch) | |
| tree | 8e62d9c1ec05142fd25d0b31073fdb56d44691b0 /source/slang/slang-diagnostics.cpp | |
| parent | 8e9b61e3bac69dbb37a1451b62302e688a017ced (diff) | |
Refactor compiler option representations. (#3598)
* Refactor compiler option representation.
* Fix binary compatibility.
* Add a test for specifying compiler options at link time.
* Fix binary compatibility.
* Fix binary compatibility.
* Fix backward compatibility on matrix layout.
* Fix.
* Fix.
* Fix.
* Fix gfx.
* Fix gfx.
* Fix dynamic dispatch.
* Polish.
Diffstat (limited to 'source/slang/slang-diagnostics.cpp')
| -rw-r--r-- | source/slang/slang-diagnostics.cpp | 64 |
1 files changed, 63 insertions, 1 deletions
diff --git a/source/slang/slang-diagnostics.cpp b/source/slang/slang-diagnostics.cpp index 08ab829b9..df8c4c0d2 100644 --- a/source/slang/slang-diagnostics.cpp +++ b/source/slang/slang-diagnostics.cpp @@ -4,10 +4,10 @@ #include "../core/slang-memory-arena.h" #include "../core/slang-dictionary.h" #include "../core/slang-string-util.h" +#include "../core/slang-char-util.h" #include "../compiler-core/slang-name.h" #include "../compiler-core/slang-core-diagnostics.h" - namespace Slang { @@ -60,4 +60,66 @@ const DiagnosticsLookup* getDiagnosticsLookup() return _getDiagnosticLookupSingleton(); } + +SlangResult overrideDiagnostic(DiagnosticSink* sink, DiagnosticSink* outDiagnostic, const UnownedStringSlice& identifier, Severity originalSeverity, Severity overrideSeverity) +{ + auto diagnosticsLookup = getDiagnosticsLookup(); + + const DiagnosticInfo* diagnostic = nullptr; + Int diagnosticId = -1; + + // If it starts with a digit we assume it a number + if (identifier.getLength() > 0 && (CharUtil::isDigit(identifier[0]) || identifier[0] == '-')) + { + if (SLANG_FAILED(StringUtil::parseInt(identifier, diagnosticId))) + { + outDiagnostic->diagnose(SourceLoc(), Diagnostics::unknownDiagnosticName, identifier); + return SLANG_FAIL; + } + + // If we use numbers, we don't worry if we can't find a diagnostic + // and silently ignore. This was the previous behavior, and perhaps + // provides a way to safely disable warnings, without worrying about + // the version of the compiler. + diagnostic = diagnosticsLookup->getDiagnosticById(diagnosticId); + } + else + { + diagnostic = diagnosticsLookup->findDiagnosticByName(identifier); + if (!diagnostic) + { + outDiagnostic->diagnose(SourceLoc(), Diagnostics::unknownDiagnosticName, identifier); + return SLANG_FAIL; + } + diagnosticId = diagnostic->id; + } + + // If we are only allowing certain original severities check it's the right type + if (diagnostic && originalSeverity != Severity::Disable && diagnostic->severity != originalSeverity) + { + // Strictly speaking the diagnostic name is known, but it's not the right severity + // to be converted from, so it is an 'unknown name' in the context of severity... + // Or perhaps we want another diagnostic + outDiagnostic->diagnose(SourceLoc(), Diagnostics::unknownDiagnosticName, identifier); + return SLANG_FAIL; + } + + // Override the diagnostic severity in the sink + sink->overrideDiagnosticSeverity(int(diagnosticId), overrideSeverity, diagnostic); + + return SLANG_OK; +} + +SlangResult overrideDiagnostics(DiagnosticSink* sink, DiagnosticSink* outDiagnostic, const UnownedStringSlice& identifierList, Severity originalSeverity, Severity overrideSeverity) +{ + List<UnownedStringSlice> slices; + StringUtil::split(identifierList, ',', slices); + + for (const auto& slice : slices) + { + SLANG_RETURN_ON_FAIL(overrideDiagnostic(sink, outDiagnostic, slice, originalSeverity, overrideSeverity)); + } + return SLANG_OK; +} + } // namespace Slang |
