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 part of dart2js; | 5 part of dart2js; |
6 | 6 |
7 /** | 7 /** |
8 * If true, print a warning for each method that was resolved, but not | 8 * If true, print a warning for each method that was resolved, but not |
9 * compiled. | 9 * compiled. |
10 */ | 10 */ |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 World world; | 106 World world; |
107 String assembledCode; | 107 String assembledCode; |
108 Types types; | 108 Types types; |
109 | 109 |
110 final bool enableMinification; | 110 final bool enableMinification; |
111 final bool enableTypeAssertions; | 111 final bool enableTypeAssertions; |
112 final bool enableUserAssertions; | 112 final bool enableUserAssertions; |
113 final bool enableConcreteTypeInference; | 113 final bool enableConcreteTypeInference; |
114 final bool analyzeAll; | 114 final bool analyzeAll; |
115 final bool enableNativeLiveTypeAnalysis; | 115 final bool enableNativeLiveTypeAnalysis; |
116 final bool rejectDeprecatedFeatures; | |
117 final bool checkDeprecationInSdk; | |
116 | 118 |
117 bool disableInlining = false; | 119 bool disableInlining = false; |
118 | 120 |
119 final Tracer tracer; | 121 final Tracer tracer; |
120 | 122 |
121 CompilerTask measuredTask; | 123 CompilerTask measuredTask; |
122 Element _currentElement; | 124 Element _currentElement; |
123 LibraryElement coreLibrary; | 125 LibraryElement coreLibrary; |
124 LibraryElement isolateLibrary; | 126 LibraryElement isolateLibrary; |
125 LibraryElement jsHelperLibrary; | 127 LibraryElement jsHelperLibrary; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
218 Compiler({this.tracer: const Tracer(), | 220 Compiler({this.tracer: const Tracer(), |
219 this.enableTypeAssertions: false, | 221 this.enableTypeAssertions: false, |
220 this.enableUserAssertions: false, | 222 this.enableUserAssertions: false, |
221 this.enableConcreteTypeInference: false, | 223 this.enableConcreteTypeInference: false, |
222 this.enableMinification: false, | 224 this.enableMinification: false, |
223 this.enableNativeLiveTypeAnalysis: false, | 225 this.enableNativeLiveTypeAnalysis: false, |
224 bool emitJavaScript: true, | 226 bool emitJavaScript: true, |
225 bool generateSourceMap: true, | 227 bool generateSourceMap: true, |
226 bool disallowUnsafeEval: false, | 228 bool disallowUnsafeEval: false, |
227 this.analyzeAll: false, | 229 this.analyzeAll: false, |
230 this.rejectDeprecatedFeatures: false, | |
231 this.checkDeprecationInSdk: false, | |
228 List<String> strips: const []}) | 232 List<String> strips: const []}) |
229 : libraries = new Map<String, LibraryElement>(), | 233 : libraries = new Map<String, LibraryElement>(), |
230 progress = new Stopwatch() { | 234 progress = new Stopwatch() { |
231 progress.start(); | 235 progress.start(); |
232 world = new World(this); | 236 world = new World(this); |
233 scanner = new ScannerTask(this); | 237 scanner = new ScannerTask(this); |
234 dietParser = new DietParserTask(this); | 238 dietParser = new DietParserTask(this); |
235 parser = new ParserTask(this); | 239 parser = new ParserTask(this); |
236 patchParser = new PatchParserTask(this); | 240 patchParser = new PatchParserTask(this); |
237 libraryLoader = new LibraryLoaderTask(this); | 241 libraryLoader = new LibraryLoaderTask(this); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
334 } | 338 } |
335 | 339 |
336 void log(message) { | 340 void log(message) { |
337 reportDiagnostic(null, message, api.Diagnostic.VERBOSE_INFO); | 341 reportDiagnostic(null, message, api.Diagnostic.VERBOSE_INFO); |
338 } | 342 } |
339 | 343 |
340 bool run(Uri uri) { | 344 bool run(Uri uri) { |
341 try { | 345 try { |
342 runCompiler(uri); | 346 runCompiler(uri); |
343 } on CompilerCancelledException catch (exception) { | 347 } on CompilerCancelledException catch (exception) { |
344 log(exception.toString()); | 348 log('Error: $exception'); |
345 log('compilation failed'); | |
346 return false; | 349 return false; |
347 } | 350 } |
348 tracer.close(); | 351 tracer.close(); |
349 log('compilation succeeded'); | |
350 return true; | 352 return true; |
351 } | 353 } |
352 | 354 |
353 void enableNoSuchMethod(Element element) { | 355 void enableNoSuchMethod(Element element) { |
354 // TODO(ahe): Move this method to Enqueuer. | 356 // TODO(ahe): Move this method to Enqueuer. |
355 if (enabledNoSuchMethod) return; | 357 if (enabledNoSuchMethod) return; |
356 if (identical(element.getEnclosingClass(), objectClass)) { | 358 if (identical(element.getEnclosingClass(), objectClass)) { |
357 enqueuer.resolution.registerDynamicInvocationOf(element); | 359 enqueuer.resolution.registerDynamicInvocationOf(element); |
358 return; | 360 return; |
359 } | 361 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
392 // this way. | 394 // this way. |
393 withCurrentElement(dynamicClass, () { | 395 withCurrentElement(dynamicClass, () { |
394 library.addToScope(dynamicClass, this); | 396 library.addToScope(dynamicClass, this); |
395 }); | 397 }); |
396 } | 398 } |
397 } | 399 } |
398 | 400 |
399 LibraryElement scanBuiltinLibrary(String filename); | 401 LibraryElement scanBuiltinLibrary(String filename); |
400 | 402 |
401 void initializeSpecialClasses() { | 403 void initializeSpecialClasses() { |
402 bool coreLibValid = true; | 404 final List missingClasses = []; |
403 ClassElement lookupSpecialClass(SourceString name) { | 405 ClassElement lookupSpecialClass(SourceString name) { |
404 ClassElement result = coreLibrary.find(name); | 406 ClassElement result = coreLibrary.find(name); |
405 if (result == null) { | 407 if (result == null) { |
406 log('core library class $name missing'); | 408 missingClasses.add(name.slowToString()); |
407 coreLibValid = false; | |
408 } | 409 } |
409 return result; | 410 return result; |
410 } | 411 } |
411 objectClass = lookupSpecialClass(const SourceString('Object')); | 412 objectClass = lookupSpecialClass(const SourceString('Object')); |
412 boolClass = lookupSpecialClass(const SourceString('bool')); | 413 boolClass = lookupSpecialClass(const SourceString('bool')); |
413 numClass = lookupSpecialClass(const SourceString('num')); | 414 numClass = lookupSpecialClass(const SourceString('num')); |
414 intClass = lookupSpecialClass(const SourceString('int')); | 415 intClass = lookupSpecialClass(const SourceString('int')); |
415 doubleClass = lookupSpecialClass(const SourceString('double')); | 416 doubleClass = lookupSpecialClass(const SourceString('double')); |
416 stringClass = lookupSpecialClass(const SourceString('String')); | 417 stringClass = lookupSpecialClass(const SourceString('String')); |
417 functionClass = lookupSpecialClass(const SourceString('Function')); | 418 functionClass = lookupSpecialClass(const SourceString('Function')); |
418 listClass = lookupSpecialClass(const SourceString('List')); | 419 listClass = lookupSpecialClass(const SourceString('List')); |
419 typeClass = lookupSpecialClass(const SourceString('Type')); | 420 typeClass = lookupSpecialClass(const SourceString('Type')); |
420 mapClass = lookupSpecialClass(const SourceString('Map')); | 421 mapClass = lookupSpecialClass(const SourceString('Map')); |
421 jsInvocationMirrorClass = | 422 jsInvocationMirrorClass = |
422 lookupSpecialClass(const SourceString('JSInvocationMirror')); | 423 lookupSpecialClass(const SourceString('JSInvocationMirror')); |
423 closureClass = lookupSpecialClass(const SourceString('Closure')); | 424 closureClass = lookupSpecialClass(const SourceString('Closure')); |
424 dynamicClass = lookupSpecialClass(const SourceString('Dynamic_')); | 425 dynamicClass = lookupSpecialClass(const SourceString('Dynamic_')); |
425 nullClass = lookupSpecialClass(const SourceString('Null')); | 426 nullClass = lookupSpecialClass(const SourceString('Null')); |
426 types = new Types(this, dynamicClass); | 427 types = new Types(this, dynamicClass); |
427 if (!coreLibValid) { | 428 if (!missingClasses.isEmpty) { |
428 cancel('core library does not contain required classes'); | 429 cancel('core library does not contain required classes: $missingClasses'); |
429 } | 430 } |
430 } | 431 } |
431 | 432 |
432 void scanBuiltinLibraries() { | 433 void scanBuiltinLibraries() { |
433 jsHelperLibrary = scanBuiltinLibrary('_js_helper'); | 434 jsHelperLibrary = scanBuiltinLibrary('_js_helper'); |
434 interceptorsLibrary = scanBuiltinLibrary('_interceptors'); | 435 interceptorsLibrary = scanBuiltinLibrary('_interceptors'); |
435 | 436 |
436 // The core library was loaded and patched before jsHelperLibrary was | 437 // The core library was loaded and patched before jsHelperLibrary was |
437 // initialized, so it wasn't imported into those two libraries during | 438 // initialized, so it wasn't imported into those two libraries during |
438 // patching. | 439 // patching. |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
760 reportDiagnostic(span, 'Error: $message', api.Diagnostic.ERROR); | 761 reportDiagnostic(span, 'Error: $message', api.Diagnostic.ERROR); |
761 throw new CompilerCancelledException(message.toString()); | 762 throw new CompilerCancelledException(message.toString()); |
762 } | 763 } |
763 | 764 |
764 void reportMessage(SourceSpan span, Diagnostic message, api.Diagnostic kind) { | 765 void reportMessage(SourceSpan span, Diagnostic message, api.Diagnostic kind) { |
765 // TODO(ahe): The names Diagnostic and api.Diagnostic are in | 766 // TODO(ahe): The names Diagnostic and api.Diagnostic are in |
766 // conflict. Fix it. | 767 // conflict. Fix it. |
767 reportDiagnostic(span, "$message", kind); | 768 reportDiagnostic(span, "$message", kind); |
768 } | 769 } |
769 | 770 |
771 void onDeprecatedFeature(Spannable span, String feature) { | |
772 if (currentElement == null) | |
773 throw new SpannableAssertionFailure(span, feature); | |
774 if (!checkDeprecationInSdk && | |
775 currentElement.getLibrary().isPlatformLibrary) { | |
776 return; | |
777 } | |
778 var kind = rejectDeprecatedFeatures | |
779 ? api.Diagnostic.ERROR : api.Diagnostic.WARNING; | |
780 var message = rejectDeprecatedFeatures | |
781 ? MessageKind.DEPRECATED_FEATURE_ERROR.error([feature]) | |
782 : MessageKind.DEPRECATED_FEATURE_WARNING.error([feature]); | |
Johnni Winther
2012/11/19 08:37:22
The error/warning information should not be redund
ahe
2012/11/19 08:42:10
I would like to have a better API, but in general,
| |
783 reportMessage(spanFromSpannable(span), message, kind); | |
784 } | |
785 | |
770 void reportDiagnostic(SourceSpan span, String message, api.Diagnostic kind); | 786 void reportDiagnostic(SourceSpan span, String message, api.Diagnostic kind); |
771 | 787 |
772 SourceSpan spanFromTokens(Token begin, Token end, [Uri uri]) { | 788 SourceSpan spanFromTokens(Token begin, Token end, [Uri uri]) { |
773 if (begin == null || end == null) { | 789 if (begin == null || end == null) { |
774 // TODO(ahe): We can almost always do better. Often it is only | 790 // TODO(ahe): We can almost always do better. Often it is only |
775 // end that is null. Otherwise, we probably know the current | 791 // end that is null. Otherwise, we probably know the current |
776 // URI. | 792 // URI. |
777 throw 'Cannot find tokens to produce error message.'; | 793 throw 'Cannot find tokens to produce error message.'; |
778 } | 794 } |
779 if (uri == null && currentElement != null) { | 795 if (uri == null && currentElement != null) { |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
924 // TODO(johnniwinther): Use [spannable] and [message] to provide better | 940 // TODO(johnniwinther): Use [spannable] and [message] to provide better |
925 // information on assertion errors. | 941 // information on assertion errors. |
926 if (condition is Function){ | 942 if (condition is Function){ |
927 condition = condition(); | 943 condition = condition(); |
928 } | 944 } |
929 if (spannable == null || !condition) { | 945 if (spannable == null || !condition) { |
930 throw new SpannableAssertionFailure(spannable, message); | 946 throw new SpannableAssertionFailure(spannable, message); |
931 } | 947 } |
932 return true; | 948 return true; |
933 } | 949 } |
OLD | NEW |