Chromium Code Reviews| Index: sdk/lib/_internal/compiler/implementation/resolution/members.dart |
| diff --git a/sdk/lib/_internal/compiler/implementation/resolution/members.dart b/sdk/lib/_internal/compiler/implementation/resolution/members.dart |
| index 1ebc7109cef5b0c72cf723b88ccd8b9772ae05cf..e163855c3c3816116672e0bef7e028cf1e41a016 100644 |
| --- a/sdk/lib/_internal/compiler/implementation/resolution/members.dart |
| +++ b/sdk/lib/_internal/compiler/implementation/resolution/members.dart |
| @@ -1735,6 +1735,13 @@ class ResolverVisitor extends CommonResolverVisitor<Element> { |
| } else if (!selector.applies(target, compiler)) { |
| warnArgumentMismatch(node, target); |
| } |
| + |
| + if (selector.name == const SourceString('JS')) { |
|
ngeoffray
2012/11/08 08:18:01
Note that the equality check must be done on the e
sra1
2012/11/15 00:09:10
Which element?
|
| + var argNodes = node.arguments; |
| + if (!argNodes.isEmpty) { |
| + resolveJsTypeParameter(argNodes.head, node); |
| + } |
| + } |
| } |
| // TODO(ngeoffray): Warn if target is null and the send is |
| @@ -1751,6 +1758,72 @@ class ResolverVisitor extends CommonResolverVisitor<Element> { |
| [target.name]); |
| } |
| + void resolveJsTypeParameter(Node node, Node expression) { |
|
ngeoffray
2012/11/08 08:18:01
I would move this method to the native enqueuer.
sra1
2012/11/12 20:28:03
Done. I've moved everything except the lookup of
|
| + // Resolve 'JS' type; mark as an instantiated native type. |
| + // |
| + // The type is currently a string. We make an attempt at parsing the |
| + // string. |
| + // |
| + // We will need the JS form to support union types and possible some other |
| + // hints. We could get the parser to resolve complex types like List<int> |
| + // by using expressions that name classes, and a union by using a list |
| + // literal. |
| + // |
| + // JS(int, '#.foo', this); |
| + // |
| + // JS([List<int>, bool], '...'); // Union of types. |
| + // |
| + // JS([], '1'); // Type not expressable but harmless. |
| + // |
| + // JS(['existing', Object], ...); // Object, but not a fresh native one. |
| + |
| + LiteralString typeStringLiteral = node.asLiteralString(); |
| + if (typeStringLiteral != null) { |
| + String typeString = typeStringLiteral.dartString.slowToString(); |
| + if (! const {'': 1, 'var':1, 'void':1, |
| + //'bool':1, 'num':1, 'int':1, 'String':1 |
| + }.containsKey(typeString)) { |
| + Element element = resolveJSTypeString(typeString, node); |
| + if (element != null) { |
| + element.ensureResolved(compiler); |
| + DartType type = element.computeType(compiler); |
| + world.nativeEnqueuer.registerJSDartType(type, expression); |
|
ngeoffray
2012/11/08 08:18:01
Could this just be (native)enqueuer.registerInstan
sra1
2012/11/12 20:28:03
No, the matching is much more complex (subtypes, a
|
| + } |
| + } |
| + // Is there some way to decorate `node` with the type? With a union? |
| + } |
| + } |
| + |
| + ClassElement resolveJSTypeString(String typeString, Node node) { |
| + String typeName; |
| + if (typeString.startsWith('new:')) { |
| + typeName = typeString.substring(4); |
| + } else { |
| + typeName = typeString; |
| + } |
| + Element element = scope.lookup(new SourceString(typeName)); |
| + if (element == null) { |
| + if (typeName == 'dynamic') return compiler.dynamicClass; |
| + int index = typeName.indexOf('<'); |
| + if (index > 1) { |
| + element = scope.lookup(new SourceString(typeName.substring(0, index))); |
| + } |
| + if (element == null) { |
| + compiler.cancel( |
| + "Type of JS expression '$typeName' not found", |
| + node: node); |
| + return; |
| + } |
| + } |
| + if (element is! ClassElement) { |
| + compiler.cancel( |
| + "Type of JS expression '$typeName' not a class", |
| + node: node); |
| + } else { |
| + return element; |
| + } |
| + } |
| + |
| visitSendSet(SendSet node) { |
| Element target = resolveSend(node); |
| Element setter = target; |