| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 /// Logic to build unlinked summaries. | 5 /// Logic to build unlinked summaries. |
| 6 library summary.src.summary_builder; | 6 library summary.src.summary_builder; |
| 7 | 7 |
| 8 import 'package:front_end/src/fasta/parser/class_member_parser.dart'; | 8 import 'package:front_end/src/fasta/parser.dart' |
| 9 import 'package:front_end/src/fasta/parser/identifier_context.dart'; | 9 show |
| 10 import 'package:front_end/src/fasta/parser/parser.dart'; | 10 ClassMemberParser, |
| 11 import 'package:front_end/src/fasta/scanner.dart'; | 11 FormalParameterType, |
| 12 IdentifierContext, |
| 13 MemberKind, |
| 14 Parser; |
| 15 |
| 16 import 'package:front_end/src/fasta/scanner.dart' show Token, scan; |
| 17 |
| 12 import 'package:front_end/src/fasta/scanner/token_constants.dart'; | 18 import 'package:front_end/src/fasta/scanner/token_constants.dart'; |
| 13 | 19 |
| 14 import 'expression_serializer.dart'; | 20 import 'expression_serializer.dart'; |
| 15 import 'model.dart'; | 21 import 'model.dart'; |
| 16 import 'stack_listener.dart'; | 22 import 'stack_listener.dart'; |
| 17 | 23 |
| 18 const _abstract_flag = 1 << 2; | 24 const _abstract_flag = 1 << 2; |
| 19 | 25 |
| 20 const _async_flag = 1; | 26 const _async_flag = 1; |
| 21 | 27 |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 void endConstructorReference( | 260 void endConstructorReference( |
| 255 Token start, Token periodBeforeName, Token endToken) { | 261 Token start, Token periodBeforeName, Token endToken) { |
| 256 debugEvent("ConstructorReference $start $periodBeforeName"); | 262 debugEvent("ConstructorReference $start $periodBeforeName"); |
| 257 Ref ctorName = popIfNotNull(periodBeforeName); | 263 Ref ctorName = popIfNotNull(periodBeforeName); |
| 258 assert(ctorName?.prefix == null); | 264 assert(ctorName?.prefix == null); |
| 259 List<TypeRef> typeArgs = pop(); | 265 List<TypeRef> typeArgs = pop(); |
| 260 Ref type = pop(); | 266 Ref type = pop(); |
| 261 push(new ConstructorName(new TypeRef(type, typeArgs), ctorName?.name)); | 267 push(new ConstructorName(new TypeRef(type, typeArgs), ctorName?.name)); |
| 262 } | 268 } |
| 263 | 269 |
| 264 void endFormalParameter(Token covariantKeyword, Token thisKeyword, | 270 void endFormalParameter(Token thisKeyword, Token nameToken, |
| 265 Token nameToken, FormalParameterType kind) { | 271 FormalParameterType kind, MemberKind memberKind) { |
| 266 debugEvent("FormalParameter"); | 272 debugEvent("FormalParameter"); |
| 267 assert(ignore); | 273 assert(ignore); |
| 268 } | 274 } |
| 269 | 275 |
| 270 void endFormalParameters(int c, begin, end) { | 276 void endFormalParameters( |
| 277 int count, Token beginToken, Token endToken, MemberKind kind) { |
| 271 debugEvent("FormalParameters"); | 278 debugEvent("FormalParameters"); |
| 272 assert(ignore); | 279 assert(ignore); |
| 273 } | 280 } |
| 274 | 281 |
| 275 void endBlockFunctionBody(int count, Token begin, Token end) { | 282 void endBlockFunctionBody(int count, Token begin, Token end) { |
| 276 debugEvent("BlockFunctionBody"); | 283 debugEvent("BlockFunctionBody"); |
| 277 assert(ignore); | 284 assert(ignore); |
| 278 } | 285 } |
| 279 | 286 |
| 280 void endFunctionDeclaration(token) { | 287 void endFunctionDeclaration(token) { |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 | 489 |
| 483 // type-variables are the declared parameters on declarations. | 490 // type-variables are the declared parameters on declarations. |
| 484 void handleNoArguments(Token token) { | 491 void handleNoArguments(Token token) { |
| 485 debugEvent("NoArguments"); | 492 debugEvent("NoArguments"); |
| 486 if (ignore) return; | 493 if (ignore) return; |
| 487 var typeArguments = pop(); | 494 var typeArguments = pop(); |
| 488 assert(typeArguments == null); | 495 assert(typeArguments == null); |
| 489 push(NullValue.Arguments); | 496 push(NullValue.Arguments); |
| 490 } | 497 } |
| 491 | 498 |
| 492 void handleNoFormalParameters(Token token) { | 499 void handleNoFormalParameters(Token token, MemberKind kind) { |
| 493 debugEvent("NoFormalParameters"); | 500 debugEvent("NoFormalParameters"); |
| 494 assert(ignore); | 501 assert(ignore); |
| 495 } | 502 } |
| 496 | 503 |
| 497 void handleNoFunctionBody(Token token) { | 504 void handleNoFunctionBody(Token token) { |
| 498 debugEvent("NoFunctionBody"); | 505 debugEvent("NoFunctionBody"); |
| 499 assert(ignore); | 506 assert(ignore); |
| 500 } | 507 } |
| 501 | 508 |
| 502 void handleNoInitializer() {} | 509 void handleNoInitializer() {} |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 if (needInitializer) { | 792 if (needInitializer) { |
| 786 parsed++; | 793 parsed++; |
| 787 if (inConstContext) { | 794 if (inConstContext) { |
| 788 push(constBuilder.computeExpression(token.next, scope)); | 795 push(constBuilder.computeExpression(token.next, scope)); |
| 789 } else { | 796 } else { |
| 790 push(initializerBuilder.computeExpression(token.next, scope)); | 797 push(initializerBuilder.computeExpression(token.next, scope)); |
| 791 } | 798 } |
| 792 } | 799 } |
| 793 } | 800 } |
| 794 | 801 |
| 795 void beginFormalParameters(Token begin) { | 802 void beginFormalParameters(Token token, MemberKind kind) { |
| 796 _nextParamKind = UnlinkedParamKind.required; | 803 _nextParamKind = UnlinkedParamKind.required; |
| 797 } | 804 } |
| 798 | 805 |
| 799 void beginFunctionTypeAlias(Token token) { | 806 void beginFunctionTypeAlias(Token token) { |
| 800 debugEvent('beginFunctionTypeAlias'); | 807 debugEvent('beginFunctionTypeAlias'); |
| 801 // TODO: use a single scope | 808 // TODO: use a single scope |
| 802 scope = new TypeParameterScope(scope); | 809 scope = new TypeParameterScope(scope); |
| 803 } | 810 } |
| 804 | 811 |
| 805 beginInitializer(Token token) { | 812 beginInitializer(Token token) { |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 984 debugEvent("FieldInitializer $typeSeen $assignmentOperator"); | 991 debugEvent("FieldInitializer $typeSeen $assignmentOperator"); |
| 985 // This is a variable initializer and it's ignored for now. May also be | 992 // This is a variable initializer and it's ignored for now. May also be |
| 986 // constructor initializer. | 993 // constructor initializer. |
| 987 var initializer = | 994 var initializer = |
| 988 needInitializer && assignmentOperator != null ? pop() : null; | 995 needInitializer && assignmentOperator != null ? pop() : null; |
| 989 var name = pop(); | 996 var name = pop(); |
| 990 push(new _InitializedName( | 997 push(new _InitializedName( |
| 991 name, new UnlinkedExecutableBuilder(bodyExpr: initializer))); | 998 name, new UnlinkedExecutableBuilder(bodyExpr: initializer))); |
| 992 } | 999 } |
| 993 | 1000 |
| 994 void endFields( | 1001 void endFields(int count, Token beginToken, Token endToken) { |
| 995 int count, Token covariantKeyword, Token beginToken, Token endToken) { | |
| 996 debugEvent("Fields"); | 1002 debugEvent("Fields"); |
| 997 var s = scope; | 1003 var s = scope; |
| 998 if (s is ClassScope) { | 1004 if (s is ClassScope) { |
| 999 _endFields(count, s.currentClass.fields, false); | 1005 _endFields(count, s.currentClass.fields, false); |
| 1000 } else { | 1006 } else { |
| 1001 throw new UnimplementedError(); // TODO(paulberry): does this ever occur? | 1007 throw new UnimplementedError(); // TODO(paulberry): does this ever occur? |
| 1002 // _endFields(count, s.currentEnum.values, false); | 1008 // _endFields(count, s.currentEnum.values, false); |
| 1003 } | 1009 } |
| 1004 } | 1010 } |
| 1005 | 1011 |
| 1006 void endFormalParameter(Token covariantKeyword, Token thisKeyword, | 1012 void endFormalParameter(Token thisKeyword, Token nameToken, |
| 1007 Token nameToken, FormalParameterType kind) { | 1013 FormalParameterType kind, MemberKind memberKind) { |
| 1008 debugEvent("FormalParameter"); | 1014 debugEvent("FormalParameter"); |
| 1009 // TODO(sigmund): clean up? | 1015 // TODO(sigmund): clean up? |
| 1010 var nameOrFormal = pop(); | 1016 var nameOrFormal = pop(); |
| 1011 if (nameOrFormal is String) { | 1017 if (nameOrFormal is String) { |
| 1012 EntityRef type = pop(); | 1018 EntityRef type = pop(); |
| 1013 pop(); // Modifiers | 1019 pop(); // Modifiers |
| 1014 List metadata = pop(); | 1020 List metadata = pop(); |
| 1015 push(new UnlinkedParamBuilder( | 1021 push(new UnlinkedParamBuilder( |
| 1016 name: nameOrFormal, | 1022 name: nameOrFormal, |
| 1017 kind: _nextParamKind, | 1023 kind: _nextParamKind, |
| 1018 inheritsCovariantSlot: slotIf(type == null), | 1024 inheritsCovariantSlot: slotIf(type == null), |
| 1019 annotations: metadata, | 1025 annotations: metadata, |
| 1020 isInitializingFormal: thisKeyword != null, | 1026 isInitializingFormal: thisKeyword != null, |
| 1021 type: type)); | 1027 type: type)); |
| 1022 } else { | 1028 } else { |
| 1023 push(nameOrFormal); | 1029 push(nameOrFormal); |
| 1024 } | 1030 } |
| 1025 } | 1031 } |
| 1026 | 1032 |
| 1027 void endFormalParameters(int count, Token beginToken, Token endToken) { | 1033 void endFormalParameters( |
| 1034 int count, Token beginToken, Token endToken, MemberKind kind) { |
| 1028 debugEvent("FormalParameters"); | 1035 debugEvent("FormalParameters"); |
| 1029 List formals = popList(count); | 1036 List formals = popList(count); |
| 1030 if (formals != null && formals.isNotEmpty) { | 1037 if (formals != null && formals.isNotEmpty) { |
| 1031 var last = formals.last; | 1038 var last = formals.last; |
| 1032 if (last is List) { | 1039 if (last is List) { |
| 1033 var newList = new List(formals.length - 1 + last.length); | 1040 var newList = new List(formals.length - 1 + last.length); |
| 1034 newList.setRange(0, formals.length - 1, formals); | 1041 newList.setRange(0, formals.length - 1, formals); |
| 1035 newList.setRange(formals.length - 1, newList.length, last); | 1042 newList.setRange(formals.length - 1, newList.length, last); |
| 1036 for (int i = 0; i < last.length; i++) { | 1043 for (int i = 0; i < last.length; i++) { |
| 1037 newList[i + formals.length - 1] = last[i]; | 1044 newList[i + formals.length - 1] = last[i]; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1058 name: name, | 1065 name: name, |
| 1059 typeParameters: typeVariables, | 1066 typeParameters: typeVariables, |
| 1060 returnType: returnType, | 1067 returnType: returnType, |
| 1061 parameters: formals, | 1068 parameters: formals, |
| 1062 annotations: metadata)); | 1069 annotations: metadata)); |
| 1063 | 1070 |
| 1064 _addNameIfPublic(name, ReferenceKind.typedef, typeVariables.length); | 1071 _addNameIfPublic(name, ReferenceKind.typedef, typeVariables.length); |
| 1065 } | 1072 } |
| 1066 | 1073 |
| 1067 void endFunctionTypedFormalParameter( | 1074 void endFunctionTypedFormalParameter( |
| 1068 Token covariantKeyword, Token thisKeyword, FormalParameterType kind) { | 1075 Token thisKeyword, FormalParameterType kind) { |
| 1069 debugEvent("FunctionTypedFormalParameter"); | 1076 debugEvent("FunctionTypedFormalParameter"); |
| 1070 List<UnlinkedParamBuilder> formals = pop(); | 1077 List<UnlinkedParamBuilder> formals = pop(); |
| 1071 if (formals != null) formals.forEach((p) => p.inheritsCovariantSlot = null); | 1078 if (formals != null) formals.forEach((p) => p.inheritsCovariantSlot = null); |
| 1072 | 1079 |
| 1073 /* List typeVariables = */ pop(); | 1080 /* List typeVariables = */ pop(); |
| 1074 String name = pop(); | 1081 String name = pop(); |
| 1075 EntityRef returnType = pop(); | 1082 EntityRef returnType = pop(); |
| 1076 /* int modifiers = */ pop(); | 1083 /* int modifiers = */ pop(); |
| 1077 List metadata = pop(); | 1084 List metadata = pop(); |
| 1078 | 1085 |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1551 } | 1558 } |
| 1552 | 1559 |
| 1553 /// Internal representation of an initialized name. | 1560 /// Internal representation of an initialized name. |
| 1554 class _InitializedName { | 1561 class _InitializedName { |
| 1555 final String name; | 1562 final String name; |
| 1556 final UnlinkedExecutableBuilder initializer; | 1563 final UnlinkedExecutableBuilder initializer; |
| 1557 _InitializedName(this.name, this.initializer); | 1564 _InitializedName(this.name, this.initializer); |
| 1558 | 1565 |
| 1559 toString() => "II:" + (initializer != null ? "$name = $initializer" : name); | 1566 toString() => "II:" + (initializer != null ? "$name = $initializer" : name); |
| 1560 } | 1567 } |
| OLD | NEW |