Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(417)

Side by Side Diff: pkg/front_end/lib/src/fasta/kernel/body_builder.dart

Issue 2746013003: [fasta] Add and correct even more offsets (Closed)
Patch Set: Removed formalParametersToken parameter Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 '../parser/parser.dart' show FormalParameterType, optional; 7 import '../parser/parser.dart' show FormalParameterType, optional;
8 8
9 import '../parser/error_kind.dart' show ErrorKind; 9 import '../parser/error_kind.dart' show ErrorKind;
10 10
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 218
219 List<Expression> popListForEffect(int n) { 219 List<Expression> popListForEffect(int n) {
220 List<Expression> list = 220 List<Expression> list =
221 new List<Expression>.filled(n, null, growable: true); 221 new List<Expression>.filled(n, null, growable: true);
222 for (int i = n - 1; i >= 0; i--) { 222 for (int i = n - 1; i >= 0; i--) {
223 list[i] = popForEffect(); 223 list[i] = popForEffect();
224 } 224 }
225 return list; 225 return list;
226 } 226 }
227 227
228 Block popBlock(int count) { 228 Block popBlock(int count, int charOffset) {
229 List<dynamic /*Statement | List<Statement>*/ > statements = 229 List<dynamic /*Statement | List<Statement>*/ > statements =
230 popList(count) ?? <Statement>[]; 230 popList(count) ?? <Statement>[];
231 List<Statement> copy; 231 List<Statement> copy;
232 for (int i = 0; i < statements.length; i++) { 232 for (int i = 0; i < statements.length; i++) {
233 var statement = statements[i]; 233 var statement = statements[i];
234 if (statement is List) { 234 if (statement is List) {
235 copy ??= new List<Statement>.from(statements.getRange(0, i)); 235 copy ??= new List<Statement>.from(statements.getRange(0, i));
236 // TODO(sigmund): remove this assignment (issue #28651) 236 // TODO(sigmund): remove this assignment (issue #28651)
237 Iterable subStatements = statement; 237 Iterable subStatements = statement;
238 copy.addAll(subStatements); 238 copy.addAll(subStatements);
239 } else if (copy != null) { 239 } else if (copy != null) {
240 copy.add(statement); 240 copy.add(statement);
241 } 241 }
242 } 242 }
243 return new Block(copy ?? statements); 243 return new Block(copy ?? statements)..fileOffset = charOffset;
244 } 244 }
245 245
246 Statement popStatementIfNotNull(Object value) { 246 Statement popStatementIfNotNull(Object value) {
247 return value == null ? null : popStatement(); 247 return value == null ? null : popStatement();
248 } 248 }
249 249
250 Statement popStatement() { 250 Statement popStatement() {
251 var statement = pop(); 251 var statement = pop();
252 if (statement is List) { 252 if (statement is List) {
253 return new Block(new List<Statement>.from(statement)); 253 return new Block(new List<Statement>.from(statement));
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 checkEmpty(-1); 349 checkEmpty(-1);
350 } 350 }
351 351
352 @override 352 @override
353 void endBlockFunctionBody(int count, Token beginToken, Token endToken) { 353 void endBlockFunctionBody(int count, Token beginToken, Token endToken) {
354 debugEvent("BlockFunctionBody"); 354 debugEvent("BlockFunctionBody");
355 if (beginToken == null) { 355 if (beginToken == null) {
356 assert(count == 0); 356 assert(count == 0);
357 push(NullValue.Block); 357 push(NullValue.Block);
358 } else { 358 } else {
359 Block block = popBlock(count); 359 Block block = popBlock(count, beginToken.charOffset);
360 exitLocalScope(); 360 exitLocalScope();
361 push(block); 361 push(block);
362 } 362 }
363 } 363 }
364 364
365 @override 365 @override
366 void prepareInitializers() { 366 void prepareInitializers() {
367 scope = formalParameterScope; 367 scope = formalParameterScope;
368 assert(fieldInitializers.isEmpty); 368 assert(fieldInitializers.isEmpty);
369 final member = this.member; 369 final member = this.member;
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 if (arguments != null && typeArguments != null) { 518 if (arguments != null && typeArguments != null) {
519 arguments.types.addAll(typeArguments); 519 arguments.types.addAll(typeArguments);
520 } else { 520 } else {
521 assert(typeArguments == null); 521 assert(typeArguments == null);
522 } 522 }
523 if (receiver is Identifier) { 523 if (receiver is Identifier) {
524 Name name = new Name(receiver.name, library.library); 524 Name name = new Name(receiver.name, library.library);
525 if (arguments == null) { 525 if (arguments == null) {
526 push(new IncompletePropertyAccessor(this, beginToken.charOffset, name)); 526 push(new IncompletePropertyAccessor(this, beginToken.charOffset, name));
527 } else { 527 } else {
528 push(new SendAccessor(this, endToken.charOffset, name, arguments)); 528 push(new SendAccessor(this, beginToken.charOffset, name, arguments));
529 } 529 }
530 } else if (arguments == null) { 530 } else if (arguments == null) {
531 push(receiver); 531 push(receiver);
532 } else { 532 } else {
533 push(finishSend(receiver, arguments, beginToken.charOffset)); 533 push(finishSend(receiver, arguments, beginToken.charOffset));
534 } 534 }
535 } 535 }
536 536
537 @override 537 @override
538 finishSend(Object receiver, Arguments arguments, int charOffset) { 538 finishSend(Object receiver, Arguments arguments, int charOffset) {
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 Token token = pop(); 813 Token token = pop();
814 push(new StringLiteral(unescapeString(token.lexeme))); 814 push(new StringLiteral(unescapeString(token.lexeme)));
815 } else { 815 } else {
816 List parts = popList(1 + interpolationCount * 2); 816 List parts = popList(1 + interpolationCount * 2);
817 Token first = parts.first; 817 Token first = parts.first;
818 Token last = parts.last; 818 Token last = parts.last;
819 Quote quote = analyzeQuote(first.lexeme); 819 Quote quote = analyzeQuote(first.lexeme);
820 List<Expression> expressions = <Expression>[]; 820 List<Expression> expressions = <Expression>[];
821 // Contains more than just \' or \". 821 // Contains more than just \' or \".
822 if (first.lexeme.length > 1) { 822 if (first.lexeme.length > 1) {
823 expressions 823 expressions.add(
824 .add(new StringLiteral(unescapeFirstStringPart(first.lexeme, quote))); 824 new StringLiteral(unescapeFirstStringPart(first.lexeme, quote)));
825 } 825 }
826 for (int i = 1; i < parts.length - 1; i++) { 826 for (int i = 1; i < parts.length - 1; i++) {
827 var part = parts[i]; 827 var part = parts[i];
828 if (part is Token) { 828 if (part is Token) {
829 if (part.lexeme.length != 0) { 829 if (part.lexeme.length != 0) {
830 expressions.add(new StringLiteral(unescape(part.lexeme, quote))); 830 expressions.add(new StringLiteral(unescape(part.lexeme, quote)));
831 } 831 }
832 } else { 832 } else {
833 expressions.add(toValue(part)); 833 expressions.add(toValue(part));
834 } 834 }
835 } 835 }
836 // Contains more than just \' or \". 836 // Contains more than just \' or \".
837 if (last.lexeme.length > 1) { 837 if (last.lexeme.length > 1) {
838 expressions 838 expressions
839 .add(new StringLiteral(unescapeLastStringPart(last.lexeme, quote))); 839 .add(new StringLiteral(unescapeLastStringPart(last.lexeme, quote)));
840 } 840 }
841 push(new StringConcatenation(expressions) 841 push(new StringConcatenation(expressions)
842 ..fileOffset = endToken.charOffset); 842 ..fileOffset = endToken.charOffset);
843 } 843 }
844 } 844 }
845 845
846 @override 846 @override
847 void handleScript(Token token) { 847 void handleScript(Token token) {
848 debugEvent("Script"); 848 debugEvent("Script");
849 } 849 }
(...skipping 28 matching lines...) Expand all
878 878
879 @override 879 @override
880 void handleEmptyFunctionBody(Token semicolon) { 880 void handleEmptyFunctionBody(Token semicolon) {
881 debugEvent("ExpressionFunctionBody"); 881 debugEvent("ExpressionFunctionBody");
882 endBlockFunctionBody(0, null, semicolon); 882 endBlockFunctionBody(0, null, semicolon);
883 } 883 }
884 884
885 @override 885 @override
886 void handleExpressionFunctionBody(Token arrowToken, Token endToken) { 886 void handleExpressionFunctionBody(Token arrowToken, Token endToken) {
887 debugEvent("ExpressionFunctionBody"); 887 debugEvent("ExpressionFunctionBody");
888 endReturnStatement(true, arrowToken, endToken); 888 endReturnStatement(true, arrowToken.next, endToken);
889 } 889 }
890 890
891 @override 891 @override
892 void endReturnStatement( 892 void endReturnStatement(
893 bool hasExpression, Token beginToken, Token endToken) { 893 bool hasExpression, Token beginToken, Token endToken) {
894 debugEvent("ReturnStatement"); 894 debugEvent("ReturnStatement");
895 Expression expression = hasExpression ? popForValue() : null; 895 Expression expression = hasExpression ? popForValue() : null;
896 if (expression != null && inConstructor) { 896 if (expression != null && inConstructor) {
897 push(buildCompileTimeErrorStatement( 897 push(buildCompileTimeErrorStatement(
898 "Can't return from a constructor.", beginToken.charOffset)); 898 "Can't return from a constructor.", beginToken.charOffset));
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 if (variables.length != 1) { 976 if (variables.length != 1) {
977 push(variables); 977 push(variables);
978 } else { 978 } else {
979 push(variables.single); 979 push(variables.single);
980 } 980 }
981 } 981 }
982 982
983 @override 983 @override
984 void endBlock(int count, Token beginToken, Token endToken) { 984 void endBlock(int count, Token beginToken, Token endToken) {
985 debugEvent("Block"); 985 debugEvent("Block");
986 Block block = popBlock(count); 986 Block block = popBlock(count, beginToken.charOffset);
987 exitLocalScope(); 987 exitLocalScope();
988 push(block); 988 push(block);
989 } 989 }
990 990
991 @override 991 @override
992 void handleAssignmentExpression(Token token) { 992 void handleAssignmentExpression(Token token) {
993 debugEvent("AssignmentExpression"); 993 debugEvent("AssignmentExpression");
994 Expression value = popForValue(); 994 Expression value = popForValue();
995 var accessor = pop(); 995 var accessor = pop();
996 if (accessor is TypeDeclarationBuilder) { 996 if (accessor is TypeDeclarationBuilder) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 if (breakTarget.hasUsers) { 1071 if (breakTarget.hasUsers) {
1072 result = new LabeledStatement(result); 1072 result = new LabeledStatement(result);
1073 breakTarget.resolveBreaks(result); 1073 breakTarget.resolveBreaks(result);
1074 } 1074 }
1075 exitLoopOrSwitch(result); 1075 exitLoopOrSwitch(result);
1076 } 1076 }
1077 1077
1078 @override 1078 @override
1079 void endAwaitExpression(Token beginToken, Token endToken) { 1079 void endAwaitExpression(Token beginToken, Token endToken) {
1080 debugEvent("AwaitExpression"); 1080 debugEvent("AwaitExpression");
1081 push(new AwaitExpression(popForValue())); 1081 push(
1082 new AwaitExpression(popForValue())..fileOffset = beginToken.charOffset);
1082 } 1083 }
1083 1084
1084 @override 1085 @override
1085 void handleAsyncModifier(Token asyncToken, Token starToken) { 1086 void handleAsyncModifier(Token asyncToken, Token starToken) {
1086 debugEvent("AsyncModifier"); 1087 debugEvent("AsyncModifier");
1087 push(asyncMarkerFromTokens(asyncToken, starToken)); 1088 push(asyncMarkerFromTokens(asyncToken, starToken));
1088 } 1089 }
1089 1090
1090 @override 1091 @override
1091 void handleLiteralList( 1092 void handleLiteralList(
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1306 } 1307 }
1307 1308
1308 @override 1309 @override
1309 void endThrowExpression(Token throwToken, Token endToken) { 1310 void endThrowExpression(Token throwToken, Token endToken) {
1310 debugEvent("ThrowExpression"); 1311 debugEvent("ThrowExpression");
1311 Expression expression = popForValue(); 1312 Expression expression = popForValue();
1312 push(new Throw(expression)..fileOffset = throwToken.charOffset); 1313 push(new Throw(expression)..fileOffset = throwToken.charOffset);
1313 } 1314 }
1314 1315
1315 @override 1316 @override
1316 void endFormalParameter( 1317 void endFormalParameter(Token covariantKeyword, Token thisKeyword,
1317 Token covariantKeyword, Token thisKeyword, FormalParameterType kind) { 1318 Token nameToken, FormalParameterType kind) {
1318 debugEvent("FormalParameter"); 1319 debugEvent("FormalParameter");
1319 // TODO(ahe): Need beginToken here. 1320 // TODO(ahe): Need beginToken here.
1320 int charOffset = thisKeyword?.charOffset; 1321 int charOffset = thisKeyword?.charOffset;
1321 if (thisKeyword != null) { 1322 if (thisKeyword != null) {
1322 if (!inConstructor) { 1323 if (!inConstructor) {
1323 addCompileTimeError(thisKeyword.charOffset, 1324 addCompileTimeError(thisKeyword.charOffset,
1324 "'this' parameters can only be used on constructors."); 1325 "'this' parameters can only be used on constructors.");
1325 thisKeyword = null; 1326 thisKeyword = null;
1326 } 1327 }
1327 } 1328 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1410 1411
1411 @override 1412 @override
1412 void endFormalParameters(int count, Token beginToken, Token endToken) { 1413 void endFormalParameters(int count, Token beginToken, Token endToken) {
1413 debugEvent("FormalParameters"); 1414 debugEvent("FormalParameters");
1414 OptionalFormals optional; 1415 OptionalFormals optional;
1415 if (count > 0 && peek() is OptionalFormals) { 1416 if (count > 0 && peek() is OptionalFormals) {
1416 optional = pop(); 1417 optional = pop();
1417 count--; 1418 count--;
1418 } 1419 }
1419 FormalParameters formals = new FormalParameters( 1420 FormalParameters formals = new FormalParameters(
1420 popList(count) ?? <VariableDeclaration>[], optional); 1421 popList(count) ?? <VariableDeclaration>[],
1422 optional,
1423 beginToken.charOffset);
1421 push(formals); 1424 push(formals);
1422 if (inCatchClause || functionNestingLevel != 0) { 1425 if (inCatchClause || functionNestingLevel != 0) {
1423 enterLocalScope(formals.computeFormalParameterScope( 1426 enterLocalScope(formals.computeFormalParameterScope(
1424 scope, member ?? classBuilder ?? library)); 1427 scope, member ?? classBuilder ?? library));
1425 } 1428 }
1426 } 1429 }
1427 1430
1428 @override 1431 @override
1429 void beginCatchClause(Token token) { 1432 void beginCatchClause(Token token) {
1430 debugEvent("beginCatchClause"); 1433 debugEvent("beginCatchClause");
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1619 Expression buildStaticInvocation(Member target, Arguments arguments, 1622 Expression buildStaticInvocation(Member target, Arguments arguments,
1620 {bool isConst: false, int charOffset: -1}) { 1623 {bool isConst: false, int charOffset: -1}) {
1621 List<TypeParameter> typeParameters = target.function.typeParameters; 1624 List<TypeParameter> typeParameters = target.function.typeParameters;
1622 if (target is Constructor) { 1625 if (target is Constructor) {
1623 typeParameters = target.enclosingClass.typeParameters; 1626 typeParameters = target.enclosingClass.typeParameters;
1624 } 1627 }
1625 if (!checkArguments(target.function, arguments, typeParameters)) { 1628 if (!checkArguments(target.function, arguments, typeParameters)) {
1626 return throwNoSuchMethodError(target.name.name, arguments, charOffset); 1629 return throwNoSuchMethodError(target.name.name, arguments, charOffset);
1627 } 1630 }
1628 if (target is Constructor) { 1631 if (target is Constructor) {
1629 return new ConstructorInvocation(target, arguments)..isConst = isConst; 1632 return new ConstructorInvocation(target, arguments)
1633 ..isConst = isConst
1634 ..fileOffset = charOffset;
1630 } else { 1635 } else {
1631 return new StaticInvocation(target, arguments)..isConst = isConst; 1636 return new StaticInvocation(target, arguments)
1637 ..isConst = isConst
1638 ..fileOffset = charOffset;
1632 } 1639 }
1633 } 1640 }
1634 1641
1635 bool checkArguments(FunctionNode function, Arguments arguments, 1642 bool checkArguments(FunctionNode function, Arguments arguments,
1636 List<TypeParameter> typeParameters) { 1643 List<TypeParameter> typeParameters) {
1637
1638 if (arguments.positional.length < function.requiredParameterCount || 1644 if (arguments.positional.length < function.requiredParameterCount ||
1639 arguments.positional.length > function.positionalParameters.length) { 1645 arguments.positional.length > function.positionalParameters.length) {
1640 return false; 1646 return false;
1641 } 1647 }
1642 Map<String, VariableDeclaration> names; 1648 Map<String, VariableDeclaration> names;
1643 if (function.namedParameters.isNotEmpty) { 1649 if (function.namedParameters.isNotEmpty) {
1644 names = <String, VariableDeclaration>{}; 1650 names = <String, VariableDeclaration>{};
1645 for (VariableDeclaration parameter in function.namedParameters) { 1651 for (VariableDeclaration parameter in function.namedParameters) {
1646 names[parameter.name] = parameter; 1652 names[parameter.name] = parameter;
1647 } 1653 }
(...skipping 13 matching lines...) Expand all
1661 arguments.types.add(const DynamicType()); 1667 arguments.types.add(const DynamicType());
1662 } 1668 }
1663 } 1669 }
1664 1670
1665 return true; 1671 return true;
1666 } 1672 }
1667 1673
1668 @override 1674 @override
1669 void handleNewExpression(Token token) { 1675 void handleNewExpression(Token token) {
1670 debugEvent("NewExpression"); 1676 debugEvent("NewExpression");
1677 Token nameToken = token.next;
1671 Arguments arguments = pop(); 1678 Arguments arguments = pop();
1672 String name = pop(); 1679 String name = pop();
1673 List<DartType> typeArguments = pop(); 1680 List<DartType> typeArguments = pop();
1674 var type = pop(); 1681 var type = pop();
1675 1682
1676 if (arguments == null) { 1683 if (arguments == null) {
1677 push(buildCompileTimeError("No arguments.", token.charOffset)); 1684 push(buildCompileTimeError("No arguments.", nameToken.charOffset));
1678 return; 1685 return;
1679 } 1686 }
1680 1687
1681 if (typeArguments != null) { 1688 if (typeArguments != null) {
1682 assert(arguments.types.isEmpty); 1689 assert(arguments.types.isEmpty);
1683 arguments.types.addAll(typeArguments); 1690 arguments.types.addAll(typeArguments);
1684 } 1691 }
1685 1692
1686 String errorName; 1693 String errorName;
1687 if (type is ClassBuilder) { 1694 if (type is ClassBuilder) {
1688 Builder b = type.findConstructorOrFactory(name); 1695 Builder b = type.findConstructorOrFactory(name);
1689 Member target; 1696 Member target;
1690 if (b == null) { 1697 if (b == null) {
1691 // Not found. Reported below. 1698 // Not found. Reported below.
1692 } else if (b.isConstructor) { 1699 } else if (b.isConstructor) {
1693 if (type.isAbstract) { 1700 if (type.isAbstract) {
1694 // TODO(ahe): Generate abstract instantiation error. 1701 // TODO(ahe): Generate abstract instantiation error.
1695 } else { 1702 } else {
1696 target = b.target; 1703 target = b.target;
1697 } 1704 }
1698 } else if (b.isFactory) { 1705 } else if (b.isFactory) {
1699 target = getRedirectionTarget(b.target); 1706 target = getRedirectionTarget(b.target);
1700 if (target == null) { 1707 if (target == null) {
1701 push(buildCompileTimeError( 1708 push(buildCompileTimeError(
1702 "Cyclic definition of factory '${name}'.", token.charOffset)); 1709 "Cyclic definition of factory '${name}'.", nameToken.charOffset));
1703 return; 1710 return;
1704 } 1711 }
1705 } 1712 }
1706 if (target is Constructor || 1713 if (target is Constructor ||
1707 (target is Procedure && target.kind == ProcedureKind.Factory)) { 1714 (target is Procedure && target.kind == ProcedureKind.Factory)) {
1708 push(buildStaticInvocation(target, arguments, 1715 push(buildStaticInvocation(target, arguments,
1709 isConst: optional("const", token), charOffset: token.charOffset)); 1716 isConst: optional("const", token),
1717 charOffset: nameToken.charOffset));
1710 return; 1718 return;
1711 } else { 1719 } else {
1712 errorName = debugName(type.name, name); 1720 errorName = debugName(type.name, name);
1713 } 1721 }
1714 } else { 1722 } else {
1715 errorName = debugName(getNodeName(type), name); 1723 errorName = debugName(getNodeName(type), name);
1716 } 1724 }
1717 errorName ??= name; 1725 errorName ??= name;
1718 push(throwNoSuchMethodError(errorName, arguments, token.charOffset)); 1726 push(throwNoSuchMethodError(errorName, arguments, nameToken.charOffset));
1719 } 1727 }
1720 1728
1721 @override 1729 @override
1722 void handleConstExpression(Token token) { 1730 void handleConstExpression(Token token) {
1723 debugEvent("ConstExpression"); 1731 debugEvent("ConstExpression");
1724 handleNewExpression(token); 1732 handleNewExpression(token);
1725 } 1733 }
1726 1734
1727 @override 1735 @override
1728 void endTypeArguments(int count, Token beginToken, Token endToken) { 1736 void endTypeArguments(int count, Token beginToken, Token endToken) {
(...skipping 28 matching lines...) Expand all
1757 1765
1758 @override 1766 @override
1759 void handleNamedArgument(Token colon) { 1767 void handleNamedArgument(Token colon) {
1760 debugEvent("NamedArgument"); 1768 debugEvent("NamedArgument");
1761 Expression value = popForValue(); 1769 Expression value = popForValue();
1762 Identifier identifier = pop(); 1770 Identifier identifier = pop();
1763 push(new NamedExpression(identifier.name, value)); 1771 push(new NamedExpression(identifier.name, value));
1764 } 1772 }
1765 1773
1766 @override 1774 @override
1767 void endFunctionName(Token token) { 1775 void endFunctionName(Token beginToken, Token token) {
1768 debugEvent("FunctionName"); 1776 debugEvent("FunctionName");
1769 Identifier name = pop(); 1777 Identifier name = pop();
1770 VariableDeclaration variable = 1778 VariableDeclaration variable =
1771 new VariableDeclaration(name.name, isFinal: true); 1779 new VariableDeclaration(name.name, isFinal: true);
1772 push(new FunctionDeclaration( 1780 push(new FunctionDeclaration(
1773 variable, new FunctionNode(new InvalidStatement()))); 1781 variable, new FunctionNode(new InvalidStatement()))
1782 ..fileOffset = beginToken.charOffset);
1774 scope[variable.name] = new KernelVariableBuilder( 1783 scope[variable.name] = new KernelVariableBuilder(
1775 variable, member ?? classBuilder ?? library, uri); 1784 variable, member ?? classBuilder ?? library, uri);
1776 enterLocalScope(); 1785 enterLocalScope();
1777 } 1786 }
1778 1787
1779 void enterFunction() { 1788 void enterFunction() {
1780 debugEvent("enterFunction"); 1789 debugEvent("enterFunction");
1781 functionNestingLevel++; 1790 functionNestingLevel++;
1782 push(switchScope ?? NullValue.SwitchScope); 1791 push(switchScope ?? NullValue.SwitchScope);
1783 switchScope = null; 1792 switchScope = null;
(...skipping 21 matching lines...) Expand all
1805 void endFunction(Token getOrSet, Token endToken) { 1814 void endFunction(Token getOrSet, Token endToken) {
1806 debugEvent("Function"); 1815 debugEvent("Function");
1807 Statement body = popStatement(); 1816 Statement body = popStatement();
1808 AsyncMarker asyncModifier = pop(); 1817 AsyncMarker asyncModifier = pop();
1809 if (functionNestingLevel != 0) { 1818 if (functionNestingLevel != 0) {
1810 exitLocalScope(); 1819 exitLocalScope();
1811 } 1820 }
1812 FormalParameters formals = pop(); 1821 FormalParameters formals = pop();
1813 List<TypeParameter> typeParameters = pop(); 1822 List<TypeParameter> typeParameters = pop();
1814 push(formals.addToFunction(new FunctionNode(body, 1823 push(formals.addToFunction(new FunctionNode(body,
1815 typeParameters: typeParameters, asyncMarker: asyncModifier))); 1824 typeParameters: typeParameters, asyncMarker: asyncModifier)
1825 ..fileOffset = formals.charOffset
1826 ..fileEndOffset = endToken.charOffset));
1816 } 1827 }
1817 1828
1818 @override 1829 @override
1819 void endFunctionDeclaration(Token token) { 1830 void endFunctionDeclaration(Token token) {
1820 debugEvent("FunctionDeclaration"); 1831 debugEvent("FunctionDeclaration");
1821 FunctionNode function = pop(); 1832 FunctionNode function = pop();
1822 exitLocalScope(); 1833 exitLocalScope();
1823 FunctionDeclaration declaration = pop(); 1834 FunctionDeclaration declaration = pop();
1824 function.returnType = pop() ?? const DynamicType(); 1835 function.returnType = pop() ?? const DynamicType();
1825 pop(); // Modifiers. 1836 pop(); // Modifiers.
1826 exitFunction(); 1837 exitFunction();
1827 declaration.function = function; 1838 declaration.function = function;
1828 function.parent = declaration; 1839 function.parent = declaration;
1829 push(declaration); 1840 push(declaration);
1830 } 1841 }
1831 1842
1832 @override 1843 @override
1833 void endUnnamedFunction(Token token) { 1844 void endUnnamedFunction(Token beginToken, Token token) {
1834 debugEvent("UnnamedFunction"); 1845 debugEvent("UnnamedFunction");
1835 Statement body = popStatement(); 1846 Statement body = popStatement();
1836 AsyncMarker asyncModifier = pop(); 1847 AsyncMarker asyncModifier = pop();
1837 exitLocalScope(); 1848 exitLocalScope();
1838 FormalParameters formals = pop(); 1849 FormalParameters formals = pop();
1839 exitFunction(); 1850 exitFunction();
1840 List<TypeParameter> typeParameters = pop(); 1851 List<TypeParameter> typeParameters = pop();
1841 FunctionNode function = formals.addToFunction(new FunctionNode(body, 1852 FunctionNode function = formals.addToFunction(new FunctionNode(body,
1842 typeParameters: typeParameters, asyncMarker: asyncModifier)); 1853 typeParameters: typeParameters, asyncMarker: asyncModifier)
1843 push(new FunctionExpression(function)); 1854 ..fileOffset = beginToken.charOffset
1855 ..fileEndOffset = token.charOffset);
1856 push(new FunctionExpression(function)..fileOffset = beginToken.charOffset);
1844 } 1857 }
1845 1858
1846 @override 1859 @override
1847 void endDoWhileStatement( 1860 void endDoWhileStatement(
1848 Token doKeyword, Token whileKeyword, Token endToken) { 1861 Token doKeyword, Token whileKeyword, Token endToken) {
1849 debugEvent("DoWhileStatement"); 1862 debugEvent("DoWhileStatement");
1850 Expression condition = popForValue(); 1863 Expression condition = popForValue();
1851 Statement body = popStatement(); 1864 Statement body = popStatement();
1852 JumpTarget continueTarget = exitContinueTarget(); 1865 JumpTarget continueTarget = exitContinueTarget();
1853 JumpTarget breakTarget = exitBreakTarget(); 1866 JumpTarget breakTarget = exitBreakTarget();
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1959 statement = new LabeledStatement(statement); 1972 statement = new LabeledStatement(statement);
1960 } 1973 }
1961 target.continueTarget.resolveContinues(statement); 1974 target.continueTarget.resolveContinues(statement);
1962 } 1975 }
1963 push(statement); 1976 push(statement);
1964 } 1977 }
1965 1978
1966 @override 1979 @override
1967 void endRethrowStatement(Token throwToken, Token endToken) { 1980 void endRethrowStatement(Token throwToken, Token endToken) {
1968 debugEvent("RethrowStatement"); 1981 debugEvent("RethrowStatement");
1969 push(new ExpressionStatement(new Rethrow())); 1982 push(new ExpressionStatement(
1983 new Rethrow()..fileOffset = throwToken.charOffset));
1970 } 1984 }
1971 1985
1972 @override 1986 @override
1973 void handleFinallyBlock(Token finallyKeyword) { 1987 void handleFinallyBlock(Token finallyKeyword) {
1974 debugEvent("FinallyBlock"); 1988 debugEvent("FinallyBlock");
1975 // Do nothing, handled by [endTryStatement]. 1989 // Do nothing, handled by [endTryStatement].
1976 } 1990 }
1977 1991
1978 @override 1992 @override
1979 void endWhileStatement(Token whileKeyword, Token endToken) { 1993 void endWhileStatement(Token whileKeyword, Token endToken) {
(...skipping 25 matching lines...) Expand all
2005 Token commaToken, Token rightParenthesis, Token semicolonToken) { 2019 Token commaToken, Token rightParenthesis, Token semicolonToken) {
2006 debugEvent("AssertStatement"); 2020 debugEvent("AssertStatement");
2007 Expression message = popForValueIfNotNull(commaToken); 2021 Expression message = popForValueIfNotNull(commaToken);
2008 Expression condition = popForValue(); 2022 Expression condition = popForValue();
2009 push(new AssertStatement(condition, message)); 2023 push(new AssertStatement(condition, message));
2010 } 2024 }
2011 2025
2012 @override 2026 @override
2013 void endYieldStatement(Token yieldToken, Token starToken, Token endToken) { 2027 void endYieldStatement(Token yieldToken, Token starToken, Token endToken) {
2014 debugEvent("YieldStatement"); 2028 debugEvent("YieldStatement");
2015 push(new YieldStatement(popForValue(), isYieldStar: starToken != null)); 2029 push(new YieldStatement(popForValue(), isYieldStar: starToken != null)
2030 ..fileOffset = yieldToken.charOffset);
2016 } 2031 }
2017 2032
2018 @override 2033 @override
2019 void beginSwitchBlock(Token token) { 2034 void beginSwitchBlock(Token token) {
2020 debugEvent("beginSwitchBlock"); 2035 debugEvent("beginSwitchBlock");
2021 enterLocalScope(); 2036 enterLocalScope();
2022 enterSwitchScope(); 2037 enterSwitchScope();
2023 enterBreakTarget(token.charOffset); 2038 enterBreakTarget(token.charOffset);
2024 } 2039 }
2025 2040
(...skipping 28 matching lines...) Expand all
2054 2069
2055 @override 2070 @override
2056 void handleSwitchCase( 2071 void handleSwitchCase(
2057 int labelCount, 2072 int labelCount,
2058 int expressionCount, 2073 int expressionCount,
2059 Token defaultKeyword, 2074 Token defaultKeyword,
2060 int statementCount, 2075 int statementCount,
2061 Token firstToken, 2076 Token firstToken,
2062 Token endToken) { 2077 Token endToken) {
2063 debugEvent("SwitchCase"); 2078 debugEvent("SwitchCase");
2064 Block block = popBlock(statementCount); 2079 Block block = popBlock(statementCount, firstToken.charOffset);
2065 exitLocalScope(); 2080 exitLocalScope();
2066 List<Label> labels = pop(); 2081 List<Label> labels = pop();
2067 List<Expression> expressions = pop(); 2082 List<Expression> expressions = pop();
2068 push(new SwitchCase(expressions, block, isDefault: defaultKeyword != null) 2083 push(new SwitchCase(expressions, block, isDefault: defaultKeyword != null)
2069 ..fileOffset = firstToken.charOffset); 2084 ..fileOffset = firstToken.charOffset);
2070 push(labels); 2085 push(labels);
2071 } 2086 }
2072 2087
2073 @override 2088 @override
2074 void endSwitchStatement(Token switchKeyword, Token endToken) { 2089 void endSwitchStatement(Token switchKeyword, Token endToken) {
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
2648 final FormalParameterType kind; 2663 final FormalParameterType kind;
2649 2664
2650 final List<VariableDeclaration> formals; 2665 final List<VariableDeclaration> formals;
2651 2666
2652 OptionalFormals(this.kind, this.formals); 2667 OptionalFormals(this.kind, this.formals);
2653 } 2668 }
2654 2669
2655 class FormalParameters { 2670 class FormalParameters {
2656 final List<VariableDeclaration> required; 2671 final List<VariableDeclaration> required;
2657 final OptionalFormals optional; 2672 final OptionalFormals optional;
2673 final int charOffset;
2658 2674
2659 FormalParameters(this.required, this.optional); 2675 FormalParameters(this.required, this.optional, this.charOffset);
2660 2676
2661 FunctionNode addToFunction(FunctionNode function) { 2677 FunctionNode addToFunction(FunctionNode function) {
2662 function.requiredParameterCount = required.length; 2678 function.requiredParameterCount = required.length;
2663 function.positionalParameters.addAll(required); 2679 function.positionalParameters.addAll(required);
2664 if (optional != null) { 2680 if (optional != null) {
2665 if (optional.kind.isPositional) { 2681 if (optional.kind.isPositional) {
2666 function.positionalParameters.addAll(optional.formals); 2682 function.positionalParameters.addAll(optional.formals);
2667 } else { 2683 } else {
2668 function.namedParameters.addAll(optional.formals); 2684 function.namedParameters.addAll(optional.formals);
2669 setParents(function.namedParameters, function); 2685 setParents(function.namedParameters, function);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
2749 } else if (node is PrefixBuilder) { 2765 } else if (node is PrefixBuilder) {
2750 return node.name; 2766 return node.name;
2751 } else if (node is ThisAccessor) { 2767 } else if (node is ThisAccessor) {
2752 return node.isSuper ? "super" : "this"; 2768 return node.isSuper ? "super" : "this";
2753 } else if (node is BuilderAccessor) { 2769 } else if (node is BuilderAccessor) {
2754 return node.plainNameForRead; 2770 return node.plainNameForRead;
2755 } else { 2771 } else {
2756 return internalError("Unhandled: ${node.runtimeType}"); 2772 return internalError("Unhandled: ${node.runtimeType}");
2757 } 2773 }
2758 } 2774 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/parser/node_listener.dart ('k') | pkg/front_end/lib/src/fasta/kernel/builder_accessors.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698