~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to contrib/ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
                        MethodDefinition oldCurrentMethod = context.CurrentMethod;
59
59
                        Debug.Assert(oldCurrentMethod == null || oldCurrentMethod == methodDef);
60
60
                        context.CurrentMethod = methodDef;
 
61
                        context.CurrentMethodIsAsync = false;
61
62
                        try {
62
63
                                AstMethodBodyBuilder builder = new AstMethodBodyBuilder();
63
64
                                builder.methodDef = methodDef;
175
176
                                };
176
177
                        } else if (node is ILSwitch) {
177
178
                                ILSwitch ilSwitch = (ILSwitch)node;
178
 
                                if (TypeAnalysis.IsBoolean(ilSwitch.Condition.InferredType) && ilSwitch.CaseBlocks.SelectMany(cb => cb.Values).Any(val => val != 0 && val != 1)) {
 
179
                                if (TypeAnalysis.IsBoolean(ilSwitch.Condition.InferredType) && (
 
180
                                        from cb in ilSwitch.CaseBlocks
 
181
                                        where cb.Values != null
 
182
                                        from val in cb.Values
 
183
                                        select val
 
184
                                ).Any(val => val != 0 && val != 1))
 
185
                                {
179
186
                                        // If switch cases contain values other then 0 and 1, force the condition to be non-boolean
180
187
                                        ilSwitch.Condition.ExpectedType = typeSystem.Int32;
181
188
                                }
525
532
                                case ILCode.Conv_Ovf_U2_Un:
526
533
                                case ILCode.Conv_Ovf_U4_Un:
527
534
                                case ILCode.Conv_Ovf_U8_Un:
 
535
                                case ILCode.Conv_Ovf_I:
 
536
                                case ILCode.Conv_Ovf_U:
 
537
                                case ILCode.Conv_Ovf_I_Un:
 
538
                                case ILCode.Conv_Ovf_U_Un:
528
539
                                        {
529
540
                                                // conversion was handled by Convert() function using the info from type analysis
530
541
                                                CastExpression cast = arg1 as CastExpression;
533
544
                                                }
534
545
                                                return arg1;
535
546
                                        }
536
 
                                        case ILCode.Conv_Ovf_I:     return arg1.CastTo(new MemberType(new SimpleType ("System"), "IntPtr")); // TODO
537
 
                                        case ILCode.Conv_Ovf_U:     return arg1.CastTo(new MemberType(new SimpleType ("System"), "UIntPtr"));
538
 
                                        case ILCode.Conv_Ovf_I_Un:  return arg1.CastTo(new MemberType(new SimpleType ("System"), "IntPtr"));
539
 
                                        case ILCode.Conv_Ovf_U_Un:  return arg1.CastTo(new MemberType(new SimpleType ("System"), "UIntPtr"));
540
 
                                        case ILCode.Castclass:      return arg1.CastTo(operandAsTypeRef);
541
547
                                case ILCode.Unbox_Any:
542
548
                                        // unboxing does not require a cast if the argument was an isinst instruction
543
549
                                        if (arg1 is AsExpression && byteCode.Arguments[0].Code == ILCode.Isinst && TypeAnalysis.IsSameType(operand as TypeReference, byteCode.Arguments[0].Operand as TypeReference))
544
550
                                                return arg1;
545
551
                                        else
 
552
                                                goto case ILCode.Castclass;
 
553
                                case ILCode.Castclass:
 
554
                                        if ((byteCode.Arguments[0].InferredType != null && byteCode.Arguments[0].InferredType.IsGenericParameter) || ((Cecil.TypeReference)operand).IsGenericParameter)
 
555
                                                return arg1.CastTo(new PrimitiveType("object")).CastTo(operandAsTypeRef);
 
556
                                        else
546
557
                                                return arg1.CastTo(operandAsTypeRef);
547
558
                                case ILCode.Isinst:
548
559
                                        return arg1.CastAs(operandAsTypeRef);
837
848
                                case ILCode.ExpressionTreeParameterDeclarations:
838
849
                                        args[args.Count - 1].AddAnnotation(new ParameterDeclarationAnnotation(byteCode));
839
850
                                        return args[args.Count - 1];
 
851
                                case ILCode.Await:
 
852
                                        return new UnaryOperatorExpression(UnaryOperatorType.Await, arg1);
840
853
                                case ILCode.NullableOf:
841
 
                                        case ILCode.ValueOf: return arg1;
 
854
                                case ILCode.ValueOf: 
 
855
                                        return arg1;
842
856
                                default:
843
857
                                        throw new Exception("Unknown OpCode: " + byteCode.Code);
844
858
                        }