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 | 8 |
9 import '../constants/values.dart'; | 9 import '../constants/values.dart'; |
10 import '../dart2jslib.dart'; | 10 import '../dart2jslib.dart'; |
11 import '../dart_types.dart'; | 11 import '../dart_types.dart'; |
12 import '../elements/elements.dart'; | 12 import '../elements/elements.dart'; |
13 import '../elements/modelx.dart' show ClassElementX, FunctionElementX; | 13 import '../elements/modelx.dart' |
| 14 show ClassElementX, FunctionElementX, LibraryElementX; |
14 import '../js/js.dart' as js; | 15 import '../js/js.dart' as js; |
15 import '../js_backend/js_backend.dart'; | 16 import '../js_backend/js_backend.dart'; |
16 import '../js_emitter/js_emitter.dart' show CodeEmitterTask; | 17 import '../js_emitter/js_emitter.dart' show CodeEmitterTask; |
17 import '../resolution/resolution.dart' show ResolverVisitor; | 18 import '../resolution/resolution.dart' show ResolverVisitor; |
18 import '../scanner/scannerlib.dart'; | 19 import '../scanner/scannerlib.dart'; |
19 import '../ssa/ssa.dart'; | 20 import '../ssa/ssa.dart'; |
20 import '../tree/tree.dart'; | 21 import '../tree/tree.dart'; |
21 import '../universe/universe.dart' show SideEffects; | 22 import '../universe/universe.dart' show SideEffects; |
22 import '../util/util.dart'; | 23 import '../util/util.dart'; |
23 | 24 |
24 part 'behavior.dart'; | 25 part 'behavior.dart'; |
25 part 'enqueue.dart'; | 26 part 'enqueue.dart'; |
26 part 'js.dart'; | 27 part 'js.dart'; |
27 part 'scanner.dart'; | 28 part 'scanner.dart'; |
28 part 'ssa.dart'; | 29 part 'ssa.dart'; |
29 | 30 |
30 void maybeEnableNative(Compiler compiler, | 31 void maybeEnableNative(Compiler compiler, |
31 LibraryElement library) { | 32 LibraryElementX library) { |
32 String libraryName = library.canonicalUri.toString(); | 33 String libraryName = library.canonicalUri.toString(); |
33 if (library.entryCompilationUnit.script.name.contains( | 34 if (library.entryCompilationUnit.script.name.contains( |
34 'dart/tests/compiler/dart2js_native') | 35 'dart/tests/compiler/dart2js_native') |
35 || libraryName == 'dart:async' | 36 || libraryName == 'dart:async' |
36 || libraryName == 'dart:html' | 37 || libraryName == 'dart:html' |
37 || libraryName == 'dart:html_common' | 38 || libraryName == 'dart:html_common' |
38 || libraryName == 'dart:indexed_db' | 39 || libraryName == 'dart:indexed_db' |
39 || libraryName == 'dart:js' | 40 || libraryName == 'dart:js' |
40 || libraryName == 'dart:svg' | 41 || libraryName == 'dart:svg' |
41 || libraryName == 'dart:_native_typed_data' | 42 || libraryName == 'dart:_native_typed_data' |
42 || libraryName == 'dart:web_audio' | 43 || libraryName == 'dart:web_audio' |
43 || libraryName == 'dart:web_gl' | 44 || libraryName == 'dart:web_gl' |
44 || libraryName == 'dart:web_sql') { | 45 || libraryName == 'dart:web_sql' |
| 46 || compiler.allowNativeExtensions) { |
45 library.canUseNative = true; | 47 library.canUseNative = true; |
46 } | 48 } |
47 } | 49 } |
48 | 50 |
49 // The tags string contains comma-separated 'words' which are either dispatch | 51 // The tags string contains comma-separated 'words' which are either dispatch |
50 // tags (having JavaScript identifier syntax) and directives that begin with | 52 // tags (having JavaScript identifier syntax) and directives that begin with |
51 // `!`. | 53 // `!`. |
52 List<String> nativeTagsOfClassRaw(ClassElement cls) { | 54 List<String> nativeTagsOfClassRaw(ClassElement cls) { |
53 String quotedName = cls.nativeTagInfo; | 55 String quotedName = cls.nativeTagInfo; |
54 return quotedName.substring(1, quotedName.length - 1).split(','); | 56 return quotedName.substring(1, quotedName.length - 1).split(','); |
55 } | 57 } |
56 | 58 |
57 List<String> nativeTagsOfClass(ClassElement cls) { | 59 List<String> nativeTagsOfClass(ClassElement cls) { |
58 return nativeTagsOfClassRaw(cls).where((s) => !s.startsWith('!')).toList(); | 60 return nativeTagsOfClassRaw(cls).where((s) => !s.startsWith('!')).toList(); |
59 } | 61 } |
60 | 62 |
61 bool nativeTagsForcedNonLeaf(ClassElement cls) => | 63 bool nativeTagsForcedNonLeaf(ClassElement cls) => |
62 nativeTagsOfClassRaw(cls).contains('!nonleaf'); | 64 nativeTagsOfClassRaw(cls).contains('!nonleaf'); |
OLD | NEW |