| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 Array& a = Array::Handle(Array::New(objs.length(), Heap::kOld)); | 79 Array& a = Array::Handle(Array::New(objs.length(), Heap::kOld)); |
| 80 for (int i = 0; i < objs.length(); i++) { | 80 for (int i = 0; i < objs.length(); i++) { |
| 81 a.SetAt(i, *objs[i]); | 81 a.SetAt(i, *objs[i]); |
| 82 } | 82 } |
| 83 return a.raw(); | 83 return a.raw(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 | 86 |
| 87 static RawTypeArguments* NewTypeArguments( | 87 static RawTypeArguments* NewTypeArguments( |
| 88 const GrowableArray<AbstractType*>& objs) { | 88 const GrowableArray<AbstractType*>& objs) { |
| 89 TypeArguments& a = TypeArguments::Handle(TypeArguments::New(objs.length())); | 89 const TypeArguments& a = |
| 90 TypeArguments::Handle(TypeArguments::New(objs.length())); |
| 90 for (int i = 0; i < objs.length(); i++) { | 91 for (int i = 0; i < objs.length(); i++) { |
| 91 a.SetTypeAt(i, *objs[i]); | 92 a.SetTypeAt(i, *objs[i]); |
| 92 } | 93 } |
| 94 // Cannot canonicalize TypeArgument yet as its types may not have been |
| 95 // finalized yet. |
| 93 return a.raw(); | 96 return a.raw(); |
| 94 } | 97 } |
| 95 | 98 |
| 96 | 99 |
| 97 static ThrowNode* CreateEvalConstConstructorThrow(intptr_t token_pos, | 100 static ThrowNode* CreateEvalConstConstructorThrow(intptr_t token_pos, |
| 98 const Instance& instance) { | 101 const Instance& instance) { |
| 99 UnhandledException& excp = UnhandledException::Handle(); | 102 UnhandledException& excp = UnhandledException::Handle(); |
| 100 excp ^= instance.raw(); | 103 excp ^= instance.raw(); |
| 101 const Instance& exception = Instance::ZoneHandle(excp.exception()); | 104 const Instance& exception = Instance::ZoneHandle(excp.exception()); |
| 102 const Instance& stack_trace = Instance::ZoneHandle(excp.stacktrace()); | 105 const Instance& stack_trace = Instance::ZoneHandle(excp.stacktrace()); |
| (...skipping 6628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6731 literal_factory_class.LookupFactory(literal_list_factory_name)); | 6734 literal_factory_class.LookupFactory(literal_list_factory_name)); |
| 6732 ASSERT(!literal_list_factory.IsNull()); | 6735 ASSERT(!literal_list_factory.IsNull()); |
| 6733 if (!type_arguments.IsNull() && | 6736 if (!type_arguments.IsNull() && |
| 6734 !type_arguments.IsInstantiated() && | 6737 !type_arguments.IsInstantiated() && |
| 6735 (current_block_->scope->function_level() > 0)) { | 6738 (current_block_->scope->function_level() > 0)) { |
| 6736 // Make sure that the instantiator is captured. | 6739 // Make sure that the instantiator is captured. |
| 6737 CaptureReceiver(); | 6740 CaptureReceiver(); |
| 6738 } | 6741 } |
| 6739 ArgumentListNode* factory_param = new ArgumentListNode(literal_pos); | 6742 ArgumentListNode* factory_param = new ArgumentListNode(literal_pos); |
| 6740 factory_param->Add(list); | 6743 factory_param->Add(list); |
| 6741 return new ConstructorCallNode( | 6744 AbstractTypeArguments& canonical_type_arguments = |
| 6742 literal_pos, type_arguments, literal_list_factory, factory_param); | 6745 AbstractTypeArguments::ZoneHandle(type_arguments.Canonicalize()); |
| 6746 return new ConstructorCallNode(literal_pos, |
| 6747 canonical_type_arguments, |
| 6748 literal_list_factory, |
| 6749 factory_param); |
| 6743 } | 6750 } |
| 6744 } | 6751 } |
| 6745 | 6752 |
| 6746 | 6753 |
| 6747 static void AddKeyValuePair(ArrayNode* pairs, | 6754 static void AddKeyValuePair(ArrayNode* pairs, |
| 6748 bool is_const, | 6755 bool is_const, |
| 6749 AstNode* key, | 6756 AstNode* key, |
| 6750 AstNode* value) { | 6757 AstNode* value) { |
| 6751 if (is_const) { | 6758 if (is_const) { |
| 6752 ASSERT(key->IsLiteralNode()); | 6759 ASSERT(key->IsLiteralNode()); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6809 type_array.SetTypeAt(1, value_type); | 6816 type_array.SetTypeAt(1, value_type); |
| 6810 map_type_arguments = type_array.raw(); | 6817 map_type_arguments = type_array.raw(); |
| 6811 } | 6818 } |
| 6812 if (is_const && !value_type.IsInstantiated()) { | 6819 if (is_const && !value_type.IsInstantiated()) { |
| 6813 ErrorMsg(type_pos, | 6820 ErrorMsg(type_pos, |
| 6814 "the type argument of a constant map literal cannot include " | 6821 "the type argument of a constant map literal cannot include " |
| 6815 "a type variable"); | 6822 "a type variable"); |
| 6816 } | 6823 } |
| 6817 } | 6824 } |
| 6818 ASSERT(map_type_arguments.IsNull() || (map_type_arguments.Length() == 2)); | 6825 ASSERT(map_type_arguments.IsNull() || (map_type_arguments.Length() == 2)); |
| 6826 map_type_arguments ^= map_type_arguments.Canonicalize(); |
| 6819 | 6827 |
| 6820 // Parse the map entries. Note: there may be an optional extra | 6828 // Parse the map entries. Note: there may be an optional extra |
| 6821 // comma after the last entry. | 6829 // comma after the last entry. |
| 6822 ArrayNode* kv_pairs = | 6830 ArrayNode* kv_pairs = |
| 6823 new ArrayNode(token_index_, TypeArguments::ZoneHandle()); | 6831 new ArrayNode(token_index_, TypeArguments::ZoneHandle()); |
| 6824 const String& dst_name = String::ZoneHandle( | 6832 const String& dst_name = String::ZoneHandle( |
| 6825 String::NewSymbol("list literal element")); | 6833 String::NewSymbol("list literal element")); |
| 6826 while (CurrentToken() != Token::kRBRACE) { | 6834 while (CurrentToken() != Token::kRBRACE) { |
| 6827 AstNode* key = NULL; | 6835 AstNode* key = NULL; |
| 6828 if (CurrentToken() == Token::kSTRING) { | 6836 if (CurrentToken() == Token::kSTRING) { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6929 literal_factory_class.LookupFactory(literal_map_factory_name)); | 6937 literal_factory_class.LookupFactory(literal_map_factory_name)); |
| 6930 ASSERT(!literal_map_factory.IsNull()); | 6938 ASSERT(!literal_map_factory.IsNull()); |
| 6931 if (!map_type_arguments.IsNull() && | 6939 if (!map_type_arguments.IsNull() && |
| 6932 !map_type_arguments.IsInstantiated() && | 6940 !map_type_arguments.IsInstantiated() && |
| 6933 (current_block_->scope->function_level() > 0)) { | 6941 (current_block_->scope->function_level() > 0)) { |
| 6934 // Make sure that the instantiator is captured. | 6942 // Make sure that the instantiator is captured. |
| 6935 CaptureReceiver(); | 6943 CaptureReceiver(); |
| 6936 } | 6944 } |
| 6937 ArgumentListNode* factory_param = new ArgumentListNode(literal_pos); | 6945 ArgumentListNode* factory_param = new ArgumentListNode(literal_pos); |
| 6938 factory_param->Add(kv_pairs); | 6946 factory_param->Add(kv_pairs); |
| 6939 return new ConstructorCallNode( | 6947 return new ConstructorCallNode(literal_pos, |
| 6940 literal_pos, map_type_arguments, literal_map_factory, factory_param); | 6948 map_type_arguments, |
| 6949 literal_map_factory, |
| 6950 factory_param); |
| 6941 } | 6951 } |
| 6942 } | 6952 } |
| 6943 | 6953 |
| 6944 | 6954 |
| 6945 AstNode* Parser::ParseCompoundLiteral() { | 6955 AstNode* Parser::ParseCompoundLiteral() { |
| 6946 bool is_const = false; | 6956 bool is_const = false; |
| 6947 if (CurrentToken() == Token::kCONST) { | 6957 if (CurrentToken() == Token::kCONST) { |
| 6948 is_const = true; | 6958 is_const = true; |
| 6949 ConsumeToken(); | 6959 ConsumeToken(); |
| 6950 } | 6960 } |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7137 String& errmsg = String::Handle(); | 7147 String& errmsg = String::Handle(); |
| 7138 type = ClassFinalizer::FinalizeAndCanonicalizeType(type, &errmsg); | 7148 type = ClassFinalizer::FinalizeAndCanonicalizeType(type, &errmsg); |
| 7139 if (!errmsg.IsNull()) { | 7149 if (!errmsg.IsNull()) { |
| 7140 ErrorMsg(errmsg.ToCString()); | 7150 ErrorMsg(errmsg.ToCString()); |
| 7141 } | 7151 } |
| 7142 // The type argument vector may have been expanded with the type arguments | 7152 // The type argument vector may have been expanded with the type arguments |
| 7143 // of the super type when finalizing the type. | 7153 // of the super type when finalizing the type. |
| 7144 type_arguments = type.arguments(); | 7154 type_arguments = type.arguments(); |
| 7145 } | 7155 } |
| 7146 | 7156 |
| 7157 type_arguments ^= type_arguments.Canonicalize(); |
| 7147 // Make the constructor call. | 7158 // Make the constructor call. |
| 7148 AstNode* new_object = NULL; | 7159 AstNode* new_object = NULL; |
| 7149 if (is_const) { | 7160 if (is_const) { |
| 7150 if (!constructor.is_const()) { | 7161 if (!constructor.is_const()) { |
| 7151 ErrorMsg("'const' requires const constructor: '%s'", | 7162 ErrorMsg("'const' requires const constructor: '%s'", |
| 7152 String::Handle(constructor.name()).ToCString()); | 7163 String::Handle(constructor.name()).ToCString()); |
| 7153 } | 7164 } |
| 7154 const Instance& const_instance = Instance::ZoneHandle( | 7165 const Instance& const_instance = Instance::ZoneHandle( |
| 7155 EvaluateConstConstructorCall(type_class, | 7166 EvaluateConstConstructorCall(type_class, |
| 7156 type_arguments, | 7167 type_arguments, |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7607 } | 7618 } |
| 7608 | 7619 |
| 7609 | 7620 |
| 7610 void Parser::SkipNestedExpr() { | 7621 void Parser::SkipNestedExpr() { |
| 7611 const bool saved_mode = SetAllowFunctionLiterals(true); | 7622 const bool saved_mode = SetAllowFunctionLiterals(true); |
| 7612 SkipExpr(); | 7623 SkipExpr(); |
| 7613 SetAllowFunctionLiterals(saved_mode); | 7624 SetAllowFunctionLiterals(saved_mode); |
| 7614 } | 7625 } |
| 7615 | 7626 |
| 7616 } // namespace dart | 7627 } // namespace dart |
| OLD | NEW |