| 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 class Universe { | 5 class Universe { |
| 6 int nextFreeClassId = 0; |
| 6 Map<Element, String> generatedCode; | 7 Map<Element, String> generatedCode; |
| 7 Map<Element, String> generatedBailoutCode; | 8 Map<Element, String> generatedBailoutCode; |
| 8 final Set<ClassElement> instantiatedClasses; | 9 final Set<ClassElement> instantiatedClasses; |
| 9 final Set<SourceString> instantiatedClassInstanceFields; | 10 final Set<SourceString> instantiatedClassInstanceFields; |
| 10 final Set<FunctionElement> staticFunctionsNeedingGetter; | 11 final Set<FunctionElement> staticFunctionsNeedingGetter; |
| 11 final Map<SourceString, Set<Selector>> invokedNames; | 12 final Map<SourceString, Set<Selector>> invokedNames; |
| 12 final Map<SourceString, Set<Selector>> invokedGetters; | 13 final Map<SourceString, Set<Selector>> invokedGetters; |
| 13 final Map<SourceString, Set<Selector>> invokedSetters; | 14 final Map<SourceString, Set<Selector>> invokedSetters; |
| 14 final Map<String, LibraryElement> libraries; | 15 final Map<String, LibraryElement> libraries; |
| 15 // TODO(ngeoffray): This should be a Set<Type>. | 16 // TODO(ngeoffray): This should be a Set<Type>. |
| 16 final Set<Element> isChecks; | 17 final Set<Element> isChecks; |
| 17 final RuntimeTypeInformation rti; | 18 final RuntimeTypeInformation rti; |
| 18 | 19 |
| 19 Universe() : generatedCode = new Map<Element, String>(), | 20 Universe() : generatedCode = new Map<Element, String>(), |
| 20 generatedBailoutCode = new Map<Element, String>(), | 21 generatedBailoutCode = new Map<Element, String>(), |
| 21 libraries = new Map<String, LibraryElement>(), | 22 libraries = new Map<String, LibraryElement>(), |
| 22 instantiatedClasses = new Set<ClassElement>(), | 23 instantiatedClasses = new Set<ClassElement>(), |
| 23 instantiatedClassInstanceFields = new Set<SourceString>(), | 24 instantiatedClassInstanceFields = new Set<SourceString>(), |
| 24 staticFunctionsNeedingGetter = new Set<FunctionElement>(), | 25 staticFunctionsNeedingGetter = new Set<FunctionElement>(), |
| 25 invokedNames = new Map<SourceString, Set<Selector>>(), | 26 invokedNames = new Map<SourceString, Set<Selector>>(), |
| 26 invokedGetters = new Map<SourceString, Set<Selector>>(), | 27 invokedGetters = new Map<SourceString, Set<Selector>>(), |
| 27 invokedSetters = new Map<SourceString, Set<Selector>>(), | 28 invokedSetters = new Map<SourceString, Set<Selector>>(), |
| 28 isChecks = new Set<Element>(), | 29 isChecks = new Set<Element>(), |
| 29 rti = new RuntimeTypeInformation(); | 30 rti = new RuntimeTypeInformation(); |
| 30 | 31 |
| 32 int getNextFreeClassId() => nextFreeClassId++; |
| 33 |
| 31 void addGeneratedCode(WorkItem work, String code) { | 34 void addGeneratedCode(WorkItem work, String code) { |
| 32 generatedCode[work.element] = code; | 35 generatedCode[work.element] = code; |
| 33 } | 36 } |
| 34 | 37 |
| 35 void addBailoutCode(WorkItem work, String code) { | 38 void addBailoutCode(WorkItem work, String code) { |
| 36 generatedBailoutCode[work.element] = code; | 39 generatedBailoutCode[work.element] = code; |
| 37 } | 40 } |
| 38 | 41 |
| 39 bool hasMatchingSelector(Set<Selector> selectors, | 42 bool hasMatchingSelector(Set<Selector> selectors, |
| 40 Element member, | 43 Element member, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 52 } | 55 } |
| 53 | 56 |
| 54 bool hasGetter(Element member, Compiler compiler) { | 57 bool hasGetter(Element member, Compiler compiler) { |
| 55 return hasMatchingSelector( | 58 return hasMatchingSelector( |
| 56 compiler.universe.invokedGetters[member.name], member, compiler); | 59 compiler.universe.invokedGetters[member.name], member, compiler); |
| 57 } | 60 } |
| 58 | 61 |
| 59 bool hasSetter(Element member, Compiler compiler) { | 62 bool hasSetter(Element member, Compiler compiler) { |
| 60 return hasMatchingSelector( | 63 return hasMatchingSelector( |
| 61 compiler.universe.invokedSetters[member.name], member, compiler); | 64 compiler.universe.invokedSetters[member.name], member, compiler); |
| 62 } | 65 } |
| 63 } | 66 } |
| 64 | 67 |
| 65 class SelectorKind { | 68 class SelectorKind { |
| 66 final String name; | 69 final String name; |
| 67 const SelectorKind(this.name); | 70 const SelectorKind(this.name); |
| 68 | 71 |
| 69 static final SelectorKind GETTER = const SelectorKind('getter'); | 72 static final SelectorKind GETTER = const SelectorKind('getter'); |
| 70 static final SelectorKind SETTER = const SelectorKind('setter'); | 73 static final SelectorKind SETTER = const SelectorKind('setter'); |
| 71 static final SelectorKind INVOCATION = const SelectorKind('invocation'); | 74 static final SelectorKind INVOCATION = const SelectorKind('invocation'); |
| 72 static final SelectorKind OPERATOR = const SelectorKind('operator'); | 75 static final SelectorKind OPERATOR = const SelectorKind('operator'); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 88 Selector( | 91 Selector( |
| 89 this.kind, | 92 this.kind, |
| 90 this.argumentCount, | 93 this.argumentCount, |
| 91 [List<SourceString> namedArguments = const <SourceString>[]]) | 94 [List<SourceString> namedArguments = const <SourceString>[]]) |
| 92 : this.namedArguments = namedArguments, | 95 : this.namedArguments = namedArguments, |
| 93 this.orderedNamedArguments = namedArguments.isEmpty() | 96 this.orderedNamedArguments = namedArguments.isEmpty() |
| 94 ? namedArguments | 97 ? namedArguments |
| 95 : <SourceString>[]; | 98 : <SourceString>[]; |
| 96 | 99 |
| 97 Selector.invocation( | 100 Selector.invocation( |
| 98 int argumentCount, | 101 int argumentCount, |
| 99 [List<SourceString> namedArguments = const <SourceString>[]]) | 102 [List<SourceString> namedArguments = const <SourceString>[]]) |
| 100 : this(SelectorKind.INVOCATION, argumentCount, namedArguments); | 103 : this(SelectorKind.INVOCATION, argumentCount, namedArguments); |
| 101 | 104 |
| 102 int hashCode() => argumentCount + 1000 * namedArguments.length; | 105 int hashCode() => argumentCount + 1000 * namedArguments.length; |
| 103 int get namedArgumentCount() => namedArguments.length; | 106 int get namedArgumentCount() => namedArguments.length; |
| 104 int get positionalArgumentCount() => argumentCount - namedArgumentCount; | 107 int get positionalArgumentCount() => argumentCount - namedArgumentCount; |
| 105 | 108 |
| 106 static final Selector GETTER = | 109 static final Selector GETTER = |
| 107 const Selector.constant(SelectorKind.GETTER, 0); | 110 const Selector.constant(SelectorKind.GETTER, 0); |
| 108 static final Selector SETTER = | 111 static final Selector SETTER = |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 for (int i = 0; i < namedArguments.length; i++) { | 239 for (int i = 0; i < namedArguments.length; i++) { |
| 237 SourceString name = namedArguments[i]; | 240 SourceString name = namedArguments[i]; |
| 238 if (name == parameter.name) { | 241 if (name == parameter.name) { |
| 239 foundIndex = i; | 242 foundIndex = i; |
| 240 break; | 243 break; |
| 241 } | 244 } |
| 242 } | 245 } |
| 243 if (foundIndex != -1) { | 246 if (foundIndex != -1) { |
| 244 list.add(compiledNamedArguments[foundIndex]); | 247 list.add(compiledNamedArguments[foundIndex]); |
| 245 } else { | 248 } else { |
| 246 list.add(compileConstant(parameter)); | 249 list.add(compileConstant(parameter)); |
| 247 } | 250 } |
| 248 } | 251 } |
| 249 return true; | 252 return true; |
| 250 } | 253 } |
| 251 | 254 |
| 252 static bool sameNames(List<SourceString> first, List<SourceString> second) { | 255 static bool sameNames(List<SourceString> first, List<SourceString> second) { |
| 253 for (int i = 0; i < first.length; i++) { | 256 for (int i = 0; i < first.length; i++) { |
| 254 if (first[i] != second[i]) return false; | 257 if (first[i] != second[i]) return false; |
| 255 } | 258 } |
| 256 return true; | 259 return true; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 | 341 |
| 339 return false; | 342 return false; |
| 340 } | 343 } |
| 341 | 344 |
| 342 bool operator ==(other) { | 345 bool operator ==(other) { |
| 343 if (other is !TypedSelector) return false; | 346 if (other is !TypedSelector) return false; |
| 344 if (other.receiverType !== receiverType) return false; | 347 if (other.receiverType !== receiverType) return false; |
| 345 return super == other; | 348 return super == other; |
| 346 } | 349 } |
| 347 } | 350 } |
| OLD | NEW |