Skip to content

Commit 61e9527

Browse files
committed
Convert CIL.GenericContext to interface
1 parent 3e2a6fc commit 61e9527

19 files changed

Lines changed: 72 additions & 61 deletions

csharp/extractor/Semmle.Extraction.CIL/Context.Factories.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ public PrimitiveType Create(PrimitiveTypeCode code)
9595
/// <param name="h">The handle of the entity.</param>
9696
/// <param name="genericContext">The generic context.</param>
9797
/// <returns></returns>
98-
public IExtractedEntity CreateGeneric(GenericContext genericContext, Handle h) => genericHandleFactory[genericContext, h];
98+
public IExtractedEntity CreateGeneric(IGenericContext genericContext, Handle h) => genericHandleFactory[genericContext, h];
9999

100-
private readonly GenericContext defaultGenericContext;
100+
private readonly IGenericContext defaultGenericContext;
101101

102-
private IExtractedEntity CreateGenericHandle(GenericContext gc, Handle handle)
102+
private IExtractedEntity CreateGenericHandle(IGenericContext gc, Handle handle)
103103
{
104104
IExtractedEntity entity;
105105
switch (handle.Kind)
@@ -136,7 +136,7 @@ private IExtractedEntity CreateGenericHandle(GenericContext gc, Handle handle)
136136
return entity;
137137
}
138138

139-
private IExtractedEntity Create(GenericContext gc, MemberReferenceHandle handle)
139+
private IExtractedEntity Create(IGenericContext gc, MemberReferenceHandle handle)
140140
{
141141
var mr = MdReader.GetMemberReference(handle);
142142
switch (mr.GetKind())
@@ -228,7 +228,7 @@ private Namespace CreateNamespace(NamespaceDefinitionHandle handle)
228228

229229
#endregion
230230

231-
private readonly CachedFunction<GenericContext, Handle, IExtractedEntity> genericHandleFactory;
231+
private readonly CachedFunction<IGenericContext, Handle, IExtractedEntity> genericHandleFactory;
232232

233233
/// <summary>
234234
/// Gets the short name of a member, without the preceding interface qualifier.

csharp/extractor/Semmle.Extraction.CIL/Context.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public Context(Extraction.Context cx, string assemblyPath, bool extractPdbs)
3737

3838
globalNamespace = new Lazy<Entities.Namespace>(() => Populate(new Entities.Namespace(this, "", null)));
3939
systemNamespace = new Lazy<Entities.Namespace>(() => Populate(new Entities.Namespace(this, "System")));
40-
genericHandleFactory = new CachedFunction<GenericContext, Handle, IExtractedEntity>(CreateGenericHandle);
40+
genericHandleFactory = new CachedFunction<IGenericContext, Handle, IExtractedEntity>(CreateGenericHandle);
4141
namespaceFactory = new CachedFunction<StringHandle, Entities.Namespace>(n => CreateNamespace(MdReader.GetString(n)));
4242
namespaceDefinitionFactory = new CachedFunction<NamespaceDefinitionHandle, Entities.Namespace>(CreateNamespace);
4343
sourceFiles = new CachedFunction<PDB.ISourceFile, Entities.PdbSourceFile>(path => new Entities.PdbSourceFile(this, path));

csharp/extractor/Semmle.Extraction.CIL/EmptyContext.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ namespace Semmle.Extraction.CIL
55
/// <summary>
66
/// A generic context which does not contain any type parameters.
77
/// </summary>
8-
public class EmptyContext : GenericContext
8+
public class EmptyContext : IGenericContext
99
{
10-
public EmptyContext(Context cx) : base(cx)
10+
public EmptyContext(Context cx)
1111
{
12+
Cx = cx;
1213
}
1314

14-
public override IEnumerable<Entities.Type> TypeParameters { get { yield break; } }
15+
public Context Cx { get; }
16+
17+
public IEnumerable<Entities.Type> TypeParameters { get { yield break; } }
18+
19+
public IEnumerable<Entities.Type> MethodParameters { get { yield break; } }
1520

16-
public override IEnumerable<Entities.Type> MethodParameters { get { yield break; } }
1721
}
1822
}

csharp/extractor/Semmle.Extraction.CIL/Entities/DefinitionMethod.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal sealed class DefinitionMethod : Method
2323

2424
public override IList<LocalVariable>? LocalVariables => locals;
2525

