OLD | NEW |
1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dartino 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 library fletchc.fletch_compiler_implementation; | 5 library dartino_compiler.dartino_compiler_implementation; |
6 | 6 |
7 import 'dart:async' show | 7 import 'dart:async' show |
8 EventSink; | 8 EventSink; |
9 | 9 |
10 import 'package:compiler/compiler_new.dart' as api; | 10 import 'package:compiler/compiler_new.dart' as api; |
11 | 11 |
12 import 'package:compiler/src/apiimpl.dart' show | 12 import 'package:compiler/src/apiimpl.dart' show |
13 CompilerImpl, | 13 CompilerImpl, |
14 makeDiagnosticOptions; | 14 makeDiagnosticOptions; |
15 | 15 |
(...skipping 17 matching lines...) Expand all Loading... |
33 import 'package:compiler/src/diagnostics/source_span.dart' show | 33 import 'package:compiler/src/diagnostics/source_span.dart' show |
34 SourceSpan; | 34 SourceSpan; |
35 | 35 |
36 import 'package:compiler/src/diagnostics/diagnostic_listener.dart' show | 36 import 'package:compiler/src/diagnostics/diagnostic_listener.dart' show |
37 DiagnosticMessage, | 37 DiagnosticMessage, |
38 DiagnosticReporter; | 38 DiagnosticReporter; |
39 | 39 |
40 import 'package:compiler/src/diagnostics/spannable.dart' show | 40 import 'package:compiler/src/diagnostics/spannable.dart' show |
41 Spannable; | 41 Spannable; |
42 | 42 |
43 import 'fletch_function_builder.dart'; | 43 import 'dartino_function_builder.dart'; |
44 import 'debug_info.dart'; | 44 import 'debug_info.dart'; |
45 import 'find_position_visitor.dart'; | 45 import 'find_position_visitor.dart'; |
46 import 'fletch_context.dart'; | 46 import 'dartino_context.dart'; |
47 | 47 |
48 import 'fletch_enqueuer.dart' show | 48 import 'dartino_enqueuer.dart' show |
49 FletchEnqueueTask; | 49 DartinoEnqueueTask; |
50 | 50 |
51 import '../fletch_system.dart'; | 51 import '../dartino_system.dart'; |
52 import 'package:compiler/src/diagnostics/diagnostic_listener.dart'; | 52 import 'package:compiler/src/diagnostics/diagnostic_listener.dart'; |
53 import 'package:compiler/src/elements/elements.dart'; | 53 import 'package:compiler/src/elements/elements.dart'; |
54 | 54 |
55 import '../incremental/fletchc_incremental.dart' show | 55 import '../incremental/dartino_compiler_incremental.dart' show |
56 IncrementalCompiler; | 56 IncrementalCompiler; |
57 | 57 |
58 import 'fletch_diagnostic_reporter.dart' show | 58 import 'dartino_diagnostic_reporter.dart' show |
59 FletchDiagnosticReporter; | 59 DartinoDiagnosticReporter; |
60 | 60 |
61 const EXTRA_DART2JS_OPTIONS = const <String>[ | 61 const EXTRA_DART2JS_OPTIONS = const <String>[ |
62 // TODO(ahe): This doesn't completely disable type inference. Investigate. | 62 // TODO(ahe): This doesn't completely disable type inference. Investigate. |
63 '--disable-type-inference', | 63 '--disable-type-inference', |
64 '--output-type=dart', | 64 '--output-type=dart', |
65 // We want to continue generating code in the case of errors, to support | 65 // We want to continue generating code in the case of errors, to support |
66 // incremental fixes of erroneous code. | 66 // incremental fixes of erroneous code. |
67 '--generate-code-with-compile-time-errors', | 67 '--generate-code-with-compile-time-errors', |
68 ]; | 68 ]; |
69 | 69 |
70 const FLETCH_PATCHES = const <String, String>{ | 70 const DARTINO_PATCHES = const <String, String>{ |
71 "_internal": "internal/internal_patch.dart", | 71 "_internal": "internal/internal_patch.dart", |
72 "collection": "collection/collection_patch.dart", | 72 "collection": "collection/collection_patch.dart", |
73 "convert": "convert/convert_patch.dart", | 73 "convert": "convert/convert_patch.dart", |
74 "math": "math/math_patch.dart", | 74 "math": "math/math_patch.dart", |
75 "async": "async/async_patch.dart", | 75 "async": "async/async_patch.dart", |
76 "typed_data": "typed_data/typed_data_patch.dart", | 76 "typed_data": "typed_data/typed_data_patch.dart", |
77 }; | 77 }; |
78 | 78 |
79 const FLETCH_PLATFORM = 3; | 79 const DARTINO_PLATFORM = 3; |
80 | 80 |
81 DiagnosticOptions makeFletchDiagnosticOptions( | 81 DiagnosticOptions makeDartinoDiagnosticOptions( |
82 {bool suppressWarnings: false, | 82 {bool suppressWarnings: false, |
83 bool fatalWarnings: false, | 83 bool fatalWarnings: false, |
84 bool suppressHints: false, | 84 bool suppressHints: false, |
85 bool terseDiagnostics: false, | 85 bool terseDiagnostics: false, |
86 bool showPackageWarnings: true}) { | 86 bool showPackageWarnings: true}) { |
87 return makeDiagnosticOptions( | 87 return makeDiagnosticOptions( |
88 suppressWarnings: suppressWarnings, | 88 suppressWarnings: suppressWarnings, |
89 fatalWarnings: fatalWarnings, | 89 fatalWarnings: fatalWarnings, |
90 suppressHints: suppressHints, | 90 suppressHints: suppressHints, |
91 terseDiagnostics: terseDiagnostics, | 91 terseDiagnostics: terseDiagnostics, |
92 showPackageWarnings: true); | 92 showPackageWarnings: true); |
93 } | 93 } |
94 | 94 |
95 class FletchCompilerImplementation extends CompilerImpl { | 95 class DartinoCompilerImplementation extends CompilerImpl { |
96 final Uri fletchVm; | 96 final Uri dartinoVm; |
97 | 97 |
98 final Uri nativesJson; | 98 final Uri nativesJson; |
99 | 99 |
100 final IncrementalCompiler incrementalCompiler; | 100 final IncrementalCompiler incrementalCompiler; |
101 | 101 |
102 Map<Uri, CompilationUnitElementX> compilationUnits; | 102 Map<Uri, CompilationUnitElementX> compilationUnits; |
103 FletchContext internalContext; | 103 DartinoContext internalContext; |
104 | 104 |
105 /// A reference to [../compiler.dart:FletchCompiler] used for testing. | 105 /// A reference to [../compiler.dart:DartinoCompiler] used for testing. |
106 // TODO(ahe): Clean this up and remove this. | 106 // TODO(ahe): Clean this up and remove this. |
107 var helper; | 107 var helper; |
108 | 108 |
109 @override | 109 @override |
110 FletchEnqueueTask get enqueuer => super.enqueuer; | 110 DartinoEnqueueTask get enqueuer => super.enqueuer; |
111 | 111 |
112 FletchCompilerImplementation( | 112 DartinoCompilerImplementation( |
113 api.CompilerInput provider, | 113 api.CompilerInput provider, |
114 api.CompilerOutput outputProvider, | 114 api.CompilerOutput outputProvider, |
115 api.CompilerDiagnostics handler, | 115 api.CompilerDiagnostics handler, |
116 Uri libraryRoot, | 116 Uri libraryRoot, |
117 Uri packageConfig, | 117 Uri packageConfig, |
118 this.nativesJson, | 118 this.nativesJson, |
119 List<String> options, | 119 List<String> options, |
120 Map<String, dynamic> environment, | 120 Map<String, dynamic> environment, |
121 this.fletchVm, | 121 this.dartinoVm, |
122 this.incrementalCompiler) | 122 this.incrementalCompiler) |
123 : super( | 123 : super( |
124 provider, outputProvider, handler, libraryRoot, null, | 124 provider, outputProvider, handler, libraryRoot, null, |
125 EXTRA_DART2JS_OPTIONS.toList()..addAll(options), environment, | 125 EXTRA_DART2JS_OPTIONS.toList()..addAll(options), environment, |
126 packageConfig, null, FletchBackend.createInstance, | 126 packageConfig, null, DartinoBackend.createInstance, |
127 FletchDiagnosticReporter.createInstance, | 127 DartinoDiagnosticReporter.createInstance, |
128 makeFletchDiagnosticOptions); | 128 makeDartinoDiagnosticOptions); |
129 | 129 |
130 FletchContext get context { | 130 DartinoContext get context { |
131 if (internalContext == null) { | 131 if (internalContext == null) { |
132 internalContext = new FletchContext(this); | 132 internalContext = new DartinoContext(this); |
133 } | 133 } |
134 return internalContext; | 134 return internalContext; |
135 } | 135 } |
136 | 136 |
137 String fletchPatchLibraryFor(String name) { | 137 String dartinoPatchLibraryFor(String name) { |
138 // TODO(sigurdm): Try to remove this special casing. | 138 // TODO(sigurdm): Try to remove this special casing. |
139 if (name == "core") { | 139 if (name == "core") { |
140 return platformConfigUri.path.endsWith("fletch_embedded.platform") | 140 return platformConfigUri.path.endsWith("dartino_embedded.platform") |
141 ? "core/embedded_core_patch.dart" | 141 ? "core/embedded_core_patch.dart" |
142 : "core/core_patch.dart"; | 142 : "core/core_patch.dart"; |
143 } | 143 } |
144 return FLETCH_PATCHES[name]; | 144 return DARTINO_PATCHES[name]; |
145 } | 145 } |
146 | 146 |
147 @override | 147 @override |
148 Uri resolvePatchUri(String dartLibraryPath) { | 148 Uri resolvePatchUri(String dartLibraryPath) { |
149 String path = fletchPatchLibraryFor(dartLibraryPath); | 149 String path = dartinoPatchLibraryFor(dartLibraryPath); |
150 if (path == null) return null; | 150 if (path == null) return null; |
151 // Fletch patches are located relative to [libraryRoot]. | 151 // Dartino patches are located relative to [libraryRoot]. |
152 return libraryRoot.resolve(path); | 152 return libraryRoot.resolve(path); |
153 } | 153 } |
154 | 154 |
155 CompilationUnitElementX compilationUnitForUri(Uri uri) { | 155 CompilationUnitElementX compilationUnitForUri(Uri uri) { |
156 if (compilationUnits == null) { | 156 if (compilationUnits == null) { |
157 compilationUnits = <Uri, CompilationUnitElementX>{}; | 157 compilationUnits = <Uri, CompilationUnitElementX>{}; |
158 libraryLoader.libraries.forEach((LibraryElementX library) { | 158 libraryLoader.libraries.forEach((LibraryElementX library) { |
159 for (CompilationUnitElementX unit in library.compilationUnits) { | 159 for (CompilationUnitElementX unit in library.compilationUnits) { |
160 compilationUnits[unit.script.resourceUri] = unit; | 160 compilationUnits[unit.script.resourceUri] = unit; |
161 } | 161 } |
162 }); | 162 }); |
163 } | 163 } |
164 return compilationUnits[uri]; | 164 return compilationUnits[uri]; |
165 } | 165 } |
166 | 166 |
167 DebugInfo debugInfoForPosition( | 167 DebugInfo debugInfoForPosition( |
168 Uri file, | 168 Uri file, |
169 int position, | 169 int position, |
170 FletchSystem currentSystem) { | 170 DartinoSystem currentSystem) { |
171 Uri uri = Uri.base.resolveUri(file); | 171 Uri uri = Uri.base.resolveUri(file); |
172 CompilationUnitElementX unit = compilationUnitForUri(uri); | 172 CompilationUnitElementX unit = compilationUnitForUri(uri); |
173 if (unit == null) return null; | 173 if (unit == null) return null; |
174 FindPositionVisitor visitor = new FindPositionVisitor(position, unit); | 174 FindPositionVisitor visitor = new FindPositionVisitor(position, unit); |
175 unit.accept(visitor, null); | 175 unit.accept(visitor, null); |
176 FletchFunctionBuilder builder = | 176 DartinoFunctionBuilder builder = |
177 context.backend.systemBuilder.lookupFunctionBuilderByElement( | 177 context.backend.systemBuilder.lookupFunctionBuilderByElement( |
178 visitor.element); | 178 visitor.element); |
179 if (builder == null) return null; | 179 if (builder == null) return null; |
180 // TODO(ajohnsen): We need a mapping from element to functionId, that can | 180 // TODO(ajohnsen): We need a mapping from element to functionId, that can |
181 // be looked up in the current fletch system. | 181 // be looked up in the current dartino system. |
182 FletchFunction function = builder.finalizeFunction(context, []); | 182 DartinoFunction function = builder.finalizeFunction(context, []); |
183 return context.backend.createDebugInfo(function, currentSystem); | 183 return context.backend.createDebugInfo(function, currentSystem); |
184 } | 184 } |
185 | 185 |
186 int positionInFileFromPattern(Uri file, int line, String pattern) { | 186 int positionInFileFromPattern(Uri file, int line, String pattern) { |
187 Uri uri = Uri.base.resolveUri(file); | 187 Uri uri = Uri.base.resolveUri(file); |
188 SourceFile sourceFile = getSourceFile(provider, uri); | 188 SourceFile sourceFile = getSourceFile(provider, uri); |
189 if (sourceFile == null) return null; | 189 if (sourceFile == null) return null; |
190 List<int> lineStarts = sourceFile.lineStarts; | 190 List<int> lineStarts = sourceFile.lineStarts; |
191 if (line >= lineStarts.length) return null; | 191 if (line >= lineStarts.length) return null; |
192 int begin = lineStarts[line]; | 192 int begin = lineStarts[line]; |
(...skipping 30 matching lines...) Expand all Loading... |
223 MessageTemplate template = MessageTemplate.TEMPLATES[MessageKind.GENERIC]; | 223 MessageTemplate template = MessageTemplate.TEMPLATES[MessageKind.GENERIC]; |
224 SourceSpan span = reporter.spanFromSpannable(node); | 224 SourceSpan span = reporter.spanFromSpannable(node); |
225 Message message = template.message({'text': messageText}); | 225 Message message = template.message({'text': messageText}); |
226 reportDiagnostic(new DiagnosticMessage(span, node, message), | 226 reportDiagnostic(new DiagnosticMessage(span, node, message), |
227 [], api.Diagnostic.HINT); | 227 [], api.Diagnostic.HINT); |
228 } | 228 } |
229 } | 229 } |
230 | 230 |
231 @override | 231 @override |
232 void compileLoadedLibraries() { | 232 void compileLoadedLibraries() { |
233 // TODO(ahe): Ensure fletchSystemLibrary is not null | 233 // TODO(ahe): Ensure dartinoSystemLibrary is not null |
234 // (also when mainApp is null). | 234 // (also when mainApp is null). |
235 if (mainApp == null) { | 235 if (mainApp == null) { |
236 return; | 236 return; |
237 } | 237 } |
238 super.compileLoadedLibraries(); | 238 super.compileLoadedLibraries(); |
239 } | 239 } |
240 } | 240 } |
241 | 241 |
242 /// Output provider which collects output in [output]. | 242 /// Output provider which collects output in [output]. |
243 class OutputProvider implements CompilerOutput { | 243 class OutputProvider implements CompilerOutput { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 } | 277 } |
278 } | 278 } |
279 | 279 |
280 SourceFile getSourceFile(api.CompilerInput provider, Uri uri) { | 280 SourceFile getSourceFile(api.CompilerInput provider, Uri uri) { |
281 if (provider is SourceFileProvider) { | 281 if (provider is SourceFileProvider) { |
282 return provider.getSourceFile(uri); | 282 return provider.getSourceFile(uri); |
283 } else { | 283 } else { |
284 return null; | 284 return null; |
285 } | 285 } |
286 } | 286 } |
OLD | NEW |