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

Side by Side Diff: pkg/analyzer/lib/src/summary/summary_file_builder.dart

Issue 2077583002: Make SDK summary writing available to analyzer clients. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 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 | « no previous file | pkg/analyzer/tool/summary/build_sdk_summaries.dart » ('j') | 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) 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
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 class SummaryOutput {
Brian Wilkerson 2016/06/16 19:43:55 Comment?
pquitslund 2016/06/16 20:52:15 Done.
86 final BuilderOutput spec;
87 final BuilderOutput strong;
88 SummaryOutput(this.spec, this.strong);
89
90 /**
91 * Write this summary output to the given [outputPath] and return the
92 * created file.
93 */
94 File write(String outputPath) => new _Writer().write(this, outputPath);
95 }
96
79 class _Builder { 97 class _Builder {
80 final Set<Source> processedSources = new Set<Source>(); 98 final Set<Source> processedSources = new Set<Source>();
81 99
82 final PackageBundleAssembler bundleAssembler = new PackageBundleAssembler(); 100 final PackageBundleAssembler bundleAssembler = new PackageBundleAssembler();
83 final PackageIndexAssembler indexAssembler = new PackageIndexAssembler(); 101 final PackageIndexAssembler indexAssembler = new PackageIndexAssembler();
84 102
85 final AnalysisContext context; 103 final AnalysisContext context;
86 final Iterable<Source> librarySources; 104 final Iterable<Source> librarySources;
87 105
88 _Builder(this.context, this.librarySources); 106 _Builder(this.context, this.librarySources);
(...skipping 30 matching lines...) Expand all
119 element.exportedLibraries.forEach((e) => _serializeLibrary(e.source)); 137 element.exportedLibraries.forEach((e) => _serializeLibrary(e.source));
120 // Index every unit of the library. 138 // Index every unit of the library.
121 for (CompilationUnitElement unitElement in element.units) { 139 for (CompilationUnitElement unitElement in element.units) {
122 Source unitSource = unitElement.source; 140 Source unitSource = unitElement.source;
123 CompilationUnit unit = 141 CompilationUnit unit =
124 context.resolveCompilationUnit2(unitSource, source); 142 context.resolveCompilationUnit2(unitSource, source);
125 indexAssembler.indexUnit(unit); 143 indexAssembler.indexUnit(unit);
126 } 144 }
127 } 145 }
128 } 146 }
147
148 class _Writer {
149 File write(SummaryOutput output, String outputPath) {
Brian Wilkerson 2016/06/16 19:43:55 Not sure what value there is in creating a private
pquitslund 2016/06/16 20:52:15 Done.
150 fb.Builder builder = new fb.Builder();
151 fb.Offset specSumOffset = builder.writeListUint8(output.spec.sum);
152 fb.Offset specIndexOffset = builder.writeListUint8(output.spec.index);
153 fb.Offset strongSumOffset = builder.writeListUint8(output.strong.sum);
154 fb.Offset strongIndexOffset = builder.writeListUint8(output.strong.index);
155 builder.startTable();
156 builder.addOffset(FIELD_SPEC_SUM, specSumOffset);
157 builder.addOffset(FIELD_SPEC_INDEX, specIndexOffset);
158 builder.addOffset(FIELD_STRONG_SUM, strongSumOffset);
159 builder.addOffset(FIELD_STRONG_INDEX, strongIndexOffset);
160 fb.Offset offset = builder.endTable();
161 return new File(outputPath)
162 ..writeAsBytesSync(builder.finish(offset), mode: FileMode.WRITE_ONLY);
163 }
164 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/tool/summary/build_sdk_summaries.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698