Move more classes to the Semmle.Extraction.CSharp namespace

This commit is contained in:
Tamas Vajk
2024-11-13 15:27:48 +01:00
parent 46da5960ee
commit 02bd204111
32 changed files with 59 additions and 148 deletions

View File

@@ -0,0 +1,340 @@
using System;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Semmle.Extraction.CSharp
{
/// <summary>
/// A `TextWriter` object that wraps another `TextWriter` object, and which
/// HTML escapes the characters `&`, `{`, `}`, `"`, `@`, and `#`, before
/// writing to the underlying object.
/// </summary>
public sealed class EscapingTextWriter : TextWriter
{
private readonly TextWriter wrapped;
private readonly bool disposeUnderlying;
public EscapingTextWriter(TextWriter wrapped, bool disposeUnderlying = false)
{
this.wrapped = wrapped;
this.disposeUnderlying = disposeUnderlying;
}
/// <summary>
/// Creates a new instance with a new underlying `StringWriter` object. The
/// underlying object is disposed of when this object is.
/// </summary>
public EscapingTextWriter() : this(new StringWriter(), true) { }
public EscapingTextWriter(IFormatProvider? formatProvider) : base(formatProvider)
=> throw new NotImplementedException();
private void WriteEscaped(char c)
{
switch (c)
{
case '&':
wrapped.Write("&amp;");
break;
case '{':
wrapped.Write("&lbrace;");
break;
case '}':
wrapped.Write("&rbrace;");
break;
case '"':
wrapped.Write("&quot;");
break;
case '@':
wrapped.Write("&commat;");
break;
case '#':
wrapped.Write("&num;");
break;
default:
wrapped.Write(c);
break;
}
}
public void WriteSubId(IEntity entity)
{
if (entity is null)
{
wrapped.Write("<null>");
return;
}
WriteUnescaped('{');
wrapped.WriteLabel(entity);
WriteUnescaped('}');
}
public void WriteUnescaped(char c)
=> wrapped.Write(c);
public void WriteUnescaped(string s)
=> wrapped.Write(s);
#region overrides
public override Encoding Encoding => wrapped.Encoding;
public override IFormatProvider FormatProvider => wrapped.FormatProvider;
public override string NewLine { get => wrapped.NewLine; }
public override void Close()
=> throw new NotImplementedException();
public override ValueTask DisposeAsync()
=> throw new NotImplementedException();
public override bool Equals(object? obj)
=> wrapped.Equals(obj) && obj is EscapingTextWriter other && disposeUnderlying == other.disposeUnderlying;
public override void Flush()
=> wrapped.Flush();
public override Task FlushAsync()
=> wrapped.FlushAsync();
public override int GetHashCode()
=> HashCode.Combine(wrapped, disposeUnderlying);
public override string ToString()
=> wrapped.ToString() ?? "";
public override void Write(bool value)
=> wrapped.Write(value);
public override void Write(char value)
=> WriteEscaped(value);
public override void Write(char[]? buffer)
{
if (buffer is null)
return;
Write(buffer, 0, buffer.Length);
}
public override void Write(char[] buffer, int index, int count)
{
for (var i = index; i < buffer.Length && i < index + count; i++)
{
WriteEscaped(buffer[i]);
}
}
public override void Write(decimal value)
=> wrapped.Write(value);
public override void Write(double value)
=> wrapped.Write(value);
public override void Write(int value)
=> wrapped.Write(value);
public override void Write(long value)
=> wrapped.Write(value);
public override void Write(object? value)
=> Write(value?.ToString());
public override void Write(ReadOnlySpan<char> buffer)
{
foreach (var c in buffer)
{
WriteEscaped(c);
}
}
public override void Write(float value)
=> wrapped.Write(value);
public override void Write(string? value)
{
if (value is null)
{
wrapped.Write(value);
}
else
{
foreach (var c in value)
{
WriteEscaped(c);
}
}
}
public override void Write(string format, object? arg0)
=> Write(string.Format(format, arg0));
public override void Write(string format, object? arg0, object? arg1)
=> Write(string.Format(format, arg0, arg1));
public override void Write(string format, object? arg0, object? arg1, object? arg2)
=> Write(string.Format(format, arg0, arg1, arg2));
public override void Write(string format, params object?[] arg)
=> Write(string.Format(format, arg));
public override void Write(StringBuilder? value)
{
if (value is null)
{
wrapped.Write(value);
}
else
{
for (var i = 0; i < value.Length; i++)
{
WriteEscaped(value[i]);
}
}
}
public override void Write(uint value)
=> wrapped.Write(value);
public override void Write(ulong value)
=> wrapped.Write(value);
public override Task WriteAsync(char value)
=> throw new NotImplementedException();
public override Task WriteAsync(char[] buffer, int index, int count)
=> throw new NotImplementedException();
public override Task WriteAsync(ReadOnlyMemory<char> buffer, CancellationToken cancellationToken = default)
=> throw new NotImplementedException();
public override Task WriteAsync(string? value)
=> throw new NotImplementedException();
public override Task WriteAsync(StringBuilder? value, CancellationToken cancellationToken = default)
=> throw new NotImplementedException();
public override void WriteLine()
=> wrapped.WriteLine();
public override void WriteLine(bool value)
=> wrapped.WriteLine(value);
public override void WriteLine(char value)
{
Write(value);
WriteLine();
}
public override void WriteLine(char[]? buffer)
{
Write(buffer);
WriteLine();
}
public override void WriteLine(char[] buffer, int index, int count)
{
Write(buffer, index, count);
WriteLine();
}
public override void WriteLine(decimal value)
=> wrapped.WriteLine(value);
public override void WriteLine(double value)
=> wrapped.WriteLine(value);
public override void WriteLine(int value)
=> wrapped.WriteLine(value);
public override void WriteLine(long value)
=> wrapped.WriteLine(value);
public override void WriteLine(object? value)
{
Write(value);
WriteLine();
}
public override void WriteLine(ReadOnlySpan<char> buffer)
{
Write(buffer);
WriteLine();
}
public override void WriteLine(float value)
=> wrapped.WriteLine(value);
public override void WriteLine(string? value)
{
Write(value);
WriteLine();
}
public override void WriteLine(string format, object? arg0)
{
Write(format, arg0);
WriteLine();
}
public override void WriteLine(string format, object? arg0, object? arg1)
{
Write(format, arg0, arg1);
WriteLine();
}
public override void WriteLine(string format, object? arg0, object? arg1, object? arg2)
{
Write(format, arg0, arg1, arg2);
WriteLine();
}
public override void WriteLine(string format, params object?[] arg)
{
Write(format, arg);
WriteLine();
}
public override void WriteLine(StringBuilder? value)
{
Write(value);
WriteLine();
}
public override void WriteLine(uint value)
=> wrapped.WriteLine(value);
public override void WriteLine(ulong value)
=> wrapped.WriteLine(value);
public override Task WriteLineAsync()
=> throw new NotImplementedException();
public override Task WriteLineAsync(char value)
=> throw new NotImplementedException();
public override Task WriteLineAsync(char[] buffer, int index, int count)
=> throw new NotImplementedException();
public override Task WriteLineAsync(ReadOnlyMemory<char> buffer, CancellationToken cancellationToken = default)
=> throw new NotImplementedException();
public override Task WriteLineAsync(string? value)
=> throw new NotImplementedException();
public override Task WriteLineAsync(StringBuilder? value, CancellationToken cancellationToken = default)
=> throw new NotImplementedException();
protected override void Dispose(bool disposing)
{
if (disposing && disposeUnderlying)
wrapped.Dispose();
}
#endregion overrides
}
}

