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 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 } | 124 } |
125 | 125 |
126 private static class Compiler { | 126 private static class Compiler { |
127 private final LibrarySource app; | 127 private final LibrarySource app; |
128 private final List<LibrarySource> embeddedLibraries = new ArrayList<LibraryS
ource>(); | 128 private final List<LibrarySource> embeddedLibraries = new ArrayList<LibraryS
ource>(); |
129 private final DartCompilerMainContext context; | 129 private final DartCompilerMainContext context; |
130 private final CompilerConfiguration config; | 130 private final CompilerConfiguration config; |
131 private final Map<URI, LibraryUnit> libraries = new LinkedHashMap<URI, Libra
ryUnit>(); | 131 private final Map<URI, LibraryUnit> libraries = new LinkedHashMap<URI, Libra
ryUnit>(); |
132 private CoreTypeProvider typeProvider; | 132 private CoreTypeProvider typeProvider; |
133 private final boolean incremental; | 133 private final boolean incremental; |
134 private final boolean usePrecompiledDartLibs; | |
135 private final List<DartCompilationPhase> phases; | 134 private final List<DartCompilationPhase> phases; |
136 private final LibrarySource coreLibrarySource; | 135 private final LibrarySource coreLibrarySource; |
137 | 136 |
138 private Compiler(LibrarySource app, List<LibrarySource> embedded, CompilerCo
nfiguration config, | 137 private Compiler(LibrarySource app, List<LibrarySource> embedded, CompilerCo
nfiguration config, |
139 DartCompilerMainContext context) { | 138 DartCompilerMainContext context) { |
140 this.app = app; | 139 this.app = app; |
141 this.config = config; | 140 this.config = config; |
142 this.phases = config.getPhases(); | 141 this.phases = config.getPhases(); |
143 this.context = context; | 142 this.context = context; |
144 for (LibrarySource library : embedded) { | 143 for (LibrarySource library : embedded) { |
145 if (SystemLibraryManager.isDartSpec(library.getName())) { | 144 if (SystemLibraryManager.isDartSpec(library.getName())) { |
146 embeddedLibraries.add(context.getSystemLibraryFor(library.getName())); | 145 embeddedLibraries.add(context.getSystemLibraryFor(library.getName())); |
147 } else { | 146 } else { |
148 embeddedLibraries.add(library); | 147 embeddedLibraries.add(library); |
149 } | 148 } |
150 } | 149 } |
151 coreLibrarySource = context.getSystemLibraryFor(CORELIB_URL_SPEC); | 150 coreLibrarySource = context.getSystemLibraryFor(CORELIB_URL_SPEC); |
152 embeddedLibraries.add(coreLibrarySource); | 151 embeddedLibraries.add(coreLibrarySource); |
153 | 152 |
154 incremental = config.incremental(); | 153 incremental = config.incremental(); |
155 usePrecompiledDartLibs = true; | |
156 } | 154 } |
157 | 155 |
158 void addResolvedLibraries(Map<URI, LibraryUnit> resolvedLibraries) { | 156 void addResolvedLibraries(Map<URI, LibraryUnit> resolvedLibraries) { |
159 libraries.putAll(resolvedLibraries); | 157 libraries.putAll(resolvedLibraries); |
160 } | 158 } |
161 | 159 |
162 Map<URI, LibraryUnit> getLibraries() { | 160 Map<URI, LibraryUnit> getLibraries() { |
163 return libraries; | 161 return libraries; |
164 } | 162 } |
165 | 163 |
166 private void compile() { | 164 private void compile() { |
167 TraceEvent logEvent = Tracer.canTrace() ? Tracer.start(DartEventType.COMPI
LE) : null; | 165 TraceEvent logEvent = Tracer.canTrace() ? Tracer.start(DartEventType.COMPI
LE) : null; |
168 try { | 166 try { |
169 updateAndResolve(); | 167 updateAndResolve(); |
170 if (!config.resolveDespiteParseErrors() && context.getErrorCount() > 0)
{ | 168 if (!config.resolveDespiteParseErrors() && context.getErrorCount() > 0)
{ |
171 return; | 169 return; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 | 245 |
248 // Prepare DartSource for "#source" unit. | 246 // Prepare DartSource for "#source" unit. |
249 final DartSource dartSrc = libSrc.getSourceFor(relPath); | 247 final DartSource dartSrc = libSrc.getSourceFor(relPath); |
250 if (dartSrc == null || !dartSrc.exists()) { | 248 if (dartSrc == null || !dartSrc.exists()) { |
251 // Dart Editor needs to have all missing files reported as compila
tion errors. | 249 // Dart Editor needs to have all missing files reported as compila
tion errors. |
252 reportMissingSource(context, libSrc, libNode); | 250 reportMissingSource(context, libSrc, libNode); |
253 continue; | 251 continue; |
254 } | 252 } |
255 | 253 |
256 if (!incremental | 254 if (!incremental |
257 || (libIsDartUri && !usePrecompiledDartLibs) | 255 || libIsDartUri |
258 || isSourceOutOfDate(dartSrc)) { | 256 || isSourceOutOfDate(dartSrc)) { |
259 DartUnit unit = parse(dartSrc, lib.getPrefixes(), false); | 257 DartUnit unit = parse(dartSrc, lib.getPrefixes(), false); |
260 | 258 |
261 // If we just parsed unit of library, report problems with its "#i
mport" declarations. | 259 // If we just parsed unit of library, report problems with its "#i
mport" declarations. |
262 if (libNode == selfSourcePath) { | 260 if (libNode == selfSourcePath) { |
263 for (LibraryNode importPathNode : lib.getImportPaths()) { | 261 for (LibraryNode importPathNode : lib.getImportPaths()) { |
264 LibrarySource dep = getImportSource(libSrc, importPathNode); | 262 LibrarySource dep = getImportSource(libSrc, importPathNode); |
265 if (dep == null) { | 263 if (dep == null) { |
266 reportMissingSource(context, libSrc, importPathNode); | 264 reportMissingSource(context, libSrc, importPathNode); |
267 } | 265 } |
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
844 event.setSource(libSrc); | 842 event.setSource(libSrc); |
845 context.onError(event); | 843 context.onError(event); |
846 } | 844 } |
847 CoreTypeProvider getTypeProvider() { | 845 CoreTypeProvider getTypeProvider() { |
848 typeProvider.getClass(); // Quick null check. | 846 typeProvider.getClass(); // Quick null check. |
849 return typeProvider; | 847 return typeProvider; |
850 } | 848 } |
851 } | 849 } |
852 | 850 |
853 /** | 851 /** |
854 * Selectively compile a library. Use supplied libraries and ASTs when availab
le. | 852 * Selectively compile a library. Use supplied libraries and ASTs when availab
le. |
855 * This allows programming tools to provide customized ASTs for code that is c
urrently being | 853 * This allows programming tools to provide customized ASTs for code that is c
urrently being |
856 * edited, and may not compile correctly. | 854 * edited, and may not compile correctly. |
857 */ | 855 */ |
858 private static class SelectiveCompiler extends Compiler { | 856 private static class SelectiveCompiler extends Compiler { |
859 /** Map from source URI to AST representing the source */ | 857 /** Map from source URI to AST representing the source */ |
860 private final Map<URI, LibraryUnit> resolvedLibraries; | 858 private final Map<URI, LibraryUnit> resolvedLibraries; |
861 private final Map<URI,DartUnit> parsedUnits; | 859 private final Map<URI,DartUnit> parsedUnits; |
862 private Collection<LibraryUnit> librariesToProcess; | 860 private Collection<LibraryUnit> librariesToProcess; |
863 | 861 |
864 private SelectiveCompiler(LibrarySource app, Map<URI, LibraryUnit> resolvedL
ibraries, | 862 private SelectiveCompiler(LibrarySource app, Map<URI, LibraryUnit> resolvedL
ibraries, |
865 Map<URI,DartUnit> parsedUnits, CompilerConfiguration config, | 863 Map<URI,DartUnit> parsedUnits, CompilerConfiguration config, |
866 DartCompilerMainContext context) { | 864 DartCompilerMainContext context) { |
867 super(app, Collections.<LibrarySource>emptyList(), config, context); | 865 super(app, Collections.<LibrarySource>emptyList(), config, context); |
868 this.resolvedLibraries = resolvedLibraries; | 866 this.resolvedLibraries = resolvedLibraries; |
869 this.parsedUnits = parsedUnits; | 867 this.parsedUnits = parsedUnits; |
870 addResolvedLibraries(resolvedLibraries); | 868 addResolvedLibraries(resolvedLibraries); |
871 } | 869 } |
872 | 870 |
873 @Override | 871 @Override |
874 Collection<LibraryUnit> getLibrariesToProcess() { | 872 Collection<LibraryUnit> getLibrariesToProcess() { |
875 if (librariesToProcess == null) { | 873 if (librariesToProcess == null) { |
876 librariesToProcess = new ArrayList<LibraryUnit>(); | 874 librariesToProcess = new ArrayList<LibraryUnit>(); |
877 librariesToProcess.addAll(super.getLibrariesToProcess()); | 875 librariesToProcess.addAll(super.getLibrariesToProcess()); |
878 librariesToProcess.removeAll(resolvedLibraries.values()); | 876 librariesToProcess.removeAll(resolvedLibraries.values()); |
879 } | 877 } |
880 return librariesToProcess; | 878 return librariesToProcess; |
881 } | 879 } |
882 | 880 |
(...skipping 21 matching lines...) Expand all Loading... |
904 } catch (CmdLineException e) { | 902 } catch (CmdLineException e) { |
905 System.err.println(e.getLocalizedMessage()); | 903 System.err.println(e.getLocalizedMessage()); |
906 showUsage(cmdLineParser, System.err); | 904 showUsage(cmdLineParser, System.err); |
907 System.exit(1); | 905 System.exit(1); |
908 } | 906 } |
909 | 907 |
910 assert compilerOptions != null; | 908 assert compilerOptions != null; |
911 return compilerOptions; | 909 return compilerOptions; |
912 } | 910 } |
913 | 911 |
914 public static void main(String[] args) { | 912 public static void main(final String[] topArgs) { |
915 Tracer.init(); | 913 Tracer.init(); |
916 | 914 |
917 CompilerOptions topCompilerOptions = processCommandLineOptions(args); | 915 CompilerOptions topCompilerOptions = processCommandLineOptions(topArgs); |
918 boolean result = false; | 916 boolean result = false; |
919 try { | 917 try { |
920 if (topCompilerOptions.shouldBatch()) { | 918 if (topCompilerOptions.shouldBatch()) { |
921 if (args.length > 1) { | 919 if (topArgs.length > 1) { |
922 System.err.println("(Extra arguments specified with -batch ignored.)")
; | 920 System.err.println("(Extra arguments specified with -batch ignored.)")
; |
923 } | 921 } |
924 UnitTestBatchRunner.runAsBatch(args, new Invocation() { | 922 UnitTestBatchRunner.runAsBatch(topArgs, new Invocation() { |
925 @Override | 923 @Override |
926 public boolean invoke(String[] args) throws Throwable { | 924 public boolean invoke(String[] lineArgs) throws Throwable { |
927 CompilerOptions compilerOptions = processCommandLineOptions(args); | 925 List<String> allArgs = new ArrayList<String>(); |
| 926 for (String arg: topArgs) { |
| 927 if (!arg.equals("-batch")) { |
| 928 allArgs.add(arg); |
| 929 } |
| 930 } |
| 931 for (String arg: lineArgs) { |
| 932 allArgs.add(arg); |
| 933 } |
| 934 |
| 935 CompilerOptions compilerOptions = processCommandLineOptions( |
| 936 allArgs.toArray(new String[allArgs.size()])); |
928 if (compilerOptions.shouldBatch()) { | 937 if (compilerOptions.shouldBatch()) { |
929 System.err.println("-batch ignored: Already in batch mode."); | 938 System.err.println("-batch ignored: Already in batch mode."); |
930 } | 939 } |
931 return compilerMain(compilerOptions); | 940 return compilerMain(compilerOptions); |
932 } | 941 } |
933 }); | 942 }); |
934 } else { | 943 } else { |
935 result = compilerMain(topCompilerOptions); | 944 result = compilerMain(topCompilerOptions); |
936 } | 945 } |
937 } catch (Throwable t) { | 946 } catch (Throwable t) { |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1233 return unit; | 1242 return unit; |
1234 } | 1243 } |
1235 } | 1244 } |
1236 return null; | 1245 return null; |
1237 } | 1246 } |
1238 | 1247 |
1239 public static LibraryUnit getCoreLib(LibraryUnit libraryUnit) { | 1248 public static LibraryUnit getCoreLib(LibraryUnit libraryUnit) { |
1240 return findLibrary(libraryUnit, "dart:core", new HashSet<LibraryElement>()); | 1249 return findLibrary(libraryUnit, "dart:core", new HashSet<LibraryElement>()); |
1241 } | 1250 } |
1242 } | 1251 } |
OLD | NEW |