| OLD | NEW |
| 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 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1012 // the constant folding code to create, compile and execute a code | 1012 // the constant folding code to create, compile and execute a code |
| 1013 // fragment to evaluate the expression. Instead, we just make sure | 1013 // fragment to evaluate the expression. Instead, we just make sure |
| 1014 // the static const field initializer is a constant expression and | 1014 // the static const field initializer is a constant expression and |
| 1015 // leave the evaluation to the getter function. | 1015 // leave the evaluation to the getter function. |
| 1016 const intptr_t expr_pos = TokenPos(); | 1016 const intptr_t expr_pos = TokenPos(); |
| 1017 AstNode* expr = ParseExpr(kAllowConst, kConsumeCascades); | 1017 AstNode* expr = ParseExpr(kAllowConst, kConsumeCascades); |
| 1018 | 1018 |
| 1019 if (field.is_const()) { | 1019 if (field.is_const()) { |
| 1020 // This getter will only be called once at compile time. | 1020 // This getter will only be called once at compile time. |
| 1021 if (expr->EvalConstExpr() == NULL) { | 1021 if (expr->EvalConstExpr() == NULL) { |
| 1022 ErrorMsg(expr_pos, "initializer must be a compile-time constant"); | 1022 ErrorMsg(expr_pos, "initializer is not a valid compile-time constant"); |
| 1023 } | 1023 } |
| 1024 ReturnNode* return_node = new ReturnNode(ident_pos, expr); | 1024 ReturnNode* return_node = new ReturnNode(ident_pos, expr); |
| 1025 current_block_->statements->Add(return_node); | 1025 current_block_->statements->Add(return_node); |
| 1026 } else { | 1026 } else { |
| 1027 // This getter may be called each time the static field is accessed. | 1027 // This getter may be called each time the static field is accessed. |
| 1028 // The following generated code lazily initializes the field: | 1028 // The following generated code lazily initializes the field: |
| 1029 // if (field.value === transition_sentinel) { | 1029 // if (field.value === transition_sentinel) { |
| 1030 // field.value = null; | 1030 // field.value = null; |
| 1031 // throw("circular dependency in field initialization"); | 1031 // throw("circular dependency in field initialization"); |
| 1032 // } | 1032 // } |
| (...skipping 6617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7650 } | 7650 } |
| 7651 | 7651 |
| 7652 | 7652 |
| 7653 // Evaluates the value of the compile time constant expression | 7653 // Evaluates the value of the compile time constant expression |
| 7654 // and returns a literal node for the value. | 7654 // and returns a literal node for the value. |
| 7655 AstNode* Parser::FoldConstExpr(intptr_t expr_pos, AstNode* expr) { | 7655 AstNode* Parser::FoldConstExpr(intptr_t expr_pos, AstNode* expr) { |
| 7656 if (expr->IsLiteralNode()) { | 7656 if (expr->IsLiteralNode()) { |
| 7657 return expr; | 7657 return expr; |
| 7658 } | 7658 } |
| 7659 if (expr->EvalConstExpr() == NULL) { | 7659 if (expr->EvalConstExpr() == NULL) { |
| 7660 ErrorMsg(expr_pos, "expression must be a compile-time constant"); | 7660 ErrorMsg(expr_pos, "expression is not a valid compile-time constant"); |
| 7661 } | 7661 } |
| 7662 return new LiteralNode(expr_pos, EvaluateConstExpr(expr)); | 7662 return new LiteralNode(expr_pos, EvaluateConstExpr(expr)); |
| 7663 } | 7663 } |
| 7664 | 7664 |
| 7665 | 7665 |
| 7666 LetNode* Parser::PrepareCompoundAssignmentNodes(AstNode** expr) { | 7666 LetNode* Parser::PrepareCompoundAssignmentNodes(AstNode** expr) { |
| 7667 AstNode* node = *expr; | 7667 AstNode* node = *expr; |
| 7668 intptr_t token_pos = node->token_pos(); | 7668 intptr_t token_pos = node->token_pos(); |
| 7669 LetNode* result = new LetNode(token_pos); | 7669 LetNode* result = new LetNode(token_pos); |
| 7670 if (node->IsLoadIndexedNode()) { | 7670 if (node->IsLoadIndexedNode()) { |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7820 expr = FoldConstExpr(expr_pos, expr); | 7820 expr = FoldConstExpr(expr_pos, expr); |
| 7821 } | 7821 } |
| 7822 return expr; | 7822 return expr; |
| 7823 } | 7823 } |
| 7824 // Assignment expressions. | 7824 // Assignment expressions. |
| 7825 const Token::Kind assignment_op = CurrentToken(); | 7825 const Token::Kind assignment_op = CurrentToken(); |
| 7826 const intptr_t assignment_pos = TokenPos(); | 7826 const intptr_t assignment_pos = TokenPos(); |
| 7827 ConsumeToken(); | 7827 ConsumeToken(); |
| 7828 const intptr_t right_expr_pos = TokenPos(); | 7828 const intptr_t right_expr_pos = TokenPos(); |
| 7829 if (require_compiletime_const && (assignment_op != Token::kASSIGN)) { | 7829 if (require_compiletime_const && (assignment_op != Token::kASSIGN)) { |
| 7830 ErrorMsg(right_expr_pos, "expression must be a compile-time constant"); | 7830 ErrorMsg(right_expr_pos, "expression is not a valid compile-time constant"); |
| 7831 } | 7831 } |
| 7832 AstNode* right_expr = ParseExpr(require_compiletime_const, consume_cascades); | 7832 AstNode* right_expr = ParseExpr(require_compiletime_const, consume_cascades); |
| 7833 if (assignment_op != Token::kASSIGN) { | 7833 if (assignment_op != Token::kASSIGN) { |
| 7834 // Compound assignment: store inputs with side effects into temp. locals. | 7834 // Compound assignment: store inputs with side effects into temp. locals. |
| 7835 LetNode* let_expr = PrepareCompoundAssignmentNodes(&expr); | 7835 LetNode* let_expr = PrepareCompoundAssignmentNodes(&expr); |
| 7836 AstNode* assigned_value = | 7836 AstNode* assigned_value = |
| 7837 ExpandAssignableOp(assignment_pos, assignment_op, expr, right_expr); | 7837 ExpandAssignableOp(assignment_pos, assignment_op, expr, right_expr); |
| 7838 AstNode* assign_expr = CreateAssignmentNode( | 7838 AstNode* assign_expr = CreateAssignmentNode( |
| 7839 expr, assigned_value, expr_ident, expr_pos); | 7839 expr, assigned_value, expr_ident, expr_pos); |
| 7840 ASSERT(assign_expr != NULL); | 7840 ASSERT(assign_expr != NULL); |
| (...skipping 2779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10620 void Parser::SkipQualIdent() { | 10620 void Parser::SkipQualIdent() { |
| 10621 ASSERT(IsIdentifier()); | 10621 ASSERT(IsIdentifier()); |
| 10622 ConsumeToken(); | 10622 ConsumeToken(); |
| 10623 if (CurrentToken() == Token::kPERIOD) { | 10623 if (CurrentToken() == Token::kPERIOD) { |
| 10624 ConsumeToken(); // Consume the kPERIOD token. | 10624 ConsumeToken(); // Consume the kPERIOD token. |
| 10625 ExpectIdentifier("identifier expected after '.'"); | 10625 ExpectIdentifier("identifier expected after '.'"); |
| 10626 } | 10626 } |
| 10627 } | 10627 } |
| 10628 | 10628 |
| 10629 } // namespace dart | 10629 } // namespace dart |
| OLD | NEW |