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

Side by Side Diff: pkg/analyzer/lib/src/task/dart.dart

Issue 1322983002: Implement task to infer instance members (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 analyzer.src.task.dart; 5 library analyzer.src.task.dart;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/src/context/cache.dart'; 9 import 'package:analyzer/src/context/cache.dart';
10 import 'package:analyzer/src/generated/ast.dart'; 10 import 'package:analyzer/src/generated/ast.dart';
(...skipping 2392 matching lines...) Expand 10 before | Expand all | Expand 10 after
2403 * Create a [GenerateHintsTask] based on the given [target] in 2403 * Create a [GenerateHintsTask] based on the given [target] in
2404 * the given [context]. 2404 * the given [context].
2405 */ 2405 */
2406 static GenerateHintsTask createTask( 2406 static GenerateHintsTask createTask(
2407 AnalysisContext context, AnalysisTarget target) { 2407 AnalysisContext context, AnalysisTarget target) {
2408 return new GenerateHintsTask(context, target); 2408 return new GenerateHintsTask(context, target);
2409 } 2409 }
2410 } 2410 }
2411 2411
2412 /** 2412 /**
2413 * A task that ensures that all of the inferrable instance members in a
2414 * compilation unit have had their type inferred.
2415 */
2416 class InferInstanceMembersInUnitTask extends SourceBasedAnalysisTask {
2417 /**
2418 * The name of the [TYPE_PROVIDER] input.
2419 */
2420 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT';
2421
2422 /**
2423 * The name of the input whose value is the [RESOLVED_UNIT6] for the
2424 * compilation unit.
2425 */
2426 static const String UNIT_INPUT = 'UNIT_INPUT';
2427
2428 /**
2429 * The task descriptor describing this kind of task.
2430 */
2431 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
2432 'InferInstanceMembersInUnitTask',
2433 createTask,
2434 buildInputs,
2435 <ResultDescriptor>[RESOLVED_UNIT7]);
2436
2437 /**
2438 * Initialize a newly created task to build a library element for the given
2439 * [unit] in the given [context].
2440 */
2441 InferInstanceMembersInUnitTask(
2442 InternalAnalysisContext context, LibrarySpecificUnit unit)
2443 : super(context, unit);
2444
2445 @override
2446 TaskDescriptor get descriptor => DESCRIPTOR;
2447
2448 @override
2449 void internalPerform() {
2450 //
2451 // Prepare inputs.
2452 //
2453 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
2454 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
2455 //
2456 // Infer instance members.
2457 //
2458 if (context.analysisOptions.strongMode) {
2459 InstanceMemberInferrer inferrer =
2460 new InstanceMemberInferrer(typeProvider);
2461 inferrer.inferCompilationUnit(unit.element);
2462 }
2463 //
2464 // Record outputs.
2465 //
2466 outputs[RESOLVED_UNIT7] = unit;
2467 }
2468
2469 /**
2470 * Return a map from the names of the inputs of this kind of task to the task
2471 * input descriptors describing those inputs for a task with the given
2472 * [libSource].
2473 */
2474 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
2475 LibrarySpecificUnit unit = target;
2476 return <String, TaskInput>{
2477 UNIT_INPUT: RESOLVED_UNIT6.of(unit),
2478 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request)
2479 };
2480 }
2481
2482 /**
2483 * Create a [InferInstanceMembersInUnitTask] based on the given [target] in
2484 * the given [context].
2485 */
2486 static InferInstanceMembersInUnitTask createTask(
2487 AnalysisContext context, AnalysisTarget target) {
2488 return new InferInstanceMembersInUnitTask(context, target);
2489 }
2490 }
2491
2492 /**
2413 * An abstract class that defines utility methods that are useful for tasks 2493 * An abstract class that defines utility methods that are useful for tasks
2414 * operating on static variables. 2494 * operating on static variables.
2415 */ 2495 */
2416 abstract class InferStaticVariableTask extends ConstantEvaluationAnalysisTask { 2496 abstract class InferStaticVariableTask extends ConstantEvaluationAnalysisTask {
2417 InferStaticVariableTask( 2497 InferStaticVariableTask(
2418 InternalAnalysisContext context, VariableElement variable) 2498 InternalAnalysisContext context, VariableElement variable)
2419 : super(context, variable); 2499 : super(context, variable);
2420 2500
2421 /** 2501 /**
2422 * Return the declaration of the target within the given compilation [unit]. 2502 * Return the declaration of the target within the given compilation [unit].
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
2496 LibrarySpecificUnit unit = target; 2576 LibrarySpecificUnit unit = target;
2497 return <String, TaskInput>{ 2577 return <String, TaskInput>{
2498 INFERRED_VARIABLES_INPUT: INFERABLE_STATIC_VARIABLES_IN_UNIT 2578 INFERRED_VARIABLES_INPUT: INFERABLE_STATIC_VARIABLES_IN_UNIT
2499 .of(unit) 2579 .of(unit)
2500 .toListOf(INFERRED_STATIC_VARIABLE), 2580 .toListOf(INFERRED_STATIC_VARIABLE),
2501 UNIT_INPUT: RESOLVED_UNIT5.of(unit) 2581 UNIT_INPUT: RESOLVED_UNIT5.of(unit)
2502 }; 2582 };
2503 } 2583 }
2504 2584
2505 /** 2585 /**
2506 * Create a [InferStaticVariableTypesInUnitTask] based on the given [target] i n the 2586 * Create a [InferStaticVariableTypesInUnitTask] based on the given [target]
2507 * given [context]. 2587 * in the given [context].
2508 */ 2588 */
2509 static InferStaticVariableTypesInUnitTask createTask( 2589 static InferStaticVariableTypesInUnitTask createTask(
2510 AnalysisContext context, AnalysisTarget target) { 2590 AnalysisContext context, AnalysisTarget target) {
2511 return new InferStaticVariableTypesInUnitTask(context, target); 2591 return new InferStaticVariableTypesInUnitTask(context, target);
2512 } 2592 }
2513 } 2593 }
2514 2594
2515 /** 2595 /**
2516 * A task that computes the type of an inferrable static variable and 2596 * A task that computes the type of an inferrable static variable and
2517 * stores it in the element model. 2597 * stores it in the element model.
(...skipping 1432 matching lines...) Expand 10 before | Expand all | Expand 10 after
3950 4030
3951 @override 4031 @override
3952 bool moveNext() { 4032 bool moveNext() {
3953 if (_newSources.isEmpty) { 4033 if (_newSources.isEmpty) {
3954 return false; 4034 return false;
3955 } 4035 }
3956 currentTarget = _newSources.removeLast(); 4036 currentTarget = _newSources.removeLast();
3957 return true; 4037 return true;
3958 } 4038 }
3959 } 4039 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698