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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 | 87 |
| 88 static const SelectorKind GETTER = const SelectorKind('getter'); | 88 static const SelectorKind GETTER = const SelectorKind('getter'); |
| 89 static const SelectorKind SETTER = const SelectorKind('setter'); | 89 static const SelectorKind SETTER = const SelectorKind('setter'); |
| 90 static const SelectorKind CALL = const SelectorKind('call'); | 90 static const SelectorKind CALL = const SelectorKind('call'); |
| 91 static const SelectorKind OPERATOR = const SelectorKind('operator'); | 91 static const SelectorKind OPERATOR = const SelectorKind('operator'); |
| 92 static const SelectorKind INDEX = const SelectorKind('index'); | 92 static const SelectorKind INDEX = const SelectorKind('index'); |
| 93 | 93 |
| 94 toString() => name; | 94 toString() => name; |
| 95 } | 95 } |
| 96 | 96 |
| 97 class SelectorName { | |
|
kasperl
2012/09/21 12:12:06
I'm not quite happy with this abstraction. Why do
aam-me
2012/09/21 12:35:27
Main reason for having library in SelectorName and
| |
| 98 final SourceString libName; | |
| 99 final SourceString className; | |
| 100 final SourceString name; | |
| 101 | |
| 102 SourceString _fullName; | |
| 103 | |
| 104 SelectorName(name, {libName: const SourceString('')}) | |
|
kasperl
2012/09/21 12:12:06
It makes me a bit uncomfortable to have these defa
aam-me
2012/09/21 12:35:27
This libName represents names which have library n
| |
| 105 : this.fullyNamed(libName, const SourceString(''), name); | |
| 106 SelectorName.namedClass(className, {libName: const SourceString('')}) | |
| 107 : this.fullyNamed(libName, className, const SourceString('')); | |
| 108 SelectorName.namedConstructor(className, | |
| 109 name, | |
| 110 {libName: const SourceString('')}) | |
| 111 : this.fullyNamed(libName, className, name); | |
| 112 | |
| 113 SelectorName.fullyNamed(this.libName, this.className, this.name) { | |
| 114 String fn = name.slowToString(); | |
| 115 String cn = className.slowToString(); | |
| 116 if (cn.length > 0) { | |
| 117 if (fn.length > 0) { | |
| 118 cn = cn.concat("."); | |
| 119 } | |
| 120 fn = cn.concat(fn); | |
| 121 } | |
| 122 String ln = libName.slowToString(); | |
| 123 if (ln.length > 0) { | |
| 124 if (fn.length >0 ) { | |
| 125 ln = ln.concat("."); | |
| 126 } | |
| 127 fn = ln.concat(fn); | |
| 128 } | |
| 129 this._fullName = new SourceString(fn); | |
| 130 } | |
| 131 | |
| 132 toString() => _fullName.stringValue; | |
| 133 isPrivate() => name.isPrivate(); | |
| 134 } | |
| 135 | |
| 97 class Selector implements Hashable { | 136 class Selector implements Hashable { |
| 98 final SelectorKind kind; | 137 final SelectorKind kind; |
| 99 final SourceString name; | 138 final SelectorName selectorName; |
| 139 SourceString get name => selectorName._fullName; | |
| 140 | |
| 100 final LibraryElement library; // Library is null for non-private selectors. | 141 final LibraryElement library; // Library is null for non-private selectors. |
| 101 | 142 |
| 102 // The numbers of arguments of the selector. Includes named arguments. | 143 // The numbers of arguments of the selector. Includes named arguments. |
| 103 final int argumentCount; | 144 final int argumentCount; |
| 104 final List<SourceString> namedArguments; | 145 final List<SourceString> namedArguments; |
| 105 final List<SourceString> orderedNamedArguments; | 146 final List<SourceString> orderedNamedArguments; |
| 106 | 147 |
| 107 Selector( | 148 Selector( |
| 149 kind, | |
| 150 SourceString name, | |
| 151 LibraryElement library, | |
| 152 argumentCount, | |
| 153 [List<SourceString> namedArguments = const <SourceString>[]]) | |
| 154 : this.fromSelectorName(kind, | |
| 155 new SelectorName(name), | |
| 156 library, | |
| 157 argumentCount, | |
| 158 namedArguments); | |
| 159 | |
| 160 Selector.fromSelectorName( | |
| 108 this.kind, | 161 this.kind, |
| 109 SourceString name, | 162 SelectorName selectorName, |
| 110 LibraryElement library, | 163 LibraryElement library, |
| 111 this.argumentCount, | 164 this.argumentCount, |
| 112 [List<SourceString> namedArguments = const <SourceString>[]]) | 165 [List<SourceString> namedArguments = const <SourceString>[]]) |
| 113 : this.name = name, | 166 : this.selectorName = selectorName, |
| 114 this.library = name.isPrivate() ? library : null, | 167 this.library = selectorName.isPrivate() ? library : null, |
| 115 this.namedArguments = namedArguments, | 168 this.namedArguments = namedArguments, |
| 116 this.orderedNamedArguments = namedArguments.isEmpty() | 169 this.orderedNamedArguments = namedArguments.isEmpty() |
| 117 ? namedArguments | 170 ? namedArguments |
| 118 : <SourceString>[] { | 171 : <SourceString>[] { |
| 119 assert(!name.isPrivate() || library != null); | 172 assert(!selectorName.isPrivate() || library != null); |
| 120 } | 173 } |
| 121 | 174 |
| 122 Selector.getter(SourceString name, LibraryElement library) | 175 Selector.getter(SourceString name, LibraryElement library) |
| 123 : this(SelectorKind.GETTER, name, library, 0); | 176 : this(SelectorKind.GETTER, name, library, 0); |
| 124 | 177 |
| 125 Selector.getterFrom(Selector selector) | 178 Selector.getterFrom(Selector selector) |
| 126 : this(SelectorKind.GETTER, selector.name, selector.library, 0); | 179 : this(SelectorKind.GETTER, selector.name, selector.library, 0); |
| 127 | 180 |
| 128 Selector.setter(SourceString name, LibraryElement library) | 181 Selector.setter(SourceString name, LibraryElement library) |
| 129 : this(SelectorKind.SETTER, name, library, 1); | 182 : this(SelectorKind.SETTER, name, library, 1); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 147 : this(SelectorKind.INDEX, | 200 : this(SelectorKind.INDEX, |
| 148 Elements.constructOperatorName(const SourceString("[]="), false), | 201 Elements.constructOperatorName(const SourceString("[]="), false), |
| 149 null, 2); | 202 null, 2); |
| 150 | 203 |
| 151 Selector.call(SourceString name, | 204 Selector.call(SourceString name, |
| 152 LibraryElement library, | 205 LibraryElement library, |
| 153 int arity, | 206 int arity, |
| 154 [List<SourceString> named = const []]) | 207 [List<SourceString> named = const []]) |
| 155 : this(SelectorKind.CALL, name, library, arity, named); | 208 : this(SelectorKind.CALL, name, library, arity, named); |
| 156 | 209 |
| 210 // Ignore arity and named parameters when creating constructor selector | |
| 211 // since constructors are uniquely identifed by name only, can't be | |
| 212 // overriden. | |
| 213 Selector.callConstructor(SelectorName name, | |
|
kasperl
2012/09/21 12:12:06
This looks nice and it looks like a good place to
| |
| 214 LibraryElement library) | |
| 215 : this.fromSelectorName(SelectorKind.CALL, name, library, 0, const []); | |
| 216 | |
| 157 Selector.callClosure(int arity, [List<SourceString> named = const []]) | 217 Selector.callClosure(int arity, [List<SourceString> named = const []]) |
| 158 : this(SelectorKind.CALL, Compiler.CALL_OPERATOR_NAME, null, | 218 : this(SelectorKind.CALL, Compiler.CALL_OPERATOR_NAME, null, |
| 159 arity, named); | 219 arity, named); |
| 160 | 220 |
| 161 Selector.callClosureFrom(Selector selector) | 221 Selector.callClosureFrom(Selector selector) |
| 162 : this(SelectorKind.CALL, Compiler.CALL_OPERATOR_NAME, null, | 222 : this(SelectorKind.CALL, Compiler.CALL_OPERATOR_NAME, null, |
| 163 selector.argumentCount, selector.namedArguments); | 223 selector.argumentCount, selector.namedArguments); |
| 164 | 224 |
| 165 // TODO(kasperl): This belongs somewhere else. | 225 // TODO(kasperl): This belongs somewhere else. |
| 166 Selector.noSuchMethod() | 226 Selector.noSuchMethod() |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 496 | 556 |
| 497 if (!self.isInterface() && self.isSubclassOf(other)) { | 557 if (!self.isInterface() && self.isSubclassOf(other)) { |
| 498 // Resolve an invocation of [element.name] on [self]. If it | 558 // Resolve an invocation of [element.name] on [self]. If it |
| 499 // is found, this selector is a candidate. | 559 // is found, this selector is a candidate. |
| 500 return hasElementIn(self, element) && appliesUntyped(element, compiler); | 560 return hasElementIn(self, element) && appliesUntyped(element, compiler); |
| 501 } | 561 } |
| 502 | 562 |
| 503 return false; | 563 return false; |
| 504 } | 564 } |
| 505 } | 565 } |
| OLD | NEW |