mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
C#: Code tidy. Rename variables, delete dead code, format whitespace, improve comments.
This commit is contained in:
@@ -54,24 +54,26 @@ namespace Semmle.Extraction
|
||||
return init == null ? CreateEntity2(factory, init) : CreateNonNullEntity(factory, init);
|
||||
}
|
||||
|
||||
bool DefiningLabel = false;
|
||||
// A recursion guard against writing to the trap file whilst writing an id to the trap file.
|
||||
bool WritingLabel = false;
|
||||
|
||||
public void DefineLabel(IEntity entity, TextWriter trapFile)
|
||||
{
|
||||
if (DefiningLabel)
|
||||
if (WritingLabel)
|
||||
{
|
||||
// Don't define a label whilst writing a label.
|
||||
PopulateLater(() => DefineLabel(entity, trapFile));
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
DefiningLabel = true;
|
||||
WritingLabel = true;
|
||||
entity.DefineLabel(trapFile);
|
||||
}
|
||||
finally
|
||||
{
|
||||
DefiningLabel = false;
|
||||
WritingLabel = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -330,19 +332,19 @@ namespace Semmle.Extraction
|
||||
Key = key;
|
||||
}
|
||||
|
||||
public void EmitToTrapBuilder(TextWriter tw)
|
||||
public void EmitToTrapBuilder(TextWriter trapFile)
|
||||
{
|
||||
tw.Write(".push ");
|
||||
Key.AppendTo(tw);
|
||||
tw.WriteLine();
|
||||
trapFile.Write(".push ");
|
||||
Key.AppendTo(trapFile);
|
||||
trapFile.WriteLine();
|
||||
}
|
||||
}
|
||||
|
||||
class PopEmitter : ITrapEmitter
|
||||
{
|
||||
public void EmitToTrapBuilder(TextWriter tw)
|
||||
public void EmitToTrapBuilder(TextWriter trapFile)
|
||||
{
|
||||
tw.WriteLine(".pop");
|
||||
trapFile.WriteLine(".pop");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -356,7 +358,7 @@ namespace Semmle.Extraction
|
||||
/// <exception cref="InternalError">Thrown on invalid trap stack behaviour.</exception>
|
||||
public void Populate(ISymbol optionalSymbol, ICachedEntity entity)
|
||||
{
|
||||
if (DefiningLabel)
|
||||
if (WritingLabel)
|
||||
{
|
||||
// Don't write tuples etc if we're currently defining a label
|
||||
PopulateLater(() => Populate(optionalSymbol, entity));
|
||||
|
||||
@@ -28,15 +28,15 @@ namespace Semmle.Extraction
|
||||
/// <summary>
|
||||
/// Writes the unique identifier of this entitiy to a trap file.
|
||||
/// </summary>
|
||||
/// <param name="writer"></param>
|
||||
void WriteId(TextWriter writer);
|
||||
/// <param name="trapFile">The trapfile to write to.</param>
|
||||
void WriteId(TextWriter writrapFileter);
|
||||
|
||||
/// <summary>
|
||||
/// Writes the quoted identifier of this entity,
|
||||
/// which could be @"..." or *
|
||||
/// </summary>
|
||||
/// <param name="writer"></param>
|
||||
void WriteQuotedId(TextWriter writer);
|
||||
/// <param name="trapFile">The trapfile to write to.</param>
|
||||
void WriteQuotedId(TextWriter trapFile);
|
||||
|
||||
/// <summary>
|
||||
/// The location for reporting purposes.
|
||||
|
||||
@@ -39,7 +39,10 @@ namespace Semmle.Extraction
|
||||
cx.Try(null, null, () => Populate(cx.TrapWriter.Writer));
|
||||
}
|
||||
|
||||
public string DebugTuples
|
||||
/// <summary>
|
||||
/// For debugging.
|
||||
/// </summary>
|
||||
public string DebugContents
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Semmle.Extraction
|
||||
/// <summary>
|
||||
/// Appends this ID to the supplied trap builder.
|
||||
/// </summary>
|
||||
void AppendTo(TextWriter tw);
|
||||
void AppendTo(TextWriter trapFile);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -38,9 +38,9 @@ namespace Semmle.Extraction
|
||||
|
||||
public override int GetHashCode() => 0;
|
||||
|
||||
public void AppendTo(System.IO.TextWriter tw)
|
||||
public void AppendTo(TextWriter trapFile)
|
||||
{
|
||||
tw.Write('*');
|
||||
trapFile.Write('*');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,11 +97,11 @@ namespace Semmle.Extraction
|
||||
|
||||
public override int GetHashCode() => TrapBuilder.ToString().GetHashCode();
|
||||
|
||||
public void AppendTo(TextWriter tb)
|
||||
public void AppendTo(TextWriter trapFile)
|
||||
{
|
||||
tb.Write("@\"");
|
||||
tb.Write(TrapBuilder.ToString());
|
||||
tb.Write("\"");
|
||||
trapFile.Write("@\"");
|
||||
trapFile.Write(TrapBuilder.ToString());
|
||||
trapFile.Write("\"");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,14 +143,14 @@ namespace Semmle.Extraction
|
||||
/// <summary>
|
||||
/// Constructs a unique string for this label.
|
||||
/// </summary>
|
||||
/// <param name="tb">The trap builder used to store the result.</param>
|
||||
public void AppendTo(System.IO.TextWriter tw)
|
||||
/// <param name="trapFile">The trap builder used to store the result.</param>
|
||||
public void AppendTo(System.IO.TextWriter trapFile)
|
||||
{
|
||||
if (!Valid)
|
||||
throw new NullReferenceException("Attempt to use an invalid label");
|
||||
|
||||
tw.Write('#');
|
||||
tw.Write(Value);
|
||||
trapFile.Write('#');
|
||||
trapFile.Write(Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Semmle.Extraction
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether one Location ends before another starts.
|
||||
/// Whether one Location ends before another starts.
|
||||
/// </summary>
|
||||
/// <param name="before">The Location coming before</param>
|
||||
/// <param name="after">The Location coming after</param>
|
||||
|
||||
@@ -22,7 +22,10 @@ namespace Semmle.Extraction
|
||||
|
||||
public abstract void Populate(TextWriter trapFile);
|
||||
|
||||
public string DebugTrapContents
|
||||
/// <summary>
|
||||
/// For debugging.
|
||||
/// </summary>
|
||||
public string DebugContents
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
@@ -11,33 +11,33 @@ namespace Semmle.Extraction
|
||||
/// Appends a [comma] separated list to a trap builder.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the list.</typeparam>
|
||||
/// <param name="tb">The trap builder to append to.</param>
|
||||
/// <param name="trapFile">The trap builder to append to.</param>
|
||||
/// <param name="separator">The separator string (e.g. ",")</param>
|
||||
/// <param name="items">The list of items.</param>
|
||||
/// <returns>The original trap builder (fluent interface).</returns>
|
||||
public static TextWriter AppendList<T>(this TextWriter tb, string separator, IEnumerable<T> items) where T:IEntity
|
||||
public static TextWriter AppendList<T>(this TextWriter trapFile, string separator, IEnumerable<T> items) where T:IEntity
|
||||
{
|
||||
return tb.BuildList(separator, items, (x, tb0) => { tb0.WriteSubId(x); });
|
||||
return trapFile.BuildList(separator, items, (x, tb0) => { tb0.WriteSubId(x); });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a trap builder using a separator and an action for each item in the list.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the items.</typeparam>
|
||||
/// <param name="tb">The trap builder to append to.</param>
|
||||
/// <param name="trapFile">The trap builder to append to.</param>
|
||||
/// <param name="separator">The separator string (e.g. ",")</param>
|
||||
/// <param name="items">The list of items.</param>
|
||||
/// <param name="action">The action on each item.</param>
|
||||
/// <returns>The original trap builder (fluent interface).</returns>
|
||||
public static TextWriter BuildList<T>(this TextWriter tb, string separator, IEnumerable<T> items, Action<T, TextWriter> action)
|
||||
public static TextWriter BuildList<T>(this TextWriter trapFile, string separator, IEnumerable<T> items, Action<T, TextWriter> action)
|
||||
{
|
||||
bool first = true;
|
||||
foreach (var item in items)
|
||||
{
|
||||
if (first) first = false; else tb.Write(separator);
|
||||
action(item, tb);
|
||||
if (first) first = false; else trapFile.Write(separator);
|
||||
action(item, trapFile);
|
||||
}
|
||||
return tb;
|
||||
return trapFile;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,42 +4,36 @@ namespace Semmle.Extraction
|
||||
{
|
||||
public static class TrapExtensions
|
||||
{
|
||||
public static void WriteLabel(this TextWriter writer, int value)
|
||||
public static void WriteLabel(this TextWriter trapFile, int value)
|
||||
{
|
||||
writer.Write('#');
|
||||
writer.Write(value);
|
||||
trapFile.Write('#');
|
||||
trapFile.Write(value);
|
||||
}
|
||||
|
||||
public static void WriteLabel(this TextWriter writer, IEntity entity)
|
||||
public static void WriteLabel(this TextWriter trapFile, IEntity entity)
|
||||
{
|
||||
writer.WriteLabel(entity.Label.Value);
|
||||
trapFile.WriteLabel(entity.Label.Value);
|
||||
}
|
||||
|
||||
public static void WriteSubId(this TextWriter writer, IEntity entity)
|
||||
public static void WriteSubId(this TextWriter trapFile, IEntity entity)
|
||||
{
|
||||
writer.Write('{');
|
||||
writer.WriteLabel(entity);
|
||||
writer.Write('}');
|
||||
trapFile.Write('{');
|
||||
trapFile.WriteLabel(entity);
|
||||
trapFile.Write('}');
|
||||
}
|
||||
|
||||
public static void WriteSeparator(this TextWriter writer, string separator, int index)
|
||||
public static void WriteSeparator(this TextWriter trapFile, string separator, ref int index)
|
||||
{
|
||||
if (index > 0) writer.Write(separator);
|
||||
}
|
||||
|
||||
// This is temporary and we can get rid of IId entirely
|
||||
public static void WriteIId(this TextWriter writer, IId iid)
|
||||
{
|
||||
iid.AppendTo(writer);
|
||||
if (index++ > 0) trapFile.Write(separator);
|
||||
}
|
||||
|
||||
public struct FirstParam
|
||||
{
|
||||
private readonly TextWriter Writer;
|
||||
|
||||
public FirstParam(TextWriter writer)
|
||||
public FirstParam(TextWriter trapFile)
|
||||
{
|
||||
Writer = writer;
|
||||
Writer = trapFile;
|
||||
}
|
||||
|
||||
public NextParam Param(IEntity entity)
|
||||
@@ -64,9 +58,9 @@ namespace Semmle.Extraction
|
||||
{
|
||||
private readonly TextWriter Writer;
|
||||
|
||||
public NextParam(TextWriter writer)
|
||||
public NextParam(TextWriter trapFile)
|
||||
{
|
||||
Writer = writer;
|
||||
Writer = trapFile;
|
||||
}
|
||||
|
||||
private void WriteComma()
|
||||
@@ -126,7 +120,7 @@ namespace Semmle.Extraction
|
||||
encoding.GetByteCount(s) > maxStringBytes;
|
||||
}
|
||||
|
||||
private static void WriteString(TextWriter writer, string s) => writer.Write(EncodeString(s));
|
||||
private static void WriteString(TextWriter trapFile, string s) => trapFile.Write(EncodeString(s));
|
||||
|
||||
/// <summary>
|
||||
/// Truncates a string such that the output UTF8 does not exceed <paramref name="bytesRemaining"/> bytes.
|
||||
@@ -161,104 +155,96 @@ namespace Semmle.Extraction
|
||||
/// Output a string to the trap file, such that the encoded output does not exceed
|
||||
/// <paramref name="bytesRemaining"/> bytes.
|
||||
/// </summary>
|
||||
/// <param name="writer">The trapbuilder</param>
|
||||
/// <param name="trapFile">The trapbuilder</param>
|
||||
/// <param name="s">The string to output.</param>
|
||||
/// <param name="bytesRemaining">The remaining bytes available to output.</param>
|
||||
private static void WriteTruncatedString(TextWriter writer, string s, ref int bytesRemaining)
|
||||
private static void WriteTruncatedString(TextWriter trapFile, string s, ref int bytesRemaining)
|
||||
{
|
||||
WriteString(writer, TruncateString(s, ref bytesRemaining));
|
||||
WriteString(trapFile, TruncateString(s, ref bytesRemaining));
|
||||
}
|
||||
|
||||
public static void WriteTrapString(this TextWriter writer, string s)
|
||||
public static void WriteTrapString(this TextWriter trapFile, string s)
|
||||
{
|
||||
writer.Write('\"');
|
||||
trapFile.Write('\"');
|
||||
if (NeedsTruncation(s))
|
||||
{
|
||||
// Slow path
|
||||
int remaining = maxStringBytes;
|
||||
WriteTruncatedString(writer, s, ref remaining);
|
||||
WriteTruncatedString(trapFile, s, ref remaining);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fast path
|
||||
WriteString(writer, s);
|
||||
WriteString(trapFile, s);
|
||||
}
|
||||
writer.Write('\"');
|
||||
trapFile.Write('\"');
|
||||
}
|
||||
|
||||
public static void WriteTrapFloat(this TextWriter writer, float f)
|
||||
public static void WriteTrapFloat(this TextWriter trapFile, float f)
|
||||
{
|
||||
writer.Write(f.ToString("0.#####e0")); // Trap importer won't accept ints
|
||||
trapFile.Write(f.ToString("0.#####e0")); // Trap importer won't accept ints
|
||||
}
|
||||
|
||||
|
||||
public static FirstParam BeginTuple(this TextWriter writer, string name)
|
||||
public static FirstParam BeginTuple(this TextWriter trapFile, string name)
|
||||
{
|
||||
writer.Write(name);
|
||||
writer.Write('(');
|
||||
return new FirstParam(writer);
|
||||
trapFile.Write(name);
|
||||
trapFile.Write('(');
|
||||
return new FirstParam(trapFile);
|
||||
}
|
||||
|
||||
public static void WriteTuple(this TextWriter writer, string name, IEntity p1)
|
||||
public static void WriteTuple(this TextWriter trapFile, string name, IEntity p1)
|
||||
{
|
||||
writer.BeginTuple(name).Param(p1).EndTuple();
|
||||
trapFile.BeginTuple(name).Param(p1).EndTuple();
|
||||
}
|
||||
|
||||
public static void WriteTuple(this TextWriter writer, string name, IEntity p1, IEntity p2)
|
||||
public static void WriteTuple(this TextWriter trapFile, string name, IEntity p1, IEntity p2)
|
||||
{
|
||||
writer.BeginTuple(name).Param(p1).Param(p2).EndTuple();
|
||||
trapFile.BeginTuple(name).Param(p1).Param(p2).EndTuple();
|
||||
}
|
||||
|
||||
public static void WriteTuple(this TextWriter writer, string name, IEntity p1, string p2, IEntity p3, IEntity p4)
|
||||
public static void WriteTuple(this TextWriter trapFile, string name, IEntity p1, string p2, IEntity p3, IEntity p4)
|
||||
{
|
||||
writer.BeginTuple(name).Param(p1).Param(p2).Param(p3).Param(p4).EndTuple();
|
||||
trapFile.BeginTuple(name).Param(p1).Param(p2).Param(p3).Param(p4).EndTuple();
|
||||
}
|
||||
|
||||
public static void WriteTuple(this TextWriter writer, string name, IEntity p1, string p2, IEntity p3)
|
||||
public static void WriteTuple(this TextWriter trapFile, string name, IEntity p1, string p2, IEntity p3)
|
||||
{
|
||||
writer.BeginTuple(name).Param(p1).Param(p2).Param(p3).EndTuple();
|
||||
trapFile.BeginTuple(name).Param(p1).Param(p2).Param(p3).EndTuple();
|
||||
}
|
||||
|
||||
public static void WriteTuple(this TextWriter writer, string name, IEntity p1, int p2, IEntity p3)
|
||||
public static void WriteTuple(this TextWriter trapFile, string name, IEntity p1, int p2, IEntity p3)
|
||||
{
|
||||
writer.BeginTuple(name).Param(p1).Param(p2).Param(p3).EndTuple();
|
||||
trapFile.BeginTuple(name).Param(p1).Param(p2).Param(p3).EndTuple();
|
||||
}
|
||||
|
||||
public static void WriteTuple(this TextWriter writer, string name, IEntity p1, int p2, int p3)
|
||||
public static void WriteTuple(this TextWriter trapFile, string name, IEntity p1, int p2, int p3)
|
||||
{
|
||||
writer.BeginTuple(name).Param(p1).Param(p2).Param(p3).EndTuple();
|
||||
trapFile.BeginTuple(name).Param(p1).Param(p2).Param(p3).EndTuple();
|
||||
}
|
||||
|
||||
public static void WriteTuple(this TextWriter writer, string name, IEntity p1, IEntity p2, int p3)
|
||||
public static void WriteTuple(this TextWriter trapFile, string name, IEntity p1, IEntity p2, int p3)
|
||||
{
|
||||
writer.BeginTuple(name).Param(p1).Param(p2).Param(p3).EndTuple();
|
||||
trapFile.BeginTuple(name).Param(p1).Param(p2).Param(p3).EndTuple();
|
||||
}
|
||||
|
||||
public static void WriteTuple(this TextWriter writer, string name, IEntity p1, IEntity p2, IEntity p3)
|
||||
public static void WriteTuple(this TextWriter trapFile, string name, IEntity p1, IEntity p2, IEntity p3)
|
||||
{
|
||||
writer.BeginTuple(name).Param(p1).Param(p2).Param(p3).EndTuple();
|
||||
trapFile.BeginTuple(name).Param(p1).Param(p2).Param(p3).EndTuple();
|
||||
}
|
||||
|
||||
public static void WriteTuple(this TextWriter writer, string name, IEntity p1, string p2, IEntity p3, IEntity p4, IEntity p5)
|
||||
public static void WriteTuple(this TextWriter trapFile, string name, IEntity p1, string p2, IEntity p3, IEntity p4, IEntity p5)
|
||||
{
|
||||
writer.BeginTuple(name).Param(p1).Param(p2).Param(p3).Param(p4).Param(p5).EndTuple();
|
||||
trapFile.BeginTuple(name).Param(p1).Param(p2).Param(p3).Param(p4).Param(p5).EndTuple();
|
||||
}
|
||||
|
||||
public static void WriteTuple(this TextWriter writer, string name, IEntity p1, int p2)
|
||||
public static void WriteTuple(this TextWriter trapFile, string name, IEntity p1, int p2)
|
||||
{
|
||||
writer.BeginTuple(name).Param(p1).Param(p2).EndTuple();
|
||||
trapFile.BeginTuple(name).Param(p1).Param(p2).EndTuple();
|
||||
}
|
||||
|
||||
public static void WriteTuple(this TextWriter writer, string name, IEntity p1, string p2)
|
||||
public static void WriteTuple(this TextWriter trapFile, string name, IEntity p1, string p2)
|
||||
{
|
||||
writer.BeginTuple(name).Param(p1).Param(p2).EndTuple();
|
||||
}
|
||||
|
||||
|
||||
// DELETEME
|
||||
public static void Emit(this TextWriter writer, Tuple t)
|
||||
{
|
||||
t.EmitToTrapBuilder(writer);
|
||||
trapFile.BeginTuple(name).Param(p1).Param(p2).EndTuple();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Semmle.Extraction
|
||||
{
|
||||
public interface ITrapEmitter
|
||||
{
|
||||
void EmitToTrapBuilder(TextWriter tw);
|
||||
void EmitToTrapBuilder(TextWriter trapFile);
|
||||
}
|
||||
|
||||
public sealed class TrapWriter : IDisposable
|
||||
@@ -88,7 +88,6 @@ namespace Semmle.Extraction
|
||||
compressionStream = fileStream;
|
||||
break;
|
||||
default:
|
||||
// Dead code
|
||||
throw new ArgumentException(nameof(trapCompression));
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Semmle.Extraction
|
||||
array.Sum(encoding.GetByteCount) > maxStringBytes;
|
||||
}
|
||||
|
||||
private static void WriteString(TextWriter tb, string s) => tb.Write(EncodeString(s));
|
||||
private static void WriteString(TextWriter trapFile, string s) => trapFile.Write(EncodeString(s));
|
||||
|
||||
/// <summary>
|
||||
/// Truncates a string such that the output UTF8 does not exceed <paramref name="bytesRemaining"/> bytes.
|
||||
@@ -71,75 +71,75 @@ namespace Semmle.Extraction
|
||||
/// Output a string to the trap file, such that the encoded output does not exceed
|
||||
/// <paramref name="bytesRemaining"/> bytes.
|
||||
/// </summary>
|
||||
/// <param name="tb">The trapbuilder</param>
|
||||
/// <param name="trapFile">The trapbuilder</param>
|
||||
/// <param name="s">The string to output.</param>
|
||||
/// <param name="bytesRemaining">The remaining bytes available to output.</param>
|
||||
private static void WriteTruncatedString(TextWriter tb, string s, ref int bytesRemaining)
|
||||
private static void WriteTruncatedString(TextWriter trapFile, string s, ref int bytesRemaining)
|
||||
{
|
||||
WriteString(tb, TruncateString(s, ref bytesRemaining));
|
||||
WriteString(trapFile, TruncateString(s, ref bytesRemaining));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a unique string for this tuple.
|
||||
/// </summary>
|
||||
/// <param name="tw">The trap builder used to store the result.</param>
|
||||
public void EmitToTrapBuilder(TextWriter tw)
|
||||
/// <param name="trapFile">The trap builder used to store the result.</param>
|
||||
public void EmitToTrapBuilder(TextWriter trapFile)
|
||||
{
|
||||
tw.Write(Name);
|
||||
tw.Write("(");
|
||||
trapFile.Write(Name);
|
||||
trapFile.Write("(");
|
||||
|
||||
int column = 0;
|
||||
foreach (var a in Args)
|
||||
{
|
||||
tw.WriteSeparator(", ", column++);
|
||||
trapFile.WriteSeparator(", ", ref column);
|
||||
switch(a)
|
||||
{
|
||||
case Label l:
|
||||
l.AppendTo(tw);
|
||||
l.AppendTo(trapFile);
|
||||
break;
|
||||
case IEntity e:
|
||||
e.Label.AppendTo(tw);
|
||||
e.Label.AppendTo(trapFile);
|
||||
break;
|
||||
case string s:
|
||||
tw.Write("\"");
|
||||
trapFile.Write("\"");
|
||||
if (NeedsTruncation(s))
|
||||
{
|
||||
// Slow path
|
||||
int remaining = maxStringBytes;
|
||||
WriteTruncatedString(tw, s, ref remaining);
|
||||
WriteTruncatedString(trapFile, s, ref remaining);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fast path
|
||||
WriteString(tw, s);
|
||||
WriteString(trapFile, s);
|
||||
}
|
||||
tw.Write("\"");
|
||||
trapFile.Write("\"");
|
||||
break;
|
||||
case System.Enum _:
|
||||
tw.Write((int)a);
|
||||
trapFile.Write((int)a);
|
||||
break;
|
||||
case int i:
|
||||
tw.Write(i);
|
||||
trapFile.Write(i);
|
||||
break;
|
||||
case float f:
|
||||
tw.Write(f.ToString("0.#####e0")); // Trap importer won't accept ints
|
||||
trapFile.Write(f.ToString("0.#####e0")); // Trap importer won't accept ints
|
||||
break;
|
||||
case string[] array:
|
||||
tw.Write('\"');
|
||||
trapFile.Write('\"');
|
||||
if (NeedsTruncation(array))
|
||||
{
|
||||
// Slow path
|
||||
int remaining = maxStringBytes;
|
||||
foreach (var element in array)
|
||||
WriteTruncatedString(tw, element, ref remaining);
|
||||
WriteTruncatedString(trapFile, element, ref remaining);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fast path
|
||||
foreach (var element in array)
|
||||
WriteString(tw, element);
|
||||
WriteString(trapFile, element);
|
||||
}
|
||||
tw.Write('\"');
|
||||
trapFile.Write('\"');
|
||||
break;
|
||||
case null:
|
||||
throw new InternalError($"Attempt to write a null argument tuple {Name} at column {column}");
|
||||
@@ -149,7 +149,7 @@ namespace Semmle.Extraction
|
||||
|
||||
++column;
|
||||
}
|
||||
tw.WriteLine(")");
|
||||
trapFile.WriteLine(")");
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
||||
Reference in New Issue
Block a user