Skip to content

Commit 40f56ff

Browse files
committed
C#: Code tidy. Rename variables, delete dead code, format whitespace, improve comments.
1 parent b3d5e40 commit 40f56ff

File tree

29 files changed

+359
-306
lines changed

29 files changed

+359
-306
lines changed

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

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

3434
globalNamespace = new Lazy<Entities.Namespace>(() => Populate(new Entities.Namespace(this, "", null)));
3535
systemNamespace = new Lazy<Entities.Namespace>(() => Populate(new Entities.Namespace(this, "System")));
36-
genericHandleFactory = new CachedFunction<GenericContext, Handle, ILabelledEntity>(CreateGenericHandle);
36+
genericHandleFactory = new CachedFunction<GenericContext, Handle, IExtractedEntity>(CreateGenericHandle);
3737
namespaceFactory = new CachedFunction<StringHandle, Entities.Namespace>(n => CreateNamespace(mdReader.GetString(n)));
3838
namespaceDefinitionFactory = new CachedFunction<NamespaceDefinitionHandle, Entities.Namespace>(CreateNamespace);
3939
sourceFiles = new CachedFunction<PDB.ISourceFile, Entities.PdbSourceFile>(path => new Entities.PdbSourceFile(this, path));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Semmle.Extraction.CIL.Entities
77
/// <summary>
88
/// An event.
99
/// </summary>
10-
interface IEvent : ILabelledEntity
10+
interface IEvent : IExtractedEntity
1111
{
1212
}
1313

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Semmle.Extraction.CIL.Entities
1313
/// An entity represting a member.
1414
/// Used to type tuples correctly.
1515
/// </summary>
16-
interface IMember : ILabelledEntity
16+
interface IMember : IExtractedEntity
1717
{
1818
}
1919

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public Folder(Context cx, string path) : base(cx)
1616
this.path = path;
1717
}
1818

