summaryrefslogtreecommitdiff
path: root/source/compiler-core/slang-diagnostic-sink.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2022-09-28 13:30:37 -0400
committerGitHub <noreply@github.com>2022-09-28 13:30:37 -0400
commitdafe651ecf21f2dce7f156179af785adca08ced0 (patch)
tree4069004abf2531c1c781dd86896a6e232840c713 /source/compiler-core/slang-diagnostic-sink.cpp
parente449446d540b6cc3d5fcd70a8f05886ef2be7547 (diff)
Improvements around diagnostic controls (#2414)
* #include an absolute path didn't work - because paths were taken to always be relative. * Test for disabling warnings. * Output diagnostic if argument parsing fails in render test. * More improvements around disabling diagnostics. * Add support for re enabling a warning. * Add warning controls to help text. * Tidy up around NameConventionUtil. * Make NameConvention an enum. * Handle leading underscores. * Update comment, and remove intial handling of _ prefix.
Diffstat (limited to 'source/compiler-core/slang-diagnostic-sink.cpp')
-rw-r--r--source/compiler-core/slang-diagnostic-sink.cpp93
1 files changed, 64 insertions, 29 deletions
diff --git a/source/compiler-core/slang-diagnostic-sink.cpp b/source/compiler-core/slang-diagnostic-sink.cpp
index 85c7792c0..5e58098b0 100644
--- a/source/compiler-core/slang-diagnostic-sink.cpp
+++ b/source/compiler-core/slang-diagnostic-sink.cpp
@@ -667,45 +667,88 @@ void DiagnosticSink::diagnoseRaw(
}
}
-/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! DiagnosticLookup !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
-
-void DiagnosticsLookup::_add(const char* name, Index index)
+void DiagnosticSink::overrideDiagnosticSeverity(int diagnosticId, Severity overrideSeverity, const DiagnosticInfo* info)
{
- UnownedStringSlice nameSlice(name);
- m_map.Add(nameSlice, index);
-
- // Add a dashed version (KababCase)
+ if (info)
{
- m_work.Clear();
+ SLANG_ASSERT(info->id == diagnosticId);
- NameConventionUtil::convert(NameConvention::Camel, nameSlice, CharCase::Lower, NameConvention::Kabab, m_work);
+ // If the override is the same as the default, we can just remove the override
+ if (info->severity == overrideSeverity)
+ {
+ m_severityOverrides.Remove(diagnosticId);
+ return;
+ }
+ }
- UnownedStringSlice dashSlice(m_arena.allocateString(m_work.getBuffer(), m_work.getLength()), m_work.getLength());
+ // Set the override
+ m_severityOverrides[diagnosticId] = overrideSeverity;
+}
- m_map.AddIfNotExists(dashSlice, index);
- }
+/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! DiagnosticLookup !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
+
+Index DiagnosticsLookup::_findDiagnosticIndexByExactName(const UnownedStringSlice& slice) const
+{
+ const Index* indexPtr = m_nameMap.TryGetValue(slice);
+ return indexPtr ? *indexPtr : -1;
+}
+
+void DiagnosticsLookup::_addName(const char* name, Index diagnosticIndex)
+{
+ UnownedStringSlice nameSlice(name);
+ m_nameMap.Add(nameSlice, diagnosticIndex);
}
+
void DiagnosticsLookup::addAlias(const char* name, const char* diagnosticName)
{
- const Index index = _findDiagnosticIndex(UnownedStringSlice(diagnosticName));
+ const Index index = _findDiagnosticIndexByExactName(UnownedStringSlice(diagnosticName));
SLANG_ASSERT(index >= 0);
if (index >= 0)
{
- _add(name, index);
+ _addName(name, index);
}
}
+const DiagnosticInfo* DiagnosticsLookup::getDiagnosticById(Int id) const
+{
+ const auto indexPtr = m_idMap.TryGetValue(id);
+ return indexPtr ? m_diagnostics[*indexPtr] : nullptr;
+}
+
+const DiagnosticInfo* DiagnosticsLookup::findDiagnosticByExactName(const UnownedStringSlice& slice) const
+{
+ const Index* indexPtr = m_nameMap.TryGetValue(slice);
+ return indexPtr ? m_diagnostics[*indexPtr] : nullptr;
+}
+
+const DiagnosticInfo* DiagnosticsLookup::findDiagnosticByName(const UnownedStringSlice& slice) const
+{
+ const auto convention = NameConventionUtil::inferConventionFromText(slice);
+ switch (convention)
+ {
+ case NameConvention::Invalid: return nullptr;
+ case NameConvention::LowerCamel: return findDiagnosticByExactName(slice);
+ default: break;
+ }
+
+ StringBuilder buf;
+ NameConventionUtil::convert(getNameStyle(convention), slice, NameConvention::LowerCamel, buf);
+
+ return findDiagnosticByExactName(buf.getUnownedSlice());
+}
+
Index DiagnosticsLookup::add(const DiagnosticInfo* info)
{
// Check it's not already added
SLANG_ASSERT(m_diagnostics.indexOf(info) < 0);
- const Index index = m_diagnostics.getCount();
-
- _add(info->name, index);
-
+ const Index diagnosticIndex = m_diagnostics.getCount();
m_diagnostics.add(info);
- return index;
+
+ _addName(info->name, diagnosticIndex);
+ m_idMap.AddIfNotExists(info->id, diagnosticIndex);
+
+ return diagnosticIndex;
}
void DiagnosticsLookup::add(const DiagnosticInfo*const* infos, Index infosCount)
@@ -724,21 +767,13 @@ DiagnosticsLookup::DiagnosticsLookup():
DiagnosticsLookup::DiagnosticsLookup(const DiagnosticInfo*const* diagnostics, Index diagnosticsCount) :
m_arena(kArenaInitialSize)
{
- m_diagnostics.addRange(diagnostics, diagnosticsCount);
-
// TODO: We should eventually have a more formal system for associating individual
// diagnostics, or groups of diagnostics, with user-exposed names for use when
// enabling/disabling warnings (or turning warnings into errors, etc.).
//
- // For now we build a map from diagnostic name to it's entry. Two entries are typically
- // added - the 'original name' as associated with the diagnostic in lowerCamel, and
- // a dashified version.
+ // For now we build a map from diagnostic name to it's entry.
- for (Index i = 0; i < diagnosticsCount; ++i)
- {
- const DiagnosticInfo* diagnostic = diagnostics[i];
- _add(diagnostic->name, i);
- }
+ add(diagnostics, diagnosticsCount);
}
} // namespace Slang