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 leg_apiimpl; | 5 library leg_apiimpl; |
6 | 6 |
7 import 'dart:uri'; | 7 import 'dart:uri'; |
8 | 8 |
9 import '../compiler.dart' as api; | 9 import '../compiler.dart' as api; |
10 import 'dart2jslib.dart' as leg; | 10 import 'dart2jslib.dart' as leg; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 elements.LibraryElement library = | 93 elements.LibraryElement library = |
94 libraryLoader.loadLibrary(uri, null, canonicalUri); | 94 libraryLoader.loadLibrary(uri, null, canonicalUri); |
95 return library; | 95 return library; |
96 } | 96 } |
97 | 97 |
98 void log(message) { | 98 void log(message) { |
99 handler(null, null, null, message, api.Diagnostic.VERBOSE_INFO); | 99 handler(null, null, null, message, api.Diagnostic.VERBOSE_INFO); |
100 } | 100 } |
101 | 101 |
102 leg.Script readScript(Uri uri, [tree.Node node]) { | 102 leg.Script readScript(Uri uri, [tree.Node node]) { |
103 if (uri.scheme == 'dart') uri = translateDartUri(uri, node); | 103 return fileReadingTask.measure(() { |
104 var translated = translateUri(uri, node); | 104 if (uri.scheme == 'dart') uri = translateDartUri(uri, node); |
105 String text = ""; | 105 var translated = translateUri(uri, node); |
106 try { | 106 String text = ""; |
107 // TODO(ahe): We expect the future to be complete and call value | 107 try { |
108 // directly. In effect, we don't support truly asynchronous API. | 108 // TODO(ahe): We expect the future to be complete and call value |
109 text = provider(translated).value; | 109 // directly. In effect, we don't support truly asynchronous API. |
110 } catch (exception) { | 110 text = provider(translated).value; |
111 if (node != null) { | 111 } catch (exception) { |
112 cancel("$exception", node: node); | 112 if (node != null) { |
113 } else { | 113 cancel("$exception", node: node); |
114 reportDiagnostic(null, "$exception", api.Diagnostic.ERROR); | 114 } else { |
115 throw new leg.CompilerCancelledException("$exception"); | 115 reportDiagnostic(null, "$exception", api.Diagnostic.ERROR); |
| 116 throw new leg.CompilerCancelledException("$exception"); |
| 117 } |
116 } | 118 } |
117 } | 119 SourceFile sourceFile = new SourceFile(translated.toString(), text); |
118 SourceFile sourceFile = new SourceFile(translated.toString(), text); | 120 return new leg.Script(uri, sourceFile); |
119 return new leg.Script(uri, sourceFile); | 121 }); |
120 } | 122 } |
121 | 123 |
122 Uri translateUri(Uri uri, tree.Node node) { | 124 Uri translateUri(Uri uri, tree.Node node) { |
123 switch (uri.scheme) { | 125 switch (uri.scheme) { |
124 case 'package': return translatePackageUri(uri, node); | 126 case 'package': return translatePackageUri(uri, node); |
125 default: return uri; | 127 default: return uri; |
126 } | 128 } |
127 } | 129 } |
128 | 130 |
129 Uri translateDartUri(Uri uri, tree.Node node) { | 131 Uri translateDartUri(Uri uri, tree.Node node) { |
(...skipping 19 matching lines...) Expand all Loading... |
149 Uri resolvePatchUri(String dartLibraryPath) { | 151 Uri resolvePatchUri(String dartLibraryPath) { |
150 String patchPath = lookupPatchPath(dartLibraryPath); | 152 String patchPath = lookupPatchPath(dartLibraryPath); |
151 if (patchPath == null) return null; | 153 if (patchPath == null) return null; |
152 return libraryRoot.resolve(patchPath); | 154 return libraryRoot.resolve(patchPath); |
153 } | 155 } |
154 | 156 |
155 translatePackageUri(Uri uri, tree.Node node) => packageRoot.resolve(uri.path); | 157 translatePackageUri(Uri uri, tree.Node node) => packageRoot.resolve(uri.path); |
156 | 158 |
157 bool run(Uri uri) { | 159 bool run(Uri uri) { |
158 bool success = super.run(uri); | 160 bool success = super.run(uri); |
| 161 int cumulated = 0; |
159 for (final task in tasks) { | 162 for (final task in tasks) { |
| 163 cumulated += task.timing; |
160 log('${task.name} took ${task.timing}msec'); | 164 log('${task.name} took ${task.timing}msec'); |
161 } | 165 } |
| 166 int total = totalCompileTime.elapsedMilliseconds; |
| 167 log('Total compile-time ${total}msec;' |
| 168 ' unaccounted ${total - cumulated}msec'); |
162 return success; | 169 return success; |
163 } | 170 } |
164 | 171 |
165 void reportDiagnostic(leg.SourceSpan span, String message, | 172 void reportDiagnostic(leg.SourceSpan span, String message, |
166 api.Diagnostic kind) { | 173 api.Diagnostic kind) { |
167 if (identical(kind, api.Diagnostic.ERROR) | 174 if (identical(kind, api.Diagnostic.ERROR) |
168 || identical(kind, api.Diagnostic.CRASH)) { | 175 || identical(kind, api.Diagnostic.CRASH)) { |
169 compilationFailed = true; | 176 compilationFailed = true; |
170 } | 177 } |
171 // [:span.uri:] might be [:null:] in case of a [Script] with no [uri]. For | 178 // [:span.uri:] might be [:null:] in case of a [Script] with no [uri]. For |
172 // instance in the [Types] constructor in typechecker.dart. | 179 // instance in the [Types] constructor in typechecker.dart. |
173 if (span == null || span.uri == null) { | 180 if (span == null || span.uri == null) { |
174 handler(null, null, null, message, kind); | 181 handler(null, null, null, message, kind); |
175 } else { | 182 } else { |
176 handler(translateUri(span.uri, null), span.begin, span.end, | 183 handler(translateUri(span.uri, null), span.begin, span.end, |
177 message, kind); | 184 message, kind); |
178 } | 185 } |
179 } | 186 } |
180 | 187 |
181 bool get isMockCompilation { | 188 bool get isMockCompilation { |
182 return mockableLibraryUsed | 189 return mockableLibraryUsed |
183 && (options.indexOf('--allow-mock-compilation') != -1); | 190 && (options.indexOf('--allow-mock-compilation') != -1); |
184 } | 191 } |
185 } | 192 } |
OLD | NEW |