You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some IL instructions are classified as "patterns".
abstractclassPatternMatchILInstruction:IStoreInstruction{publicILInstructionTestedOperand{get;}publicILVariableVariable{get;}// variable that receives the match result; may also be a temporary}publicboolIsPattern(thisILInstructioninst,outILInstructiontestedOperand)=>instswitch{PatternMatchILInstructionpm=>testedOperand=pm.TestedOperand;returntrue;LogicNot logicNot =>IsPattern(logicNot.Operand,outtestedOperand),Comp comp =>testedOperand=comp.Left;return IsConstant(comp.Right);}
Every match.* instruction has the following properties:
The TestedOperand specifies what gets matched against the pattern.
The Variable stores the value of TestedOperand (after converting to the matched type, if appropriate).
If this variable is also used outside the match.* node, it corresponds to the C# single_variable_designation.
Otherwise it's a temporary used for pattern matching.
I think in both cases it should have VariableKind.PatternVar
The match instruction evaluates to StackType.I4: 1 if the pattern was matched, 0 otherwise.
Some match instructions have a body with List<ILInstruction> nestedPatterns. Here every nested pattern must be a pattern according to IsPattern(), and the testedOperand of each must be a member of the Variable of the parent pattern. (members are: field, property, or deconstruction.result).
(exception: match.and/match.or, these instead require the testedOperand to be exactly the Variable of the parent pattern)
Examples
expr is var x
=> match.var(x = expr)
=>
Block (VarPattern) {
stloc x(expr) // single eval expr
final: ldc.i4 1 // match always
}
ILAst Pattern Matching
Some IL instructions are classified as "patterns".
Every
match.*
instruction has the following properties:TestedOperand
specifies what gets matched against the pattern.Variable
stores the value ofTestedOperand
(after converting to the matched type, if appropriate).match.*
node, it corresponds to the C#single_variable_designation
.StackType.I4
: 1 if the pattern was matched, 0 otherwise.Some
match
instructions have a body withList<ILInstruction> nestedPatterns
. Here every nested pattern must be a pattern according toIsPattern()
, and thetestedOperand
of each must be a member of theVariable
of the parent pattern. (members are: field, property, or deconstruction.result).(exception:
match.and
/match.or
, these instead require thetestedOperand
to be exactly theVariable
of the parent pattern)Examples
expr is var x
=>
match.var(x = expr)
=>
expr is T x
=>
match.type T(x = expr) {}
=>
expr is C { A: var x } z
=>
=>
expr is C { A: var x, B: 42, C: { A: 4 } } z
=>
=>
expr is C(var x, var y, <4) { ... }
=>
expr is C(1, D(2, 3))
=>
x is >= 0 and var y and <= 100
x is not C _
=>
expr is (var a, var b)
(when expr is object)=>
expr is (var a, var b)
(when expr is ValueTuple<int, int>)=>
The text was updated successfully, but these errors were encountered: