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

Side by Side Diff: runtime/vm/parser.cc

Issue 27192005: Add new style of string interpolation optimization: new nodes, working constant folding. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 #include "vm/parser.h" 5 #include "vm/parser.h"
6 6
7 #include "lib/invocation_mirror.h" 7 #include "lib/invocation_mirror.h"
8 #include "vm/bigint_operations.h" 8 #include "vm/bigint_operations.h"
9 #include "vm/bootstrap.h" 9 #include "vm/bootstrap.h"
10 #include "vm/class_finalizer.h" 10 #include "vm/class_finalizer.h"
(...skipping 10039 matching lines...) Expand 10 before | Expand all | Expand 10 after
10050 expr = ResolveIdent(TokenPos(), *CurrentLiteral(), true); 10050 expr = ResolveIdent(TokenPos(), *CurrentLiteral(), true);
10051 ConsumeToken(); 10051 ConsumeToken();
10052 } else { 10052 } else {
10053 ASSERT(CurrentToken() == Token::kINTERPOL_START); 10053 ASSERT(CurrentToken() == Token::kINTERPOL_START);
10054 ConsumeToken(); 10054 ConsumeToken();
10055 expr = ParseExpr(kAllowConst, kConsumeCascades); 10055 expr = ParseExpr(kAllowConst, kConsumeCascades);
10056 ExpectToken(Token::kINTERPOL_END); 10056 ExpectToken(Token::kINTERPOL_END);
10057 } 10057 }
10058 // Check if this interpolated string is still considered a compile time 10058 // Check if this interpolated string is still considered a compile time
10059 // constant. If it is we need to evaluate if the current string part is 10059 // constant. If it is we need to evaluate if the current string part is
10060 // a constant or not. Only stings, numbers, booleans and null values 10060 // a constant or not. Only strings, numbers, booleans and null values
10061 // are allowed in compile time const interpolations. 10061 // are allowed in compile time const interpolations.
10062 if (is_compiletime_const) { 10062 if (is_compiletime_const) {
10063 const Object* const_expr = expr->EvalConstExpr(); 10063 const Object* const_expr = expr->EvalConstExpr();
10064 if ((const_expr != NULL) && 10064 if ((const_expr != NULL) &&
10065 (const_expr->IsNumber() || 10065 (const_expr->IsNumber() ||
10066 const_expr->IsString() || 10066 const_expr->IsString() ||
10067 const_expr->IsBool() || 10067 const_expr->IsBool() ||
10068 const_expr->IsNull())) { 10068 const_expr->IsNull())) {
10069 // Change expr into a literal. 10069 // Change expr into a literal.
10070 expr = new LiteralNode(expr_pos, EvaluateConstExpr(expr)); 10070 expr = new LiteralNode(expr_pos, EvaluateConstExpr(expr));
10071 } else { 10071 } else {
10072 is_compiletime_const = false; 10072 is_compiletime_const = false;
10073 } 10073 }
10074 } 10074 }
10075 values_list.Add(expr); 10075 values_list.Add(expr);
10076 } 10076 }
10077 } 10077 }
10078 if (is_compiletime_const) { 10078 if (is_compiletime_const) {
10079 primary = new LiteralNode(literal_start, Interpolate(values_list)); 10079 primary = new LiteralNode(literal_start, Interpolate(values_list));
10080 } else { 10080 } else {
10081 ArgumentListNode* interpolate_arg = new ArgumentListNode(TokenPos());
10082 ArrayNode* values = new ArrayNode( 10081 ArrayNode* values = new ArrayNode(
10083 TokenPos(), 10082 TokenPos(),
10084 Type::ZoneHandle(Type::ArrayType()), 10083 Type::ZoneHandle(Type::ArrayType()),
10085 values_list); 10084 values_list);
10086 interpolate_arg->Add(values); 10085 primary = new StringInterpolateNode(TokenPos(), values);
10087 primary =
10088 MakeStaticCall(Symbols::StringBase(),
10089 Library::PrivateCoreLibName(Symbols::Interpolate()),
10090 interpolate_arg);
10091 } 10086 }
10092 return primary; 10087 return primary;
10093 } 10088 }
10094 10089
10095 10090
10096 AstNode* Parser::ParsePrimary() { 10091 AstNode* Parser::ParsePrimary() {
10097 TRACE_PARSER("ParsePrimary"); 10092 TRACE_PARSER("ParsePrimary");
10098 ASSERT(!is_top_level_); 10093 ASSERT(!is_top_level_);
10099 AstNode* primary = NULL; 10094 AstNode* primary = NULL;
10100 if (IsFunctionLiteral()) { 10095 if (IsFunctionLiteral()) {
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
10611 void Parser::SkipQualIdent() { 10606 void Parser::SkipQualIdent() {
10612 ASSERT(IsIdentifier()); 10607 ASSERT(IsIdentifier());
10613 ConsumeToken(); 10608 ConsumeToken();
10614 if (CurrentToken() == Token::kPERIOD) { 10609 if (CurrentToken() == Token::kPERIOD) {
10615 ConsumeToken(); // Consume the kPERIOD token. 10610 ConsumeToken(); // Consume the kPERIOD token.
10616 ExpectIdentifier("identifier expected after '.'"); 10611 ExpectIdentifier("identifier expected after '.'");
10617 } 10612 }
10618 } 10613 }
10619 10614
10620 } // namespace dart 10615 } // namespace dart
OLDNEW
« runtime/vm/intermediate_language.h ('K') | « runtime/vm/intermediate_language_x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698