Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: runtime/vm/parser.cc

Issue 18272027: Add debugging info for 'this' (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/vm/scopes.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 const AbstractType* type) { 441 const AbstractType* type) {
442 this->num_fixed_parameters++; 442 this->num_fixed_parameters++;
443 ParamDesc param; 443 ParamDesc param;
444 param.name_pos = name_pos; 444 param.name_pos = name_pos;
445 param.name = name; 445 param.name = name;
446 param.is_final = true; 446 param.is_final = true;
447 param.type = type; 447 param.type = type;
448 this->parameters->Add(param); 448 this->parameters->Add(param);
449 } 449 }
450 450
451 void AddReceiver(const Type* receiver_type) { 451 void AddReceiver(const Type* receiver_type, intptr_t token_pos) {
452 ASSERT(this->parameters->is_empty()); 452 ASSERT(this->parameters->is_empty());
453 AddFinalParameter(receiver_type->token_pos(), 453 AddFinalParameter(token_pos, &Symbols::This(), receiver_type);
454 &Symbols::This(),
455 receiver_type);
456 } 454 }
457 455
458 void SetImplicitlyFinal() { 456 void SetImplicitlyFinal() {
459 implicitly_final = true; 457 implicitly_final = true;
460 } 458 }
461 459
462 int num_fixed_parameters; 460 int num_fixed_parameters;
463 int num_optional_parameters; 461 int num_optional_parameters;
464 bool has_optional_positional_parameters; 462 bool has_optional_positional_parameters;
465 bool has_optional_named_parameters; 463 bool has_optional_named_parameters;
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
1001 // Create AstNodes for an implicit instance getter method: 999 // Create AstNodes for an implicit instance getter method:
1002 // LoadLocalNode 0 ('this'); 1000 // LoadLocalNode 0 ('this');
1003 // LoadInstanceFieldNode (field_name); 1001 // LoadInstanceFieldNode (field_name);
1004 // ReturnNode (field's value); 1002 // ReturnNode (field's value);
1005 SequenceNode* Parser::ParseInstanceGetter(const Function& func) { 1003 SequenceNode* Parser::ParseInstanceGetter(const Function& func) {
1006 TRACE_PARSER("ParseInstanceGetter"); 1004 TRACE_PARSER("ParseInstanceGetter");
1007 ParamList params; 1005 ParamList params;
1008 // func.token_pos() points to the name of the field. 1006 // func.token_pos() points to the name of the field.
1009 intptr_t ident_pos = func.token_pos(); 1007 intptr_t ident_pos = func.token_pos();
1010 ASSERT(current_class().raw() == func.Owner()); 1008 ASSERT(current_class().raw() == func.Owner());
1011 params.AddReceiver(ReceiverType(ident_pos)); 1009 params.AddReceiver(ReceiverType(ident_pos), ident_pos);
1012 ASSERT(func.num_fixed_parameters() == 1); // receiver. 1010 ASSERT(func.num_fixed_parameters() == 1); // receiver.
1013 ASSERT(!func.HasOptionalParameters()); 1011 ASSERT(!func.HasOptionalParameters());
1014 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); 1012 ASSERT(AbstractType::Handle(func.result_type()).IsResolved());
1015 1013
1016 // Build local scope for function and populate with the formal parameters. 1014 // Build local scope for function and populate with the formal parameters.
1017 OpenFunctionBlock(func); 1015 OpenFunctionBlock(func);
1018 AddFormalParamsToScope(&params, current_block_->scope); 1016 AddFormalParamsToScope(&params, current_block_->scope);
1019 1017
1020 // Receiver is local 0. 1018 // Receiver is local 0.
1021 LocalVariable* receiver = current_block_->scope->VariableAt(0); 1019 LocalVariable* receiver = current_block_->scope->VariableAt(0);
(...skipping 23 matching lines...) Expand all
1045 // func.token_pos() points to the name of the field. 1043 // func.token_pos() points to the name of the field.
1046 intptr_t ident_pos = func.token_pos(); 1044 intptr_t ident_pos = func.token_pos();
1047 const String& field_name = *CurrentLiteral(); 1045 const String& field_name = *CurrentLiteral();
1048 const Class& field_class = Class::ZoneHandle(func.Owner()); 1046 const Class& field_class = Class::ZoneHandle(func.Owner());
1049 const Field& field = 1047 const Field& field =
1050 Field::ZoneHandle(field_class.LookupInstanceField(field_name)); 1048 Field::ZoneHandle(field_class.LookupInstanceField(field_name));
1051 const AbstractType& field_type = AbstractType::ZoneHandle(field.type()); 1049 const AbstractType& field_type = AbstractType::ZoneHandle(field.type());
1052 1050
1053 ParamList params; 1051 ParamList params;
1054 ASSERT(current_class().raw() == func.Owner()); 1052 ASSERT(current_class().raw() == func.Owner());
1055 params.AddReceiver(ReceiverType(ident_pos)); 1053 params.AddReceiver(ReceiverType(ident_pos), ident_pos);
1056 params.AddFinalParameter(ident_pos, 1054 params.AddFinalParameter(ident_pos,
1057 &Symbols::Value(), 1055 &Symbols::Value(),
1058 &field_type); 1056 &field_type);
1059 ASSERT(func.num_fixed_parameters() == 2); // receiver, value. 1057 ASSERT(func.num_fixed_parameters() == 2); // receiver, value.
1060 ASSERT(!func.HasOptionalParameters()); 1058 ASSERT(!func.HasOptionalParameters());
1061 ASSERT(AbstractType::Handle(func.result_type()).IsVoidType()); 1059 ASSERT(AbstractType::Handle(func.result_type()).IsVoidType());
1062 1060
1063 // Build local scope for function and populate with the formal parameters. 1061 // Build local scope for function and populate with the formal parameters.
1064 OpenFunctionBlock(func); 1062 OpenFunctionBlock(func);
1065 AddFormalParamsToScope(&params, current_block_->scope); 1063 AddFormalParamsToScope(&params, current_block_->scope);
(...skipping 12 matching lines...) Expand all
1078 } 1076 }
1079 1077
1080 1078
1081 SequenceNode* Parser::ParseMethodExtractor(const Function& func) { 1079 SequenceNode* Parser::ParseMethodExtractor(const Function& func) {
1082 TRACE_PARSER("ParseMethodExtractor"); 1080 TRACE_PARSER("ParseMethodExtractor");
1083 ParamList params; 1081 ParamList params;
1084 1082
1085 const intptr_t ident_pos = func.token_pos(); 1083 const intptr_t ident_pos = func.token_pos();
1086 ASSERT(func.token_pos() == 0); 1084 ASSERT(func.token_pos() == 0);
1087 ASSERT(current_class().raw() == func.Owner()); 1085 ASSERT(current_class().raw() == func.Owner());
1088 params.AddReceiver(ReceiverType(ident_pos)); 1086 params.AddReceiver(ReceiverType(ident_pos), ident_pos);
1089 ASSERT(func.num_fixed_parameters() == 1); // Receiver. 1087 ASSERT(func.num_fixed_parameters() == 1); // Receiver.
1090 ASSERT(!func.HasOptionalParameters()); 1088 ASSERT(!func.HasOptionalParameters());
1091 1089
1092 // Build local scope for function and populate with the formal parameters. 1090 // Build local scope for function and populate with the formal parameters.
1093 OpenFunctionBlock(func); 1091 OpenFunctionBlock(func);
1094 AddFormalParamsToScope(&params, current_block_->scope); 1092 AddFormalParamsToScope(&params, current_block_->scope);
1095 1093
1096 // Receiver is local 0. 1094 // Receiver is local 0.
1097 LocalVariable* receiver = current_block_->scope->VariableAt(0); 1095 LocalVariable* receiver = current_block_->scope->VariableAt(0);
1098 LoadLocalNode* load_receiver = new LoadLocalNode(ident_pos, receiver); 1096 LoadLocalNode* load_receiver = new LoadLocalNode(ident_pos, receiver);
(...skipping 11 matching lines...) Expand all
1110 1108
1111 1109
1112 SequenceNode* Parser::ParseNoSuchMethodDispatcher(const Function& func) { 1110 SequenceNode* Parser::ParseNoSuchMethodDispatcher(const Function& func) {
1113 TRACE_PARSER("ParseNoSuchMethodDispatcher"); 1111 TRACE_PARSER("ParseNoSuchMethodDispatcher");
1114 ParamList params; 1112 ParamList params;
1115 1113
1116 ASSERT(func.IsNoSuchMethodDispatcher()); 1114 ASSERT(func.IsNoSuchMethodDispatcher());
1117 intptr_t token_pos = func.token_pos(); 1115 intptr_t token_pos = func.token_pos();
1118 ASSERT(func.token_pos() == 0); 1116 ASSERT(func.token_pos() == 0);
1119 ASSERT(current_class().raw() == func.Owner()); 1117 ASSERT(current_class().raw() == func.Owner());
1120 params.AddReceiver(ReceiverType(token_pos)); 1118 params.AddReceiver(ReceiverType(token_pos), token_pos);
1121 ASSERT(func.num_fixed_parameters() == 1); // Receiver. 1119 ASSERT(func.num_fixed_parameters() == 1); // Receiver.
1122 ASSERT(!func.HasOptionalParameters()); 1120 ASSERT(!func.HasOptionalParameters());
1123 1121
1124 // Build local scope for function and populate with the formal parameters. 1122 // Build local scope for function and populate with the formal parameters.
1125 OpenFunctionBlock(func); 1123 OpenFunctionBlock(func);
1126 LocalScope* scope = current_block_->scope; 1124 LocalScope* scope = current_block_->scope;
1127 AddFormalParamsToScope(&params, scope); 1125 AddFormalParamsToScope(&params, scope);
1128 1126
1129 // Receiver is local 0. 1127 // Receiver is local 0.
1130 LocalVariable* receiver = scope->VariableAt(0); 1128 LocalVariable* receiver = scope->VariableAt(0);
(...skipping 1084 matching lines...) Expand 10 before | Expand all | Expand 10 after
2215 } 2213 }
2216 2214
2217 OpenFunctionBlock(func); 2215 OpenFunctionBlock(func);
2218 ParamList params; 2216 ParamList params;
2219 const bool allow_explicit_default_values = true; 2217 const bool allow_explicit_default_values = true;
2220 ASSERT(CurrentToken() == Token::kLPAREN); 2218 ASSERT(CurrentToken() == Token::kLPAREN);
2221 2219
2222 // Add implicit receiver parameter which is passed the allocated 2220 // Add implicit receiver parameter which is passed the allocated
2223 // but uninitialized instance to construct. 2221 // but uninitialized instance to construct.
2224 ASSERT(current_class().raw() == func.Owner()); 2222 ASSERT(current_class().raw() == func.Owner());
2225 params.AddReceiver(ReceiverType(TokenPos())); 2223 params.AddReceiver(ReceiverType(TokenPos()), func.token_pos());
2226 2224
2227 // Add implicit parameter for construction phase. 2225 // Add implicit parameter for construction phase.
2228 params.AddFinalParameter( 2226 params.AddFinalParameter(
2229 TokenPos(), 2227 TokenPos(),
2230 &Symbols::PhaseParameter(), 2228 &Symbols::PhaseParameter(),
2231 &Type::ZoneHandle(Type::SmiType())); 2229 &Type::ZoneHandle(Type::SmiType()));
2232 2230
2233 if (func.is_const()) { 2231 if (func.is_const()) {
2234 params.SetImplicitlyFinal(); 2232 params.SetImplicitlyFinal();
2235 } 2233 }
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
2474 if (func.IsClosureFunction()) { 2472 if (func.IsClosureFunction()) {
2475 // The first parameter of a closure function is the closure object. 2473 // The first parameter of a closure function is the closure object.
2476 ASSERT(!func.is_const()); // Closure functions cannot be const. 2474 ASSERT(!func.is_const()); // Closure functions cannot be const.
2477 params.AddFinalParameter( 2475 params.AddFinalParameter(
2478 TokenPos(), 2476 TokenPos(),
2479 &Symbols::ClosureParameter(), 2477 &Symbols::ClosureParameter(),
2480 &Type::ZoneHandle(Type::DynamicType())); 2478 &Type::ZoneHandle(Type::DynamicType()));
2481 } else if (!func.is_static()) { 2479 } else if (!func.is_static()) {
2482 // Static functions do not have a receiver. 2480 // Static functions do not have a receiver.
2483 ASSERT(current_class().raw() == func.Owner()); 2481 ASSERT(current_class().raw() == func.Owner());
2484 params.AddReceiver(ReceiverType(TokenPos())); 2482 params.AddReceiver(ReceiverType(TokenPos()), func.token_pos());
2485 } else if (func.IsFactory()) { 2483 } else if (func.IsFactory()) {
2486 // The first parameter of a factory is the AbstractTypeArguments vector of 2484 // The first parameter of a factory is the AbstractTypeArguments vector of
2487 // the type of the instance to be allocated. 2485 // the type of the instance to be allocated.
2488 params.AddFinalParameter( 2486 params.AddFinalParameter(
2489 TokenPos(), 2487 TokenPos(),
2490 &Symbols::TypeArgumentsParameter(), 2488 &Symbols::TypeArgumentsParameter(),
2491 &Type::ZoneHandle(Type::DynamicType())); 2489 &Type::ZoneHandle(Type::DynamicType()));
2492 } 2490 }
2493 ASSERT((CurrentToken() == Token::kLPAREN) || func.IsGetterFunction()); 2491 ASSERT((CurrentToken() == Token::kLPAREN) || func.IsGetterFunction());
2494 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
2691 2689
2692 // Parse the formal parameters. 2690 // Parse the formal parameters.
2693 const bool are_implicitly_final = method->has_const; 2691 const bool are_implicitly_final = method->has_const;
2694 const bool allow_explicit_default_values = true; 2692 const bool allow_explicit_default_values = true;
2695 const intptr_t formal_param_pos = TokenPos(); 2693 const intptr_t formal_param_pos = TokenPos();
2696 method->params.Clear(); 2694 method->params.Clear();
2697 // Static functions do not have a receiver. 2695 // Static functions do not have a receiver.
2698 // The first parameter of a factory is the AbstractTypeArguments vector of 2696 // The first parameter of a factory is the AbstractTypeArguments vector of
2699 // the type of the instance to be allocated. 2697 // the type of the instance to be allocated.
2700 if (!method->has_static || method->IsConstructor()) { 2698 if (!method->has_static || method->IsConstructor()) {
2701 method->params.AddReceiver(ReceiverType(formal_param_pos)); 2699 method->params.AddReceiver(ReceiverType(formal_param_pos),
2700 formal_param_pos);
2702 } else if (method->IsFactory()) { 2701 } else if (method->IsFactory()) {
2703 method->params.AddFinalParameter( 2702 method->params.AddFinalParameter(
2704 formal_param_pos, 2703 formal_param_pos,
2705 &Symbols::TypeArgumentsParameter(), 2704 &Symbols::TypeArgumentsParameter(),
2706 &Type::ZoneHandle(Type::DynamicType())); 2705 &Type::ZoneHandle(Type::DynamicType()));
2707 } 2706 }
2708 // Constructors have an implicit parameter for the construction phase. 2707 // Constructors have an implicit parameter for the construction phase.
2709 if (method->IsConstructor()) { 2708 if (method->IsConstructor()) {
2710 method->params.AddFinalParameter( 2709 method->params.AddFinalParameter(
2711 TokenPos(), 2710 TokenPos(),
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
3042 String& getter_name = String::Handle(Field::GetterSymbol(*field->name)); 3041 String& getter_name = String::Handle(Field::GetterSymbol(*field->name));
3043 getter = Function::New(getter_name, RawFunction::kImplicitGetter, 3042 getter = Function::New(getter_name, RawFunction::kImplicitGetter,
3044 field->has_static, 3043 field->has_static,
3045 field->has_final, 3044 field->has_final,
3046 /* is_abstract = */ false, 3045 /* is_abstract = */ false,
3047 /* is_external = */ false, 3046 /* is_external = */ false,
3048 current_class(), 3047 current_class(),
3049 field->name_pos); 3048 field->name_pos);
3050 ParamList params; 3049 ParamList params;
3051 ASSERT(current_class().raw() == getter.Owner()); 3050 ASSERT(current_class().raw() == getter.Owner());
3052 params.AddReceiver(ReceiverType(TokenPos())); 3051 params.AddReceiver(ReceiverType(TokenPos()), field->name_pos);
3053 getter.set_result_type(*field->type); 3052 getter.set_result_type(*field->type);
3054 AddFormalParamsToFunction(&params, getter); 3053 AddFormalParamsToFunction(&params, getter);
3055 members->AddFunction(getter); 3054 members->AddFunction(getter);
3056 if (!field->has_final) { 3055 if (!field->has_final) {
3057 // Build a setter accessor for non-const fields. 3056 // Build a setter accessor for non-const fields.
3058 String& setter_name = String::Handle(Field::SetterSymbol(*field->name)); 3057 String& setter_name = String::Handle(Field::SetterSymbol(*field->name));
3059 setter = Function::New(setter_name, RawFunction::kImplicitSetter, 3058 setter = Function::New(setter_name, RawFunction::kImplicitSetter,
3060 field->has_static, 3059 field->has_static,
3061 field->has_final, 3060 field->has_final,
3062 /* is_abstract = */ false, 3061 /* is_abstract = */ false,
3063 /* is_external = */ false, 3062 /* is_external = */ false,
3064 current_class(), 3063 current_class(),
3065 field->name_pos); 3064 field->name_pos);
3066 ParamList params; 3065 ParamList params;
3067 ASSERT(current_class().raw() == setter.Owner()); 3066 ASSERT(current_class().raw() == setter.Owner());
3068 params.AddReceiver(ReceiverType(TokenPos())); 3067 params.AddReceiver(ReceiverType(TokenPos()), field->name_pos);
3069 params.AddFinalParameter(TokenPos(), 3068 params.AddFinalParameter(TokenPos(),
3070 &Symbols::Value(), 3069 &Symbols::Value(),
3071 field->type); 3070 field->type);
3072 setter.set_result_type(Type::Handle(Type::VoidType())); 3071 setter.set_result_type(Type::Handle(Type::VoidType()));
3073 AddFormalParamsToFunction(&params, setter); 3072 AddFormalParamsToFunction(&params, setter);
3074 members->AddFunction(setter); 3073 members->AddFunction(setter);
3075 } 3074 }
3076 } 3075 }
3077 3076
3078 if (CurrentToken() != Token::kCOMMA) { 3077 if (CurrentToken() != Token::kCOMMA) {
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
3545 /* is_static = */ false, 3544 /* is_static = */ false,
3546 /* is_const = */ false, 3545 /* is_const = */ false,
3547 /* is_abstract = */ false, 3546 /* is_abstract = */ false,
3548 /* is_external = */ false, 3547 /* is_external = */ false,
3549 cls, 3548 cls,
3550 cls.token_pos())); 3549 cls.token_pos()));
3551 ParamList params; 3550 ParamList params;
3552 // Add implicit 'this' parameter. We don't care about the specific type 3551 // Add implicit 'this' parameter. We don't care about the specific type
3553 // and just specify dynamic. 3552 // and just specify dynamic.
3554 const Type& receiver_type = Type::Handle(Type::DynamicType()); 3553 const Type& receiver_type = Type::Handle(Type::DynamicType());
3555 params.AddReceiver(&receiver_type); 3554 params.AddReceiver(&receiver_type, cls.token_pos());
3556 // Add implicit parameter for construction phase. 3555 // Add implicit parameter for construction phase.
3557 params.AddFinalParameter(cls.token_pos(), 3556 params.AddFinalParameter(cls.token_pos(),
3558 &Symbols::PhaseParameter(), 3557 &Symbols::PhaseParameter(),
3559 &Type::ZoneHandle(Type::SmiType())); 3558 &Type::ZoneHandle(Type::SmiType()));
3560 3559
3561 AddFormalParamsToFunction(&params, ctor); 3560 AddFormalParamsToFunction(&params, ctor);
3562 // The body of the constructor cannot modify the type of the constructed 3561 // The body of the constructor cannot modify the type of the constructed
3563 // instance, which is passed in as the receiver. 3562 // instance, which is passed in as the receiver.
3564 ctor.set_result_type(receiver_type); 3563 ctor.set_result_type(receiver_type);
3565 cls.AddFunction(ctor); 3564 cls.AddFunction(ctor);
(...skipping 6412 matching lines...) Expand 10 before | Expand all | Expand 10 after
9978 void Parser::SkipQualIdent() { 9977 void Parser::SkipQualIdent() {
9979 ASSERT(IsIdentifier()); 9978 ASSERT(IsIdentifier());
9980 ConsumeToken(); 9979 ConsumeToken();
9981 if (CurrentToken() == Token::kPERIOD) { 9980 if (CurrentToken() == Token::kPERIOD) {
9982 ConsumeToken(); // Consume the kPERIOD token. 9981 ConsumeToken(); // Consume the kPERIOD token.
9983 ExpectIdentifier("identifier expected after '.'"); 9982 ExpectIdentifier("identifier expected after '.'");
9984 } 9983 }
9985 } 9984 }
9986 9985
9987 } // namespace dart 9986 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698