Clean up a few misc. spots in `BizHawk.Analyzer`

will rebuild in later commit
This commit is contained in:
YoshiRulz 2025-02-22 11:16:26 +10:00
parent 507b30a1dc
commit 57921a9206
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
4 changed files with 11 additions and 8 deletions

View File

@ -3,4 +3,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<Import Project="../AnalyzersCommon.props" />
<ItemGroup>
<PackageReference Include="PolySharp" />
</ItemGroup>
</Project>

View File

@ -49,14 +49,13 @@ public sealed class FeatureNotImplementedAnalyzer : DiagnosticAnalyzer
.Any(aSyn => featureNotImplementedAttrSym.Matches(snac.SemanticModel.GetTypeInfo(aSyn, snac.CancellationToken).Type));
void CheckBlockBody(BlockSyntax bs, Location location)
{
if (bs.Statements.Count is not 1) snac.ReportDiagnostic(Diagnostic.Create(DiagShouldThrowNIE, location, ERR_MSG_DOES_NOT_THROW));
else if (bs.Statements[0] is not ThrowStatementSyntax tss) snac.ReportDiagnostic(Diagnostic.Create(DiagShouldThrowNIE, location, ERR_MSG_DOES_NOT_THROW));
else MaybeReportFor(snac.SemanticModel.GetThrownExceptionType(tss), tss.GetLocation());
if (bs.Statements is [ ThrowStatementSyntax tss ]) MaybeReportFor(snac.SemanticModel.GetThrownExceptionType(tss), tss.GetLocation());
else snac.ReportDiagnostic(Diagnostic.Create(DiagShouldThrowNIE, location, ERR_MSG_DOES_NOT_THROW));
}
void CheckExprBody(ArrowExpressionClauseSyntax aecs, Location location)
{
if (aecs.Expression is not ThrowExpressionSyntax tes) snac.ReportDiagnostic(Diagnostic.Create(DiagShouldThrowNIE, location, ERR_MSG_DOES_NOT_THROW));
else MaybeReportFor(snac.SemanticModel.GetThrownExceptionType(tes), tes.GetLocation());
if (aecs.Expression is ThrowExpressionSyntax tes) MaybeReportFor(snac.SemanticModel.GetThrownExceptionType(tes), tes.GetLocation());
else snac.ReportDiagnostic(Diagnostic.Create(DiagShouldThrowNIE, location, ERR_MSG_DOES_NOT_THROW));
}
void CheckAccessor(AccessorDeclarationSyntax ads)
{

View File

@ -150,8 +150,8 @@ public class HawkSourceAnalyzer : DiagnosticAnalyzer
case QueryExpressionSyntax:
snac.ReportDiagnostic(Diagnostic.Create(DiagNoQueryExpression, snac.Node.GetLocation()));
break;
case RecordDeclarationSyntax rds:
if (!rds.ClassOrStructKeyword.ToFullString().Contains("class")) snac.ReportDiagnostic(Diagnostic.Create(DiagRecordImplicitlyRefType, rds.GetLocation()));
case RecordDeclarationSyntax rds when rds.ClassOrStructKeyword.ToString() is not "class": // `record struct`s don't use this kind
snac.ReportDiagnostic(Diagnostic.Create(DiagRecordImplicitlyRefType, rds.GetLocation()));
break;
case SwitchExpressionArmSyntax { WhenClause: null, Pattern: DiscardPatternSyntax, Expression: ThrowExpressionSyntax tes }:
var thrownExceptionType = snac.SemanticModel.GetThrownExceptionType(tes);

View File

@ -33,7 +33,8 @@ public sealed class UseNameofOperatorAnalyzer : DiagnosticAnalyzer
snac =>
{
memberInfoDotNameSym ??= snac.Compilation.GetTypeByMetadataName("System.Reflection.MemberInfo")!.GetMembers("Name")[0];
typeDotToStringSym ??= snac.Compilation.GetTypeByMetadataName("System.Type")!.GetMembers("ToString")[0];
typeDotToStringSym ??= snac.Compilation.GetTypeByMetadataName("System.Type")!
.GetMembers(WellKnownMemberNames.ObjectToString)[0];
var toes = (TypeOfExpressionSyntax) snac.Node;
switch (toes.Parent)
{