View File

@@ -0,0 +1,118 @@
using System;
using System.IO;
namespace Semmle.Extraction.CSharp
{
/// <summary>
/// A key. Either a simple key, e.g. `@"bool A.M();method"`, or a compound key, e.g.
/// `@"{0} {1}.M();method"` where `0` and `1` are both labels.
/// </summary>
public class Key
{
private readonly StringWriter trapBuilder = new StringWriter();
/// <summary>
/// Creates a new key by concatenating the contents of the supplied arguments.
/// </summary>
public Key(params object[] args)
{
trapBuilder = new StringWriter();
foreach (var arg in args)
{
if (arg is IEntity entity)
{
var key = entity.Label;
trapBuilder.Write("{#");
trapBuilder.Write(key.Value.ToString());
trapBuilder.Write("}");
}
else
{
trapBuilder.Write(arg.ToString());
}
}
}
/// <summary>
/// Creates a new key by applying the supplied action to an empty
/// trap builder.
/// </summary>
public Key(Action<TextWriter> action)
{
action(trapBuilder);
}
public override string ToString()
{
return trapBuilder.ToString();
}
public override bool Equals(object? obj)
{
if (obj is null || obj.GetType() != GetType())
return false;
var id = (Key)obj;
return trapBuilder.ToString() == id.trapBuilder.ToString();
}
public override int GetHashCode() => trapBuilder.ToString().GetHashCode();
public void AppendTo(TextWriter trapFile)
{
trapFile.Write("@\"");
trapFile.Write(trapBuilder.ToString());
trapFile.Write("\"");
}
}
/// <summary>
/// A label referencing an entity, of the form "#123".
/// </summary>
public struct Label
{
public Label(int value) : this()
{
Value = value;
}
public int Value { get; private set; }
public static Label InvalidLabel { get; } = new Label(0);
public bool Valid => Value > 0;
public override string ToString()
{
if (!Valid)
throw new InvalidOperationException("Attempt to use an invalid label");
return $"#{Value}";
}
public static bool operator ==(Label l1, Label l2) => l1.Value == l2.Value;
public static bool operator !=(Label l1, Label l2) => l1.Value != l2.Value;
public override bool Equals(object? other)
{
if (other is null)
return false;
return GetType() == other.GetType() && ((Label)other).Value == Value;
}
public override int GetHashCode() => 61 * Value;
/// <summary>
/// Constructs a unique string for this label.
/// </summary>
/// <param name="trapFile">The trap builder used to store the result.</param>
public void AppendTo(System.IO.TextWriter trapFile)
{
if (!Valid)
throw new InvalidOperationException("Attempt to use an invalid label");
trapFile.Write('#');
trapFile.Write(Value);
}
}
}

View File

