| OLD | NEW |
| 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.driver; | 5 library analyzer.src.task.driver; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'package:analyzer/src/context/cache.dart'; | 10 import 'package:analyzer/src/context/cache.dart'; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 */ | 59 */ |
| 60 Stream<AnalysisTask> get onTaskCompleted => _onTaskCompletedController.stream; | 60 Stream<AnalysisTask> get onTaskCompleted => _onTaskCompletedController.stream; |
| 61 | 61 |
| 62 /** | 62 /** |
| 63 * The stream that is notified when a task is started. | 63 * The stream that is notified when a task is started. |
| 64 */ | 64 */ |
| 65 Stream<AnalysisTask> get onTaskStarted => _onTaskStartedController.stream; | 65 Stream<AnalysisTask> get onTaskStarted => _onTaskStartedController.stream; |
| 66 | 66 |
| 67 /** | 67 /** |
| 68 * Perform work until the given [result] has been computed for the given | 68 * Perform work until the given [result] has been computed for the given |
| 69 * [target]. | 69 * [target]. Return the last [AnalysisTask] that was performed. |
| 70 */ | 70 */ |
| 71 void computeResult(AnalysisTarget target, ResultDescriptor result) { | 71 AnalysisTask computeResult(AnalysisTarget target, ResultDescriptor result) { |
| 72 AnalysisTask task; |
| 72 WorkOrder workOrder = createWorkOrderForResult(target, result); | 73 WorkOrder workOrder = createWorkOrderForResult(target, result); |
| 73 if (workOrder != null) { | 74 if (workOrder != null) { |
| 74 while (workOrder.moveNext()) { | 75 while (workOrder.moveNext()) { |
| 75 performWorkItem(workOrder.current); | 76 task = performWorkItem(workOrder.current); |
| 76 } | 77 } |
| 77 } | 78 } |
| 79 return task; |
| 78 } | 80 } |
| 79 | 81 |
| 80 /** | 82 /** |
| 81 * Return the work order describing the work that should be getting worked on, | 83 * Return the work order describing the work that should be getting worked on, |
| 82 * or `null` if there is currently no work to be done. | 84 * or `null` if there is currently no work to be done. |
| 83 */ | 85 */ |
| 84 WorkOrder createNextWorkOrder() { | 86 WorkOrder createNextWorkOrder() { |
| 85 // | 87 // |
| 86 // TODO(brianwilkerson) This is an inefficient implementation. We need to | 88 // TODO(brianwilkerson) This is an inefficient implementation. We need to |
| 87 // port over the concept of the WorkManager to manage the list of sources | 89 // port over the concept of the WorkManager to manage the list of sources |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 } else if (currentWorkOrder.moveNext()) { | 180 } else if (currentWorkOrder.moveNext()) { |
| 179 performWorkItem(currentWorkOrder.current); | 181 performWorkItem(currentWorkOrder.current); |
| 180 } else { | 182 } else { |
| 181 currentWorkOrder = createNextWorkOrder(); | 183 currentWorkOrder = createNextWorkOrder(); |
| 182 } | 184 } |
| 183 return currentWorkOrder != null; | 185 return currentWorkOrder != null; |
| 184 } | 186 } |
| 185 | 187 |
| 186 /** | 188 /** |
| 187 * Perform the given work item. | 189 * Perform the given work item. |
| 190 * Return the performed [AnalysisTask]. |
| 188 */ | 191 */ |
| 189 void performWorkItem(WorkItem item) { | 192 AnalysisTask performWorkItem(WorkItem item) { |
| 190 if (item.exception != null) { | 193 if (item.exception != null) { |
| 191 // Mark all of the results that the task would have computed as being in | 194 // Mark all of the results that the task would have computed as being in |
| 192 // ERROR with the exception recorded on the work item. | 195 // ERROR with the exception recorded on the work item. |
| 193 CacheEntry targetEntry = context.getCacheEntry(item.target); | 196 CacheEntry targetEntry = context.getCacheEntry(item.target); |
| 194 targetEntry.setErrorState(item.exception, item.descriptor.results); | 197 targetEntry.setErrorState(item.exception, item.descriptor.results); |
| 195 return; | 198 return null; |
| 196 } | 199 } |
| 197 // Otherwise, perform the task. | 200 // Otherwise, perform the task. |
| 198 AnalysisTask task = item.buildTask(); | 201 AnalysisTask task = item.buildTask(); |
| 199 _onTaskStartedController.add(task); | 202 _onTaskStartedController.add(task); |
| 200 task.perform(); | 203 task.perform(); |
| 201 CacheEntry entry = context.getCacheEntry(task.target); | 204 CacheEntry entry = context.getCacheEntry(task.target); |
| 202 if (task.caughtException == null) { | 205 if (task.caughtException == null) { |
| 203 Map<ResultDescriptor, dynamic> outputs = task.outputs; | 206 Map<ResultDescriptor, dynamic> outputs = task.outputs; |
| 204 for (ResultDescriptor result in task.descriptor.results) { | 207 for (ResultDescriptor result in task.descriptor.results) { |
| 205 // TODO(brianwilkerson) We could check here that a value was produced | 208 // TODO(brianwilkerson) We could check here that a value was produced |
| 206 // and throw an exception if not (unless we want to allow null values). | 209 // and throw an exception if not (unless we want to allow null values). |
| 207 entry.setValue(result, outputs[result]); | 210 entry.setValue(result, outputs[result]); |
| 208 } | 211 } |
| 209 } else { | 212 } else { |
| 210 entry.setErrorState(task.caughtException, item.descriptor.results); | 213 entry.setErrorState(task.caughtException, item.descriptor.results); |
| 211 } | 214 } |
| 212 _onTaskCompletedController.add(task); | 215 _onTaskCompletedController.add(task); |
| 216 return task; |
| 213 } | 217 } |
| 214 | 218 |
| 215 /** | 219 /** |
| 216 * Reset the state of the driver in response to a change in the state of one | 220 * Reset the state of the driver in response to a change in the state of one |
| 217 * or more analysis targets. This will cause any analysis that was currently | 221 * or more analysis targets. This will cause any analysis that was currently |
| 218 * in process to be stopped and for analysis to resume based on the new state. | 222 * in process to be stopped and for analysis to resume based on the new state. |
| 219 */ | 223 */ |
| 220 void reset() { | 224 void reset() { |
| 221 currentWorkOrder = null; | 225 currentWorkOrder = null; |
| 222 } | 226 } |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 currentItem = pendingItems.removeLast(); | 405 currentItem = pendingItems.removeLast(); |
| 402 WorkItem childItem = currentItem.gatherInputs(taskManager); | 406 WorkItem childItem = currentItem.gatherInputs(taskManager); |
| 403 while (childItem != null) { | 407 while (childItem != null) { |
| 404 pendingItems.add(currentItem); | 408 pendingItems.add(currentItem); |
| 405 currentItem = childItem; | 409 currentItem = childItem; |
| 406 childItem = currentItem.gatherInputs(taskManager); | 410 childItem = currentItem.gatherInputs(taskManager); |
| 407 } | 411 } |
| 408 return true; | 412 return true; |
| 409 } | 413 } |
| 410 } | 414 } |
| OLD | NEW |