| 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.collect.Sets; | 8 import com.google.common.collect.Sets; |
| 9 import com.google.common.collect.Sets.SetView; | 9 import com.google.common.collect.Sets.SetView; |
| 10 import com.google.common.io.CharStreams; | 10 import com.google.common.io.CharStreams; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 import com.google.dart.compiler.ast.LibraryUnit; | 22 import com.google.dart.compiler.ast.LibraryUnit; |
| 23 import com.google.dart.compiler.ast.Modifiers; | 23 import com.google.dart.compiler.ast.Modifiers; |
| 24 import com.google.dart.compiler.ast.viz.ASTWriterFactory; | 24 import com.google.dart.compiler.ast.viz.ASTWriterFactory; |
| 25 import com.google.dart.compiler.ast.viz.BaseASTWriter; | 25 import com.google.dart.compiler.ast.viz.BaseASTWriter; |
| 26 import com.google.dart.compiler.common.SourceInfo; | 26 import com.google.dart.compiler.common.SourceInfo; |
| 27 import com.google.dart.compiler.metrics.CompilerMetrics; | 27 import com.google.dart.compiler.metrics.CompilerMetrics; |
| 28 import com.google.dart.compiler.metrics.DartEventType; | 28 import com.google.dart.compiler.metrics.DartEventType; |
| 29 import com.google.dart.compiler.metrics.JvmMetrics; | 29 import com.google.dart.compiler.metrics.JvmMetrics; |
| 30 import com.google.dart.compiler.metrics.Tracer; | 30 import com.google.dart.compiler.metrics.Tracer; |
| 31 import com.google.dart.compiler.metrics.Tracer.TraceEvent; | 31 import com.google.dart.compiler.metrics.Tracer.TraceEvent; |
| 32 import com.google.dart.compiler.parser.CommentPreservingParser; | |
| 33 import com.google.dart.compiler.parser.DartParser; | 32 import com.google.dart.compiler.parser.DartParser; |
| 34 import com.google.dart.compiler.parser.DartScanner.Location; | 33 import com.google.dart.compiler.parser.DartScanner.Location; |
| 35 import com.google.dart.compiler.parser.DartScannerParserContext; | 34 import com.google.dart.compiler.parser.DartScannerParserContext; |
| 36 import com.google.dart.compiler.resolver.CompileTimeConstantResolver; | 35 import com.google.dart.compiler.resolver.CompileTimeConstantResolver; |
| 37 import com.google.dart.compiler.resolver.CoreTypeProvider; | 36 import com.google.dart.compiler.resolver.CoreTypeProvider; |
| 38 import com.google.dart.compiler.resolver.CoreTypeProviderImplementation; | 37 import com.google.dart.compiler.resolver.CoreTypeProviderImplementation; |
| 39 import com.google.dart.compiler.resolver.Element; | 38 import com.google.dart.compiler.resolver.Element; |
| 40 import com.google.dart.compiler.resolver.ElementKind; | 39 import com.google.dart.compiler.resolver.ElementKind; |
| 41 import com.google.dart.compiler.resolver.LibraryElement; | 40 import com.google.dart.compiler.resolver.LibraryElement; |
| 42 import com.google.dart.compiler.resolver.MemberBuilder; | 41 import com.google.dart.compiler.resolver.MemberBuilder; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 } | 120 } |
| 122 | 121 |
| 123 private static class Compiler { | 122 private static class Compiler { |
| 124 private final LibrarySource app; | 123 private final LibrarySource app; |
| 125 private final List<LibrarySource> embeddedLibraries = new ArrayList<LibraryS
ource>(); | 124 private final List<LibrarySource> embeddedLibraries = new ArrayList<LibraryS
ource>(); |
| 126 private final DartCompilerMainContext context; | 125 private final DartCompilerMainContext context; |
| 127 private final CompilerConfiguration config; | 126 private final CompilerConfiguration config; |
| 128 private final Map<URI, LibraryUnit> libraries = new LinkedHashMap<URI, Libra
ryUnit>(); | 127 private final Map<URI, LibraryUnit> libraries = new LinkedHashMap<URI, Libra
ryUnit>(); |
| 129 private boolean packageApp = false; | 128 private boolean packageApp = false; |
| 130 private final boolean checkOnly; | 129 private final boolean checkOnly; |
| 131 private final boolean collectComments; | |
| 132 private CoreTypeProvider typeProvider; | 130 private CoreTypeProvider typeProvider; |
| 133 private final boolean incremental; | 131 private final boolean incremental; |
| 134 private final boolean usePrecompiledDartLibs; | 132 private final boolean usePrecompiledDartLibs; |
| 135 private final List<DartCompilationPhase> phases; | 133 private final List<DartCompilationPhase> phases; |
| 136 private final List<Backend> backends; | 134 private final List<Backend> backends; |
| 137 private final LibrarySource coreLibrarySource; | 135 private final LibrarySource coreLibrarySource; |
| 138 | 136 |
| 139 private Compiler(LibrarySource app, List<LibrarySource> embedded, CompilerCo
nfiguration config, | 137 private Compiler(LibrarySource app, List<LibrarySource> embedded, CompilerCo
nfiguration config, |
| 140 DartCompilerMainContext context) { | 138 DartCompilerMainContext context) { |
| 141 this.app = app; | 139 this.app = app; |
| 142 this.config = config; | 140 this.config = config; |
| 143 this.phases = config.getPhases(); | 141 this.phases = config.getPhases(); |
| 144 this.backends = config.getBackends(); | 142 this.backends = config.getBackends(); |
| 145 this.context = context; | 143 this.context = context; |
| 146 checkOnly = config.checkOnly(); | 144 checkOnly = config.checkOnly(); |
| 147 collectComments = config.collectComments(); | |
| 148 for (LibrarySource library : embedded) { | 145 for (LibrarySource library : embedded) { |
| 149 if (SystemLibraryManager.isDartSpec(library.getName())) { | 146 if (SystemLibraryManager.isDartSpec(library.getName())) { |
| 150 embeddedLibraries.add(context.getSystemLibraryFor(library.getName())); | 147 embeddedLibraries.add(context.getSystemLibraryFor(library.getName())); |
| 151 } else { | 148 } else { |
| 152 embeddedLibraries.add(library); | 149 embeddedLibraries.add(library); |
| 153 } | 150 } |
| 154 } | 151 } |
| 155 coreLibrarySource = context.getSystemLibraryFor(CORELIB_URL_SPEC); | 152 coreLibrarySource = context.getSystemLibraryFor(CORELIB_URL_SPEC); |
| 156 embeddedLibraries.add(coreLibrarySource); | 153 embeddedLibraries.add(coreLibrarySource); |
| 157 | 154 |
| (...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 812 CompilerMetrics compilerMetrics = context.getCompilerMetrics(); | 809 CompilerMetrics compilerMetrics = context.getCompilerMetrics(); |
| 813 if (compilerMetrics != null) { | 810 if (compilerMetrics != null) { |
| 814 compilerMetrics.startPackageAppTime(); | 811 compilerMetrics.startPackageAppTime(); |
| 815 } | 812 } |
| 816 | 813 |
| 817 try { | 814 try { |
| 818 // Package output for each backend. | 815 // Package output for each backend. |
| 819 if (packageApp) { | 816 if (packageApp) { |
| 820 // When there's no entry-point in the application unit, | 817 // When there's no entry-point in the application unit, |
| 821 // don't attempt to package it. This can happen when | 818 // don't attempt to package it. This can happen when |
| 822 // compileUnit() is called on a library. Always package app | 819 // compileUnit() is called on a library. |
| 823 // when generating documentation. | 820 if (context.getApplicationUnit().getEntryNode() == null) { |
| 824 if (context.getApplicationUnit().getEntryNode() == null && !collectCom
ments) { | |
| 825 if (config.expectEntryPoint()) { | 821 if (config.expectEntryPoint()) { |
| 826 context.onError(new DartCompilationError( | 822 context.onError(new DartCompilationError( |
| 827 context.getApplicationUnit().getSource(), Location.NONE, | 823 context.getApplicationUnit().getSource(), Location.NONE, |
| 828 DartCompilerErrorCode.NO_ENTRY_POINT)); | 824 DartCompilerErrorCode.NO_ENTRY_POINT)); |
| 829 } | 825 } |
| 830 return; | 826 return; |
| 831 } | 827 } |
| 832 | 828 |
| 833 for (Backend be : backends) { | 829 for (Backend be : backends) { |
| 834 TraceEvent backendEvent = | 830 TraceEvent backendEvent = |
| (...skipping 23 matching lines...) Expand all Loading... |
| 858 String srcCode; | 854 String srcCode; |
| 859 boolean failed = true; | 855 boolean failed = true; |
| 860 try { | 856 try { |
| 861 try { | 857 try { |
| 862 srcCode = CharStreams.toString(r); | 858 srcCode = CharStreams.toString(r); |
| 863 failed = false; | 859 failed = false; |
| 864 } finally { | 860 } finally { |
| 865 Closeables.close(r, failed); | 861 Closeables.close(r, failed); |
| 866 } | 862 } |
| 867 | 863 |
| 868 DartParser parser; | 864 DartScannerParserContext parserContext = |
| 869 if (collectComments) { | 865 new DartScannerParserContext(dartSrc, srcCode, context, context.getC
ompilerMetrics()); |
| 870 DartScannerParserContext parserContext = | 866 DartParser parser = new DartParser(parserContext, libraryPrefixes, diet)
; |
| 871 CommentPreservingParser.createContext(dartSrc, srcCode, context, | |
| 872 context.getCompilerMetrics()); | |
| 873 parser = new CommentPreservingParser(parserContext, false); | |
| 874 } else { | |
| 875 DartScannerParserContext parserContext = | |
| 876 new DartScannerParserContext(dartSrc, srcCode, context, context.ge
tCompilerMetrics()); | |
| 877 parser = new DartParser(parserContext, libraryPrefixes, diet); | |
| 878 } | |
| 879 DartUnit unit = parser.parseUnit(dartSrc); | 867 DartUnit unit = parser.parseUnit(dartSrc); |
| 880 if (compilerMetrics != null) { | 868 if (compilerMetrics != null) { |
| 881 compilerMetrics.addParseTimeNano(CompilerMetrics.getThreadTime() - par
seStart); | 869 compilerMetrics.addParseTimeNano(CompilerMetrics.getThreadTime() - par
seStart); |
| 882 } | 870 } |
| 883 | 871 |
| 884 if (!config.resolveDespiteParseErrors() && context.getErrorCount() > 0)
{ | 872 if (!config.resolveDespiteParseErrors() && context.getErrorCount() > 0)
{ |
| 885 // Dump the compiler parse tree if dump format is set in arguments | 873 // Dump the compiler parse tree if dump format is set in arguments |
| 886 ASTWriterFactory.create(config).process(unit); | 874 ASTWriterFactory.create(config).process(unit); |
| 887 return null; | 875 return null; |
| 888 } | 876 } |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1306 return unit; | 1294 return unit; |
| 1307 } | 1295 } |
| 1308 } | 1296 } |
| 1309 return null; | 1297 return null; |
| 1310 } | 1298 } |
| 1311 | 1299 |
| 1312 public static LibraryUnit getCoreLib(LibraryUnit libraryUnit) { | 1300 public static LibraryUnit getCoreLib(LibraryUnit libraryUnit) { |
| 1313 return findLibrary(libraryUnit, "corelib.dart", new HashSet<LibraryElement>(
)); | 1301 return findLibrary(libraryUnit, "corelib.dart", new HashSet<LibraryElement>(
)); |
| 1314 } | 1302 } |
| 1315 } | 1303 } |
| OLD | NEW |