| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 package com.google.dart.compiler; | 5 package com.google.dart.compiler; |
| 6 | 6 |
| 7 import com.google.common.collect.Lists; | 7 import com.google.common.collect.Lists; |
| 8 import com.google.common.io.CharStreams; | 8 import com.google.common.io.CharStreams; |
| 9 import com.google.common.io.Closeables; | 9 import com.google.common.io.Closeables; |
| 10 import com.google.common.io.Files; | 10 import com.google.common.io.Files; |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 | 349 |
| 350 libraries.put(libSrc.getUri(), lib); | 350 libraries.put(libSrc.getUri(), lib); |
| 351 | 351 |
| 352 // Update dependencies. | 352 // Update dependencies. |
| 353 for (LibraryNode libNode : lib.getImportPaths()) { | 353 for (LibraryNode libNode : lib.getImportPaths()) { |
| 354 String libSpec = libNode.getText(); | 354 String libSpec = libNode.getText(); |
| 355 LibrarySource dep; | 355 LibrarySource dep; |
| 356 if (SystemLibraryManager.isDartSpec(libSpec)) { | 356 if (SystemLibraryManager.isDartSpec(libSpec)) { |
| 357 dep = context.getSystemLibraryFor(libSpec); | 357 dep = context.getSystemLibraryFor(libSpec); |
| 358 } else { | 358 } else { |
| 359 dep = libSrc.getImportFor(libSpec); | 359 try { |
| 360 dep = libSrc.getImportFor(libSpec); |
| 361 } catch (IllegalArgumentException ex) { |
| 362 reportImportError(context, libSrc, libNode); |
| 363 continue; |
| 364 } |
| 360 } | 365 } |
| 361 if (dep == null) { | 366 if (dep == null) { |
| 362 reportMissingSource(context, libSrc, libNode); | 367 reportMissingSource(context, libSrc, libNode); |
| 363 continue; | 368 continue; |
| 364 } | 369 } |
| 365 | 370 |
| 366 lib.addImport(updateLibraries(dep), libNode); | 371 lib.addImport(updateLibraries(dep), libNode); |
| 367 } | 372 } |
| 368 return lib; | 373 return lib; |
| 369 } finally { | 374 } finally { |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 Tracer.canTrace() ? Tracer.start(DartEventType.COMPILE_LIBRARIES) : nu
ll; | 672 Tracer.canTrace() ? Tracer.start(DartEventType.COMPILE_LIBRARIES) : nu
ll; |
| 668 | 673 |
| 669 CompilerMetrics compilerMetrics = context.getCompilerMetrics(); | 674 CompilerMetrics compilerMetrics = context.getCompilerMetrics(); |
| 670 if (compilerMetrics != null) { | 675 if (compilerMetrics != null) { |
| 671 compilerMetrics.startCompileLibrariesTime(); | 676 compilerMetrics.startCompileLibrariesTime(); |
| 672 } | 677 } |
| 673 | 678 |
| 674 try { | 679 try { |
| 675 // Set entry point | 680 // Set entry point |
| 676 setEntryPoint(); | 681 setEntryPoint(); |
| 677 | 682 |
| 678 // Dump the compiler parse tree if dump format is set in arguments | 683 // Dump the compiler parse tree if dump format is set in arguments |
| 679 BaseASTWriter astWriter = ASTWriterFactory.create(config); | 684 BaseASTWriter astWriter = ASTWriterFactory.create(config); |
| 680 | 685 |
| 681 // The two following for loops can be parallelized. | 686 // The two following for loops can be parallelized. |
| 682 for (LibraryUnit lib : libraries.values()) { | 687 for (LibraryUnit lib : libraries.values()) { |
| 683 boolean persist = false; | 688 boolean persist = false; |
| 684 | 689 |
| 685 // Compile all the units in this library. | 690 // Compile all the units in this library. |
| 686 for (DartUnit unit : lib.getUnits()) { | 691 for (DartUnit unit : lib.getUnits()) { |
| 687 | 692 |
| 688 if(astWriter != null) { | 693 if(astWriter != null) { |
| 689 astWriter.process(unit); | 694 astWriter.process(unit); |
| 690 } | 695 } |
| 691 | 696 |
| 692 // Don't compile api-only units. | 697 // Don't compile api-only units. |
| 693 if (unit.isDiet()) { | 698 if (unit.isDiet()) { |
| 694 continue; | 699 continue; |
| 695 } | 700 } |
| 696 | 701 |
| 697 // Run all compiler phases including AST simplification and symbol | 702 // Run all compiler phases including AST simplification and symbol |
| 698 // resolution. This must run in serial. | 703 // resolution. This must run in serial. |
| 699 for (DartCompilationPhase phase : phases) { | 704 for (DartCompilationPhase phase : phases) { |
| 700 TraceEvent phaseEvent = | 705 TraceEvent phaseEvent = |
| 701 Tracer.canTrace() ? Tracer.start(DartEventType.EXEC_PHASE, "ph
ase", phase | 706 Tracer.canTrace() ? Tracer.start(DartEventType.EXEC_PHASE, "ph
ase", phase |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 private void reportMissingSource(DartCompilerContext context, | 848 private void reportMissingSource(DartCompilerContext context, |
| 844 LibrarySource libSrc, | 849 LibrarySource libSrc, |
| 845 LibraryNode libNode) { | 850 LibraryNode libNode) { |
| 846 DartCompilationError event = new DartCompilationError(libNode, | 851 DartCompilationError event = new DartCompilationError(libNode, |
| 847 DartCompilerErrorCod
e.MISSING_SOURCE, | 852 DartCompilerErrorCod
e.MISSING_SOURCE, |
| 848 libNode.getText()); | 853 libNode.getText()); |
| 849 event.setSource(libSrc); | 854 event.setSource(libSrc); |
| 850 context.onError(event); | 855 context.onError(event); |
| 851 } | 856 } |
| 852 | 857 |
| 858 private void reportImportError(DartCompilerContext context, |
| 859 LibrarySource libSrc, |
| 860 LibraryNode libNode) { |
| 861 DartCompilationError event = new DartCompilationError(libNode, |
| 862 DartCompilerErrorCode.COULD_NOT_PARSE_IMPORT, libNode.getText()); |
| 863 event.setSource(libSrc); |
| 864 context.onError(event); |
| 865 } |
| 853 CoreTypeProvider getTypeProvider() { | 866 CoreTypeProvider getTypeProvider() { |
| 854 typeProvider.getClass(); // Quick null check. | 867 typeProvider.getClass(); // Quick null check. |
| 855 return typeProvider; | 868 return typeProvider; |
| 856 } | 869 } |
| 857 } | 870 } |
| 858 | 871 |
| 859 /** | 872 /** |
| 860 * Selectively compile a library. Use supplied ASTs when available. This allow
s programming | 873 * Selectively compile a library. Use supplied ASTs when available. This allow
s programming |
| 861 * tools to provide customized ASTs for code that is currently being edited, a
nd may not | 874 * tools to provide customized ASTs for code that is currently being edited, a
nd may not |
| 862 * compile correctly. | 875 * compile correctly. |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1244 return unit; | 1257 return unit; |
| 1245 } | 1258 } |
| 1246 } | 1259 } |
| 1247 return null; | 1260 return null; |
| 1248 } | 1261 } |
| 1249 | 1262 |
| 1250 public static LibraryUnit getCoreLib(LibraryUnit libraryUnit) { | 1263 public static LibraryUnit getCoreLib(LibraryUnit libraryUnit) { |
| 1251 return findLibrary(libraryUnit, "corelib.dart", new HashSet<LibraryElement>(
)); | 1264 return findLibrary(libraryUnit, "corelib.dart", new HashSet<LibraryElement>(
)); |
| 1252 } | 1265 } |
| 1253 } | 1266 } |
| OLD | NEW |