40 Commits
Author SHA1 Message Date
Daniel Grunwald c4e181505c Prepare for a split of StackType.O into StackType.Obj and StackType.VT: the easy cases 2026-09-05 22:11:12 +02:00
Daniel Grunwald 5526400b17 Extend InferType() to every ILInstruction
Change InferType() to an abstract method and implement for every ILInstruction.
With this change, we now always have enough information to create a variable of an appropriate type to store the result of evaluating the instruction.
This previously was not the case for instructions producing "other value type", for which the stacktype-based fallback incorrectly produced `object`.
2026-08-30 21:25:45 +02:00
Daniel Grunwald cf4dba7015 Always pass the type system into InferType(). 2026-08-30 19:18:47 +02:00
Siegfried Pammer cd212ea05f Pass the compilation to ILInstruction.CheckInvariant
Invariants that involve types (stack type of a variable against its IType,
the element type of an array access, the operand types of a comparison)
need a type system to resolve them against, and the only correct one is the
type system the instruction tree was decoded with. Until now CheckInvariant
took only the phase, so such a check had no compilation to use:
DeconstructInstruction.CheckInvariant called IsAssignment with a null type
system, which only held up because the targets it sees are ldloc, whose
InferType never touches the compilation; a ldflda-wrapped or pointer target
would have failed inside the invariant instead of reporting a violation.

Every call site already has that type system in scope: the ILReader's
compilation, the ILTransformContext of the running transform, or the
decompiler's own IDecompilerTypeSystem. It is now passed explicitly and the
base implementation asserts it is present, so a future invariant can rely
on it without re-plumbing the callers.

Assisted-by: Claude:claude-fable-5:Claude Code
2026-08-30 12:43:40 +02:00
Siegfried Pammer 468e3da92c Bracket ILAst WriteTo in one place via WriteToCore
The debug-step node bracket (MarkNodeStart/try/finally/MarkNodeEnd) was copied
into every hand-written WriteTo override and re-emitted by the T4 generator, so
a newly added instruction could silently omit it and lose step highlighting with
no compile error or test failure. Seal WriteTo on ILInstruction to apply the
bracket once and delegate to a new abstract WriteToCore; move every override
(hand-written and generated) to WriteToCore without the wrapper. Rendered output
is unchanged -- the marks are no-ops unless the output tracks nodes.

Assisted-by: Claude:claude-opus-4-8:Claude Code
2026-07-02 01:08:51 +02:00
Siegfried Pammer 04505bbdf2 Highlight and scroll to the changed instruction in the ILAst view
The C# debug-steps view highlights and centers the exact AST node a
transform changed; the ILAst view already had the step tree and
replay-at-step but produced no highlight. Bring it to parity.

IL rendering has no token-writer seam like the C# output visitor, so
per-instruction text spans are recorded by bracketing
ILInstruction.WriteTo via a new INodeTrackingOutput. The dominant
inst.ReplaceWith(newInst) transform pattern detaches the instruction
passed to Step, so ILTransformContext gains EndStep to record the
produced instruction; Stepper additionally records the position's
ancestor chain as fallback candidates before the step-limit throw, so
the "show state before" view -- which halts at the selected step --
still resolves to a surviving ancestor (ultimately the ILFunction).
The highlight-range resolver is shared with the C# language.

Assisted-by: Claude:claude-opus-4-8:Claude Code
2026-07-02 01:08:51 +02:00
Siegfried PammerandClaude Opus 4.7 a541fc0ddf Fix CS9336 precedence bug in CompoundAssignmentInstruction.
The C# 9 IntPtr / UIntPtr guard in IsBinaryCompatibleWithType read

    type.Kind is not TypeKind.NInt or TypeKind.NUInt

