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 native; | 5 library native; |
| 6 | 6 |
| 7 import 'dart:collection' show Queue; | 7 import 'dart:collection' show Queue; |
| 8 import 'dart:uri'; | 8 import 'dart:uri'; |
| 9 import 'dart2jslib.dart' hide SourceString; | 9 import 'dart2jslib.dart' hide SourceString; |
| 10 import 'elements/elements.dart'; | 10 import 'elements/elements.dart'; |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 532 if (specLiteral != null) { | 532 if (specLiteral != null) { |
| 533 String specString = specLiteral.dartString.slowToString(); | 533 String specString = specLiteral.dartString.slowToString(); |
| 534 // Various things that are not in fact types. | 534 // Various things that are not in fact types. |
| 535 if (specString == 'void') return NativeBehavior.NONE; | 535 if (specString == 'void') return NativeBehavior.NONE; |
| 536 if (specString == '' || specString == 'var') { | 536 if (specString == '' || specString == 'var') { |
| 537 var behavior = new NativeBehavior(); | 537 var behavior = new NativeBehavior(); |
| 538 behavior.typesReturned.add(compiler.objectClass.computeType(compiler)); | 538 behavior.typesReturned.add(compiler.objectClass.computeType(compiler)); |
| 539 return behavior; | 539 return behavior; |
| 540 } | 540 } |
| 541 var behavior = new NativeBehavior(); | 541 var behavior = new NativeBehavior(); |
| 542 LinkBuilder<Element> types = new LinkBuilder<Element>(); | |
|
ahe
2013/01/28 15:14:31
This looks like a list of "elements", not "types".
| |
| 542 for (final typeString in specString.split('|')) { | 543 for (final typeString in specString.split('|')) { |
| 543 var type = _parseType(typeString, compiler, | 544 var type = _parseType(typeString, compiler, |
| 544 (name) => resolver.resolveTypeFromString(name), | 545 (name) => resolver.resolveTypeFromString(name), |
| 545 jsCall); | 546 jsCall); |
| 546 behavior.typesInstantiated.add(type); | 547 behavior.typesInstantiated.add(type); |
| 547 behavior.typesReturned.add(type); | 548 behavior.typesReturned.add(type); |
| 549 if (type == SpecialType.JsObject) { | |
| 550 types.addLast(compiler.objectClass); | |
| 551 } else if (type == SpecialType.JsArray) { | |
| 552 types.addLast(compiler.backend.listImplementation); | |
| 553 } else { | |
| 554 types.addLast(type.element); | |
| 555 } | |
| 548 } | 556 } |
| 557 compiler.typesTask.typedNodes[jsCall] = types.toLink(); | |
|
ahe
2013/01/28 15:14:31
Please abstract this operation.
sra1
2013/01/28 20:12:20
Move the assignment out to the call site of ofJsCa
| |
| 549 return behavior; | 558 return behavior; |
| 550 } | 559 } |
| 551 | 560 |
| 552 // TODO(sra): We could accept a type identifier? e.g. JS(bool, '1<2'). It | 561 // TODO(sra): We could accept a type identifier? e.g. JS(bool, '1<2'). It |
| 553 // is not very satisfactory because it does not work for void, dynamic. | 562 // is not very satisfactory because it does not work for void, dynamic. |
| 554 | 563 |
| 555 compiler.cancel("Unexpected JS first argument", node: firstArg); | 564 compiler.cancel("Unexpected JS first argument", node: firstArg); |
| 556 } | 565 } |
| 557 | 566 |
| 558 static NativeBehavior ofMethod(FunctionElement method, Compiler compiler) { | 567 static NativeBehavior ofMethod(FunctionElement method, Compiler compiler) { |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 873 } else if (element.kind == ElementKind.GETTER) { | 882 } else if (element.kind == ElementKind.GETTER) { |
| 874 nativeMethodCall = '$receiver$nativeMethodName'; | 883 nativeMethodCall = '$receiver$nativeMethodName'; |
| 875 } else if (element.kind == ElementKind.SETTER) { | 884 } else if (element.kind == ElementKind.SETTER) { |
| 876 nativeMethodCall = '$receiver$nativeMethodName = $foreignParameters'; | 885 nativeMethodCall = '$receiver$nativeMethodName = $foreignParameters'; |
| 877 } else { | 886 } else { |
| 878 builder.compiler.internalError('unexpected kind: "${element.kind}"', | 887 builder.compiler.internalError('unexpected kind: "${element.kind}"', |
| 879 element: element); | 888 element: element); |
| 880 } | 889 } |
| 881 | 890 |
| 882 DartString jsCode = new DartString.literal(nativeMethodCall); | 891 DartString jsCode = new DartString.literal(nativeMethodCall); |
| 883 builder.push( | 892 builder.push(new HForeign(jsCode, HType.UNKNOWN, inputs)); |
| 884 new HForeign(jsCode, const LiteralDartString('Object'), inputs)); | |
| 885 builder.close(new HReturn(builder.pop())).addSuccessor(builder.graph.exit); | 893 builder.close(new HReturn(builder.pop())).addSuccessor(builder.graph.exit); |
| 886 } else { | 894 } else { |
| 887 if (parameters.parameterCount != 0) { | 895 if (parameters.parameterCount != 0) { |
| 888 compiler.cancel( | 896 compiler.cancel( |
| 889 'native "..." syntax is restricted to functions with zero parameters', | 897 'native "..." syntax is restricted to functions with zero parameters', |
| 890 node: nativeBody); | 898 node: nativeBody); |
| 891 } | 899 } |
| 892 LiteralString jsCode = nativeBody.asLiteralString(); | 900 LiteralString jsCode = nativeBody.asLiteralString(); |
| 893 builder.push(new HForeign.statement(jsCode.dartString, <HInstruction>[])); | 901 builder.push(new HForeign.statement(jsCode.dartString, <HInstruction>[])); |
| 894 } | 902 } |
| 895 } | 903 } |
| OLD | NEW |