Chromium Code Reviews| 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/src/generated/utilities_dart.dart'; | 10 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 248 /** | 248 /** |
| 249 * Names referenced by this compilation unit. Structured as a map from | 249 * Names referenced by this compilation unit. Structured as a map from |
| 250 * prefix index to (map from name to reference table index), where "prefix | 250 * prefix index to (map from name to reference table index), where "prefix |
| 251 * index" means the index into [UnlinkedUnit.references] of the prefix (or | 251 * index" means the index into [UnlinkedUnit.references] of the prefix (or |
| 252 * `null` if there is no prefix), and "reference table index" means the index | 252 * `null` if there is no prefix), and "reference table index" means the index |
| 253 * into [UnlinkedUnit.references] for the name itself. | 253 * into [UnlinkedUnit.references] for the name itself. |
| 254 */ | 254 */ |
| 255 final Map<int, Map<String, int>> nameToReference = <int, Map<String, int>>{}; | 255 final Map<int, Map<String, int>> nameToReference = <int, Map<String, int>>{}; |
| 256 | 256 |
| 257 /** | 257 /** |
| 258 * True if the 'dart:core' library is been summarizing. | |
|
Paul Berry
2016/03/28 15:38:33
s/is been summarizing/is being summarized/
| |
| 259 */ | |
| 260 bool isCoreLibrary = false; | |
| 261 | |
| 262 /** | |
| 258 * If the library has a library directive, the library name derived from it. | 263 * If the library has a library directive, the library name derived from it. |
| 259 * Otherwise `null`. | 264 * Otherwise `null`. |
| 260 */ | 265 */ |
| 261 String libraryName; | 266 String libraryName; |
| 262 | 267 |
| 263 /** | 268 /** |
| 264 * If the library has a library directive, the offset of the library name. | 269 * If the library has a library directive, the offset of the library name. |
| 265 * Otherwise `null`. | 270 * Otherwise `null`. |
| 266 */ | 271 */ |
| 267 int libraryNameOffset; | 272 int libraryNameOffset; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 368 _TypeParameterScope typeParameterScope = new _TypeParameterScope(); | 373 _TypeParameterScope typeParameterScope = new _TypeParameterScope(); |
| 369 scopes.add(typeParameterScope); | 374 scopes.add(typeParameterScope); |
| 370 UnlinkedClassBuilder b = new UnlinkedClassBuilder(); | 375 UnlinkedClassBuilder b = new UnlinkedClassBuilder(); |
| 371 b.name = name; | 376 b.name = name; |
| 372 b.nameOffset = nameOffset; | 377 b.nameOffset = nameOffset; |
| 373 b.isMixinApplication = isMixinApplication; | 378 b.isMixinApplication = isMixinApplication; |
| 374 b.typeParameters = | 379 b.typeParameters = |
| 375 serializeTypeParameters(typeParameters, typeParameterScope); | 380 serializeTypeParameters(typeParameters, typeParameterScope); |
| 376 if (superclass != null) { | 381 if (superclass != null) { |
| 377 b.supertype = serializeTypeName(superclass); | 382 b.supertype = serializeTypeName(superclass); |
| 383 } else { | |
| 384 b.hasNoSupertype = isCoreLibrary && name == 'Object'; | |
| 378 } | 385 } |
| 379 if (withClause != null) { | 386 if (withClause != null) { |
| 380 b.mixins = withClause.mixinTypes.map(serializeTypeName).toList(); | 387 b.mixins = withClause.mixinTypes.map(serializeTypeName).toList(); |
| 381 } | 388 } |
| 382 if (implementsClause != null) { | 389 if (implementsClause != null) { |
| 383 b.interfaces = | 390 b.interfaces = |
| 384 implementsClause.interfaces.map(serializeTypeName).toList(); | 391 implementsClause.interfaces.map(serializeTypeName).toList(); |
| 385 } | 392 } |
| 386 if (members != null) { | 393 if (members != null) { |
| 387 scopes.add(buildClassMemberScope(name, members)); | 394 scopes.add(buildClassMemberScope(name, members)); |
| (...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1069 isOnSwitchStatement: | 1076 isOnSwitchStatement: |
| 1070 parent is LabeledStatement && parent.statement is SwitchStatement)); | 1077 parent is LabeledStatement && parent.statement is SwitchStatement)); |
| 1071 } | 1078 } |
| 1072 | 1079 |
| 1073 @override | 1080 @override |
| 1074 void visitLibraryDirective(LibraryDirective node) { | 1081 void visitLibraryDirective(LibraryDirective node) { |
| 1075 libraryName = | 1082 libraryName = |
| 1076 node.name.components.map((SimpleIdentifier id) => id.name).join('.'); | 1083 node.name.components.map((SimpleIdentifier id) => id.name).join('.'); |
| 1077 libraryNameOffset = node.name.offset; | 1084 libraryNameOffset = node.name.offset; |
| 1078 libraryNameLength = node.name.length; | 1085 libraryNameLength = node.name.length; |
| 1086 isCoreLibrary = libraryName == 'dart.core'; | |
| 1079 libraryDocumentationComment = | 1087 libraryDocumentationComment = |
| 1080 serializeDocumentation(node.documentationComment); | 1088 serializeDocumentation(node.documentationComment); |
| 1081 libraryAnnotations = serializeAnnotations(node.metadata); | 1089 libraryAnnotations = serializeAnnotations(node.metadata); |
| 1082 } | 1090 } |
| 1083 | 1091 |
| 1084 @override | 1092 @override |
| 1085 void visitMethodDeclaration(MethodDeclaration node) { | 1093 void visitMethodDeclaration(MethodDeclaration node) { |
| 1086 executables.add(serializeExecutable( | 1094 executables.add(serializeExecutable( |
| 1087 node, | 1095 node, |
| 1088 node.name.name, | 1096 node.name.name, |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1102 | 1110 |
| 1103 @override | 1111 @override |
| 1104 void visitPartDirective(PartDirective node) { | 1112 void visitPartDirective(PartDirective node) { |
| 1105 parts.add(new UnlinkedPartBuilder( | 1113 parts.add(new UnlinkedPartBuilder( |
| 1106 uriOffset: node.uri.offset, | 1114 uriOffset: node.uri.offset, |
| 1107 uriEnd: node.uri.end, | 1115 uriEnd: node.uri.end, |
| 1108 annotations: serializeAnnotations(node.metadata))); | 1116 annotations: serializeAnnotations(node.metadata))); |
| 1109 } | 1117 } |
| 1110 | 1118 |
| 1111 @override | 1119 @override |
| 1112 void visitPartOfDirective(PartOfDirective node) {} | 1120 void visitPartOfDirective(PartOfDirective node) { |
| 1121 isCoreLibrary = node.libraryName.name == 'dart.core'; | |
| 1122 } | |
| 1113 | 1123 |
| 1114 @override | 1124 @override |
| 1115 UnlinkedParamBuilder visitSimpleFormalParameter(SimpleFormalParameter node) { | 1125 UnlinkedParamBuilder visitSimpleFormalParameter(SimpleFormalParameter node) { |
| 1116 UnlinkedParamBuilder b = serializeParameter(node); | 1126 UnlinkedParamBuilder b = serializeParameter(node); |
| 1117 b.type = serializeTypeName(node.type); | 1127 b.type = serializeTypeName(node.type); |
| 1118 return b; | 1128 return b; |
| 1119 } | 1129 } |
| 1120 | 1130 |
| 1121 @override | 1131 @override |
| 1122 void visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { | 1132 void visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1154 /** | 1164 /** |
| 1155 * A [_TypeParameterScope] is a [_Scope] which defines [_ScopedTypeParameter]s. | 1165 * A [_TypeParameterScope] is a [_Scope] which defines [_ScopedTypeParameter]s. |
| 1156 */ | 1166 */ |
| 1157 class _TypeParameterScope extends _Scope { | 1167 class _TypeParameterScope extends _Scope { |
| 1158 /** | 1168 /** |
| 1159 * Get the number of [_ScopedTypeParameter]s defined in this | 1169 * Get the number of [_ScopedTypeParameter]s defined in this |
| 1160 * [_TypeParameterScope]. | 1170 * [_TypeParameterScope]. |
| 1161 */ | 1171 */ |
| 1162 int get length => _definedNames.length; | 1172 int get length => _definedNames.length; |
| 1163 } | 1173 } |
| OLD | NEW |