Skip to content

Commit

Permalink
Fix opcode typos in xml docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ltrzesniewski committed Nov 16, 2024
1 parent a7bd763 commit baecf8f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
22 changes: 11 additions & 11 deletions src/InlineIL/IL.Emit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static void Ldloc_3()
=> IL.Throw();

/// <summary>
/// <c>stloc.0</c> - Pops the current value from the top of the evaluation stack and stores it in a the local variable list at index 0.
/// <c>stloc.0</c> - Pops the current value from the top of the evaluation stack and stores it in the local variable list at index 0.
/// </summary>
/// <remarks>
/// <para>Stack Transition: ..., value -&gt; ...</para>
Expand All @@ -123,7 +123,7 @@ public static void Stloc_0()
=> IL.Throw();

/// <summary>
/// <c>stloc.1</c> - Pops the current value from the top of the evaluation stack and stores it in a the local variable list at index 1.
/// <c>stloc.1</c> - Pops the current value from the top of the evaluation stack and stores it in the local variable list at index 1.
/// </summary>
/// <remarks>
/// <para>Stack Transition: ..., value -&gt; ...</para>
Expand All @@ -132,7 +132,7 @@ public static void Stloc_1()
=> IL.Throw();

/// <summary>
/// <c>stloc.2</c> - Pops the current value from the top of the evaluation stack and stores it in a the local variable list at index 2.
/// <c>stloc.2</c> - Pops the current value from the top of the evaluation stack and stores it in the local variable list at index 2.
/// </summary>
/// <remarks>
/// <para>Stack Transition: ..., value -&gt; ...</para>
Expand All @@ -141,7 +141,7 @@ public static void Stloc_2()
=> IL.Throw();

/// <summary>
/// <c>stloc.3</c> - Pops the current value from the top of the evaluation stack and stores it in a the local variable list at index 3.
/// <c>stloc.3</c> - Pops the current value from the top of the evaluation stack and stores it in the local variable list at index 3.
/// </summary>
/// <remarks>
/// <para>Stack Transition: ..., value -&gt; ...</para>
Expand Down Expand Up @@ -250,7 +250,7 @@ public static void Ldloca_S(byte index)
=> IL.Throw();

/// <summary>
/// <c>stloc.s</c> - Pops the current value from the top of the evaluation stack and stores it in a the local variable list at index (short form).
/// <c>stloc.s</c> - Pops the current value from the top of the evaluation stack and stores it in the local variable list at index (short form).
/// </summary>
/// <remarks>
/// <para>Stack Transition: ..., value -&gt; ...</para>
Expand All @@ -260,7 +260,7 @@ public static void Stloc_S(string name)
=> IL.Throw();

/// <summary>
/// <c>stloc.s</c> - Pops the current value from the top of the evaluation stack and stores it in a the local variable list at index (short form).
/// <c>stloc.s</c> - Pops the current value from the top of the evaluation stack and stores it in the local variable list at index (short form).
/// </summary>
/// <remarks>
/// <para>Stack Transition: ..., value -&gt; ...</para>
Expand Down Expand Up @@ -845,7 +845,7 @@ public static void Ldind_Ref()
=> IL.Throw();

/// <summary>
/// <c>stind.ref</c> - Stores a object reference value at a supplied address.
/// <c>stind.ref</c> - Stores an object reference value at a supplied address.
/// </summary>
/// <remarks>
/// <para>Stack Transition: ..., I, I -&gt; ...</para>
Expand Down Expand Up @@ -1841,7 +1841,7 @@ public static void Conv_Ovf_U8()
=> IL.Throw();

/// <summary>
/// <c>refanyval</c> - Retrieves the address (type &amp;) embedded in a typed reference.
/// <c>refanyval</c> - Retrieves the address &#x0028;type &amp;&#x0029; embedded in a typed reference.
/// </summary>
/// <remarks>
/// <para>Stack Transition: ..., value -&gt; ..., I</para>
Expand All @@ -1851,7 +1851,7 @@ public static void Refanyval(TypeRef type)
=> IL.Throw();

/// <summary>
/// <c>refanyval</c> - Retrieves the address (type &amp;) embedded in a typed reference.
/// <c>refanyval</c> - Retrieves the address &#x0028;type &amp;&#x0029; embedded in a typed reference.
/// </summary>
/// <remarks>
/// <para>Stack Transition: ..., value -&gt; ..., I</para>
Expand Down Expand Up @@ -2259,7 +2259,7 @@ public static void Ldloca(ushort index)
=> IL.Throw();

/// <summary>
/// <c>stloc</c> - Pops the current value from the top of the evaluation stack and stores it in a the local variable list at a specified index.
/// <c>stloc</c> - Pops the current value from the top of the evaluation stack and stores it in the local variable list at a specified index.
/// </summary>
/// <remarks>
/// <para>Stack Transition: ..., value -&gt; ...</para>
Expand All @@ -2269,7 +2269,7 @@ public static void Stloc(string name)
=> IL.Throw();

/// <summary>
/// <c>stloc</c> - Pops the current value from the top of the evaluation stack and stores it in a the local variable list at a specified index.
/// <c>stloc</c> - Pops the current value from the top of the evaluation stack and stores it in the local variable list at a specified index.
/// </summary>
/// <remarks>
/// <para>Stack Transition: ..., value -&gt; ...</para>
Expand Down
18 changes: 13 additions & 5 deletions src/InlineIL/IL.Emit.tt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@
.Elements("member")
.ToDictionary(elem => elem.Attribute("name")!.Value, elem => elem);

static string EscapeXml(string value) => value.Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;");
static string EscapeXml(string value)
=> value.Replace("&", "&amp;")
.Replace("<", "&lt;")
.Replace(">", "&gt;");

static string FixTypos(string value)
=> value.Replace(" a the ", " the ")
.Replace(" a object ", " an object ")
.Replace("(type &amp;)", "&#x0028;type &amp;&#x0029;");

string GetInstructionXmlDoc(OpCode opCode)
{
Expand All @@ -40,7 +48,7 @@
var sb = new StringBuilder();
sb.AppendLine("<summary>");
sb.Append("<c>").Append(opCode.Name).Append("</c> - ");
AppendXmlDoc(sb, "F:System.Reflection.Emit.OpCodes." + reflectionEmitCode.fieldName);
AppendXmlDoc(sb, $"F:System.Reflection.Emit.OpCodes.{reflectionEmitCode.fieldName}");
TrimEnd(sb);
sb.AppendLine();
sb.AppendLine("</summary>");
Expand All @@ -53,7 +61,7 @@
);
sb.AppendLine("</remarks>");

return sb.ToString();
return FixTypos(sb.ToString());
}

void AppendXmlDoc(StringBuilder sb, string elementId)
Expand Down Expand Up @@ -99,10 +107,10 @@

static string GetStackTransition(OpCode opCode)
{
if (opCode.StackBehaviourPop == StackBehaviour.Pop0 && opCode.StackBehaviourPush == StackBehaviour.Push0)
if (opCode is { StackBehaviourPop: StackBehaviour.Pop0, StackBehaviourPush: StackBehaviour.Push0 })
return "none";

if (opCode.StackBehaviourPop == StackBehaviour.PopAll && opCode.StackBehaviourPush == StackBehaviour.Push0)
if (opCode is { StackBehaviourPop: StackBehaviour.PopAll, StackBehaviourPush: StackBehaviour.Push0 })
return "clears the stack";

var pop = GetStackBehaviour(opCode, opCode.StackBehaviourPop);
Expand Down

0 comments on commit baecf8f

Please sign in to comment.