Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ TryEmitSwitchInstruction()

bool System.Linq.Expressions.Compiler.LambdaCompiler.TryEmitSwitchInstruction ( SwitchExpression node,
CompilationFlags flags )
inlineprivate

Definition at line 3065 of file LambdaCompiler.cs.

3066 {
3067 if (node.Comparison != null)
3068 {
3069 return false;
3070 }
3071 Type type = node.SwitchValue.Type;
3072 if (!CanOptimizeSwitchType(type) || !TypeUtils.AreEquivalent(type, node.Cases[0].TestValues[0].Type))
3073 {
3074 return false;
3075 }
3076 if (!node.Cases.All((SwitchCase c) => c.TestValues.All((Expression t) => t is ConstantExpression)))
3077 {
3078 return false;
3079 }
3080 Label[] array = new Label[node.Cases.Count];
3081 bool[] array2 = new bool[node.Cases.Count];
3084 for (int i = 0; i < node.Cases.Count; i++)
3085 {
3086 DefineSwitchCaseLabel(node.Cases[i], out array[i], out array2[i]);
3087 foreach (ConstantExpression testValue in node.Cases[i].TestValues)
3088 {
3089 decimal num = ConvertSwitchValue(testValue.Value);
3090 if (hashSet.Add(num))
3091 {
3092 list.Add(new SwitchLabel(num, testValue.Value, array[i]));
3093 }
3094 }
3095 }
3096 list.Sort((SwitchLabel x, SwitchLabel y) => Math.Sign(x.Key - y.Key));
3098 foreach (SwitchLabel item in list)
3099 {
3101 }
3102 LocalBuilder local = GetLocal(node.SwitchValue.Type);
3103 EmitExpression(node.SwitchValue);
3106 Label @default = ((node.DefaultBody == null) ? label : _ilg.DefineLabel());
3107 SwitchInfo info = new SwitchInfo(node, local, @default);
3109 EmitSwitchCases(node, array, array2, @default, label, flags);
3111 return true;
3112 }
void Add(TKey key, TValue value)
static bool AreEquivalent(Type t1, Type t2)
Definition TypeUtils.cs:664
void EmitSwitchBuckets(SwitchInfo info, List< List< SwitchLabel > > buckets, int first, int last)
static void AddToBuckets(List< List< SwitchLabel > > buckets, SwitchLabel key)
void DefineSwitchCaseLabel(SwitchCase @case, out Label label, out bool isGoto)
void EmitSwitchCases(SwitchExpression node, Label[] labels, bool[] isGoto, Label @default, Label end, CompilationFlags flags)
virtual void Emit(OpCode opcode)
static readonly OpCode Stloc
Definition OpCodes.cs:429

References System.Linq.Expressions.Compiler.LambdaCompiler._ilg, System.Collections.Generic.Dictionary< TKey, TValue >.Add(), System.Linq.Expressions.Compiler.LambdaCompiler.AddToBuckets(), System.Dynamic.Utils.TypeUtils.AreEquivalent(), System.array, System.Linq.Expressions.Compiler.LambdaCompiler.CanOptimizeSwitchType(), System.Linq.Expressions.Compiler.LambdaCompiler.ConvertSwitchValue(), System.Collections.Generic.Dictionary< TKey, TValue >.Count, System.Reflection.Emit.ILGenerator.DefineLabel(), System.Linq.Expressions.Compiler.LambdaCompiler.DefineSwitchCaseLabel(), System.Reflection.Emit.ILGenerator.Emit(), System.Linq.Expressions.Compiler.LambdaCompiler.EmitExpression(), System.Linq.Expressions.Compiler.LambdaCompiler.EmitSwitchBuckets(), System.Linq.Expressions.Compiler.LambdaCompiler.EmitSwitchCases(), System.Linq.Expressions.Compiler.LambdaCompiler.FreeLocal(), System.Linq.Expressions.Compiler.LambdaCompiler.GetLocal(), System.info, System.item, System.Linq.Expressions.Compiler.LambdaCompiler.SwitchLabel.Key, System.list, System.Math.Sign(), System.Reflection.Emit.OpCodes.Stloc, System.Linq.Expressions.SwitchCase.TestValues, and System.type.

Referenced by System.Linq.Expressions.Compiler.LambdaCompiler.EmitSwitchExpression().