| 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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 } | 170 } |
| 171 } | 171 } |
| 172 | 172 |
| 173 Program readProgramFile() { | 173 Program readProgramFile() { |
| 174 int magic = readMagicWord(); | 174 int magic = readMagicWord(); |
| 175 if (magic != Tag.ProgramFile) { | 175 if (magic != Tag.ProgramFile) { |
| 176 throw fail('This is not a binary dart file. ' | 176 throw fail('This is not a binary dart file. ' |
| 177 'Magic number was: ${magic.toRadixString(16)}'); | 177 'Magic number was: ${magic.toRadixString(16)}'); |
| 178 } | 178 } |
| 179 readStringTable(); | 179 readStringTable(); |
| 180 Map<String, List<int>> uriToLineStarts = readUriToLineStarts(); | 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, uriToLineStarts)..mainMethod = mainMethod; | 190 return new Program(importTable, uriToSource) |
| 191 ..mainMethod = mainMethod; |
| 191 } | 192 } |
| 192 | 193 |
| 193 Map<String, List<int>> readUriToLineStarts() { | 194 Map<String, Source> readUriToSource() { |
| 194 readSourceUriTable(); | 195 readSourceUriTable(); |
| 195 int length = _sourceUriTable.length; | 196 int length = _sourceUriTable.length; |
| 196 Map<String, List<int>> uriToLineStarts = {}; | 197 Map<String, Source> uriToLineStarts = <String, Source>{}; |
| 197 for (int i = 0; i < length; ++i) { | 198 for (int i = 0; i < length; ++i) { |
| 198 String uri = _sourceUriTable[i]; | 199 String uri = _sourceUriTable[i]; |
| 200 String sourceCode = readStringEntry(); |
| 199 int lineCount = readUInt(); | 201 int lineCount = readUInt(); |
| 200 List<int> lineStarts = new List<int>(lineCount); | 202 List<int> lineStarts = new List<int>(lineCount); |
| 201 int previousLineStart = 0; | 203 int previousLineStart = 0; |
| 202 for (int j = 0; j < lineCount; ++j) { | 204 for (int j = 0; j < lineCount; ++j) { |
| 203 int lineStart = readUInt() + previousLineStart; | 205 int lineStart = readUInt() + previousLineStart; |
| 204 lineStarts[j] = lineStart; | 206 lineStarts[j] = lineStart; |
| 205 previousLineStart = lineStart; | 207 previousLineStart = lineStart; |
| 206 } | 208 } |
| 207 uriToLineStarts[uri] = lineStarts; | 209 uriToLineStarts[uri] = new Source(lineStarts, sourceCode); |
| 208 } | 210 } |
| 209 return uriToLineStarts; | 211 return uriToLineStarts; |
| 210 } | 212 } |
| 211 | 213 |
| 212 void _fillLazilyLoadedList( | 214 void _fillLazilyLoadedList( |
| 213 List<TreeNode> list, void buildObject(int tag, int index)) { | 215 List<TreeNode> list, void buildObject(int tag, int index)) { |
| 214 int length = readUInt(); | 216 int length = readUInt(); |
| 215 list.length = length; | 217 list.length = length; |
| 216 for (int i = 0; i < length; ++i) { | 218 for (int i = 0; i < length; ++i) { |
| 217 int tag = readByte(); | 219 int tag = readByte(); |
| (...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 isFinal: flags & 0x1 != 0, | 933 isFinal: flags & 0x1 != 0, |
| 932 isConst: flags & 0x2 != 0); | 934 isConst: flags & 0x2 != 0); |
| 933 } | 935 } |
| 934 | 936 |
| 935 int readOffset() { | 937 int readOffset() { |
| 936 // Offset is saved as unsigned, | 938 // Offset is saved as unsigned, |
| 937 // but actually ranges from -1 and up (thus the -1) | 939 // but actually ranges from -1 and up (thus the -1) |
| 938 return readUInt() - 1; | 940 return readUInt() - 1; |
| 939 } | 941 } |
| 940 } | 942 } |
| OLD | NEW |