mirror of
https://github.com/github/codeql.git
synced 2026-04-27 09:45:15 +02:00
C#: Address review comments.
This commit is contained in:
@@ -43,11 +43,11 @@ namespace Semmle.Extraction.CIL.Entities
|
||||
public virtual IList<LocalVariable> LocalVariables => throw new NotImplementedException();
|
||||
public IList<Parameter> Parameters { get; private set; }
|
||||
|
||||
public override void WriteId(TextWriter trapFile) => MakeMethodId(trapFile, DeclaringType, NameLabel);
|
||||
public override void WriteId(TextWriter trapFile) => WriteMethodId(trapFile, DeclaringType, NameLabel);
|
||||
|
||||
public abstract string NameLabel { get; }
|
||||
|
||||
internal protected void MakeMethodId(TextWriter trapFile, Type parent, string methodName)
|
||||
internal protected void WriteMethodId(TextWriter trapFile, Type parent, string methodName)
|
||||
{
|
||||
signature.ReturnType.WriteId(trapFile, this);
|
||||
trapFile.Write(' ');
|
||||
|
||||
@@ -131,12 +131,12 @@ namespace Semmle.Extraction.CIL.Entities
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the assembly identifier of this type.
|
||||
/// Writes the assembly identifier of this type.
|
||||
/// </summary>
|
||||
public abstract void WriteAssemblyPrefix(TextWriter trapFile);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ID part to be used in a method.
|
||||
/// Writes the ID part to be used in a method ID.
|
||||
/// </summary>
|
||||
/// <param name="inContext">
|
||||
/// Whether we should output the context prefix of type parameters.
|
||||
|
||||
@@ -34,8 +34,8 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
PopulateMethod(trapFile);
|
||||
ExtractModifiers(trapFile);
|
||||
ContainingType.ExtractGenerics();
|
||||
PopulateModifiers(trapFile);
|
||||
ContainingType.PopulateGenerics();
|
||||
|
||||
var prop = PropertySymbol;
|
||||
if (prop == null)
|
||||
|
||||
@@ -17,8 +17,8 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
PopulateMethod(trapFile);
|
||||
ExtractModifiers(trapFile);
|
||||
ContainingType.ExtractGenerics();
|
||||
PopulateModifiers(trapFile);
|
||||
ContainingType.PopulateGenerics();
|
||||
|
||||
trapFile.constructors(this, symbol.ContainingType.Name, ContainingType, (Constructor)OriginalDefinition);
|
||||
trapFile.constructor_location(this, Location);
|
||||
|
||||
@@ -11,8 +11,8 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
PopulateMethod(trapFile);
|
||||
ExtractModifiers(trapFile);
|
||||
ContainingType.ExtractGenerics();
|
||||
PopulateModifiers(trapFile);
|
||||
ContainingType.PopulateGenerics();
|
||||
|
||||
trapFile.destructors(this, string.Format("~{0}", symbol.ContainingType.Name), ContainingType, OriginalDefinition(Context, this, symbol));
|
||||
trapFile.destructor_location(this, Location);
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
ExtractNullability(trapFile, symbol.NullableAnnotation);
|
||||
PopulateNullability(trapFile, symbol.NullableAnnotation);
|
||||
|
||||
var type = Type.Create(Context, symbol.Type);
|
||||
trapFile.events(this, symbol.GetName(), ContainingType, type.TypeRef, Create(Context, symbol.OriginalDefinition));
|
||||
@@ -35,7 +35,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
if (!(remover is null))
|
||||
Method.Create(Context, remover);
|
||||
|
||||
ExtractModifiers(trapFile);
|
||||
PopulateModifiers(trapFile);
|
||||
BindComments();
|
||||
|
||||
var declSyntaxReferences = IsSourceDeclaration
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
PopulateMethod(trapFile);
|
||||
ContainingType.ExtractGenerics();
|
||||
ContainingType.PopulateGenerics();
|
||||
|
||||
var @event = EventSymbol;
|
||||
if (@event == null)
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
if (Info.ExprValue is string value)
|
||||
trapFile.expr_value(this, value);
|
||||
|
||||
Type.Type.ExtractGenerics();
|
||||
Type.Type.PopulateGenerics();
|
||||
}
|
||||
|
||||
public override Microsoft.CodeAnalysis.Location ReportingLocation => Location.symbol;
|
||||
|
||||
@@ -27,15 +27,15 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
ExtractMetadataHandle(trapFile);
|
||||
ExtractAttributes();
|
||||
ContainingType.ExtractGenerics();
|
||||
ExtractNullability(trapFile, symbol.NullableAnnotation);
|
||||
PopulateMetadataHandle(trapFile);
|
||||
PopulateAttributes();
|
||||
ContainingType.PopulateGenerics();
|
||||
PopulateNullability(trapFile, symbol.NullableAnnotation);
|
||||
|
||||
Field unboundFieldKey = Field.Create(Context, symbol.OriginalDefinition);
|
||||
trapFile.fields(this, (symbol.IsConst ? 2 : 1), symbol.Name, ContainingType, Type.Type.TypeRef, unboundFieldKey);
|
||||
|
||||
ExtractModifiers(trapFile);
|
||||
PopulateModifiers(trapFile);
|
||||
|
||||
if (symbol.IsVolatile)
|
||||
Modifier.HasModifier(Context, trapFile, this, "volatile");
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
ExtractNullability(trapFile, symbol.NullableAnnotation);
|
||||
PopulateNullability(trapFile, symbol.NullableAnnotation);
|
||||
|
||||
var type = Type.Create(Context, symbol.Type);
|
||||
trapFile.indexers(this, symbol.GetName(useMetadataName: true), ContainingType, type.TypeRef, OriginalDefinition);
|
||||
@@ -50,7 +50,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
}
|
||||
}
|
||||
|
||||
ExtractModifiers(trapFile);
|
||||
PopulateModifiers(trapFile);
|
||||
BindComments();
|
||||
|
||||
var declSyntaxReferences = IsSourceDeclaration
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
{
|
||||
if (symbol is ILocalSymbol local)
|
||||
{
|
||||
ExtractNullability(trapFile, local.NullableAnnotation);
|
||||
PopulateNullability(trapFile, local.NullableAnnotation);
|
||||
if (local.IsRef)
|
||||
trapFile.type_annotation(this, Kinds.TypeAnnotation.Ref);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
public Method(Context cx, IMethodSymbol init)
|
||||
: base(cx, init) { }
|
||||
|
||||
protected void ExtractParameters(TextWriter trapFile)
|
||||
protected void PopulateParameters(TextWriter trapFile)
|
||||
{
|
||||
var originalMethod = OriginalDefinition;
|
||||
IEnumerable<IParameterSymbol> parameters = symbol.Parameters;
|
||||
@@ -62,7 +62,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
// so there's nothing to extract.
|
||||
}
|
||||
|
||||
void ExtractMethodBody(TextWriter trapFile)
|
||||
void PopulateMethodBody(TextWriter trapFile)
|
||||
{
|
||||
if (!IsSourceDeclaration)
|
||||
return;
|
||||
@@ -330,7 +330,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
|
||||
bool IStatementParentEntity.IsTopLevelParent => true;
|
||||
|
||||
protected void ExtractGenerics(TextWriter trapFile)
|
||||
protected void PopulateGenerics(TextWriter trapFile)
|
||||
{
|
||||
var isFullyConstructed = IsBoundGeneric;
|
||||
|
||||
@@ -375,12 +375,12 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
{
|
||||
// Common population code for all callables
|
||||
BindComments();
|
||||
ExtractAttributes();
|
||||
ExtractParameters(trapFile);
|
||||
ExtractMethodBody(trapFile);
|
||||
ExtractGenerics(trapFile);
|
||||
ExtractMetadataHandle(trapFile);
|
||||
ExtractNullability(trapFile, symbol.ReturnNullableAnnotation);
|
||||
PopulateAttributes();
|
||||
PopulateParameters(trapFile);
|
||||
PopulateMethodBody(trapFile);
|
||||
PopulateGenerics(trapFile);
|
||||
PopulateMetadataHandle(trapFile);
|
||||
PopulateNullability(trapFile, symbol.ReturnNullableAnnotation);
|
||||
}
|
||||
|
||||
public override TrapStackBehaviour TrapStackBehaviour => TrapStackBehaviour.PushesLabel;
|
||||
|
||||
@@ -27,8 +27,8 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
PopulateMethod(trapFile);
|
||||
ExtractModifiers(trapFile);
|
||||
ContainingType.ExtractGenerics();
|
||||
PopulateModifiers(trapFile);
|
||||
ContainingType.PopulateGenerics();
|
||||
|
||||
var returnType = Type.Create(Context, symbol.ReturnType);
|
||||
trapFile.methods(this, Name, ContainingType, returnType.TypeRef, OriginalDefinition);
|
||||
@@ -43,7 +43,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
foreach (var l in Locations)
|
||||
trapFile.method_location(this, l);
|
||||
|
||||
ExtractGenerics(trapFile);
|
||||
PopulateGenerics(trapFile);
|
||||
Overrides(trapFile);
|
||||
ExtractRefReturn(trapFile);
|
||||
ExtractCompilerGenerated(trapFile);
|
||||
|
||||
@@ -102,9 +102,9 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
ExtractAttributes();
|
||||
ExtractNullability(trapFile, symbol.NullableAnnotation);
|
||||
ExtractRefKind(trapFile, symbol.RefKind);
|
||||
PopulateAttributes();
|
||||
PopulateNullability(trapFile, symbol.NullableAnnotation);
|
||||
PopulateRefKind(trapFile, symbol.RefKind);
|
||||
|
||||
if (symbol.Name != Original.symbol.Name)
|
||||
Context.ModelError(symbol, "Inconsistent parameter declaration");
|
||||
|
||||
@@ -24,12 +24,12 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
ExtractMetadataHandle(trapFile);
|
||||
ExtractAttributes();
|
||||
ExtractModifiers(trapFile);
|
||||
PopulateMetadataHandle(trapFile);
|
||||
PopulateAttributes();
|
||||
PopulateModifiers(trapFile);
|
||||
BindComments();
|
||||
ExtractNullability(trapFile, symbol.NullableAnnotation);
|
||||
ExtractRefKind(trapFile, symbol.RefKind);
|
||||
PopulateNullability(trapFile, symbol.NullableAnnotation);
|
||||
PopulateRefKind(trapFile, symbol.RefKind);
|
||||
|
||||
var type = Type.Create(Context, symbol.Type);
|
||||
trapFile.properties(this, symbol.GetName(), ContainingType, type.TypeRef, Create(Context, symbol.OriginalDefinition));
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
cx.BindComments(this, location.symbol);
|
||||
}
|
||||
|
||||
protected override void Populate(TextWriter trapFile)
|
||||
protected sealed override void Populate(TextWriter trapFile)
|
||||
{
|
||||
trapFile.statements(this, Kind);
|
||||
if (Parent.IsTopLevelParent)
|
||||
|
||||
@@ -16,26 +16,26 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
|
||||
public virtual Type ContainingType => symbol.ContainingType != null ? Type.Create(Context, symbol.ContainingType) : null;
|
||||
|
||||
public void ExtractModifiers(TextWriter trapFile)
|
||||
public void PopulateModifiers(TextWriter trapFile)
|
||||
{
|
||||
Modifier.ExtractModifiers(Context, trapFile, this, symbol);
|
||||
}
|
||||
|
||||
protected void ExtractAttributes()
|
||||
protected void PopulateAttributes()
|
||||
{
|
||||
// Only extract attributes for source declarations
|
||||
if (ReferenceEquals(symbol, symbol.OriginalDefinition))
|
||||
Attribute.ExtractAttributes(Context, symbol, this);
|
||||
}
|
||||
|
||||
protected void ExtractNullability(TextWriter trapFile, NullableAnnotation annotation)
|
||||
protected void PopulateNullability(TextWriter trapFile, NullableAnnotation annotation)
|
||||
{
|
||||
var ta = annotation.GetTypeAnnotation();
|
||||
if (ta != Kinds.TypeAnnotation.None)
|
||||
trapFile.type_annotation(this, ta);
|
||||
}
|
||||
|
||||
protected void ExtractRefKind(TextWriter trapFile, RefKind kind)
|
||||
protected void PopulateRefKind(TextWriter trapFile, RefKind kind)
|
||||
{
|
||||
switch (kind)
|
||||
{
|
||||
@@ -125,7 +125,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
|
||||
public Extraction.Entities.Location Location => Context.Create(ReportingLocation);
|
||||
|
||||
protected void ExtractMetadataHandle(TextWriter trapFile)
|
||||
protected void PopulateMetadataHandle(TextWriter trapFile)
|
||||
{
|
||||
var handle = MetadataHandle;
|
||||
|
||||
|
||||
@@ -26,8 +26,8 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
trapFile.array_element_type(this, Dimension, Rank, element.Type.TypeRef);
|
||||
ExtractType(trapFile);
|
||||
ExtractNullability(trapFile, symbol.ElementNullableAnnotation);
|
||||
PopulateType(trapFile);
|
||||
PopulateNullability(trapFile, symbol.ElementNullableAnnotation);
|
||||
}
|
||||
|
||||
public override void WriteId(TextWriter trapFile)
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
}
|
||||
}
|
||||
|
||||
ExtractType(trapFile);
|
||||
PopulateType(trapFile);
|
||||
|
||||
if (symbol.EnumUnderlyingType != null)
|
||||
{
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
trapFile.pointer_referent_type(this, PointedAtType.TypeRef);
|
||||
ExtractType(trapFile);
|
||||
PopulateType(trapFile);
|
||||
}
|
||||
|
||||
public Type PointedAtType { get; private set; }
|
||||
|
||||
@@ -38,8 +38,8 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
ExtractType(trapFile);
|
||||
ExtractGenerics();
|
||||
PopulateType(trapFile);
|
||||
PopulateGenerics();
|
||||
|
||||
var underlyingType = NamedType.Create(Context, symbol.TupleUnderlyingType);
|
||||
trapFile.tuple_underlying_type(this, underlyingType);
|
||||
|
||||
@@ -78,16 +78,18 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
}
|
||||
}
|
||||
|
||||
protected void ExtractType(TextWriter trapFile)
|
||||
protected void PopulateType(TextWriter trapFile)
|
||||
{
|
||||
ExtractMetadataHandle(trapFile);
|
||||
ExtractAttributes();
|
||||
PopulateMetadataHandle(trapFile);
|
||||
PopulateAttributes();
|
||||
|
||||
using (var tb = new StringWriter())
|
||||
{
|
||||
symbol.BuildDisplayName(Context, tb);
|
||||
trapFile.types(this, GetClassType(Context, symbol), tb.ToString());
|
||||
}
|
||||
trapFile.Write("types(");
|
||||
trapFile.WriteColumn(this);
|
||||
trapFile.Write(',');
|
||||
trapFile.WriteColumn((int)GetClassType(Context, symbol));
|
||||
trapFile.Write(",\"");
|
||||
symbol.BuildDisplayName(Context, trapFile);
|
||||
trapFile.WriteLine("\")");
|
||||
|
||||
// Visit base types
|
||||
var baseTypes = new List<Type>();
|
||||
@@ -214,7 +216,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
/// <summary>
|
||||
/// Extracts all members and nested types of this type.
|
||||
/// </summary>
|
||||
public void ExtractGenerics()
|
||||
public void PopulateGenerics()
|
||||
{
|
||||
if (symbol == null || !NeedsPopulation || !Context.ExtractGenerics(this))
|
||||
return;
|
||||
@@ -245,11 +247,11 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
}
|
||||
|
||||
if (symbol.BaseType != null)
|
||||
Create(Context, symbol.BaseType).ExtractGenerics();
|
||||
Create(Context, symbol.BaseType).PopulateGenerics();
|
||||
|
||||
foreach (var i in symbol.Interfaces)
|
||||
{
|
||||
Create(Context, i).ExtractGenerics();
|
||||
Create(Context, i).PopulateGenerics();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
PopulateMethod(trapFile);
|
||||
ExtractModifiers(trapFile);
|
||||
PopulateModifiers(trapFile);
|
||||
|
||||
var returnType = Type.Create(Context, symbol.ReturnType);
|
||||
trapFile.operators(this,
|
||||
@@ -35,7 +35,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
TypeMention.Create(Context, declaration.Type, this, returnType);
|
||||
}
|
||||
|
||||
ContainingType.ExtractGenerics();
|
||||
ContainingType.PopulateGenerics();
|
||||
}
|
||||
|
||||
public override bool NeedsPopulation => Context.Defines(symbol) || IsImplicitOperator(out _);
|
||||
|
||||
Reference in New Issue
Block a user