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:uri'; | 7 import 'dart:uri'; |
8 import 'dart2jslib.dart' hide SourceString; | 8 import 'dart2jslib.dart' hide SourceString; |
9 import 'elements/elements.dart'; | 9 import 'elements/elements.dart'; |
10 import 'js_backend/js_backend.dart'; | 10 import 'js_backend/js_backend.dart'; |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 // Also parse the node to know all its methods because otherwise it will | 216 // Also parse the node to know all its methods because otherwise it will |
217 // only be parsed if there is a call to one of its constructors. | 217 // only be parsed if there is a call to one of its constructors. |
218 classElement.parseNode(compiler); | 218 classElement.parseNode(compiler); |
219 | 219 |
220 if (firstTime) { | 220 if (firstTime) { |
221 queue.add(onFirstNativeClass); | 221 queue.add(onFirstNativeClass); |
222 } | 222 } |
223 } | 223 } |
224 | 224 |
225 registerElement(Element element) { | 225 registerElement(Element element) { |
226 if (element.isFunction() || element.isGetter() || element.isSetter()) { | 226 compiler.withCurrentElement(element, () { |
227 handleMethodAnnotations(element); | 227 if (element.isFunction() || element.isGetter() || element.isSetter()) { |
228 if (element.isNative()) { | 228 handleMethodAnnotations(element); |
229 registerMethodUsed(element); | 229 if (element.isNative()) { |
| 230 registerMethodUsed(element); |
| 231 } |
| 232 } else if (element.isField()) { |
| 233 handleFieldAnnotations(element); |
| 234 if (element.isNative()) { |
| 235 registerFieldLoad(element); |
| 236 registerFieldStore(element); |
| 237 } |
230 } | 238 } |
231 } else if (element.isField()) { | 239 }); |
232 handleFieldAnnotations(element); | |
233 if (element.isNative()) { | |
234 registerFieldLoad(element); | |
235 registerFieldStore(element); | |
236 } | |
237 } | |
238 } | 240 } |
239 | 241 |
240 handleFieldAnnotations(Element element) { | 242 handleFieldAnnotations(Element element) { |
241 if (element.enclosingElement.isNative()) { | 243 if (element.enclosingElement.isNative()) { |
242 // Exclude non-instance (static) fields - they not really native and are | 244 // Exclude non-instance (static) fields - they not really native and are |
243 // compiled as isolate globals. Access of a property of a constructor | 245 // compiled as isolate globals. Access of a property of a constructor |
244 // function or a non-method property in the prototype chain, must be coded | 246 // function or a non-method property in the prototype chain, must be coded |
245 // using a JS-call. | 247 // using a JS-call. |
246 if (element.isInstanceMember()) { | 248 if (element.isInstanceMember()) { |
247 setNativeName(element); | 249 setNativeName(element); |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 directSubtypes.add(cls); | 444 directSubtypes.add(cls); |
443 } | 445 } |
444 | 446 |
445 void logSummary(log(message)) { | 447 void logSummary(log(message)) { |
446 log('Compiled ${registeredClasses.length} native classes, ' | 448 log('Compiled ${registeredClasses.length} native classes, ' |
447 '${unusedClasses.length} native classes omitted.'); | 449 '${unusedClasses.length} native classes omitted.'); |
448 } | 450 } |
449 } | 451 } |
450 | 452 |
451 void maybeEnableNative(Compiler compiler, | 453 void maybeEnableNative(Compiler compiler, |
452 LibraryElement library, | 454 LibraryElement library) { |
453 Uri uri) { | 455 String libraryName = library.uri.toString(); |
454 String libraryName = uri.toString(); | |
455 if (library.entryCompilationUnit.script.name.contains( | 456 if (library.entryCompilationUnit.script.name.contains( |
456 'dart/tests/compiler/dart2js_native') | 457 'dart/tests/compiler/dart2js_native') |
457 || libraryName == 'dart:async' | 458 || libraryName == 'dart:async' |
458 || libraryName == 'dart:html' | 459 || libraryName == 'dart:html' |
459 || libraryName == 'dart:html_common' | 460 || libraryName == 'dart:html_common' |
460 || libraryName == 'dart:indexed_db' | 461 || libraryName == 'dart:indexed_db' |
461 || libraryName == 'dart:svg' | 462 || libraryName == 'dart:svg' |
462 || libraryName == 'dart:web_audio') { | 463 || libraryName == 'dart:web_audio') { |
463 library.canUseNative = true; | 464 library.canUseNative = true; |
464 } | 465 } |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 } else { | 876 } else { |
876 if (parameters.parameterCount != 0) { | 877 if (parameters.parameterCount != 0) { |
877 compiler.cancel( | 878 compiler.cancel( |
878 'native "..." syntax is restricted to functions with zero parameters', | 879 'native "..." syntax is restricted to functions with zero parameters', |
879 node: nativeBody); | 880 node: nativeBody); |
880 } | 881 } |
881 LiteralString jsCode = nativeBody.asLiteralString(); | 882 LiteralString jsCode = nativeBody.asLiteralString(); |
882 builder.push(new HForeign.statement(jsCode.dartString, <HInstruction>[])); | 883 builder.push(new HForeign.statement(jsCode.dartString, <HInstruction>[])); |
883 } | 884 } |
884 } | 885 } |
OLD | NEW |