@@ -0,0 +1,264 @@
using System;
using System.Collections.Generic;
using System.IO;
namespace Semmle.Extraction.CSharp
{
public static class TrapExtensions
{
public static void WriteLabel(this TextWriter trapFile, int value)
{
trapFile.Write('#');
trapFile.Write(value);
}
public static void WriteLabel(this TextWriter trapFile, IEntity entity)
{
trapFile.WriteLabel(entity.Label.Value);
}
public static void WriteSeparator(this TextWriter trapFile, string separator, ref int index)
{
if (index++ > 0)
trapFile.Write(separator);
}
public static TextWriter WriteColumn(this TextWriter trapFile, int i)
{
trapFile.Write(i);
return trapFile;
}
public static TextWriter WriteColumn(this TextWriter trapFile, string s)
{
trapFile.WriteTrapString(s);
return trapFile;
}
public static TextWriter WriteColumn(this TextWriter trapFile, IEntity entity)
{
trapFile.WriteLabel(entity.Label.Value);
return trapFile;
}
public static TextWriter WriteColumn(this TextWriter trapFile, Label label)
{
trapFile.WriteLabel(label.Value);
return trapFile;
}
public static TextWriter WriteColumn(this TextWriter trapFile, float f)
{
trapFile.WriteTrapFloat(f);
return trapFile;
}
public static TextWriter WriteColumn(this TextWriter trapFile, object o)
{
switch (o)
{
case int i:
return trapFile.WriteColumn(i);
case float f:
return trapFile.WriteColumn(f);
case string s:
return trapFile.WriteColumn(s);
case IEntity e:
return trapFile.WriteColumn(e);
case Label l:
return trapFile.WriteColumn(l);
case Enum _:
return trapFile.WriteColumn((int)o);
default:
throw new NotSupportedException($"Unsupported object type '{o.GetType()}' received");
}
}
private const int maxStringBytes = 1 << 20; // 1MB
private static readonly System.Text.Encoding encoding = System.Text.Encoding.UTF8;
private static bool NeedsTruncation(string s)
{
// Optimization: only count the actual number of bytes if there is the possibility
// of the string exceeding maxStringBytes
return encoding.GetMaxByteCount(s.Length) > maxStringBytes &&
encoding.GetByteCount(s) > maxStringBytes;
}
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.
/// </summary>
/// <param name="s">The input string to truncate.</param>
/// <param name="bytesRemaining">The number of bytes available.</param>
/// <returns>The truncated string.</returns>
private static string TruncateString(string s, ref int bytesRemaining)
{
var outputLen = encoding.GetByteCount(s);
if (outputLen > bytesRemaining)
{
outputLen = 0;
int chars;
for (chars = 0; chars < s.Length; ++chars)
{
var bytes = encoding.GetByteCount(s, chars, 1);
if (outputLen + bytes <= bytesRemaining)
outputLen += bytes;
else
break;
}
s = s.Substring(0, chars);
}
bytesRemaining -= outputLen;
return s;
}
public static string EncodeString(string s) => s.Replace("\"", "\"\"");
/// <summary>
/// Output a string to the trap file, such that the encoded output does not exceed
/// <paramref name="bytesRemaining"/> bytes.
/// </summary>
/// <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 trapFile, string s, ref int bytesRemaining)
{
WriteString(trapFile, TruncateString(s, ref bytesRemaining));
}
public static void WriteTrapString(this TextWriter trapFile, string s)
{
trapFile.Write('\"');
if (NeedsTruncation(s))
{
// Slow path
var remaining = maxStringBytes;
WriteTruncatedString(trapFile, s, ref remaining);
}
else
{
// Fast path
WriteString(trapFile, s);
}
trapFile.Write('\"');
}
public static void WriteTrapFloat(this TextWriter trapFile, float f)
{
trapFile.Write(f.ToString("F5", System.Globalization.CultureInfo.InvariantCulture)); // Trap importer won't accept ints
}
public static void WriteTuple(this TextWriter trapFile, string name, params object[] @params)
{
trapFile.Write(name);
trapFile.Write('(');
var index = 0;
foreach (var p in @params)
{
trapFile.WriteSeparator(",", ref index);
trapFile.WriteColumn(p);
}
trapFile.WriteLine(')');
}
public static void WriteTuple(this TextWriter trapFile, string name, IEntity p1)
{
trapFile.Write(name);
trapFile.Write('(');
trapFile.WriteColumn(p1);
trapFile.WriteLine(')');
}
public static void WriteTuple(this TextWriter trapFile, string name, IEntity p1, object p2)
{
trapFile.Write(name);
trapFile.Write('(');
trapFile.WriteColumn(p1);
trapFile.Write(',');
trapFile.WriteColumn(p2);
trapFile.WriteLine(')');
}
public static void WriteTuple(this TextWriter trapFile, string name, IEntity p1, object p2, object p3)
{
trapFile.Write(name);
trapFile.Write('(');
trapFile.WriteColumn(p1);
trapFile.Write(',');
trapFile.WriteColumn(p2);
trapFile.Write(',');
trapFile.WriteColumn(p3);
trapFile.WriteLine(')');
}
public static void WriteTuple(this TextWriter trapFile, string name, IEntity p1, object p2, object p3, object p4)
{
trapFile.Write(name);
trapFile.Write('(');
trapFile.WriteColumn(p1);
trapFile.Write(',');
trapFile.WriteColumn(p2);
trapFile.Write(',');
trapFile.WriteColumn(p3);
trapFile.Write(',');
trapFile.WriteColumn(p4);
trapFile.WriteLine(')');
}
/// <summary>
/// Appends a [comma] separated list to a trap builder.
/// </summary>
/// <typeparam name="T">The type of the list.</typeparam>
/// <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 EscapingTextWriter trapFile, string separator, IEnumerable<T> items) where T : IEntity
{
return trapFile.BuildList(separator, items, x => trapFile.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="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 T1 BuildList<T1, T2>(this T1 trapFile, string separator, IEnumerable<T2> items, Action<int, T2> action)
where T1 : TextWriter
{
var first = true;
var i = 0;
foreach (var item in items)
{
if (first)
first = false;
else
trapFile.Write(separator);
action(i++, item);
}
return trapFile;
}
/// <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="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 T1 BuildList<T1, T2>(this T1 trapFile, string separator, IEnumerable<T2> items, Action<T2> action)
where T1 : TextWriter =>
trapFile.BuildList(separator, items, (_, item) => action(item));
}
}

View File

@@ -0,0 +1,28 @@
namespace Semmle.Extraction.CSharp
{
/// <summary>
/// How an entity behaves with respect to .push and .pop
/// </summary>
public enum TrapStackBehaviour
{
/// <summary>
/// The entity must not be extracted inside a .push/.pop
/// </summary>
NoLabel,
/// <summary>
/// The entity defines its own label, creating a .push/.pop
/// </summary>
PushesLabel,
/// <summary>
/// The entity must be extracted inside a .push/.pop
/// </summary>
NeedsLabel,
/// <summary>
/// The entity can be extracted inside or outside of a .push/.pop
/// </summary>
OptionalLabel
}
}

View File

@@ -0,0 +1,484 @@
using System.IO;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Semmle.Util;
using Semmle.Extraction.CSharp.Entities;
using Semmle.Extraction.CSharp.Entities.Expressions;
using Semmle.Extraction.Entities;
using Semmle.Extraction.Kinds;
namespace Semmle.Extraction.CSharp
{
/// <summary>
/// Methods for writing DB tuples.
/// </summary>
///
/// <remarks>
/// The parameters to the tuples are well-typed.
/// </remarks>
internal static class Tuples
{
public static void containerparent(this TextWriter trapFile, Folder parent, IEntity child) =>
trapFile.WriteTuple("containerparent", parent, child);
internal static void extractor_messages(this TextWriter trapFile, ExtractionMessage error, Semmle.Util.Logging.Severity severity, string errorMessage, string entityText, Location location, string stackTrace) =>
trapFile.WriteTuple("extractor_messages", error, (int)severity, "C# extractor", errorMessage, entityText, location, stackTrace);
public static void files(this TextWriter trapFile, Entities.File file, string fullName) =>
trapFile.WriteTuple("files", file, fullName);
internal static void folders(this TextWriter trapFile, Folder folder, string path) =>
trapFile.WriteTuple("folders", folder, path);
public static void locations_default(this TextWriter trapFile, SourceLocation label, Entities.File file, int startLine, int startCol, int endLine, int endCol) =>
trapFile.WriteTuple("locations_default", label, file, startLine, startCol, endLine, endCol);
internal static void assemblies(this TextWriter trapFile, Assembly assembly, Entities.File file, string identifier, string name, string version) =>
trapFile.WriteTuple("assemblies", assembly, file, identifier, name, version);
internal static void accessor_location(this TextWriter trapFile, Accessor accessorKey, Location location) =>
trapFile.WriteTuple("accessor_location", accessorKey, location);
internal static void accessors(this TextWriter trapFile, Accessor accessorKey, int kind, string name, Property propKey, Accessor unboundAccessor) =>
trapFile.WriteTuple("accessors", accessorKey, kind, name, propKey, unboundAccessor);
internal static void init_only_accessors(this TextWriter trapFile, Accessor accessorKey) =>
trapFile.WriteTuple("init_only_accessors", accessorKey);
internal static void array_element_type(this TextWriter trapFile, ArrayType array, int dimension, int rank, Type elementType) =>
trapFile.WriteTuple("array_element_type", array, dimension, rank, elementType);
internal static void attributes(this TextWriter trapFile, Attribute attribute, AttributeKind kind, Type attributeType, IEntity entity) =>
trapFile.WriteTuple("attributes", attribute, kind, attributeType, entity);
internal static void attribute_location(this TextWriter trapFile, Attribute attribute, Location location) =>
trapFile.WriteTuple("attribute_location", attribute, location);
internal static void catch_type(this TextWriter trapFile, Entities.Statements.Catch @catch, Type type, bool explicityCaught) =>
trapFile.WriteTuple("catch_type", @catch, type, explicityCaught ? 1 : 2);
internal static void foreach_stmt_info(this TextWriter trapFile, Entities.Statements.ForEach @foreach, bool isAsync) =>
trapFile.WriteTuple("foreach_stmt_info", @foreach, isAsync ? 2 : 1);
internal static void foreach_stmt_desugar(this TextWriter trapFile, Entities.Statements.ForEach @foreach, IEntity entity,
Entities.Statements.ForEach.ForeachSymbolType type) => trapFile.WriteTuple("foreach_stmt_desugar", @foreach, entity, (int)type);
internal static void commentblock(this TextWriter trapFile, CommentBlock k) =>
trapFile.WriteTuple("commentblock", k);
internal static void commentblock_binding(this TextWriter trapFile, CommentBlock commentBlock, Label entity, CommentBinding binding) =>
trapFile.WriteTuple("commentblock_binding", commentBlock, entity, (int)binding);
internal static void commentblock_child(this TextWriter trapFile, CommentBlock commentBlock, CommentLine commentLine, int child) =>
trapFile.WriteTuple("commentblock_child", commentBlock, commentLine, child);
internal static void commentblock_location(this TextWriter trapFile, CommentBlock k, Location l) =>
trapFile.WriteTuple("commentblock_location", k, l);
internal static void commentline(this TextWriter trapFile, CommentLine commentLine, CommentLineType type, string text, string rawtext) =>
trapFile.WriteTuple("commentline", commentLine, (int)type, text, rawtext);
internal static void commentline_location(this TextWriter trapFile, CommentLine commentLine, Location location) =>
trapFile.WriteTuple("commentline_location", commentLine, location);
internal static void compilation_args(this TextWriter trapFile, Compilation compilation, int index, string arg) =>
trapFile.WriteTuple("compilation_args", compilation, index, arg);
internal static void compilation_expanded_args(this TextWriter trapFile, Compilation compilation, int index, string arg) =>
trapFile.WriteTuple("compilation_expanded_args", compilation, index, arg);
internal static void compilation_info(this TextWriter trapFile, Compilation compilation, string infoKey, string infoValue) =>
trapFile.WriteTuple("compilation_info", compilation, infoKey, infoValue);
internal static void compilation_compiling_files(this TextWriter trapFile, Compilation compilation, int index, Entities.File file) =>
trapFile.WriteTuple("compilation_compiling_files", compilation, index, file);
internal static void compilation_referencing_files(this TextWriter trapFile, Compilation compilation, int index, Entities.File file) =>
trapFile.WriteTuple("compilation_referencing_files", compilation, index, file);
internal static void compilation_finished(this TextWriter trapFile, Compilation compilation, float cpuSeconds, float elapsedSeconds) =>
trapFile.WriteTuple("compilation_finished", compilation, cpuSeconds, elapsedSeconds);
internal static void compilation_time(this TextWriter trapFile, Compilation compilation, int num, int index, float metric) =>
trapFile.WriteTuple("compilation_time", compilation, num, index, metric);
internal static void compilations(this TextWriter trapFile, Compilation compilation, string cwd) =>
trapFile.WriteTuple("compilations", compilation, cwd);
internal static void compilation_assembly(this TextWriter trapFile, Compilation compilation, Assembly assembly) =>
trapFile.WriteTuple("compilation_assembly", compilation, assembly);
internal static void compiler_generated(this TextWriter trapFile, IEntity entity) =>
trapFile.WriteTuple("compiler_generated", entity);
internal static void conditional_access(this TextWriter trapFile, Expression access) =>
trapFile.WriteTuple("conditional_access", access);
internal static void constant_value(this TextWriter trapFile, IEntity field, string value) =>
trapFile.WriteTuple("constant_value", field, value);
internal static void constructed_generic(this TextWriter trapFile, IEntity constructedTypeOrMethod, IEntity unboundTypeOrMethod) =>
trapFile.WriteTuple("constructed_generic", constructedTypeOrMethod, unboundTypeOrMethod);
internal static void constructor_location(this TextWriter trapFile, Constructor constructor, Location location) =>
trapFile.WriteTuple("constructor_location", constructor, location);
internal static void constructors(this TextWriter trapFile, Constructor key, string name, Type definingType, Constructor originalDefinition) =>
trapFile.WriteTuple("constructors", key, name, definingType, originalDefinition);
internal static void delegate_return_type(this TextWriter trapFile, Type delegateKey, Type returnType) =>
trapFile.WriteTuple("delegate_return_type", delegateKey, returnType);
internal static void function_pointer_return_type(this TextWriter trapFile, Type functionPointer, Type returnType) =>
trapFile.WriteTuple("function_pointer_return_type", functionPointer, returnType);
internal static void destructor_location(this TextWriter trapFile, Destructor destructor, Location location) =>
trapFile.WriteTuple("destructor_location", destructor, location);
internal static void destructors(this TextWriter trapFile, Destructor destructor, string name, Type containingType, Destructor original) =>
trapFile.WriteTuple("destructors", destructor, name, containingType, original);
internal static void diagnostic_for(this TextWriter trapFile, CompilerDiagnostic diag, Compilation comp, int fileNo, int index) =>
trapFile.WriteTuple("diagnostic_for", diag, comp, fileNo, index);
internal static void diagnostics(this TextWriter trapFile, CompilerDiagnostic diag, int severity, string errorTag, string errorMessage, string fullErrorMessage, Location location) =>
trapFile.WriteTuple("diagnostics", diag, severity, errorTag, errorMessage, fullErrorMessage, location);
internal static void dynamic_member_name(this TextWriter trapFile, Expression e, string name) =>
trapFile.WriteTuple("dynamic_member_name", e, name);
internal static void enum_underlying_type(this TextWriter trapFile, Type @enum, Type type) =>
trapFile.WriteTuple("enum_underlying_type", @enum, type);
internal static void event_accessor_location(this TextWriter trapFile, EventAccessor accessor, Location location) =>
trapFile.WriteTuple("event_accessor_location", accessor, location);
internal static void event_accessors(this TextWriter trapFile, EventAccessor accessorKey, int type, string name, Event eventKey, EventAccessor unboundAccessor) =>
trapFile.WriteTuple("event_accessors", accessorKey, type, name, eventKey, unboundAccessor);
internal static void event_location(this TextWriter trapFile, Event eventKey, Location locationKey) =>
trapFile.WriteTuple("event_location", eventKey, locationKey);
internal static void events(this TextWriter trapFile, Event eventKey, string name, Type declaringType, Type memberType, Event originalDefinition) =>
trapFile.WriteTuple("events", eventKey, name, declaringType, memberType, originalDefinition);
internal static void explicitly_implements(this TextWriter trapFile, IEntity member, Type @interface) =>
trapFile.WriteTuple("explicitly_implements", member, @interface);
internal static void explicitly_sized_array_creation(this TextWriter trapFile, Expression array) =>
trapFile.WriteTuple("explicitly_sized_array_creation", array);
internal static void expr_access(this TextWriter trapFile, Expression expr, IEntity access) =>
trapFile.WriteTuple("expr_access", expr, access);
internal static void expr_argument(this TextWriter trapFile, Expression expr, int mode) =>
trapFile.WriteTuple("expr_argument", expr, mode);
internal static void expr_argument_name(this TextWriter trapFile, Expression expr, string name) =>
trapFile.WriteTuple("expr_argument_name", expr, name);
internal static void expr_call(this TextWriter trapFile, Expression expr, Method target) =>
trapFile.WriteTuple("expr_call", expr, target);
internal static void expr_flowstate(this TextWriter trapFile, Expression expr, int flowState) =>
trapFile.WriteTuple("expr_flowstate", expr, flowState);
internal static void expr_location(this TextWriter trapFile, Expression expr, Location location) =>
trapFile.WriteTuple("expr_location", expr, location);
internal static void expr_parent(this TextWriter trapFile, Expression expr, int child, IExpressionParentEntity parent) =>
trapFile.WriteTuple("expr_parent", expr, child, parent);
internal static void expr_parent_top_level(this TextWriter trapFile, Expression expr, int child, IExpressionParentEntity parent) =>
trapFile.WriteTuple("expr_parent_top_level", expr, child, parent);
internal static void expr_value(this TextWriter trapFile, Expression expr, string value) =>
trapFile.WriteTuple("expr_value", expr, value);
internal static void expressions(this TextWriter trapFile, Expression expr, ExprKind kind, Type exprType) =>
trapFile.WriteTuple("expressions", expr, (int)kind, exprType);
internal static void exprorstmt_name(this TextWriter trapFile, IEntity expr, string name) =>
trapFile.WriteTuple("exprorstmt_name", expr, name);
internal static void extend(this TextWriter trapFile, Type type, Type super) =>
trapFile.WriteTuple("extend", type, super);
internal static void anonymous_types(this TextWriter trapFile, Type type) =>
trapFile.WriteTuple("anonymous_types", type);
internal static void field_location(this TextWriter trapFile, Field field, Location location) =>
trapFile.WriteTuple("field_location", field, location);
internal static void fields(this TextWriter trapFile, Field field, VariableKind kind, string name, Type declaringType, Type fieldType, Field unboundKey) =>
trapFile.WriteTuple("fields", field, (int)kind, name, declaringType, fieldType, unboundKey);
internal static void general_type_parameter_constraints(this TextWriter trapFile, TypeParameterConstraints constraints, int hasKind) =>
trapFile.WriteTuple("general_type_parameter_constraints", constraints, hasKind);
internal static void has_modifiers(this TextWriter trapFile, IEntity entity, Modifier modifier) =>
trapFile.WriteTuple("has_modifiers", entity, modifier);
internal static void implement(this TextWriter trapFile, Type type, Type @interface) =>
trapFile.WriteTuple("implement", type, @interface);
internal static void implicitly_typed_array_creation(this TextWriter trapFile, Expression array) =>
trapFile.WriteTuple("implicitly_typed_array_creation", array);
internal static void implicitly_typed_object_creation(this TextWriter trapFile, Expression expression) =>
trapFile.WriteTuple("implicitly_typed_object_creation", expression);
internal static void indexer_location(this TextWriter trapFile, Indexer indexer, Location location) =>
trapFile.WriteTuple("indexer_location", indexer, location);
internal static void indexers(this TextWriter trapFile, Indexer propKey, string name, Type declaringType, Type memberType, Indexer unboundProperty) =>
trapFile.WriteTuple("indexers", propKey, name, declaringType, memberType, unboundProperty);
internal static void lambda_expr_return_type(this TextWriter trapFile, Lambda expr, Type returnType) =>
trapFile.WriteTuple("lambda_expr_return_type", expr, returnType);
internal static void local_function_stmts(this TextWriter trapFile, Entities.Statements.LocalFunction fnStmt, LocalFunction fn) =>
trapFile.WriteTuple("local_function_stmts", fnStmt, fn);
internal static void local_functions(this TextWriter trapFile, LocalFunction fn, string name, Type returnType, LocalFunction unboundFn) =>
trapFile.WriteTuple("local_functions", fn, name, returnType, unboundFn);
internal static void localvar_location(this TextWriter trapFile, LocalVariable var, Location location) =>
trapFile.WriteTuple("localvar_location", var, location);
internal static void localvars(this TextWriter trapFile, LocalVariable key, VariableKind kind, string name, int @var, Type type, Expression expr) =>
trapFile.WriteTuple("localvars", key, (int)kind, name, @var, type, expr);
internal static void method_location(this TextWriter trapFile, Method method, Location location) =>
trapFile.WriteTuple("method_location", method, location);
internal static void methods(this TextWriter trapFile, Method method, string name, Type declType, Type retType, Method originalDefinition) =>
trapFile.WriteTuple("methods", method, name, declType, retType, originalDefinition);
internal static void modifiers(this TextWriter trapFile, Label entity, string modifier) =>
trapFile.WriteTuple("modifiers", entity, modifier);
internal static void mutator_invocation_mode(this TextWriter trapFile, Expression expr, int mode) =>
trapFile.WriteTuple("mutator_invocation_mode", expr, mode);
internal static void namespace_declaration_location(this TextWriter trapFile, NamespaceDeclaration decl, Location location) =>
trapFile.WriteTuple("namespace_declaration_location", decl, location);
internal static void namespace_declarations(this TextWriter trapFile, NamespaceDeclaration decl, Namespace ns) =>
trapFile.WriteTuple("namespace_declarations", decl, ns);
internal static void namespaces(this TextWriter trapFile, Namespace ns, string name) =>
trapFile.WriteTuple("namespaces", ns, name);
internal static void nested_types(this TextWriter trapFile, Type typeKey, Type declaringTypeKey, Type unboundTypeKey) =>
trapFile.WriteTuple("nested_types", typeKey, declaringTypeKey, unboundTypeKey);
internal static void nullable_underlying_type(this TextWriter trapFile, Type nullableType, Type underlyingType) =>
trapFile.WriteTuple("nullable_underlying_type", nullableType, underlyingType);
internal static void nullability(this TextWriter trapFile, NullabilityEntity nullability, int annotation) =>
trapFile.WriteTuple("nullability", nullability, annotation);
internal static void nullability_parent(this TextWriter trapFile, NullabilityEntity nullability, int index, NullabilityEntity parent) =>
trapFile.WriteTuple("nullability_parent", nullability, index, parent);
internal static void numlines(this TextWriter trapFile, IEntity label, LineCounts lineCounts) =>
trapFile.WriteTuple("numlines", label, lineCounts.Total, lineCounts.Code, lineCounts.Comment);
internal static void operator_location(this TextWriter trapFile, UserOperator @operator, Location location) =>
trapFile.WriteTuple("operator_location", @operator, location);
internal static void operators(this TextWriter trapFile, UserOperator method, string methodName, string symbol, Type classKey, Type returnType, UserOperator originalDefinition) =>
trapFile.WriteTuple("operators", method, methodName, symbol, classKey, returnType, originalDefinition);
internal static void overrides(this TextWriter trapFile, Method overriding, Method overridden) =>
trapFile.WriteTuple("overrides", overriding, overridden);
internal static void param_location(this TextWriter trapFile, Parameter param, Location location) =>
trapFile.WriteTuple("param_location", param, location);
internal static void @params(this TextWriter trapFile, Parameter param, string name, Type type, int child, Parameter.Kind mode, IEntity method, Parameter originalDefinition) =>
trapFile.WriteTuple("params", param, name, type, child, (int)mode, method, originalDefinition);
internal static void parent_namespace(this TextWriter trapFile, IEntity type, Namespace parent) =>
trapFile.WriteTuple("parent_namespace", type, parent);
internal static void parent_namespace_declaration(this TextWriter trapFile, IEntity item, NamespaceDeclaration parent) =>
trapFile.WriteTuple("parent_namespace_declaration", item, parent);
internal static void pointer_referent_type(this TextWriter trapFile, PointerType pointerType, Type referentType) =>
trapFile.WriteTuple("pointer_referent_type", pointerType, referentType);
internal static void property_location(this TextWriter trapFile, Property property, Location location) =>
trapFile.WriteTuple("property_location", property, location);
internal static void properties(this TextWriter trapFile, Property propKey, string name, Type declaringType, Type memberType, Property unboundProperty) =>
trapFile.WriteTuple("properties", propKey, name, declaringType, memberType, unboundProperty);
internal static void statements(this TextWriter trapFile, Statement stmt, StmtKind kind) =>
trapFile.WriteTuple("statements", stmt, (int)kind);
internal static void specific_type_parameter_constraints(this TextWriter trapFile, TypeParameterConstraints constraints, Type baseType) =>
trapFile.WriteTuple("specific_type_parameter_constraints", constraints, baseType);
internal static void specific_type_parameter_nullability(this TextWriter trapFile, TypeParameterConstraints constraints, Type baseType, NullabilityEntity nullability) =>
trapFile.WriteTuple("specific_type_parameter_nullability", constraints, baseType, nullability);
internal static void function_pointer_calling_conventions(this TextWriter trapFile, FunctionPointerType type, int kind) =>
trapFile.WriteTuple("function_pointer_calling_conventions", type, kind);
internal static void has_unmanaged_calling_conventions(this TextWriter trapFile, FunctionPointerType type, int index, Type convention) =>
trapFile.WriteTuple("has_unmanaged_calling_conventions", type, index, convention);
internal static void stackalloc_array_creation(this TextWriter trapFile, Expression array) =>
trapFile.WriteTuple("stackalloc_array_creation", array);
internal static void stmt_location(this TextWriter trapFile, Statement stmt, Location location) =>
trapFile.WriteTuple("stmt_location", stmt, location);
internal static void stmt_parent(this TextWriter trapFile, Statement stmt, int child, IStatementParentEntity parent) =>
trapFile.WriteTuple("stmt_parent", stmt, child, parent);
internal static void stmt_parent_top_level(this TextWriter trapFile, Statement stmt, int child, IStatementParentEntity parent) =>
trapFile.WriteTuple("stmt_parent_top_level", stmt, child, parent);
internal static void tuple_element(this TextWriter trapFile, TupleType type, int index, Field field) =>
trapFile.WriteTuple("tuple_element", type, index, field);
internal static void tuple_underlying_type(this TextWriter trapFile, TupleType type, NamedType underlying) =>
trapFile.WriteTuple("tuple_underlying_type", type, underlying);
internal static void type_annotation(this TextWriter trapFile, IEntity element, Kinds.TypeAnnotation annotation) =>
trapFile.WriteTuple("type_annotation", element, (int)annotation);
internal static void type_arguments(this TextWriter trapFile, Type arg, int n, IEntity typeOrMethod) =>
trapFile.WriteTuple("type_arguments", arg, n, typeOrMethod);
internal static void type_location(this TextWriter trapFile, Type type, Location location) =>
trapFile.WriteTuple("type_location", type, location);
internal static void type_mention(this TextWriter trapFile, TypeMention ta, Type type, IEntity parent) =>
trapFile.WriteTuple("type_mention", ta, type, parent);
internal static void type_mention_location(this TextWriter trapFile, TypeMention ta, Location loc) =>
trapFile.WriteTuple("type_mention_location", ta, loc);
internal static void type_nullability(this TextWriter trapFile, IEntity element, NullabilityEntity nullability) =>
trapFile.WriteTuple("type_nullability", element, nullability);
internal static void type_parameter_constraints(this TextWriter trapFile, TypeParameterConstraints constraints, TypeParameter typeParam) =>
trapFile.WriteTuple("type_parameter_constraints", constraints, typeParam);
internal static void type_parameters(this TextWriter trapFile, TypeParameter param, int child, IEntity typeOrMethod) =>
trapFile.WriteTuple("type_parameters", param, child, typeOrMethod, (int)param.Variance);
internal static void typeref_type(this TextWriter trapFile, NamedTypeRef typeref, Type type) =>
trapFile.WriteTuple("typeref_type", typeref, type);
internal static void typerefs(this TextWriter trapFile, NamedTypeRef type, string name) =>
trapFile.WriteTuple("typerefs", type, name);
internal static void types(this TextWriter trapFile, Type type, TypeKind kind, string name) =>
trapFile.WriteTuple("types", type, (int)kind, name);
internal static void using_namespace_directives(this TextWriter trapFile, UsingDirective @using, Namespace ns) =>
trapFile.WriteTuple("using_namespace_directives", @using, ns);
internal static void using_directive_location(this TextWriter trapFile, UsingDirective @using, Location location) =>
trapFile.WriteTuple("using_directive_location", @using, location);
internal static void using_static_directives(this TextWriter trapFile, UsingDirective @using, Type type) =>
trapFile.WriteTuple("using_static_directives", @using, type);
internal static void using_global(this TextWriter trapFile, UsingDirective @using) =>
trapFile.WriteTuple("using_global", @using);
internal static void preprocessor_directive_location<TDirective>(this TextWriter trapFile,
PreprocessorDirective<TDirective> directive, Location location)
where TDirective : DirectiveTriviaSyntax =>
trapFile.WriteTuple("preprocessor_directive_location", directive, location);
internal static void preprocessor_directive_compilation<TDirective>(this TextWriter trapFile,
PreprocessorDirective<TDirective> directive, Compilation compilation)
where TDirective : DirectiveTriviaSyntax =>
trapFile.WriteTuple("preprocessor_directive_compilation", directive, compilation);
internal static void preprocessor_directive_active<TDirective>(this TextWriter trapFile,
PreprocessorDirective<TDirective> directive, bool isActive)
where TDirective : DirectiveTriviaSyntax =>
trapFile.WriteTuple("preprocessor_directive_active", directive, isActive ? 1 : 0);
internal static void pragma_warnings(this TextWriter trapFile, PragmaWarningDirective pragma, int kind) =>
trapFile.WriteTuple("pragma_warnings", pragma, kind);
internal static void pragma_warning_error_codes(this TextWriter trapFile, PragmaWarningDirective pragma, string errorCode, int child) =>
trapFile.WriteTuple("pragma_warning_error_codes", pragma, errorCode, child);
internal static void pragma_checksums(this TextWriter trapFile, PragmaChecksumDirective pragma, Entities.File file, string guid, string bytes) =>
trapFile.WriteTuple("pragma_checksums", pragma, file, guid, bytes);
internal static void directive_defines(this TextWriter trapFile, DefineDirective directive, string name) =>
trapFile.WriteTuple("directive_defines", directive, name);
internal static void directive_undefines(this TextWriter trapFile, UndefineDirective directive, string name) =>
trapFile.WriteTuple("directive_undefines", directive, name);
internal static void directive_warnings(this TextWriter trapFile, WarningDirective directive, string message) =>
trapFile.WriteTuple("directive_warnings", directive, message);
internal static void directive_errors(this TextWriter trapFile, ErrorDirective directive, string message) =>
trapFile.WriteTuple("directive_errors", directive, message);
internal static void directive_nullables(this TextWriter trapFile, NullableDirective directive, int setting, int target) =>
trapFile.WriteTuple("directive_nullables", directive, setting, target);
internal static void directive_lines<T>(this TextWriter trapFile, LineOrSpanDirective<T> directive, LineDirectiveKind kind) where T : LineOrSpanDirectiveTriviaSyntax =>
trapFile.WriteTuple("directive_lines", directive, (int)kind);
internal static void directive_line_value(this TextWriter trapFile, LineDirective directive, int line) =>
trapFile.WriteTuple("directive_line_value", directive, line);
internal static void directive_line_file<T>(this TextWriter trapFile, LineOrSpanDirective<T> directive, Entities.File file) where T : LineOrSpanDirectiveTriviaSyntax =>
trapFile.WriteTuple("directive_line_file", directive, file);
internal static void directive_line_offset(this TextWriter trapFile, LineSpanDirective directive, int offset) =>
trapFile.WriteTuple("directive_line_offset", directive, offset);
internal static void directive_line_span(this TextWriter trapFile, LineSpanDirective directive, int startLine, int startColumn, int endLine, int endColumn) =>
trapFile.WriteTuple("directive_line_span", directive, startLine, startColumn, endLine, endColumn);
internal static void directive_regions(this TextWriter trapFile, RegionDirective directive, string name) =>
trapFile.WriteTuple("directive_regions", directive, name);
internal static void directive_endregions(this TextWriter trapFile, EndRegionDirective directive, RegionDirective start) =>
trapFile.WriteTuple("directive_endregions", directive, start);
internal static void regions(this TextWriter trapFile, RegionDirective start, EndRegionDirective end) =>
trapFile.WriteTuple("regions", start, end);
internal static void directive_ifs(this TextWriter trapFile, IfDirective directive, bool branchTaken, bool conditionValue) =>
trapFile.WriteTuple("directive_ifs", directive, branchTaken ? 1 : 0, conditionValue ? 1 : 0);
internal static void directive_elifs(this TextWriter trapFile, ElifDirective directive, bool branchTaken, bool conditionValue,
IfDirective start, int index) =>
trapFile.WriteTuple("directive_elifs", directive, branchTaken ? 1 : 0, conditionValue ? 1 : 0, start, index);
internal static void directive_elses(this TextWriter trapFile, ElseDirective directive, bool branchTaken,
IfDirective start, int index) =>
trapFile.WriteTuple("directive_elses", directive, branchTaken ? 1 : 0, start, index);
internal static void directive_endifs(this TextWriter trapFile, EndIfDirective directive, IfDirective start) =>
trapFile.WriteTuple("directive_endifs", directive, start);
internal static void directive_define_symbols(this TextWriter trapFile, DefineSymbol symb, string name) =>
trapFile.WriteTuple("directive_define_symbols", symb, name);
internal static void locations_mapped(this System.IO.TextWriter trapFile, NonGeneratedSourceLocation l1, Location l2) =>
trapFile.WriteTuple("locations_mapped", l1, l2);
internal static void file_extraction_mode(this System.IO.TextWriter trapFile, Entities.File file, ExtractorMode mode) =>
trapFile.WriteTuple("file_extraction_mode", file, mode);
internal static void scoped_annotation(this TextWriter trapFile, IEntity element, ScopedAnnotation @scoped) =>
trapFile.WriteTuple("scoped_annotation", element, (int)@scoped);
}
}