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 'dart:convert'; | 6 import 'dart:convert'; |
7 import 'dart:typed_data'; | 7 import 'dart:typed_data'; |
8 | 8 |
9 import '../ast.dart'; | 9 import '../ast.dart'; |
10 import '../transformations/flags.dart'; | 10 import '../transformations/flags.dart'; |
(...skipping 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1039 var offset = readOffset(); | 1039 var offset = readOffset(); |
1040 var bodyOffset = readOffset(); | 1040 var bodyOffset = readOffset(); |
1041 var variable = readAndPushVariableDeclaration(); | 1041 var variable = readAndPushVariableDeclaration(); |
1042 var iterable = readExpression(); | 1042 var iterable = readExpression(); |
1043 var body = readStatement(); | 1043 var body = readStatement(); |
1044 variableStack.length = variableStackHeight; | 1044 variableStack.length = variableStackHeight; |
1045 return new ForInStatement(variable, iterable, body, isAsync: isAsync) | 1045 return new ForInStatement(variable, iterable, body, isAsync: isAsync) |
1046 ..fileOffset = offset | 1046 ..fileOffset = offset |
1047 ..bodyOffset = bodyOffset; | 1047 ..bodyOffset = bodyOffset; |
1048 case Tag.SwitchStatement: | 1048 case Tag.SwitchStatement: |
| 1049 var offset = readOffset(); |
1049 var expression = readExpression(); | 1050 var expression = readExpression(); |
1050 int count = readUInt(); | 1051 int count = readUInt(); |
1051 List<SwitchCase> cases = | 1052 List<SwitchCase> cases = |
1052 new List<SwitchCase>.generate(count, (i) => new SwitchCase.empty()); | 1053 new List<SwitchCase>.generate(count, (i) => new SwitchCase.empty()); |
1053 switchCaseStack.addAll(cases); | 1054 switchCaseStack.addAll(cases); |
1054 for (int i = 0; i < cases.length; ++i) { | 1055 for (int i = 0; i < cases.length; ++i) { |
1055 var caseNode = cases[i]; | 1056 var caseNode = cases[i]; |
1056 int length = readUInt(); | 1057 int length = readUInt(); |
1057 caseNode.expressions.length = length; | 1058 caseNode.expressions.length = length; |
1058 caseNode.expressionOffsets.length = length; | 1059 caseNode.expressionOffsets.length = length; |
1059 for (int i = 0; i < length; ++i) { | 1060 for (int i = 0; i < length; ++i) { |
1060 caseNode.expressionOffsets[i] = readOffset(); | 1061 caseNode.expressionOffsets[i] = readOffset(); |
1061 caseNode.expressions[i] = readExpression()..parent = caseNode; | 1062 caseNode.expressions[i] = readExpression()..parent = caseNode; |
1062 } | 1063 } |
1063 caseNode.isDefault = readByte() == 1; | 1064 caseNode.isDefault = readByte() == 1; |
1064 caseNode.body = readStatement()..parent = caseNode; | 1065 caseNode.body = readStatement()..parent = caseNode; |
1065 } | 1066 } |
1066 switchCaseStack.length -= count; | 1067 switchCaseStack.length -= count; |
1067 return new SwitchStatement(expression, cases); | 1068 return new SwitchStatement(expression, cases)..fileOffset = offset; |
1068 case Tag.ContinueSwitchStatement: | 1069 case Tag.ContinueSwitchStatement: |
1069 int index = readUInt(); | 1070 int index = readUInt(); |
1070 return new ContinueSwitchStatement(switchCaseStack[index]); | 1071 return new ContinueSwitchStatement(switchCaseStack[index]); |
1071 case Tag.IfStatement: | 1072 case Tag.IfStatement: |
1072 return new IfStatement( | 1073 return new IfStatement( |
1073 readExpression(), readStatement(), readStatementOrNullIfEmpty()); | 1074 readExpression(), readStatement(), readStatementOrNullIfEmpty()); |
1074 case Tag.ReturnStatement: | 1075 case Tag.ReturnStatement: |
1075 int offset = readOffset(); | 1076 int offset = readOffset(); |
1076 return new ReturnStatement(readExpressionOption())..fileOffset = offset; | 1077 return new ReturnStatement(readExpressionOption())..fileOffset = offset; |
1077 case Tag.TryCatch: | 1078 case Tag.TryCatch: |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1277 ..fileOffset = offset | 1278 ..fileOffset = offset |
1278 ..fileEqualsOffset = fileEqualsOffset; | 1279 ..fileEqualsOffset = fileEqualsOffset; |
1279 } | 1280 } |
1280 | 1281 |
1281 int readOffset() { | 1282 int readOffset() { |
1282 // Offset is saved as unsigned, | 1283 // Offset is saved as unsigned, |
1283 // but actually ranges from -1 and up (thus the -1) | 1284 // but actually ranges from -1 and up (thus the -1) |
1284 return readUInt() - 1; | 1285 return readUInt() - 1; |
1285 } | 1286 } |
1286 } | 1287 } |
OLD | NEW |