| 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_from_binary; | 4 library kernel.ast_from_binary; |
| 5 | 5 |
| 6 import '../ast.dart'; | 6 import '../ast.dart'; |
| 7 import 'tag.dart'; | 7 import 'tag.dart'; |
| 8 import 'loader.dart'; | 8 import 'loader.dart'; |
| 9 import 'dart:convert'; | 9 import 'dart:convert'; |
| 10 import 'package:kernel/transformations/flags.dart'; | 10 import 'package:kernel/transformations/flags.dart'; |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 Map<String, Source> uriToSource = readUriToSource(); | 180 Map<String, Source> uriToSource = readUriToSource(); |
| 181 importTable.length = readUInt(); | 181 importTable.length = readUInt(); |
| 182 for (int i = 0; i < importTable.length; ++i) { | 182 for (int i = 0; i < importTable.length; ++i) { |
| 183 importTable[i] = new Library(null); | 183 importTable[i] = new Library(null); |
| 184 } | 184 } |
| 185 for (int i = 0; i < importTable.length; ++i) { | 185 for (int i = 0; i < importTable.length; ++i) { |
| 186 _currentLibrary = importTable[i]; | 186 _currentLibrary = importTable[i]; |
| 187 readLibrary(); | 187 readLibrary(); |
| 188 } | 188 } |
| 189 var mainMethod = readMemberReference(allowNull: true); | 189 var mainMethod = readMemberReference(allowNull: true); |
| 190 return new Program(importTable, uriToSource) | 190 return new Program(importTable, uriToSource)..mainMethod = mainMethod; |
| 191 ..mainMethod = mainMethod; | |
| 192 } | 191 } |
| 193 | 192 |
| 194 Map<String, Source> readUriToSource() { | 193 Map<String, Source> readUriToSource() { |
| 195 readSourceUriTable(); | 194 readSourceUriTable(); |
| 196 int length = _sourceUriTable.length; | 195 int length = _sourceUriTable.length; |
| 197 Map<String, Source> uriToLineStarts = <String, Source>{}; | 196 Map<String, Source> uriToLineStarts = <String, Source>{}; |
| 198 for (int i = 0; i < length; ++i) { | 197 for (int i = 0; i < length; ++i) { |
| 199 String uri = _sourceUriTable[i]; | 198 String uri = _sourceUriTable[i]; |
| 200 String sourceCode = readStringEntry(); | 199 String sourceCode = readStringEntry(); |
| 201 int lineCount = readUInt(); | 200 int lineCount = readUInt(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 219 int tag = readByte(); | 218 int tag = readByte(); |
| 220 buildObject(tag, i); | 219 buildObject(tag, i); |
| 221 } | 220 } |
| 222 } | 221 } |
| 223 | 222 |
| 224 Library readLibraryReference() { | 223 Library readLibraryReference() { |
| 225 int index = readUInt(); | 224 int index = readUInt(); |
| 226 return importTable[index]; | 225 return importTable[index]; |
| 227 } | 226 } |
| 228 | 227 |
| 228 DeferredImport readDeferredImportReference() { |
| 229 int index = readUInt(); |
| 230 return _currentLibrary.deferredImports[index]; |
| 231 } |
| 232 |
| 229 Class readClassReference({bool allowNull: false}) { | 233 Class readClassReference({bool allowNull: false}) { |
| 230 int tag = readByte(); | 234 int tag = readByte(); |
| 231 if (tag == Tag.NullReference) { | 235 if (tag == Tag.NullReference) { |
| 232 if (!allowNull) { | 236 if (!allowNull) { |
| 233 throw 'Expected a class reference to be valid but was `null`.'; | 237 throw 'Expected a class reference to be valid but was `null`.'; |
| 234 } | 238 } |
| 235 return null; | 239 return null; |
| 236 } else { | 240 } else { |
| 237 var library = readLibraryReference(); | 241 var library = readLibraryReference(); |
| 238 int index = readUInt(); | 242 int index = readUInt(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 _currentLibrary.isExternal = (flags & 0x1) != 0; | 289 _currentLibrary.isExternal = (flags & 0x1) != 0; |
| 286 _currentLibrary.name = readStringOrNullIfEmpty(); | 290 _currentLibrary.name = readStringOrNullIfEmpty(); |
| 287 _currentLibrary.importUri = readImportUri(); | 291 _currentLibrary.importUri = readImportUri(); |
| 288 debugPath.add(_currentLibrary.name ?? | 292 debugPath.add(_currentLibrary.name ?? |
| 289 _currentLibrary.importUri?.toString() ?? | 293 _currentLibrary.importUri?.toString() ?? |
| 290 'library'); | 294 'library'); |
| 291 | 295 |
| 292 // TODO(jensj): We currently save (almost the same) uri twice. | 296 // TODO(jensj): We currently save (almost the same) uri twice. |
| 293 _currentLibrary.fileUri = readUriReference(); | 297 _currentLibrary.fileUri = readUriReference(); |
| 294 | 298 |
| 299 _readDeferredImports(_currentLibrary); |
| 295 _fillLazilyLoadedList(_currentLibrary.classes, (int tag, int index) { | 300 _fillLazilyLoadedList(_currentLibrary.classes, (int tag, int index) { |
| 296 readClass(loader.getClassReference(_currentLibrary, tag, index), tag); | 301 readClass(loader.getClassReference(_currentLibrary, tag, index), tag); |
| 297 }); | 302 }); |
| 298 _fillLazilyLoadedList(_currentLibrary.fields, (int tag, int index) { | 303 _fillLazilyLoadedList(_currentLibrary.fields, (int tag, int index) { |
| 299 readField( | 304 readField( |
| 300 loader.getLibraryMemberReference(_currentLibrary, tag, index), tag); | 305 loader.getLibraryMemberReference(_currentLibrary, tag, index), tag); |
| 301 }); | 306 }); |
| 302 _fillLazilyLoadedList(_currentLibrary.procedures, (int tag, int index) { | 307 _fillLazilyLoadedList(_currentLibrary.procedures, (int tag, int index) { |
| 303 readProcedure( | 308 readProcedure( |
| 304 loader.getLibraryMemberReference(_currentLibrary, tag, index), tag); | 309 loader.getLibraryMemberReference(_currentLibrary, tag, index), tag); |
| 305 }); | 310 }); |
| 306 debugPath.removeLast(); | 311 debugPath.removeLast(); |
| 307 } | 312 } |
| 308 | 313 |
| 314 void _readDeferredImports(Library library) { |
| 315 int count = readUInt(); |
| 316 library.deferredImports.length = count; |
| 317 for (int i = 0; i < count; ++i) { |
| 318 var importNode = _readDeferredImport(); |
| 319 library.deferredImports.add(importNode..parent = library); |
| 320 } |
| 321 } |
| 322 |
| 323 DeferredImport _readDeferredImport() { |
| 324 return new DeferredImport(readLibraryReference(), readStringReference()); |
| 325 } |
| 326 |
| 309 void readClass(Class node, int tag) { | 327 void readClass(Class node, int tag) { |
| 310 assert(node != null); | 328 assert(node != null); |
| 311 switch (tag) { | 329 switch (tag) { |
| 312 case Tag.NormalClass: | 330 case Tag.NormalClass: |
| 313 readNormalClass(node); | 331 readNormalClass(node); |
| 314 break; | 332 break; |
| 315 case Tag.MixinClass: | 333 case Tag.MixinClass: |
| 316 readMixinClass(node); | 334 readMixinClass(node); |
| 317 break; | 335 break; |
| 318 default: | 336 default: |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 Expression readExpressionOption() { | 541 Expression readExpressionOption() { |
| 524 return readAndCheckOptionTag() ? readExpression() : null; | 542 return readAndCheckOptionTag() ? readExpression() : null; |
| 525 } | 543 } |
| 526 | 544 |
| 527 Expression readExpression() { | 545 Expression readExpression() { |
| 528 int tagByte = readByte(); | 546 int tagByte = readByte(); |
| 529 int tag = tagByte & Tag.SpecializedTagHighBit == 0 | 547 int tag = tagByte & Tag.SpecializedTagHighBit == 0 |
| 530 ? tagByte | 548 ? tagByte |
| 531 : (tagByte & Tag.SpecializedTagMask); | 549 : (tagByte & Tag.SpecializedTagMask); |
| 532 switch (tag) { | 550 switch (tag) { |
| 551 case Tag.LoadLibrary: |
| 552 return new LoadLibrary(readDeferredImportReference()); |
| 553 case Tag.CheckLibraryIsLoaded: |
| 554 return new CheckLibraryIsLoaded(readDeferredImportReference()); |
| 533 case Tag.InvalidExpression: | 555 case Tag.InvalidExpression: |
| 534 return new InvalidExpression(); | 556 return new InvalidExpression(); |
| 535 case Tag.VariableGet: | 557 case Tag.VariableGet: |
| 536 int offset = readOffset(); | 558 int offset = readOffset(); |
| 537 return new VariableGet(readVariableReference(), readDartTypeOption()) | 559 return new VariableGet(readVariableReference(), readDartTypeOption()) |
| 538 ..fileOffset = offset; | 560 ..fileOffset = offset; |
| 539 case Tag.SpecializedVariableGet: | 561 case Tag.SpecializedVariableGet: |
| 540 int index = tagByte & Tag.SpecializedPayloadMask; | 562 int index = tagByte & Tag.SpecializedPayloadMask; |
| 541 int offset = readOffset(); | 563 int offset = readOffset(); |
| 542 return new VariableGet(variableStack[index])..fileOffset = offset; | 564 return new VariableGet(variableStack[index])..fileOffset = offset; |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 968 isFinal: flags & 0x1 != 0, | 990 isFinal: flags & 0x1 != 0, |
| 969 isConst: flags & 0x2 != 0)..fileOffset = offset; | 991 isConst: flags & 0x2 != 0)..fileOffset = offset; |
| 970 } | 992 } |
| 971 | 993 |
| 972 int readOffset() { | 994 int readOffset() { |
| 973 // Offset is saved as unsigned, | 995 // Offset is saved as unsigned, |
| 974 // but actually ranges from -1 and up (thus the -1) | 996 // but actually ranges from -1 and up (thus the -1) |
| 975 return readUInt() - 1; | 997 return readUInt() - 1; |
| 976 } | 998 } |
| 977 } | 999 } |
| OLD | NEW |