| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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.summary.summary_file_builder; | 5 library analyzer.src.summary.summary_file_builder; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| 11 import 'package:analyzer/dart/element/element.dart'; | 11 import 'package:analyzer/dart/element/element.dart'; |
| 12 import 'package:analyzer/src/generated/engine.dart'; | 12 import 'package:analyzer/src/generated/engine.dart'; |
| 13 import 'package:analyzer/src/generated/java_io.dart'; | 13 import 'package:analyzer/src/generated/java_io.dart'; |
| 14 import 'package:analyzer/src/generated/sdk.dart'; | 14 import 'package:analyzer/src/generated/sdk.dart'; |
| 15 import 'package:analyzer/src/generated/sdk_io.dart'; | 15 import 'package:analyzer/src/generated/sdk_io.dart'; |
| 16 import 'package:analyzer/src/generated/source.dart'; | 16 import 'package:analyzer/src/generated/source.dart'; |
| 17 import 'package:analyzer/src/summary/flat_buffers.dart' as fb; |
| 17 import 'package:analyzer/src/summary/index_unit.dart'; | 18 import 'package:analyzer/src/summary/index_unit.dart'; |
| 18 import 'package:analyzer/src/summary/summarize_elements.dart'; | 19 import 'package:analyzer/src/summary/summarize_elements.dart'; |
| 19 import 'package:path/path.dart'; | 20 import 'package:path/path.dart'; |
| 20 | 21 |
| 22 const int FIELD_SPEC_INDEX = 1; |
| 23 const int FIELD_SPEC_SUM = 0; |
| 24 const int FIELD_STRONG_INDEX = 3; |
| 25 const int FIELD_STRONG_SUM = 2; |
| 26 |
| 21 class BuilderOutput { | 27 class BuilderOutput { |
| 22 final List<int> sum; | 28 final List<int> sum; |
| 23 final List<int> index; | 29 final List<int> index; |
| 24 | 30 |
| 25 BuilderOutput(this.sum, this.index); | 31 BuilderOutput(this.sum, this.index); |
| 26 | 32 |
| 27 void writeMultiple(String outputDirectoryPath, String modeName) { | 33 void writeMultiple(String outputDirectoryPath, String modeName) { |
| 28 // Write summary. | 34 // Write summary. |
| 29 { | 35 { |
| 30 String outputPath = join(outputDirectoryPath, '$modeName.sum'); | 36 String outputPath = join(outputDirectoryPath, '$modeName.sum'); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 for (String uri in uriSet) { | 75 for (String uri in uriSet) { |
| 70 librarySources.add(sdk.mapDartUri(uri)); | 76 librarySources.add(sdk.mapDartUri(uri)); |
| 71 } | 77 } |
| 72 | 78 |
| 73 return new SummaryBuilder(librarySources, sdk.context); | 79 return new SummaryBuilder(librarySources, sdk.context); |
| 74 } | 80 } |
| 75 | 81 |
| 76 BuilderOutput build() => new _Builder(_context, _librarySources).build(); | 82 BuilderOutput build() => new _Builder(_context, _librarySources).build(); |
| 77 } | 83 } |
| 78 | 84 |
| 85 /** |
| 86 * Intermediary summary output result. |
| 87 */ |
| 88 class SummaryOutput { |
| 89 final BuilderOutput spec; |
| 90 final BuilderOutput strong; |
| 91 SummaryOutput(this.spec, this.strong); |
| 92 |
| 93 /** |
| 94 * Write this summary output to the given [outputPath] and return the |
| 95 * created file. |
| 96 */ |
| 97 File write(String outputPath) { |
| 98 fb.Builder builder = new fb.Builder(); |
| 99 fb.Offset specSumOffset = builder.writeListUint8(spec.sum); |
| 100 fb.Offset specIndexOffset = builder.writeListUint8(spec.index); |
| 101 fb.Offset strongSumOffset = builder.writeListUint8(strong.sum); |
| 102 fb.Offset strongIndexOffset = builder.writeListUint8(strong.index); |
| 103 builder.startTable(); |
| 104 builder.addOffset(FIELD_SPEC_SUM, specSumOffset); |
| 105 builder.addOffset(FIELD_SPEC_INDEX, specIndexOffset); |
| 106 builder.addOffset(FIELD_STRONG_SUM, strongSumOffset); |
| 107 builder.addOffset(FIELD_STRONG_INDEX, strongIndexOffset); |
| 108 fb.Offset offset = builder.endTable(); |
| 109 return new File(outputPath) |
| 110 ..writeAsBytesSync(builder.finish(offset), mode: FileMode.WRITE_ONLY); |
| 111 } |
| 112 } |
| 113 |
| 79 class _Builder { | 114 class _Builder { |
| 80 final Set<Source> processedSources = new Set<Source>(); | 115 final Set<Source> processedSources = new Set<Source>(); |
| 81 | 116 |
| 82 final PackageBundleAssembler bundleAssembler = new PackageBundleAssembler(); | 117 final PackageBundleAssembler bundleAssembler = new PackageBundleAssembler(); |
| 83 final PackageIndexAssembler indexAssembler = new PackageIndexAssembler(); | 118 final PackageIndexAssembler indexAssembler = new PackageIndexAssembler(); |
| 84 | 119 |
| 85 final AnalysisContext context; | 120 final AnalysisContext context; |
| 86 final Iterable<Source> librarySources; | 121 final Iterable<Source> librarySources; |
| 87 | 122 |
| 88 _Builder(this.context, this.librarySources); | 123 _Builder(this.context, this.librarySources); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 119 element.exportedLibraries.forEach((e) => _serializeLibrary(e.source)); | 154 element.exportedLibraries.forEach((e) => _serializeLibrary(e.source)); |
| 120 // Index every unit of the library. | 155 // Index every unit of the library. |
| 121 for (CompilationUnitElement unitElement in element.units) { | 156 for (CompilationUnitElement unitElement in element.units) { |
| 122 Source unitSource = unitElement.source; | 157 Source unitSource = unitElement.source; |
| 123 CompilationUnit unit = | 158 CompilationUnit unit = |
| 124 context.resolveCompilationUnit2(unitSource, source); | 159 context.resolveCompilationUnit2(unitSource, source); |
| 125 indexAssembler.indexUnit(unit); | 160 indexAssembler.indexUnit(unit); |
| 126 } | 161 } |
| 127 } | 162 } |
| 128 } | 163 } |
| OLD | NEW |