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 | 4 |
5 library serialization.summarize_ast; | 5 library serialization.summarize_ast; |
6 | 6 |
7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
8 import 'package:analyzer/dart/ast/token.dart'; | 8 import 'package:analyzer/dart/ast/token.dart'; |
9 import 'package:analyzer/dart/ast/visitor.dart'; | 9 import 'package:analyzer/dart/ast/visitor.dart'; |
10 import 'package:analyzer/dart/element/type.dart' show DartType; | 10 import 'package:analyzer/dart/element/type.dart' show DartType; |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 */ | 228 */ |
229 List<UnlinkedExecutableBuilder> executables = <UnlinkedExecutableBuilder>[]; | 229 List<UnlinkedExecutableBuilder> executables = <UnlinkedExecutableBuilder>[]; |
230 | 230 |
231 /** | 231 /** |
232 * List of objects which should be written to [UnlinkedUnit.exports]. | 232 * List of objects which should be written to [UnlinkedUnit.exports]. |
233 */ | 233 */ |
234 final List<UnlinkedExportNonPublicBuilder> exports = | 234 final List<UnlinkedExportNonPublicBuilder> exports = |
235 <UnlinkedExportNonPublicBuilder>[]; | 235 <UnlinkedExportNonPublicBuilder>[]; |
236 | 236 |
237 /** | 237 /** |
238 * List of objects which should be written to | |
239 * [UnlinkedExecutable.localLabels]. | |
240 */ | |
241 List<UnlinkedLabelBuilder> labels = <UnlinkedLabelBuilder>[]; | |
242 | |
243 /** | |
244 * List of objects which should be written to [UnlinkedUnit.parts]. | 238 * List of objects which should be written to [UnlinkedUnit.parts]. |
245 */ | 239 */ |
246 final List<UnlinkedPartBuilder> parts = <UnlinkedPartBuilder>[]; | 240 final List<UnlinkedPartBuilder> parts = <UnlinkedPartBuilder>[]; |
247 | 241 |
248 /** | 242 /** |
249 * List of objects which should be written to [UnlinkedUnit.typedefs]. | 243 * List of objects which should be written to [UnlinkedUnit.typedefs]. |
250 */ | 244 */ |
251 final List<UnlinkedTypedefBuilder> typedefs = <UnlinkedTypedefBuilder>[]; | 245 final List<UnlinkedTypedefBuilder> typedefs = <UnlinkedTypedefBuilder>[]; |
252 | 246 |
253 /** | 247 /** |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 bool forConst) { | 690 bool forConst) { |
697 if (body is BlockFunctionBody || body is ExpressionFunctionBody) { | 691 if (body is BlockFunctionBody || body is ExpressionFunctionBody) { |
698 for (UnlinkedParamBuilder parameter in b.parameters) { | 692 for (UnlinkedParamBuilder parameter in b.parameters) { |
699 if (!parameter.isInitializingFormal) { | 693 if (!parameter.isInitializingFormal) { |
700 parameter.visibleOffset = body.offset; | 694 parameter.visibleOffset = body.offset; |
701 parameter.visibleLength = body.length; | 695 parameter.visibleLength = body.length; |
702 } | 696 } |
703 } | 697 } |
704 } | 698 } |
705 List<UnlinkedExecutableBuilder> oldExecutables = executables; | 699 List<UnlinkedExecutableBuilder> oldExecutables = executables; |
706 List<UnlinkedLabelBuilder> oldLabels = labels; | |
707 Map<int, int> oldLocalClosureIndexMap = _localClosureIndexMap; | 700 Map<int, int> oldLocalClosureIndexMap = _localClosureIndexMap; |
708 bool oldSerializeClosureBodyExprs = _serializeClosureBodyExprs; | 701 bool oldSerializeClosureBodyExprs = _serializeClosureBodyExprs; |
709 executables = <UnlinkedExecutableBuilder>[]; | 702 executables = <UnlinkedExecutableBuilder>[]; |
710 labels = <UnlinkedLabelBuilder>[]; | |
711 _localClosureIndexMap = <int, int>{}; | 703 _localClosureIndexMap = <int, int>{}; |
712 _serializeClosureBodyExprs = serializeBodyExpr; | 704 _serializeClosureBodyExprs = serializeBodyExpr; |
713 if (initializers != null) { | 705 if (initializers != null) { |
714 for (ConstructorInitializer initializer in initializers) { | 706 for (ConstructorInitializer initializer in initializers) { |
715 initializer.accept(this); | 707 initializer.accept(this); |
716 } | 708 } |
717 } | 709 } |
718 if (serializeBody) { | 710 if (serializeBody) { |
719 body.accept(this); | 711 body.accept(this); |
720 } | 712 } |
721 if (serializeBodyExpr) { | 713 if (serializeBodyExpr) { |
722 if (body is Expression) { | 714 if (body is Expression) { |
723 b.bodyExpr = serializeConstExpr( | 715 b.bodyExpr = serializeConstExpr( |
724 forConst, _localClosureIndexMap, body, _parameterNames); | 716 forConst, _localClosureIndexMap, body, _parameterNames); |
725 } else if (body is ExpressionFunctionBody) { | 717 } else if (body is ExpressionFunctionBody) { |
726 b.bodyExpr = serializeConstExpr( | 718 b.bodyExpr = serializeConstExpr( |
727 forConst, _localClosureIndexMap, body.expression, _parameterNames); | 719 forConst, _localClosureIndexMap, body.expression, _parameterNames); |
728 } else { | 720 } else { |
729 // TODO(paulberry): serialize other types of function bodies. | 721 // TODO(paulberry): serialize other types of function bodies. |
730 } | 722 } |
731 } | 723 } |
732 b.localFunctions = executables; | 724 b.localFunctions = executables; |
733 b.localLabels = labels; | |
734 Map<int, int> localClosureIndexMap = _localClosureIndexMap; | 725 Map<int, int> localClosureIndexMap = _localClosureIndexMap; |
735 executables = oldExecutables; | 726 executables = oldExecutables; |
736 labels = oldLabels; | |
737 _localClosureIndexMap = oldLocalClosureIndexMap; | 727 _localClosureIndexMap = oldLocalClosureIndexMap; |
738 _serializeClosureBodyExprs = oldSerializeClosureBodyExprs; | 728 _serializeClosureBodyExprs = oldSerializeClosureBodyExprs; |
739 return localClosureIndexMap; | 729 return localClosureIndexMap; |
740 } | 730 } |
741 | 731 |
742 /** | 732 /** |
743 * Serialize the return type and parameters of a function-typed formal | 733 * Serialize the return type and parameters of a function-typed formal |
744 * parameter and store them in [b]. | 734 * parameter and store them in [b]. |
745 */ | 735 */ |
746 void serializeFunctionTypedParameterDetails(UnlinkedParamBuilder b, | 736 void serializeFunctionTypedParameterDetails(UnlinkedParamBuilder b, |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1297 b.prefixOffset = node.prefix.offset; | 1287 b.prefixOffset = node.prefix.offset; |
1298 } | 1288 } |
1299 b.isDeferred = node.deferredKeyword != null; | 1289 b.isDeferred = node.deferredKeyword != null; |
1300 b.uri = node.uri.stringValue; | 1290 b.uri = node.uri.stringValue; |
1301 b.uriOffset = node.uri.offset; | 1291 b.uriOffset = node.uri.offset; |
1302 b.uriEnd = node.uri.end; | 1292 b.uriEnd = node.uri.end; |
1303 unlinkedImports.add(b); | 1293 unlinkedImports.add(b); |
1304 } | 1294 } |
1305 | 1295 |
1306 @override | 1296 @override |
1307 void visitLabel(Label node) { | |
1308 AstNode parent = node.parent; | |
1309 if (parent is! NamedExpression) { | |
1310 labels.add(new UnlinkedLabelBuilder( | |
1311 name: node.label.name, | |
1312 nameOffset: node.offset, | |
1313 isOnSwitchMember: parent is SwitchMember, | |
1314 isOnSwitchStatement: parent is LabeledStatement && | |
1315 parent.statement is SwitchStatement)); | |
1316 } | |
1317 } | |
1318 | |
1319 @override | |
1320 void visitLibraryDirective(LibraryDirective node) { | 1297 void visitLibraryDirective(LibraryDirective node) { |
1321 libraryName = | 1298 libraryName = |
1322 node.name.components.map((SimpleIdentifier id) => id.name).join('.'); | 1299 node.name.components.map((SimpleIdentifier id) => id.name).join('.'); |
1323 libraryNameOffset = node.name.offset; | 1300 libraryNameOffset = node.name.offset; |
1324 libraryNameLength = node.name.length; | 1301 libraryNameLength = node.name.length; |
1325 isCoreLibrary = libraryName == 'dart.core'; | 1302 isCoreLibrary = libraryName == 'dart.core'; |
1326 libraryDocumentationComment = | 1303 libraryDocumentationComment = |
1327 serializeDocumentation(node.documentationComment); | 1304 serializeDocumentation(node.documentationComment); |
1328 libraryAnnotations = serializeAnnotations(node.metadata); | 1305 libraryAnnotations = serializeAnnotations(node.metadata); |
1329 } | 1306 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1408 /** | 1385 /** |
1409 * A [_TypeParameterScope] is a [_Scope] which defines [_ScopedTypeParameter]s. | 1386 * A [_TypeParameterScope] is a [_Scope] which defines [_ScopedTypeParameter]s. |
1410 */ | 1387 */ |
1411 class _TypeParameterScope extends _Scope { | 1388 class _TypeParameterScope extends _Scope { |
1412 /** | 1389 /** |
1413 * Get the number of [_ScopedTypeParameter]s defined in this | 1390 * Get the number of [_ScopedTypeParameter]s defined in this |
1414 * [_TypeParameterScope]. | 1391 * [_TypeParameterScope]. |
1415 */ | 1392 */ |
1416 int get length => _definedNames.length; | 1393 int get length => _definedNames.length; |
1417 } | 1394 } |
OLD | NEW |