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, CodeBuffer> generatedCode; | 6 Map<Element, CodeBuffer> generatedCode; |
| 7 Map<Element, CodeBuffer> generatedBailoutCode; | 7 Map<Element, CodeBuffer> 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; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 return hasMatchingSelector(fieldSetters[member.name], member, compiler); | 68 return hasMatchingSelector(fieldSetters[member.name], member, compiler); |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 | 71 |
| 72 class SelectorKind { | 72 class SelectorKind { |
| 73 final String name; | 73 final String name; |
| 74 const SelectorKind(this.name); | 74 const SelectorKind(this.name); |
| 75 | 75 |
| 76 static final SelectorKind GETTER = const SelectorKind('getter'); | 76 static final SelectorKind GETTER = const SelectorKind('getter'); |
| 77 static final SelectorKind SETTER = const SelectorKind('setter'); | 77 static final SelectorKind SETTER = const SelectorKind('setter'); |
| 78 // TODO(kasperl): Rename INVOCATION to CALL and introduce CALL_ANY. | 78 static final SelectorKind CALL = const SelectorKind('call'); |
| 79 static final SelectorKind INVOCATION = const SelectorKind('invocation'); | |
| 80 static final SelectorKind OPERATOR = const SelectorKind('operator'); | 79 static final SelectorKind OPERATOR = const SelectorKind('operator'); |
| 81 static final SelectorKind INDEX = const SelectorKind('index'); | 80 static final SelectorKind INDEX = const SelectorKind('index'); |
| 82 | 81 |
| 83 toString() => name; | 82 toString() => name; |
| 84 } | 83 } |
| 85 | 84 |
| 86 class Selector implements Hashable { | 85 class Selector implements Hashable { |
| 87 final SelectorKind kind; | 86 final SelectorKind kind; |
| 88 final SourceString name; // Name is null for call-any selectors. | 87 final SourceString name; |
| 89 final LibraryElement library; // Library is null for non-private selectors. | 88 final LibraryElement library; // Library is null for non-private selectors. |
|
ahe
2012/08/15 14:32:21
Extra space before //
kasperl
2012/08/16 10:35:47
Done.
| |
| 90 | 89 |
| 91 // The numbers of arguments of the selector. Includes named arguments. | 90 // The numbers of arguments of the selector. Includes named arguments. |
| 92 final int argumentCount; | 91 final int argumentCount; |
| 93 final List<SourceString> namedArguments; | 92 final List<SourceString> namedArguments; |
| 94 final List<SourceString> orderedNamedArguments; | 93 final List<SourceString> orderedNamedArguments; |
| 95 | 94 |
| 96 Selector( | 95 Selector( |
| 97 this.kind, | 96 this.kind, |
| 98 SourceString name, | 97 SourceString name, |
| 99 LibraryElement library, | 98 LibraryElement library, |
| 100 this.argumentCount, | 99 this.argumentCount, |
| 101 [List<SourceString> namedArguments = const <SourceString>[]]) | 100 [List<SourceString> namedArguments = const <SourceString>[]]) |
| 102 : this.name = name, | 101 : this.name = name, |
| 103 this.library = (name != null && name.isPrivate()) ? library : null, | 102 this.library = name.isPrivate() ? library : null, |
| 104 this.namedArguments = namedArguments, | 103 this.namedArguments = namedArguments, |
| 105 this.orderedNamedArguments = namedArguments.isEmpty() | 104 this.orderedNamedArguments = namedArguments.isEmpty() |
| 106 ? namedArguments | 105 ? namedArguments |
| 107 : <SourceString>[] { | 106 : <SourceString>[] { |
| 108 // TODO(kasperl): Only allow null name for call-any selectors. | 107 assert(!name.isPrivate() || library != null); |
| 109 assert(name == null || !name.isPrivate() || library != null); | |
| 110 } | 108 } |
| 111 | 109 |
| 112 Selector.getter(SourceString name, LibraryElement library) | 110 Selector.getter(SourceString name, LibraryElement library) |
| 113 : this(SelectorKind.GETTER, name, library, 0); | 111 : this(SelectorKind.GETTER, name, library, 0); |
| 114 | 112 |
| 113 Selector.getterFrom(Selector selector) | |
| 114 : this(SelectorKind.GETTER, selector.name, selector.library, 0); | |
| 115 | |
| 115 Selector.setter(SourceString name, LibraryElement library) | 116 Selector.setter(SourceString name, LibraryElement library) |
| 116 : this(SelectorKind.SETTER, name, library, 1); | 117 : this(SelectorKind.SETTER, name, library, 1); |
| 117 | 118 |
| 118 Selector.unaryOperator(SourceString name) | 119 Selector.unaryOperator(SourceString name) |
| 119 : this(SelectorKind.OPERATOR, operatorName(name, true), null, 0); | 120 : this(SelectorKind.OPERATOR, operatorName(name, true), null, 0); |
| 120 | 121 |
| 121 Selector.binaryOperator(SourceString name) | 122 Selector.binaryOperator(SourceString name) |
| 122 : this(SelectorKind.OPERATOR, operatorName(name, false), null, 1); | 123 : this(SelectorKind.OPERATOR, operatorName(name, false), null, 1); |
| 123 | 124 |
| 124 Selector.index() | 125 Selector.index() |
| 125 : this(SelectorKind.INDEX, indexName(), null, 1); | 126 : this(SelectorKind.INDEX, indexName(), null, 1); |
| 126 | 127 |
| 127 Selector.indexSet() | 128 Selector.indexSet() |
| 128 : this(SelectorKind.INDEX, indexSetName(), null, 2); | 129 : this(SelectorKind.INDEX, indexSetName(), null, 2); |
| 129 | 130 |
| 130 Selector.call(SourceString name, | 131 Selector.call(SourceString name, |
| 131 LibraryElement library, | 132 LibraryElement library, |
| 132 int arity, | 133 int arity, |
| 133 [List<SourceString> named = const []]) | 134 [List<SourceString> named = const []]) |
| 134 : this(SelectorKind.INVOCATION, name, library, arity, named); | 135 : this(SelectorKind.CALL, name, library, arity, named); |
| 135 | 136 |
| 136 Selector.callAny(int arity, [List<SourceString> named = const []]) | 137 Selector.callClosure(int arity, [List<SourceString> named = const []]) |
| 137 : this(SelectorKind.INVOCATION, null, null, arity, named); | 138 : this(SelectorKind.CALL, Namer.CLOSURE_INVOCATION_NAME, null, |
| 139 arity, named); | |
| 140 | |
| 141 Selector.callClosureFrom(Selector selector) | |
| 142 : this(SelectorKind.CALL, Namer.CLOSURE_INVOCATION_NAME, null, | |
| 143 selector.argumentCount, selector.namedArguments); | |
| 138 | 144 |
| 139 // TODO(kasperl): This belongs somewhere else. | 145 // TODO(kasperl): This belongs somewhere else. |
| 140 Selector.noSuchMethod() | 146 Selector.noSuchMethod() |
| 141 : this(SelectorKind.INVOCATION, Compiler.NO_SUCH_METHOD, null, 2); | 147 : this(SelectorKind.CALL, Compiler.NO_SUCH_METHOD, null, 2); |
| 142 | 148 |
| 143 bool isGetter() => kind === SelectorKind.GETTER; | 149 bool isGetter() => kind === SelectorKind.GETTER; |
| 144 bool isSetter() => kind === SelectorKind.SETTER; | 150 bool isSetter() => kind === SelectorKind.SETTER; |
| 145 bool isCall() => kind === SelectorKind.INVOCATION; | 151 bool isCall() => kind === SelectorKind.CALL; |
| 146 | 152 |
| 147 bool isIndex() => kind === SelectorKind.INDEX && argumentCount == 1; | 153 bool isIndex() => kind === SelectorKind.INDEX && argumentCount == 1; |
| 148 bool isIndexSet() => kind === SelectorKind.INDEX && argumentCount == 2; | 154 bool isIndexSet() => kind === SelectorKind.INDEX && argumentCount == 2; |
| 149 | 155 |
| 150 bool isOperator() => kind === SelectorKind.OPERATOR; | 156 bool isOperator() => kind === SelectorKind.OPERATOR; |
| 151 bool isUnaryOperator() => isOperator() && argumentCount == 0; | 157 bool isUnaryOperator() => isOperator() && argumentCount == 0; |
| 152 bool isBinaryOperator() => isOperator() && argumentCount == 1; | 158 bool isBinaryOperator() => isOperator() && argumentCount == 1; |
| 153 | 159 |
| 154 static SourceString operatorName(SourceString name, bool isUnary) | 160 static SourceString operatorName(SourceString name, bool isUnary) |
| 155 => Elements.constructOperatorName( | 161 => Elements.constructOperatorName( |
| 156 const SourceString('operator'), name, isUnary); | 162 const SourceString('operator'), name, isUnary); |
| 157 | 163 |
| 158 static SourceString indexName() | 164 static SourceString indexName() |
| 159 => operatorName(const SourceString('[]'), false); | 165 => operatorName(const SourceString('[]'), false); |
| 160 | 166 |
| 161 static SourceString indexSetName() | 167 static SourceString indexSetName() |
| 162 => operatorName(const SourceString('[]='), false); | 168 => operatorName(const SourceString('[]='), false); |
| 163 | 169 |
| 164 int hashCode() => argumentCount + 1000 * namedArguments.length; | 170 int hashCode() => argumentCount + 1000 * namedArguments.length; |
| 165 int get namedArgumentCount() => namedArguments.length; | 171 int get namedArgumentCount() => namedArguments.length; |
| 166 int get positionalArgumentCount() => argumentCount - namedArgumentCount; | 172 int get positionalArgumentCount() => argumentCount - namedArgumentCount; |
| 167 Type get receiverType() => null; | 173 Type get receiverType() => null; |
| 168 | 174 |
| 169 bool applies(Element element, Compiler compiler) { | 175 bool applies(Element element, Compiler compiler) { |
| 170 if (element.isSetter()) return kind === SelectorKind.SETTER; | 176 if (element.isSetter()) return isSetter(); |
| 171 if (element.isGetter()) { | 177 if (element.isGetter()) return isGetter() || isCall(); |
| 172 return kind === SelectorKind.GETTER || kind === SelectorKind.INVOCATION; | 178 if (element.isField()) return isGetter() || isSetter() || isCall(); |
| 173 } | 179 if (isGetter()) return true; |
| 174 if (element.isField()) { | |
| 175 return kind === SelectorKind.GETTER | |
| 176 || kind === SelectorKind.INVOCATION | |
| 177 || kind === SelectorKind.SETTER; | |
| 178 } | |
| 179 if (kind === SelectorKind.GETTER) return true; | |
| 180 | 180 |
| 181 FunctionElement function = element; | 181 FunctionElement function = element; |
| 182 FunctionSignature parameters = function.computeSignature(compiler); | 182 FunctionSignature parameters = function.computeSignature(compiler); |
| 183 if (argumentCount > parameters.parameterCount) return false; | 183 if (argumentCount > parameters.parameterCount) return false; |
| 184 int requiredParameterCount = parameters.requiredParameterCount; | 184 int requiredParameterCount = parameters.requiredParameterCount; |
| 185 int optionalParameterCount = parameters.optionalParameterCount; | 185 int optionalParameterCount = parameters.optionalParameterCount; |
| 186 if (positionalArgumentCount < requiredParameterCount) return false; | 186 if (positionalArgumentCount < requiredParameterCount) return false; |
| 187 | 187 |
| 188 bool hasOptionalParameters = !parameters.optionalParameters.isEmpty(); | 188 bool hasOptionalParameters = !parameters.optionalParameters.isEmpty(); |
| 189 if (namedArguments.isEmpty()) { | 189 if (namedArguments.isEmpty()) { |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 377 | 377 |
| 378 if (!self.isInterface() && self.isSubclassOf(other)) { | 378 if (!self.isInterface() && self.isSubclassOf(other)) { |
| 379 // Resolve an invocation of [element.name] on [self]. If it | 379 // Resolve an invocation of [element.name] on [self]. If it |
| 380 // is found, this selector is a candidate. | 380 // is found, this selector is a candidate. |
| 381 return hasElementIn(self, element) && super.applies(element, compiler); | 381 return hasElementIn(self, element) && super.applies(element, compiler); |
| 382 } | 382 } |
| 383 | 383 |
| 384 return false; | 384 return false; |
| 385 } | 385 } |
| 386 | 386 |
| 387 toString() => 'TypedSelector($kind, $receiverType, $argumentCount)'; | 387 toString() => 'Selector($kind, $name, $argumentCount, type=$receiverType)'; |
| 388 } | 388 } |
| OLD | NEW |