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

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

Issue 2738313002: rename fasta.Token.value --> lexeme (Closed)
Patch Set: merge 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 699 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 Builder computeSetter( 710 Builder computeSetter(
711 Builder builder, Scope scope, String name, int charOffset) { 711 Builder builder, Scope scope, String name, int charOffset) {
712 if (builder.isSetter) return builder; 712 if (builder.isSetter) return builder;
713 if (builder.isGetter) return scope.lookupSetter(name, charOffset, uri); 713 if (builder.isGetter) return scope.lookupSetter(name, charOffset, uri);
714 return builder.isField ? (builder.isFinal ? null : builder) : null; 714 return builder.isField ? (builder.isFinal ? null : builder) : null;
715 } 715 }
716 716
717 @override 717 @override
718 void handleIdentifier(Token token, IdentifierContext context) { 718 void handleIdentifier(Token token, IdentifierContext context) {
719 debugEvent("handleIdentifier"); 719 debugEvent("handleIdentifier");
720 String name = token.value; 720 String name = token.lexeme;
721 if (isFirstIdentifier) { 721 if (isFirstIdentifier) {
722 assert(!inInitializer || 722 assert(!inInitializer ||
723 this.scope == enclosingScope || 723 this.scope == enclosingScope ||
724 this.scope.parent == enclosingScope); 724 this.scope.parent == enclosingScope);
725 // This deals with this kind of initializer: `C(a) : a = a;` 725 // This deals with this kind of initializer: `C(a) : a = a;`
726 Scope scope = inInitializer ? enclosingScope : this.scope; 726 Scope scope = inInitializer ? enclosingScope : this.scope;
727 Builder builder = scope.lookup(name, token.charOffset, uri); 727 Builder builder = scope.lookup(name, token.charOffset, uri);
728 push(builderToFirstExpression(builder, name, token.charOffset)); 728 push(builderToFirstExpression(builder, name, token.charOffset));
729 } else { 729 } else {
730 push(new Identifier(name)..fileOffset = token.charOffset); 730 push(new Identifier(name)..fileOffset = token.charOffset);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 void handleStringPart(Token token) { 793 void handleStringPart(Token token) {
794 debugEvent("StringPart"); 794 debugEvent("StringPart");
795 push(token); 795 push(token);
796 } 796 }
797 797
798 @override 798 @override
799 void endLiteralString(int interpolationCount, Token endToken) { 799 void endLiteralString(int interpolationCount, Token endToken) {
800 debugEvent("endLiteralString"); 800 debugEvent("endLiteralString");
801 if (interpolationCount == 0) { 801 if (interpolationCount == 0) {
802 Token token = pop(); 802 Token token = pop();
803 push(new StringLiteral(unescapeString(token.value))); 803 push(new StringLiteral(unescapeString(token.lexeme)));
804 } else { 804 } else {
805 List parts = popList(1 + interpolationCount * 2); 805 List parts = popList(1 + interpolationCount * 2);
806 Token first = parts.first; 806 Token first = parts.first;
807 Token last = parts.last; 807 Token last = parts.last;
808 Quote quote = analyzeQuote(first.value); 808 Quote quote = analyzeQuote(first.lexeme);
809 List<Expression> expressions = <Expression>[]; 809 List<Expression> expressions = <Expression>[];
810 expressions 810 expressions
811 .add(new StringLiteral(unescapeFirstStringPart(first.value, quote))); 811 .add(new StringLiteral(unescapeFirstStringPart(first.lexeme, quote)));
812 for (int i = 1; i < parts.length - 1; i++) { 812 for (int i = 1; i < parts.length - 1; i++) {
813 var part = parts[i]; 813 var part = parts[i];
814 if (part is Token) { 814 if (part is Token) {
815 expressions.add(new StringLiteral(unescape(part.value, quote))); 815 expressions.add(new StringLiteral(unescape(part.lexeme, quote)));
816 } else { 816 } else {
817 expressions.add(toValue(part)); 817 expressions.add(toValue(part));
818 } 818 }
819 } 819 }
820 expressions 820 expressions
821 .add(new StringLiteral(unescapeLastStringPart(last.value, quote))); 821 .add(new StringLiteral(unescapeLastStringPart(last.lexeme, quote)));
822 push(new StringConcatenation(expressions) 822 push(new StringConcatenation(expressions)
823 ..fileOffset = endToken.charOffset); 823 ..fileOffset = endToken.charOffset);
824 } 824 }
825 } 825 }
826 826
827 @override 827 @override
828 void handleScript(Token token) { 828 void handleScript(Token token) {
829 debugEvent("Script"); 829 debugEvent("Script");
830 } 830 }
831 831
(...skipping 15 matching lines...) Expand all
847 expressions.add(part); 847 expressions.add(part);
848 } 848 }
849 } 849 }
850 } 850 }
851 push(new StringConcatenation(expressions ?? parts)); 851 push(new StringConcatenation(expressions ?? parts));
852 } 852 }
853 853
854 @override 854 @override
855 void handleLiteralInt(Token token) { 855 void handleLiteralInt(Token token) {
856 debugEvent("LiteralInt"); 856 debugEvent("LiteralInt");
857 push(new IntLiteral(int.parse(token.value))); 857 push(new IntLiteral(int.parse(token.lexeme)));
858 } 858 }
859 859
860 @override 860 @override
861 void endExpressionFunctionBody(Token arrowToken, Token endToken) { 861 void endExpressionFunctionBody(Token arrowToken, Token endToken) {
862 debugEvent("ExpressionFunctionBody"); 862 debugEvent("ExpressionFunctionBody");
863 endReturnStatement(true, arrowToken, endToken); 863 endReturnStatement(true, arrowToken, endToken);
864 } 864 }
865 865
866 @override 866 @override
867 void endReturnStatement( 867 void endReturnStatement(
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 void handleLiteralBool(Token token) { 1086 void handleLiteralBool(Token token) {
1087 debugEvent("LiteralBool"); 1087 debugEvent("LiteralBool");
1088 bool value = optional("true", token); 1088 bool value = optional("true", token);
1089 assert(value || optional("false", token)); 1089 assert(value || optional("false", token));
1090 push(new BoolLiteral(value)); 1090 push(new BoolLiteral(value));
1091 } 1091 }
1092 1092
1093 @override 1093 @override
1094 void handleLiteralDouble(Token token) { 1094 void handleLiteralDouble(Token token) {
1095 debugEvent("LiteralDouble"); 1095 debugEvent("LiteralDouble");
1096 push(new DoubleLiteral(double.parse(token.value))); 1096 push(new DoubleLiteral(double.parse(token.lexeme)));
1097 } 1097 }
1098 1098
1099 @override 1099 @override
1100 void handleLiteralNull(Token token) { 1100 void handleLiteralNull(Token token) {
1101 debugEvent("LiteralNull"); 1101 debugEvent("LiteralNull");
1102 push(new NullLiteral()); 1102 push(new NullLiteral());
1103 } 1103 }
1104 1104
1105 @override 1105 @override
1106 void handleLiteralMap( 1106 void handleLiteralMap(
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1211 push(const DynamicType()); 1211 push(const DynamicType());
1212 addCompileTimeError(beginToken.charOffset, 1212 addCompileTimeError(beginToken.charOffset,
1213 "Can't be used as a type: '${debugName(prefix, suffix)}'."); 1213 "Can't be used as a type: '${debugName(prefix, suffix)}'.");
1214 return; 1214 return;
1215 } 1215 }
1216 } 1216 }
1217 if (name is Identifier) { 1217 if (name is Identifier) {
1218 name = name.name; 1218 name = name.name;
1219 } 1219 }
1220 if (name is BuilderAccessor) { 1220 if (name is BuilderAccessor) {
1221 warning("'${beginToken.value}' isn't a type.", beginToken.charOffset); 1221 warning("'${beginToken.lexeme}' isn't a type.", beginToken.charOffset);
1222 push(const DynamicType()); 1222 push(const DynamicType());
1223 } else if (name is UnresolvedIdentifier) { 1223 } else if (name is UnresolvedIdentifier) {
1224 warning("'${name.name}' isn't a type.", beginToken.charOffset); 1224 warning("'${name.name}' isn't a type.", beginToken.charOffset);
1225 push(const DynamicType()); 1225 push(const DynamicType());
1226 } else if (name is TypeVariableBuilder) { 1226 } else if (name is TypeVariableBuilder) {
1227 push(name.buildTypesWithBuiltArguments(library, arguments)); 1227 push(name.buildTypesWithBuiltArguments(library, arguments));
1228 } else if (name is TypeDeclarationBuilder) { 1228 } else if (name is TypeDeclarationBuilder) {
1229 push(name.buildTypesWithBuiltArguments(library, arguments)); 1229 push(name.buildTypesWithBuiltArguments(library, arguments));
1230 } else if (name is TypeBuilder) { 1230 } else if (name is TypeBuilder) {
1231 push(name.build(library)); 1231 push(name.build(library));
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
1500 } else { 1500 } else {
1501 push(buildMethodInvocation(toValue(receiver), new Name(operator), 1501 push(buildMethodInvocation(toValue(receiver), new Name(operator),
1502 new Arguments.empty(), token.charOffset)); 1502 new Arguments.empty(), token.charOffset));
1503 } 1503 }
1504 } 1504 }
1505 } 1505 }
1506 1506
1507 Name incrementOperator(Token token) { 1507 Name incrementOperator(Token token) {
1508 if (optional("++", token)) return plusName; 1508 if (optional("++", token)) return plusName;
1509 if (optional("--", token)) return minusName; 1509 if (optional("--", token)) return minusName;
1510 return internalError("Unknown increment operator: ${token.value}"); 1510 return internalError("Unknown increment operator: ${token.lexeme}");
1511 } 1511 }
1512 1512
1513 @override 1513 @override
1514 void handleUnaryPrefixAssignmentExpression(Token token) { 1514 void handleUnaryPrefixAssignmentExpression(Token token) {
1515 debugEvent("UnaryPrefixAssignmentExpression"); 1515 debugEvent("UnaryPrefixAssignmentExpression");
1516 var accessor = pop(); 1516 var accessor = pop();
1517 if (accessor is BuilderAccessor) { 1517 if (accessor is BuilderAccessor) {
1518 push(accessor.buildPrefixIncrement( 1518 push(accessor.buildPrefixIncrement(
1519 incrementOperator(token), token.charOffset)); 1519 incrementOperator(token), token.charOffset));
1520 } else { 1520 } else {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1565 var prefix = type[0]; 1565 var prefix = type[0];
1566 identifier = type[1]; 1566 identifier = type[1];
1567 if (prefix is PrefixBuilder) { 1567 if (prefix is PrefixBuilder) {
1568 // TODO(ahe): Handle privacy in prefix.exports. 1568 // TODO(ahe): Handle privacy in prefix.exports.
1569 type = builderToFirstExpression( 1569 type = builderToFirstExpression(
1570 prefix.exports[identifier.name], identifier.name, start.charOffset); 1570 prefix.exports[identifier.name], identifier.name, start.charOffset);
1571 identifier = null; 1571 identifier = null;
1572 } else if (prefix is ClassBuilder) { 1572 } else if (prefix is ClassBuilder) {
1573 type = prefix; 1573 type = prefix;
1574 } else { 1574 } else {
1575 type = new Identifier(start.value)..fileOffset = start.charOffset; 1575 type = new Identifier(start.lexeme)..fileOffset = start.charOffset;
1576 } 1576 }
1577 } 1577 }
1578 String name; 1578 String name;
1579 if (identifier != null && suffix != null) { 1579 if (identifier != null && suffix != null) {
1580 name = "${identifier.name}.${suffix.name}"; 1580 name = "${identifier.name}.${suffix.name}";
1581 } else if (identifier != null) { 1581 } else if (identifier != null) {
1582 name = identifier.name; 1582 name = identifier.name;
1583 } else if (suffix != null) { 1583 } else if (suffix != null) {
1584 name = suffix.name; 1584 name = suffix.name;
1585 } else { 1585 } else {
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
2210 2210
2211 @override 2211 @override
2212 Token handleUnrecoverableError(Token token, ErrorKind kind, Map arguments) { 2212 Token handleUnrecoverableError(Token token, ErrorKind kind, Map arguments) {
2213 if (isDartLibrary && kind == ErrorKind.ExpectedFunctionBody) { 2213 if (isDartLibrary && kind == ErrorKind.ExpectedFunctionBody) {
2214 Token recover = skipNativeClause(token); 2214 Token recover = skipNativeClause(token);
2215 if (recover != null) return recover; 2215 if (recover != null) return recover;
2216 } else if (kind == ErrorKind.UnexpectedToken) { 2216 } else if (kind == ErrorKind.UnexpectedToken) {
2217 String expected = arguments["expected"]; 2217 String expected = arguments["expected"];
2218 const List<String> trailing = const <String>[")", "}", ";", ","]; 2218 const List<String> trailing = const <String>[")", "}", ";", ","];
2219 if (trailing.contains(token.stringValue) && trailing.contains(expected)) { 2219 if (trailing.contains(token.stringValue) && trailing.contains(expected)) {
2220 arguments.putIfAbsent("actual", () => token.value); 2220 arguments.putIfAbsent("actual", () => token.lexeme);
2221 handleRecoverableError(token, ErrorKind.ExpectedButGot, arguments); 2221 handleRecoverableError(token, ErrorKind.ExpectedButGot, arguments);
2222 return newSyntheticToken(token); 2222 return newSyntheticToken(token);
2223 } 2223 }
2224 } 2224 }
2225 return super.handleUnrecoverableError(token, kind, arguments); 2225 return super.handleUnrecoverableError(token, kind, arguments);
2226 } 2226 }
2227 2227
2228 @override 2228 @override
2229 Expression buildCompileTimeError(error, [int charOffset = -1]) { 2229 Expression buildCompileTimeError(error, [int charOffset = -1]) {
2230 addCompileTimeError(charOffset, error); 2230 addCompileTimeError(charOffset, error);
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
2721 } else if (node is PrefixBuilder) { 2721 } else if (node is PrefixBuilder) {
2722 return node.name; 2722 return node.name;
2723 } else if (node is ThisAccessor) { 2723 } else if (node is ThisAccessor) {
2724 return node.isSuper ? "super" : "this"; 2724 return node.isSuper ? "super" : "this";
2725 } else if (node is BuilderAccessor) { 2725 } else if (node is BuilderAccessor) {
2726 return node.plainNameForRead; 2726 return node.plainNameForRead;
2727 } else { 2727 } else {
2728 return internalError("Unhandled: ${node.runtimeType}"); 2728 return internalError("Unhandled: ${node.runtimeType}");
2729 } 2729 }
2730 } 2730 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/analyzer/token_utils.dart ('k') | pkg/front_end/lib/src/fasta/parser/parser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698