mirror of
https://github.com/github/codeql.git
synced 2026-02-12 05:01:06 +01:00
C#: Move some populate methods and location writing methods.
This commit is contained in:
@@ -54,22 +54,6 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
}
|
||||
}
|
||||
|
||||
protected static void WriteLocationToTrap<T1>(Action<T1, Location> writeAction, T1 entity, Location l)
|
||||
{
|
||||
if (l is not EmptyLocation)
|
||||
{
|
||||
writeAction(entity, l);
|
||||
}
|
||||
}
|
||||
|
||||
protected static void WriteLocationsToTrap<T1>(Action<T1, Location> writeAction, T1 entity, IEnumerable<Location> locations)
|
||||
{
|
||||
foreach (var loc in locations)
|
||||
{
|
||||
WriteLocationToTrap(writeAction, entity, loc);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool NeedsPopulation { get; }
|
||||
|
||||
public override int GetHashCode() => Symbol is null ? 0 : Symbol.GetHashCode();
|
||||
|
||||
@@ -32,32 +32,6 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
Attribute.ExtractAttributes(Context, Symbol, this);
|
||||
}
|
||||
|
||||
protected void PopulateNullability(TextWriter trapFile, AnnotatedTypeSymbol type)
|
||||
{
|
||||
var n = NullabilityEntity.Create(Context, Nullability.Create(type));
|
||||
if (!type.HasObliviousNullability())
|
||||
{
|
||||
trapFile.type_nullability(this, n);
|
||||
}
|
||||
}
|
||||
|
||||
protected void PopulateRefKind(TextWriter trapFile, RefKind kind)
|
||||
{
|
||||
switch (kind)
|
||||
{
|
||||
case RefKind.Out:
|
||||
trapFile.type_annotation(this, Kinds.TypeAnnotation.Out);
|
||||
break;
|
||||
case RefKind.Ref:
|
||||
trapFile.type_annotation(this, Kinds.TypeAnnotation.Ref);
|
||||
break;
|
||||
case RefKind.RefReadOnly:
|
||||
case RefKind.RefReadOnlyParameter:
|
||||
trapFile.type_annotation(this, Kinds.TypeAnnotation.ReadonlyRef);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected void PopulateScopedKind(TextWriter trapFile, ScopedKind kind)
|
||||
{
|
||||
switch (kind)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Semmle.Extraction.CSharp.Entities;
|
||||
|
||||
namespace Semmle.Extraction.CSharp
|
||||
{
|
||||
@@ -24,7 +26,7 @@ namespace Semmle.Extraction.CSharp
|
||||
trapFile.WriteUnescaped('\"');
|
||||
}
|
||||
|
||||
public abstract Location? ReportingLocation { get; }
|
||||
public abstract Microsoft.CodeAnalysis.Location? ReportingLocation { get; }
|
||||
|
||||
public abstract TrapStackBehaviour TrapStackBehaviour { get; }
|
||||
|
||||
@@ -65,6 +67,48 @@ namespace Semmle.Extraction.CSharp
|
||||
}
|
||||
#endif
|
||||
|
||||
protected void PopulateRefKind(TextWriter trapFile, RefKind kind)
|
||||
{
|
||||
switch (kind)
|
||||
{
|
||||
case RefKind.Out:
|
||||
trapFile.type_annotation(this, Kinds.TypeAnnotation.Out);
|
||||
break;
|
||||
case RefKind.Ref:
|
||||
trapFile.type_annotation(this, Kinds.TypeAnnotation.Ref);
|
||||
break;
|
||||
case RefKind.RefReadOnly:
|
||||
case RefKind.RefReadOnlyParameter:
|
||||
trapFile.type_annotation(this, Kinds.TypeAnnotation.ReadonlyRef);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected void PopulateNullability(TextWriter trapFile, AnnotatedTypeSymbol type)
|
||||
{
|
||||
var n = NullabilityEntity.Create(Context, Nullability.Create(type));
|
||||
if (!type.HasObliviousNullability())
|
||||
{
|
||||
trapFile.type_nullability(this, n);
|
||||
}
|
||||
}
|
||||
|
||||
protected static void WriteLocationToTrap<T1>(Action<T1, Entities.Location> writeAction, T1 entity, Entities.Location l)
|
||||
{
|
||||
if (l is not EmptyLocation)
|
||||
{
|
||||
writeAction(entity, l);
|
||||
}
|
||||
}
|
||||
|
||||
protected static void WriteLocationsToTrap<T1>(Action<T1, Entities.Location> writeAction, T1 entity, IEnumerable<Entities.Location> locations)
|
||||
{
|
||||
foreach (var loc in locations)
|
||||
{
|
||||
WriteLocationToTrap(writeAction, entity, loc);
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString() => Label.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user