C#: Remove marker interfaces from CIL extraction

This commit is contained in:
Tamas Vajk
2020-12-01 15:17:25 +01:00
parent df28544020
commit 9ab930f812
49 changed files with 97 additions and 272 deletions

View File

@@ -7,7 +7,7 @@ namespace Semmle.Extraction.CIL.Entities
/// <summary>
/// An array type.
/// </summary>
internal sealed class ArrayType : Type, IArrayType
internal sealed class ArrayType : Type
{
private readonly Type elementType;
private readonly int rank;

View File

@@ -12,7 +12,7 @@ namespace Semmle.Extraction.CIL.Entities
/// <summary>
/// An assembly to extract.
/// </summary>
public class Assembly : LabelledEntity, IAssembly
public class Assembly : LabelledEntity, ILocation
{
private readonly File file;
private readonly AssemblyName assemblyName;

View File

@@ -7,7 +7,7 @@ namespace Semmle.Extraction.CIL.Entities
/// <summary>
/// Entity representing a CIL attribute.
/// </summary>
internal sealed class Attribute : UnlabelledEntity, IAttribute
internal sealed class Attribute : UnlabelledEntity
{
private readonly CustomAttributeHandle handle;
private readonly CustomAttribute attrib;

View File

@@ -9,11 +9,11 @@ namespace Semmle.Extraction.CIL.Entities
/// <summary>
/// A definition method - a method defined in the current assembly.
/// </summary>
internal sealed class DefinitionMethod : Method, IMember
internal sealed class DefinitionMethod : Method
{
private readonly Handle handle;
private readonly MethodDefinition md;
private readonly PDB.IMethod? methodDebugInformation;
private readonly PDB.Method? methodDebugInformation;
private readonly Type declaringType;
private readonly string name;
@@ -120,7 +120,7 @@ namespace Semmle.Extraction.CIL.Entities
}
}
var jump_table = new Dictionary<int, IInstruction>();
var jump_table = new Dictionary<int, Instruction>();
foreach (var c in Decode(body.GetILBytes(), jump_table))
yield return c;
@@ -178,7 +178,7 @@ namespace Semmle.Extraction.CIL.Entities
}
}
private IEnumerable<IExtractionProduct> Decode(byte[] ilbytes, Dictionary<int, IInstruction> jump_table)
private IEnumerable<IExtractionProduct> Decode(byte[] ilbytes, Dictionary<int, Instruction> jump_table)
{
// Sequence points are stored in order of offset.
// We use an enumerator to locate the correct sequence point for each instruction.

View File

@@ -7,7 +7,7 @@ namespace Semmle.Extraction.CIL.Entities
/// <summary>
/// An event entity.
/// </summary>
internal sealed class Event : LabelledEntity, IEvent
internal sealed class Event : LabelledEntity
{
private readonly EventDefinitionHandle handle;
private readonly Type parent;

View File

@@ -5,15 +5,15 @@ namespace Semmle.Extraction.CIL.Entities
/// <summary>
/// An exception region entity.
/// </summary>
internal class ExceptionRegion : UnlabelledEntity, IExceptionRegion
internal class ExceptionRegion : UnlabelledEntity
{
private readonly GenericContext gc;
private readonly MethodImplementation method;
private readonly int index;
private readonly System.Reflection.Metadata.ExceptionRegion r;
private readonly Dictionary<int, IInstruction> jump_table;
private readonly Dictionary<int, Instruction> jump_table;
public ExceptionRegion(GenericContext gc, MethodImplementation method, int index, System.Reflection.Metadata.ExceptionRegion r, Dictionary<int, IInstruction> jump_table) : base(gc.Cx)
public ExceptionRegion(GenericContext gc, MethodImplementation method, int index, System.Reflection.Metadata.ExceptionRegion r, Dictionary<int, Instruction> jump_table) : base(gc.Cx)
{
this.gc = gc;
this.method = method;

View File

@@ -8,7 +8,7 @@ namespace Semmle.Extraction.CIL.Entities
/// <summary>
/// An entity representing a field.
/// </summary>
internal abstract class Field : GenericContext, IField
internal abstract class Field : GenericContext, IMember
{
protected Field(Context cx) : base(cx)
{

View File

@@ -3,7 +3,7 @@ using System.IO;
namespace Semmle.Extraction.CIL.Entities
{
public class File : LabelledEntity, IFile
public class File : LabelledEntity, IFileOrFolder
{
protected string OriginalPath { get; }
protected PathTransformer.ITransformedPath TransformedPath { get; }

View File

@@ -3,7 +3,7 @@ using System.IO;
namespace Semmle.Extraction.CIL.Entities
{
public sealed class Folder : LabelledEntity, IFolder
public sealed class Folder : LabelledEntity, IFileOrFolder
{
private readonly PathTransformer.ITransformedPath transformedPath;

View File

@@ -1,9 +0,0 @@
namespace Semmle.Extraction.CIL.Entities
{
/// <summary>
/// An array type.
/// </summary>
internal interface IArrayType : IType
{
}
}

View File

@@ -1,6 +0,0 @@
namespace Semmle.Extraction.CIL.Entities
{
internal interface IAssembly : ILocation
{
}
}

View File

@@ -1,9 +0,0 @@
namespace Semmle.Extraction.CIL.Entities
{
/// <summary>
/// A CIL attribute.
/// </summary>
internal interface IAttribute : IExtractedEntity
{
}
}

View File

@@ -1,9 +0,0 @@
namespace Semmle.Extraction.CIL.Entities
{
/// <summary>
/// An event.
/// </summary>
internal interface IEvent : IExtractedEntity
{
}
}

View File

@@ -1,6 +0,0 @@
namespace Semmle.Extraction.CIL.Entities
{
internal interface IExceptionRegion : IExtractedEntity
{
}
}

View File

@@ -1,9 +0,0 @@
namespace Semmle.Extraction.CIL.Entities
{
/// <summary>
/// An entity representing a field.
/// </summary>
internal interface IField : IMember
{
}
}

View File

@@ -1,6 +0,0 @@
namespace Semmle.Extraction.CIL.Entities
{
internal interface IFile : IFileOrFolder
{
}
}

View File

@@ -1,6 +0,0 @@
namespace Semmle.Extraction.CIL.Entities
{
internal interface IFolder : IFileOrFolder
{
}
}

View File

@@ -1,17 +0,0 @@
using System.Collections.Generic;
namespace Semmle.Extraction.CIL.Entities
{
/// <summary>
/// A CIL instruction.
/// </summary>
internal interface IInstruction : IExtractedEntity
{
/// <summary>
/// Gets the extraction products for branches.
/// </summary>
/// <param name="jump_table">The map from offset to instruction.</param>
/// <returns>The extraction products.</returns>
IEnumerable<IExtractionProduct> JumpContents(Dictionary<int, IInstruction> jump_table);
}
}

View File

@@ -1,6 +0,0 @@
namespace Semmle.Extraction.CIL.Entities
{
internal interface ILocal : IExtractedEntity
{
}
}

View File

@@ -1,9 +0,0 @@
namespace Semmle.Extraction.CIL.Entities
{
/// <summary>
/// A method entity.
/// </summary>
internal interface IMethod : IMember
{
}
}

View File

@@ -1,9 +0,0 @@
namespace Semmle.Extraction.CIL.Entities
{
/// <summary>
/// A method implementation entity.
/// </summary>
internal interface IMethodImplementation : IExtractedEntity
{
}
}

View File

@@ -1,9 +0,0 @@
namespace Semmle.Extraction.CIL.Entities
{
/// <summary>
/// A namespace.
/// </summary>
internal interface INamespace : ITypeContainer
{
}
}

View File

@@ -1,9 +0,0 @@
namespace Semmle.Extraction.CIL.Entities
{
/// <summary>
/// A parameter entity.
/// </summary>
internal interface IParameter : IExtractedEntity
{
}
}

View File

@@ -1,6 +0,0 @@
namespace Semmle.Extraction.CIL.Entities
{
internal interface IPointerType : IType
{
}
}

View File

@@ -1,9 +0,0 @@
namespace Semmle.Extraction.CIL.Entities
{
/// <summary>
/// A property.
/// </summary>
internal interface IProperty : IExtractedEntity
{
}
}

View File

@@ -1,6 +0,0 @@
namespace Semmle.Extraction.CIL.Entities
{
public interface ISourceLocation : ILocation
{
}
}

View File

@@ -1,9 +0,0 @@
namespace Semmle.Extraction.CIL.Entities
{
/// <summary>
/// A type.
/// </summary>
internal interface IType : IEntity
{
}
}

View File

@@ -1,9 +0,0 @@
namespace Semmle.Extraction.CIL.Entities
{
/// <summary>
/// A type container (namespace/types/method).
/// </summary>
internal interface ITypeContainer : IExtractedEntity
{
}
}

View File

@@ -1,6 +0,0 @@
namespace Semmle.Extraction.CIL.Entities
{
internal interface ITypeParameter : IType
{
}
}

View File

@@ -8,7 +8,7 @@ namespace Semmle.Extraction.CIL.Entities
/// <summary>
/// A CIL instruction.
/// </summary>
internal class Instruction : UnlabelledEntity, IInstruction
internal class Instruction : UnlabelledEntity, IEntity
{
/// <summary>
/// The additional data following the opcode, if any.
@@ -433,10 +433,10 @@ namespace Semmle.Extraction.CIL.Entities
}
// Called to populate the jumps in each instruction.
public IEnumerable<IExtractionProduct> JumpContents(Dictionary<int, IInstruction> jump_table)
public IEnumerable<IExtractionProduct> JumpContents(Dictionary<int, Instruction> jump_table)
{
int target;
IInstruction? inst;
Instruction? inst;
switch (PayloadType)
{

View File

@@ -3,7 +3,7 @@ using System.IO;
namespace Semmle.Extraction.CIL.Entities
{
internal class LocalVariable : LabelledEntity, ILocal
internal class LocalVariable : LabelledEntity
{
private readonly MethodImplementation method;
private readonly int index;

View File

@@ -10,7 +10,7 @@ namespace Semmle.Extraction.CIL.Entities
/// <summary>
/// A method entity.
/// </summary>
internal abstract class Method : TypeContainer, IMethod
internal abstract class Method : TypeContainer, IMember
{
protected MethodTypeParameter[]? genericParams;
protected GenericContext gc;

View File

@@ -6,7 +6,7 @@ namespace Semmle.Extraction.CIL.Entities
/// A method implementation entity.
/// In the database, the same method could in principle have multiple implementations.
/// </summary>
internal class MethodImplementation : UnlabelledEntity, IMethodImplementation
internal class MethodImplementation : UnlabelledEntity
{
private readonly Method m;

View File

@@ -7,7 +7,7 @@ namespace Semmle.Extraction.CIL.Entities
/// <summary>
/// A namespace.
/// </summary>
public sealed class Namespace : TypeContainer, INamespace
public sealed class Namespace : TypeContainer
{
public Namespace? ParentNamespace { get; }
public string Name { get; }

View File

@@ -6,7 +6,7 @@ namespace Semmle.Extraction.CIL.Entities
/// <summary>
/// A parameter entity.
/// </summary>
internal sealed class Parameter : LabelledEntity, IParameter
internal sealed class Parameter : LabelledEntity
{
private readonly Method method;
private readonly int index;

View File

@@ -4,7 +4,7 @@ using System.IO;
namespace Semmle.Extraction.CIL.Entities
{
internal sealed class PointerType : Type, IPointerType
internal sealed class PointerType : Type
{
private readonly Type pointee;

View File

@@ -8,7 +8,7 @@ namespace Semmle.Extraction.CIL.Entities
/// <summary>
/// A property.
/// </summary>
internal sealed class Property : LabelledEntity, IProperty
internal sealed class Property : LabelledEntity
{
private readonly Handle handle;
private readonly Type type;

View File

@@ -4,7 +4,7 @@ using Semmle.Extraction.PDB;
namespace Semmle.Extraction.CIL.Entities
{
public sealed class PdbSourceLocation : LabelledEntity, ISourceLocation
public sealed class PdbSourceLocation : LabelledEntity, ILocation
{
private readonly Location location;
private readonly PdbSourceFile file;

View File

@@ -9,7 +9,7 @@ namespace Semmle.Extraction.CIL.Entities
/// <summary>
/// A type.
/// </summary>
public abstract class Type : TypeContainer, IMember, IType
public abstract class Type : TypeContainer, IMember
{
public override string IdSuffix => ";cil-type";

View File

@@ -8,7 +8,7 @@ namespace Semmle.Extraction.CIL.Entities
/// <summary>
/// Base class for all type containers (namespaces, types, methods).
/// </summary>
public abstract class TypeContainer : GenericContext, ITypeContainer
public abstract class TypeContainer : GenericContext, IExtractedEntity
{
protected TypeContainer(Context cx) : base(cx)
{

View File

@@ -7,7 +7,7 @@ using System.IO;
namespace Semmle.Extraction.CIL.Entities
{
internal abstract class TypeParameter : Type, ITypeParameter
internal abstract class TypeParameter : Type
{
protected readonly GenericContext gc;