| 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 95 |
| 96 static RawTypeArray* NewTypeArray(const GrowableArray<Type*>& objs) { | 96 static RawTypeArray* NewTypeArray(const GrowableArray<Type*>& objs) { |
| 97 TypeArray& a = TypeArray::Handle(TypeArray::New(objs.length())); | 97 TypeArray& a = TypeArray::Handle(TypeArray::New(objs.length())); |
| 98 for (int i = 0; i < objs.length(); i++) { | 98 for (int i = 0; i < objs.length(); i++) { |
| 99 a.SetTypeAt(i, *objs[i]); | 99 a.SetTypeAt(i, *objs[i]); |
| 100 } | 100 } |
| 101 return a.raw(); | 101 return a.raw(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 | 104 |
| 105 static ThrowNode* CreateEvalConstConstructorThrow(intptr_t token_pos, |
| 106 const Instance& instance) { |
| 107 UnhandledException& excp = UnhandledException::Handle(); |
| 108 excp ^= instance.raw(); |
| 109 const Instance& exception = Instance::ZoneHandle(excp.exception()); |
| 110 const Instance& stack_trace = Instance::ZoneHandle(excp.stacktrace()); |
| 111 return new ThrowNode(token_pos, |
| 112 new LiteralNode(token_pos, exception), |
| 113 new LiteralNode(token_pos, stack_trace)); |
| 114 } |
| 115 |
| 116 |
| 105 struct Parser::Block : public ZoneAllocated { | 117 struct Parser::Block : public ZoneAllocated { |
| 106 Block(Block* outer_block, LocalScope* local_scope, SequenceNode* seq) | 118 Block(Block* outer_block, LocalScope* local_scope, SequenceNode* seq) |
| 107 : parent(outer_block), scope(local_scope), statements(seq) { | 119 : parent(outer_block), scope(local_scope), statements(seq) { |
| 108 ASSERT(scope != NULL); | 120 ASSERT(scope != NULL); |
| 109 ASSERT(statements != NULL); | 121 ASSERT(statements != NULL); |
| 110 } | 122 } |
| 111 Block* parent; // Enclosing block, or NULL if outermost. | 123 Block* parent; // Enclosing block, or NULL if outermost. |
| 112 LocalScope* scope; | 124 LocalScope* scope; |
| 113 SequenceNode* statements; | 125 SequenceNode* statements; |
| 114 }; | 126 }; |
| (...skipping 5697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5812 for (int i = 0; i < arguments->length(); i++) { | 5824 for (int i = 0; i < arguments->length(); i++) { |
| 5813 AstNode* arg = arguments->NodeAt(i); | 5825 AstNode* arg = arguments->NodeAt(i); |
| 5814 // Arguments have been evaluated to a literal value already. | 5826 // Arguments have been evaluated to a literal value already. |
| 5815 ASSERT(arg->IsLiteralNode()); | 5827 ASSERT(arg->IsLiteralNode()); |
| 5816 arg_values.Add(&arg->AsLiteralNode()->literal()); | 5828 arg_values.Add(&arg->AsLiteralNode()->literal()); |
| 5817 } | 5829 } |
| 5818 const Array& opt_arg_names = arguments->names(); | 5830 const Array& opt_arg_names = arguments->names(); |
| 5819 const Instance& result = Instance::Handle( | 5831 const Instance& result = Instance::Handle( |
| 5820 DartEntry::InvokeStatic(constructor, arg_values, opt_arg_names)); | 5832 DartEntry::InvokeStatic(constructor, arg_values, opt_arg_names)); |
| 5821 if (result.IsUnhandledException()) { | 5833 if (result.IsUnhandledException()) { |
| 5822 ErrorMsg("Exception thrown in EvaluateConstConstructorCall"); | |
| 5823 } | |
| 5824 if (constructor.IsFactory()) { | |
| 5825 // The factory method returns the allocated object. | |
| 5826 instance = result.raw(); | 5834 instance = result.raw(); |
| 5827 } | 5835 } else { |
| 5828 if (!instance.IsNull()) { | 5836 if (constructor.IsFactory()) { |
| 5829 instance ^= instance.Canonicalize(); | 5837 // The factory method returns the allocated object. |
| 5838 instance = result.raw(); |
| 5839 } |
| 5840 if (!instance.IsNull()) { |
| 5841 instance ^= instance.Canonicalize(); |
| 5842 } |
| 5830 } | 5843 } |
| 5831 return instance.raw(); | 5844 return instance.raw(); |
| 5832 } | 5845 } |
| 5833 | 5846 |
| 5834 | 5847 |
| 5835 // Do a lookup for the identifier in the block scope and the class scope | 5848 // Do a lookup for the identifier in the block scope and the class scope |
| 5836 // return true if the identifier is found, false otherwise. | 5849 // return true if the identifier is found, false otherwise. |
| 5837 // If node is non NULL return an AST node corresponding to the identifier. | 5850 // If node is non NULL return an AST node corresponding to the identifier. |
| 5838 bool Parser::ResolveIdentInLocalScope(intptr_t ident_pos, | 5851 bool Parser::ResolveIdentInLocalScope(intptr_t ident_pos, |
| 5839 const String &ident, | 5852 const String &ident, |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6312 key_value_array.MakeImmutable(); | 6325 key_value_array.MakeImmutable(); |
| 6313 | 6326 |
| 6314 // Construct the map object. | 6327 // Construct the map object. |
| 6315 ArgumentListNode* constr_args = new ArgumentListNode(token_index_); | 6328 ArgumentListNode* constr_args = new ArgumentListNode(token_index_); |
| 6316 constr_args->Add(new LiteralNode(literal_pos, key_value_array)); | 6329 constr_args->Add(new LiteralNode(literal_pos, key_value_array)); |
| 6317 const String& constr_name = | 6330 const String& constr_name = |
| 6318 String::Handle(String::NewSymbol(kImmutableMapConstructorName)); | 6331 String::Handle(String::NewSymbol(kImmutableMapConstructorName)); |
| 6319 const Function& map_constr = Function::ZoneHandle( | 6332 const Function& map_constr = Function::ZoneHandle( |
| 6320 map_class.LookupConstructor(constr_name)); | 6333 map_class.LookupConstructor(constr_name)); |
| 6321 ASSERT(!map_constr.IsNull()); | 6334 ASSERT(!map_constr.IsNull()); |
| 6322 return new LiteralNode(literal_pos, Instance::ZoneHandle( | 6335 const Instance& const_instance = Instance::ZoneHandle( |
| 6323 EvaluateConstConstructorCall( | 6336 EvaluateConstConstructorCall(map_class, |
| 6324 map_class, map_type_arguments, map_constr, constr_args))); | 6337 map_type_arguments, |
| 6338 map_constr, |
| 6339 constr_args)); |
| 6340 if (const_instance.IsUnhandledException()) { |
| 6341 return CreateEvalConstConstructorThrow(literal_pos, const_instance); |
| 6342 } else { |
| 6343 return new LiteralNode(literal_pos, const_instance); |
| 6344 } |
| 6325 } else { | 6345 } else { |
| 6326 // Static call at runtime. | 6346 // Static call at runtime. |
| 6327 const String& static_factory_name = | 6347 const String& static_factory_name = |
| 6328 String::Handle(String::NewSymbol(kMutableMapFromLiteralName)); | 6348 String::Handle(String::NewSymbol(kMutableMapFromLiteralName)); |
| 6329 const Function& static_factory = Function::ZoneHandle( | 6349 const Function& static_factory = Function::ZoneHandle( |
| 6330 map_class.LookupStaticFunction(static_factory_name)); | 6350 map_class.LookupStaticFunction(static_factory_name)); |
| 6331 ASSERT(!static_factory.IsNull()); | 6351 ASSERT(!static_factory.IsNull()); |
| 6332 if (!map_type_arguments.IsNull() && | 6352 if (!map_type_arguments.IsNull() && |
| 6333 !map_type_arguments.IsInstantiated() && | 6353 !map_type_arguments.IsInstantiated() && |
| 6334 (current_block_->scope->function_level() > 0)) { | 6354 (current_block_->scope->function_level() > 0)) { |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6538 String::Handle(type_class.Name()).ToCString()); | 6558 String::Handle(type_class.Name()).ToCString()); |
| 6539 } | 6559 } |
| 6540 | 6560 |
| 6541 AstNode* new_object = NULL; | 6561 AstNode* new_object = NULL; |
| 6542 if (is_const) { | 6562 if (is_const) { |
| 6543 if (!constructor.is_const()) { | 6563 if (!constructor.is_const()) { |
| 6544 ErrorMsg("'const' requires const constructor: '%s'", | 6564 ErrorMsg("'const' requires const constructor: '%s'", |
| 6545 String::Handle(constructor.name()).ToCString()); | 6565 String::Handle(constructor.name()).ToCString()); |
| 6546 } | 6566 } |
| 6547 const Instance& const_instance = Instance::ZoneHandle( | 6567 const Instance& const_instance = Instance::ZoneHandle( |
| 6548 EvaluateConstConstructorCall( | 6568 EvaluateConstConstructorCall(type_class, |
| 6549 type_class, type_arguments, constructor, arguments)); | 6569 type_arguments, |
| 6550 new_object = new LiteralNode(new_pos, const_instance); | 6570 constructor, |
| 6571 arguments)); |
| 6572 if (const_instance.IsUnhandledException()) { |
| 6573 new_object = CreateEvalConstConstructorThrow(new_pos, const_instance); |
| 6574 } else { |
| 6575 new_object = new LiteralNode(new_pos, const_instance); |
| 6576 } |
| 6551 } else { | 6577 } else { |
| 6552 CheckFunctionIsCallable(new_pos, constructor); | 6578 CheckFunctionIsCallable(new_pos, constructor); |
| 6553 if (!type_arguments.IsNull() && | 6579 if (!type_arguments.IsNull() && |
| 6554 !type_arguments.IsInstantiated() && | 6580 !type_arguments.IsInstantiated() && |
| 6555 (current_block_->scope->function_level() > 0)) { | 6581 (current_block_->scope->function_level() > 0)) { |
| 6556 // Make sure that the instantiator is captured. | 6582 // Make sure that the instantiator is captured. |
| 6557 CaptureReceiver(); | 6583 CaptureReceiver(); |
| 6558 } | 6584 } |
| 6559 new_object = new ConstructorCallNode( | 6585 new_object = new ConstructorCallNode( |
| 6560 new_pos, type_arguments, constructor, arguments); | 6586 new_pos, type_arguments, constructor, arguments); |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6993 } | 7019 } |
| 6994 | 7020 |
| 6995 | 7021 |
| 6996 void Parser::SkipNestedExpr() { | 7022 void Parser::SkipNestedExpr() { |
| 6997 const bool saved_mode = SetAllowFunctionLiterals(true); | 7023 const bool saved_mode = SetAllowFunctionLiterals(true); |
| 6998 SkipExpr(); | 7024 SkipExpr(); |
| 6999 SetAllowFunctionLiterals(saved_mode); | 7025 SetAllowFunctionLiterals(saved_mode); |
| 7000 } | 7026 } |
| 7001 | 7027 |
| 7002 } // namespace dart | 7028 } // namespace dart |
| OLD | NEW |