| 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 5708 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 5823   for (int i = 0; i < arguments->length(); i++) { | 5835   for (int i = 0; i < arguments->length(); i++) { | 
| 5824     AstNode* arg = arguments->NodeAt(i); | 5836     AstNode* arg = arguments->NodeAt(i); | 
| 5825     // Arguments have been evaluated to a literal value already. | 5837     // Arguments have been evaluated to a literal value already. | 
| 5826     ASSERT(arg->IsLiteralNode()); | 5838     ASSERT(arg->IsLiteralNode()); | 
| 5827     arg_values.Add(&arg->AsLiteralNode()->literal()); | 5839     arg_values.Add(&arg->AsLiteralNode()->literal()); | 
| 5828   } | 5840   } | 
| 5829   const Array& opt_arg_names = arguments->names(); | 5841   const Array& opt_arg_names = arguments->names(); | 
| 5830   const Instance& result = Instance::Handle( | 5842   const Instance& result = Instance::Handle( | 
| 5831       DartEntry::InvokeStatic(constructor, arg_values, opt_arg_names)); | 5843       DartEntry::InvokeStatic(constructor, arg_values, opt_arg_names)); | 
| 5832   if (result.IsUnhandledException()) { | 5844   if (result.IsUnhandledException()) { | 
| 5833     ErrorMsg("Exception thrown in EvaluateConstConstructorCall"); |  | 
| 5834   } |  | 
| 5835   if (constructor.IsFactory()) { |  | 
| 5836     // The factory method returns the allocated object. |  | 
| 5837     instance = result.raw(); | 5845     instance = result.raw(); | 
| 5838   } | 5846   } else { | 
| 5839   if (!instance.IsNull()) { | 5847     if (constructor.IsFactory()) { | 
| 5840     instance ^= instance.Canonicalize(); | 5848       // The factory method returns the allocated object. | 
|  | 5849       instance = result.raw(); | 
|  | 5850     } | 
|  | 5851     if (!instance.IsNull()) { | 
|  | 5852       instance ^= instance.Canonicalize(); | 
|  | 5853     } | 
| 5841   } | 5854   } | 
| 5842   return instance.raw(); | 5855   return instance.raw(); | 
| 5843 } | 5856 } | 
| 5844 | 5857 | 
| 5845 | 5858 | 
| 5846 // Do a lookup for the identifier in the block scope and the class scope | 5859 // Do a lookup for the identifier in the block scope and the class scope | 
| 5847 // return true if the identifier is found, false otherwise. | 5860 // return true if the identifier is found, false otherwise. | 
| 5848 // If node is non NULL return an AST node corresponding to the identifier. | 5861 // If node is non NULL return an AST node corresponding to the identifier. | 
| 5849 bool Parser::ResolveIdentInLocalScope(intptr_t ident_pos, | 5862 bool Parser::ResolveIdentInLocalScope(intptr_t ident_pos, | 
| 5850                                       const String &ident, | 5863                                       const String &ident, | 
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 6323     key_value_array.MakeImmutable(); | 6336     key_value_array.MakeImmutable(); | 
| 6324 | 6337 | 
| 6325     // Construct the map object. | 6338     // Construct the map object. | 
| 6326     ArgumentListNode* constr_args = new ArgumentListNode(token_index_); | 6339     ArgumentListNode* constr_args = new ArgumentListNode(token_index_); | 
| 6327     constr_args->Add(new LiteralNode(literal_pos, key_value_array)); | 6340     constr_args->Add(new LiteralNode(literal_pos, key_value_array)); | 
| 6328     const String& constr_name = | 6341     const String& constr_name = | 
| 6329         String::Handle(String::NewSymbol(kImmutableMapConstructorName)); | 6342         String::Handle(String::NewSymbol(kImmutableMapConstructorName)); | 
| 6330     const Function& map_constr = Function::ZoneHandle( | 6343     const Function& map_constr = Function::ZoneHandle( | 
| 6331         map_class.LookupConstructor(constr_name)); | 6344         map_class.LookupConstructor(constr_name)); | 
| 6332     ASSERT(!map_constr.IsNull()); | 6345     ASSERT(!map_constr.IsNull()); | 
| 6333     return new LiteralNode(literal_pos, Instance::ZoneHandle( | 6346     const Instance& const_instance = Instance::ZoneHandle( | 
| 6334         EvaluateConstConstructorCall( | 6347         EvaluateConstConstructorCall(map_class, | 
| 6335             map_class, map_type_arguments, map_constr, constr_args))); | 6348                                      map_type_arguments, | 
|  | 6349                                      map_constr, | 
|  | 6350                                      constr_args)); | 
|  | 6351     if (const_instance.IsUnhandledException()) { | 
|  | 6352       return CreateEvalConstConstructorThrow(literal_pos, const_instance); | 
|  | 6353     } else { | 
|  | 6354       return new LiteralNode(literal_pos, const_instance); | 
|  | 6355     } | 
| 6336   } else { | 6356   } else { | 
| 6337     // Static call at runtime. | 6357     // Static call at runtime. | 
| 6338     const String& static_factory_name = | 6358     const String& static_factory_name = | 
| 6339         String::Handle(String::NewSymbol(kMutableMapFromLiteralName)); | 6359         String::Handle(String::NewSymbol(kMutableMapFromLiteralName)); | 
| 6340     const Function& static_factory = Function::ZoneHandle( | 6360     const Function& static_factory = Function::ZoneHandle( | 
| 6341         map_class.LookupStaticFunction(static_factory_name)); | 6361         map_class.LookupStaticFunction(static_factory_name)); | 
| 6342     ASSERT(!static_factory.IsNull()); | 6362     ASSERT(!static_factory.IsNull()); | 
| 6343     if (!map_type_arguments.IsNull() && | 6363     if (!map_type_arguments.IsNull() && | 
| 6344         !map_type_arguments.IsInstantiated() && | 6364         !map_type_arguments.IsInstantiated() && | 
| 6345         (current_block_->scope->function_level() > 0)) { | 6365         (current_block_->scope->function_level() > 0)) { | 
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 6549              String::Handle(type_class.Name()).ToCString()); | 6569              String::Handle(type_class.Name()).ToCString()); | 
| 6550   } | 6570   } | 
| 6551 | 6571 | 
| 6552   AstNode* new_object = NULL; | 6572   AstNode* new_object = NULL; | 
| 6553   if (is_const) { | 6573   if (is_const) { | 
| 6554     if (!constructor.is_const()) { | 6574     if (!constructor.is_const()) { | 
| 6555       ErrorMsg("'const' requires const constructor: '%s'", | 6575       ErrorMsg("'const' requires const constructor: '%s'", | 
| 6556           String::Handle(constructor.name()).ToCString()); | 6576           String::Handle(constructor.name()).ToCString()); | 
| 6557     } | 6577     } | 
| 6558     const Instance& const_instance = Instance::ZoneHandle( | 6578     const Instance& const_instance = Instance::ZoneHandle( | 
| 6559         EvaluateConstConstructorCall( | 6579         EvaluateConstConstructorCall(type_class, | 
| 6560             type_class, type_arguments, constructor, arguments)); | 6580                                      type_arguments, | 
| 6561     new_object = new LiteralNode(new_pos, const_instance); | 6581                                      constructor, | 
|  | 6582                                      arguments)); | 
|  | 6583     if (const_instance.IsUnhandledException()) { | 
|  | 6584       new_object = CreateEvalConstConstructorThrow(new_pos, const_instance); | 
|  | 6585     } else { | 
|  | 6586       new_object = new LiteralNode(new_pos, const_instance); | 
|  | 6587     } | 
| 6562   } else { | 6588   } else { | 
| 6563     CheckFunctionIsCallable(new_pos, constructor); | 6589     CheckFunctionIsCallable(new_pos, constructor); | 
| 6564     if (!type_arguments.IsNull() && | 6590     if (!type_arguments.IsNull() && | 
| 6565         !type_arguments.IsInstantiated() && | 6591         !type_arguments.IsInstantiated() && | 
| 6566         (current_block_->scope->function_level() > 0)) { | 6592         (current_block_->scope->function_level() > 0)) { | 
| 6567       // Make sure that the instantiator is captured. | 6593       // Make sure that the instantiator is captured. | 
| 6568       CaptureReceiver(); | 6594       CaptureReceiver(); | 
| 6569     } | 6595     } | 
| 6570     new_object = new ConstructorCallNode( | 6596     new_object = new ConstructorCallNode( | 
| 6571         new_pos, type_arguments, constructor, arguments); | 6597         new_pos, type_arguments, constructor, arguments); | 
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 7004 } | 7030 } | 
| 7005 | 7031 | 
| 7006 | 7032 | 
| 7007 void Parser::SkipNestedExpr() { | 7033 void Parser::SkipNestedExpr() { | 
| 7008   const bool saved_mode = SetAllowFunctionLiterals(true); | 7034   const bool saved_mode = SetAllowFunctionLiterals(true); | 
| 7009   SkipExpr(); | 7035   SkipExpr(); | 
| 7010   SetAllowFunctionLiterals(saved_mode); | 7036   SetAllowFunctionLiterals(saved_mode); | 
| 7011 } | 7037 } | 
| 7012 | 7038 | 
| 7013 }  // namespace dart | 7039 }  // namespace dart | 
| OLD | NEW | 
|---|