Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1689)

Side by Side Diff: pkg/compiler/lib/src/compiler.dart

Issue 1897863007: Make backend and reporter customizable. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Merged with 09c242e729de2e488cd36960fe2a4a882421086c Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/compiler/lib/src/common/backend_api.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 dart2js.compiler_base; 5 library dart2js.compiler_base;
6 6
7 import 'dart:async' show EventSink, Future; 7 import 'dart:async' show EventSink, Future;
8 8
9 import '../compiler_new.dart' as api; 9 import '../compiler_new.dart' as api;
10 import 'cache_strategy.dart' show CacheStrategy; 10 import 'cache_strategy.dart' show CacheStrategy;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 import 'tree/tree.dart' show Node, TypeAnnotation; 72 import 'tree/tree.dart' show Node, TypeAnnotation;
73 import 'typechecker.dart' show TypeCheckerTask; 73 import 'typechecker.dart' show TypeCheckerTask;
74 import 'types/types.dart' as ti; 74 import 'types/types.dart' as ti;
75 import 'universe/selector.dart' show Selector; 75 import 'universe/selector.dart' show Selector;
76 import 'universe/universe.dart' show Universe; 76 import 'universe/universe.dart' show Universe;
77 import 'universe/use.dart' show StaticUse; 77 import 'universe/use.dart' show StaticUse;
78 import 'universe/world_impact.dart' show ImpactStrategy, WorldImpact; 78 import 'universe/world_impact.dart' show ImpactStrategy, WorldImpact;
79 import 'util/util.dart' show Link, Setlet; 79 import 'util/util.dart' show Link, Setlet;
80 import 'world.dart' show World; 80 import 'world.dart' show World;
81 81
82 typedef Backend MakeBackendFuncion(Compiler compiler);
83
84 typedef CompilerDiagnosticReporter MakeReporterFunction(
85 Compiler compiler, CompilerOptions options);
86
82 abstract class Compiler implements LibraryLoaderListener { 87 abstract class Compiler implements LibraryLoaderListener {
83 final Stopwatch totalCompileTime = new Stopwatch(); 88 final Stopwatch totalCompileTime = new Stopwatch();
84 final IdGenerator idGenerator = new IdGenerator(); 89 final IdGenerator idGenerator = new IdGenerator();
85 World world; 90 World world;
86 Types types; 91 Types types;
87 _CompilerCoreTypes _coreTypes; 92 _CompilerCoreTypes _coreTypes;
88 _CompilerDiagnosticReporter _reporter; 93 CompilerDiagnosticReporter _reporter;
89 _CompilerResolution _resolution; 94 _CompilerResolution _resolution;
90 ParsingContext _parsingContext; 95 ParsingContext _parsingContext;
91 96
92 final CacheStrategy cacheStrategy; 97 final CacheStrategy cacheStrategy;
93 98
94 ImpactStrategy impactStrategy = const ImpactStrategy(); 99 ImpactStrategy impactStrategy = const ImpactStrategy();
95 100
96 /** 101 /**
97 * Map from token to the first preceding comment token. 102 * Map from token to the first preceding comment token.
98 */ 103 */
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 void set compilationFailed(bool value) { 279 void set compilationFailed(bool value) {
275 if (value) { 280 if (value) {
276 elementsWithCompileTimeErrors.add(currentElement); 281 elementsWithCompileTimeErrors.add(currentElement);
277 } 282 }
278 compilationFailedInternal = value; 283 compilationFailedInternal = value;
279 } 284 }
280 285
281 Compiler( 286 Compiler(
282 {CompilerOptions options, 287 {CompilerOptions options,
283 api.CompilerOutput outputProvider, 288 api.CompilerOutput outputProvider,
284 this.environment: const _EmptyEnvironment()}) 289 this.environment: const _EmptyEnvironment(),
290 MakeBackendFuncion makeBackend,
291 MakeReporterFunction makeReporter})
285 : this.options = options, 292 : this.options = options,
286 this.cacheStrategy = new CacheStrategy(options.hasIncrementalSupport), 293 this.cacheStrategy = new CacheStrategy(options.hasIncrementalSupport),
287 this.userOutputProvider = outputProvider == null 294 this.userOutputProvider = outputProvider == null
288 ? const NullCompilerOutput() 295 ? const NullCompilerOutput()
289 : outputProvider { 296 : outputProvider {
290 world = new World(this); 297 world = new World(this);
298 if (makeReporter != null) {
299 _reporter = makeReporter(this, options);
300 } else {
301 _reporter = new CompilerDiagnosticReporter(this, options);
302 }
303 _resolution = new _CompilerResolution(this);
291 // TODO(johnniwinther): Initialize core types in [initializeCoreClasses] and 304 // TODO(johnniwinther): Initialize core types in [initializeCoreClasses] and
292 // make its field final. 305 // make its field final.
293 _reporter = new _CompilerDiagnosticReporter(this, options);
294 _resolution = new _CompilerResolution(this);
295 _coreTypes = new _CompilerCoreTypes(_resolution); 306 _coreTypes = new _CompilerCoreTypes(_resolution);
296 types = new Types(_resolution); 307 types = new Types(_resolution);
297 tracer = new Tracer(this, this.outputProvider); 308 tracer = new Tracer(this, this.outputProvider);
298 309
299 if (options.verbose) { 310 if (options.verbose) {
300 progress = new Stopwatch()..start(); 311 progress = new Stopwatch()..start();
301 } 312 }
302 313
303 // TODO(johnniwinther): Separate the dependency tracking from the enqueuing 314 // TODO(johnniwinther): Separate the dependency tracking from the enqueuing
304 // for global dependencies. 315 // for global dependencies.
305 globalDependencies = new GlobalDependencyRegistry(this); 316 globalDependencies = new GlobalDependencyRegistry(this);
306 317
307 if (options.emitJavaScript) { 318 if (makeBackend != null) {
319 backend = makeBackend(this);
320 } else if (options.emitJavaScript) {
308 js_backend.JavaScriptBackend jsBackend = new js_backend.JavaScriptBackend( 321 js_backend.JavaScriptBackend jsBackend = new js_backend.JavaScriptBackend(
309 this, 322 this,
310 generateSourceMap: options.generateSourceMap, 323 generateSourceMap: options.generateSourceMap,
311 useStartupEmitter: options.useStartupEmitter, 324 useStartupEmitter: options.useStartupEmitter,
312 useNewSourceInfo: options.useNewSourceInfo); 325 useNewSourceInfo: options.useNewSourceInfo);
313 backend = jsBackend; 326 backend = jsBackend;
314 } else { 327 } else {
315 backend = new dart_backend.DartBackend(this, options.strips, 328 backend = new dart_backend.DartBackend(this, options.strips,
316 multiFile: options.dart2dartMultiFile); 329 multiFile: options.dart2dartMultiFile);
317 if (options.dumpInfo) { 330 if (options.dumpInfo) {
(...skipping 21 matching lines...) Expand all
339 environment), 352 environment),
340 parser = new ParserTask(this, options), 353 parser = new ParserTask(this, options),
341 patchParser = new PatchParserTask(this, options), 354 patchParser = new PatchParserTask(this, options),
342 resolver = createResolverTask(), 355 resolver = createResolverTask(),
343 closureToClassMapper = new closureMapping.ClosureTask(this), 356 closureToClassMapper = new closureMapping.ClosureTask(this),
344 checker = new TypeCheckerTask(this), 357 checker = new TypeCheckerTask(this),
345 typesTask = new ti.TypesTask(this), 358 typesTask = new ti.TypesTask(this),
346 constants = backend.constantCompilerTask, 359 constants = backend.constantCompilerTask,
347 deferredLoadTask = new DeferredLoadTask(this), 360 deferredLoadTask = new DeferredLoadTask(this),
348 mirrorUsageAnalyzerTask = new MirrorUsageAnalyzerTask(this), 361 mirrorUsageAnalyzerTask = new MirrorUsageAnalyzerTask(this),
349 enqueuer = new EnqueueTask(this), 362 enqueuer = backend.makeEnqueuer(),
350 dumpInfoTask = new DumpInfoTask(this), 363 dumpInfoTask = new DumpInfoTask(this),
351 reuseLibraryTask = new GenericTask('Reuse library', this), 364 reuseLibraryTask = new GenericTask('Reuse library', this),
352 ]; 365 ];
353 366
354 _parsingContext = 367 _parsingContext =
355 new ParsingContext(reporter, options, parser, patchParser, backend); 368 new ParsingContext(reporter, options, parser, patchParser, backend);
356 369
357 tasks.addAll(backend.tasks); 370 tasks.addAll(backend.tasks);
358 } 371 }
359 372
(...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after
1384 InterfaceType streamType([DartType elementType]) { 1397 InterfaceType streamType([DartType elementType]) {
1385 streamClass.ensureResolved(resolution); 1398 streamClass.ensureResolved(resolution);
1386 InterfaceType type = streamClass.rawType; 1399 InterfaceType type = streamClass.rawType;
1387 if (elementType == null) { 1400 if (elementType == null) {
1388 return type; 1401 return type;
1389 } 1402 }
1390 return type.createInstantiation([elementType]); 1403 return type.createInstantiation([elementType]);
1391 } 1404 }
1392 } 1405 }
1393 1406
1394 class _CompilerDiagnosticReporter extends DiagnosticReporter { 1407 class CompilerDiagnosticReporter extends DiagnosticReporter {
1395 final Compiler compiler; 1408 final Compiler compiler;
1396 final DiagnosticOptions options; 1409 final DiagnosticOptions options;
1397 1410
1398 Element _currentElement; 1411 Element _currentElement;
1399 bool hasCrashed = false; 1412 bool hasCrashed = false;
1400 1413
1401 /// `true` if the last diagnostic was filtered, in which case the 1414 /// `true` if the last diagnostic was filtered, in which case the
1402 /// accompanying info message should be filtered as well. 1415 /// accompanying info message should be filtered as well.
1403 bool lastDiagnosticWasFiltered = false; 1416 bool lastDiagnosticWasFiltered = false;
1404 1417
1405 /// Map containing information about the warnings and hints that have been 1418 /// Map containing information about the warnings and hints that have been
1406 /// suppressed for each library. 1419 /// suppressed for each library.
1407 Map<Uri, SuppressionInfo> suppressedWarnings = <Uri, SuppressionInfo>{}; 1420 Map<Uri, SuppressionInfo> suppressedWarnings = <Uri, SuppressionInfo>{};
1408 1421
1409 _CompilerDiagnosticReporter(this.compiler, this.options); 1422 CompilerDiagnosticReporter(this.compiler, this.options);
1410 1423
1411 Element get currentElement => _currentElement; 1424 Element get currentElement => _currentElement;
1412 1425
1413 DiagnosticMessage createMessage(Spannable spannable, MessageKind messageKind, 1426 DiagnosticMessage createMessage(Spannable spannable, MessageKind messageKind,
1414 [Map arguments = const {}]) { 1427 [Map arguments = const {}]) {
1415 SourceSpan span = spanFromSpannable(spannable); 1428 SourceSpan span = spanFromSpannable(spannable);
1416 MessageTemplate template = MessageTemplate.TEMPLATES[messageKind]; 1429 MessageTemplate template = MessageTemplate.TEMPLATES[messageKind];
1417 Message message = template.message(arguments, options.terseDiagnostics); 1430 Message message = template.message(arguments, options.terseDiagnostics);
1418 return new DiagnosticMessage(span, spannable, message); 1431 return new DiagnosticMessage(span, spannable, message);
1419 } 1432 }
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after
2016 _ElementScanner(this.scanner); 2029 _ElementScanner(this.scanner);
2017 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); 2030 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library);
2018 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); 2031 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit);
2019 } 2032 }
2020 2033
2021 class _EmptyEnvironment implements Environment { 2034 class _EmptyEnvironment implements Environment {
2022 const _EmptyEnvironment(); 2035 const _EmptyEnvironment();
2023 2036
2024 String valueOf(String key) => null; 2037 String valueOf(String key) => null;
2025 } 2038 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/common/backend_api.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698