GetUnderlyingTypeIfEnum() private method

private GetUnderlyingTypeIfEnum ( ) : IReflect
return IReflect
Beispiel #1
0
        internal override AST PartiallyEvaluate()
        {
            if (this.alreadyPartiallyEvaluated)
            {
                return(this);
            }
            this.alreadyPartiallyEvaluated = true;
            if (this.inBrackets && this.AllParamsAreMissing())
            {
                if (this.isConstructor)
                {
                    this.args.context.HandleError(JSError.TypeMismatch);
                }
                return(new ConstantWrapper(new TypedArray(((TypeExpression) new TypeExpression(this.func).PartiallyEvaluate()).ToIReflect(), this.args.count + 1), base.context));
            }
            this.func = this.func.PartiallyEvaluateAsCallable();
            this.args = (ASTList)this.args.PartiallyEvaluate();
            IReflect[] argIRs = this.ArgIRs();
            this.func.ResolveCall(this.args, argIRs, this.isConstructor, this.inBrackets);
            if ((!this.isConstructor && !this.inBrackets) && ((this.func is Binding) && (this.args.count == 1)))
            {
                Binding func = (Binding)this.func;
                if (func.member is Type)
                {
                    Type            member  = (Type)func.member;
                    ConstantWrapper wrapper = this.args[0] as ConstantWrapper;
                    if (wrapper != null)
                    {
                        try
                        {
                            if ((wrapper.value == null) || (wrapper.value is DBNull))
                            {
                                return(this);
                            }
                            if (wrapper.isNumericLiteral && (((member == Typeob.Decimal) || (member == Typeob.Int64)) || ((member == Typeob.UInt64) || (member == Typeob.Single))))
                            {
                                return(new ConstantWrapper(Microsoft.JScript.Convert.CoerceT(wrapper.context.GetCode(), member, true), base.context));
                            }
                            return(new ConstantWrapper(Microsoft.JScript.Convert.CoerceT(wrapper.Evaluate(), member, true), base.context));
                        }
                        catch
                        {
                            wrapper.context.HandleError(JSError.TypeMismatch);
                            goto Label_0354;
                        }
                    }
                    if (!Binding.AssignmentCompatible(member, this.args[0], argIRs[0], false))
                    {
                        this.args[0].context.HandleError(JSError.ImpossibleConversion);
                    }
                }
                else if (func.member is JSVariableField)
                {
                    JSVariableField field = (JSVariableField)func.member;
                    if (field.IsLiteral)
                    {
                        if (field.value is ClassScope)
                        {
                            ClassScope scope = (ClassScope)field.value;
                            IReflect   underlyingTypeIfEnum = scope.GetUnderlyingTypeIfEnum();
                            if (underlyingTypeIfEnum != null)
                            {
                                if ((!Microsoft.JScript.Convert.IsPromotableTo(argIRs[0], underlyingTypeIfEnum) && !Microsoft.JScript.Convert.IsPromotableTo(underlyingTypeIfEnum, argIRs[0])) && ((argIRs[0] != Typeob.String) || (underlyingTypeIfEnum == scope)))
                                {
                                    this.args[0].context.HandleError(JSError.ImpossibleConversion);
                                }
                            }
                            else if (!Microsoft.JScript.Convert.IsPromotableTo(argIRs[0], scope) && !Microsoft.JScript.Convert.IsPromotableTo(scope, argIRs[0]))
                            {
                                this.args[0].context.HandleError(JSError.ImpossibleConversion);
                            }
                        }
                        else if (field.value is TypedArray)
                        {
                            TypedArray array = (TypedArray)field.value;
                            if (!Microsoft.JScript.Convert.IsPromotableTo(argIRs[0], array) && !Microsoft.JScript.Convert.IsPromotableTo(array, argIRs[0]))
                            {
                                this.args[0].context.HandleError(JSError.ImpossibleConversion);
                            }
                        }
                    }
                }
            }
Label_0354:
            return(this);
        }
Beispiel #2
0
 internal override AST PartiallyEvaluate()
 {
     if (this.alreadyPartiallyEvaluated)
     {
         return(this);
     }
     this.alreadyPartiallyEvaluated = true;
     if (this.inBrackets && this.AllParamsAreMissing())
     {
         if (this.isConstructor)
         {
             this.args.context.HandleError(JSError.TypeMismatch);
         }
         IReflect ir = ((TypeExpression)(new TypeExpression(this.func)).PartiallyEvaluate()).ToIReflect();
         return(new ConstantWrapper(new TypedArray(ir, this.args.count + 1), this.context));
     }
     this.func = this.func.PartiallyEvaluateAsCallable();
     this.args = (ASTList)this.args.PartiallyEvaluate();
     IReflect[] argIRs = this.ArgIRs();
     this.func.ResolveCall(this.args, argIRs, this.isConstructor, this.inBrackets);
     if (!this.isConstructor && !this.inBrackets && this.func is Binding && this.args.count == 1)
     {
         Binding b = (Binding)this.func;
         if (b.member is Type)
         {
             Type            t    = (Type)b.member;
             ConstantWrapper arg0 = this.args[0] as ConstantWrapper;
             if (arg0 != null)
             {
                 try{
                     if (arg0.value == null || arg0.value is DBNull)
                     {
                         return(this);
                     }
                     else if (arg0.isNumericLiteral && (t == Typeob.Decimal || t == Typeob.Int64 || t == Typeob.UInt64 || t == Typeob.Single))
                     {
                         return(new ConstantWrapper(Convert.CoerceT(arg0.context.GetCode(), t, true), this.context));
                     }
                     else
                     {
                         return(new ConstantWrapper(Convert.CoerceT(arg0.Evaluate(), t, true), this.context));
                     }
                 }catch {
                     arg0.context.HandleError(JSError.TypeMismatch);
                 }
             }
             else
             {
                 if (!Binding.AssignmentCompatible(t, this.args[0], argIRs[0], false))
                 {
                     this.args[0].context.HandleError(JSError.ImpossibleConversion);
                 }
             }
         }
         else if (b.member is JSVariableField)
         {
             JSVariableField field = (JSVariableField)b.member;
             if (field.IsLiteral)
             {
                 if (field.value is ClassScope)
                 {
                     ClassScope csc = (ClassScope)field.value;
                     IReflect   ut  = csc.GetUnderlyingTypeIfEnum();
                     if (ut != null)
                     {
                         if (!Convert.IsPromotableTo(argIRs[0], ut) && !Convert.IsPromotableTo(ut, argIRs[0]) && (argIRs[0] != Typeob.String || ut == csc))
                         {
                             this.args[0].context.HandleError(JSError.ImpossibleConversion);
                         }
                     }
                     else
                     {
                         if (!Convert.IsPromotableTo(argIRs[0], csc) && !Convert.IsPromotableTo(csc, argIRs[0]))
                         {
                             this.args[0].context.HandleError(JSError.ImpossibleConversion);
                         }
                     }
                 }
                 else if (field.value is TypedArray)
                 {
                     TypedArray ta = (TypedArray)field.value;
                     if (!Convert.IsPromotableTo(argIRs[0], ta) && !Convert.IsPromotableTo(ta, argIRs[0]))
                     {
                         this.args[0].context.HandleError(JSError.ImpossibleConversion);
                     }
                 }
             }
         }
     }
     return(this);
 }