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 fasta.body_builder; | 5 library fasta.body_builder; |
6 | 6 |
7 import '../fasta_codes.dart' | 7 import '../fasta_codes.dart' |
8 show FastaMessage, codeExpectedButGot, codeExpectedFunctionBody; | 8 show FastaMessage, codeExpectedButGot, codeExpectedFunctionBody; |
9 | 9 |
10 import '../parser/parser.dart' show FormalParameterType, MemberKind, optional; | 10 import '../parser/parser.dart' show FormalParameterType, MemberKind, optional; |
11 | 11 |
12 import '../parser/identifier_context.dart' show IdentifierContext; | 12 import '../parser/identifier_context.dart' show IdentifierContext; |
13 | 13 |
14 import 'package:front_end/src/fasta/builder/ast_factory.dart' show AstFactory; | |
15 | |
16 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart' | 14 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart' |
ahe
2017/05/24 18:12:57
FWIW, I think it makes sense to remove the show cl
Paul Berry
2017/05/24 18:24:11
Agreed, it's not adding much value at this point :
| |
17 show | 15 show |
18 KernelArguments, | 16 KernelArguments, |
17 KernelAsExpression, | |
18 KernelAwaitExpression, | |
19 KernelBlock, | |
20 KernelBoolLiteral, | |
21 KernelConditionalExpression, | |
22 KernelConstructorInvocation, | |
23 KernelDirectMethodInvocation, | |
24 KernelDirectPropertyGet, | |
25 KernelDoubleLiteral, | |
26 KernelExpressionStatement, | |
27 KernelFactoryConstructorInvocation, | |
19 KernelField, | 28 KernelField, |
20 KernelFunctionDeclaration, | 29 KernelFunctionDeclaration, |
30 KernelFunctionExpression, | |
31 KernelIfStatement, | |
32 KernelIntLiteral, | |
33 KernelIsExpression, | |
34 KernelIsNotExpression, | |
35 KernelListLiteral, | |
36 KernelLogicalExpression, | |
37 KernelMapLiteral, | |
38 KernelNot, | |
39 KernelNullLiteral, | |
40 KernelRethrow, | |
21 KernelReturnStatement, | 41 KernelReturnStatement, |
42 KernelStaticGet, | |
43 KernelStaticInvocation, | |
44 KernelStringConcatenation, | |
45 KernelStringLiteral, | |
46 KernelSuperMethodInvocation, | |
47 KernelSuperPropertyGet, | |
48 KernelSymbolLiteral, | |
49 KernelThisExpression, | |
50 KernelThrow, | |
51 KernelTypeLiteral, | |
52 KernelVariableDeclaration, | |
22 KernelYieldStatement; | 53 KernelYieldStatement; |
23 | 54 |
24 import 'package:front_end/src/fasta/kernel/utils.dart' show offsetForToken; | 55 import 'package:front_end/src/fasta/kernel/utils.dart' show offsetForToken; |
25 | 56 |
26 import 'package:front_end/src/fasta/type_inference/type_inference_engine.dart' | 57 import 'package:front_end/src/fasta/type_inference/type_inference_engine.dart' |
27 show FieldNode; | 58 show FieldNode; |
28 | 59 |
29 import 'package:front_end/src/fasta/type_inference/type_inferrer.dart' | 60 import 'package:front_end/src/fasta/type_inference/type_inferrer.dart' |
30 show TypeInferrer; | 61 show TypeInferrer; |
31 | 62 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 final Scope enclosingScope; | 125 final Scope enclosingScope; |
95 | 126 |
96 final bool isDartLibrary; | 127 final bool isDartLibrary; |
97 | 128 |
98 @override | 129 @override |
99 final Uri uri; | 130 final Uri uri; |
100 | 131 |
101 final TypeInferrer _typeInferrer; | 132 final TypeInferrer _typeInferrer; |
102 | 133 |
103 @override | 134 @override |
104 final AstFactory astFactory; | |
105 | |
106 @override | |
107 final TypePromoter<Expression, VariableDeclaration> typePromoter; | 135 final TypePromoter<Expression, VariableDeclaration> typePromoter; |
108 | 136 |
109 /// If not `null`, dependencies on fields are accumulated into this list. | 137 /// If not `null`, dependencies on fields are accumulated into this list. |
110 /// | 138 /// |
111 /// If `null`, no dependency information is recorded. | 139 /// If `null`, no dependency information is recorded. |
112 final List<FieldNode> fieldDependencies; | 140 final List<FieldNode> fieldDependencies; |
113 | 141 |
114 /// Only used when [member] is a constructor. It tracks if an implicit super | 142 /// Only used when [member] is a constructor. It tracks if an implicit super |
115 /// initializer is needed. | 143 /// initializer is needed. |
116 /// | 144 /// |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 KernelLibraryBuilder library, | 181 KernelLibraryBuilder library, |
154 this.member, | 182 this.member, |
155 Scope scope, | 183 Scope scope, |
156 this.formalParameterScope, | 184 this.formalParameterScope, |
157 this.hierarchy, | 185 this.hierarchy, |
158 this.coreTypes, | 186 this.coreTypes, |
159 this.classBuilder, | 187 this.classBuilder, |
160 this.isInstanceMember, | 188 this.isInstanceMember, |
161 this.uri, | 189 this.uri, |
162 this._typeInferrer, | 190 this._typeInferrer, |
163 this.astFactory, | |
164 {this.fieldDependencies}) | 191 {this.fieldDependencies}) |
165 : enclosingScope = scope, | 192 : enclosingScope = scope, |
166 library = library, | 193 library = library, |
167 isDartLibrary = library.uri.scheme == "dart", | 194 isDartLibrary = library.uri.scheme == "dart", |
168 needsImplicitSuperInitializer = | 195 needsImplicitSuperInitializer = |
169 coreTypes.objectClass != classBuilder?.cls, | 196 coreTypes.objectClass != classBuilder?.cls, |
170 typePromoter = _typeInferrer.typePromoter, | 197 typePromoter = _typeInferrer.typePromoter, |
171 super(scope); | 198 super(scope); |
172 | 199 |
173 bool get hasParserError => recoverableErrors.isNotEmpty; | 200 bool get hasParserError => recoverableErrors.isNotEmpty; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
256 var statement = statements[i]; | 283 var statement = statements[i]; |
257 if (statement is List) { | 284 if (statement is List) { |
258 copy ??= new List<Statement>.from(statements.getRange(0, i)); | 285 copy ??= new List<Statement>.from(statements.getRange(0, i)); |
259 // TODO(sigmund): remove this assignment (issue #28651) | 286 // TODO(sigmund): remove this assignment (issue #28651) |
260 Iterable subStatements = statement; | 287 Iterable subStatements = statement; |
261 copy.addAll(subStatements); | 288 copy.addAll(subStatements); |
262 } else if (copy != null) { | 289 } else if (copy != null) { |
263 copy.add(statement); | 290 copy.add(statement); |
264 } | 291 } |
265 } | 292 } |
266 return astFactory.block(copy ?? statements, beginToken); | 293 return new KernelBlock(copy ?? statements) |
294 ..fileOffset = offsetForToken(beginToken); | |
267 } | 295 } |
268 | 296 |
269 Statement popStatementIfNotNull(Object value) { | 297 Statement popStatementIfNotNull(Object value) { |
270 return value == null ? null : popStatement(); | 298 return value == null ? null : popStatement(); |
271 } | 299 } |
272 | 300 |
273 Statement popStatement() { | 301 Statement popStatement() { |
274 var statement = pop(); | 302 var statement = pop(); |
275 if (statement is List) { | 303 if (statement is List) { |
276 return new Block(new List<Statement>.from(statement)); | 304 return new Block(new List<Statement>.from(statement)); |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
489 KernelFunctionBuilder builder = member; | 517 KernelFunctionBuilder builder = member; |
490 builder.body = body; | 518 builder.body = body; |
491 if (formals?.optional != null) { | 519 if (formals?.optional != null) { |
492 Iterator<FormalParameterBuilder> formalBuilders = | 520 Iterator<FormalParameterBuilder> formalBuilders = |
493 builder.formals.skip(formals.required.length).iterator; | 521 builder.formals.skip(formals.required.length).iterator; |
494 for (VariableDeclaration parameter in formals.optional.formals) { | 522 for (VariableDeclaration parameter in formals.optional.formals) { |
495 bool hasMore = formalBuilders.moveNext(); | 523 bool hasMore = formalBuilders.moveNext(); |
496 assert(hasMore); | 524 assert(hasMore); |
497 VariableDeclaration realParameter = formalBuilders.current.target; | 525 VariableDeclaration realParameter = formalBuilders.current.target; |
498 Expression initializer = | 526 Expression initializer = |
499 parameter.initializer ?? astFactory.nullLiteral(null); | 527 parameter.initializer ?? new KernelNullLiteral(); |
500 realParameter.initializer = initializer..parent = realParameter; | 528 realParameter.initializer = initializer..parent = realParameter; |
501 } | 529 } |
502 } | 530 } |
503 if (builder is KernelConstructorBuilder) { | 531 if (builder is KernelConstructorBuilder) { |
504 finishConstructor(builder, asyncModifier); | 532 finishConstructor(builder, asyncModifier); |
505 } else if (builder is KernelProcedureBuilder) { | 533 } else if (builder is KernelProcedureBuilder) { |
506 builder.asyncModifier = asyncModifier; | 534 builder.asyncModifier = asyncModifier; |
507 } else { | 535 } else { |
508 internalError("Unhandled: ${builder.runtimeType}"); | 536 internalError("Unhandled: ${builder.runtimeType}"); |
509 } | 537 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
553 /// >and no body is provided, then c implicitly has an empty body {}. | 581 /// >and no body is provided, then c implicitly has an empty body {}. |
554 /// We use an empty statement instead. | 582 /// We use an empty statement instead. |
555 constructor.function.body = new EmptyStatement(); | 583 constructor.function.body = new EmptyStatement(); |
556 constructor.function.body.parent = constructor.function; | 584 constructor.function.body.parent = constructor.function; |
557 } | 585 } |
558 } | 586 } |
559 | 587 |
560 @override | 588 @override |
561 void endExpressionStatement(Token token) { | 589 void endExpressionStatement(Token token) { |
562 debugEvent("ExpressionStatement"); | 590 debugEvent("ExpressionStatement"); |
563 push(astFactory.expressionStatement(popForEffect())); | 591 push(new KernelExpressionStatement(popForEffect())); |
564 } | 592 } |
565 | 593 |
566 @override | 594 @override |
567 void endArguments(int count, Token beginToken, Token endToken) { | 595 void endArguments(int count, Token beginToken, Token endToken) { |
568 debugEvent("Arguments"); | 596 debugEvent("Arguments"); |
569 List arguments = popList(count) ?? <Expression>[]; | 597 List arguments = popList(count) ?? <Expression>[]; |
570 int firstNamedArgumentIndex = arguments.length; | 598 int firstNamedArgumentIndex = arguments.length; |
571 for (int i = 0; i < arguments.length; i++) { | 599 for (int i = 0; i < arguments.length; i++) { |
572 var node = arguments[i]; | 600 var node = arguments[i]; |
573 if (node is NamedExpression) { | 601 if (node is NamedExpression) { |
574 firstNamedArgumentIndex = | 602 firstNamedArgumentIndex = |
575 i < firstNamedArgumentIndex ? i : firstNamedArgumentIndex; | 603 i < firstNamedArgumentIndex ? i : firstNamedArgumentIndex; |
576 } else { | 604 } else { |
577 arguments[i] = toValue(node); | 605 arguments[i] = toValue(node); |
578 if (i > firstNamedArgumentIndex) { | 606 if (i > firstNamedArgumentIndex) { |
579 arguments[i] = new NamedExpression( | 607 arguments[i] = new NamedExpression( |
580 "#$i", | 608 "#$i", |
581 buildCompileTimeError( | 609 buildCompileTimeError( |
582 "Expected named argument.", arguments[i].fileOffset)); | 610 "Expected named argument.", arguments[i].fileOffset)); |
583 } | 611 } |
584 } | 612 } |
585 } | 613 } |
586 if (firstNamedArgumentIndex < arguments.length) { | 614 if (firstNamedArgumentIndex < arguments.length) { |
587 List<Expression> positional = new List<Expression>.from( | 615 List<Expression> positional = new List<Expression>.from( |
588 arguments.getRange(0, firstNamedArgumentIndex)); | 616 arguments.getRange(0, firstNamedArgumentIndex)); |
589 List<NamedExpression> named = new List<NamedExpression>.from( | 617 List<NamedExpression> named = new List<NamedExpression>.from( |
590 arguments.getRange(firstNamedArgumentIndex, arguments.length)); | 618 arguments.getRange(firstNamedArgumentIndex, arguments.length)); |
591 push(astFactory.arguments(positional, named: named)); | 619 push(new KernelArguments(positional, named: named)); |
592 } else { | 620 } else { |
593 push(astFactory.arguments(arguments)); | 621 push(new KernelArguments(arguments)); |
594 } | 622 } |
595 } | 623 } |
596 | 624 |
597 @override | 625 @override |
598 void handleParenthesizedExpression(BeginGroupToken token) { | 626 void handleParenthesizedExpression(BeginGroupToken token) { |
599 debugEvent("ParenthesizedExpression"); | 627 debugEvent("ParenthesizedExpression"); |
600 push(new ParenthesizedExpression(this, popForValue(), token.endGroup)); | 628 push(new ParenthesizedExpression(this, popForValue(), token.endGroup)); |
601 } | 629 } |
602 | 630 |
603 @override | 631 @override |
604 void endSend(Token beginToken, Token endToken) { | 632 void endSend(Token beginToken, Token endToken) { |
605 debugEvent("Send"); | 633 debugEvent("Send"); |
606 Arguments arguments = pop(); | 634 Arguments arguments = pop(); |
607 List<DartType> typeArguments = pop(); | 635 List<DartType> typeArguments = pop(); |
608 Object receiver = pop(); | 636 Object receiver = pop(); |
609 if (arguments != null && typeArguments != null) { | 637 if (arguments != null && typeArguments != null) { |
610 assert(arguments.types.isEmpty); | 638 assert(arguments.types.isEmpty); |
611 astFactory.setExplicitArgumentTypes(arguments, typeArguments); | 639 KernelArguments.setExplicitArgumentTypes(arguments, typeArguments); |
612 } else { | 640 } else { |
613 assert(typeArguments == null); | 641 assert(typeArguments == null); |
614 } | 642 } |
615 if (receiver is Identifier) { | 643 if (receiver is Identifier) { |
616 Name name = new Name(receiver.name, library.library); | 644 Name name = new Name(receiver.name, library.library); |
617 if (arguments == null) { | 645 if (arguments == null) { |
618 push(new IncompletePropertyAccessor(this, beginToken, name)); | 646 push(new IncompletePropertyAccessor(this, beginToken, name)); |
619 } else { | 647 } else { |
620 push(new SendAccessor(this, beginToken, name, arguments)); | 648 push(new SendAccessor(this, beginToken, name, arguments)); |
621 } | 649 } |
(...skipping 13 matching lines...) Expand all Loading... | |
635 | 663 |
636 if (receiver is FastaAccessor) { | 664 if (receiver is FastaAccessor) { |
637 if (constantExpressionRequired && | 665 if (constantExpressionRequired && |
638 !isIdentical(receiver) && | 666 !isIdentical(receiver) && |
639 !receiver.isInitializer) { | 667 !receiver.isInitializer) { |
640 addCompileTimeError(charOffset, "Not a constant expression."); | 668 addCompileTimeError(charOffset, "Not a constant expression."); |
641 } | 669 } |
642 return receiver.doInvocation(charOffset, arguments); | 670 return receiver.doInvocation(charOffset, arguments); |
643 } else { | 671 } else { |
644 return buildMethodInvocation( | 672 return buildMethodInvocation( |
645 astFactory, toValue(receiver), callName, arguments, charOffset); | 673 toValue(receiver), callName, arguments, charOffset); |
646 } | 674 } |
647 } | 675 } |
648 | 676 |
649 @override | 677 @override |
650 void beginCascade(Token token) { | 678 void beginCascade(Token token) { |
651 debugEvent("beginCascade"); | 679 debugEvent("beginCascade"); |
652 Expression expression = popForValue(); | 680 Expression expression = popForValue(); |
653 if (expression is CascadeReceiver) { | 681 if (expression is CascadeReceiver) { |
654 push(expression); | 682 push(expression); |
655 push(new VariableAccessor(this, token, expression.variable)); | 683 push(new VariableAccessor(this, token, expression.variable)); |
(...skipping 25 matching lines...) Expand all Loading... | |
681 return doLogicalExpression(token); | 709 return doLogicalExpression(token); |
682 } | 710 } |
683 if (optional("??", token)) return doIfNull(token); | 711 if (optional("??", token)) return doIfNull(token); |
684 if (optional("?.", token)) return doIfNotNull(token); | 712 if (optional("?.", token)) return doIfNotNull(token); |
685 Expression argument = popForValue(); | 713 Expression argument = popForValue(); |
686 var receiver = pop(); | 714 var receiver = pop(); |
687 bool isSuper = false; | 715 bool isSuper = false; |
688 if (receiver is ThisAccessor && receiver.isSuper) { | 716 if (receiver is ThisAccessor && receiver.isSuper) { |
689 ThisAccessor thisAccessorReceiver = receiver; | 717 ThisAccessor thisAccessorReceiver = receiver; |
690 isSuper = true; | 718 isSuper = true; |
691 receiver = astFactory.thisExpression(thisAccessorReceiver.token); | 719 receiver = new KernelThisExpression() |
720 ..fileOffset = offsetForToken(thisAccessorReceiver.token); | |
692 } | 721 } |
693 push(buildBinaryOperator(toValue(receiver), token, argument, isSuper)); | 722 push(buildBinaryOperator(toValue(receiver), token, argument, isSuper)); |
694 } | 723 } |
695 | 724 |
696 Expression buildBinaryOperator( | 725 Expression buildBinaryOperator( |
697 Expression a, Token token, Expression b, bool isSuper) { | 726 Expression a, Token token, Expression b, bool isSuper) { |
698 bool negate = false; | 727 bool negate = false; |
699 String operator = token.stringValue; | 728 String operator = token.stringValue; |
700 if (identical("!=", operator)) { | 729 if (identical("!=", operator)) { |
701 operator = "=="; | 730 operator = "=="; |
702 negate = true; | 731 negate = true; |
703 } | 732 } |
704 if (!isBinaryOperator(operator) && !isMinusOperator(operator)) { | 733 if (!isBinaryOperator(operator) && !isMinusOperator(operator)) { |
705 return buildCompileTimeError( | 734 return buildCompileTimeError( |
706 "Not an operator: '$operator'.", token.charOffset); | 735 "Not an operator: '$operator'.", token.charOffset); |
707 } else { | 736 } else { |
708 Expression result = makeBinary(astFactory, a, new Name(operator), null, b, | 737 Expression result = |
709 offset: token.charOffset); | 738 makeBinary(a, new Name(operator), null, b, offset: token.charOffset); |
710 if (isSuper) { | 739 if (isSuper) { |
711 result = toSuperMethodInvocation(result); | 740 result = toSuperMethodInvocation(result); |
712 } | 741 } |
713 return negate ? astFactory.not(null, result) : result; | 742 return negate ? new KernelNot(result) : result; |
714 } | 743 } |
715 } | 744 } |
716 | 745 |
717 void doLogicalExpression(Token token) { | 746 void doLogicalExpression(Token token) { |
718 Expression argument = popForValue(); | 747 Expression argument = popForValue(); |
719 Expression receiver = popForValue(); | 748 Expression receiver = popForValue(); |
720 push(astFactory.logicalExpression(receiver, token.stringValue, argument)); | 749 push(new KernelLogicalExpression(receiver, token.stringValue, argument)); |
721 } | 750 } |
722 | 751 |
723 /// Handle `a ?? b`. | 752 /// Handle `a ?? b`. |
724 void doIfNull(Token token) { | 753 void doIfNull(Token token) { |
725 Expression b = popForValue(); | 754 Expression b = popForValue(); |
726 Expression a = popForValue(); | 755 Expression a = popForValue(); |
727 VariableDeclaration variable = new VariableDeclaration.forValue(a); | 756 VariableDeclaration variable = new VariableDeclaration.forValue(a); |
728 push(makeLet( | 757 push(makeLet( |
729 variable, | 758 variable, |
730 new ConditionalExpression( | 759 new ConditionalExpression(buildIsNull(new VariableGet(variable)), b, |
731 buildIsNull(astFactory, new VariableGet(variable)), | 760 new VariableGet(variable), const DynamicType()))); |
732 b, | |
733 new VariableGet(variable), | |
734 const DynamicType()))); | |
735 } | 761 } |
736 | 762 |
737 /// Handle `a?.b(...)`. | 763 /// Handle `a?.b(...)`. |
738 void doIfNotNull(Token token) { | 764 void doIfNotNull(Token token) { |
739 IncompleteSend send = pop(); | 765 IncompleteSend send = pop(); |
740 push(send.withReceiver(pop(), isNullAware: true)); | 766 push(send.withReceiver(pop(), isNullAware: true)); |
741 } | 767 } |
742 | 768 |
743 void doDotOrCascadeExpression(Token token) { | 769 void doDotOrCascadeExpression(Token token) { |
744 // TODO(ahe): Handle null-aware. | 770 // TODO(ahe): Handle null-aware. |
745 IncompleteSend send = pop(); | 771 IncompleteSend send = pop(); |
746 Object receiver = optional(".", token) ? pop() : popForValue(); | 772 Object receiver = optional(".", token) ? pop() : popForValue(); |
747 push(send.withReceiver(receiver)); | 773 push(send.withReceiver(receiver)); |
748 } | 774 } |
749 | 775 |
750 @override | 776 @override |
751 Expression toSuperMethodInvocation(MethodInvocation node) { | 777 Expression toSuperMethodInvocation(MethodInvocation node) { |
752 Member target = lookupSuperMember(node.name); | 778 Member target = lookupSuperMember(node.name); |
753 bool isNoSuchMethod = target == null; | 779 bool isNoSuchMethod = target == null; |
754 if (target is Procedure) { | 780 if (target is Procedure) { |
755 if (!target.isAccessor) { | 781 if (!target.isAccessor) { |
756 if (areArgumentsCompatible(target.function, node.arguments)) { | 782 if (areArgumentsCompatible(target.function, node.arguments)) { |
757 // TODO(ahe): Use [DirectMethodInvocation] when possible. | 783 // TODO(ahe): Use [DirectMethodInvocation] when possible. |
758 Expression result = astFactory.directMethodInvocation( | 784 Expression result = new KernelDirectMethodInvocation( |
759 new ThisExpression(), target, node.arguments); | 785 new ThisExpression(), target, node.arguments); |
760 result = astFactory.superMethodInvocation( | 786 result = |
761 null, node.name, node.arguments, null); | 787 new KernelSuperMethodInvocation(node.name, node.arguments, null); |
762 return result; | 788 return result; |
763 } else { | 789 } else { |
764 isNoSuchMethod = true; | 790 isNoSuchMethod = true; |
765 } | 791 } |
766 } | 792 } |
767 } | 793 } |
768 if (isNoSuchMethod) { | 794 if (isNoSuchMethod) { |
769 return throwNoSuchMethodError( | 795 return throwNoSuchMethodError( |
770 node.name.name, node.arguments, node.fileOffset, | 796 node.name.name, node.arguments, node.fileOffset, |
771 isSuper: true); | 797 isSuper: true); |
772 } | 798 } |
773 // TODO(ahe): Use [DirectPropertyGet] when possible. | 799 // TODO(ahe): Use [DirectPropertyGet] when possible. |
774 Expression receiver = | 800 Expression receiver = |
775 astFactory.directPropertyGet(new ThisExpression(), target); | 801 new KernelDirectPropertyGet(new ThisExpression(), target); |
776 receiver = astFactory.superPropertyGet(node.name, target); | 802 receiver = new KernelSuperPropertyGet(node.name, target); |
777 return buildMethodInvocation( | 803 return buildMethodInvocation( |
778 astFactory, receiver, callName, node.arguments, node.fileOffset); | 804 receiver, callName, node.arguments, node.fileOffset); |
779 } | 805 } |
780 | 806 |
781 bool areArgumentsCompatible(FunctionNode function, Arguments arguments) { | 807 bool areArgumentsCompatible(FunctionNode function, Arguments arguments) { |
782 // TODO(ahe): Implement this. | 808 // TODO(ahe): Implement this. |
783 return true; | 809 return true; |
784 } | 810 } |
785 | 811 |
786 @override | 812 @override |
787 Expression throwNoSuchMethodError( | 813 Expression throwNoSuchMethodError( |
788 String name, Arguments arguments, int charOffset, | 814 String name, Arguments arguments, int charOffset, |
789 {bool isSuper: false, isGetter: false, isSetter: false}) { | 815 {bool isSuper: false, isGetter: false, isSetter: false}) { |
790 String errorName = isSuper ? "super.$name" : name; | 816 String errorName = isSuper ? "super.$name" : name; |
791 String message; | 817 String message; |
792 if (isGetter) { | 818 if (isGetter) { |
793 message = "Getter not found: '$errorName'."; | 819 message = "Getter not found: '$errorName'."; |
794 } else if (isSetter) { | 820 } else if (isSetter) { |
795 message = "Setter not found: '$errorName'."; | 821 message = "Setter not found: '$errorName'."; |
796 } else { | 822 } else { |
797 message = "Method not found: '$errorName'."; | 823 message = "Method not found: '$errorName'."; |
798 } | 824 } |
799 if (constantExpressionRequired) { | 825 if (constantExpressionRequired) { |
800 return buildCompileTimeError(message, charOffset); | 826 return buildCompileTimeError(message, charOffset); |
801 } | 827 } |
802 warning(message, charOffset); | 828 warning(message, charOffset); |
803 Constructor constructor = | 829 Constructor constructor = |
804 coreTypes.noSuchMethodErrorClass.constructors.first; | 830 coreTypes.noSuchMethodErrorClass.constructors.first; |
805 return new Throw(new ConstructorInvocation( | 831 return new Throw(new ConstructorInvocation( |
806 constructor, | 832 constructor, |
807 astFactory.arguments(<Expression>[ | 833 new KernelArguments(<Expression>[ |
808 astFactory.nullLiteral(null), | 834 new KernelNullLiteral(), |
809 new SymbolLiteral(name), | 835 new SymbolLiteral(name), |
810 new ListLiteral(arguments.positional), | 836 new ListLiteral(arguments.positional), |
811 new MapLiteral(arguments.named.map((arg) { | 837 new MapLiteral(arguments.named.map((arg) { |
812 return new MapEntry(new SymbolLiteral(arg.name), arg.value); | 838 return new MapEntry(new SymbolLiteral(arg.name), arg.value); |
813 }).toList()), | 839 }).toList()), |
814 astFactory.nullLiteral(null) | 840 new KernelNullLiteral() |
815 ]))); | 841 ]))); |
816 } | 842 } |
817 | 843 |
818 @override | 844 @override |
819 Member lookupSuperMember(Name name, {bool isSetter: false}) { | 845 Member lookupSuperMember(Name name, {bool isSetter: false}) { |
820 Class superclass = classBuilder.cls.superclass; | 846 Class superclass = classBuilder.cls.superclass; |
821 return superclass == null | 847 return superclass == null |
822 ? null | 848 ? null |
823 : hierarchy.getDispatchTarget(superclass, name, setter: isSetter); | 849 : hierarchy.getDispatchTarget(superclass, name, setter: isSetter); |
824 } | 850 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
886 assert(builder == null); | 912 assert(builder == null); |
887 if (constantExpressionRequired) { | 913 if (constantExpressionRequired) { |
888 return new UnresolvedAccessor(this, n, token); | 914 return new UnresolvedAccessor(this, n, token); |
889 } | 915 } |
890 return new ThisPropertyAccessor(this, token, n, null, null); | 916 return new ThisPropertyAccessor(this, token, n, null, null); |
891 } else if (isDartLibrary && | 917 } else if (isDartLibrary && |
892 name == "main" && | 918 name == "main" && |
893 library.uri.path == "_builtin" && | 919 library.uri.path == "_builtin" && |
894 member?.name == "_getMainClosure") { | 920 member?.name == "_getMainClosure") { |
895 // TODO(ahe): https://github.com/dart-lang/sdk/issues/28989 | 921 // TODO(ahe): https://github.com/dart-lang/sdk/issues/28989 |
896 return astFactory.nullLiteral(token); | 922 return new KernelNullLiteral()..fileOffset = offsetForToken(token); |
897 } else { | 923 } else { |
898 return new UnresolvedAccessor(this, n, token); | 924 return new UnresolvedAccessor(this, n, token); |
899 } | 925 } |
900 } else if (builder.isTypeDeclaration) { | 926 } else if (builder.isTypeDeclaration) { |
901 if (constantExpressionRequired && | 927 if (constantExpressionRequired && |
902 builder.isTypeVariable && | 928 builder.isTypeVariable && |
903 !member.isConstructor) { | 929 !member.isConstructor) { |
904 addCompileTimeError( | 930 addCompileTimeError( |
905 offsetForToken(token), "Not a constant expression."); | 931 offsetForToken(token), "Not a constant expression."); |
906 } | 932 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
984 debugEvent("StringPart"); | 1010 debugEvent("StringPart"); |
985 push(token); | 1011 push(token); |
986 } | 1012 } |
987 | 1013 |
988 @override | 1014 @override |
989 void endLiteralString(int interpolationCount, Token endToken) { | 1015 void endLiteralString(int interpolationCount, Token endToken) { |
990 debugEvent("endLiteralString"); | 1016 debugEvent("endLiteralString"); |
991 if (interpolationCount == 0) { | 1017 if (interpolationCount == 0) { |
992 Token token = pop(); | 1018 Token token = pop(); |
993 String value = unescapeString(token.lexeme); | 1019 String value = unescapeString(token.lexeme); |
994 push(astFactory.stringLiteral(value, token)); | 1020 push(new KernelStringLiteral(value)..fileOffset = offsetForToken(token)); |
995 } else { | 1021 } else { |
996 List parts = popList(1 + interpolationCount * 2); | 1022 List parts = popList(1 + interpolationCount * 2); |
997 Token first = parts.first; | 1023 Token first = parts.first; |
998 Token last = parts.last; | 1024 Token last = parts.last; |
999 Quote quote = analyzeQuote(first.lexeme); | 1025 Quote quote = analyzeQuote(first.lexeme); |
1000 List<Expression> expressions = <Expression>[]; | 1026 List<Expression> expressions = <Expression>[]; |
1001 // Contains more than just \' or \". | 1027 // Contains more than just \' or \". |
1002 if (first.lexeme.length > 1) { | 1028 if (first.lexeme.length > 1) { |
1003 String value = unescapeFirstStringPart(first.lexeme, quote); | 1029 String value = unescapeFirstStringPart(first.lexeme, quote); |
1004 expressions.add(astFactory.stringLiteral(value, first)); | 1030 expressions.add( |
1031 new KernelStringLiteral(value)..fileOffset = offsetForToken(first)); | |
1005 } | 1032 } |
1006 for (int i = 1; i < parts.length - 1; i++) { | 1033 for (int i = 1; i < parts.length - 1; i++) { |
1007 var part = parts[i]; | 1034 var part = parts[i]; |
1008 if (part is Token) { | 1035 if (part is Token) { |
1009 if (part.lexeme.length != 0) { | 1036 if (part.lexeme.length != 0) { |
1010 String value = unescape(part.lexeme, quote); | 1037 String value = unescape(part.lexeme, quote); |
1011 expressions.add(astFactory.stringLiteral(value, part)); | 1038 expressions.add(new KernelStringLiteral(value) |
1039 ..fileOffset = offsetForToken(part)); | |
1012 } | 1040 } |
1013 } else { | 1041 } else { |
1014 expressions.add(toValue(part)); | 1042 expressions.add(toValue(part)); |
1015 } | 1043 } |
1016 } | 1044 } |
1017 // Contains more than just \' or \". | 1045 // Contains more than just \' or \". |
1018 if (last.lexeme.length > 1) { | 1046 if (last.lexeme.length > 1) { |
1019 String value = unescapeLastStringPart(last.lexeme, quote); | 1047 String value = unescapeLastStringPart(last.lexeme, quote); |
1020 expressions.add(astFactory.stringLiteral(value, last)); | 1048 expressions.add( |
1049 new KernelStringLiteral(value)..fileOffset = offsetForToken(last)); | |
1021 } | 1050 } |
1022 push(astFactory.stringConcatenation(expressions, endToken)); | 1051 push(new KernelStringConcatenation(expressions) |
1052 ..fileOffset = offsetForToken(endToken)); | |
1023 } | 1053 } |
1024 } | 1054 } |
1025 | 1055 |
1026 @override | 1056 @override |
1027 void handleScript(Token token) { | 1057 void handleScript(Token token) { |
1028 debugEvent("Script"); | 1058 debugEvent("Script"); |
1029 } | 1059 } |
1030 | 1060 |
1031 @override | 1061 @override |
1032 void handleStringJuxtaposition(int literalCount) { | 1062 void handleStringJuxtaposition(int literalCount) { |
1033 debugEvent("StringJuxtaposition"); | 1063 debugEvent("StringJuxtaposition"); |
1034 List<Expression> parts = popListForValue(literalCount); | 1064 List<Expression> parts = popListForValue(literalCount); |
1035 List<Expression> expressions; | 1065 List<Expression> expressions; |
1036 // Flatten string juxtapositions of string interpolation. | 1066 // Flatten string juxtapositions of string interpolation. |
1037 for (int i = 0; i < parts.length; i++) { | 1067 for (int i = 0; i < parts.length; i++) { |
1038 Expression part = parts[i]; | 1068 Expression part = parts[i]; |
1039 if (part is StringConcatenation) { | 1069 if (part is StringConcatenation) { |
1040 if (expressions == null) { | 1070 if (expressions == null) { |
1041 expressions = parts.sublist(0, i); | 1071 expressions = parts.sublist(0, i); |
1042 } | 1072 } |
1043 expressions.addAll(part.expressions); | 1073 expressions.addAll(part.expressions); |
1044 } else { | 1074 } else { |
1045 if (expressions != null) { | 1075 if (expressions != null) { |
1046 expressions.add(part); | 1076 expressions.add(part); |
1047 } | 1077 } |
1048 } | 1078 } |
1049 } | 1079 } |
1050 push(astFactory.stringConcatenation(expressions ?? parts, null)); | 1080 push(new KernelStringConcatenation(expressions ?? parts)); |
1051 } | 1081 } |
1052 | 1082 |
1053 @override | 1083 @override |
1054 void handleLiteralInt(Token token) { | 1084 void handleLiteralInt(Token token) { |
1055 debugEvent("LiteralInt"); | 1085 debugEvent("LiteralInt"); |
1056 push(astFactory.intLiteral(int.parse(token.lexeme), token)); | 1086 push(new KernelIntLiteral(int.parse(token.lexeme)) |
1087 ..fileOffset = offsetForToken(token)); | |
1057 } | 1088 } |
1058 | 1089 |
1059 @override | 1090 @override |
1060 void handleEmptyFunctionBody(Token semicolon) { | 1091 void handleEmptyFunctionBody(Token semicolon) { |
1061 debugEvent("ExpressionFunctionBody"); | 1092 debugEvent("ExpressionFunctionBody"); |
1062 endBlockFunctionBody(0, null, semicolon); | 1093 endBlockFunctionBody(0, null, semicolon); |
1063 } | 1094 } |
1064 | 1095 |
1065 @override | 1096 @override |
1066 void handleExpressionFunctionBody(Token arrowToken, Token endToken) { | 1097 void handleExpressionFunctionBody(Token arrowToken, Token endToken) { |
(...skipping 28 matching lines...) Expand all Loading... | |
1095 typePromoter.enterElse(); | 1126 typePromoter.enterElse(); |
1096 super.endThenStatement(token); | 1127 super.endThenStatement(token); |
1097 } | 1128 } |
1098 | 1129 |
1099 @override | 1130 @override |
1100 void endIfStatement(Token ifToken, Token elseToken) { | 1131 void endIfStatement(Token ifToken, Token elseToken) { |
1101 Statement elsePart = popStatementIfNotNull(elseToken); | 1132 Statement elsePart = popStatementIfNotNull(elseToken); |
1102 Statement thenPart = popStatement(); | 1133 Statement thenPart = popStatement(); |
1103 Expression condition = popForValue(); | 1134 Expression condition = popForValue(); |
1104 typePromoter.exitConditional(); | 1135 typePromoter.exitConditional(); |
1105 push(astFactory.ifStatement(condition, thenPart, elsePart)); | 1136 push(new KernelIfStatement(condition, thenPart, elsePart)); |
1106 } | 1137 } |
1107 | 1138 |
1108 @override | 1139 @override |
1109 void endVariableInitializer(Token assignmentOperator) { | 1140 void endVariableInitializer(Token assignmentOperator) { |
1110 debugEvent("VariableInitializer"); | 1141 debugEvent("VariableInitializer"); |
1111 assert(assignmentOperator.stringValue == "="); | 1142 assert(assignmentOperator.stringValue == "="); |
1112 pushNewLocalVariable(popForValue(), equalsToken: assignmentOperator); | 1143 pushNewLocalVariable(popForValue(), equalsToken: assignmentOperator); |
1113 } | 1144 } |
1114 | 1145 |
1115 @override | 1146 @override |
1116 void handleNoVariableInitializer(Token token) { | 1147 void handleNoVariableInitializer(Token token) { |
1117 debugEvent("NoVariableInitializer"); | 1148 debugEvent("NoVariableInitializer"); |
1118 pushNewLocalVariable(null); | 1149 pushNewLocalVariable(null); |
1119 } | 1150 } |
1120 | 1151 |
1121 void pushNewLocalVariable(Expression initializer, {Token equalsToken}) { | 1152 void pushNewLocalVariable(Expression initializer, {Token equalsToken}) { |
1122 Identifier identifier = pop(); | 1153 Identifier identifier = pop(); |
1123 assert(currentLocalVariableModifiers != -1); | 1154 assert(currentLocalVariableModifiers != -1); |
1124 bool isConst = (currentLocalVariableModifiers & constMask) != 0; | 1155 bool isConst = (currentLocalVariableModifiers & constMask) != 0; |
1125 bool isFinal = (currentLocalVariableModifiers & finalMask) != 0; | 1156 bool isFinal = (currentLocalVariableModifiers & finalMask) != 0; |
1126 assert(isConst == constantExpressionRequired); | 1157 assert(isConst == constantExpressionRequired); |
1127 push(astFactory.variableDeclaration( | 1158 push(new KernelVariableDeclaration(identifier.name, functionNestingLevel, |
1128 identifier.name, identifier.token, functionNestingLevel, | |
1129 initializer: initializer, | 1159 initializer: initializer, |
1130 type: currentLocalVariableType, | 1160 type: currentLocalVariableType, |
1131 isFinal: isFinal, | 1161 isFinal: isFinal, |
1132 isConst: isConst, | 1162 isConst: isConst) |
1133 equalsToken: equalsToken)); | 1163 ..fileOffset = offsetForToken(identifier.token) |
1164 ..fileEqualsOffset = offsetForToken(equalsToken)); | |
1134 } | 1165 } |
1135 | 1166 |
1136 @override | 1167 @override |
1137 void endFieldInitializer(Token assignmentOperator, Token token) { | 1168 void endFieldInitializer(Token assignmentOperator, Token token) { |
1138 debugEvent("FieldInitializer"); | 1169 debugEvent("FieldInitializer"); |
1139 assert(assignmentOperator.stringValue == "="); | 1170 assert(assignmentOperator.stringValue == "="); |
1140 push(popForValue()); | 1171 push(popForValue()); |
1141 } | 1172 } |
1142 | 1173 |
1143 @override | 1174 @override |
1144 void handleNoFieldInitializer(Token token) { | 1175 void handleNoFieldInitializer(Token token) { |
1145 debugEvent("NoFieldInitializer"); | 1176 debugEvent("NoFieldInitializer"); |
1146 if (constantExpressionRequired) { | 1177 if (constantExpressionRequired) { |
1147 addCompileTimeError( | 1178 addCompileTimeError( |
1148 token.charOffset, "const field must have initializer."); | 1179 token.charOffset, "const field must have initializer."); |
1149 // Creating a null value to prevent the Dart VM from crashing. | 1180 // Creating a null value to prevent the Dart VM from crashing. |
1150 push(astFactory.nullLiteral(token)); | 1181 push(new KernelNullLiteral()..fileOffset = offsetForToken(token)); |
1151 } else { | 1182 } else { |
1152 push(NullValue.FieldInitializer); | 1183 push(NullValue.FieldInitializer); |
1153 } | 1184 } |
1154 } | 1185 } |
1155 | 1186 |
1156 @override | 1187 @override |
1157 void endInitializedIdentifier(Token nameToken) { | 1188 void endInitializedIdentifier(Token nameToken) { |
1158 // TODO(ahe): Use [InitializedIdentifier] here? | 1189 // TODO(ahe): Use [InitializedIdentifier] here? |
1159 debugEvent("InitializedIdentifier"); | 1190 debugEvent("InitializedIdentifier"); |
1160 VariableDeclaration variable = pop(); | 1191 VariableDeclaration variable = pop(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1198 exitLocalScope(); | 1229 exitLocalScope(); |
1199 push(block); | 1230 push(block); |
1200 } | 1231 } |
1201 | 1232 |
1202 @override | 1233 @override |
1203 void handleAssignmentExpression(Token token) { | 1234 void handleAssignmentExpression(Token token) { |
1204 debugEvent("AssignmentExpression"); | 1235 debugEvent("AssignmentExpression"); |
1205 Expression value = popForValue(); | 1236 Expression value = popForValue(); |
1206 var accessor = pop(); | 1237 var accessor = pop(); |
1207 if (accessor is TypeDeclarationBuilder) { | 1238 if (accessor is TypeDeclarationBuilder) { |
1208 push(wrapInvalid(astFactory | 1239 push(wrapInvalid(new KernelTypeLiteral( |
1209 .typeLiteral(accessor.buildTypesWithBuiltArguments(library, null)))); | 1240 accessor.buildTypesWithBuiltArguments(library, null)))); |
1210 } else if (accessor is! FastaAccessor) { | 1241 } else if (accessor is! FastaAccessor) { |
1211 push(buildCompileTimeError("Can't assign to this.", token.charOffset)); | 1242 push(buildCompileTimeError("Can't assign to this.", token.charOffset)); |
1212 } else { | 1243 } else { |
1213 push(new DelayedAssignment( | 1244 push(new DelayedAssignment( |
1214 this, token, accessor, value, token.stringValue)); | 1245 this, token, accessor, value, token.stringValue)); |
1215 } | 1246 } |
1216 } | 1247 } |
1217 | 1248 |
1218 @override | 1249 @override |
1219 void enterLoop(int charOffset) { | 1250 void enterLoop(int charOffset) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1257 } | 1288 } |
1258 if (variableOrExpression is VariableDeclaration) { | 1289 if (variableOrExpression is VariableDeclaration) { |
1259 variables.add(variableOrExpression); | 1290 variables.add(variableOrExpression); |
1260 } else if (variableOrExpression is List) { | 1291 } else if (variableOrExpression is List) { |
1261 // TODO(sigmund): remove this assignment (see issue #28651) | 1292 // TODO(sigmund): remove this assignment (see issue #28651) |
1262 Iterable vars = variableOrExpression; | 1293 Iterable vars = variableOrExpression; |
1263 variables.addAll(vars); | 1294 variables.addAll(vars); |
1264 } else if (variableOrExpression == null) { | 1295 } else if (variableOrExpression == null) { |
1265 // Do nothing. | 1296 // Do nothing. |
1266 } else if (variableOrExpression is Expression) { | 1297 } else if (variableOrExpression is Expression) { |
1267 begin = astFactory.expressionStatement(variableOrExpression); | 1298 begin = new KernelExpressionStatement(variableOrExpression); |
1268 } else { | 1299 } else { |
1269 return internalError("Unhandled: ${variableOrExpression.runtimeType}"); | 1300 return internalError("Unhandled: ${variableOrExpression.runtimeType}"); |
1270 } | 1301 } |
1271 exitLocalScope(); | 1302 exitLocalScope(); |
1272 JumpTarget continueTarget = exitContinueTarget(); | 1303 JumpTarget continueTarget = exitContinueTarget(); |
1273 JumpTarget breakTarget = exitBreakTarget(); | 1304 JumpTarget breakTarget = exitBreakTarget(); |
1274 if (continueTarget.hasUsers) { | 1305 if (continueTarget.hasUsers) { |
1275 body = new LabeledStatement(body); | 1306 body = new LabeledStatement(body); |
1276 continueTarget.resolveContinues(body); | 1307 continueTarget.resolveContinues(body); |
1277 } | 1308 } |
1278 Statement result = new ForStatement(variables, condition, updates, body); | 1309 Statement result = new ForStatement(variables, condition, updates, body); |
1279 if (begin != null) { | 1310 if (begin != null) { |
1280 result = new Block(<Statement>[begin, result]); | 1311 result = new Block(<Statement>[begin, result]); |
1281 } | 1312 } |
1282 if (breakTarget.hasUsers) { | 1313 if (breakTarget.hasUsers) { |
1283 result = new LabeledStatement(result); | 1314 result = new LabeledStatement(result); |
1284 breakTarget.resolveBreaks(result); | 1315 breakTarget.resolveBreaks(result); |
1285 } | 1316 } |
1286 exitLoopOrSwitch(result); | 1317 exitLoopOrSwitch(result); |
1287 } | 1318 } |
1288 | 1319 |
1289 @override | 1320 @override |
1290 void endAwaitExpression(Token keyword, Token endToken) { | 1321 void endAwaitExpression(Token keyword, Token endToken) { |
1291 debugEvent("AwaitExpression"); | 1322 debugEvent("AwaitExpression"); |
1292 push(astFactory.awaitExpression(keyword, popForValue())); | 1323 push(new KernelAwaitExpression(popForValue()) |
1324 ..fileOffset = offsetForToken(keyword)); | |
1293 } | 1325 } |
1294 | 1326 |
1295 @override | 1327 @override |
1296 void handleAsyncModifier(Token asyncToken, Token starToken) { | 1328 void handleAsyncModifier(Token asyncToken, Token starToken) { |
1297 debugEvent("AsyncModifier"); | 1329 debugEvent("AsyncModifier"); |
1298 push(asyncMarkerFromTokens(asyncToken, starToken)); | 1330 push(asyncMarkerFromTokens(asyncToken, starToken)); |
1299 } | 1331 } |
1300 | 1332 |
1301 @override | 1333 @override |
1302 void handleLiteralList( | 1334 void handleLiteralList( |
1303 int count, Token beginToken, Token constKeyword, Token endToken) { | 1335 int count, Token beginToken, Token constKeyword, Token endToken) { |
1304 debugEvent("LiteralList"); | 1336 debugEvent("LiteralList"); |
1305 List<Expression> expressions = popListForValue(count); | 1337 List<Expression> expressions = popListForValue(count); |
1306 List<DartType> typeArguments = pop(); | 1338 List<DartType> typeArguments = pop(); |
1307 DartType typeArgument; | 1339 DartType typeArgument; |
1308 if (typeArguments != null) { | 1340 if (typeArguments != null) { |
1309 typeArgument = typeArguments.first; | 1341 typeArgument = typeArguments.first; |
1310 if (typeArguments.length > 1) { | 1342 if (typeArguments.length > 1) { |
1311 typeArgument = null; | 1343 typeArgument = null; |
1312 warningNotError( | 1344 warningNotError( |
1313 "Too many type arguments on List literal.", beginToken.charOffset); | 1345 "Too many type arguments on List literal.", beginToken.charOffset); |
1314 } | 1346 } |
1315 } | 1347 } |
1316 push(astFactory.listLiteral(expressions, typeArgument, constKeyword != null, | 1348 push(new KernelListLiteral(expressions, |
1317 constKeyword ?? beginToken)); | 1349 typeArgument: typeArgument, isConst: constKeyword != null) |
1350 ..fileOffset = offsetForToken(constKeyword ?? beginToken)); | |
1318 } | 1351 } |
1319 | 1352 |
1320 @override | 1353 @override |
1321 void handleLiteralBool(Token token) { | 1354 void handleLiteralBool(Token token) { |
1322 debugEvent("LiteralBool"); | 1355 debugEvent("LiteralBool"); |
1323 bool value = optional("true", token); | 1356 bool value = optional("true", token); |
1324 assert(value || optional("false", token)); | 1357 assert(value || optional("false", token)); |
1325 push(astFactory.boolLiteral(value, token)); | 1358 push(new KernelBoolLiteral(value)..fileOffset = offsetForToken(token)); |
1326 } | 1359 } |
1327 | 1360 |
1328 @override | 1361 @override |
1329 void handleLiteralDouble(Token token) { | 1362 void handleLiteralDouble(Token token) { |
1330 debugEvent("LiteralDouble"); | 1363 debugEvent("LiteralDouble"); |
1331 push(astFactory.doubleLiteral(double.parse(token.lexeme), token)); | 1364 push(new KernelDoubleLiteral(double.parse(token.lexeme)) |
1365 ..fileOffset = offsetForToken(token)); | |
1332 } | 1366 } |
1333 | 1367 |
1334 @override | 1368 @override |
1335 void handleLiteralNull(Token token) { | 1369 void handleLiteralNull(Token token) { |
1336 debugEvent("LiteralNull"); | 1370 debugEvent("LiteralNull"); |
1337 push(astFactory.nullLiteral(token)); | 1371 push(new KernelNullLiteral()..fileOffset = offsetForToken(token)); |
1338 } | 1372 } |
1339 | 1373 |
1340 @override | 1374 @override |
1341 void handleLiteralMap( | 1375 void handleLiteralMap( |
1342 int count, Token beginToken, Token constKeyword, Token endToken) { | 1376 int count, Token beginToken, Token constKeyword, Token endToken) { |
1343 debugEvent("LiteralMap"); | 1377 debugEvent("LiteralMap"); |
1344 List<MapEntry> entries = popList(count) ?? <MapEntry>[]; | 1378 List<MapEntry> entries = popList(count) ?? <MapEntry>[]; |
1345 List<DartType> typeArguments = pop(); | 1379 List<DartType> typeArguments = pop(); |
1346 DartType keyType = const DynamicType(); | 1380 DartType keyType = const DynamicType(); |
1347 DartType valueType = const DynamicType(); | 1381 DartType valueType = const DynamicType(); |
1348 if (typeArguments != null) { | 1382 if (typeArguments != null) { |
1349 if (typeArguments.length != 2) { | 1383 if (typeArguments.length != 2) { |
1350 keyType = const DynamicType(); | 1384 keyType = const DynamicType(); |
1351 valueType = const DynamicType(); | 1385 valueType = const DynamicType(); |
1352 warningNotError( | 1386 warningNotError( |
1353 "Map literal requires two type arguments.", beginToken.charOffset); | 1387 "Map literal requires two type arguments.", beginToken.charOffset); |
1354 } else { | 1388 } else { |
1355 keyType = typeArguments[0]; | 1389 keyType = typeArguments[0]; |
1356 valueType = typeArguments[1]; | 1390 valueType = typeArguments[1]; |
1357 } | 1391 } |
1358 } | 1392 } |
1359 push(astFactory.mapLiteral(beginToken, constKeyword, entries, | 1393 push(new KernelMapLiteral(entries, |
1360 keyType: keyType, valueType: valueType)); | 1394 keyType: keyType, valueType: valueType, isConst: constKeyword != null) |
1395 ..fileOffset = constKeyword?.charOffset ?? offsetForToken(beginToken)); | |
1361 } | 1396 } |
1362 | 1397 |
1363 @override | 1398 @override |
1364 void endLiteralMapEntry(Token colon, Token endToken) { | 1399 void endLiteralMapEntry(Token colon, Token endToken) { |
1365 debugEvent("LiteralMapEntry"); | 1400 debugEvent("LiteralMapEntry"); |
1366 Expression value = popForValue(); | 1401 Expression value = popForValue(); |
1367 Expression key = popForValue(); | 1402 Expression key = popForValue(); |
1368 push(new MapEntry(key, value)); | 1403 push(new MapEntry(key, value)); |
1369 } | 1404 } |
1370 | 1405 |
(...skipping 13 matching lines...) Expand all Loading... | |
1384 String value; | 1419 String value; |
1385 if (identifierCount == 1) { | 1420 if (identifierCount == 1) { |
1386 value = symbolPartToString(pop()); | 1421 value = symbolPartToString(pop()); |
1387 } else { | 1422 } else { |
1388 List parts = popList(identifierCount); | 1423 List parts = popList(identifierCount); |
1389 value = symbolPartToString(parts.first); | 1424 value = symbolPartToString(parts.first); |
1390 for (int i = 1; i < parts.length; i++) { | 1425 for (int i = 1; i < parts.length; i++) { |
1391 value += ".${symbolPartToString(parts[i])}"; | 1426 value += ".${symbolPartToString(parts[i])}"; |
1392 } | 1427 } |
1393 } | 1428 } |
1394 push(astFactory.symbolLiteral(hashToken, value)); | 1429 push( |
1430 new KernelSymbolLiteral(value)..fileOffset = offsetForToken(hashToken)); | |
1395 } | 1431 } |
1396 | 1432 |
1397 DartType kernelTypeFromString( | 1433 DartType kernelTypeFromString( |
1398 String name, List<DartType> arguments, int charOffset) { | 1434 String name, List<DartType> arguments, int charOffset) { |
1399 Builder builder = scope.lookup(name, charOffset, uri); | 1435 Builder builder = scope.lookup(name, charOffset, uri); |
1400 if (builder == null) { | 1436 if (builder == null) { |
1401 warning("Type not found: '$name'.", charOffset); | 1437 warning("Type not found: '$name'.", charOffset); |
1402 return const DynamicType(); | 1438 return const DynamicType(); |
1403 } else { | 1439 } else { |
1404 return kernelTypeFromBuilder(builder, arguments, charOffset); | 1440 return kernelTypeFromBuilder(builder, arguments, charOffset); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1505 void handleVoidKeyword(Token token) { | 1541 void handleVoidKeyword(Token token) { |
1506 debugEvent("VoidKeyword"); | 1542 debugEvent("VoidKeyword"); |
1507 push(const VoidType()); | 1543 push(const VoidType()); |
1508 } | 1544 } |
1509 | 1545 |
1510 @override | 1546 @override |
1511 void handleAsOperator(Token operator, Token endToken) { | 1547 void handleAsOperator(Token operator, Token endToken) { |
1512 debugEvent("AsOperator"); | 1548 debugEvent("AsOperator"); |
1513 DartType type = pop(); | 1549 DartType type = pop(); |
1514 Expression expression = popForValue(); | 1550 Expression expression = popForValue(); |
1515 push(astFactory.asExpression(expression, operator, type)); | 1551 push(new KernelAsExpression(expression, type) |
1552 ..fileOffset = offsetForToken(operator)); | |
1516 } | 1553 } |
1517 | 1554 |
1518 @override | 1555 @override |
1519 void handleIsOperator(Token operator, Token not, Token endToken) { | 1556 void handleIsOperator(Token operator, Token not, Token endToken) { |
1520 debugEvent("IsOperator"); | 1557 debugEvent("IsOperator"); |
1521 DartType type = pop(); | 1558 DartType type = pop(); |
1522 Expression operand = popForValue(); | 1559 Expression operand = popForValue(); |
1523 bool isInverted = not != null; | 1560 bool isInverted = not != null; |
1524 Expression isExpression = | 1561 var offset = offsetForToken(operator); |
1525 astFactory.isExpression(operand, type, operator, isInverted); | 1562 Expression isExpression = isInverted |
1563 ? new KernelIsNotExpression(operand, type, offset) | |
1564 : new KernelIsExpression(operand, type) | |
1565 ..fileOffset = offset; | |
1526 if (operand is VariableGet) { | 1566 if (operand is VariableGet) { |
1527 typePromoter.handleIsCheck(isExpression, isInverted, operand.variable, | 1567 typePromoter.handleIsCheck(isExpression, isInverted, operand.variable, |
1528 type, functionNestingLevel); | 1568 type, functionNestingLevel); |
1529 } | 1569 } |
1530 push(isExpression); | 1570 push(isExpression); |
1531 } | 1571 } |
1532 | 1572 |
1533 @override | 1573 @override |
1534 void handleConditionalExpression(Token question, Token colon) { | 1574 void handleConditionalExpression(Token question, Token colon) { |
1535 debugEvent("ConditionalExpression"); | 1575 debugEvent("ConditionalExpression"); |
1536 Expression elseExpression = popForValue(); | 1576 Expression elseExpression = popForValue(); |
1537 Expression thenExpression = popForValue(); | 1577 Expression thenExpression = popForValue(); |
1538 Expression condition = popForValue(); | 1578 Expression condition = popForValue(); |
1539 push(astFactory.conditionalExpression( | 1579 push(new KernelConditionalExpression( |
1540 condition, thenExpression, elseExpression)); | 1580 condition, thenExpression, elseExpression)); |
1541 } | 1581 } |
1542 | 1582 |
1543 @override | 1583 @override |
1544 void endThrowExpression(Token throwToken, Token endToken) { | 1584 void endThrowExpression(Token throwToken, Token endToken) { |
1545 debugEvent("ThrowExpression"); | 1585 debugEvent("ThrowExpression"); |
1546 Expression expression = popForValue(); | 1586 Expression expression = popForValue(); |
1547 if (constantExpressionRequired) { | 1587 if (constantExpressionRequired) { |
1548 push(buildCompileTimeError( | 1588 push(buildCompileTimeError( |
1549 "Not a constant expression.", throwToken.charOffset)); | 1589 "Not a constant expression.", throwToken.charOffset)); |
1550 } else { | 1590 } else { |
1551 push(astFactory.throwExpression(throwToken, expression)); | 1591 push( |
1592 new KernelThrow(expression)..fileOffset = offsetForToken(throwToken)); | |
1552 } | 1593 } |
1553 } | 1594 } |
1554 | 1595 |
1555 @override | 1596 @override |
1556 void endFormalParameter(Token thisKeyword, Token nameToken, | 1597 void endFormalParameter(Token thisKeyword, Token nameToken, |
1557 FormalParameterType kind, MemberKind memberKind) { | 1598 FormalParameterType kind, MemberKind memberKind) { |
1558 debugEvent("FormalParameter"); | 1599 debugEvent("FormalParameter"); |
1559 if (thisKeyword != null) { | 1600 if (thisKeyword != null) { |
1560 if (!inConstructor) { | 1601 if (!inConstructor) { |
1561 addCompileTimeError(thisKeyword.charOffset, | 1602 addCompileTimeError(thisKeyword.charOffset, |
(...skipping 27 matching lines...) Expand all Loading... | |
1589 } else if (thisKeyword == null) { | 1630 } else if (thisKeyword == null) { |
1590 variable = builder.build(library); | 1631 variable = builder.build(library); |
1591 variable.initializer = name.initializer; | 1632 variable.initializer = name.initializer; |
1592 } else if (builder.isField && builder.parent == classBuilder) { | 1633 } else if (builder.isField && builder.parent == classBuilder) { |
1593 FieldBuilder field = builder; | 1634 FieldBuilder field = builder; |
1594 if (type != null) { | 1635 if (type != null) { |
1595 nit("Ignoring type on 'this' parameter '${name.name}'.", | 1636 nit("Ignoring type on 'this' parameter '${name.name}'.", |
1596 thisKeyword.charOffset); | 1637 thisKeyword.charOffset); |
1597 } | 1638 } |
1598 type = field.target.type; | 1639 type = field.target.type; |
1599 variable = astFactory.variableDeclaration( | 1640 variable = new KernelVariableDeclaration( |
1600 name.name, name.token, functionNestingLevel, | 1641 name.name, functionNestingLevel, |
1601 type: type, | 1642 type: type, |
1602 initializer: name.initializer, | 1643 initializer: name.initializer, |
1603 isFinal: isFinal, | 1644 isFinal: isFinal, |
1604 isConst: isConst); | 1645 isConst: isConst) |
1646 ..fileOffset = offsetForToken(name.token); | |
1605 } else { | 1647 } else { |
1606 addCompileTimeError(offsetForToken(name.token), | 1648 addCompileTimeError(offsetForToken(name.token), |
1607 "'${name.name}' isn't a field in this class."); | 1649 "'${name.name}' isn't a field in this class."); |
1608 } | 1650 } |
1609 } | 1651 } |
1610 variable ??= astFactory.variableDeclaration( | 1652 variable ??= new KernelVariableDeclaration(name?.name, functionNestingLevel, |
1611 name?.name, name?.token, functionNestingLevel, | |
1612 type: type, | 1653 type: type, |
1613 initializer: name?.initializer, | 1654 initializer: name?.initializer, |
1614 isFinal: isFinal, | 1655 isFinal: isFinal, |
1615 isConst: isConst); | 1656 isConst: isConst) |
1657 ..fileOffset = offsetForToken(name?.token); | |
1616 push(variable); | 1658 push(variable); |
1617 } | 1659 } |
1618 | 1660 |
1619 @override | 1661 @override |
1620 void endOptionalFormalParameters( | 1662 void endOptionalFormalParameters( |
1621 int count, Token beginToken, Token endToken) { | 1663 int count, Token beginToken, Token endToken) { |
1622 debugEvent("OptionalFormalParameters"); | 1664 debugEvent("OptionalFormalParameters"); |
1623 FormalParameterType kind = optional("{", beginToken) | 1665 FormalParameterType kind = optional("{", beginToken) |
1624 ? FormalParameterType.NAMED | 1666 ? FormalParameterType.NAMED |
1625 : FormalParameterType.POSITIONAL; | 1667 : FormalParameterType.POSITIONAL; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1763 push(IndexAccessor.make( | 1805 push(IndexAccessor.make( |
1764 this, openCurlyBracket, toValue(receiver), index, null, null)); | 1806 this, openCurlyBracket, toValue(receiver), index, null, null)); |
1765 } | 1807 } |
1766 } | 1808 } |
1767 | 1809 |
1768 @override | 1810 @override |
1769 void handleUnaryPrefixExpression(Token token) { | 1811 void handleUnaryPrefixExpression(Token token) { |
1770 debugEvent("UnaryPrefixExpression"); | 1812 debugEvent("UnaryPrefixExpression"); |
1771 var receiver = pop(); | 1813 var receiver = pop(); |
1772 if (optional("!", token)) { | 1814 if (optional("!", token)) { |
1773 push(astFactory.not(token, toValue(receiver))); | 1815 push( |
1816 new KernelNot(toValue(receiver))..fileOffset = offsetForToken(token)); | |
1774 } else { | 1817 } else { |
1775 String operator = token.stringValue; | 1818 String operator = token.stringValue; |
1776 if (optional("-", token)) { | 1819 if (optional("-", token)) { |
1777 operator = "unary-"; | 1820 operator = "unary-"; |
1778 } | 1821 } |
1779 if (receiver is ThisAccessor && receiver.isSuper) { | 1822 if (receiver is ThisAccessor && receiver.isSuper) { |
1780 push(toSuperMethodInvocation(buildMethodInvocation( | 1823 push(toSuperMethodInvocation(buildMethodInvocation( |
1781 astFactory, | 1824 new KernelThisExpression() |
1782 astFactory.thisExpression(receiver.token), | 1825 ..fileOffset = offsetForToken(receiver.token), |
1783 new Name(operator), | 1826 new Name(operator), |
1784 new Arguments.empty(), | 1827 new Arguments.empty(), |
1785 token.charOffset))); | 1828 token.charOffset))); |
1786 } else { | 1829 } else { |
1787 push(buildMethodInvocation(astFactory, toValue(receiver), | 1830 push(buildMethodInvocation(toValue(receiver), new Name(operator), |
1788 new Name(operator), new Arguments.empty(), token.charOffset)); | 1831 new Arguments.empty(), token.charOffset)); |
1789 } | 1832 } |
1790 } | 1833 } |
1791 } | 1834 } |
1792 | 1835 |
1793 Name incrementOperator(Token token) { | 1836 Name incrementOperator(Token token) { |
1794 if (optional("++", token)) return plusName; | 1837 if (optional("++", token)) return plusName; |
1795 if (optional("--", token)) return minusName; | 1838 if (optional("--", token)) return minusName; |
1796 return internalError("Unknown increment operator: ${token.lexeme}"); | 1839 return internalError("Unknown increment operator: ${token.lexeme}"); |
1797 } | 1840 } |
1798 | 1841 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1880 {bool isConst: false, int charOffset: -1}) { | 1923 {bool isConst: false, int charOffset: -1}) { |
1881 List<TypeParameter> typeParameters = target.function.typeParameters; | 1924 List<TypeParameter> typeParameters = target.function.typeParameters; |
1882 if (target is Constructor) { | 1925 if (target is Constructor) { |
1883 assert(!target.enclosingClass.isAbstract); | 1926 assert(!target.enclosingClass.isAbstract); |
1884 typeParameters = target.enclosingClass.typeParameters; | 1927 typeParameters = target.enclosingClass.typeParameters; |
1885 } | 1928 } |
1886 if (!checkArguments(target.function, arguments, typeParameters)) { | 1929 if (!checkArguments(target.function, arguments, typeParameters)) { |
1887 return throwNoSuchMethodError(target.name.name, arguments, charOffset); | 1930 return throwNoSuchMethodError(target.name.name, arguments, charOffset); |
1888 } | 1931 } |
1889 if (target is Constructor) { | 1932 if (target is Constructor) { |
1890 return astFactory.constructorInvocation(target, arguments, | 1933 return new KernelConstructorInvocation(target, arguments, |
1934 isConst: isConst) | |
1935 ..fileOffset = charOffset; | |
1936 } else if (target is Procedure && target.kind == ProcedureKind.Factory) { | |
1937 return new KernelFactoryConstructorInvocation(target, arguments, | |
1891 isConst: isConst) | 1938 isConst: isConst) |
1892 ..fileOffset = charOffset; | 1939 ..fileOffset = charOffset; |
1893 } else { | 1940 } else { |
1894 return astFactory.staticInvocation(target, arguments, isConst: isConst) | 1941 return new KernelStaticInvocation(target, arguments, isConst: isConst) |
1895 ..fileOffset = charOffset; | 1942 ..fileOffset = charOffset; |
1896 } | 1943 } |
1897 } | 1944 } |
1898 | 1945 |
1899 @override | 1946 @override |
1900 bool checkArguments(FunctionNode function, Arguments arguments, | 1947 bool checkArguments(FunctionNode function, Arguments arguments, |
1901 List<TypeParameter> typeParameters) { | 1948 List<TypeParameter> typeParameters) { |
1902 if (arguments.positional.length < function.requiredParameterCount || | 1949 if (arguments.positional.length < function.requiredParameterCount || |
1903 arguments.positional.length > function.positionalParameters.length) { | 1950 arguments.positional.length > function.positionalParameters.length) { |
1904 return false; | 1951 return false; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1971 var type = pop(); | 2018 var type = pop(); |
1972 bool savedConstantExpressionRequired = pop(); | 2019 bool savedConstantExpressionRequired = pop(); |
1973 () { | 2020 () { |
1974 if (arguments == null) { | 2021 if (arguments == null) { |
1975 push(buildCompileTimeError("No arguments.", nameToken.charOffset)); | 2022 push(buildCompileTimeError("No arguments.", nameToken.charOffset)); |
1976 return; | 2023 return; |
1977 } | 2024 } |
1978 | 2025 |
1979 if (typeArguments != null) { | 2026 if (typeArguments != null) { |
1980 assert(arguments.types.isEmpty); | 2027 assert(arguments.types.isEmpty); |
1981 astFactory.setExplicitArgumentTypes(arguments, typeArguments); | 2028 KernelArguments.setExplicitArgumentTypes(arguments, typeArguments); |
1982 } | 2029 } |
1983 | 2030 |
1984 String errorName; | 2031 String errorName; |
1985 if (type is ClassBuilder) { | 2032 if (type is ClassBuilder) { |
1986 Builder b = type.findConstructorOrFactory(name, token.charOffset, uri); | 2033 Builder b = type.findConstructorOrFactory(name, token.charOffset, uri); |
1987 Member target; | 2034 Member target; |
1988 if (b == null) { | 2035 if (b == null) { |
1989 // Not found. Reported below. | 2036 // Not found. Reported below. |
1990 } else if (b.isConstructor) { | 2037 } else if (b.isConstructor) { |
1991 if (type.isAbstract) { | 2038 if (type.isAbstract) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2065 debugEvent("NamedArgument"); | 2112 debugEvent("NamedArgument"); |
2066 Expression value = popForValue(); | 2113 Expression value = popForValue(); |
2067 Identifier identifier = pop(); | 2114 Identifier identifier = pop(); |
2068 push(new NamedExpression(identifier.name, value)); | 2115 push(new NamedExpression(identifier.name, value)); |
2069 } | 2116 } |
2070 | 2117 |
2071 @override | 2118 @override |
2072 void endFunctionName(Token beginToken, Token token) { | 2119 void endFunctionName(Token beginToken, Token token) { |
2073 debugEvent("FunctionName"); | 2120 debugEvent("FunctionName"); |
2074 Identifier name = pop(); | 2121 Identifier name = pop(); |
2075 VariableDeclaration variable = astFactory.variableDeclaration( | 2122 VariableDeclaration variable = new KernelVariableDeclaration( |
2076 name.name, name.token, functionNestingLevel, | 2123 name.name, functionNestingLevel, |
2077 isFinal: true, isLocalFunction: true); | 2124 isFinal: true, isLocalFunction: true) |
2125 ..fileOffset = offsetForToken(name.token); | |
2078 push(new KernelFunctionDeclaration( | 2126 push(new KernelFunctionDeclaration( |
2079 variable, new FunctionNode(new InvalidStatement())) | 2127 variable, new FunctionNode(new InvalidStatement())) |
2080 ..fileOffset = beginToken.charOffset); | 2128 ..fileOffset = beginToken.charOffset); |
2081 declareVariable(variable); | 2129 declareVariable(variable); |
2082 enterLocalScope(); | 2130 enterLocalScope(); |
2083 } | 2131 } |
2084 | 2132 |
2085 void enterFunction() { | 2133 void enterFunction() { |
2086 debugEvent("enterFunction"); | 2134 debugEvent("enterFunction"); |
2087 functionNestingLevel++; | 2135 functionNestingLevel++; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2147 Statement body = popStatement(); | 2195 Statement body = popStatement(); |
2148 AsyncMarker asyncModifier = pop(); | 2196 AsyncMarker asyncModifier = pop(); |
2149 exitLocalScope(); | 2197 exitLocalScope(); |
2150 FormalParameters formals = pop(); | 2198 FormalParameters formals = pop(); |
2151 exitFunction(); | 2199 exitFunction(); |
2152 List<TypeParameter> typeParameters = pop(); | 2200 List<TypeParameter> typeParameters = pop(); |
2153 FunctionNode function = formals.addToFunction(new FunctionNode(body, | 2201 FunctionNode function = formals.addToFunction(new FunctionNode(body, |
2154 typeParameters: typeParameters, asyncMarker: asyncModifier) | 2202 typeParameters: typeParameters, asyncMarker: asyncModifier) |
2155 ..fileOffset = beginToken.charOffset | 2203 ..fileOffset = beginToken.charOffset |
2156 ..fileEndOffset = token.charOffset); | 2204 ..fileEndOffset = token.charOffset); |
2157 push(astFactory.functionExpression(function, beginToken)); | 2205 push(new KernelFunctionExpression(function) |
2206 ..fileOffset = offsetForToken(beginToken)); | |
2158 } | 2207 } |
2159 | 2208 |
2160 @override | 2209 @override |
2161 void endDoWhileStatement( | 2210 void endDoWhileStatement( |
2162 Token doKeyword, Token whileKeyword, Token endToken) { | 2211 Token doKeyword, Token whileKeyword, Token endToken) { |
2163 debugEvent("DoWhileStatement"); | 2212 debugEvent("DoWhileStatement"); |
2164 Expression condition = popForValue(); | 2213 Expression condition = popForValue(); |
2165 Statement body = popStatement(); | 2214 Statement body = popStatement(); |
2166 JumpTarget continueTarget = exitContinueTarget(); | 2215 JumpTarget continueTarget = exitContinueTarget(); |
2167 JumpTarget breakTarget = exitBreakTarget(); | 2216 JumpTarget breakTarget = exitBreakTarget(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2213 /// for (lvalue in expression) body | 2262 /// for (lvalue in expression) body |
2214 /// | 2263 /// |
2215 /// This is normalized to: | 2264 /// This is normalized to: |
2216 /// | 2265 /// |
2217 /// for (final #t in expression) { | 2266 /// for (final #t in expression) { |
2218 /// lvalue = #t; | 2267 /// lvalue = #t; |
2219 /// body; | 2268 /// body; |
2220 /// } | 2269 /// } |
2221 variable = new VariableDeclaration.forValue(null); | 2270 variable = new VariableDeclaration.forValue(null); |
2222 body = combineStatements( | 2271 body = combineStatements( |
2223 astFactory.expressionStatement(lvalue | 2272 new KernelExpressionStatement(lvalue |
2224 .buildAssignment(new VariableGet(variable), voidContext: true)), | 2273 .buildAssignment(new VariableGet(variable), voidContext: true)), |
2225 body); | 2274 body); |
2226 } else { | 2275 } else { |
2227 variable = new VariableDeclaration.forValue(buildCompileTimeError( | 2276 variable = new VariableDeclaration.forValue(buildCompileTimeError( |
2228 "Expected lvalue, but got ${lvalue}", forToken.next.next.charOffset)); | 2277 "Expected lvalue, but got ${lvalue}", forToken.next.next.charOffset)); |
2229 } | 2278 } |
2230 Statement result = new ForInStatement(variable, expression, body, | 2279 Statement result = new ForInStatement(variable, expression, body, |
2231 isAsync: awaitToken != null) | 2280 isAsync: awaitToken != null) |
2232 ..fileOffset = body.fileOffset; | 2281 ..fileOffset = body.fileOffset; |
2233 if (breakTarget.hasUsers) { | 2282 if (breakTarget.hasUsers) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2275 } | 2324 } |
2276 target.continueTarget.resolveContinues(statement); | 2325 target.continueTarget.resolveContinues(statement); |
2277 } | 2326 } |
2278 push(statement); | 2327 push(statement); |
2279 } | 2328 } |
2280 | 2329 |
2281 @override | 2330 @override |
2282 void endRethrowStatement(Token rethrowToken, Token endToken) { | 2331 void endRethrowStatement(Token rethrowToken, Token endToken) { |
2283 debugEvent("RethrowStatement"); | 2332 debugEvent("RethrowStatement"); |
2284 if (inCatchBlock) { | 2333 if (inCatchBlock) { |
2285 push(astFactory | 2334 push(new KernelExpressionStatement( |
2286 .expressionStatement(astFactory.rethrowExpression(rethrowToken))); | 2335 new KernelRethrow()..fileOffset = offsetForToken(rethrowToken))); |
2287 } else { | 2336 } else { |
2288 push(buildCompileTimeErrorStatement( | 2337 push(buildCompileTimeErrorStatement( |
2289 "'rethrow' can only be used in catch clauses.", | 2338 "'rethrow' can only be used in catch clauses.", |
2290 rethrowToken.charOffset)); | 2339 rethrowToken.charOffset)); |
2291 } | 2340 } |
2292 } | 2341 } |
2293 | 2342 |
2294 @override | 2343 @override |
2295 void handleFinallyBlock(Token finallyKeyword) { | 2344 void handleFinallyBlock(Token finallyKeyword) { |
2296 debugEvent("FinallyBlock"); | 2345 debugEvent("FinallyBlock"); |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2570 } | 2619 } |
2571 return super.handleUnrecoverableError(token, message); | 2620 return super.handleUnrecoverableError(token, message); |
2572 } | 2621 } |
2573 | 2622 |
2574 @override | 2623 @override |
2575 Expression buildCompileTimeError(error, [int charOffset = -1]) { | 2624 Expression buildCompileTimeError(error, [int charOffset = -1]) { |
2576 addCompileTimeError(charOffset, error); | 2625 addCompileTimeError(charOffset, error); |
2577 String message = formatUnexpected(uri, charOffset, error); | 2626 String message = formatUnexpected(uri, charOffset, error); |
2578 Builder constructor = library.loader.getCompileTimeError(); | 2627 Builder constructor = library.loader.getCompileTimeError(); |
2579 return new Throw(buildStaticInvocation(constructor.target, | 2628 return new Throw(buildStaticInvocation(constructor.target, |
2580 astFactory.arguments(<Expression>[new StringLiteral(message)]))); | 2629 new KernelArguments(<Expression>[new StringLiteral(message)]))); |
2581 } | 2630 } |
2582 | 2631 |
2583 Expression buildAbstractClassInstantiationError(String className, | 2632 Expression buildAbstractClassInstantiationError(String className, |
2584 [int charOffset = -1]) { | 2633 [int charOffset = -1]) { |
2585 warning("The class '$className' is abstract and can't be instantiated.", | 2634 warning("The class '$className' is abstract and can't be instantiated.", |
2586 charOffset); | 2635 charOffset); |
2587 Builder constructor = library.loader.getAbstractClassInstantiationError(); | 2636 Builder constructor = library.loader.getAbstractClassInstantiationError(); |
2588 return new Throw(buildStaticInvocation(constructor.target, | 2637 return new Throw(buildStaticInvocation(constructor.target, |
2589 astFactory.arguments(<Expression>[new StringLiteral(className)]))); | 2638 new KernelArguments(<Expression>[new StringLiteral(className)]))); |
2590 } | 2639 } |
2591 | 2640 |
2592 Statement buildCompileTimeErrorStatement(error, [int charOffset = -1]) { | 2641 Statement buildCompileTimeErrorStatement(error, [int charOffset = -1]) { |
2593 return astFactory | 2642 return new KernelExpressionStatement( |
2594 .expressionStatement(buildCompileTimeError(error, charOffset)); | 2643 buildCompileTimeError(error, charOffset)); |
2595 } | 2644 } |
2596 | 2645 |
2597 @override | 2646 @override |
2598 Initializer buildInvalidIntializer(Expression expression, | 2647 Initializer buildInvalidIntializer(Expression expression, |
2599 [int charOffset = -1]) { | 2648 [int charOffset = -1]) { |
2600 needsImplicitSuperInitializer = false; | 2649 needsImplicitSuperInitializer = false; |
2601 return new LocalInitializer(new VariableDeclaration.forValue(expression)) | 2650 return new LocalInitializer(new VariableDeclaration.forValue(expression)) |
2602 ..fileOffset = charOffset; | 2651 ..fileOffset = charOffset; |
2603 } | 2652 } |
2604 | 2653 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2696 @override | 2745 @override |
2697 StaticGet makeStaticGet(Member readTarget, Token token) { | 2746 StaticGet makeStaticGet(Member readTarget, Token token) { |
2698 // TODO(paulberry): only record the dependencies mandated by the top level | 2747 // TODO(paulberry): only record the dependencies mandated by the top level |
2699 // type inference spec. | 2748 // type inference spec. |
2700 if (fieldDependencies != null && readTarget is KernelField) { | 2749 if (fieldDependencies != null && readTarget is KernelField) { |
2701 var fieldNode = _typeInferrer.getFieldNodeForReadTarget(readTarget); | 2750 var fieldNode = _typeInferrer.getFieldNodeForReadTarget(readTarget); |
2702 if (fieldNode != null) { | 2751 if (fieldNode != null) { |
2703 fieldDependencies.add(fieldNode); | 2752 fieldDependencies.add(fieldNode); |
2704 } | 2753 } |
2705 } | 2754 } |
2706 return astFactory.staticGet(readTarget, token); | 2755 return new KernelStaticGet(readTarget)..fileOffset = offsetForToken(token); |
2707 } | 2756 } |
2708 } | 2757 } |
2709 | 2758 |
2710 class Identifier { | 2759 class Identifier { |
2711 final Token token; | 2760 final Token token; |
2712 String get name => token.lexeme; | 2761 String get name => token.lexeme; |
2713 | 2762 |
2714 Identifier(this.token); | 2763 Identifier(this.token); |
2715 | 2764 |
2716 Expression get initializer => null; | 2765 Expression get initializer => null; |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3188 if (starToken == null) { | 3237 if (starToken == null) { |
3189 return AsyncMarker.Async; | 3238 return AsyncMarker.Async; |
3190 } else { | 3239 } else { |
3191 assert(identical(starToken.stringValue, "*")); | 3240 assert(identical(starToken.stringValue, "*")); |
3192 return AsyncMarker.AsyncStar; | 3241 return AsyncMarker.AsyncStar; |
3193 } | 3242 } |
3194 } else { | 3243 } else { |
3195 return internalError("Unknown async modifier: $asyncToken"); | 3244 return internalError("Unknown async modifier: $asyncToken"); |
3196 } | 3245 } |
3197 } | 3246 } |
OLD | NEW |