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

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

Issue 1303973007: Moar constant caching (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: less moar Created 5 years, 3 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
« no previous file with comments | « runtime/vm/parser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "platform/utils.h" 8 #include "platform/utils.h"
9 #include "vm/ast_transformer.h" 9 #include "vm/ast_transformer.h"
10 #include "vm/bootstrap.h" 10 #include "vm/bootstrap.h"
(...skipping 10615 matching lines...) Expand 10 before | Expand all | Expand 10 after
10626 "internal error: ExpandAssignableOp '%s' unimplemented", 10626 "internal error: ExpandAssignableOp '%s' unimplemented",
10627 Token::Name(assignment_op)); 10627 Token::Name(assignment_op));
10628 UNIMPLEMENTED(); 10628 UNIMPLEMENTED();
10629 return NULL; 10629 return NULL;
10630 } 10630 }
10631 } 10631 }
10632 10632
10633 10633
10634 // Evaluates the value of the compile time constant expression 10634 // Evaluates the value of the compile time constant expression
10635 // and returns a literal node for the value. 10635 // and returns a literal node for the value.
10636 AstNode* Parser::FoldConstExpr(intptr_t expr_pos, AstNode* expr) { 10636 LiteralNode* Parser::FoldConstExpr(intptr_t expr_pos, AstNode* expr) {
10637 if (expr->IsLiteralNode()) { 10637 if (expr->IsLiteralNode()) {
10638 return expr; 10638 return expr->AsLiteralNode();
10639 } 10639 }
10640 if (expr->EvalConstExpr() == NULL) { 10640 if (expr->EvalConstExpr() == NULL) {
10641 ReportError(expr_pos, "expression is not a valid compile-time constant"); 10641 ReportError(expr_pos, "expression is not a valid compile-time constant");
10642 } 10642 }
10643 return new(Z) LiteralNode( 10643 return new(Z) LiteralNode(
10644 expr_pos, EvaluateConstExpr(expr_pos, expr)); 10644 expr_pos, EvaluateConstExpr(expr_pos, expr));
10645 } 10645 }
10646 10646
10647 10647
10648 LetNode* Parser::PrepareCompoundAssignmentNodes(AstNode** expr) { 10648 LetNode* Parser::PrepareCompoundAssignmentNodes(AstNode** expr) {
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
10875 if (require_compiletime_const) { 10875 if (require_compiletime_const) {
10876 ReportError("'throw expr' is not a valid compile-time constant"); 10876 ReportError("'throw expr' is not a valid compile-time constant");
10877 } 10877 }
10878 ConsumeToken(); 10878 ConsumeToken();
10879 if (CurrentToken() == Token::kSEMICOLON) { 10879 if (CurrentToken() == Token::kSEMICOLON) {
10880 ReportError("expression expected after throw"); 10880 ReportError("expression expected after throw");
10881 } 10881 }
10882 AstNode* expr = ParseExpr(require_compiletime_const, consume_cascades); 10882 AstNode* expr = ParseExpr(require_compiletime_const, consume_cascades);
10883 return new(Z) ThrowNode(expr_pos, expr, NULL); 10883 return new(Z) ThrowNode(expr_pos, expr, NULL);
10884 } 10884 }
10885
10886 if (require_compiletime_const) {
srdjan 2015/09/01 21:33:51 How about skipping lookup if expr->IsLiteralNode()
hausner 2015/09/01 21:37:38 The lookup happens before the expression is parsed
10887 // Check whether we already have evaluated a compile-time constant
10888 // at this source location.
10889 Instance& existing_const = Instance::ZoneHandle(Z);
10890 if (GetCachedConstant(expr_pos, &existing_const)) {
10891 SkipConditionalExpr();
10892 return new(Z) LiteralNode(expr_pos, existing_const);
10893 }
10894 }
10895
10885 AstNode* expr = ParseConditionalExpr(); 10896 AstNode* expr = ParseConditionalExpr();
10886 if (!Token::IsAssignmentOperator(CurrentToken())) { 10897 if (!Token::IsAssignmentOperator(CurrentToken())) {
10887 if ((CurrentToken() == Token::kCASCADE) && consume_cascades) { 10898 if ((CurrentToken() == Token::kCASCADE) && consume_cascades) {
10888 return ParseCascades(expr); 10899 return ParseCascades(expr);
10889 } 10900 }
10890 if (require_compiletime_const) { 10901 if (require_compiletime_const) {
10891 expr = FoldConstExpr(expr_pos, expr); 10902 const bool use_cache = !expr->IsLiteralNode();
10903 LiteralNode* const_value = FoldConstExpr(expr_pos, expr);
10904 if (use_cache) CacheConstantValue(expr_pos, const_value->literal());
10905 expr = const_value;
10892 } else { 10906 } else {
10893 expr = LiteralIfStaticConst(Z, expr); 10907 expr = LiteralIfStaticConst(Z, expr);
10894 } 10908 }
10895 return expr; 10909 return expr;
10896 } 10910 }
10897 // Assignment expressions. 10911 // Assignment expressions.
10898 if (!IsLegalAssignableSyntax(expr, TokenPos())) { 10912 if (!IsLegalAssignableSyntax(expr, TokenPos())) {
10899 ReportError(expr_pos, "expression is not assignable"); 10913 ReportError(expr_pos, "expression is not assignable");
10900 } 10914 }
10901 const Token::Kind assignment_op = CurrentToken(); 10915 const Token::Kind assignment_op = CurrentToken();
(...skipping 3387 matching lines...) Expand 10 before | Expand all | Expand 10 after
14289 void Parser::SkipQualIdent() { 14303 void Parser::SkipQualIdent() {
14290 ASSERT(IsIdentifier()); 14304 ASSERT(IsIdentifier());
14291 ConsumeToken(); 14305 ConsumeToken();
14292 if (CurrentToken() == Token::kPERIOD) { 14306 if (CurrentToken() == Token::kPERIOD) {
14293 ConsumeToken(); // Consume the kPERIOD token. 14307 ConsumeToken(); // Consume the kPERIOD token.
14294 ExpectIdentifier("identifier expected after '.'"); 14308 ExpectIdentifier("identifier expected after '.'");
14295 } 14309 }
14296 } 14310 }
14297 14311
14298 } // namespace dart 14312 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698