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 #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('../leg.dart'); | 9 #import('../leg.dart'); |
| 10 #import('../scanner/scannerlib.dart'); | 10 #import('../scanner/scannerlib.dart'); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 class Selector implements Hashable { | 122 class Selector implements Hashable { |
| 123 final SelectorKind kind; | 123 final SelectorKind kind; |
| 124 final SourceString name; | 124 final SourceString name; |
| 125 final LibraryElement library; // Library is null for non-private selectors. | 125 final LibraryElement library; // Library is null for non-private selectors. |
| 126 | 126 |
| 127 // The numbers of arguments of the selector. Includes named arguments. | 127 // The numbers of arguments of the selector. Includes named arguments. |
| 128 final int argumentCount; | 128 final int argumentCount; |
| 129 final List<SourceString> namedArguments; | 129 final List<SourceString> namedArguments; |
| 130 final List<SourceString> orderedNamedArguments; | 130 final List<SourceString> orderedNamedArguments; |
| 131 | 131 |
| 132 Selector( | 132 Selector._noLibraryCheck( |
|
ahe
2012/09/24 06:43:31
This is getting really confusing now. First, I'd l
aam-me
2012/09/24 13:08:20
This implementation doesn't rely on name prefixed
aam-me
2012/09/25 04:15:18
I reverted this in most recent implementation.
| |
| 133 this.kind, | 133 this.kind, |
| 134 SourceString name, | 134 this.name, |
| 135 LibraryElement library, | 135 this.library, |
| 136 this.argumentCount, | 136 this.argumentCount, |
| 137 [List<SourceString> namedArguments = const <SourceString>[]]) | 137 namedArguments) |
| 138 : this.name = name, | 138 : this.namedArguments = namedArguments, |
| 139 this.library = name.isPrivate() ? library : null, | 139 this.orderedNamedArguments = namedArguments.isEmpty() ? namedArguments |
| 140 this.namedArguments = namedArguments, | 140 : <SourceString>[]; |
|
kasperl
2012/09/24 05:52:38
Somewhere you lost the
assert(!name.isPrivate
| |
| 141 this.orderedNamedArguments = namedArguments.isEmpty() | 141 |
| 142 ? namedArguments | 142 Selector(kind, |
| 143 : <SourceString>[] { | 143 name, |
| 144 assert(!name.isPrivate() || library != null); | 144 LibraryElement library, |
| 145 } | 145 argumentCount, |
| 146 [List<SourceString> namedArguments = const <SourceString>[]]) | |
| 147 : this._noLibraryCheck(kind, | |
| 148 name, | |
| 149 name.isPrivate() ? library : null, | |
| 150 argumentCount, | |
| 151 namedArguments); | |
| 146 | 152 |
| 147 Selector.getter(SourceString name, LibraryElement library) | 153 Selector.getter(SourceString name, LibraryElement library) |
| 148 : this(SelectorKind.GETTER, name, library, 0); | 154 : this(SelectorKind.GETTER, name, library, 0); |
| 149 | 155 |
| 150 Selector.getterFrom(Selector selector) | 156 Selector.getterFrom(Selector selector) |
| 151 : this(SelectorKind.GETTER, selector.name, selector.library, 0); | 157 : this(SelectorKind.GETTER, selector.name, selector.library, 0); |
| 152 | 158 |
| 153 Selector.setter(SourceString name, LibraryElement library) | 159 Selector.setter(SourceString name, LibraryElement library) |
| 154 : this(SelectorKind.SETTER, name, library, 1); | 160 : this(SelectorKind.SETTER, name, library, 1); |
| 155 | 161 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 172 : this(SelectorKind.INDEX, | 178 : this(SelectorKind.INDEX, |
| 173 Elements.constructOperatorName(const SourceString("[]="), false), | 179 Elements.constructOperatorName(const SourceString("[]="), false), |
| 174 null, 2); | 180 null, 2); |
| 175 | 181 |
| 176 Selector.call(SourceString name, | 182 Selector.call(SourceString name, |
| 177 LibraryElement library, | 183 LibraryElement library, |
| 178 int arity, | 184 int arity, |
| 179 [List<SourceString> named = const []]) | 185 [List<SourceString> named = const []]) |
| 180 : this(SelectorKind.CALL, name, library, arity, named); | 186 : this(SelectorKind.CALL, name, library, arity, named); |
| 181 | 187 |
| 188 // Ignore arity and named parameters when creating constructor selector | |
| 189 // since constructors are uniquely identifed by name only, can't be | |
| 190 // overriden. | |
| 191 Selector.callConstructor(SourceString className, | |
|
kasperl
2012/09/24 05:52:38
I know I sort of led you to a design where the sel
aam-me
2012/09/24 13:08:20
Let me give it a try!
aam-me
2012/09/25 04:15:18
Okay, so name is just a constructor name, but now
| |
| 192 SourceString constructorName, | |
| 193 LibraryElement library) | |
| 194 : this._noLibraryCheck(SelectorKind.CALL, | |
| 195 (constructorName === const SourceString('')) | |
|
kasperl
2012/09/24 05:52:38
Can't you make it so this will never be called wit
aam-me
2012/09/25 04:15:18
I'm not certain on how to ensure that callConstruc
| |
| 196 ? className | |
| 197 : new SourceString( | |
| 198 "${className.slowToString()}." | |
| 199 "${constructorName.slowToString()}"), | |
|
ahe
2012/09/24 06:43:31
I think this is problematic. The constructor name
aam-me
2012/09/25 04:15:18
All this is gone now.
| |
| 200 constructorName.isPrivate()? library: null, | |
|
kasperl
2012/09/24 05:52:38
Space before ? and before :.
| |
| 201 0, | |
| 202 const []); | |
| 203 | |
| 204 Selector.callDefaultConstructor(SourceString name, | |
| 205 LibraryElement library) | |
| 206 : this(SelectorKind.CALL, name, library, 0, const []); | |
| 207 | |
| 182 Selector.callClosure(int arity, [List<SourceString> named = const []]) | 208 Selector.callClosure(int arity, [List<SourceString> named = const []]) |
| 183 : this(SelectorKind.CALL, Compiler.CALL_OPERATOR_NAME, null, | 209 : this(SelectorKind.CALL, Compiler.CALL_OPERATOR_NAME, null, |
| 184 arity, named); | 210 arity, named); |
| 185 | 211 |
| 186 Selector.callClosureFrom(Selector selector) | 212 Selector.callClosureFrom(Selector selector) |
| 187 : this(SelectorKind.CALL, Compiler.CALL_OPERATOR_NAME, null, | 213 : this(SelectorKind.CALL, Compiler.CALL_OPERATOR_NAME, null, |
| 188 selector.argumentCount, selector.namedArguments); | 214 selector.argumentCount, selector.namedArguments); |
| 189 | 215 |
| 190 // TODO(kasperl): This belongs somewhere else. | 216 // TODO(kasperl): This belongs somewhere else. |
| 191 Selector.noSuchMethod() | 217 Selector.noSuchMethod() |
| 192 : this(SelectorKind.CALL, Compiler.NO_SUCH_METHOD, null, 2); | 218 : this(SelectorKind.CALL, Compiler.NO_SUCH_METHOD, null, 2); |
| 193 | 219 |
| 194 bool isGetter() => kind === SelectorKind.GETTER; | 220 bool isGetter() => kind === SelectorKind.GETTER; |
| 195 bool isSetter() => kind === SelectorKind.SETTER; | 221 bool isSetter() => kind === SelectorKind.SETTER; |
| 196 bool isCall() => kind === SelectorKind.CALL; | 222 bool isCall() => kind === SelectorKind.CALL; |
| 197 | 223 |
| 198 bool isIndex() => kind === SelectorKind.INDEX && argumentCount == 1; | 224 bool isIndex() => kind === SelectorKind.INDEX && argumentCount == 1; |
| 199 bool isIndexSet() => kind === SelectorKind.INDEX && argumentCount == 2; | 225 bool isIndexSet() => kind === SelectorKind.INDEX && argumentCount == 2; |
| 200 | 226 |
| 201 bool isOperator() => kind === SelectorKind.OPERATOR; | 227 bool isOperator() => kind === SelectorKind.OPERATOR; |
| 202 bool isUnaryOperator() => isOperator() && argumentCount == 0; | 228 bool isUnaryOperator() => isOperator() && argumentCount == 0; |
| 203 bool isBinaryOperator() => isOperator() && argumentCount == 1; | 229 bool isBinaryOperator() => isOperator() && argumentCount == 1; |
| 204 | 230 |
| 231 bool isPrivate() => library != null; | |
| 232 | |
| 205 /** Check whether this is a call to 'assert' with one positional parameter. */ | 233 /** Check whether this is a call to 'assert' with one positional parameter. */ |
| 206 bool isAssertSyntax() { | 234 bool isAssertSyntax() { |
| 207 return (isCall() && | 235 return (isCall() && |
| 208 name.stringValue === "assert" && | 236 name.stringValue === "assert" && |
| 209 argumentCount == 1 && | 237 argumentCount == 1 && |
| 210 namedArgumentCount == 0); | 238 namedArgumentCount == 0); |
| 211 } | 239 } |
| 212 | 240 |
| 213 int hashCode() => argumentCount + 1000 * namedArguments.length; | 241 int hashCode() => argumentCount + 1000 * namedArguments.length; |
| 214 int get namedArgumentCount => namedArguments.length; | 242 int get namedArgumentCount => namedArguments.length; |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 525 | 553 |
| 526 if (!self.isInterface() && self.isSubclassOf(other)) { | 554 if (!self.isInterface() && self.isSubclassOf(other)) { |
| 527 // Resolve an invocation of [element.name] on [self]. If it | 555 // Resolve an invocation of [element.name] on [self]. If it |
| 528 // is found, this selector is a candidate. | 556 // is found, this selector is a candidate. |
| 529 return hasElementIn(self, element) && appliesUntyped(element, compiler); | 557 return hasElementIn(self, element) && appliesUntyped(element, compiler); |
| 530 } | 558 } |
| 531 | 559 |
| 532 return false; | 560 return false; |
| 533 } | 561 } |
| 534 } | 562 } |
| OLD | NEW |