| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 part of ssa; | |
| 6 | |
| 7 class TypeMaskFactory { | |
| 8 static TypeMask fromInferredType(TypeMask mask, Compiler compiler) { | |
| 9 JavaScriptBackend backend = compiler.backend; | |
| 10 if (mask == null) return backend.dynamicType; | |
| 11 return mask; | |
| 12 } | |
| 13 | |
| 14 static TypeMask inferredReturnTypeForElement( | |
| 15 Element element, Compiler compiler) { | |
| 16 return fromInferredType( | |
| 17 compiler.typesTask.getGuaranteedReturnTypeOfElement(element), | |
| 18 compiler); | |
| 19 } | |
| 20 | |
| 21 static TypeMask inferredTypeForElement(Element element, Compiler compiler) { | |
| 22 return fromInferredType( | |
| 23 compiler.typesTask.getGuaranteedTypeOfElement(element), | |
| 24 compiler); | |
| 25 } | |
| 26 | |
| 27 static TypeMask inferredTypeForSelector(Selector selector, Compiler compiler)
{ | |
| 28 return fromInferredType( | |
| 29 compiler.typesTask.getGuaranteedTypeOfSelector(selector), | |
| 30 compiler); | |
| 31 } | |
| 32 | |
| 33 static TypeMask inferredForNode(Element owner, ast.Node node, | |
| 34 Compiler compiler) { | |
| 35 return fromInferredType( | |
| 36 compiler.typesTask.getGuaranteedTypeOfNode(owner, node), | |
| 37 compiler); | |
| 38 } | |
| 39 | |
| 40 static TypeMask fromNativeBehavior(native.NativeBehavior nativeBehavior, | |
| 41 Compiler compiler) { | |
| 42 ClassWorld classWorld = compiler.world; | |
| 43 JavaScriptBackend backend = compiler.backend; | |
| 44 if (nativeBehavior.typesReturned.isEmpty) return backend.dynamicType; | |
| 45 | |
| 46 TypeMask result = nativeBehavior.typesReturned | |
| 47 .map((type) => fromNativeType(type, compiler)) | |
| 48 .reduce((t1, t2) => t1.union(t2, classWorld)); | |
| 49 assert(!(result.isEmpty && !result.isNullable)); | |
| 50 return result; | |
| 51 } | |
| 52 | |
| 53 // [type] is either an instance of [DartType] or special objects | |
| 54 // like [native.SpecialType.JsObject]. | |
| 55 static TypeMask fromNativeType(type, Compiler compiler) { | |
| 56 ClassWorld classWorld = compiler.world; | |
| 57 JavaScriptBackend backend = compiler.backend; | |
| 58 if (type == native.SpecialType.JsObject) { | |
| 59 return new TypeMask.nonNullExact(compiler.objectClass, classWorld); | |
| 60 } else if (type.isVoid) { | |
| 61 return backend.nullType; | |
| 62 } else if (type.element == compiler.nullClass) { | |
| 63 return backend.nullType; | |
| 64 } else if (type.treatAsDynamic) { | |
| 65 return backend.dynamicType; | |
| 66 } else { | |
| 67 return new TypeMask.nonNullSubtype(type.element, classWorld); | |
| 68 } | |
| 69 } | |
| 70 } | |
| OLD | NEW |