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

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

Issue 16780008: Reified metadata in the VM (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 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 | « runtime/vm/parser.h ('k') | runtime/vm/raw_object.h » ('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 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 } 504 }
505 void Clear() { 505 void Clear() {
506 has_abstract = false; 506 has_abstract = false;
507 has_external = false; 507 has_external = false;
508 has_final = false; 508 has_final = false;
509 has_const = false; 509 has_const = false;
510 has_static = false; 510 has_static = false;
511 has_var = false; 511 has_var = false;
512 has_factory = false; 512 has_factory = false;
513 has_operator = false; 513 has_operator = false;
514 metadata_pos = -1;
514 operator_token = Token::kILLEGAL; 515 operator_token = Token::kILLEGAL;
515 type = NULL; 516 type = NULL;
516 name_pos = 0; 517 name_pos = 0;
517 name = NULL; 518 name = NULL;
518 redirect_name = NULL; 519 redirect_name = NULL;
519 constructor_name = NULL; 520 constructor_name = NULL;
520 params.Clear(); 521 params.Clear();
521 kind = RawFunction::kRegularFunction; 522 kind = RawFunction::kRegularFunction;
522 } 523 }
523 bool IsConstructor() const { 524 bool IsConstructor() const {
(...skipping 12 matching lines...) Expand all
536 return kind == RawFunction::kSetterFunction; 537 return kind == RawFunction::kSetterFunction;
537 } 538 }
538 bool has_abstract; 539 bool has_abstract;
539 bool has_external; 540 bool has_external;
540 bool has_final; 541 bool has_final;
541 bool has_const; 542 bool has_const;
542 bool has_static; 543 bool has_static;
543 bool has_var; 544 bool has_var;
544 bool has_factory; 545 bool has_factory;
545 bool has_operator; 546 bool has_operator;
547 intptr_t metadata_pos;
546 Token::Kind operator_token; 548 Token::Kind operator_token;
547 const AbstractType* type; 549 const AbstractType* type;
548 intptr_t name_pos; 550 intptr_t name_pos;
549 String* name; 551 String* name;
550 // For constructors: NULL or name of redirected to constructor. 552 // For constructors: NULL or name of redirected to constructor.
551 String* redirect_name; 553 String* redirect_name;
552 // For constructors: NULL for unnamed constructor, 554 // For constructors: NULL for unnamed constructor,
553 // identifier after classname for named constructors. 555 // identifier after classname for named constructors.
554 String* constructor_name; 556 String* constructor_name;
555 ParamList params; 557 ParamList params;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 642
641 void AddField(const Field& field) { 643 void AddField(const Field& field) {
642 ASSERT(!FieldExists(String::Handle(field.name()))); 644 ASSERT(!FieldExists(String::Handle(field.name())));
643 fields_.Add(field); 645 fields_.Add(field);
644 } 646 }
645 647
646 const GrowableObjectArray& fields() const { 648 const GrowableObjectArray& fields() const {
647 return fields_; 649 return fields_;
648 } 650 }
649 651
650 RawClass* clazz() const { 652 const Class& clazz() const {
651 return clazz_.raw(); 653 return clazz_;
652 } 654 }
653 655
654 const String& class_name() const { 656 const String& class_name() const {
655 return class_name_; 657 return class_name_;
656 } 658 }
657 659
658 bool has_constructor() const { 660 bool has_constructor() const {
659 Function& func = Function::Handle(); 661 Function& func = Function::Handle();
660 for (int i = 0; i < functions_.Length(); i++) { 662 for (int i = 0; i < functions_.Length(); i++) {
661 func ^= functions_.At(i); 663 func ^= functions_.At(i);
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 ((instantiator != NULL) && instantiator->is_captured())) { 836 ((instantiator != NULL) && instantiator->is_captured())) {
835 parsed_function->set_instantiator( 837 parsed_function->set_instantiator(
836 new LoadLocalNode(node_sequence->token_pos(), instantiator)); 838 new LoadLocalNode(node_sequence->token_pos(), instantiator));
837 } 839 }
838 } 840 }
839 841
840 parsed_function->set_default_parameter_values(default_parameter_values); 842 parsed_function->set_default_parameter_values(default_parameter_values);
841 } 843 }
842 844
843 845
846 RawObject* Parser::ParseMetadata(const Class& cls, intptr_t token_pos) {
847 Isolate* isolate = Isolate::Current();
848 StackZone zone(isolate);
849 LongJump* base = isolate->long_jump_base();
850 LongJump jump;
851 isolate->set_long_jump_base(&jump);
852 if (setjmp(*jump.Set()) == 0) {
853 const Script& script = Script::Handle(cls.script());
854 const Library& lib = Library::Handle(cls.library());
855 Parser parser(script, lib, token_pos);
856 parser.set_current_class(cls);
857 return parser.EvaluateMetadata();
858 } else {
859 Error& error = Error::Handle();
860 error = isolate->object_store()->sticky_error();
861 isolate->object_store()->clear_sticky_error();
862 isolate->set_long_jump_base(base);
863 return error.raw();
864 }
865 UNREACHABLE();
866 return Object::null();
867 }
868
869
870 RawArray* Parser::EvaluateMetadata() {
871 if (CurrentToken() != Token::kAT) {
872 ErrorMsg("Metadata character '@' expected");
873 }
874 GrowableObjectArray& meta_values =
875 GrowableObjectArray::Handle(GrowableObjectArray::New());
876 while (CurrentToken() == Token::kAT) {
877 ConsumeToken();
878 intptr_t expr_pos = TokenPos();
879 if (!IsIdentifier()) {
880 ExpectIdentifier("identifier expected");
881 }
882 AstNode* expr = NULL;
883 if ((LookaheadToken(1) == Token::kLPAREN) ||
884 ((LookaheadToken(1) == Token::kPERIOD) &&
885 (LookaheadToken(3) == Token::kLPAREN)) ||
886 ((LookaheadToken(1) == Token::kPERIOD) &&
887 (LookaheadToken(3) == Token::kPERIOD) &&
888 (LookaheadToken(5) == Token::kLPAREN))) {
889 expr = ParseNewOperator(Token::kCONST);
890 } else {
891 expr = ParsePrimary();
892 }
893 if (expr->EvalConstExpr() == NULL) {
894 ErrorMsg(expr_pos, "expression must be a compile-time constant");
895 }
896 const Instance& val = EvaluateConstExpr(expr);
897 meta_values.Add(val);
898 }
899 return Array::MakeArray(meta_values);
900 }
901
902
844 // TODO(regis): Since a const variable is implicitly final, 903 // TODO(regis): Since a const variable is implicitly final,
845 // rename ParseStaticConstGetter to ParseStaticFinalGetter and 904 // rename ParseStaticConstGetter to ParseStaticFinalGetter and
846 // rename kConstImplicitGetter to kImplicitFinalGetter. 905 // rename kConstImplicitGetter to kImplicitFinalGetter.
847 SequenceNode* Parser::ParseStaticConstGetter(const Function& func) { 906 SequenceNode* Parser::ParseStaticConstGetter(const Function& func) {
848 TRACE_PARSER("ParseStaticConstGetter"); 907 TRACE_PARSER("ParseStaticConstGetter");
849 ParamList params; 908 ParamList params;
850 ASSERT(func.num_fixed_parameters() == 0); // static. 909 ASSERT(func.num_fixed_parameters() == 0); // static.
851 ASSERT(!func.HasOptionalParameters()); 910 ASSERT(!func.HasOptionalParameters());
852 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); 911 ASSERT(AbstractType::Handle(func.result_type()).IsResolved());
853 912
(...skipping 1963 matching lines...) Expand 10 before | Expand all | Expand 10 after
2817 Function::New(*method->name, 2876 Function::New(*method->name,
2818 function_kind, 2877 function_kind,
2819 method->has_static, 2878 method->has_static,
2820 method->has_const, 2879 method->has_const,
2821 method->has_abstract, 2880 method->has_abstract,
2822 method->has_external, 2881 method->has_external,
2823 current_class(), 2882 current_class(),
2824 method_pos)); 2883 method_pos));
2825 func.set_result_type(*method->type); 2884 func.set_result_type(*method->type);
2826 func.set_end_token_pos(method_end_pos); 2885 func.set_end_token_pos(method_end_pos);
2886 if (method->metadata_pos > 0) {
2887 library_.AddFunctionMetadata(func, method->metadata_pos);
2888 }
2827 2889
2828 // If this method is a redirecting factory, set the redirection information. 2890 // If this method is a redirecting factory, set the redirection information.
2829 if (!redirection_type.IsNull()) { 2891 if (!redirection_type.IsNull()) {
2830 ASSERT(func.IsFactory()); 2892 ASSERT(func.IsFactory());
2831 func.SetRedirectionType(redirection_type); 2893 func.SetRedirectionType(redirection_type);
2832 if (!redirection_identifier.IsNull()) { 2894 if (!redirection_identifier.IsNull()) {
2833 func.SetRedirectionIdentifier(redirection_identifier); 2895 func.SetRedirectionIdentifier(redirection_identifier);
2834 } 2896 }
2835 } 2897 }
2836 2898
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
2904 // Create the field object. 2966 // Create the field object.
2905 class_field = Field::New(*field->name, 2967 class_field = Field::New(*field->name,
2906 field->has_static, 2968 field->has_static,
2907 field->has_final, 2969 field->has_final,
2908 field->has_const, 2970 field->has_const,
2909 current_class(), 2971 current_class(),
2910 field->name_pos); 2972 field->name_pos);
2911 class_field.set_type(*field->type); 2973 class_field.set_type(*field->type);
2912 class_field.set_has_initializer(has_initializer); 2974 class_field.set_has_initializer(has_initializer);
2913 members->AddField(class_field); 2975 members->AddField(class_field);
2976 if (field->metadata_pos >= 0) {
2977 library_.AddFieldMetadata(class_field, field->metadata_pos);
2978 }
2914 2979
2915 // For static const fields, set value to "uninitialized" and 2980 // For static const fields, set value to "uninitialized" and
2916 // create a kConstImplicitGetter getter method. 2981 // create a kConstImplicitGetter getter method.
2917 if (field->has_static && has_initializer) { 2982 if (field->has_static && has_initializer) {
2918 class_field.set_value(init_value); 2983 class_field.set_value(init_value);
2919 if (!has_simple_literal) { 2984 if (!has_simple_literal) {
2920 String& getter_name = String::Handle(Field::GetterSymbol(*field->name)); 2985 String& getter_name = String::Handle(Field::GetterSymbol(*field->name));
2921 getter = Function::New(getter_name, 2986 getter = Function::New(getter_name,
2922 RawFunction::kConstImplicitGetter, 2987 RawFunction::kConstImplicitGetter,
2923 field->has_static, 2988 field->has_static,
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2994 member.params.has_optional_positional_parameters || 3059 member.params.has_optional_positional_parameters ||
2995 member.params.has_optional_named_parameters || 3060 member.params.has_optional_named_parameters ||
2996 (member.params.num_fixed_parameters != expected_num_parameters)) { 3061 (member.params.num_fixed_parameters != expected_num_parameters)) {
2997 // Subtract receiver when reporting number of expected arguments. 3062 // Subtract receiver when reporting number of expected arguments.
2998 ErrorMsg(member.name_pos, "operator %s expects %"Pd" argument(s)", 3063 ErrorMsg(member.name_pos, "operator %s expects %"Pd" argument(s)",
2999 member.name->ToCString(), (expected_num_parameters - 1)); 3064 member.name->ToCString(), (expected_num_parameters - 1));
3000 } 3065 }
3001 } 3066 }
3002 3067
3003 3068
3004 void Parser::ParseClassMemberDefinition(ClassDesc* members) { 3069 void Parser::ParseClassMemberDefinition(ClassDesc* members,
3070 intptr_t metadata_pos) {
3005 TRACE_PARSER("ParseClassMemberDefinition"); 3071 TRACE_PARSER("ParseClassMemberDefinition");
3006 MemberDesc member; 3072 MemberDesc member;
3007 current_member_ = &member; 3073 current_member_ = &member;
3074 member.metadata_pos = metadata_pos;
3008 if ((CurrentToken() == Token::kEXTERNAL) && 3075 if ((CurrentToken() == Token::kEXTERNAL) &&
3009 (LookaheadToken(1) != Token::kLPAREN)) { 3076 (LookaheadToken(1) != Token::kLPAREN)) {
3010 ConsumeToken(); 3077 ConsumeToken();
3011 member.has_external = true; 3078 member.has_external = true;
3012 } 3079 }
3013 if ((CurrentToken() == Token::kSTATIC) && 3080 if ((CurrentToken() == Token::kSTATIC) &&
3014 (LookaheadToken(1) != Token::kLPAREN)) { 3081 (LookaheadToken(1) != Token::kLPAREN)) {
3015 ConsumeToken(); 3082 ConsumeToken();
3016 member.has_static = true; 3083 member.has_static = true;
3017 } 3084 }
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
3210 } 3277 }
3211 ParseFieldDefinition(members, &member); 3278 ParseFieldDefinition(members, &member);
3212 } else { 3279 } else {
3213 UnexpectedToken(); 3280 UnexpectedToken();
3214 } 3281 }
3215 current_member_ = NULL; 3282 current_member_ = NULL;
3216 members->AddMember(member); 3283 members->AddMember(member);
3217 } 3284 }
3218 3285
3219 3286
3220 void Parser::ParseClassDeclaration(const GrowableObjectArray& pending_classes) { 3287 void Parser::ParseClassDeclaration(const GrowableObjectArray& pending_classes,
3288 intptr_t metadata_pos) {
3221 TRACE_PARSER("ParseClassDeclaration"); 3289 TRACE_PARSER("ParseClassDeclaration");
3222 bool is_patch = false; 3290 bool is_patch = false;
3223 bool is_abstract = false; 3291 bool is_abstract = false;
3224 if (is_patch_source() && 3292 if (is_patch_source() &&
3225 (CurrentToken() == Token::kIDENT) && 3293 (CurrentToken() == Token::kIDENT) &&
3226 CurrentLiteral()->Equals("patch")) { 3294 CurrentLiteral()->Equals("patch")) {
3227 ConsumeToken(); 3295 ConsumeToken();
3228 is_patch = true; 3296 is_patch = true;
3229 } else if (CurrentToken() == Token::kABSTRACT) { 3297 } else if (CurrentToken() == Token::kABSTRACT) {
3230 is_abstract = true; 3298 is_abstract = true;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
3352 if (is_patch) { 3420 if (is_patch) {
3353 // Apply the changes to the patched class looked up above. 3421 // Apply the changes to the patched class looked up above.
3354 ASSERT(obj.raw() == library_.LookupLocalObject(class_name)); 3422 ASSERT(obj.raw() == library_.LookupLocalObject(class_name));
3355 // The patched class must not be finalized yet. 3423 // The patched class must not be finalized yet.
3356 const Class& orig_class = Class::Cast(obj); 3424 const Class& orig_class = Class::Cast(obj);
3357 ASSERT(!orig_class.is_finalized()); 3425 ASSERT(!orig_class.is_finalized());
3358 orig_class.set_patch_class(cls); 3426 orig_class.set_patch_class(cls);
3359 cls.set_is_patch(); 3427 cls.set_is_patch();
3360 } 3428 }
3361 pending_classes.Add(cls, Heap::kOld); 3429 pending_classes.Add(cls, Heap::kOld);
3430 if (metadata_pos >= 0) {
3431 library_.AddClassMetadata(cls, metadata_pos);
3432 }
3362 3433
3363 if (CurrentToken() != Token::kLBRACE) { 3434 if (CurrentToken() != Token::kLBRACE) {
3364 ErrorMsg("{ expected"); 3435 ErrorMsg("{ expected");
3365 } 3436 }
3366 SkipBlock(); 3437 SkipBlock();
3367 } 3438 }
3368 3439
3369 3440
3370 void Parser::ParseClassDefinition(const Class& cls) { 3441 void Parser::ParseClassDefinition(const Class& cls) {
3371 TRACE_PARSER("ParseClassDefinition"); 3442 TRACE_PARSER("ParseClassDefinition");
3372 set_current_class(cls); 3443 set_current_class(cls);
3373 is_top_level_ = true; 3444 is_top_level_ = true;
3374 String& class_name = String::Handle(cls.Name()); 3445 String& class_name = String::Handle(cls.Name());
3375 const intptr_t class_pos = TokenPos(); 3446 const intptr_t class_pos = TokenPos();
3376 ClassDesc members(cls, class_name, false, class_pos); 3447 ClassDesc members(cls, class_name, false, class_pos);
3377 while (CurrentToken() != Token::kLBRACE) { 3448 while (CurrentToken() != Token::kLBRACE) {
3378 ConsumeToken(); 3449 ConsumeToken();
3379 } 3450 }
3380 ExpectToken(Token::kLBRACE); 3451 ExpectToken(Token::kLBRACE);
3381 while (CurrentToken() != Token::kRBRACE) { 3452 while (CurrentToken() != Token::kRBRACE) {
3382 SkipMetadata(); 3453 intptr_t metadata_pos = SkipMetadata();
3383 ParseClassMemberDefinition(&members); 3454 ParseClassMemberDefinition(&members, metadata_pos);
3384 } 3455 }
3385 ExpectToken(Token::kRBRACE); 3456 ExpectToken(Token::kRBRACE);
3386 3457
3387 CheckConstructors(&members); 3458 CheckConstructors(&members);
3388 3459
3389 // Need to compute this here since MakeArray() will clear the 3460 // Need to compute this here since MakeArray() will clear the
3390 // functions array in members. 3461 // functions array in members.
3391 const bool need_implicit_constructor = 3462 const bool need_implicit_constructor =
3392 !members.has_constructor() && !cls.is_patch(); 3463 !members.has_constructor() && !cls.is_patch();
3393 3464
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
3712 if (token_kind_ == Token::kGT) { 3783 if (token_kind_ == Token::kGT) {
3713 ConsumeToken(); 3784 ConsumeToken();
3714 } else if (token_kind_ == Token::kSHR) { 3785 } else if (token_kind_ == Token::kSHR) {
3715 token_kind_ = Token::kGT; 3786 token_kind_ = Token::kGT;
3716 } else { 3787 } else {
3717 UNREACHABLE(); 3788 UNREACHABLE();
3718 } 3789 }
3719 } 3790 }
3720 3791
3721 3792
3722 void Parser::SkipMetadata() { 3793 intptr_t Parser::SkipMetadata() {
3794 if (CurrentToken() != Token::kAT) {
3795 return -1;
3796 }
3797 intptr_t metadata_pos = TokenPos();
3723 while (CurrentToken() == Token::kAT) { 3798 while (CurrentToken() == Token::kAT) {
3724 ConsumeToken(); 3799 ConsumeToken();
3725 ExpectIdentifier("identifier expected"); 3800 ExpectIdentifier("identifier expected");
3726 if (CurrentToken() == Token::kPERIOD) { 3801 if (CurrentToken() == Token::kPERIOD) {
3727 ConsumeToken(); 3802 ConsumeToken();
3728 ExpectIdentifier("identifier expected"); 3803 ExpectIdentifier("identifier expected");
3729 if (CurrentToken() == Token::kPERIOD) { 3804 if (CurrentToken() == Token::kPERIOD) {
3730 ConsumeToken(); 3805 ConsumeToken();
3731 ExpectIdentifier("identifier expected"); 3806 ExpectIdentifier("identifier expected");
3732 } 3807 }
3733 } 3808 }
3734 if (CurrentToken() == Token::kLPAREN) { 3809 if (CurrentToken() == Token::kLPAREN) {
3735 SkipToMatchingParenthesis(); 3810 SkipToMatchingParenthesis();
3736 } 3811 }
3737 } 3812 }
3813 return metadata_pos;
3738 } 3814 }
3739 3815
3740 3816
3741 void Parser::SkipTypeArguments() { 3817 void Parser::SkipTypeArguments() {
3742 if (CurrentToken() == Token::kLT) { 3818 if (CurrentToken() == Token::kLT) {
3743 do { 3819 do {
3744 ConsumeToken(); 3820 ConsumeToken();
3745 SkipType(false); 3821 SkipType(false);
3746 } while (CurrentToken() == Token::kCOMMA); 3822 } while (CurrentToken() == Token::kCOMMA);
3747 Token::Kind token = CurrentToken(); 3823 Token::Kind token = CurrentToken();
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
3966 mixin_type_arguments, 4042 mixin_type_arguments,
3967 mixin_pos); 4043 mixin_pos);
3968 mixin_super_type = mixin_application_type.raw(); 4044 mixin_super_type = mixin_application_type.raw();
3969 mixin_apps.Add(mixin_application_type); 4045 mixin_apps.Add(mixin_application_type);
3970 } while (CurrentToken() == Token::kCOMMA); 4046 } while (CurrentToken() == Token::kCOMMA);
3971 return MixinAppType::New(super_type, 4047 return MixinAppType::New(super_type,
3972 Array::Handle(Array::MakeArray(mixin_apps))); 4048 Array::Handle(Array::MakeArray(mixin_apps)));
3973 } 4049 }
3974 4050
3975 4051
3976 void Parser::ParseTopLevelVariable(TopLevel* top_level) { 4052 void Parser::ParseTopLevelVariable(TopLevel* top_level,
4053 intptr_t metadata_pos) {
3977 TRACE_PARSER("ParseTopLevelVariable"); 4054 TRACE_PARSER("ParseTopLevelVariable");
3978 const bool is_const = (CurrentToken() == Token::kCONST); 4055 const bool is_const = (CurrentToken() == Token::kCONST);
3979 // Const fields are implicitly final. 4056 // Const fields are implicitly final.
3980 const bool is_final = is_const || (CurrentToken() == Token::kFINAL); 4057 const bool is_final = is_const || (CurrentToken() == Token::kFINAL);
3981 const bool is_static = true; 4058 const bool is_static = true;
3982 const AbstractType& type = 4059 const AbstractType& type =
3983 AbstractType::ZoneHandle(ParseConstFinalVarOrType( 4060 AbstractType::ZoneHandle(ParseConstFinalVarOrType(
3984 FLAG_enable_type_checks ? ClassFinalizer::kTryResolve : 4061 FLAG_enable_type_checks ? ClassFinalizer::kTryResolve :
3985 ClassFinalizer::kIgnore)); 4062 ClassFinalizer::kIgnore));
3986 Field& field = Field::Handle(); 4063 Field& field = Field::Handle();
(...skipping 19 matching lines...) Expand all
4006 var_name.ToCString()); 4083 var_name.ToCString());
4007 } 4084 }
4008 } 4085 }
4009 4086
4010 field = Field::New(var_name, is_static, is_final, is_const, 4087 field = Field::New(var_name, is_static, is_final, is_const,
4011 current_class(), name_pos); 4088 current_class(), name_pos);
4012 field.set_type(type); 4089 field.set_type(type);
4013 field.set_value(Instance::Handle(Instance::null())); 4090 field.set_value(Instance::Handle(Instance::null()));
4014 top_level->fields.Add(field); 4091 top_level->fields.Add(field);
4015 library_.AddObject(field, var_name); 4092 library_.AddObject(field, var_name);
4093 if (metadata_pos >= 0) {
4094 library_.AddFieldMetadata(field, metadata_pos);
4095 }
4016 if (CurrentToken() == Token::kASSIGN) { 4096 if (CurrentToken() == Token::kASSIGN) {
4017 ConsumeToken(); 4097 ConsumeToken();
4018 Instance& field_value = Instance::Handle(Object::sentinel().raw()); 4098 Instance& field_value = Instance::Handle(Object::sentinel().raw());
4019 bool has_simple_literal = false; 4099 bool has_simple_literal = false;
4020 if (is_final && (LookaheadToken(1) == Token::kSEMICOLON)) { 4100 if (is_final && (LookaheadToken(1) == Token::kSEMICOLON)) {
4021 has_simple_literal = IsSimpleLiteral(type, &field_value); 4101 has_simple_literal = IsSimpleLiteral(type, &field_value);
4022 } 4102 }
4023 SkipExpr(); 4103 SkipExpr();
4024 field.set_value(field_value); 4104 field.set_value(field_value);
4025 if (!has_simple_literal) { 4105 if (!has_simple_literal) {
(...skipping 19 matching lines...) Expand all
4045 } else if (CurrentToken() == Token::kSEMICOLON) { 4125 } else if (CurrentToken() == Token::kSEMICOLON) {
4046 ConsumeToken(); 4126 ConsumeToken();
4047 break; 4127 break;
4048 } else { 4128 } else {
4049 ExpectSemicolon(); // Reports error. 4129 ExpectSemicolon(); // Reports error.
4050 } 4130 }
4051 } 4131 }
4052 } 4132 }
4053 4133
4054 4134
4055 void Parser::ParseTopLevelFunction(TopLevel* top_level) { 4135 void Parser::ParseTopLevelFunction(TopLevel* top_level,
4136 intptr_t metadata_pos) {
4056 TRACE_PARSER("ParseTopLevelFunction"); 4137 TRACE_PARSER("ParseTopLevelFunction");
4057 AbstractType& result_type = Type::Handle(Type::DynamicType()); 4138 AbstractType& result_type = Type::Handle(Type::DynamicType());
4058 const bool is_static = true; 4139 const bool is_static = true;
4059 bool is_external = false; 4140 bool is_external = false;
4060 bool is_patch = false; 4141 bool is_patch = false;
4061 if (is_patch_source() && 4142 if (is_patch_source() &&
4062 (CurrentToken() == Token::kIDENT) && 4143 (CurrentToken() == Token::kIDENT) &&
4063 CurrentLiteral()->Equals("patch") && 4144 CurrentLiteral()->Equals("patch") &&
4064 (LookaheadToken(1) != Token::kLPAREN)) { 4145 (LookaheadToken(1) != Token::kLPAREN)) {
4065 ConsumeToken(); 4146 ConsumeToken();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
4130 function_pos)); 4211 function_pos));
4131 func.set_result_type(result_type); 4212 func.set_result_type(result_type);
4132 func.set_end_token_pos(function_end_pos); 4213 func.set_end_token_pos(function_end_pos);
4133 AddFormalParamsToFunction(&params, func); 4214 AddFormalParamsToFunction(&params, func);
4134 top_level->functions.Add(func); 4215 top_level->functions.Add(func);
4135 if (!is_patch) { 4216 if (!is_patch) {
4136 library_.AddObject(func, func_name); 4217 library_.AddObject(func, func_name);
4137 } else { 4218 } else {
4138 library_.ReplaceObject(func, func_name); 4219 library_.ReplaceObject(func, func_name);
4139 } 4220 }
4221 if (metadata_pos >= 0) {
4222 library_.AddFunctionMetadata(func, metadata_pos);
4223 }
4140 } 4224 }
4141 4225
4142 4226
4143 void Parser::ParseTopLevelAccessor(TopLevel* top_level) { 4227 void Parser::ParseTopLevelAccessor(TopLevel* top_level,
4228 intptr_t metadata_pos) {
4144 TRACE_PARSER("ParseTopLevelAccessor"); 4229 TRACE_PARSER("ParseTopLevelAccessor");
4145 const bool is_static = true; 4230 const bool is_static = true;
4146 bool is_external = false; 4231 bool is_external = false;
4147 bool is_patch = false; 4232 bool is_patch = false;
4148 AbstractType& result_type = AbstractType::Handle(); 4233 AbstractType& result_type = AbstractType::Handle();
4149 if (is_patch_source() && 4234 if (is_patch_source() &&
4150 (CurrentToken() == Token::kIDENT) && 4235 (CurrentToken() == Token::kIDENT) &&
4151 CurrentLiteral()->Equals("patch")) { 4236 CurrentLiteral()->Equals("patch")) {
4152 ConsumeToken(); 4237 ConsumeToken();
4153 is_patch = true; 4238 is_patch = true;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
4251 accessor_pos)); 4336 accessor_pos));
4252 func.set_result_type(result_type); 4337 func.set_result_type(result_type);
4253 func.set_end_token_pos(accessor_end_pos); 4338 func.set_end_token_pos(accessor_end_pos);
4254 AddFormalParamsToFunction(&params, func); 4339 AddFormalParamsToFunction(&params, func);
4255 top_level->functions.Add(func); 4340 top_level->functions.Add(func);
4256 if (!is_patch) { 4341 if (!is_patch) {
4257 library_.AddObject(func, accessor_name); 4342 library_.AddObject(func, accessor_name);
4258 } else { 4343 } else {
4259 library_.ReplaceObject(func, accessor_name); 4344 library_.ReplaceObject(func, accessor_name);
4260 } 4345 }
4346 if (metadata_pos >= 0) {
4347 library_.AddFunctionMetadata(func, metadata_pos);
4348 }
4261 } 4349 }
4262 4350
4263 4351
4264 4352
4265 RawObject* Parser::CallLibraryTagHandler(Dart_LibraryTag tag, 4353 RawObject* Parser::CallLibraryTagHandler(Dart_LibraryTag tag,
4266 intptr_t token_pos, 4354 intptr_t token_pos,
4267 const String& url) { 4355 const String& url) {
4268 Dart_LibraryTagHandler handler = isolate()->library_tag_handler(); 4356 Dart_LibraryTagHandler handler = isolate()->library_tag_handler();
4269 if (handler == NULL) { 4357 if (handler == NULL) {
4270 if (url.StartsWith(Symbols::DartScheme())) { 4358 if (url.StartsWith(Symbols::DartScheme())) {
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
4521 4609
4522 if (is_library_source() || is_patch_source()) { 4610 if (is_library_source() || is_patch_source()) {
4523 ParseLibraryDefinition(); 4611 ParseLibraryDefinition();
4524 } else if (is_part_source()) { 4612 } else if (is_part_source()) {
4525 ParsePartHeader(); 4613 ParsePartHeader();
4526 } 4614 }
4527 4615
4528 const Class& cls = Class::Handle(isolate()); 4616 const Class& cls = Class::Handle(isolate());
4529 while (true) { 4617 while (true) {
4530 set_current_class(cls); // No current class. 4618 set_current_class(cls); // No current class.
4531 SkipMetadata(); 4619 intptr_t metadata_pos = SkipMetadata();
4532 if (CurrentToken() == Token::kCLASS) { 4620 if (CurrentToken() == Token::kCLASS) {
4533 ParseClassDeclaration(pending_classes); 4621 ParseClassDeclaration(pending_classes, metadata_pos);
4534 } else if ((CurrentToken() == Token::kTYPEDEF) && 4622 } else if ((CurrentToken() == Token::kTYPEDEF) &&
4535 (LookaheadToken(1) != Token::kLPAREN)) { 4623 (LookaheadToken(1) != Token::kLPAREN)) {
4536 set_current_class(toplevel_class); 4624 set_current_class(toplevel_class);
4537 ParseTypedef(pending_classes); 4625 ParseTypedef(pending_classes);
4538 } else if ((CurrentToken() == Token::kABSTRACT) && 4626 } else if ((CurrentToken() == Token::kABSTRACT) &&
4539 (LookaheadToken(1) == Token::kCLASS)) { 4627 (LookaheadToken(1) == Token::kCLASS)) {
4540 ParseClassDeclaration(pending_classes); 4628 ParseClassDeclaration(pending_classes, metadata_pos);
4541 } else if (is_patch_source() && IsLiteral("patch") && 4629 } else if (is_patch_source() && IsLiteral("patch") &&
4542 (LookaheadToken(1) == Token::kCLASS)) { 4630 (LookaheadToken(1) == Token::kCLASS)) {
4543 ParseClassDeclaration(pending_classes); 4631 ParseClassDeclaration(pending_classes, metadata_pos);
4544 } else { 4632 } else {
4545 set_current_class(toplevel_class); 4633 set_current_class(toplevel_class);
4546 if (IsVariableDeclaration()) { 4634 if (IsVariableDeclaration()) {
4547 ParseTopLevelVariable(&top_level); 4635 ParseTopLevelVariable(&top_level, metadata_pos);
4548 } else if (IsFunctionDeclaration()) { 4636 } else if (IsFunctionDeclaration()) {
4549 ParseTopLevelFunction(&top_level); 4637 ParseTopLevelFunction(&top_level, metadata_pos);
4550 } else if (IsTopLevelAccessor()) { 4638 } else if (IsTopLevelAccessor()) {
4551 ParseTopLevelAccessor(&top_level); 4639 ParseTopLevelAccessor(&top_level, metadata_pos);
4552 } else if (CurrentToken() == Token::kEOS) { 4640 } else if (CurrentToken() == Token::kEOS) {
4553 break; 4641 break;
4554 } else { 4642 } else {
4555 UnexpectedToken(); 4643 UnexpectedToken();
4556 } 4644 }
4557 } 4645 }
4558 } 4646 }
4559 if ((top_level.fields.Length() > 0) || (top_level.functions.Length() > 0)) { 4647 if ((top_level.fields.Length() > 0) || (top_level.functions.Length() > 0)) {
4560 Array& array = Array::Handle(); 4648 Array& array = Array::Handle();
4561 4649
(...skipping 4577 matching lines...) Expand 10 before | Expand all | Expand 10 after
9139 // This convention prevents users from explicitly calling constructors. 9227 // This convention prevents users from explicitly calling constructors.
9140 String& constructor_name = 9228 String& constructor_name =
9141 String::Handle(String::Concat(type_class_name, Symbols::Dot())); 9229 String::Handle(String::Concat(type_class_name, Symbols::Dot()));
9142 if (named_constructor != NULL) { 9230 if (named_constructor != NULL) {
9143 constructor_name = String::Concat(constructor_name, *named_constructor); 9231 constructor_name = String::Concat(constructor_name, *named_constructor);
9144 } 9232 }
9145 return constructor_name; 9233 return constructor_name;
9146 } 9234 }
9147 9235
9148 9236
9149 AstNode* Parser::ParseNewOperator() { 9237 AstNode* Parser::ParseNewOperator(Token::Kind op_kind) {
9150 TRACE_PARSER("ParseNewOperator"); 9238 TRACE_PARSER("ParseNewOperator");
9151 const intptr_t new_pos = TokenPos(); 9239 const intptr_t new_pos = TokenPos();
9152 ASSERT((CurrentToken() == Token::kNEW) || (CurrentToken() == Token::kCONST)); 9240 ASSERT((op_kind == Token::kNEW) || (op_kind == Token::kCONST));
9153 bool is_const = (CurrentToken() == Token::kCONST); 9241 bool is_const = (op_kind == Token::kCONST);
9154 ConsumeToken();
9155 if (!IsIdentifier()) { 9242 if (!IsIdentifier()) {
9156 ErrorMsg("type name expected"); 9243 ErrorMsg("type name expected");
9157 } 9244 }
9158 intptr_t type_pos = TokenPos(); 9245 intptr_t type_pos = TokenPos();
9159 AbstractType& type = AbstractType::Handle( 9246 AbstractType& type = AbstractType::Handle(
9160 ParseType(ClassFinalizer::kCanonicalizeExpression)); 9247 ParseType(ClassFinalizer::kCanonicalizeExpression));
9161 // In case the type is malformed, throw a dynamic type error after finishing 9248 // In case the type is malformed, throw a dynamic type error after finishing
9162 // parsing the instance creation expression. 9249 // parsing the instance creation expression.
9163 if (!type.IsMalformed() && (type.IsTypeParameter() || type.IsDynamicType())) { 9250 if (!type.IsMalformed() && (type.IsTypeParameter() || type.IsDynamicType())) {
9164 // Replace the type with a malformed type. 9251 // Replace the type with a malformed type.
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
9612 } else if (CurrentToken() == Token::kDOUBLE) { 9699 } else if (CurrentToken() == Token::kDOUBLE) {
9613 Double& double_value = Double::ZoneHandle(CurrentDoubleLiteral()); 9700 Double& double_value = Double::ZoneHandle(CurrentDoubleLiteral());
9614 if (double_value.IsNull()) { 9701 if (double_value.IsNull()) {
9615 ErrorMsg("invalid double literal"); 9702 ErrorMsg("invalid double literal");
9616 } 9703 }
9617 primary = new LiteralNode(TokenPos(), double_value); 9704 primary = new LiteralNode(TokenPos(), double_value);
9618 ConsumeToken(); 9705 ConsumeToken();
9619 } else if (CurrentToken() == Token::kSTRING) { 9706 } else if (CurrentToken() == Token::kSTRING) {
9620 primary = ParseStringLiteral(); 9707 primary = ParseStringLiteral();
9621 } else if (CurrentToken() == Token::kNEW) { 9708 } else if (CurrentToken() == Token::kNEW) {
9622 primary = ParseNewOperator(); 9709 ConsumeToken();
9710 primary = ParseNewOperator(Token::kNEW);
9623 } else if (CurrentToken() == Token::kCONST) { 9711 } else if (CurrentToken() == Token::kCONST) {
9624 if ((LookaheadToken(1) == Token::kLT) || 9712 if ((LookaheadToken(1) == Token::kLT) ||
9625 (LookaheadToken(1) == Token::kLBRACK) || 9713 (LookaheadToken(1) == Token::kLBRACK) ||
9626 (LookaheadToken(1) == Token::kINDEX) || 9714 (LookaheadToken(1) == Token::kINDEX) ||
9627 (LookaheadToken(1) == Token::kLBRACE)) { 9715 (LookaheadToken(1) == Token::kLBRACE)) {
9628 primary = ParseCompoundLiteral(); 9716 primary = ParseCompoundLiteral();
9629 } else { 9717 } else {
9630 primary = ParseNewOperator(); 9718 ConsumeToken();
9719 primary = ParseNewOperator(Token::kCONST);
9631 } 9720 }
9632 } else if (CurrentToken() == Token::kLT || 9721 } else if (CurrentToken() == Token::kLT ||
9633 CurrentToken() == Token::kLBRACK || 9722 CurrentToken() == Token::kLBRACK ||
9634 CurrentToken() == Token::kINDEX || 9723 CurrentToken() == Token::kINDEX ||
9635 CurrentToken() == Token::kLBRACE) { 9724 CurrentToken() == Token::kLBRACE) {
9636 primary = ParseCompoundLiteral(); 9725 primary = ParseCompoundLiteral();
9637 } else if (CurrentToken() == Token::kSUPER) { 9726 } else if (CurrentToken() == Token::kSUPER) {
9638 if (current_function().is_static()) { 9727 if (current_function().is_static()) {
9639 ErrorMsg("cannot access superclass from static method"); 9728 ErrorMsg("cannot access superclass from static method");
9640 } 9729 }
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
9990 void Parser::SkipQualIdent() { 10079 void Parser::SkipQualIdent() {
9991 ASSERT(IsIdentifier()); 10080 ASSERT(IsIdentifier());
9992 ConsumeToken(); 10081 ConsumeToken();
9993 if (CurrentToken() == Token::kPERIOD) { 10082 if (CurrentToken() == Token::kPERIOD) {
9994 ConsumeToken(); // Consume the kPERIOD token. 10083 ConsumeToken(); // Consume the kPERIOD token.
9995 ExpectIdentifier("identifier expected after '.'"); 10084 ExpectIdentifier("identifier expected after '.'");
9996 } 10085 }
9997 } 10086 }
9998 10087
9999 } // namespace dart 10088 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/parser.h ('k') | runtime/vm/raw_object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698