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, optional; | 10 import '../parser/parser.dart' show FormalParameterType, optional; |
(...skipping 946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
957 void handleStringPart(Token token) { | 957 void handleStringPart(Token token) { |
958 debugEvent("StringPart"); | 958 debugEvent("StringPart"); |
959 push(token); | 959 push(token); |
960 } | 960 } |
961 | 961 |
962 @override | 962 @override |
963 void endLiteralString(int interpolationCount, Token endToken) { | 963 void endLiteralString(int interpolationCount, Token endToken) { |
964 debugEvent("endLiteralString"); | 964 debugEvent("endLiteralString"); |
965 if (interpolationCount == 0) { | 965 if (interpolationCount == 0) { |
966 Token token = pop(); | 966 Token token = pop(); |
967 push(new StringLiteral(unescapeString(token.lexeme)) | 967 String value = unescapeString(token.lexeme); |
968 ..fileOffset = token.charOffset); | 968 push(astFactory.stringLiteral(value, token)); |
969 } else { | 969 } else { |
970 List parts = popList(1 + interpolationCount * 2); | 970 List parts = popList(1 + interpolationCount * 2); |
971 Token first = parts.first; | 971 Token first = parts.first; |
972 Token last = parts.last; | 972 Token last = parts.last; |
973 Quote quote = analyzeQuote(first.lexeme); | 973 Quote quote = analyzeQuote(first.lexeme); |
974 List<Expression> expressions = <Expression>[]; | 974 List<Expression> expressions = <Expression>[]; |
975 // Contains more than just \' or \". | 975 // Contains more than just \' or \". |
976 if (first.lexeme.length > 1) { | 976 if (first.lexeme.length > 1) { |
977 expressions.add( | 977 String value = unescapeFirstStringPart(first.lexeme, quote); |
978 new StringLiteral(unescapeFirstStringPart(first.lexeme, quote))); | 978 expressions.add(astFactory.stringLiteral(value, first)); |
979 } | 979 } |
980 for (int i = 1; i < parts.length - 1; i++) { | 980 for (int i = 1; i < parts.length - 1; i++) { |
981 var part = parts[i]; | 981 var part = parts[i]; |
982 if (part is Token) { | 982 if (part is Token) { |
983 if (part.lexeme.length != 0) { | 983 if (part.lexeme.length != 0) { |
984 expressions.add(new StringLiteral(unescape(part.lexeme, quote))); | 984 String value = unescape(part.lexeme, quote); |
| 985 expressions.add(astFactory.stringLiteral(value, part)); |
985 } | 986 } |
986 } else { | 987 } else { |
987 expressions.add(toValue(part)); | 988 expressions.add(toValue(part)); |
988 } | 989 } |
989 } | 990 } |
990 // Contains more than just \' or \". | 991 // Contains more than just \' or \". |
991 if (last.lexeme.length > 1) { | 992 if (last.lexeme.length > 1) { |
992 expressions | 993 String value = unescapeLastStringPart(last.lexeme, quote); |
993 .add(new StringLiteral(unescapeLastStringPart(last.lexeme, quote))); | 994 expressions.add(astFactory.stringLiteral(value, last)); |
994 } | 995 } |
995 push(new StringConcatenation(expressions) | 996 push(astFactory.stringConcatenation(expressions, endToken)); |
996 ..fileOffset = endToken.charOffset); | |
997 } | 997 } |
998 } | 998 } |
999 | 999 |
1000 @override | 1000 @override |
1001 void handleScript(Token token) { | 1001 void handleScript(Token token) { |
1002 debugEvent("Script"); | 1002 debugEvent("Script"); |
1003 } | 1003 } |
1004 | 1004 |
1005 @override | 1005 @override |
1006 void handleStringJuxtaposition(int literalCount) { | 1006 void handleStringJuxtaposition(int literalCount) { |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1291 push(new ListLiteral(expressions, | 1291 push(new ListLiteral(expressions, |
1292 typeArgument: typeArgument, isConst: constKeyword != null) | 1292 typeArgument: typeArgument, isConst: constKeyword != null) |
1293 ..fileOffset = constKeyword?.charOffset ?? beginToken.charOffset); | 1293 ..fileOffset = constKeyword?.charOffset ?? beginToken.charOffset); |
1294 } | 1294 } |
1295 | 1295 |
1296 @override | 1296 @override |
1297 void handleLiteralBool(Token token) { | 1297 void handleLiteralBool(Token token) { |
1298 debugEvent("LiteralBool"); | 1298 debugEvent("LiteralBool"); |
1299 bool value = optional("true", token); | 1299 bool value = optional("true", token); |
1300 assert(value || optional("false", token)); | 1300 assert(value || optional("false", token)); |
1301 push(new BoolLiteral(value)..fileOffset = token.charOffset); | 1301 push(astFactory.boolLiteral(value, token)); |
1302 } | 1302 } |
1303 | 1303 |
1304 @override | 1304 @override |
1305 void handleLiteralDouble(Token token) { | 1305 void handleLiteralDouble(Token token) { |
1306 debugEvent("LiteralDouble"); | 1306 debugEvent("LiteralDouble"); |
1307 push(astFactory.doubleLiteral(double.parse(token.lexeme), token)); | 1307 push(astFactory.doubleLiteral(double.parse(token.lexeme), token)); |
1308 } | 1308 } |
1309 | 1309 |
1310 @override | 1310 @override |
1311 void handleLiteralNull(Token token) { | 1311 void handleLiteralNull(Token token) { |
(...skipping 1816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3128 } else if (node is PrefixBuilder) { | 3128 } else if (node is PrefixBuilder) { |
3129 return node.name; | 3129 return node.name; |
3130 } else if (node is ThisAccessor) { | 3130 } else if (node is ThisAccessor) { |
3131 return node.isSuper ? "super" : "this"; | 3131 return node.isSuper ? "super" : "this"; |
3132 } else if (node is FastaAccessor) { | 3132 } else if (node is FastaAccessor) { |
3133 return node.plainNameForRead; | 3133 return node.plainNameForRead; |
3134 } else { | 3134 } else { |
3135 return internalError("Unhandled: ${node.runtimeType}"); | 3135 return internalError("Unhandled: ${node.runtimeType}"); |
3136 } | 3136 } |
3137 } | 3137 } |
OLD | NEW |