C#: Compare CIL entities directly by handle rather than by label.

C#: Remove IDs from the CIL extractor and make consistent with C# extractor.
C#: Fix method collisions.
This commit is contained in:
Calum Grant
2019-08-13 18:50:25 +01:00
parent 685c494bcb
commit b500a02b1e
34 changed files with 878 additions and 642 deletions

View File

@@ -332,7 +332,7 @@ namespace Semmle.Extraction.CommentProcessing
class CommentBlock : ICommentBlock
{
private List<ICommentLine> lines = new List<ICommentLine>();
private readonly List<ICommentLine> lines = new List<ICommentLine>();
public IEnumerable<ICommentLine> CommentLines => lines;

View File

@@ -105,9 +105,11 @@ namespace Semmle.Extraction
if (entity.NeedsPopulation)
Populate(init as ISymbol, entity);
#if DEBUG_LABELS
var id = new StringWriter();
entity.WriteId(id);
CheckEntityHasUniqueLabel(id.ToString(), entity);
using (var id = new StringWriter())
{
entity.WriteId(id);
CheckEntityHasUniqueLabel(id.ToString(), entity);
}
#endif
}
@@ -149,9 +151,11 @@ namespace Semmle.Extraction
Populate(init as ISymbol, entity);
#if DEBUG_LABELS
var id = new StringWriter();
entity.WriteId(id);
CheckEntityHasUniqueLabel(id.ToString(), entity);
using (var id = new StringWriter())
{
entity.WriteId(id);
CheckEntityHasUniqueLabel(id.ToString(), entity);
}
#endif
return entity;

View File

@@ -69,7 +69,7 @@ namespace Semmle.Extraction.Entities
public override void WriteId(System.IO.TextWriter trapFile)
{
trapFile.Write(assembly.ToString());
if (assemblyPath is null)
if (!(assemblyPath is null))
{
trapFile.Write("#file:///");
trapFile.Write(assemblyPath.Replace("\\", "/"));

View File

@@ -162,11 +162,13 @@ namespace Semmle.Extraction
/// <returns>The debug string.</returns>
public static string GetDebugLabel(this IEntity entity)
{
var writer = new StringWriter();
writer.WriteLabel(entity.Label.Value);
writer.Write('=');
entity.WriteQuotedId(writer);
return writer.ToString();
using (var writer = new StringWriter())
{
writer.WriteLabel(entity.Label.Value);
writer.Write('=');
entity.WriteQuotedId(writer);
return writer.ToString();
}
}
}

View File

@@ -106,7 +106,7 @@ namespace Semmle.Extraction
class IdTrapBuilder
{
readonly public List<string> Fragments = new List<string>();
public readonly List<string> Fragments = new List<string>();
public void Append(object arg)
{

View File

@@ -90,6 +90,9 @@ namespace Semmle.Extraction
CIL = !value;
Fast = value;
return true;
case "brotli":
TrapCompression = value ? TrapWriter.CompressionMode.Brotli : TrapWriter.CompressionMode.Gzip;
return true;
default:
return false;
}

View File

@@ -26,9 +26,11 @@ namespace Semmle.Extraction
{
get
{
var trap = new StringWriter();
Populate(trap);
return trap.ToString();
using (var trap = new StringWriter())
{
Populate(trap);
return trap.ToString();
}
}
}

View File

@@ -48,6 +48,12 @@ namespace Semmle.Extraction
return new NextParam(Writer);
}
public NextParam Param(Label label)
{
Writer.WriteLabel(label.Value);
return new NextParam(Writer);
}
public void EndTuple()
{
Writer.WriteLine(')');

View File

@@ -155,9 +155,11 @@ namespace Semmle.Extraction
public override string ToString()
{
// Only implemented for debugging purposes
var tsb = new StringWriter();
EmitToTrapBuilder(tsb);
return tsb.ToString();
using (var writer = new StringWriter())
{
EmitToTrapBuilder(writer);
return writer.ToString();
}
}
}
}