| 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 "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 7134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7145 if (!is_empty_literal) { | 7145 if (!is_empty_literal) { |
| 7146 const bool saved_mode = SetAllowFunctionLiterals(true); | 7146 const bool saved_mode = SetAllowFunctionLiterals(true); |
| 7147 const String& dst_name = String::ZoneHandle( | 7147 const String& dst_name = String::ZoneHandle( |
| 7148 String::NewSymbol("list literal element")); | 7148 String::NewSymbol("list literal element")); |
| 7149 while (CurrentToken() != Token::kRBRACK) { | 7149 while (CurrentToken() != Token::kRBRACK) { |
| 7150 const intptr_t element_pos = token_index_; | 7150 const intptr_t element_pos = token_index_; |
| 7151 AstNode* element = ParseExpr(is_const); | 7151 AstNode* element = ParseExpr(is_const); |
| 7152 if (FLAG_enable_type_checks && | 7152 if (FLAG_enable_type_checks && |
| 7153 !is_const && | 7153 !is_const && |
| 7154 !element_type.IsDynamicType()) { | 7154 !element_type.IsDynamicType()) { |
| 7155 // The expression needs to be type checked at runtime. | 7155 element = new AssignableNode(element_pos, |
| 7156 // Eliminate the type check if it can be performed at compile time and | 7156 element, |
| 7157 // if it succeeds. | 7157 element_type, |
| 7158 Error& malformed_error = Error::Handle(); | 7158 dst_name); |
| 7159 if (!element_type.IsInstantiated() || | |
| 7160 !element->IsLiteralNode() || | |
| 7161 (!element->AsLiteralNode()->literal().IsNull() && | |
| 7162 !element->AsLiteralNode()->literal().IsInstanceOf( | |
| 7163 element_type, | |
| 7164 TypeArguments::Handle(), | |
| 7165 &malformed_error))) { | |
| 7166 element = new AssignableNode(element_pos, | |
| 7167 element, | |
| 7168 element_type, | |
| 7169 dst_name); | |
| 7170 } | |
| 7171 } | 7159 } |
| 7172 list->AddElement(element); | 7160 list->AddElement(element); |
| 7173 if (CurrentToken() == Token::kCOMMA) { | 7161 if (CurrentToken() == Token::kCOMMA) { |
| 7174 ConsumeToken(); | 7162 ConsumeToken(); |
| 7175 } else if (CurrentToken() != Token::kRBRACK) { | 7163 } else if (CurrentToken() != Token::kRBRACK) { |
| 7176 ErrorMsg("comma or ']' expected"); | 7164 ErrorMsg("comma or ']' expected"); |
| 7177 } | 7165 } |
| 7178 } | 7166 } |
| 7179 ExpectToken(Token::kRBRACK); | 7167 ExpectToken(Token::kRBRACK); |
| 7180 SetAllowFunctionLiterals(saved_mode); | 7168 SetAllowFunctionLiterals(saved_mode); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7332 ErrorMsg("map entry key must be compile time constant string"); | 7320 ErrorMsg("map entry key must be compile time constant string"); |
| 7333 } | 7321 } |
| 7334 ExpectToken(Token::kCOLON); | 7322 ExpectToken(Token::kCOLON); |
| 7335 const bool saved_mode = SetAllowFunctionLiterals(true); | 7323 const bool saved_mode = SetAllowFunctionLiterals(true); |
| 7336 const intptr_t value_pos = token_index_; | 7324 const intptr_t value_pos = token_index_; |
| 7337 AstNode* value = ParseExpr(is_const); | 7325 AstNode* value = ParseExpr(is_const); |
| 7338 SetAllowFunctionLiterals(saved_mode); | 7326 SetAllowFunctionLiterals(saved_mode); |
| 7339 if (FLAG_enable_type_checks && | 7327 if (FLAG_enable_type_checks && |
| 7340 !is_const && | 7328 !is_const && |
| 7341 !value_type.IsDynamicType()) { | 7329 !value_type.IsDynamicType()) { |
| 7342 // The expression needs to be type checked at runtime. | 7330 value = new AssignableNode(value_pos, |
| 7343 // Eliminate the type check if it can be performed at compile time and | 7331 value, |
| 7344 // if it succeeds. | 7332 value_type, |
| 7345 Error& malformed_error = Error::Handle(); | 7333 dst_name); |
| 7346 if (!value_type.IsInstantiated() || | |
| 7347 !value->IsLiteralNode() || | |
| 7348 (!value->AsLiteralNode()->literal().IsNull() && | |
| 7349 !value->AsLiteralNode()->literal().IsInstanceOf( | |
| 7350 value_type, TypeArguments::Handle(), &malformed_error))) { | |
| 7351 value = new AssignableNode(value_pos, | |
| 7352 value, | |
| 7353 value_type, | |
| 7354 dst_name); | |
| 7355 } | |
| 7356 } | 7334 } |
| 7357 AddKeyValuePair(kv_pairs, is_const, key, value); | 7335 AddKeyValuePair(kv_pairs, is_const, key, value); |
| 7358 | 7336 |
| 7359 if (CurrentToken() == Token::kCOMMA) { | 7337 if (CurrentToken() == Token::kCOMMA) { |
| 7360 ConsumeToken(); | 7338 ConsumeToken(); |
| 7361 } else if (CurrentToken() != Token::kRBRACE) { | 7339 } else if (CurrentToken() != Token::kRBRACE) { |
| 7362 ErrorMsg("comma or '}' expected"); | 7340 ErrorMsg("comma or '}' expected"); |
| 7363 } | 7341 } |
| 7364 } | 7342 } |
| 7365 ASSERT(kv_pairs->length() % 2 == 0); | 7343 ASSERT(kv_pairs->length() % 2 == 0); |
| (...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8279 void Parser::SkipQualIdent() { | 8257 void Parser::SkipQualIdent() { |
| 8280 ASSERT(IsIdentifier()); | 8258 ASSERT(IsIdentifier()); |
| 8281 ConsumeToken(); | 8259 ConsumeToken(); |
| 8282 if (CurrentToken() == Token::kPERIOD) { | 8260 if (CurrentToken() == Token::kPERIOD) { |
| 8283 ConsumeToken(); // Consume the kPERIOD token. | 8261 ConsumeToken(); // Consume the kPERIOD token. |
| 8284 ExpectIdentifier("identifier expected after '.'"); | 8262 ExpectIdentifier("identifier expected after '.'"); |
| 8285 } | 8263 } |
| 8286 } | 8264 } |
| 8287 | 8265 |
| 8288 } // namespace dart | 8266 } // namespace dart |
| OLD | NEW |