26-
public DefinitionMethod(GenericContext gc, MethodDefinitionHandle handle) : base(gc)
26+
public DefinitionMethod(IGenericContext gc, MethodDefinitionHandle handle) : base(gc)
2727
{
2828
md = Cx.MdReader.GetMethodDefinition(handle);
2929
this.gc = gc;

csharp/extractor/Semmle.Extraction.CIL/Entities/ExceptionRegion.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ namespace Semmle.Extraction.CIL.Entities
77
/// </summary>
88
internal class ExceptionRegion : UnlabelledEntity
99
{
10-
private readonly GenericContext gc;
10+
private readonly IGenericContext gc;
1111
private readonly MethodImplementation method;
1212
private readonly int index;
1313
private readonly System.Reflection.Metadata.ExceptionRegion r;
1414
private readonly Dictionary<int, Instruction> jump_table;
1515

16-
public ExceptionRegion(GenericContext gc, MethodImplementation method, int index, System.Reflection.Metadata.ExceptionRegion r, Dictionary<int, Instruction> jump_table) : base(gc.Cx)
16+
public ExceptionRegion(IGenericContext gc, MethodImplementation method, int index, System.Reflection.Metadata.ExceptionRegion r, Dictionary<int, Instruction> jump_table) : base(gc.Cx)
1717
{
1818
this.gc = gc;
1919
this.method = method;

csharp/extractor/Semmle.Extraction.CIL/Entities/Field.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ namespace Semmle.Extraction.CIL.Entities
88
/// <summary>
99
/// An entity representing a field.
1010
/// </summary>
11-
internal abstract class Field : GenericContext, IMember, ICustomModifierReceiver
11+
internal abstract class Field : IGenericContext, IMember, ICustomModifierReceiver
1212
{
13-
protected Field(Context cx) : base(cx)
13+
protected Field(Context cx)
1414
{
15+
Cx = cx;
1516
}
1617

1718
public Label Label { get; set; }
@@ -61,5 +62,11 @@ public void Extract(Context cx2)
6162
}
6263

6364
TrapStackBehaviour IEntity.TrapStackBehaviour => TrapStackBehaviour.NoLabel;
65+
66+
public abstract IEnumerable<Type> TypeParameters { get; }
67+
68+
public abstract IEnumerable<Type> MethodParameters { get; }
69+
70+
public Context Cx { get; }
6471
}
6572
}

csharp/extractor/Semmle.Extraction.CIL/Entities/ITypeSignature.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ namespace Semmle.Extraction.CIL.Entities
44
{
55
internal interface ITypeSignature
66
{
7-
void WriteId(TextWriter trapFile, GenericContext gc);
7+
void WriteId(TextWriter trapFile, IGenericContext gc);
88
}
99
}

csharp/extractor/Semmle.Extraction.CIL/Entities/MemberReferenceField.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ internal sealed class MemberReferenceField : Field
88
{
99
private readonly MemberReferenceHandle handle;
1010
private readonly MemberReference mr;
11-
private readonly GenericContext gc;
11+
private readonly IGenericContext gc;
1212
private readonly Type declType;
1313

14-
public MemberReferenceField(GenericContext gc, MemberReferenceHandle handle) : base(gc.Cx)
14+
public MemberReferenceField(IGenericContext gc, MemberReferenceHandle handle) : base(gc.Cx)
1515
{
1616
this.handle = handle;
1717
this.gc = gc;

csharp/extractor/Semmle.Extraction.CIL/Entities/MemberReferenceMethod.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ internal sealed class MemberReferenceMethod : Method
1212
private readonly MemberReferenceHandle handle;
1313
private readonly MemberReference mr;
1414
private readonly Type declaringType;
15-
private readonly GenericContext parent;
15+
private readonly IGenericContext parent;
1616
private readonly Method? sourceDeclaration;
1717

18-
public MemberReferenceMethod(GenericContext gc, MemberReferenceHandle handle) : base(gc)
18+
public MemberReferenceMethod(IGenericContext gc, MemberReferenceHandle handle) : base(gc)
1919
{
2020
this.handle = handle;
2121
this.gc = gc;
2222
mr = Cx.MdReader.GetMemberReference(handle);
2323

2424
signature = mr.DecodeMethodSignature(new SignatureDecoder(), gc);
2525

26-
parent = (GenericContext)Cx.CreateGeneric(gc, mr.Parent);
26+
parent = (IGenericContext)Cx.CreateGeneric(gc, mr.Parent);
2727

2828
var declType = parent is Method parentMethod
2929
? parentMethod.DeclaringType

csharp/extractor/Semmle.Extraction.CIL/Entities/Method.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ namespace Semmle.Extraction.CIL.Entities
1212
internal abstract class Method : TypeContainer, IMember, ICustomModifierReceiver, IParameterizable
1313
{
1414
protected MethodTypeParameter[]? genericParams;
15-
protected GenericContext gc;
15+
protected IGenericContext gc;
1616
protected MethodSignature<ITypeSignature> signature;
1717

18-
protected Method(GenericContext gc) : base(gc.Cx)
18+
protected Method(IGenericContext gc) : base(gc.Cx)
1919
{
2020
this.gc = gc;
2121
}

0 commit comments

Comments
 (0)