| 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 '../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 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 Builder computeSetter( | 709 Builder computeSetter( |
| 710 Builder builder, Scope scope, String name, int charOffset) { | 710 Builder builder, Scope scope, String name, int charOffset) { |
| 711 if (builder.isSetter) return builder; | 711 if (builder.isSetter) return builder; |
| 712 if (builder.isGetter) return scope.lookupSetter(name, charOffset, uri); | 712 if (builder.isGetter) return scope.lookupSetter(name, charOffset, uri); |
| 713 return builder.isField ? (builder.isFinal ? null : builder) : null; | 713 return builder.isField ? (builder.isFinal ? null : builder) : null; |
| 714 } | 714 } |
| 715 | 715 |
| 716 @override | 716 @override |
| 717 void handleIdentifier(Token token, IdentifierContext context) { | 717 void handleIdentifier(Token token, IdentifierContext context) { |
| 718 debugEvent("handleIdentifier"); | 718 debugEvent("handleIdentifier"); |
| 719 String name = token.value; | 719 String name = token.lexeme; |
| 720 if (isFirstIdentifier) { | 720 if (isFirstIdentifier) { |
| 721 assert(!inInitializer || | 721 assert(!inInitializer || |
| 722 this.scope == enclosingScope || | 722 this.scope == enclosingScope || |
| 723 this.scope.parent == enclosingScope); | 723 this.scope.parent == enclosingScope); |
| 724 // This deals with this kind of initializer: `C(a) : a = a;` | 724 // This deals with this kind of initializer: `C(a) : a = a;` |
| 725 Scope scope = inInitializer ? enclosingScope : this.scope; | 725 Scope scope = inInitializer ? enclosingScope : this.scope; |
| 726 Builder builder = scope.lookup(name, token.charOffset, uri); | 726 Builder builder = scope.lookup(name, token.charOffset, uri); |
| 727 push(builderToFirstExpression(builder, name, token.charOffset)); | 727 push(builderToFirstExpression(builder, name, token.charOffset)); |
| 728 } else { | 728 } else { |
| 729 push(new Identifier(name)..fileOffset = token.charOffset); | 729 push(new Identifier(name)..fileOffset = token.charOffset); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 void handleStringPart(Token token) { | 792 void handleStringPart(Token token) { |
| 793 debugEvent("StringPart"); | 793 debugEvent("StringPart"); |
| 794 push(token); | 794 push(token); |
| 795 } | 795 } |
| 796 | 796 |
| 797 @override | 797 @override |
| 798 void endLiteralString(int interpolationCount) { | 798 void endLiteralString(int interpolationCount) { |
| 799 debugEvent("endLiteralString"); | 799 debugEvent("endLiteralString"); |
| 800 if (interpolationCount == 0) { | 800 if (interpolationCount == 0) { |
| 801 Token token = pop(); | 801 Token token = pop(); |
| 802 push(new StringLiteral(unescapeString(token.value))); | 802 push(new StringLiteral(unescapeString(token.lexeme))); |
| 803 } else { | 803 } else { |
| 804 List parts = popList(1 + interpolationCount * 2); | 804 List parts = popList(1 + interpolationCount * 2); |
| 805 Token first = parts.first; | 805 Token first = parts.first; |
| 806 Token last = parts.last; | 806 Token last = parts.last; |
| 807 Quote quote = analyzeQuote(first.value); | 807 Quote quote = analyzeQuote(first.lexeme); |
| 808 List<Expression> expressions = <Expression>[]; | 808 List<Expression> expressions = <Expression>[]; |
| 809 expressions | 809 expressions |
| 810 .add(new StringLiteral(unescapeFirstStringPart(first.value, quote))); | 810 .add(new StringLiteral(unescapeFirstStringPart(first.lexeme, quote))); |
| 811 for (int i = 1; i < parts.length - 1; i++) { | 811 for (int i = 1; i < parts.length - 1; i++) { |
| 812 var part = parts[i]; | 812 var part = parts[i]; |
| 813 if (part is Token) { | 813 if (part is Token) { |
| 814 expressions.add(new StringLiteral(unescape(part.value, quote))); | 814 expressions.add(new StringLiteral(unescape(part.lexeme, quote))); |
| 815 } else { | 815 } else { |
| 816 expressions.add(toValue(part)); | 816 expressions.add(toValue(part)); |
| 817 } | 817 } |
| 818 } | 818 } |
| 819 expressions | 819 expressions |
| 820 .add(new StringLiteral(unescapeLastStringPart(last.value, quote))); | 820 .add(new StringLiteral(unescapeLastStringPart(last.lexeme, quote))); |
| 821 push(new StringConcatenation(expressions)); | 821 push(new StringConcatenation(expressions)); |
| 822 } | 822 } |
| 823 } | 823 } |
| 824 | 824 |
| 825 @override | 825 @override |
| 826 void handleScript(Token token) { | 826 void handleScript(Token token) { |
| 827 debugEvent("Script"); | 827 debugEvent("Script"); |
| 828 } | 828 } |
| 829 | 829 |
| 830 @override | 830 @override |
| (...skipping 14 matching lines...) Expand all Loading... |
| 845 expressions.add(part); | 845 expressions.add(part); |
| 846 } | 846 } |
| 847 } | 847 } |
| 848 } | 848 } |
| 849 push(new StringConcatenation(expressions ?? parts)); | 849 push(new StringConcatenation(expressions ?? parts)); |
| 850 } | 850 } |
| 851 | 851 |
| 852 @override | 852 @override |
| 853 void handleLiteralInt(Token token) { | 853 void handleLiteralInt(Token token) { |
| 854 debugEvent("LiteralInt"); | 854 debugEvent("LiteralInt"); |
| 855 push(new IntLiteral(int.parse(token.value))); | 855 push(new IntLiteral(int.parse(token.lexeme))); |
| 856 } | 856 } |
| 857 | 857 |
| 858 @override | 858 @override |
| 859 void endExpressionFunctionBody(Token arrowToken, Token endToken) { | 859 void endExpressionFunctionBody(Token arrowToken, Token endToken) { |
| 860 debugEvent("ExpressionFunctionBody"); | 860 debugEvent("ExpressionFunctionBody"); |
| 861 endReturnStatement(true, arrowToken, endToken); | 861 endReturnStatement(true, arrowToken, endToken); |
| 862 } | 862 } |
| 863 | 863 |
| 864 @override | 864 @override |
| 865 void endReturnStatement( | 865 void endReturnStatement( |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1083 void handleLiteralBool(Token token) { | 1083 void handleLiteralBool(Token token) { |
| 1084 debugEvent("LiteralBool"); | 1084 debugEvent("LiteralBool"); |
| 1085 bool value = optional("true", token); | 1085 bool value = optional("true", token); |
| 1086 assert(value || optional("false", token)); | 1086 assert(value || optional("false", token)); |
| 1087 push(new BoolLiteral(value)); | 1087 push(new BoolLiteral(value)); |
| 1088 } | 1088 } |
| 1089 | 1089 |
| 1090 @override | 1090 @override |
| 1091 void handleLiteralDouble(Token token) { | 1091 void handleLiteralDouble(Token token) { |
| 1092 debugEvent("LiteralDouble"); | 1092 debugEvent("LiteralDouble"); |
| 1093 push(new DoubleLiteral(double.parse(token.value))); | 1093 push(new DoubleLiteral(double.parse(token.lexeme))); |
| 1094 } | 1094 } |
| 1095 | 1095 |
| 1096 @override | 1096 @override |
| 1097 void handleLiteralNull(Token token) { | 1097 void handleLiteralNull(Token token) { |
| 1098 debugEvent("LiteralNull"); | 1098 debugEvent("LiteralNull"); |
| 1099 push(new NullLiteral()); | 1099 push(new NullLiteral()); |
| 1100 } | 1100 } |
| 1101 | 1101 |
| 1102 @override | 1102 @override |
| 1103 void handleLiteralMap( | 1103 void handleLiteralMap( |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1207 push(const DynamicType()); | 1207 push(const DynamicType()); |
| 1208 addCompileTimeError(beginToken.charOffset, | 1208 addCompileTimeError(beginToken.charOffset, |
| 1209 "Can't be used as a type: '${debugName(prefix, suffix)}'."); | 1209 "Can't be used as a type: '${debugName(prefix, suffix)}'."); |
| 1210 return; | 1210 return; |
| 1211 } | 1211 } |
| 1212 } | 1212 } |
| 1213 if (name is Identifier) { | 1213 if (name is Identifier) { |
| 1214 name = name.name; | 1214 name = name.name; |
| 1215 } | 1215 } |
| 1216 if (name is BuilderAccessor) { | 1216 if (name is BuilderAccessor) { |
| 1217 warning("'${beginToken.value}' isn't a type.", beginToken.charOffset); | 1217 warning("'${beginToken.lexeme}' isn't a type.", beginToken.charOffset); |
| 1218 push(const DynamicType()); | 1218 push(const DynamicType()); |
| 1219 } else if (name is UnresolvedIdentifier) { | 1219 } else if (name is UnresolvedIdentifier) { |
| 1220 warning("'${name.name}' isn't a type.", beginToken.charOffset); | 1220 warning("'${name.name}' isn't a type.", beginToken.charOffset); |
| 1221 push(const DynamicType()); | 1221 push(const DynamicType()); |
| 1222 } else if (name is TypeVariableBuilder) { | 1222 } else if (name is TypeVariableBuilder) { |
| 1223 push(name.buildTypesWithBuiltArguments(library, arguments)); | 1223 push(name.buildTypesWithBuiltArguments(library, arguments)); |
| 1224 } else if (name is TypeDeclarationBuilder) { | 1224 } else if (name is TypeDeclarationBuilder) { |
| 1225 push(name.buildTypesWithBuiltArguments(library, arguments)); | 1225 push(name.buildTypesWithBuiltArguments(library, arguments)); |
| 1226 } else if (name is TypeBuilder) { | 1226 } else if (name is TypeBuilder) { |
| 1227 push(name.build(library)); | 1227 push(name.build(library)); |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1495 } else { | 1495 } else { |
| 1496 push(buildMethodInvocation(toValue(receiver), new Name(operator), | 1496 push(buildMethodInvocation(toValue(receiver), new Name(operator), |
| 1497 new Arguments.empty(), token.charOffset)); | 1497 new Arguments.empty(), token.charOffset)); |
| 1498 } | 1498 } |
| 1499 } | 1499 } |
| 1500 } | 1500 } |
| 1501 | 1501 |
| 1502 Name incrementOperator(Token token) { | 1502 Name incrementOperator(Token token) { |
| 1503 if (optional("++", token)) return plusName; | 1503 if (optional("++", token)) return plusName; |
| 1504 if (optional("--", token)) return minusName; | 1504 if (optional("--", token)) return minusName; |
| 1505 return internalError("Unknown increment operator: ${token.value}"); | 1505 return internalError("Unknown increment operator: ${token.lexeme}"); |
| 1506 } | 1506 } |
| 1507 | 1507 |
| 1508 @override | 1508 @override |
| 1509 void handleUnaryPrefixAssignmentExpression(Token token) { | 1509 void handleUnaryPrefixAssignmentExpression(Token token) { |
| 1510 debugEvent("UnaryPrefixAssignmentExpression"); | 1510 debugEvent("UnaryPrefixAssignmentExpression"); |
| 1511 var accessor = pop(); | 1511 var accessor = pop(); |
| 1512 if (accessor is BuilderAccessor) { | 1512 if (accessor is BuilderAccessor) { |
| 1513 push(accessor.buildPrefixIncrement(incrementOperator(token))); | 1513 push(accessor.buildPrefixIncrement(incrementOperator(token))); |
| 1514 } else { | 1514 } else { |
| 1515 push(wrapInvalid(toValue(accessor))); | 1515 push(wrapInvalid(toValue(accessor))); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1559 var prefix = type[0]; | 1559 var prefix = type[0]; |
| 1560 identifier = type[1]; | 1560 identifier = type[1]; |
| 1561 if (prefix is PrefixBuilder) { | 1561 if (prefix is PrefixBuilder) { |
| 1562 // TODO(ahe): Handle privacy in prefix.exports. | 1562 // TODO(ahe): Handle privacy in prefix.exports. |
| 1563 type = builderToFirstExpression( | 1563 type = builderToFirstExpression( |
| 1564 prefix.exports[identifier.name], identifier.name, start.charOffset); | 1564 prefix.exports[identifier.name], identifier.name, start.charOffset); |
| 1565 identifier = null; | 1565 identifier = null; |
| 1566 } else if (prefix is ClassBuilder) { | 1566 } else if (prefix is ClassBuilder) { |
| 1567 type = prefix; | 1567 type = prefix; |
| 1568 } else { | 1568 } else { |
| 1569 type = new Identifier(start.value)..fileOffset = start.charOffset; | 1569 type = new Identifier(start.lexeme)..fileOffset = start.charOffset; |
| 1570 } | 1570 } |
| 1571 } | 1571 } |
| 1572 String name; | 1572 String name; |
| 1573 if (identifier != null && suffix != null) { | 1573 if (identifier != null && suffix != null) { |
| 1574 name = "${identifier.name}.${suffix.name}"; | 1574 name = "${identifier.name}.${suffix.name}"; |
| 1575 } else if (identifier != null) { | 1575 } else if (identifier != null) { |
| 1576 name = identifier.name; | 1576 name = identifier.name; |
| 1577 } else if (suffix != null) { | 1577 } else if (suffix != null) { |
| 1578 name = suffix.name; | 1578 name = suffix.name; |
| 1579 } else { | 1579 } else { |
| (...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2206 | 2206 |
| 2207 @override | 2207 @override |
| 2208 Token handleUnrecoverableError(Token token, ErrorKind kind, Map arguments) { | 2208 Token handleUnrecoverableError(Token token, ErrorKind kind, Map arguments) { |
| 2209 if (isDartLibrary && kind == ErrorKind.ExpectedFunctionBody) { | 2209 if (isDartLibrary && kind == ErrorKind.ExpectedFunctionBody) { |
| 2210 Token recover = skipNativeClause(token); | 2210 Token recover = skipNativeClause(token); |
| 2211 if (recover != null) return recover; | 2211 if (recover != null) return recover; |
| 2212 } else if (kind == ErrorKind.UnexpectedToken) { | 2212 } else if (kind == ErrorKind.UnexpectedToken) { |
| 2213 String expected = arguments["expected"]; | 2213 String expected = arguments["expected"]; |
| 2214 const List<String> trailing = const <String>[")", "}", ";", ","]; | 2214 const List<String> trailing = const <String>[")", "}", ";", ","]; |
| 2215 if (trailing.contains(token.stringValue) && trailing.contains(expected)) { | 2215 if (trailing.contains(token.stringValue) && trailing.contains(expected)) { |
| 2216 arguments.putIfAbsent("actual", () => token.value); | 2216 arguments.putIfAbsent("actual", () => token.lexeme); |
| 2217 handleRecoverableError(token, ErrorKind.ExpectedButGot, arguments); | 2217 handleRecoverableError(token, ErrorKind.ExpectedButGot, arguments); |
| 2218 return token; | 2218 return token; |
| 2219 } | 2219 } |
| 2220 } | 2220 } |
| 2221 return super.handleUnrecoverableError(token, kind, arguments); | 2221 return super.handleUnrecoverableError(token, kind, arguments); |
| 2222 } | 2222 } |
| 2223 | 2223 |
| 2224 @override | 2224 @override |
| 2225 Expression buildCompileTimeError(error, [int charOffset = -1]) { | 2225 Expression buildCompileTimeError(error, [int charOffset = -1]) { |
| 2226 String message = printUnexpected(uri, charOffset, error); | 2226 String message = printUnexpected(uri, charOffset, error); |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2714 } else if (node is PrefixBuilder) { | 2714 } else if (node is PrefixBuilder) { |
| 2715 return node.name; | 2715 return node.name; |
| 2716 } else if (node is ThisAccessor) { | 2716 } else if (node is ThisAccessor) { |
| 2717 return node.isSuper ? "super" : "this"; | 2717 return node.isSuper ? "super" : "this"; |
| 2718 } else if (node is BuilderAccessor) { | 2718 } else if (node is BuilderAccessor) { |
| 2719 return node.plainNameForRead; | 2719 return node.plainNameForRead; |
| 2720 } else { | 2720 } else { |
| 2721 return internalError("Unhandled: ${node.runtimeType}"); | 2721 return internalError("Unhandled: ${node.runtimeType}"); |
| 2722 } | 2722 } |
| 2723 } | 2723 } |
| OLD | NEW |