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 library kernel.ast_to_binary; | 4 library kernel.ast_to_binary; |
5 | 5 |
6 import '../ast.dart'; | 6 import '../ast.dart'; |
7 import '../import_table.dart'; | 7 import '../import_table.dart'; |
8 import 'tag.dart'; | 8 import 'tag.dart'; |
9 import 'dart:convert'; | 9 import 'dart:convert'; |
10 import 'dart:typed_data'; | 10 import 'dart:typed_data'; |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 visitLibrary(Library node) { | 305 visitLibrary(Library node) { |
306 insideExternalLibrary = node.isExternal; | 306 insideExternalLibrary = node.isExternal; |
307 node.binaryOffset = _sink.flushedLength + _sink.length; | 307 node.binaryOffset = _sink.flushedLength + _sink.length; |
308 writeByte(insideExternalLibrary ? 1 : 0); | 308 writeByte(insideExternalLibrary ? 1 : 0); |
309 writeCanonicalNameReference(getCanonicalNameOfLibrary(node)); | 309 writeCanonicalNameReference(getCanonicalNameOfLibrary(node)); |
310 writeStringReference(node.name ?? ''); | 310 writeStringReference(node.name ?? ''); |
311 // TODO(jensj): We save (almost) the same URI twice. | 311 // TODO(jensj): We save (almost) the same URI twice. |
312 writeUriReference(node.fileUri ?? ''); | 312 writeUriReference(node.fileUri ?? ''); |
313 writeAnnotationList(node.annotations); | 313 writeAnnotationList(node.annotations); |
314 writeLibraryDependencies(node); | 314 writeLibraryDependencies(node); |
315 writeAdditionalExports(node); | |
316 writeLibraryParts(node); | 315 writeLibraryParts(node); |
317 writeNodeList(node.typedefs); | 316 writeNodeList(node.typedefs); |
318 writeNodeList(node.classes); | 317 writeNodeList(node.classes); |
319 writeNodeList(node.fields); | 318 writeNodeList(node.fields); |
320 writeNodeList(node.procedures); | 319 writeNodeList(node.procedures); |
321 } | 320 } |
322 | 321 |
323 void writeLibraryDependencies(Library library) { | 322 void writeLibraryDependencies(Library library) { |
324 _libraryDependencyIndex = library.dependencies.isEmpty | 323 _libraryDependencyIndex = library.dependencies.isEmpty |
325 ? const <LibraryDependency, int>{} | 324 ? const <LibraryDependency, int>{} |
326 : <LibraryDependency, int>{}; | 325 : <LibraryDependency, int>{}; |
327 writeUInt30(library.dependencies.length); | 326 writeUInt30(library.dependencies.length); |
328 for (int i = 0; i < library.dependencies.length; ++i) { | 327 for (int i = 0; i < library.dependencies.length; ++i) { |
329 var importNode = library.dependencies[i]; | 328 var importNode = library.dependencies[i]; |
330 _libraryDependencyIndex[importNode] = i; | 329 _libraryDependencyIndex[importNode] = i; |
331 writeLibraryDependency(importNode); | 330 writeLibraryDependency(importNode); |
332 } | 331 } |
333 } | 332 } |
334 | 333 |
335 void writeAdditionalExports(Library library) { | |
336 writeUInt30(library.additionalExports.length); | |
337 for (Reference ref in library.additionalExports) { | |
338 writeReference(ref); | |
339 } | |
340 } | |
341 | |
342 void writeLibraryDependency(LibraryDependency node) { | 334 void writeLibraryDependency(LibraryDependency node) { |
343 writeByte(node.flags); | 335 writeByte(node.flags); |
344 writeNodeList(node.annotations); | 336 writeNodeList(node.annotations); |
345 writeLibraryReference(node.targetLibrary); | 337 writeLibraryReference(node.targetLibrary); |
346 writeStringReference(node.name ?? ''); | 338 writeStringReference(node.name ?? ''); |
347 writeNodeList(node.combinators); | 339 writeNodeList(node.combinators); |
348 } | 340 } |
349 | 341 |
350 void visitCombinator(Combinator node) { | 342 void visitCombinator(Combinator node) { |
351 writeByte(node.isShow ? 1 : 0); | 343 writeByte(node.isShow ? 1 : 0); |
(...skipping 1209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1561 _sink.add(_buffer.sublist(0, length)); | 1553 _sink.add(_buffer.sublist(0, length)); |
1562 _buffer = new Uint8List(SIZE); | 1554 _buffer = new Uint8List(SIZE); |
1563 flushedLength += length; | 1555 flushedLength += length; |
1564 length = 0; | 1556 length = 0; |
1565 } | 1557 } |
1566 | 1558 |
1567 void flushAndDestroy() { | 1559 void flushAndDestroy() { |
1568 _sink.add(_buffer.sublist(0, length)); | 1560 _sink.add(_buffer.sublist(0, length)); |
1569 } | 1561 } |
1570 } | 1562 } |
OLD | NEW |