| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library universe; | 5 library universe; |
| 6 | 6 |
| 7 import '../closure.dart'; | 7 import '../closure.dart'; |
| 8 import '../elements/elements.dart'; | 8 import '../elements/elements.dart'; |
| 9 import '../dart2jslib.dart'; | 9 import '../dart2jslib.dart'; |
| 10 import '../tree/tree.dart'; | 10 import '../tree/tree.dart'; |
| 11 import '../util/util.dart'; | 11 import '../util/util.dart'; |
| 12 import '../js/js.dart' as js; |
| 12 | 13 |
| 13 part 'function_set.dart'; | 14 part 'function_set.dart'; |
| 14 part 'partial_type_tree.dart'; | 15 part 'partial_type_tree.dart'; |
| 15 part 'selector_map.dart'; | 16 part 'selector_map.dart'; |
| 16 | 17 |
| 17 class Universe { | 18 class Universe { |
| 18 /** | 19 /** |
| 19 * Documentation wanted -- johnniwinther | 20 * Documentation wanted -- johnniwinther |
| 20 * | 21 * |
| 21 * Invariant: Key elements are declaration elements. | 22 * Invariant: Key elements are declaration elements. |
| 22 */ | 23 */ |
| 23 Map<Element, CodeBuffer> generatedCode; | 24 Map<Element, js.Expression> generatedCode; |
| 24 | 25 |
| 25 /** | 26 /** |
| 26 * Documentation wanted -- johnniwinther | 27 * Documentation wanted -- johnniwinther |
| 27 * | 28 * |
| 28 * Invariant: Key elements are declaration elements. | 29 * Invariant: Key elements are declaration elements. |
| 29 */ | 30 */ |
| 30 Map<Element, CodeBuffer> generatedBailoutCode; | 31 Map<Element, js.Expression> generatedBailoutCode; |
| 31 | 32 |
| 32 /** | 33 /** |
| 33 * Documentation wanted -- johnniwinther | 34 * Documentation wanted -- johnniwinther |
| 34 * | 35 * |
| 35 * Invariant: Elements are declaration elements. | 36 * Invariant: Elements are declaration elements. |
| 36 */ | 37 */ |
| 37 // TODO(karlklose): these sets should be merged. | 38 // TODO(karlklose): these sets should be merged. |
| 38 final Set<ClassElement> instantiatedClasses; | 39 final Set<ClassElement> instantiatedClasses; |
| 39 final Set<DartType> instantiatedTypes; | 40 final Set<DartType> instantiatedTypes; |
| 40 | 41 |
| 41 /** | 42 /** |
| 42 * Documentation wanted -- johnniwinther | 43 * Documentation wanted -- johnniwinther |
| 43 * | 44 * |
| 44 * Invariant: Elements are declaration elements. | 45 * Invariant: Elements are declaration elements. |
| 45 */ | 46 */ |
| 46 final Set<FunctionElement> staticFunctionsNeedingGetter; | 47 final Set<FunctionElement> staticFunctionsNeedingGetter; |
| 47 final Map<SourceString, Set<Selector>> invokedNames; | 48 final Map<SourceString, Set<Selector>> invokedNames; |
| 48 final Map<SourceString, Set<Selector>> invokedGetters; | 49 final Map<SourceString, Set<Selector>> invokedGetters; |
| 49 final Map<SourceString, Set<Selector>> invokedSetters; | 50 final Map<SourceString, Set<Selector>> invokedSetters; |
| 50 final Map<SourceString, Set<Selector>> fieldGetters; | 51 final Map<SourceString, Set<Selector>> fieldGetters; |
| 51 final Map<SourceString, Set<Selector>> fieldSetters; | 52 final Map<SourceString, Set<Selector>> fieldSetters; |
| 52 final Set<DartType> isChecks; | 53 final Set<DartType> isChecks; |
| 53 | 54 |
| 54 Universe() : generatedCode = new Map<Element, CodeBuffer>(), | 55 Universe() : generatedCode = new Map<Element, js.Expression>(), |
| 55 generatedBailoutCode = new Map<Element, CodeBuffer>(), | 56 generatedBailoutCode = new Map<Element, js.Expression>(), |
| 56 instantiatedClasses = new Set<ClassElement>(), | 57 instantiatedClasses = new Set<ClassElement>(), |
| 57 instantiatedTypes = new Set<DartType>(), | 58 instantiatedTypes = new Set<DartType>(), |
| 58 staticFunctionsNeedingGetter = new Set<FunctionElement>(), | 59 staticFunctionsNeedingGetter = new Set<FunctionElement>(), |
| 59 invokedNames = new Map<SourceString, Set<Selector>>(), | 60 invokedNames = new Map<SourceString, Set<Selector>>(), |
| 60 invokedGetters = new Map<SourceString, Set<Selector>>(), | 61 invokedGetters = new Map<SourceString, Set<Selector>>(), |
| 61 invokedSetters = new Map<SourceString, Set<Selector>>(), | 62 invokedSetters = new Map<SourceString, Set<Selector>>(), |
| 62 fieldGetters = new Map<SourceString, Set<Selector>>(), | 63 fieldGetters = new Map<SourceString, Set<Selector>>(), |
| 63 fieldSetters = new Map<SourceString, Set<Selector>>(), | 64 fieldSetters = new Map<SourceString, Set<Selector>>(), |
| 64 isChecks = new Set<DartType>(); | 65 isChecks = new Set<DartType>(); |
| 65 | 66 |
| 66 void addGeneratedCode(WorkItem work, CodeBuffer codeBuffer) { | 67 void addGeneratedCode(WorkItem work, js.Expression code) { |
| 67 assert(invariant(work.element, work.element.isDeclaration)); | 68 assert(invariant(work.element, work.element.isDeclaration)); |
| 68 generatedCode[work.element] = codeBuffer; | 69 generatedCode[work.element] = code; |
| 69 } | 70 } |
| 70 | 71 |
| 71 void addBailoutCode(WorkItem work, CodeBuffer codeBuffer) { | 72 void addBailoutCode(WorkItem work, js.Expression code) { |
| 72 assert(invariant(work.element, work.element.isDeclaration)); | 73 assert(invariant(work.element, work.element.isDeclaration)); |
| 73 generatedBailoutCode[work.element] = codeBuffer; | 74 generatedBailoutCode[work.element] = code; |
| 74 } | 75 } |
| 75 | 76 |
| 76 bool hasMatchingSelector(Set<Selector> selectors, | 77 bool hasMatchingSelector(Set<Selector> selectors, |
| 77 Element member, | 78 Element member, |
| 78 Compiler compiler) { | 79 Compiler compiler) { |
| 79 if (selectors == null) return false; | 80 if (selectors == null) return false; |
| 80 for (Selector selector in selectors) { | 81 for (Selector selector in selectors) { |
| 81 if (selector.applies(member, compiler)) return true; | 82 if (selector.applies(member, compiler)) return true; |
| 82 } | 83 } |
| 83 return false; | 84 return false; |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 ClassElement cls = self; | 465 ClassElement cls = self; |
| 465 if (cls.isSubclassOf(other)) { | 466 if (cls.isSubclassOf(other)) { |
| 466 // Resolve an invocation of [element.name] on [self]. If it | 467 // Resolve an invocation of [element.name] on [self]. If it |
| 467 // is found, this selector is a candidate. | 468 // is found, this selector is a candidate. |
| 468 return hasElementIn(self, element) && appliesUntyped(element, compiler); | 469 return hasElementIn(self, element) && appliesUntyped(element, compiler); |
| 469 } | 470 } |
| 470 | 471 |
| 471 return false; | 472 return false; |
| 472 } | 473 } |
| 473 } | 474 } |
| OLD | NEW |