summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-diagnostics.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/slang-diagnostics.cpp')
-rw-r--r--source/slang/slang-diagnostics.cpp64
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