| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 6371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6382 String& errmsg = String::Handle(); | 6382 String& errmsg = String::Handle(); |
| 6383 type = ClassFinalizer::FinalizeAndCanonicalizeType(type, &errmsg); | 6383 type = ClassFinalizer::FinalizeAndCanonicalizeType(type, &errmsg); |
| 6384 if (!errmsg.IsNull()) { | 6384 if (!errmsg.IsNull()) { |
| 6385 ErrorMsg(errmsg.ToCString()); | 6385 ErrorMsg(errmsg.ToCString()); |
| 6386 } | 6386 } |
| 6387 } | 6387 } |
| 6388 return type.raw(); | 6388 return type.raw(); |
| 6389 } | 6389 } |
| 6390 | 6390 |
| 6391 | 6391 |
| 6392 void Parser::CheckConstructorCallTypeArguments( |
| 6393 intptr_t pos, Function& constructor, const TypeArguments& type_arguments) { |
| 6394 if (!type_arguments.IsNull() && |
| 6395 (type_arguments.Length() != |
| 6396 Class::Handle(constructor.owner()).NumTypeArguments())) { |
| 6397 ErrorMsg(pos, "Incorrect number of type arguments, expected %d got %d", |
| 6398 Class::Handle(constructor.owner()).NumTypeArguments(), |
| 6399 type_arguments.Length()); |
| 6400 } |
| 6401 } |
| 6402 |
| 6403 |
| 6392 // Parse "[" [ expr { "," expr } ["," ] "]". | 6404 // Parse "[" [ expr { "," expr } ["," ] "]". |
| 6393 // Note: if the array literal is empty and the brackets have no whitespace | 6405 // Note: if the array literal is empty and the brackets have no whitespace |
| 6394 // between them, the scanner recognizes the opening and closing bracket | 6406 // between them, the scanner recognizes the opening and closing bracket |
| 6395 // as one token of type Token::kINDEX. | 6407 // as one token of type Token::kINDEX. |
| 6396 AstNode* Parser::ParseArrayLiteral(intptr_t type_pos, | 6408 AstNode* Parser::ParseArrayLiteral(intptr_t type_pos, |
| 6397 bool is_const, | 6409 bool is_const, |
| 6398 const TypeArguments& type_arguments) { | 6410 const TypeArguments& type_arguments) { |
| 6399 ASSERT(CurrentToken() == Token::kLBRACK || CurrentToken() == Token::kINDEX); | 6411 ASSERT(CurrentToken() == Token::kLBRACK || CurrentToken() == Token::kINDEX); |
| 6400 intptr_t literal_pos = token_index_; | 6412 intptr_t literal_pos = token_index_; |
| 6401 bool is_empty_literal = CurrentToken() == Token::kINDEX; | 6413 bool is_empty_literal = CurrentToken() == Token::kINDEX; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6462 String::NewSymbol(kGrowableObjectArrayName)); | 6474 String::NewSymbol(kGrowableObjectArrayName)); |
| 6463 const Class& growable_array_class = Class::Handle( | 6475 const Class& growable_array_class = Class::Handle( |
| 6464 LookupImplClass(growable_object_array_class_name)); | 6476 LookupImplClass(growable_object_array_class_name)); |
| 6465 String& ctor_name = | 6477 String& ctor_name = |
| 6466 String::Handle(String::NewSymbol(kGrowableObjectArrayFromArrayName)); | 6478 String::Handle(String::NewSymbol(kGrowableObjectArrayFromArrayName)); |
| 6467 Function& array_ctor = Function::ZoneHandle( | 6479 Function& array_ctor = Function::ZoneHandle( |
| 6468 growable_array_class.LookupConstructor(ctor_name)); | 6480 growable_array_class.LookupConstructor(ctor_name)); |
| 6469 ASSERT(!array_ctor.IsNull()); | 6481 ASSERT(!array_ctor.IsNull()); |
| 6470 ArgumentListNode* ctor_args = new ArgumentListNode(literal_pos); | 6482 ArgumentListNode* ctor_args = new ArgumentListNode(literal_pos); |
| 6471 ctor_args->Add(array); | 6483 ctor_args->Add(array); |
| 6484 CheckConstructorCallTypeArguments(literal_pos, array_ctor, type_arguments); |
| 6472 return new ConstructorCallNode( | 6485 return new ConstructorCallNode( |
| 6473 literal_pos, type_arguments, array_ctor, ctor_args); | 6486 literal_pos, type_arguments, array_ctor, ctor_args); |
| 6474 } | 6487 } |
| 6475 } | 6488 } |
| 6476 | 6489 |
| 6477 | 6490 |
| 6478 static void AddKeyValuePair(ArrayNode* pairs, | 6491 static void AddKeyValuePair(ArrayNode* pairs, |
| 6479 bool is_const, | 6492 bool is_const, |
| 6480 AstNode* key, | 6493 AstNode* key, |
| 6481 AstNode* value) { | 6494 AstNode* value) { |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6826 new_object = new LiteralNode(new_pos, const_instance); | 6839 new_object = new LiteralNode(new_pos, const_instance); |
| 6827 } | 6840 } |
| 6828 } else { | 6841 } else { |
| 6829 CheckFunctionIsCallable(new_pos, constructor); | 6842 CheckFunctionIsCallable(new_pos, constructor); |
| 6830 if (!type_arguments.IsNull() && | 6843 if (!type_arguments.IsNull() && |
| 6831 !type_arguments.IsInstantiated() && | 6844 !type_arguments.IsInstantiated() && |
| 6832 (current_block_->scope->function_level() > 0)) { | 6845 (current_block_->scope->function_level() > 0)) { |
| 6833 // Make sure that the instantiator is captured. | 6846 // Make sure that the instantiator is captured. |
| 6834 CaptureReceiver(); | 6847 CaptureReceiver(); |
| 6835 } | 6848 } |
| 6849 CheckConstructorCallTypeArguments(new_pos, constructor, type_arguments); |
| 6836 new_object = new ConstructorCallNode( | 6850 new_object = new ConstructorCallNode( |
| 6837 new_pos, type_arguments, constructor, arguments); | 6851 new_pos, type_arguments, constructor, arguments); |
| 6838 } | 6852 } |
| 6839 return new_object; | 6853 return new_object; |
| 6840 } | 6854 } |
| 6841 | 6855 |
| 6842 | 6856 |
| 6843 // A string literal consists of the concatenation of the next n tokens | 6857 // A string literal consists of the concatenation of the next n tokens |
| 6844 // that satisfy the EBNF grammar: | 6858 // that satisfy the EBNF grammar: |
| 6845 // literal = kSTRING {{ interpol }+ kSTRING } | 6859 // literal = kSTRING {{ interpol }+ kSTRING } |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7270 } | 7284 } |
| 7271 | 7285 |
| 7272 | 7286 |
| 7273 void Parser::SkipNestedExpr() { | 7287 void Parser::SkipNestedExpr() { |
| 7274 const bool saved_mode = SetAllowFunctionLiterals(true); | 7288 const bool saved_mode = SetAllowFunctionLiterals(true); |
| 7275 SkipExpr(); | 7289 SkipExpr(); |
| 7276 SetAllowFunctionLiterals(saved_mode); | 7290 SetAllowFunctionLiterals(saved_mode); |
| 7277 } | 7291 } |
| 7278 | 7292 |
| 7279 } // namespace dart | 7293 } // namespace dart |
| OLD | NEW |