| 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 "lib/invocation_mirror.h" | 7 #include "lib/invocation_mirror.h" |
| 8 #include "vm/bigint_operations.h" | 8 #include "vm/bigint_operations.h" |
| 9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
| 10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
| (...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 999 // Create AstNodes for an implicit instance getter method: | 999 // Create AstNodes for an implicit instance getter method: |
| 1000 // LoadLocalNode 0 ('this'); | 1000 // LoadLocalNode 0 ('this'); |
| 1001 // LoadInstanceFieldNode (field_name); | 1001 // LoadInstanceFieldNode (field_name); |
| 1002 // ReturnNode (field's value); | 1002 // ReturnNode (field's value); |
| 1003 SequenceNode* Parser::ParseInstanceGetter(const Function& func) { | 1003 SequenceNode* Parser::ParseInstanceGetter(const Function& func) { |
| 1004 TRACE_PARSER("ParseInstanceGetter"); | 1004 TRACE_PARSER("ParseInstanceGetter"); |
| 1005 ParamList params; | 1005 ParamList params; |
| 1006 // func.token_pos() points to the name of the field. | 1006 // func.token_pos() points to the name of the field. |
| 1007 intptr_t ident_pos = func.token_pos(); | 1007 intptr_t ident_pos = func.token_pos(); |
| 1008 ASSERT(current_class().raw() == func.Owner()); | 1008 ASSERT(current_class().raw() == func.Owner()); |
| 1009 params.AddReceiver(ReceiverType(ident_pos), ident_pos); | 1009 params.AddReceiver(ReceiverType(), ident_pos); |
| 1010 ASSERT(func.num_fixed_parameters() == 1); // receiver. | 1010 ASSERT(func.num_fixed_parameters() == 1); // receiver. |
| 1011 ASSERT(!func.HasOptionalParameters()); | 1011 ASSERT(!func.HasOptionalParameters()); |
| 1012 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); | 1012 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); |
| 1013 | 1013 |
| 1014 // Build local scope for function and populate with the formal parameters. | 1014 // Build local scope for function and populate with the formal parameters. |
| 1015 OpenFunctionBlock(func); | 1015 OpenFunctionBlock(func); |
| 1016 AddFormalParamsToScope(¶ms, current_block_->scope); | 1016 AddFormalParamsToScope(¶ms, current_block_->scope); |
| 1017 | 1017 |
| 1018 // Receiver is local 0. | 1018 // Receiver is local 0. |
| 1019 LocalVariable* receiver = current_block_->scope->VariableAt(0); | 1019 LocalVariable* receiver = current_block_->scope->VariableAt(0); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1043 // func.token_pos() points to the name of the field. | 1043 // func.token_pos() points to the name of the field. |
| 1044 intptr_t ident_pos = func.token_pos(); | 1044 intptr_t ident_pos = func.token_pos(); |
| 1045 const String& field_name = *CurrentLiteral(); | 1045 const String& field_name = *CurrentLiteral(); |
| 1046 const Class& field_class = Class::ZoneHandle(func.Owner()); | 1046 const Class& field_class = Class::ZoneHandle(func.Owner()); |
| 1047 const Field& field = | 1047 const Field& field = |
| 1048 Field::ZoneHandle(field_class.LookupInstanceField(field_name)); | 1048 Field::ZoneHandle(field_class.LookupInstanceField(field_name)); |
| 1049 const AbstractType& field_type = AbstractType::ZoneHandle(field.type()); | 1049 const AbstractType& field_type = AbstractType::ZoneHandle(field.type()); |
| 1050 | 1050 |
| 1051 ParamList params; | 1051 ParamList params; |
| 1052 ASSERT(current_class().raw() == func.Owner()); | 1052 ASSERT(current_class().raw() == func.Owner()); |
| 1053 params.AddReceiver(ReceiverType(ident_pos), ident_pos); | 1053 params.AddReceiver(ReceiverType(), ident_pos); |
| 1054 params.AddFinalParameter(ident_pos, | 1054 params.AddFinalParameter(ident_pos, |
| 1055 &Symbols::Value(), | 1055 &Symbols::Value(), |
| 1056 &field_type); | 1056 &field_type); |
| 1057 ASSERT(func.num_fixed_parameters() == 2); // receiver, value. | 1057 ASSERT(func.num_fixed_parameters() == 2); // receiver, value. |
| 1058 ASSERT(!func.HasOptionalParameters()); | 1058 ASSERT(!func.HasOptionalParameters()); |
| 1059 ASSERT(AbstractType::Handle(func.result_type()).IsVoidType()); | 1059 ASSERT(AbstractType::Handle(func.result_type()).IsVoidType()); |
| 1060 | 1060 |
| 1061 // Build local scope for function and populate with the formal parameters. | 1061 // Build local scope for function and populate with the formal parameters. |
| 1062 OpenFunctionBlock(func); | 1062 OpenFunctionBlock(func); |
| 1063 AddFormalParamsToScope(¶ms, current_block_->scope); | 1063 AddFormalParamsToScope(¶ms, current_block_->scope); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1076 } | 1076 } |
| 1077 | 1077 |
| 1078 | 1078 |
| 1079 SequenceNode* Parser::ParseMethodExtractor(const Function& func) { | 1079 SequenceNode* Parser::ParseMethodExtractor(const Function& func) { |
| 1080 TRACE_PARSER("ParseMethodExtractor"); | 1080 TRACE_PARSER("ParseMethodExtractor"); |
| 1081 ParamList params; | 1081 ParamList params; |
| 1082 | 1082 |
| 1083 const intptr_t ident_pos = func.token_pos(); | 1083 const intptr_t ident_pos = func.token_pos(); |
| 1084 ASSERT(func.token_pos() == 0); | 1084 ASSERT(func.token_pos() == 0); |
| 1085 ASSERT(current_class().raw() == func.Owner()); | 1085 ASSERT(current_class().raw() == func.Owner()); |
| 1086 params.AddReceiver(ReceiverType(ident_pos), ident_pos); | 1086 params.AddReceiver(ReceiverType(), ident_pos); |
| 1087 ASSERT(func.num_fixed_parameters() == 1); // Receiver. | 1087 ASSERT(func.num_fixed_parameters() == 1); // Receiver. |
| 1088 ASSERT(!func.HasOptionalParameters()); | 1088 ASSERT(!func.HasOptionalParameters()); |
| 1089 | 1089 |
| 1090 // Build local scope for function and populate with the formal parameters. | 1090 // Build local scope for function and populate with the formal parameters. |
| 1091 OpenFunctionBlock(func); | 1091 OpenFunctionBlock(func); |
| 1092 AddFormalParamsToScope(¶ms, current_block_->scope); | 1092 AddFormalParamsToScope(¶ms, current_block_->scope); |
| 1093 | 1093 |
| 1094 // Receiver is local 0. | 1094 // Receiver is local 0. |
| 1095 LocalVariable* receiver = current_block_->scope->VariableAt(0); | 1095 LocalVariable* receiver = current_block_->scope->VariableAt(0); |
| 1096 LoadLocalNode* load_receiver = new LoadLocalNode(ident_pos, receiver); | 1096 LoadLocalNode* load_receiver = new LoadLocalNode(ident_pos, receiver); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1108 | 1108 |
| 1109 | 1109 |
| 1110 SequenceNode* Parser::ParseNoSuchMethodDispatcher(const Function& func) { | 1110 SequenceNode* Parser::ParseNoSuchMethodDispatcher(const Function& func) { |
| 1111 TRACE_PARSER("ParseNoSuchMethodDispatcher"); | 1111 TRACE_PARSER("ParseNoSuchMethodDispatcher"); |
| 1112 ParamList params; | 1112 ParamList params; |
| 1113 | 1113 |
| 1114 ASSERT(func.IsNoSuchMethodDispatcher()); | 1114 ASSERT(func.IsNoSuchMethodDispatcher()); |
| 1115 intptr_t token_pos = func.token_pos(); | 1115 intptr_t token_pos = func.token_pos(); |
| 1116 ASSERT(func.token_pos() == 0); | 1116 ASSERT(func.token_pos() == 0); |
| 1117 ASSERT(current_class().raw() == func.Owner()); | 1117 ASSERT(current_class().raw() == func.Owner()); |
| 1118 params.AddReceiver(ReceiverType(token_pos), token_pos); | 1118 params.AddReceiver(ReceiverType(), token_pos); |
| 1119 ASSERT(func.num_fixed_parameters() == 1); // Receiver. | 1119 ASSERT(func.num_fixed_parameters() == 1); // Receiver. |
| 1120 ASSERT(!func.HasOptionalParameters()); | 1120 ASSERT(!func.HasOptionalParameters()); |
| 1121 | 1121 |
| 1122 // Build local scope for function and populate with the formal parameters. | 1122 // Build local scope for function and populate with the formal parameters. |
| 1123 OpenFunctionBlock(func); | 1123 OpenFunctionBlock(func); |
| 1124 LocalScope* scope = current_block_->scope; | 1124 LocalScope* scope = current_block_->scope; |
| 1125 AddFormalParamsToScope(¶ms, scope); | 1125 AddFormalParamsToScope(¶ms, scope); |
| 1126 | 1126 |
| 1127 // Receiver is local 0. | 1127 // Receiver is local 0. |
| 1128 LocalVariable* receiver = scope->VariableAt(0); | 1128 LocalVariable* receiver = scope->VariableAt(0); |
| (...skipping 1084 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2213 } | 2213 } |
| 2214 | 2214 |
| 2215 OpenFunctionBlock(func); | 2215 OpenFunctionBlock(func); |
| 2216 ParamList params; | 2216 ParamList params; |
| 2217 const bool allow_explicit_default_values = true; | 2217 const bool allow_explicit_default_values = true; |
| 2218 ASSERT(CurrentToken() == Token::kLPAREN); | 2218 ASSERT(CurrentToken() == Token::kLPAREN); |
| 2219 | 2219 |
| 2220 // Add implicit receiver parameter which is passed the allocated | 2220 // Add implicit receiver parameter which is passed the allocated |
| 2221 // but uninitialized instance to construct. | 2221 // but uninitialized instance to construct. |
| 2222 ASSERT(current_class().raw() == func.Owner()); | 2222 ASSERT(current_class().raw() == func.Owner()); |
| 2223 params.AddReceiver(ReceiverType(TokenPos()), func.token_pos()); | 2223 params.AddReceiver(ReceiverType(), func.token_pos()); |
| 2224 | 2224 |
| 2225 // Add implicit parameter for construction phase. | 2225 // Add implicit parameter for construction phase. |
| 2226 params.AddFinalParameter( | 2226 params.AddFinalParameter( |
| 2227 TokenPos(), | 2227 TokenPos(), |
| 2228 &Symbols::PhaseParameter(), | 2228 &Symbols::PhaseParameter(), |
| 2229 &Type::ZoneHandle(Type::SmiType())); | 2229 &Type::ZoneHandle(Type::SmiType())); |
| 2230 | 2230 |
| 2231 if (func.is_const()) { | 2231 if (func.is_const()) { |
| 2232 params.SetImplicitlyFinal(); | 2232 params.SetImplicitlyFinal(); |
| 2233 } | 2233 } |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2472 if (func.IsClosureFunction()) { | 2472 if (func.IsClosureFunction()) { |
| 2473 // The first parameter of a closure function is the closure object. | 2473 // The first parameter of a closure function is the closure object. |
| 2474 ASSERT(!func.is_const()); // Closure functions cannot be const. | 2474 ASSERT(!func.is_const()); // Closure functions cannot be const. |
| 2475 params.AddFinalParameter( | 2475 params.AddFinalParameter( |
| 2476 TokenPos(), | 2476 TokenPos(), |
| 2477 &Symbols::ClosureParameter(), | 2477 &Symbols::ClosureParameter(), |
| 2478 &Type::ZoneHandle(Type::DynamicType())); | 2478 &Type::ZoneHandle(Type::DynamicType())); |
| 2479 } else if (!func.is_static()) { | 2479 } else if (!func.is_static()) { |
| 2480 // Static functions do not have a receiver. | 2480 // Static functions do not have a receiver. |
| 2481 ASSERT(current_class().raw() == func.Owner()); | 2481 ASSERT(current_class().raw() == func.Owner()); |
| 2482 params.AddReceiver(ReceiverType(TokenPos()), func.token_pos()); | 2482 params.AddReceiver(ReceiverType(), func.token_pos()); |
| 2483 } else if (func.IsFactory()) { | 2483 } else if (func.IsFactory()) { |
| 2484 // The first parameter of a factory is the AbstractTypeArguments vector of | 2484 // The first parameter of a factory is the AbstractTypeArguments vector of |
| 2485 // the type of the instance to be allocated. | 2485 // the type of the instance to be allocated. |
| 2486 params.AddFinalParameter( | 2486 params.AddFinalParameter( |
| 2487 TokenPos(), | 2487 TokenPos(), |
| 2488 &Symbols::TypeArgumentsParameter(), | 2488 &Symbols::TypeArgumentsParameter(), |
| 2489 &Type::ZoneHandle(Type::DynamicType())); | 2489 &Type::ZoneHandle(Type::DynamicType())); |
| 2490 } | 2490 } |
| 2491 ASSERT((CurrentToken() == Token::kLPAREN) || func.IsGetterFunction()); | 2491 ASSERT((CurrentToken() == Token::kLPAREN) || func.IsGetterFunction()); |
| 2492 const bool allow_explicit_default_values = true; | 2492 const bool allow_explicit_default_values = true; |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2689 | 2689 |
| 2690 // Parse the formal parameters. | 2690 // Parse the formal parameters. |
| 2691 const bool are_implicitly_final = method->has_const; | 2691 const bool are_implicitly_final = method->has_const; |
| 2692 const bool allow_explicit_default_values = true; | 2692 const bool allow_explicit_default_values = true; |
| 2693 const intptr_t formal_param_pos = TokenPos(); | 2693 const intptr_t formal_param_pos = TokenPos(); |
| 2694 method->params.Clear(); | 2694 method->params.Clear(); |
| 2695 // Static functions do not have a receiver. | 2695 // Static functions do not have a receiver. |
| 2696 // The first parameter of a factory is the AbstractTypeArguments vector of | 2696 // The first parameter of a factory is the AbstractTypeArguments vector of |
| 2697 // the type of the instance to be allocated. | 2697 // the type of the instance to be allocated. |
| 2698 if (!method->has_static || method->IsConstructor()) { | 2698 if (!method->has_static || method->IsConstructor()) { |
| 2699 method->params.AddReceiver(ReceiverType(formal_param_pos), | 2699 method->params.AddReceiver(ReceiverType(), formal_param_pos); |
| 2700 formal_param_pos); | |
| 2701 } else if (method->IsFactory()) { | 2700 } else if (method->IsFactory()) { |
| 2702 method->params.AddFinalParameter( | 2701 method->params.AddFinalParameter( |
| 2703 formal_param_pos, | 2702 formal_param_pos, |
| 2704 &Symbols::TypeArgumentsParameter(), | 2703 &Symbols::TypeArgumentsParameter(), |
| 2705 &Type::ZoneHandle(Type::DynamicType())); | 2704 &Type::ZoneHandle(Type::DynamicType())); |
| 2706 } | 2705 } |
| 2707 // Constructors have an implicit parameter for the construction phase. | 2706 // Constructors have an implicit parameter for the construction phase. |
| 2708 if (method->IsConstructor()) { | 2707 if (method->IsConstructor()) { |
| 2709 method->params.AddFinalParameter( | 2708 method->params.AddFinalParameter( |
| 2710 TokenPos(), | 2709 TokenPos(), |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3041 String& getter_name = String::Handle(Field::GetterSymbol(*field->name)); | 3040 String& getter_name = String::Handle(Field::GetterSymbol(*field->name)); |
| 3042 getter = Function::New(getter_name, RawFunction::kImplicitGetter, | 3041 getter = Function::New(getter_name, RawFunction::kImplicitGetter, |
| 3043 field->has_static, | 3042 field->has_static, |
| 3044 field->has_final, | 3043 field->has_final, |
| 3045 /* is_abstract = */ false, | 3044 /* is_abstract = */ false, |
| 3046 /* is_external = */ false, | 3045 /* is_external = */ false, |
| 3047 current_class(), | 3046 current_class(), |
| 3048 field->name_pos); | 3047 field->name_pos); |
| 3049 ParamList params; | 3048 ParamList params; |
| 3050 ASSERT(current_class().raw() == getter.Owner()); | 3049 ASSERT(current_class().raw() == getter.Owner()); |
| 3051 params.AddReceiver(ReceiverType(TokenPos()), field->name_pos); | 3050 params.AddReceiver(ReceiverType(), field->name_pos); |
| 3052 getter.set_result_type(*field->type); | 3051 getter.set_result_type(*field->type); |
| 3053 AddFormalParamsToFunction(¶ms, getter); | 3052 AddFormalParamsToFunction(¶ms, getter); |
| 3054 members->AddFunction(getter); | 3053 members->AddFunction(getter); |
| 3055 if (!field->has_final) { | 3054 if (!field->has_final) { |
| 3056 // Build a setter accessor for non-const fields. | 3055 // Build a setter accessor for non-const fields. |
| 3057 String& setter_name = String::Handle(Field::SetterSymbol(*field->name)); | 3056 String& setter_name = String::Handle(Field::SetterSymbol(*field->name)); |
| 3058 setter = Function::New(setter_name, RawFunction::kImplicitSetter, | 3057 setter = Function::New(setter_name, RawFunction::kImplicitSetter, |
| 3059 field->has_static, | 3058 field->has_static, |
| 3060 field->has_final, | 3059 field->has_final, |
| 3061 /* is_abstract = */ false, | 3060 /* is_abstract = */ false, |
| 3062 /* is_external = */ false, | 3061 /* is_external = */ false, |
| 3063 current_class(), | 3062 current_class(), |
| 3064 field->name_pos); | 3063 field->name_pos); |
| 3065 ParamList params; | 3064 ParamList params; |
| 3066 ASSERT(current_class().raw() == setter.Owner()); | 3065 ASSERT(current_class().raw() == setter.Owner()); |
| 3067 params.AddReceiver(ReceiverType(TokenPos()), field->name_pos); | 3066 params.AddReceiver(ReceiverType(), field->name_pos); |
| 3068 params.AddFinalParameter(TokenPos(), | 3067 params.AddFinalParameter(TokenPos(), |
| 3069 &Symbols::Value(), | 3068 &Symbols::Value(), |
| 3070 field->type); | 3069 field->type); |
| 3071 setter.set_result_type(Type::Handle(Type::VoidType())); | 3070 setter.set_result_type(Type::Handle(Type::VoidType())); |
| 3072 AddFormalParamsToFunction(¶ms, setter); | 3071 AddFormalParamsToFunction(¶ms, setter); |
| 3073 members->AddFunction(setter); | 3072 members->AddFunction(setter); |
| 3074 } | 3073 } |
| 3075 } | 3074 } |
| 3076 | 3075 |
| 3077 if (CurrentToken() != Token::kCOMMA) { | 3076 if (CurrentToken() != Token::kCOMMA) { |
| (...skipping 4987 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8065 if (is_top_level_) { | 8064 if (is_top_level_) { |
| 8066 return (current_member_ != NULL) && | 8065 return (current_member_ != NULL) && |
| 8067 current_member_->has_static && !current_member_->has_factory; | 8066 current_member_->has_static && !current_member_->has_factory; |
| 8068 } | 8067 } |
| 8069 ASSERT(!current_function().IsNull()); | 8068 ASSERT(!current_function().IsNull()); |
| 8070 return | 8069 return |
| 8071 current_function().is_static() && !current_function().IsInFactoryScope(); | 8070 current_function().is_static() && !current_function().IsInFactoryScope(); |
| 8072 } | 8071 } |
| 8073 | 8072 |
| 8074 | 8073 |
| 8075 const Type* Parser::ReceiverType(intptr_t type_pos) const { | 8074 const Type* Parser::ReceiverType() const { |
| 8076 ASSERT(!current_class().IsNull()); | 8075 ASSERT(!current_class().IsNull()); |
| 8077 TypeArguments& type_arguments = TypeArguments::Handle(); | 8076 TypeArguments& type_arguments = TypeArguments::Handle(); |
| 8078 if (current_class().NumTypeParameters() > 0) { | 8077 if (current_class().NumTypeParameters() > 0) { |
| 8079 type_arguments = current_class().type_parameters(); | 8078 type_arguments = current_class().type_parameters(); |
| 8080 } | 8079 } |
| 8081 Type& type = Type::ZoneHandle( | 8080 Type& type = Type::ZoneHandle( |
| 8082 Type::New(current_class(), type_arguments, type_pos)); | 8081 Type::New(current_class(), type_arguments, current_class().token_pos())); |
| 8083 if (!is_top_level_ || current_class().is_type_finalized()) { | 8082 if (!is_top_level_ || current_class().is_type_finalized()) { |
| 8084 type ^= ClassFinalizer::FinalizeType( | 8083 type ^= ClassFinalizer::FinalizeType( |
| 8085 current_class(), type, ClassFinalizer::kCanonicalizeWellFormed); | 8084 current_class(), type, ClassFinalizer::kCanonicalizeWellFormed); |
| 8086 } | 8085 } |
| 8087 return &type; | 8086 return &type; |
| 8088 } | 8087 } |
| 8089 | 8088 |
| 8090 | 8089 |
| 8091 bool Parser::IsInstantiatorRequired() const { | 8090 bool Parser::IsInstantiatorRequired() const { |
| 8092 ASSERT(!current_function().IsNull()); | 8091 ASSERT(!current_function().IsNull()); |
| (...skipping 1884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9977 void Parser::SkipQualIdent() { | 9976 void Parser::SkipQualIdent() { |
| 9978 ASSERT(IsIdentifier()); | 9977 ASSERT(IsIdentifier()); |
| 9979 ConsumeToken(); | 9978 ConsumeToken(); |
| 9980 if (CurrentToken() == Token::kPERIOD) { | 9979 if (CurrentToken() == Token::kPERIOD) { |
| 9981 ConsumeToken(); // Consume the kPERIOD token. | 9980 ConsumeToken(); // Consume the kPERIOD token. |
| 9982 ExpectIdentifier("identifier expected after '.'"); | 9981 ExpectIdentifier("identifier expected after '.'"); |
| 9983 } | 9982 } |
| 9984 } | 9983 } |
| 9985 | 9984 |
| 9986 } // namespace dart | 9985 } // namespace dart |
| OLD | NEW |