@@ -667,45 +667,88 @@ void DiagnosticSink::diagnoseRaw(
667
667
}
668
668
}
669
669
670
- /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! DiagnosticLookup !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
671
-
672
- void DiagnosticsLookup::_add (const char * name, Index index)
670
+ void DiagnosticSink::overrideDiagnosticSeverity (int diagnosticId, Severity overrideSeverity, const DiagnosticInfo* info)
673
671
{
674
- UnownedStringSlice nameSlice (name);
675
- m_map.Add (nameSlice, index );
676
-
677
- // Add a dashed version (KababCase)
672
+ if (info)
678
673
{
679
- m_work. Clear ( );
674
+ SLANG_ASSERT (info-> id == diagnosticId );
680
675
681
- NameConventionUtil::convert (NameConvention::Camel, nameSlice, CharCase::Lower, NameConvention::Kabab, m_work);
676
+ // If the override is the same as the default, we can just remove the override
677
+ if (info->severity == overrideSeverity)
678
+ {
679
+ m_severityOverrides.Remove (diagnosticId);
680
+ return ;
681
+ }
682
+ }
682
683
683
- UnownedStringSlice dashSlice (m_arena.allocateString (m_work.getBuffer (), m_work.getLength ()), m_work.getLength ());
684
+ // Set the override
685
+ m_severityOverrides[diagnosticId] = overrideSeverity;
686
+ }
684
687
685
- m_map.AddIfNotExists (dashSlice, index );
686
- }
688
+ /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! DiagnosticLookup !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
689
+
690
+ Index DiagnosticsLookup::_findDiagnosticIndexByExactName (const UnownedStringSlice& slice) const
691
+ {
692
+ const Index* indexPtr = m_nameMap.TryGetValue (slice);
693
+ return indexPtr ? *indexPtr : -1 ;
694
+ }
695
+
696
+ void DiagnosticsLookup::_addName (const char * name, Index diagnosticIndex)
697
+ {
698
+ UnownedStringSlice nameSlice (name);
699
+ m_nameMap.Add (nameSlice, diagnosticIndex);
687
700
}
701
+
688
702
void DiagnosticsLookup::addAlias (const char * name, const char * diagnosticName)
689
703
{
690
- const Index index = _findDiagnosticIndex (UnownedStringSlice (diagnosticName));
704
+ const Index index = _findDiagnosticIndexByExactName (UnownedStringSlice (diagnosticName));
691
705
SLANG_ASSERT (index >= 0 );
692
706
if (index >= 0 )
693
707
{
694
- _add (name, index );
708
+ _addName (name, index );
695
709
}
696
710
}
697
711
712
+ const DiagnosticInfo* DiagnosticsLookup::getDiagnosticById (Int id) const
713
+ {
714
+ const auto indexPtr = m_idMap.TryGetValue (id);
715
+ return indexPtr ? m_diagnostics[*indexPtr] : nullptr ;
716
+ }
717
+
718
+ const DiagnosticInfo* DiagnosticsLookup::findDiagnosticByExactName (const UnownedStringSlice& slice) const
719
+ {
720
+ const Index* indexPtr = m_nameMap.TryGetValue (slice);
721
+ return indexPtr ? m_diagnostics[*indexPtr] : nullptr ;
722
+ }
723
+
724
+ const DiagnosticInfo* DiagnosticsLookup::findDiagnosticByName (const UnownedStringSlice& slice) const
725
+ {
726
+ const auto convention = NameConventionUtil::inferConventionFromText (slice);
727
+ switch (convention)
728
+ {
729
+ case NameConvention::Invalid: return nullptr ;
730
+ case NameConvention::LowerCamel: return findDiagnosticByExactName (slice);
731
+ default : break ;
732
+ }
733
+
734
+ StringBuilder buf;
735
+ NameConventionUtil::convert (getNameStyle (convention), slice, NameConvention::LowerCamel, buf);
736
+
737
+ return findDiagnosticByExactName (buf.getUnownedSlice ());
738
+ }
739
+
698
740
Index DiagnosticsLookup::add (const DiagnosticInfo* info)
699
741
{
700
742
// Check it's not already added
701
743
SLANG_ASSERT (m_diagnostics.indexOf (info) < 0 );
702
744
703
- const Index index = m_diagnostics.getCount ();
704
-
705
- _add (info->name , index );
706
-
745
+ const Index diagnosticIndex = m_diagnostics.getCount ();
707
746
m_diagnostics.add (info);
708
- return index ;
747
+
748
+ _addName (info->name , diagnosticIndex);
749
+ m_idMap.AddIfNotExists (info->id , diagnosticIndex);
750
+
751
+ return diagnosticIndex;
709
752
}
710
753
711
754
void DiagnosticsLookup::add (const DiagnosticInfo*const * infos, Index infosCount)
@@ -724,21 +767,13 @@ DiagnosticsLookup::DiagnosticsLookup():
724
767
DiagnosticsLookup::DiagnosticsLookup (const DiagnosticInfo*const * diagnostics, Index diagnosticsCount) :
725
768
m_arena (kArenaInitialSize )
726
769
{
727
- m_diagnostics.addRange (diagnostics, diagnosticsCount);
728
-
729
770
// TODO: We should eventually have a more formal system for associating individual
730
771
// diagnostics, or groups of diagnostics, with user-exposed names for use when
731
772
// enabling/disabling warnings (or turning warnings into errors, etc.).
732
773
//
733
- // For now we build a map from diagnostic name to it's entry. Two entries are typically
734
- // added - the 'original name' as associated with the diagnostic in lowerCamel, and
735
- // a dashified version.
774
+ // For now we build a map from diagnostic name to it's entry.
736
775
737
- for (Index i = 0 ; i < diagnosticsCount; ++i)
738
- {
739
- const DiagnosticInfo* diagnostic = diagnostics[i];
740
- _add (diagnostic->name , i);
741
- }
776
+ add (diagnostics, diagnosticsCount);
742
777
}
743
778
744
779
} // namespace Slang
0 commit comments