| 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 2001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2012 &Type::ZoneHandle(Type::DynamicType())); | 2012 &Type::ZoneHandle(Type::DynamicType())); |
| 2013 } | 2013 } |
| 2014 if (are_implicitly_final) { | 2014 if (are_implicitly_final) { |
| 2015 method->params.SetImplicitlyFinal(); | 2015 method->params.SetImplicitlyFinal(); |
| 2016 } | 2016 } |
| 2017 ParseFormalParameterList(allow_explicit_default_values, &method->params); | 2017 ParseFormalParameterList(allow_explicit_default_values, &method->params); |
| 2018 if (method->IsGetter() || method->IsSetter()) { | 2018 if (method->IsGetter() || method->IsSetter()) { |
| 2019 int expected_num_parameters = 0; | 2019 int expected_num_parameters = 0; |
| 2020 if (method->IsGetter()) { | 2020 if (method->IsGetter()) { |
| 2021 expected_num_parameters = (method->has_static) ? 0 : 1; | 2021 expected_num_parameters = (method->has_static) ? 0 : 1; |
| 2022 method->name = &String::ZoneHandle(Field::GetterName(*method->name)); | 2022 method->name = &String::ZoneHandle(Field::GetterSymbol(*method->name)); |
| 2023 } else { | 2023 } else { |
| 2024 ASSERT(method->IsSetter()); | 2024 ASSERT(method->IsSetter()); |
| 2025 expected_num_parameters = (method->has_static) ? 1 : 2; | 2025 expected_num_parameters = (method->has_static) ? 1 : 2; |
| 2026 method->name = &String::ZoneHandle(Field::SetterName(*method->name)); | 2026 method->name = &String::ZoneHandle(Field::SetterSymbol(*method->name)); |
| 2027 } | 2027 } |
| 2028 if ((method->params.num_fixed_parameters != expected_num_parameters) || | 2028 if ((method->params.num_fixed_parameters != expected_num_parameters) || |
| 2029 (method->params.num_optional_parameters != 0)) { | 2029 (method->params.num_optional_parameters != 0)) { |
| 2030 ErrorMsg(method->name_pos, "illegal %s parameters", | 2030 ErrorMsg(method->name_pos, "illegal %s parameters", |
| 2031 method->IsGetter() ? "getter" : "setter"); | 2031 method->IsGetter() ? "getter" : "setter"); |
| 2032 } | 2032 } |
| 2033 } | 2033 } |
| 2034 | 2034 |
| 2035 // Parse initializers. | 2035 // Parse initializers. |
| 2036 if (CurrentToken() == Token::kCOLON) { | 2036 if (CurrentToken() == Token::kCOLON) { |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2211 field->has_final, | 2211 field->has_final, |
| 2212 field->name_pos)); | 2212 field->name_pos)); |
| 2213 class_field.set_type(*field->type); | 2213 class_field.set_type(*field->type); |
| 2214 class_field.set_has_initializer(has_initializer); | 2214 class_field.set_has_initializer(has_initializer); |
| 2215 members->AddField(&class_field); | 2215 members->AddField(&class_field); |
| 2216 | 2216 |
| 2217 // For static final fields, set value to "uninitialized" and | 2217 // For static final fields, set value to "uninitialized" and |
| 2218 // create a kConstImplicitGetter getter method. | 2218 // create a kConstImplicitGetter getter method. |
| 2219 if (field->has_static && has_initializer) { | 2219 if (field->has_static && has_initializer) { |
| 2220 class_field.set_value(Instance::Handle(Object::sentinel())); | 2220 class_field.set_value(Instance::Handle(Object::sentinel())); |
| 2221 String& getter_name = String::ZoneHandle(Field::GetterName(*field->name)); | 2221 String& getter_name = |
| 2222 String::ZoneHandle(Field::GetterSymbol(*field->name)); |
| 2222 Function& getter = Function::ZoneHandle( | 2223 Function& getter = Function::ZoneHandle( |
| 2223 Function::New(getter_name, RawFunction::kConstImplicitGetter, | 2224 Function::New(getter_name, RawFunction::kConstImplicitGetter, |
| 2224 field->has_static, field->has_final, | 2225 field->has_static, field->has_final, |
| 2225 field->name_pos)); | 2226 field->name_pos)); |
| 2226 getter.set_result_type(*field->type); | 2227 getter.set_result_type(*field->type); |
| 2227 members->AddFunction(&getter); | 2228 members->AddFunction(&getter); |
| 2228 } | 2229 } |
| 2229 | 2230 |
| 2230 // For instance fields, we create implicit getter and setter methods. | 2231 // For instance fields, we create implicit getter and setter methods. |
| 2231 if (!field->has_static) { | 2232 if (!field->has_static) { |
| 2232 String& getter_name = | 2233 String& getter_name = |
| 2233 String::ZoneHandle(Field::GetterName(*field->name)); | 2234 String::ZoneHandle(Field::GetterSymbol(*field->name)); |
| 2234 Function& getter = Function::ZoneHandle( | 2235 Function& getter = Function::ZoneHandle( |
| 2235 Function::New(getter_name, RawFunction::kImplicitGetter, | 2236 Function::New(getter_name, RawFunction::kImplicitGetter, |
| 2236 field->has_static, field->has_final, | 2237 field->has_static, field->has_final, |
| 2237 field->name_pos)); | 2238 field->name_pos)); |
| 2238 ParamList params; | 2239 ParamList params; |
| 2239 params.AddReceiver(token_index_); | 2240 params.AddReceiver(token_index_); |
| 2240 getter.set_result_type(*field->type); | 2241 getter.set_result_type(*field->type); |
| 2241 AddFormalParamsToFunction(¶ms, getter); | 2242 AddFormalParamsToFunction(¶ms, getter); |
| 2242 members->AddFunction(&getter); | 2243 members->AddFunction(&getter); |
| 2243 if (!field->has_final) { | 2244 if (!field->has_final) { |
| 2244 // Build a setter accessor for non-const fields. | 2245 // Build a setter accessor for non-const fields. |
| 2245 String& setter_name = String::ZoneHandle( | 2246 String& setter_name = String::ZoneHandle( |
| 2246 Field::SetterName(*field->name)); | 2247 Field::SetterSymbol(*field->name)); |
| 2247 Function& setter = Function::ZoneHandle( | 2248 Function& setter = Function::ZoneHandle( |
| 2248 Function::New(setter_name, RawFunction::kImplicitSetter, | 2249 Function::New(setter_name, RawFunction::kImplicitSetter, |
| 2249 field->has_static, field->has_final, | 2250 field->has_static, field->has_final, |
| 2250 field->name_pos)); | 2251 field->name_pos)); |
| 2251 ParamList params; | 2252 ParamList params; |
| 2252 params.AddReceiver(token_index_); | 2253 params.AddReceiver(token_index_); |
| 2253 params.AddFinalParameter(token_index_, "value", field->type); | 2254 params.AddFinalParameter(token_index_, "value", field->type); |
| 2254 setter.set_result_type(Type::Handle(Type::VoidType())); | 2255 setter.set_result_type(Type::Handle(Type::VoidType())); |
| 2255 AddFormalParamsToFunction(¶ms, setter); | 2256 AddFormalParamsToFunction(¶ms, setter); |
| 2256 members->AddFunction(&setter); | 2257 members->AddFunction(&setter); |
| (...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3081 Field::New(var_name, is_static, is_final, name_pos)); | 3082 Field::New(var_name, is_static, is_final, name_pos)); |
| 3082 field.set_type(type); | 3083 field.set_type(type); |
| 3083 field.set_value(Instance::Handle(Instance::null())); | 3084 field.set_value(Instance::Handle(Instance::null())); |
| 3084 top_level->fields.Add(&field); | 3085 top_level->fields.Add(&field); |
| 3085 library_.AddObject(field, var_name); | 3086 library_.AddObject(field, var_name); |
| 3086 if (CurrentToken() == Token::kASSIGN) { | 3087 if (CurrentToken() == Token::kASSIGN) { |
| 3087 ConsumeToken(); | 3088 ConsumeToken(); |
| 3088 SkipExpr(); | 3089 SkipExpr(); |
| 3089 field.set_value(Instance::Handle(Object::sentinel())); | 3090 field.set_value(Instance::Handle(Object::sentinel())); |
| 3090 // Create a static const getter. | 3091 // Create a static const getter. |
| 3091 String& getter_name = String::ZoneHandle(Field::GetterName(var_name)); | 3092 String& getter_name = String::ZoneHandle(Field::GetterSymbol(var_name)); |
| 3092 Function& getter = Function::ZoneHandle( | 3093 Function& getter = Function::ZoneHandle( |
| 3093 Function::New(getter_name, RawFunction::kConstImplicitGetter, | 3094 Function::New(getter_name, RawFunction::kConstImplicitGetter, |
| 3094 is_static, is_final, name_pos)); | 3095 is_static, is_final, name_pos)); |
| 3095 getter.set_result_type(type); | 3096 getter.set_result_type(type); |
| 3096 top_level->functions.Add(&getter); | 3097 top_level->functions.Add(&getter); |
| 3097 } else if (is_final) { | 3098 } else if (is_final) { |
| 3098 ErrorMsg(name_pos, "missing initializer for final variable"); | 3099 ErrorMsg(name_pos, "missing initializer for final variable"); |
| 3099 } | 3100 } |
| 3100 | 3101 |
| 3101 if (CurrentToken() == Token::kCOMMA) { | 3102 if (CurrentToken() == Token::kCOMMA) { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3202 ErrorMsg("'(' expected"); | 3203 ErrorMsg("'(' expected"); |
| 3203 } | 3204 } |
| 3204 const intptr_t accessor_pos = token_index_; | 3205 const intptr_t accessor_pos = token_index_; |
| 3205 ParamList params; | 3206 ParamList params; |
| 3206 const bool allow_explicit_default_values = true; | 3207 const bool allow_explicit_default_values = true; |
| 3207 ParseFormalParameterList(allow_explicit_default_values, ¶ms); | 3208 ParseFormalParameterList(allow_explicit_default_values, ¶ms); |
| 3208 String& accessor_name = String::ZoneHandle(); | 3209 String& accessor_name = String::ZoneHandle(); |
| 3209 int expected_num_parameters = -1; | 3210 int expected_num_parameters = -1; |
| 3210 if (is_getter) { | 3211 if (is_getter) { |
| 3211 expected_num_parameters = 0; | 3212 expected_num_parameters = 0; |
| 3212 accessor_name = Field::GetterName(*field_name); | 3213 accessor_name = Field::GetterSymbol(*field_name); |
| 3213 } else { | 3214 } else { |
| 3214 expected_num_parameters = 1; | 3215 expected_num_parameters = 1; |
| 3215 accessor_name = Field::SetterName(*field_name); | 3216 accessor_name = Field::SetterSymbol(*field_name); |
| 3216 } | 3217 } |
| 3217 if ((params.num_fixed_parameters != expected_num_parameters) || | 3218 if ((params.num_fixed_parameters != expected_num_parameters) || |
| 3218 (params.num_optional_parameters != 0)) { | 3219 (params.num_optional_parameters != 0)) { |
| 3219 ErrorMsg(name_pos, "illegal %s parameters", | 3220 ErrorMsg(name_pos, "illegal %s parameters", |
| 3220 is_getter ? "getter" : "setter"); | 3221 is_getter ? "getter" : "setter"); |
| 3221 } | 3222 } |
| 3222 | 3223 |
| 3223 if (library_.LookupObject(*field_name) != Object::null()) { | 3224 if (library_.LookupObject(*field_name) != Object::null()) { |
| 3224 ErrorMsg(name_pos, "'%s' is already defined in this library", | 3225 ErrorMsg(name_pos, "'%s' is already defined in this library", |
| 3225 field_name->ToCString()); | 3226 field_name->ToCString()); |
| (...skipping 3217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6443 LocalVariable* local = LookupLocalScope(ident); | 6444 LocalVariable* local = LookupLocalScope(ident); |
| 6444 if (local != NULL) { | 6445 if (local != NULL) { |
| 6445 *node = new LoadLocalNode(ident_pos, *local); | 6446 *node = new LoadLocalNode(ident_pos, *local); |
| 6446 return true; | 6447 return true; |
| 6447 } | 6448 } |
| 6448 | 6449 |
| 6449 // Try to find the identifier in the class scope. | 6450 // Try to find the identifier in the class scope. |
| 6450 Class& cls = Class::Handle(isolate, current_class().raw()); | 6451 Class& cls = Class::Handle(isolate, current_class().raw()); |
| 6451 Function& func = Function::Handle(isolate, Function::null()); | 6452 Function& func = Function::Handle(isolate, Function::null()); |
| 6452 Field& field = Field::Handle(isolate, Field::null()); | 6453 Field& field = Field::Handle(isolate, Field::null()); |
| 6453 String& accessor_name = String::Handle(isolate, String::null()); | |
| 6454 while (!cls.IsNull()) { | 6454 while (!cls.IsNull()) { |
| 6455 // First check if a field exists. | 6455 // First check if a field exists. |
| 6456 field = cls.LookupField(ident); | 6456 field = cls.LookupField(ident); |
| 6457 if (!field.IsNull()) { | 6457 if (!field.IsNull()) { |
| 6458 if (!field.is_static()) { | 6458 if (!field.is_static()) { |
| 6459 CheckInstanceFieldAccess(ident_pos, ident); | 6459 CheckInstanceFieldAccess(ident_pos, ident); |
| 6460 *node = CallGetter(ident_pos, LoadReceiver(ident_pos), ident); | 6460 *node = CallGetter(ident_pos, LoadReceiver(ident_pos), ident); |
| 6461 } else { | 6461 } else { |
| 6462 *node = GenerateStaticFieldLookup(field, ident_pos); | 6462 *node = GenerateStaticFieldLookup(field, ident_pos); |
| 6463 } | 6463 } |
| 6464 return true; | 6464 return true; |
| 6465 } | 6465 } |
| 6466 | 6466 |
| 6467 // Check if an instance/static function exists. | 6467 // Check if an instance/static function exists. |
| 6468 func = cls.LookupFunction(ident); | 6468 func = cls.LookupFunction(ident); |
| 6469 if (!func.IsNull() && | 6469 if (!func.IsNull() && |
| 6470 (func.IsDynamicFunction() || func.IsStaticFunction())) { | 6470 (func.IsDynamicFunction() || func.IsStaticFunction())) { |
| 6471 *node = new PrimaryNode(ident_pos, | 6471 *node = new PrimaryNode(ident_pos, |
| 6472 Function::ZoneHandle(isolate, func.raw())); | 6472 Function::ZoneHandle(isolate, func.raw())); |
| 6473 return true; | 6473 return true; |
| 6474 } | 6474 } |
| 6475 | 6475 |
| 6476 // Now check if a getter/setter method exists for it in which case | 6476 // Now check if a getter/setter method exists for it in which case |
| 6477 // it is still a field. | 6477 // it is still a field. |
| 6478 accessor_name = Field::GetterName(ident); | 6478 func = cls.LookupGetterFunction(ident); |
| 6479 func = cls.LookupFunction(accessor_name); | |
| 6480 if (!func.IsNull()) { | 6479 if (!func.IsNull()) { |
| 6481 if (func.IsDynamicFunction()) { | 6480 if (func.IsDynamicFunction()) { |
| 6482 CheckInstanceFieldAccess(ident_pos, ident); | 6481 CheckInstanceFieldAccess(ident_pos, ident); |
| 6483 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); | 6482 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); |
| 6484 *node = CallGetter(ident_pos, LoadReceiver(ident_pos), ident); | 6483 *node = CallGetter(ident_pos, LoadReceiver(ident_pos), ident); |
| 6485 return true; | 6484 return true; |
| 6486 } else if (func.IsStaticFunction()) { | 6485 } else if (func.IsStaticFunction()) { |
| 6487 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); | 6486 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); |
| 6488 *node = new StaticGetterNode(ident_pos, | 6487 *node = new StaticGetterNode(ident_pos, |
| 6489 Class::ZoneHandle(isolate, cls.raw()), | 6488 Class::ZoneHandle(isolate, cls.raw()), |
| 6490 ident); | 6489 ident); |
| 6491 return true; | 6490 return true; |
| 6492 } | 6491 } |
| 6493 } | 6492 } |
| 6494 accessor_name = Field::SetterName(ident); | 6493 func = cls.LookupSetterFunction(ident); |
| 6495 func = cls.LookupFunction(accessor_name); | |
| 6496 if (!func.IsNull()) { | 6494 if (!func.IsNull()) { |
| 6497 if (func.IsDynamicFunction()) { | 6495 if (func.IsDynamicFunction()) { |
| 6498 // We create a getter node even though a getter doesn't exist as | 6496 // We create a getter node even though a getter doesn't exist as |
| 6499 // it could be followed by an assignment which will convert it to | 6497 // it could be followed by an assignment which will convert it to |
| 6500 // a setter node. If there is no assignment we will get an error | 6498 // a setter node. If there is no assignment we will get an error |
| 6501 // when we try to invoke the getter. | 6499 // when we try to invoke the getter. |
| 6502 CheckInstanceFieldAccess(ident_pos, ident); | 6500 CheckInstanceFieldAccess(ident_pos, ident); |
| 6503 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); | 6501 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); |
| 6504 *node = CallGetter(ident_pos, LoadReceiver(ident_pos), ident); | 6502 *node = CallGetter(ident_pos, LoadReceiver(ident_pos), ident); |
| 6505 return true; | 6503 return true; |
| (...skipping 1252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7758 } | 7756 } |
| 7759 | 7757 |
| 7760 | 7758 |
| 7761 void Parser::SkipNestedExpr() { | 7759 void Parser::SkipNestedExpr() { |
| 7762 const bool saved_mode = SetAllowFunctionLiterals(true); | 7760 const bool saved_mode = SetAllowFunctionLiterals(true); |
| 7763 SkipExpr(); | 7761 SkipExpr(); |
| 7764 SetAllowFunctionLiterals(saved_mode); | 7762 SetAllowFunctionLiterals(saved_mode); |
| 7765 } | 7763 } |
| 7766 | 7764 |
| 7767 } // namespace dart | 7765 } // namespace dart |
| OLD | NEW |