示例#1
0
文件: convert.cs 项目: ArildF/masters
 internal static Type ToType(IReflect ir){
   if (ir is Type)
     return (Type)ir;
   if (ir is ClassScope)
     return ((ClassScope)ir).GetTypeBuilderOrEnumBuilder();
   if (ir is TypedArray){
     return ((TypedArray)ir).ToType();
   }
   if (ir is ScriptFunction)
     return Typeob.ScriptFunction;
   return ir.GetType();
 }
示例#2
0
 internal static Type ToType(TypeReferences typeRefs, IReflect ir){
   if (ir is Type)
     return (Type)ir;
   if (ir is ClassScope)
     return ((ClassScope)ir).GetTypeBuilderOrEnumBuilder();
   if (ir is TypedArray){
     return typeRefs.ToReferenceContext(((TypedArray)ir).ToType());
   }
   if (ir is ScriptFunction)
     return typeRefs.ScriptFunction;
   return typeRefs.ToReferenceContext(ir.GetType());
 }
示例#3
0
文件: convert.cs 项目: ArildF/masters
 internal static bool IsPromotableTo(IReflect source_ir, IReflect target_ir){
   Type target_type;
   if (source_ir is TypedArray || target_ir is TypedArray ||
       source_ir is ArrayObject || target_ir is ArrayObject ||
       source_ir == Typeob.ArrayObject || target_ir == Typeob.ArrayObject)
     return Convert.IsPromotableToArray(source_ir, target_ir);
   if (target_ir is ClassScope){
     if (((ClassScope)target_ir).owner is EnumDeclaration){
       if (Convert.IsPrimitiveNumericType(source_ir))
         return IsPromotableTo(source_ir, ((EnumDeclaration)((ClassScope)target_ir).owner).baseType.ToType());
       else if (source_ir == Typeob.String) return true;
       else if (source_ir == target_ir) return true;
       return false;
     }
     if (source_ir is ClassScope)
       return (((ClassScope)source_ir).IsSameOrDerivedFrom((ClassScope)target_ir));
     return false; //The source is not in the same compilation unit. Thus it can only extend the target type if there is a circular dependency and separate compilation. Can't handle that.
   }else if (target_ir is Type){
     if (target_ir == Typeob.Object) return !(source_ir is Type) || !((Type)source_ir).IsByRef;
     target_type = (Type)target_ir;
   }else if (target_ir is ScriptFunction)
     target_type = Typeob.ScriptFunction;
   else
     //assert that target_ir is JSObject
     target_type = target_ir.GetType();
   if (source_ir is ClassScope)
     return ((ClassScope)source_ir).IsPromotableTo(target_type);
   else
     return IsPromotableTo(source_ir is Type ? (Type)source_ir : source_ir.GetType(), target_type);
 }
 internal static bool IsPromotableTo(IReflect source_ir, IReflect target_ir)
 {
     Type scriptFunction;
     if ((((source_ir is TypedArray) || (target_ir is TypedArray)) || ((source_ir is ArrayObject) || (target_ir is ArrayObject))) || ((source_ir == Typeob.ArrayObject) || (target_ir == Typeob.ArrayObject)))
     {
         return IsPromotableToArray(source_ir, target_ir);
     }
     if (target_ir is ClassScope)
     {
         if (((ClassScope) target_ir).owner is EnumDeclaration)
         {
             if (IsPrimitiveNumericType(source_ir))
             {
                 return IsPromotableTo(source_ir, ((EnumDeclaration) ((ClassScope) target_ir).owner).baseType.ToType());
             }
             return ((source_ir == Typeob.String) || (source_ir == target_ir));
         }
         return ((source_ir is ClassScope) && ((ClassScope) source_ir).IsSameOrDerivedFrom((ClassScope) target_ir));
     }
     if (target_ir is Type)
     {
         if (target_ir == Typeob.Object)
         {
             if (source_ir is Type)
             {
                 return !((Type) source_ir).IsByRef;
             }
             return true;
         }
         scriptFunction = (Type) target_ir;
     }
     else if (target_ir is ScriptFunction)
     {
         scriptFunction = Typeob.ScriptFunction;
     }
     else
     {
         scriptFunction = Globals.TypeRefs.ToReferenceContext(target_ir.GetType());
     }
     if (source_ir is ClassScope)
     {
         return ((ClassScope) source_ir).IsPromotableTo(scriptFunction);
     }
     return IsPromotableTo((source_ir is Type) ? ((Type) source_ir) : Globals.TypeRefs.ToReferenceContext(source_ir.GetType()), scriptFunction);
 }