mirror of
https://github.com/github/codeql.git
synced 2026-04-26 17:25:19 +02:00
C#: Remove ITrapBuilder in favour of TextWriter.
This commit is contained in:
@@ -5,6 +5,7 @@ using Microsoft.CodeAnalysis;
|
||||
using System.Reflection.Metadata;
|
||||
using System.Reflection;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CIL.Entities
|
||||
{
|
||||
@@ -38,6 +39,16 @@ namespace Semmle.Extraction.CIL.Entities
|
||||
|
||||
public IId Id => ShortId + IdSuffix;
|
||||
|
||||
public void WriteId(TextWriter trapFile)
|
||||
{
|
||||
trapFile.WriteIId(Id);
|
||||
}
|
||||
|
||||
public void WriteQuotedId(TextWriter trapFile)
|
||||
{
|
||||
WriteId(trapFile);
|
||||
}
|
||||
|
||||
public Id IdSuffix => fieldSuffix;
|
||||
|
||||
static readonly StringId fieldSuffix = new StringId(";cil-field");
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Linq;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CIL.Entities
|
||||
{
|
||||
|
||||
@@ -6,6 +6,8 @@ using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Semmle.Util;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Semmle.Extraction.CIL.Entities
|
||||
{
|
||||
@@ -55,6 +57,22 @@ namespace Semmle.Extraction.CIL.Entities
|
||||
|
||||
public virtual IId Id { get { return ShortId + IdSuffix; } }
|
||||
|
||||
public void WriteId(System.IO.TextWriter trapFile)
|
||||
{
|
||||
// TODO: Specialise this
|
||||
trapFile.WriteIId(Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// For debugging purposes.
|
||||
/// </summary>
|
||||
string DebugId => this.GetDebugLabel();
|
||||
|
||||
public void WriteQuotedId(TextWriter trapFile)
|
||||
{
|
||||
WriteId(trapFile);
|
||||
}
|
||||
|
||||
public Id ShortId { get; set; }
|
||||
public abstract Id IdSuffix { get; }
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CIL
|
||||
{
|
||||
@@ -45,6 +46,16 @@ namespace Semmle.Extraction.CIL
|
||||
public abstract IEnumerable<IExtractionProduct> Contents { get; }
|
||||
public Label Label { get; set; }
|
||||
|
||||
public void WriteId(System.IO.TextWriter trapFile)
|
||||
{
|
||||
trapFile.Write('*');
|
||||
}
|
||||
|
||||
public void WriteQuotedId(TextWriter trapFile)
|
||||
{
|
||||
WriteId(trapFile);
|
||||
}
|
||||
|
||||
public Microsoft.CodeAnalysis.Location ReportingLocation => throw new NotImplementedException();
|
||||
|
||||
public virtual IId Id => FreshId.Instance;
|
||||
@@ -79,6 +90,16 @@ namespace Semmle.Extraction.CIL
|
||||
public abstract Id IdSuffix { get; }
|
||||
public IId Id => ShortId + IdSuffix;
|
||||
|
||||
public void WriteId(System.IO.TextWriter trapFile)
|
||||
{
|
||||
trapFile.WriteIId(Id);
|
||||
}
|
||||
|
||||
public void WriteQuotedId(TextWriter trapFile)
|
||||
{
|
||||
WriteId(trapFile);
|
||||
}
|
||||
|
||||
public void Extract(Context cx2)
|
||||
{
|
||||
cx2.Populate(this);
|
||||
|
||||
@@ -23,7 +23,8 @@ namespace Semmle.Extraction.CIL
|
||||
}
|
||||
else
|
||||
{
|
||||
cx.DefineLabel(e);
|
||||
e.Label = cx.GetNewLabel();
|
||||
cx.DefineLabel(e, cx.TrapWriter.Writer);
|
||||
ids.Add(id, (e.Label, id));
|
||||
cx.PopulateLater(() =>
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection.Metadata;
|
||||
|
||||
namespace Semmle.Extraction.CIL
|
||||
@@ -9,14 +10,14 @@ namespace Semmle.Extraction.CIL
|
||||
/// </summary>
|
||||
public abstract class Id : IId
|
||||
{
|
||||
public void AppendTo(ITrapBuilder tb)
|
||||
public void AppendTo(System.IO.TextWriter tb)
|
||||
{
|
||||
tb.Append("@\"");
|
||||
tb.Write("@\"");
|
||||
BuildParts(tb);
|
||||
tb.Append("\"");
|
||||
tb.Write("\"");
|
||||
}
|
||||
|
||||
public abstract void BuildParts(ITrapBuilder tb);
|
||||
public abstract void BuildParts(System.IO.TextWriter tb);
|
||||
|
||||
public static Id operator +(Id l1, Id l2) => Create(l1, l2);
|
||||
|
||||
@@ -76,7 +77,7 @@ namespace Semmle.Extraction.CIL
|
||||
hash = unchecked(12 + 3 * (left.GetHashCode() + 51 * right.GetHashCode()));
|
||||
}
|
||||
|
||||
public override void BuildParts(ITrapBuilder tb)
|
||||
public override void BuildParts(System.IO.TextWriter tb)
|
||||
{
|
||||
left.BuildParts(tb);
|
||||
right.BuildParts(tb);
|
||||
@@ -112,9 +113,9 @@ namespace Semmle.Extraction.CIL
|
||||
value = s;
|
||||
}
|
||||
|
||||
public override void BuildParts(ITrapBuilder tb)
|
||||
public override void BuildParts(System.IO.TextWriter tw)
|
||||
{
|
||||
tb.Append(value);
|
||||
tw.Write(value);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
@@ -138,9 +139,9 @@ namespace Semmle.Extraction.CIL
|
||||
value = i;
|
||||
}
|
||||
|
||||
public override void BuildParts(ITrapBuilder tb)
|
||||
public override void BuildParts(System.IO.TextWriter tw)
|
||||
{
|
||||
tb.Append(value);
|
||||
tw.Write(value);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
|
||||
Reference in New Issue
Block a user