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

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

Issue 10796004: Consolidate a few fields in RawFunction using bitfields. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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
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 "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 1063 matching lines...) Expand 10 before | Expand all | Expand 10 after
1074 ParamList func_params; 1074 ParamList func_params;
1075 const bool no_explicit_default_values = false; 1075 const bool no_explicit_default_values = false;
1076 ParseFormalParameterList(no_explicit_default_values, &func_params); 1076 ParseFormalParameterList(no_explicit_default_values, &func_params);
1077 1077
1078 // The field 'is_static' has no meaning for signature functions. 1078 // The field 'is_static' has no meaning for signature functions.
1079 const Function& signature_function = Function::Handle( 1079 const Function& signature_function = Function::Handle(
1080 Function::New(*parameter.name, 1080 Function::New(*parameter.name,
1081 RawFunction::kSignatureFunction, 1081 RawFunction::kSignatureFunction,
1082 /* is_static = */ false, 1082 /* is_static = */ false,
1083 /* is_const = */ false, 1083 /* is_const = */ false,
1084 /* is_abstract = */ false,
1084 parameter.name_pos)); 1085 parameter.name_pos));
1085 signature_function.set_owner(current_class()); 1086 signature_function.set_owner(current_class());
1086 signature_function.set_result_type(result_type); 1087 signature_function.set_result_type(result_type);
1087 AddFormalParamsToFunction(&func_params, signature_function); 1088 AddFormalParamsToFunction(&func_params, signature_function);
1088 const String& signature = String::Handle(signature_function.Signature()); 1089 const String& signature = String::Handle(signature_function.Signature());
1089 // Lookup the signature class, i.e. the class whose name is the signature. 1090 // Lookup the signature class, i.e. the class whose name is the signature.
1090 // We only lookup in the current library, but not in its imports, and only 1091 // We only lookup in the current library, but not in its imports, and only
1091 // create a new canonical signature class if it does not exist yet. 1092 // create a new canonical signature class if it does not exist yet.
1092 Class& signature_class = Class::ZoneHandle( 1093 Class& signature_class = Class::ZoneHandle(
1093 library_.LookupLocalClass(signature)); 1094 library_.LookupLocalClass(signature));
(...skipping 1361 matching lines...) Expand 10 before | Expand all | Expand 10 after
2455 } else { 2456 } else {
2456 ErrorMsg(method->name_pos, 2457 ErrorMsg(method->name_pos,
2457 "function body expected for method '%s'", 2458 "function body expected for method '%s'",
2458 method->name->ToCString()); 2459 method->name->ToCString());
2459 } 2460 }
2460 } 2461 }
2461 2462
2462 RawFunction::Kind function_kind; 2463 RawFunction::Kind function_kind;
2463 if (method->IsFactoryOrConstructor()) { 2464 if (method->IsFactoryOrConstructor()) {
2464 function_kind = RawFunction::kConstructor; 2465 function_kind = RawFunction::kConstructor;
2465 } else if (method->has_abstract) {
2466 function_kind = RawFunction::kAbstract;
2467 } else if (method->IsGetter()) { 2466 } else if (method->IsGetter()) {
2468 function_kind = RawFunction::kGetterFunction; 2467 function_kind = RawFunction::kGetterFunction;
2469 } else if (method->IsSetter()) { 2468 } else if (method->IsSetter()) {
2470 function_kind = RawFunction::kSetterFunction; 2469 function_kind = RawFunction::kSetterFunction;
2471 } else { 2470 } else {
2472 function_kind = RawFunction::kFunction; 2471 function_kind = RawFunction::kFunction;
2473 } 2472 }
2474 Function& func = Function::Handle( 2473 Function& func = Function::Handle(
2475 Function::New(*method->name, 2474 Function::New(*method->name,
2476 function_kind, 2475 function_kind,
2477 method->has_static, 2476 method->has_static,
2478 method->has_const, 2477 method->has_const,
2478 method->has_abstract,
2479 method_pos)); 2479 method_pos));
2480 func.set_result_type(*method->type); 2480 func.set_result_type(*method->type);
2481 func.set_end_token_pos(method_end_pos); 2481 func.set_end_token_pos(method_end_pos);
2482 2482
2483 // No need to resolve parameter types yet, or add parameters to local scope. 2483 // No need to resolve parameter types yet, or add parameters to local scope.
2484 ASSERT(is_top_level_); 2484 ASSERT(is_top_level_);
2485 AddFormalParamsToFunction(&method->params, func); 2485 AddFormalParamsToFunction(&method->params, func);
2486 members->AddFunction(func); 2486 members->AddFunction(func);
2487 } 2487 }
2488 2488
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2541 class_field.set_has_initializer(has_initializer); 2541 class_field.set_has_initializer(has_initializer);
2542 members->AddField(class_field); 2542 members->AddField(class_field);
2543 2543
2544 // For static final fields, set value to "uninitialized" and 2544 // For static final fields, set value to "uninitialized" and
2545 // create a kConstImplicitGetter getter method. 2545 // create a kConstImplicitGetter getter method.
2546 if (field->has_static && has_initializer) { 2546 if (field->has_static && has_initializer) {
2547 class_field.set_value(Instance::Handle(Object::sentinel())); 2547 class_field.set_value(Instance::Handle(Object::sentinel()));
2548 String& getter_name = String::Handle(Field::GetterSymbol(*field->name)); 2548 String& getter_name = String::Handle(Field::GetterSymbol(*field->name));
2549 getter = Function::New(getter_name, RawFunction::kConstImplicitGetter, 2549 getter = Function::New(getter_name, RawFunction::kConstImplicitGetter,
2550 field->has_static, field->has_final, 2550 field->has_static, field->has_final,
2551 /* is_abstract */ false,
2551 field->name_pos); 2552 field->name_pos);
2552 getter.set_result_type(*field->type); 2553 getter.set_result_type(*field->type);
2553 members->AddFunction(getter); 2554 members->AddFunction(getter);
2554 } 2555 }
2555 2556
2556 // For instance fields, we create implicit getter and setter methods. 2557 // For instance fields, we create implicit getter and setter methods.
2557 if (!field->has_static) { 2558 if (!field->has_static) {
2558 String& getter_name = String::Handle(Field::GetterSymbol(*field->name)); 2559 String& getter_name = String::Handle(Field::GetterSymbol(*field->name));
2559 getter = Function::New(getter_name, RawFunction::kImplicitGetter, 2560 getter = Function::New(getter_name, RawFunction::kImplicitGetter,
2560 field->has_static, field->has_final, 2561 field->has_static, field->has_final,
2562 /* is_abstract */ false,
2561 field->name_pos); 2563 field->name_pos);
2562 ParamList params; 2564 ParamList params;
2563 params.AddReceiver(TokenPos()); 2565 params.AddReceiver(TokenPos());
2564 getter.set_result_type(*field->type); 2566 getter.set_result_type(*field->type);
2565 AddFormalParamsToFunction(&params, getter); 2567 AddFormalParamsToFunction(&params, getter);
2566 members->AddFunction(getter); 2568 members->AddFunction(getter);
2567 if (!field->has_final) { 2569 if (!field->has_final) {
2568 // Build a setter accessor for non-const fields. 2570 // Build a setter accessor for non-const fields.
2569 String& setter_name = String::Handle(Field::SetterSymbol(*field->name)); 2571 String& setter_name = String::Handle(Field::SetterSymbol(*field->name));
2570 setter = Function::New(setter_name, RawFunction::kImplicitSetter, 2572 setter = Function::New(setter_name, RawFunction::kImplicitSetter,
2571 field->has_static, field->has_final, 2573 field->has_static, field->has_final,
2574 /* is_abstract */ false,
2572 field->name_pos); 2575 field->name_pos);
2573 ParamList params; 2576 ParamList params;
2574 params.AddReceiver(TokenPos()); 2577 params.AddReceiver(TokenPos());
2575 params.AddFinalParameter(TokenPos(), "value", field->type); 2578 params.AddFinalParameter(TokenPos(), "value", field->type);
2576 setter.set_result_type(Type::Handle(Type::VoidType())); 2579 setter.set_result_type(Type::Handle(Type::VoidType()));
2577 AddFormalParamsToFunction(&params, setter); 2580 AddFormalParamsToFunction(&params, setter);
2578 members->AddFunction(setter); 2581 members->AddFunction(setter);
2579 } 2582 }
2580 } 2583 }
2581 2584
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
2929 String::Concat(class_desc->class_name(), 2932 String::Concat(class_desc->class_name(),
2930 String::Handle(String::NewSymbol(".")))); 2933 String::Handle(String::NewSymbol("."))));
2931 ctor_name = String::NewSymbol(ctor_name); 2934 ctor_name = String::NewSymbol(ctor_name);
2932 // The token position for the implicit constructor is the 'class' 2935 // The token position for the implicit constructor is the 'class'
2933 // keyword of the constructor's class. 2936 // keyword of the constructor's class.
2934 Function& ctor = Function::Handle( 2937 Function& ctor = Function::Handle(
2935 Function::New(ctor_name, 2938 Function::New(ctor_name,
2936 RawFunction::kConstructor, 2939 RawFunction::kConstructor,
2937 /* is_static = */ false, 2940 /* is_static = */ false,
2938 /* is_const = */ false, 2941 /* is_const = */ false,
2942 /* is_abstract = */ false,
2939 class_desc->token_pos())); 2943 class_desc->token_pos()));
2940 ParamList params; 2944 ParamList params;
2941 // Add implicit 'this' parameter. 2945 // Add implicit 'this' parameter.
2942 params.AddReceiver(TokenPos()); 2946 params.AddReceiver(TokenPos());
2943 // Add implicit parameter for construction phase. 2947 // Add implicit parameter for construction phase.
2944 params.AddFinalParameter( 2948 params.AddFinalParameter(
2945 TokenPos(), 2949 TokenPos(),
2946 kPhaseParameterName, 2950 kPhaseParameterName,
2947 &Type::ZoneHandle(Type::DynamicType())); 2951 &Type::ZoneHandle(Type::DynamicType()));
2948 2952
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
3047 } 3051 }
3048 ParamList func_params; 3052 ParamList func_params;
3049 const bool no_explicit_default_values = false; 3053 const bool no_explicit_default_values = false;
3050 ParseFormalParameterList(no_explicit_default_values, &func_params); 3054 ParseFormalParameterList(no_explicit_default_values, &func_params);
3051 // The field 'is_static' has no meaning for signature functions. 3055 // The field 'is_static' has no meaning for signature functions.
3052 Function& signature_function = Function::Handle( 3056 Function& signature_function = Function::Handle(
3053 Function::New(*alias_name, 3057 Function::New(*alias_name,
3054 RawFunction::kSignatureFunction, 3058 RawFunction::kSignatureFunction,
3055 /* is_static = */ false, 3059 /* is_static = */ false,
3056 /* is_const = */ false, 3060 /* is_const = */ false,
3061 /* is_abstract = */ false,
3057 alias_name_pos)); 3062 alias_name_pos));
3058 signature_function.set_owner(alias_owner); 3063 signature_function.set_owner(alias_owner);
3059 signature_function.set_result_type(result_type); 3064 signature_function.set_result_type(result_type);
3060 AddFormalParamsToFunction(&func_params, signature_function); 3065 AddFormalParamsToFunction(&func_params, signature_function);
3061 const String& signature = String::Handle(signature_function.Signature()); 3066 const String& signature = String::Handle(signature_function.Signature());
3062 if (FLAG_trace_parser) { 3067 if (FLAG_trace_parser) {
3063 OS::Print("TopLevel parsing function type alias '%s'\n", 3068 OS::Print("TopLevel parsing function type alias '%s'\n",
3064 signature.ToCString()); 3069 signature.ToCString());
3065 } 3070 }
3066 // Lookup the signature class, i.e. the class whose name is the signature. 3071 // Lookup the signature class, i.e. the class whose name is the signature.
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
3441 } 3446 }
3442 cls_interfaces = Array::MakeArray(all_interfaces); 3447 cls_interfaces = Array::MakeArray(all_interfaces);
3443 cls.set_interfaces(cls_interfaces); 3448 cls.set_interfaces(cls_interfaces);
3444 } 3449 }
3445 3450
3446 3451
3447 void Parser::ParseTopLevelVariable(TopLevel* top_level) { 3452 void Parser::ParseTopLevelVariable(TopLevel* top_level) {
3448 TRACE_PARSER("ParseTopLevelVariable"); 3453 TRACE_PARSER("ParseTopLevelVariable");
3449 const bool is_final = (CurrentToken() == Token::kFINAL); 3454 const bool is_final = (CurrentToken() == Token::kFINAL);
3450 const bool is_static = true; 3455 const bool is_static = true;
3456 const bool is_abstract = false;
3451 const AbstractType& type = AbstractType::ZoneHandle(ParseFinalVarOrType( 3457 const AbstractType& type = AbstractType::ZoneHandle(ParseFinalVarOrType(
3452 FLAG_enable_type_checks ? ClassFinalizer::kTryResolve : 3458 FLAG_enable_type_checks ? ClassFinalizer::kTryResolve :
3453 ClassFinalizer::kIgnore)); 3459 ClassFinalizer::kIgnore));
3454 Field& field = Field::Handle(); 3460 Field& field = Field::Handle();
3455 Function& getter = Function::Handle(); 3461 Function& getter = Function::Handle();
3456 while (true) { 3462 while (true) {
3457 const intptr_t name_pos = TokenPos(); 3463 const intptr_t name_pos = TokenPos();
3458 String& var_name = *ExpectIdentifier("variable name expected"); 3464 String& var_name = *ExpectIdentifier("variable name expected");
3459 3465
3460 if (library_.LookupObject(var_name) != Object::null()) { 3466 if (library_.LookupObject(var_name) != Object::null()) {
(...skipping 15 matching lines...) Expand all
3476 field.set_value(Instance::Handle(Instance::null())); 3482 field.set_value(Instance::Handle(Instance::null()));
3477 top_level->fields.Add(field); 3483 top_level->fields.Add(field);
3478 library_.AddObject(field, var_name); 3484 library_.AddObject(field, var_name);
3479 if (CurrentToken() == Token::kASSIGN) { 3485 if (CurrentToken() == Token::kASSIGN) {
3480 ConsumeToken(); 3486 ConsumeToken();
3481 SkipExpr(); 3487 SkipExpr();
3482 field.set_value(Instance::Handle(Object::sentinel())); 3488 field.set_value(Instance::Handle(Object::sentinel()));
3483 // Create a static const getter. 3489 // Create a static const getter.
3484 String& getter_name = String::ZoneHandle(Field::GetterSymbol(var_name)); 3490 String& getter_name = String::ZoneHandle(Field::GetterSymbol(var_name));
3485 getter = Function::New(getter_name, RawFunction::kConstImplicitGetter, 3491 getter = Function::New(getter_name, RawFunction::kConstImplicitGetter,
3486 is_static, is_final, name_pos); 3492 is_static, is_final, is_abstract, name_pos);
3487 getter.set_result_type(type); 3493 getter.set_result_type(type);
3488 top_level->functions.Add(getter); 3494 top_level->functions.Add(getter);
3489 } else if (is_final) { 3495 } else if (is_final) {
3490 ErrorMsg(name_pos, "missing initializer for final variable"); 3496 ErrorMsg(name_pos, "missing initializer for final variable");
3491 } 3497 }
3492 3498
3493 if (CurrentToken() == Token::kCOMMA) { 3499 if (CurrentToken() == Token::kCOMMA) {
3494 ConsumeToken(); 3500 ConsumeToken();
3495 } else if (CurrentToken() == Token::kSEMICOLON) { 3501 } else if (CurrentToken() == Token::kSEMICOLON) {
3496 ConsumeToken(); 3502 ConsumeToken();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
3550 SkipExpr(); 3556 SkipExpr();
3551 ExpectSemicolon(); 3557 ExpectSemicolon();
3552 function_end_pos = TokenPos(); 3558 function_end_pos = TokenPos();
3553 } else if (IsLiteral("native")) { 3559 } else if (IsLiteral("native")) {
3554 ParseNativeDeclaration(); 3560 ParseNativeDeclaration();
3555 } else { 3561 } else {
3556 ErrorMsg("function block expected"); 3562 ErrorMsg("function block expected");
3557 } 3563 }
3558 Function& func = Function::Handle( 3564 Function& func = Function::Handle(
3559 Function::New(func_name, RawFunction::kFunction, 3565 Function::New(func_name, RawFunction::kFunction,
3560 is_static, false, function_pos)); 3566 is_static, false, false, function_pos));
3561 func.set_result_type(result_type); 3567 func.set_result_type(result_type);
3562 func.set_end_token_pos(function_end_pos); 3568 func.set_end_token_pos(function_end_pos);
3563 AddFormalParamsToFunction(&params, func); 3569 AddFormalParamsToFunction(&params, func);
3564 top_level->functions.Add(func); 3570 top_level->functions.Add(func);
3565 library_.AddObject(func, func_name); 3571 library_.AddObject(func, func_name);
3566 } 3572 }
3567 3573
3568 3574
3569 void Parser::ParseTopLevelAccessor(TopLevel* top_level) { 3575 void Parser::ParseTopLevelAccessor(TopLevel* top_level) {
3570 TRACE_PARSER("ParseTopLevelAccessor"); 3576 TRACE_PARSER("ParseTopLevelAccessor");
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
3632 ExpectSemicolon(); 3638 ExpectSemicolon();
3633 } else if (IsLiteral("native")) { 3639 } else if (IsLiteral("native")) {
3634 ParseNativeDeclaration(); 3640 ParseNativeDeclaration();
3635 } else { 3641 } else {
3636 ErrorMsg("function block expected"); 3642 ErrorMsg("function block expected");
3637 } 3643 }
3638 Function& func = Function::Handle( 3644 Function& func = Function::Handle(
3639 Function::New(accessor_name, 3645 Function::New(accessor_name,
3640 is_getter? RawFunction::kGetterFunction : 3646 is_getter? RawFunction::kGetterFunction :
3641 RawFunction::kSetterFunction, 3647 RawFunction::kSetterFunction,
3642 is_static, false, accessor_pos)); 3648 is_static, false, false, accessor_pos));
3643 func.set_result_type(result_type); 3649 func.set_result_type(result_type);
3644 AddFormalParamsToFunction(&params, func); 3650 AddFormalParamsToFunction(&params, func);
3645 top_level->functions.Add(func); 3651 top_level->functions.Add(func);
3646 library_.AddObject(func, accessor_name); 3652 library_.AddObject(func, accessor_name);
3647 } 3653 }
3648 3654
3649 3655
3650 void Parser::ParseLibraryName() { 3656 void Parser::ParseLibraryName() {
3651 TRACE_PARSER("ParseLibraryName"); 3657 TRACE_PARSER("ParseLibraryName");
3652 if ((script_.kind() == RawScript::kLibrary) && 3658 if ((script_.kind() == RawScript::kLibrary) &&
(...skipping 5006 matching lines...) Expand 10 before | Expand all | Expand 10 after
8659 void Parser::SkipQualIdent() { 8665 void Parser::SkipQualIdent() {
8660 ASSERT(IsIdentifier()); 8666 ASSERT(IsIdentifier());
8661 ConsumeToken(); 8667 ConsumeToken();
8662 if (CurrentToken() == Token::kPERIOD) { 8668 if (CurrentToken() == Token::kPERIOD) {
8663 ConsumeToken(); // Consume the kPERIOD token. 8669 ConsumeToken(); // Consume the kPERIOD token.
8664 ExpectIdentifier("identifier expected after '.'"); 8670 ExpectIdentifier("identifier expected after '.'");
8665 } 8671 }
8666 } 8672 }
8667 8673
8668 } // namespace dart 8674 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698