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

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

Issue 11363012: Prevent mutation of final variables (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month 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
« no previous file with comments | « runtime/vm/ast.cc ('k') | tests/language/final_variable_assignment_test.dart » ('j') | 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 "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/compiler_stats.h" 10 #include "vm/compiler_stats.h"
(...skipping 6758 matching lines...) Expand 10 before | Expand all | Expand 10 after
6769 op_pos, op_kind, left_operand, right_operand); 6769 op_pos, op_kind, left_operand, right_operand);
6770 } 6770 }
6771 } 6771 }
6772 current_preced--; 6772 current_preced--;
6773 } 6773 }
6774 return left_operand; 6774 return left_operand;
6775 } 6775 }
6776 6776
6777 6777
6778 bool Parser::IsAssignableExpr(AstNode* expr) { 6778 bool Parser::IsAssignableExpr(AstNode* expr) {
6779 return (expr->IsLoadLocalNode() && !expr->AsLoadLocalNode()->HasPseudo()) 6779 return (expr->IsLoadLocalNode() && !expr->AsLoadLocalNode()->HasPseudo()
6780 && (!expr->AsLoadLocalNode()->local().is_final()))
6780 || expr->IsLoadStaticFieldNode() 6781 || expr->IsLoadStaticFieldNode()
6781 || expr->IsStaticGetterNode() 6782 || expr->IsStaticGetterNode()
6782 || expr->IsInstanceGetterNode() 6783 || expr->IsInstanceGetterNode()
6783 || expr->IsLoadIndexedNode() 6784 || expr->IsLoadIndexedNode()
6784 || (expr->IsPrimaryNode() && !expr->AsPrimaryNode()->IsSuper()); 6785 || (expr->IsPrimaryNode() && !expr->AsPrimaryNode()->IsSuper());
6785 } 6786 }
6786 6787
6787 6788
6788 AstNode* Parser::ParseExprList() { 6789 AstNode* Parser::ParseExprList() {
6789 TRACE_PARSER("ParseExprList"); 6790 TRACE_PARSER("ParseExprList");
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
6980 6981
6981 6982
6982 // Ensure that the expression temp is allocated for nodes that may need it. 6983 // Ensure that the expression temp is allocated for nodes that may need it.
6983 AstNode* Parser::CreateAssignmentNode(AstNode* original, AstNode* rhs) { 6984 AstNode* Parser::CreateAssignmentNode(AstNode* original, AstNode* rhs) {
6984 AstNode* result = original->MakeAssignmentNode(rhs); 6985 AstNode* result = original->MakeAssignmentNode(rhs);
6985 if ((result == NULL) && original->IsStaticGetterNode()) { 6986 if ((result == NULL) && original->IsStaticGetterNode()) {
6986 const String& setter_name = String::ZoneHandle( 6987 const String& setter_name = String::ZoneHandle(
6987 Field::SetterSymbol(original->AsStaticGetterNode()->field_name())); 6988 Field::SetterSymbol(original->AsStaticGetterNode()->field_name()));
6988 result = ThrowNoSuchMethodError(original->token_pos(), setter_name); 6989 result = ThrowNoSuchMethodError(original->token_pos(), setter_name);
6989 } 6990 }
6991 // TODO(hausner): if we decide to throw a no such method error on
6992 // assignment to a final variable, we need to do the same as in the
6993 // StaticGetterNode above.
6990 if ((result != NULL) && 6994 if ((result != NULL) &&
6991 (result->IsStoreIndexedNode() || 6995 (result->IsStoreIndexedNode() ||
6992 result->IsInstanceSetterNode() || 6996 result->IsInstanceSetterNode() ||
6993 result->IsStaticSetterNode() || 6997 result->IsStaticSetterNode() ||
6994 result->IsStoreStaticFieldNode() || 6998 result->IsStoreStaticFieldNode() ||
6995 result->IsStoreLocalNode())) { 6999 result->IsStoreLocalNode())) {
6996 EnsureExpressionTemp(); 7000 EnsureExpressionTemp();
6997 } 7001 }
6998 return result; 7002 return result;
6999 } 7003 }
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
7153 // Is prefix. 7157 // Is prefix.
7154 AstNode* left_expr = PrepareCompoundAssignmentNodes(&expr); 7158 AstNode* left_expr = PrepareCompoundAssignmentNodes(&expr);
7155 Token::Kind binary_op = 7159 Token::Kind binary_op =
7156 (incr_op == Token::kINCR) ? Token::kADD : Token::kSUB; 7160 (incr_op == Token::kINCR) ? Token::kADD : Token::kSUB;
7157 BinaryOpNode* add = new BinaryOpNode( 7161 BinaryOpNode* add = new BinaryOpNode(
7158 op_pos, 7162 op_pos,
7159 binary_op, 7163 binary_op,
7160 expr, 7164 expr,
7161 new LiteralNode(op_pos, Smi::ZoneHandle(Smi::New(1)))); 7165 new LiteralNode(op_pos, Smi::ZoneHandle(Smi::New(1))));
7162 AstNode* store = CreateAssignmentNode(left_expr, add); 7166 AstNode* store = CreateAssignmentNode(left_expr, add);
7167 ASSERT(store != NULL);
7163 expr = store; 7168 expr = store;
7164 } else { 7169 } else {
7165 expr = ParsePostfixExpr(); 7170 expr = ParsePostfixExpr();
7166 } 7171 }
7167 return expr; 7172 return expr;
7168 } 7173 }
7169 7174
7170 7175
7171 ArgumentListNode* Parser::ParseActualParameters( 7176 ArgumentListNode* Parser::ParseActualParameters(
7172 ArgumentListNode* implicit_arguments, 7177 ArgumentListNode* implicit_arguments,
(...skipping 2690 matching lines...) Expand 10 before | Expand all | Expand 10 after
9863 void Parser::SkipQualIdent() { 9868 void Parser::SkipQualIdent() {
9864 ASSERT(IsIdentifier()); 9869 ASSERT(IsIdentifier());
9865 ConsumeToken(); 9870 ConsumeToken();
9866 if (CurrentToken() == Token::kPERIOD) { 9871 if (CurrentToken() == Token::kPERIOD) {
9867 ConsumeToken(); // Consume the kPERIOD token. 9872 ConsumeToken(); // Consume the kPERIOD token.
9868 ExpectIdentifier("identifier expected after '.'"); 9873 ExpectIdentifier("identifier expected after '.'");
9869 } 9874 }
9870 } 9875 }
9871 9876
9872 } // namespace dart 9877 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/ast.cc ('k') | tests/language/final_variable_assignment_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698