diff --git a/Shockky.SourceGeneration.Tests/InstructionGeneratorTests.cs b/Shockky.SourceGeneration.Tests/InstructionGeneratorTests.cs index 6317251..55a24a0 100644 --- a/Shockky.SourceGeneration.Tests/InstructionGeneratorTests.cs +++ b/Shockky.SourceGeneration.Tests/InstructionGeneratorTests.cs @@ -20,7 +20,7 @@ public enum OPCode : byte [OP] Return = 0x01, } """; - string expected = """ + string expectedSyntaxForReturn = """ namespace Shockky.Lingo.Instructions; [global::System.CodeDom.Compiler.GeneratedCode("InstructionGenerator", )] @@ -33,12 +33,11 @@ public sealed class Return : IInstruction /// public OPCode OP => OPCode.Return; + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + [global::System.Diagnostics.DebuggerBrowsable(global::System.Diagnostics.DebuggerBrowsableState.Never)] public int Immediate { get; set; } - public int GetSize() - { - return sizeof(OPCode); - } + public int GetSize() => sizeof(OPCode); public void WriteTo(global::Shockky.IO.ShockwaveWriter output) { @@ -49,7 +48,7 @@ public void WriteTo(global::Shockky.IO.ShockwaveWriter output) VerifyGenerateSources(source, [new InstructionGenerator()], - ("Shockky.Lingo.Instructions.Return.g.cs", expected)); + ("Shockky.Lingo.Instructions.Return.g.cs", expectedSyntaxForReturn)); } [Fact] @@ -98,7 +97,7 @@ public void WriteTo(global::Shockky.IO.ShockwaveWriter output) output.Write(op + 0x40); output.Write((ushort)Immediate); } - else + else { output.Write(op + 0x80); output.Write(Immediate); diff --git a/Shockky.SourceGeneration/InstructionGenerator.cs b/Shockky.SourceGeneration/InstructionGenerator.cs index 61a213e..3f13a74 100644 --- a/Shockky.SourceGeneration/InstructionGenerator.cs +++ b/Shockky.SourceGeneration/InstructionGenerator.cs @@ -127,25 +127,32 @@ internal static void WriteInstructionSyntax(IndentedTextWriter writer, writer.WriteLine($$""" /// public OPCode OP => OPCode.{{instruction.Name}}; - - public int Immediate { get; set; } """, true); + writer.WriteLine(); + + // If the OP has no immediate, hide it from debugger and editor on the concrete implementation. + if (!hasImmediate) + { + writer.WriteLine("[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]"); + writer.WriteLine("[global::System.Diagnostics.DebuggerBrowsable(global::System.Diagnostics.DebuggerBrowsableState.Never)]"); + } + writer.WriteLine("public int Immediate { get; set; }"); writer.WriteLine(); - writer.WriteLine("public int GetSize()"); - using (var getSizeBlock = writer.WriteBlock()) + + if (hasImmediate) { - if (hasImmediate) - { - writer.WriteLine(""" + writer.WriteLine(""" + public int GetSize() + { uint imm = (uint)Immediate; if (imm <= byte.MaxValue) return sizeof(OPCode) + 1; else if (imm <= ushort.MaxValue) return sizeof(OPCode) + 2; else return sizeof(OPCode) + 4; - """, true); - } - else writer.WriteLine("return sizeof(OPCode);"); + } + """, true); } + else writer.WriteLine("public int GetSize() => sizeof(OPCode);"); writer.WriteLine(); writer.WriteLine("public void WriteTo(global::Shockky.IO.ShockwaveWriter output)");