Skip to content

Commit 23d994a

Browse files
authored
Merge pull request github#5197 from tamasvajk/feature/refactor-4
C#: Enable nullability in Extraction.CSharp
2 parents cf4f55d + c6b4764 commit 23d994a

File tree

118 files changed

+1322
-1177
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+1322
-1177
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Semmle.Extraction.CIL
77
{
88
public static class Analyser
99
{
10-
private static void ExtractCIL(Extractor extractor, TrapWriter trapWriter, bool extractPdbs)
10+
private static void ExtractCIL(TracingExtractor extractor, TrapWriter trapWriter, bool extractPdbs)
1111
{
1212
using var cilContext = new Context(extractor, trapWriter, extractor.OutputPath, extractPdbs);
1313
cilContext.Populate(new Assembly(cilContext));
@@ -33,7 +33,7 @@ public static void ExtractCIL(Layout layout, string assemblyPath, ILogger logger
3333
{
3434
var canonicalPathCache = CanonicalPathCache.Create(logger, 1000);
3535
var pathTransformer = new PathTransformer(canonicalPathCache);
36-
var extractor = new Extractor(false, assemblyPath, logger, pathTransformer);
36+
var extractor = new TracingExtractor(assemblyPath, logger, pathTransformer);
3737
var transformedAssemblyPath = pathTransformer.Transform(assemblyPath);
3838
var project = layout.LookupProjectOrDefault(transformedAssemblyPath);
3939
using var trapWriter = project.CreateTrapWriter(logger, transformedAssemblyPath.WithSuffix(".cil"), trapCompression, discardDuplicates: true);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ private IExtractedEntity CreateGenericHandle(IGenericContext gc, Handle handle)
114114
entity = new MethodSpecificationMethod(gc, (MethodSpecificationHandle)handle);
115115
break;
116116
case HandleKind.FieldDefinition:
117-
entity = new DefinitionField(gc.Cx, (FieldDefinitionHandle)handle);
117+
entity = new DefinitionField(gc.Context, (FieldDefinitionHandle)handle);
118118
break;
119119
case HandleKind.TypeReference:
120120
var tr = new TypeReferenceType(this, (TypeReferenceHandle)handle);
@@ -130,7 +130,7 @@ private IExtractedEntity CreateGenericHandle(IGenericContext gc, Handle handle)
130130
break;
131131
case HandleKind.StandaloneSignature:
132132
var signature = MdReader.GetStandaloneSignature((StandaloneSignatureHandle)handle);
133-
var method = signature.DecodeMethodSignature(gc.Cx.TypeSignatureDecoder, gc);
133+
var method = signature.DecodeMethodSignature(gc.Context.TypeSignatureDecoder, gc);
134134
entity = new FunctionPointerType(this, method);
135135
break;
136136
default:

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ internal class EmptyContext : IGenericContext
99
{
1010
public EmptyContext(Context cx)
1111
{
12-
Cx = cx;
12+
Context = cx;
1313
}
1414

15-
public Context Cx { get; }
15+
public Context Context { get; }
1616

1717
public IEnumerable<Entities.Type> TypeParameters { get { yield break; } }
1818

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@ public override void WriteId(TextWriter trapFile, bool inContext)
4242

4343
public override string Name => elementType.Name + "[]";
4444

45-
public override Namespace ContainingNamespace => Cx.SystemNamespace;
45+
public override Namespace ContainingNamespace => Context.SystemNamespace;
4646

4747
public override Type? ContainingType => null;
4848

4949
public override int ThisTypeParameterCount => elementType.ThisTypeParameterCount;
5050

5151
public override CilTypeKind Kind => CilTypeKind.Array;
5252

53-
public override Type Construct(IEnumerable<Type> typeArguments) => Cx.Populate(new ArrayType(Cx, elementType.Construct(typeArguments)));
53+
public override Type Construct(IEnumerable<Type> typeArguments) => Context.Populate(new ArrayType(Context, elementType.Construct(typeArguments)));
5454

55-
public override Type SourceDeclaration => Cx.Populate(new ArrayType(Cx, elementType.SourceDeclaration));
55+
public override Type SourceDeclaration => Context.Populate(new ArrayType(Context, elementType.SourceDeclaration));
5656

5757
public override IEnumerable<IExtractionProduct> Contents
5858
{

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public override void WriteId(TextWriter trapFile)
3636
{
3737
trapFile.Write(FullName);
3838
trapFile.Write("#file:///");
39-
trapFile.Write(Cx.AssemblyPath.Replace("\\", "/"));
39+
trapFile.Write(Context.AssemblyPath.Replace("\\", "/"));
4040
trapFile.Write(";assembly");
4141
}
4242

@@ -56,41 +56,41 @@ public override IEnumerable<IExtractionProduct> Contents
5656
yield return file;
5757
yield return Tuples.assemblies(this, file, FullName, assemblyName.Name ?? string.Empty, assemblyName.Version?.ToString() ?? string.Empty);
5858

59-
if (Cx.Pdb != null)
59+
if (Context.Pdb != null)
6060
{
61-
foreach (var f in Cx.Pdb.SourceFiles)
61+
foreach (var f in Context.Pdb.SourceFiles)
6262
{
63-
yield return Cx.CreateSourceFile(f);
63+
yield return Context.CreateSourceFile(f);
6464
}
6565
}
6666

67-
foreach (var handle in Cx.MdReader.TypeDefinitions)
67+
foreach (var handle in Context.MdReader.TypeDefinitions)
6868
{
6969
IExtractionProduct? product = null;
7070
try
7171
{
72-
product = Cx.Create(handle);
72+
product = Context.Create(handle);
7373
}
7474
catch (InternalError e)
7575
{
76-
Cx.ExtractionError("Error processing type definition", e.Message, GeneratedLocation.Create(Cx), e.StackTrace);
76+
Context.ExtractionError("Error processing type definition", e.Message, GeneratedLocation.Create(Context), e.StackTrace);
7777
}
7878

7979
// Limitation of C#: Cannot yield return inside a try-catch.
8080
if (product != null)
8181
yield return product;
8282
}
8383

84-
foreach (var handle in Cx.MdReader.MethodDefinitions)
84+
foreach (var handle in Context.MdReader.MethodDefinitions)
8585
{
8686
IExtractionProduct? product = null;
8787
try
8888
{
89-
product = Cx.Create(handle);
89+
product = Context.Create(handle);
9090
}
9191
catch (InternalError e)
9292
{
93-
Cx.ExtractionError("Error processing bytecode", e.Message, GeneratedLocation.Create(Cx), e.StackTrace);
93+
Context.ExtractionError("Error processing bytecode", e.Message, GeneratedLocation.Create(Context), e.StackTrace);
9494
}
9595

9696
if (product != null)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public override IEnumerable<IExtractionProduct> Contents
3232
{
3333
get
3434
{
35-
var constructor = (Method)Cx.Create(attrib.Constructor);
35+
var constructor = (Method)Context.Create(attrib.Constructor);
3636
yield return constructor;
3737

3838
yield return Tuples.cil_attribute(this, @object, constructor);
@@ -41,11 +41,11 @@ public override IEnumerable<IExtractionProduct> Contents
4141

4242
try
4343
{
44-
decoded = attrib.DecodeValue(new CustomAttributeDecoder(Cx));
44+
decoded = attrib.DecodeValue(new CustomAttributeDecoder(Context));
4545
}
4646
catch
4747
{
48-
Cx.Extractor.Logger.Log(Util.Logging.Severity.Info,
48+
Context.Extractor.Logger.Log(Util.Logging.Severity.Info,
4949
$"Attribute decoding is partial. Decoding attribute {constructor.DeclaringType.GetQualifiedName()} failed on {@object}.");
5050
yield break;
5151
}

csharp/extractor/Semmle.Extraction.CIL/Entities/Base/IGenericContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Semmle.Extraction.CIL
88
/// </summary>
99
internal interface IGenericContext
1010
{
11-
Context Cx { get; }
11+
Context Context { get; }
1212

1313
/// <summary>
1414
/// The list of generic type parameters/arguments, including type parameters/arguments of

csharp/extractor/Semmle.Extraction.CIL/Entities/Base/LabelledEntity.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ namespace Semmle.Extraction.CIL
1010
/// </summary>
1111
internal abstract class LabelledEntity : Extraction.LabelledEntity, IExtractedEntity
1212
{
13-
// todo: with .NET 5 this can override the base context, and change the return type.
14-
public Context Cx => (Context)base.Context;
13+
public override Context Context => (Context)base.Context;
1514

1615
protected LabelledEntity(Context cx) : base(cx)
1716
{

csharp/extractor/Semmle.Extraction.CIL/Entities/Base/UnlabelledEntity.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ namespace Semmle.Extraction.CIL
99
/// </summary>
1010
internal abstract class UnlabelledEntity : Extraction.UnlabelledEntity, IExtractedEntity
1111
{
12-
// todo: with .NET 5 this can override the base context, and change the return type.
13-
public Context Cx => (Context)base.Context;
12+
public override Context Context => (Context)base.Context;
1413

1514
protected UnlabelledEntity(Context cx) : base(cx)
1615
{

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ internal sealed class DefinitionField : Field
1414
public DefinitionField(Context cx, FieldDefinitionHandle handle) : base(cx)
1515
{
1616
this.handle = handle;
17-
fd = Cx.MdReader.GetFieldDefinition(handle);
17+
fd = Context.MdReader.GetFieldDefinition(handle);
1818
}
1919

2020
public override bool Equals(object? obj)
@@ -28,7 +28,7 @@ public override IEnumerable<IExtractionProduct> Contents
2828
{
2929
get
3030
{
31-
yield return Tuples.metadata_handle(this, Cx.Assembly, MetadataTokens.GetToken(handle));
31+
yield return Tuples.metadata_handle(this, Context.Assembly, MetadataTokens.GetToken(handle));
3232

3333
foreach (var c in base.Contents)
3434
yield return c;
@@ -48,16 +48,16 @@ public override IEnumerable<IExtractionProduct> Contents
4848
if (fd.Attributes.HasFlag(FieldAttributes.Assembly))
4949
yield return Tuples.cil_internal(this);
5050

51-
foreach (var c in Attribute.Populate(Cx, this, fd.GetCustomAttributes()))
51+
foreach (var c in Attribute.Populate(Context, this, fd.GetCustomAttributes()))
5252
yield return c;
5353
}
5454
}
5555

56-
public override string Name => Cx.GetString(fd.Name);
56+
public override string Name => Context.GetString(fd.Name);
5757

58-
public override Type DeclaringType => (Type)Cx.Create(fd.GetDeclaringType());
58+
public override Type DeclaringType => (Type)Context.Create(fd.GetDeclaringType());
5959

60-
public override Type Type => fd.DecodeSignature(Cx.TypeSignatureDecoder, DeclaringType);
60+
public override Type Type => fd.DecodeSignature(Context.TypeSignatureDecoder, DeclaringType);
6161

6262
public override IEnumerable<Type> TypeParameters => throw new NotImplementedException();
6363

0 commit comments

Comments
 (0)