Chromium Code Reviews| 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 Map<Element, String> generatedCode; | 6 Map<Element, String> generatedCode; |
| 7 Map<Element, String> generatedBailoutCode; | 7 Map<Element, String> generatedBailoutCode; |
| 8 final Set<ClassElement> instantiatedClasses; | 8 final Set<ClassElement> instantiatedClasses; |
| 9 final Set<SourceString> instantiatedClassInstanceFields; | 9 final Set<SourceString> instantiatedClassInstanceFields; |
| 10 final Set<FunctionElement> staticFunctionsNeedingGetter; | 10 final Set<FunctionElement> staticFunctionsNeedingGetter; |
| 11 final Map<SourceString, Set<Selector>> invokedNames; | 11 final Map<SourceString, Set<Selector>> invokedNames; |
| 12 final Map<SourceString, Set<Selector>> invokedGetters; | 12 final Map<SourceString, Set<Selector>> invokedGetters; |
| 13 final Map<SourceString, Set<Selector>> invokedSetters; | 13 final Map<SourceString, Set<Selector>> invokedSetters; |
| 14 final Map<String, LibraryElement> libraries; | 14 final Map<String, LibraryElement> libraries; |
| 15 // TODO(ngeoffray): This should be a Set<Type>. | 15 // TODO(ngeoffray): This should be a Set<Type>. |
| 16 final Set<Element> isChecks; | 16 final Set<Element> isChecks; |
| 17 final RuntimeTypeInformation rti; | 17 final RuntimeTypeInformation rti; |
| 18 final Map<ClassElement, Set<ClassElement>> subtypes; | |
| 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>(), |
| 30 subtypes = new Map<ClassElement, Set<ClassElement>>(), | |
| 29 rti = new RuntimeTypeInformation(); | 31 rti = new RuntimeTypeInformation(); |
| 30 | 32 |
| 31 void addGeneratedCode(WorkItem work, String code) { | 33 void addGeneratedCode(WorkItem work, String code) { |
| 32 generatedCode[work.element] = code; | 34 generatedCode[work.element] = code; |
| 33 } | 35 } |
| 34 | 36 |
| 35 void addBailoutCode(WorkItem work, String code) { | 37 void addBailoutCode(WorkItem work, String code) { |
| 36 generatedBailoutCode[work.element] = code; | 38 generatedBailoutCode[work.element] = code; |
| 37 } | 39 } |
| 38 | 40 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 52 } | 54 } |
| 53 | 55 |
| 54 bool hasGetter(Element member, Compiler compiler) { | 56 bool hasGetter(Element member, Compiler compiler) { |
| 55 return hasMatchingSelector( | 57 return hasMatchingSelector( |
| 56 compiler.universe.invokedGetters[member.name], member, compiler); | 58 compiler.universe.invokedGetters[member.name], member, compiler); |
| 57 } | 59 } |
| 58 | 60 |
| 59 bool hasSetter(Element member, Compiler compiler) { | 61 bool hasSetter(Element member, Compiler compiler) { |
| 60 return hasMatchingSelector( | 62 return hasMatchingSelector( |
| 61 compiler.universe.invokedSetters[member.name], member, compiler); | 63 compiler.universe.invokedSetters[member.name], member, compiler); |
| 62 } | 64 } |
| 65 | |
| 66 /** | |
| 67 * Returns a [MemberSet] that contains the possible targets of a | |
| 68 * selector named [member] on a receiver whose type is [type]. | |
|
kasperl
2012/05/09 08:04:23
Wouldn't it be more logical to let this be paramet
ngeoffray
2012/05/09 10:07:58
Yes, that's what I started with. But right now, th
| |
| 69 */ | |
| 70 MemberSet memberSetFor(Type type, SourceString member) { | |
| 71 ClassElement cls = type.element; | |
| 72 MemberSet result = new MemberSet(member); | |
| 73 Element element = cls.lookupMember(member); | |
| 74 if (element !== null) result.add(element); | |
| 75 | |
| 76 Set<ClassElement> subtypes = subtypes[cls]; | |
| 77 if (subtypes !== null) { | |
| 78 for (ClassElement sub in subtypes) { | |
| 79 element = sub.lookupLocalMember(member); | |
| 80 if (element !== null) result.add(element); | |
| 81 } | |
| 82 } | |
| 83 return result; | |
| 84 } | |
| 85 } | |
| 86 | |
| 87 /** | |
| 88 * A [MemberSet] contains all the possible targets for a selector. | |
| 89 */ | |
| 90 class MemberSet { | |
| 91 final Set<Element> elements; | |
| 92 final SourceString name; | |
| 93 | |
| 94 MemberSet(SourceString this.name) : elements = new Set<Element>(); | |
| 95 | |
| 96 void add(Element element) { | |
| 97 elements.add(element); | |
| 98 } | |
| 99 | |
| 100 bool isEmpty() => elements.isEmpty(); | |
| 101 | |
| 102 bool hasJustFields() { | |
| 103 return elements.every((Element element) => element.isField()); | |
| 104 } | |
| 63 } | 105 } |
| 64 | 106 |
| 65 class SelectorKind { | 107 class SelectorKind { |
| 66 final String name; | 108 final String name; |
| 67 const SelectorKind(this.name); | 109 const SelectorKind(this.name); |
| 68 | 110 |
| 69 static final SelectorKind GETTER = const SelectorKind('getter'); | 111 static final SelectorKind GETTER = const SelectorKind('getter'); |
| 70 static final SelectorKind SETTER = const SelectorKind('setter'); | 112 static final SelectorKind SETTER = const SelectorKind('setter'); |
| 71 static final SelectorKind INVOCATION = const SelectorKind('invocation'); | 113 static final SelectorKind INVOCATION = const SelectorKind('invocation'); |
| 72 static final SelectorKind OPERATOR = const SelectorKind('operator'); | 114 static final SelectorKind OPERATOR = const SelectorKind('operator'); |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 338 | 380 |
| 339 return false; | 381 return false; |
| 340 } | 382 } |
| 341 | 383 |
| 342 bool operator ==(other) { | 384 bool operator ==(other) { |
| 343 if (other is !TypedSelector) return false; | 385 if (other is !TypedSelector) return false; |
| 344 if (other.receiverType !== receiverType) return false; | 386 if (other.receiverType !== receiverType) return false; |
| 345 return super == other; | 387 return super == other; |
| 346 } | 388 } |
| 347 } | 389 } |
| OLD | NEW |