19-
2019
public override void WriteId(TextWriter trapFile)
2120
{
2221
trapFile.Write(Semmle.Extraction.Entities.File.PathAsDatabaseId(path));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Semmle.Extraction.CIL.Entities
55
{
6-
interface ILocal : ILabelledEntity
6+
interface ILocal : IExtractedEntity
77
{
88
}
99

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ internal protected void MakeMethodId(TextWriter trapFile, Type parent, string me
6464
int index = 0;
6565
foreach (var param in signature.ParameterTypes)
6666
{
67-
trapFile.WriteSeparator(",", index++);
67+
trapFile.WriteSeparator(",", ref index);
6868
param.WriteId(trapFile, this);
6969
}
7070
trapFile.Write(')');
@@ -503,7 +503,7 @@ public override void WriteId(TextWriter trapFile)
503503
int index = 0;
504504
foreach(var param in typeParams)
505505
{
506-
trapFile.WriteSeparator(",", index++);
506+
trapFile.WriteSeparator(",", ref index);
507507
trapFile.WriteSubId(param);
508508
}
509509
trapFile.Write('>');
@@ -516,10 +516,7 @@ public override bool Equals(object obj)
516516
return obj is MethodSpecificationMethod method && handle.Equals(method.handle) && typeParams.SequenceEqual(method.typeParams);
517517
}
518518

519-
public override int GetHashCode()
520-
{
521-
return handle.GetHashCode() * 11 + typeParams.SequenceHash();
522-
}
519+
public override int GetHashCode() => handle.GetHashCode() * 11 + typeParams.SequenceHash();
523520

524521
public override Method SourceDeclaration => unboundMethod;
525522

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Semmle.Extraction.CIL.Entities
66
/// <summary>
77
/// A parameter entity.
88
/// </summary>
9-
interface IParameter : ILabelledEntity
9+
interface IParameter : IExtractedEntity
1010
{
1111
}
1212

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Semmle.Extraction.CIL.Entities
99
/// <summary>
1010
/// A property.
1111
/// </summary>
12-
interface IProperty : ILabelledEntity
12+
interface IProperty : IExtractedEntity
1313
{
1414
}
1515

@@ -42,11 +42,12 @@ public override void WriteId(TextWriter trapFile)
4242
var signature = pd.DecodeSignature(new SignatureDecoder(), gc);
4343
foreach (var param in signature.ParameterTypes)
4444
{
45-
trapFile.WriteSeparator(",", index++);
45+
trapFile.WriteSeparator(",", ref index);
4646
param.WriteId(trapFile, gc);
4747
}
4848
trapFile.Write(")");
4949
}
50+
5051
public override bool Equals(object obj)
5152
{
5253
return obj is Property property && Equals(handle, property.handle);

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public enum CilTypeKind
3939
/// <summary>
4040
/// A type container (namespace/types/method).
4141
/// </summary>
42-
interface ITypeContainer : ILabelledEntity
42+
interface ITypeContainer : IExtractedEntity
4343
{
4444
}
4545

@@ -231,10 +231,9 @@ public void PrimitiveTypeId(TextWriter trapFile)
231231
/// <summary>
232232
/// Gets the primitive type corresponding to this type, if possible.
233233
/// </summary>
234-
/// <param name="cx">Extraction context.</param>
235-
/// <param name="t">The resulting primitive type.</param>
234+
/// <param name="t">The resulting primitive type, or null.</param>
236235
/// <returns>True if this type is a primitive type.</returns>
237-
public bool TryGetPrimitiveType(Context cx, out PrimitiveType t)
236+
public bool TryGetPrimitiveType(out PrimitiveType t)
238237
{
239238
if (TryGetPrimitiveTypeCode(out var code))
240239
{
@@ -830,7 +829,7 @@ public override void WriteId(TextWriter trapFile, bool inContext)
830829
int index = 0;
831830
foreach (var t in thisTypeArguments)
832831
{
833-
trapFile.WriteSeparator(",", index++);
832+
trapFile.WriteSeparator(",", ref index);
834833
t.WriteId(trapFile);
835834
}
836835
trapFile.Write('>');
@@ -1253,7 +1252,7 @@ public void WriteId(TextWriter trapFile, GenericContext gc)
12531252
int index = 0;
12541253
foreach(var arg in typeArguments)
12551254
{
1256-
trapFile.WriteSeparator(",", index++);
1255+
trapFile.WriteSeparator(",", ref index);
12571256
arg.WriteId(trapFile, gc);
12581257
}
12591258
trapFile.Write('>');

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Semmle.Extraction.CIL
1212
/// The extraction algorithm proceeds as follows:
1313
/// - Construct entity
1414
/// - Call Extract()
15-
/// - ILabelledEntity check if already extracted
15+
/// - IExtractedEntity check if already extracted
1616
/// - Enumerate Contents to produce more extraction products
1717
/// - Extract these until there is nothing left to extract
1818
/// </remarks>
@@ -78,7 +78,7 @@ protected UnlabelledEntity(Context cx)
7878
/// An entity that needs to be populated during extraction.
7979
/// This assigns a key and optionally extracts its contents.
8080
/// </summary>
81-
public abstract class LabelledEntity : ILabelledEntity
81+
public abstract class LabelledEntity : IExtractedEntity
8282
{
8383
public abstract IEnumerable<IExtractionProduct> Contents { get; }
8484
public Label Label { get; set; }
@@ -120,13 +120,6 @@ public override string ToString()
120120
TrapStackBehaviour IEntity.TrapStackBehaviour => TrapStackBehaviour.NoLabel;
121121
}
122122

123-
/// <summary>
124-
/// An entity with a defined ID.
125-
/// </summary>
126-
public interface ILabelledEntity : IExtractedEntity
127-
{
128-
}
129-
130123
/// <summary>
131124
/// A tuple that is an extraction product.
132125
/// </summary>

0 commit comments

Comments
 (0)