OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 fasta.target_implementation; | 5 library fasta.target_implementation; |
6 | 6 |
7 import 'package:kernel/target/targets.dart' as backend show Target; | 7 import 'package:kernel/target/targets.dart' as backend show Target; |
8 | 8 |
9 import 'builder/builder.dart' show Builder, ClassBuilder, LibraryBuilder; | 9 import 'builder/builder.dart' show Builder, ClassBuilder, LibraryBuilder; |
10 | 10 |
11 import 'parser/dart_vm_native.dart' as vm show skipNativeClause; | |
12 | |
13 import '../scanner/token.dart' show Token; | |
14 | |
15 import 'loader.dart' show Loader; | 11 import 'loader.dart' show Loader; |
16 | 12 |
17 import 'quote.dart' show unescapeString; | |
18 | |
19 import 'target.dart' show Target; | 13 import 'target.dart' show Target; |
20 | 14 |
21 import 'ticker.dart' show Ticker; | 15 import 'ticker.dart' show Ticker; |
22 | 16 |
23 import 'translate_uri.dart' show TranslateUri; | 17 import 'translate_uri.dart' show TranslateUri; |
24 | 18 |
25 /// Provides the implementation details used by a loader for a target. | 19 /// Provides the implementation details used by a loader for a target. |
26 abstract class TargetImplementation extends Target { | 20 abstract class TargetImplementation extends Target { |
27 final TranslateUri uriTranslator; | 21 final TranslateUri uriTranslator; |
28 | 22 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 LibraryBuilder internal = loader.read(Uri.parse("dart:_internal"), -1); | 89 LibraryBuilder internal = loader.read(Uri.parse("dart:_internal"), -1); |
96 return cachedNativeAnnotation = internal.getConstructor("ExternalName"); | 90 return cachedNativeAnnotation = internal.getConstructor("ExternalName"); |
97 } | 91 } |
98 | 92 |
99 void loadExtraRequiredLibraries(Loader loader) { | 93 void loadExtraRequiredLibraries(Loader loader) { |
100 for (String uri in backendTarget.extraRequiredLibraries) { | 94 for (String uri in backendTarget.extraRequiredLibraries) { |
101 loader.read(Uri.parse(uri), -1); | 95 loader.read(Uri.parse(uri), -1); |
102 } | 96 } |
103 } | 97 } |
104 | 98 |
105 /// Whether the `native` language extension is supported within [library]. | |
106 /// | |
107 /// The `native` language extension is not part of the language specification, | |
108 /// means something else to each target, and is enabled differently for each | |
109 /// target implementation. For example, the VM target enables it everywhere | |
110 /// because of existing support for "dart-ext:" native extensions, but targets | |
111 /// like dart2js only enable it on the core libraries. | |
112 /// | |
113 /// This default implementation assumes a VM target, but it can be overriden | |
114 /// in subclasses to change the behavior. | |
115 // TODO(sigmund,ahe): limit this to `dart-ext` libraries only (see | |
116 // https://github.com/dart-lang/sdk/issues/29763). | |
117 bool enableNative(LibraryBuilder library) => true; | |
118 | |
119 Token skipNativeClause(Token token) => vm.skipNativeClause(token); | |
120 | |
121 String extractNativeMethodName(Token token) => | |
122 unescapeString(token.next.lexeme); | |
123 | |
124 void addSourceInformation( | 99 void addSourceInformation( |
125 Uri uri, List<int> lineStarts, List<int> sourceCode); | 100 Uri uri, List<int> lineStarts, List<int> sourceCode); |
126 | 101 |
127 void readPatchFiles(LibraryBuilder library) { | 102 void readPatchFiles(LibraryBuilder library) { |
128 assert(library.uri.scheme == "dart"); | 103 assert(library.uri.scheme == "dart"); |
129 List<Uri> patches = uriTranslator.patches[library.uri.path]; | 104 List<Uri> patches = uriTranslator.patches[library.uri.path]; |
130 if (patches != null) { | 105 if (patches != null) { |
131 for (Uri patch in patches) { | 106 for (Uri patch in patches) { |
132 library.loader.read(patch, -1, fileUri: patch, isPatch: true); | 107 library.loader.read(patch, -1, fileUri: patch, isPatch: true); |
133 } | 108 } |
134 } | 109 } |
135 } | 110 } |
136 } | 111 } |
OLD | NEW |