which parses as `(is not NInt) or (is NUInt)` — true unless
Kind == NInt. The intent (per the surrounding comment "but not nint
or C# 11 IntPtr") is "Kind is neither NInt nor NUInt", which needs
parentheses around the alternation:

    type.Kind is not (TypeKind.NInt or TypeKind.NUInt)

Effect: when Kind == NUInt the branch no longer mistakenly applies
the C# 9 IntPtr-only restrictions (suppressing compound assignment
without nint, disallowing shifts).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
2026-05-08 21:23:04 +02:00
Siegfried Pammer 77d9ee73e9 Fix IDE2000 globally 2025-12-29 19:24:31 +01:00
Peter Crabtree e1e16b64f5 dev: Strip BOM mark from text files 2025-08-28 20:56:19 -04:00
Daniel Grunwald b80d20b15d Add support for calling operator checked. 2023-06-03 18:37:15 +02:00
Daniel Grunwald 8b9ba20847 Builtin unsigned right shift operator. 2023-06-03 13:26:09 +02:00
Daniel Grunwald 5fb2f7a22f #nullable enable for ILAst (except for generated code) 2021-06-03 21:36:12 +02:00
dotnet format 0d9f871a4f #2128: Reformat the whole code base. 2020-08-28 01:05:38 +02:00
Daniel Grunwald 1d684102ac Support compound assignment for native integers. 2020-07-14 00:44:35 +02:00
Siegfried Pammer e211b01595 Fix CA1507:UseNameofInPlaceOfString, adjust formatting of some older source files copied from NRefactory. 2019-11-04 20:40:21 +01:00
Daniel Grunwald f2151972a0 Redesign CompoundAssignmentInstruction to support an 'Address' mode where we don't implicitly turn an LdObj into an StObj, but instead directly operate on an address.
This means we can get rid of the special case in TransformDisplayClassUsage, as compound.assign can now also be used with the address of a local variable.
2019-07-16 00:11:08 +02:00
Daniel Grunwald a6def4cdf5 Fix incorrect type for numeric.compound.assign when the pointer type is incompatible with the store type.
Closes #1511, #1530, #1533.
2019-07-13 23:08:30 +02:00
Daniel Grunwald 961923f4fd #1499, #1240: Translate pointer arithmetic on managed pointers (ref T) using the System.Runtime.CompilerServices.Unsafe intrinsics 2019-04-28 20:22:48 +02:00
Siegfried Pammer c1fca21e8a Make ILRange field private - introduce public API for IL range manipulation. 2019-02-16 20:36:17 +01:00
Daniel Grunwald 12e74daf48 Handle Comp in InferType(). 2018-10-14 18:09:28 +02:00
Daniel Grunwald 33ef82f75c Fix #1082: Add support for compound assignment with string.Concat().
Currently only supports the binary overloads of string.Concat().
2018-07-13 21:12:16 +02:00
Siegfried Pammer c4f41f459f Add support for more dynamic binary operators. 2018-06-04 22:14:29 +02:00
Siegfried Pammer 0bb71f469d Add DynamicCompoundAssign instruction 2018-06-01 20:14:22 +02:00
Daniel Grunwald f021ec4383 NumericCompoundAssign: implement ILiftableInstruction 2018-05-10 16:39:29 +02:00
Daniel Grunwald 3956fa685d Refactor TransformAssignment to reduce code duplication. 2018-05-10 16:19:06 +02:00
Siegfried Pammer 845c620a9f Implement UserDefinedCompoundAssign
rename CompoundAssignmentInstruction -> NumericCompoundAssign
2018-05-09 21:33:10 +02:00
Daniel Grunwald 75a627d40b Don't use compound assignment when the RHS value does not fit into the LHS type. 2018-05-05 23:40:12 +02:00
Daniel Grunwald b9337c6129 Fix #1021: Compound assignments on pointer types. 2018-03-10 23:58:24 +01:00
Daniel Grunwald 4c5f0b7e9c Convert TransformAssignment into a statement transform and add support for inline property assignments. 2017-11-01 16:31:59 +01:00
Daniel Grunwald 40a4f08a8d Add support for compound assignment of short integers. 2017-11-01 13:49:55 +01:00
Daniel Grunwald 248a9ad76f Fix #954: don't use invalid compound assignments on enums 2017-11-01 03:31:19 +01:00
Siegfried Pammer 5fec6bd7f7 Implement Interval.WriteTo extension method on ILAst 2017-10-14 16:00:01 +02:00
Daniel Grunwald 39bb6856b7 Fix various bugs with compound assignments. 2017-10-01 21:15:32 +02:00
Daniel Grunwald 61900e33c3 [nullables] Lifted compound assignments 2017-10-01 21:15:31 +02:00
Daniel Grunwald 66d1b744c3 Add ILAstWritingOptions parameter to ILInstruction.WriteTo(). 2017-09-23 14:54:18 +02:00
Siegfried Pammer 840ec04fde Namespace adjustments for Syntax classes 2016-11-26 12:06:58 +01:00
Christoph Wille 1ce8349dd9 Adjust namespaces 2016-11-26 11:12:53 +01:00
Daniel Grunwald 421ad617f8 Fix MayThrow flag on BinaryNumericInstruction 2016-07-25 18:23:24 +02:00
Siegfried Pammer 1d92df7723 Add HasTypeOperand to CompoundAssignmentInstruction 2016-07-25 14:25:14 +09:00
Siegfried Pammer ae75c57e22 Basic implementation of CompoundAssignmentInstruction 2016-07-14 16:41:34 +09:00