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

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

Issue 1316373002: Remove more GrowableObjectArray usage in parser (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Address comments Created 5 years, 3 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
« no previous file with comments | « runtime/vm/parser.h ('k') | no next file » | 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 "platform/utils.h" 8 #include "platform/utils.h"
9 #include "vm/ast_transformer.h" 9 #include "vm/ast_transformer.h"
10 #include "vm/bootstrap.h" 10 #include "vm/bootstrap.h"
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 String* dict_name; 678 String* dict_name;
679 ParamList params; 679 ParamList params;
680 RawFunction::Kind kind; 680 RawFunction::Kind kind;
681 // NULL for functions, field object for static or instance fields. 681 // NULL for functions, field object for static or instance fields.
682 Field* field_; 682 Field* field_;
683 }; 683 };
684 684
685 685
686 class ClassDesc : public ValueObject { 686 class ClassDesc : public ValueObject {
687 public: 687 public:
688 ClassDesc(const Class& cls, 688 ClassDesc(Zone* zone,
689 const Class& cls,
689 const String& cls_name, 690 const String& cls_name,
690 bool is_interface, 691 bool is_interface,
691 intptr_t token_pos) 692 intptr_t token_pos)
692 : clazz_(cls), 693 : zone_(zone),
694 clazz_(cls),
693 class_name_(cls_name), 695 class_name_(cls_name),
694 token_pos_(token_pos), 696 token_pos_(token_pos),
695 functions_(GrowableObjectArray::Handle(GrowableObjectArray::New())), 697 functions_(zone, 4),
696 fields_(GrowableObjectArray::Handle(GrowableObjectArray::New())) { 698 fields_(zone, 4) {
697 } 699 }
698 700
699 void AddFunction(const Function& function) { 701 void AddFunction(const Function& function) {
700 functions_.Add(function); 702 functions_.Add(&Function::ZoneHandle(zone_, function.raw()));
701 } 703 }
702 704
703 const GrowableObjectArray& functions() const { 705 const GrowableArray<const Function*>& functions() const {
704 return functions_; 706 return functions_;
705 } 707 }
706 708
707 void AddField(const Field& field) { 709 void AddField(const Field& field) {
708 fields_.Add(field); 710 fields_.Add(&Field::ZoneHandle(zone_, field.raw()));
709 } 711 }
710 712
711 const GrowableObjectArray& fields() const { 713 const GrowableArray<const Field*>& fields() const {
712 return fields_; 714 return fields_;
713 } 715 }
714 716
715 const Class& clazz() const { 717 const Class& clazz() const {
716 return clazz_; 718 return clazz_;
717 } 719 }
718 720
719 const String& class_name() const { 721 const String& class_name() const {
720 return class_name_; 722 return class_name_;
721 } 723 }
722 724
723 bool has_constructor() const { 725 bool has_constructor() const {
724 Function& func = Function::Handle(); 726 for (int i = 0; i < functions_.length(); i++) {
725 for (int i = 0; i < functions_.Length(); i++) { 727 const Function* func = functions_.At(i);
726 func ^= functions_.At(i); 728 if (func->kind() == RawFunction::kConstructor) {
727 if (func.kind() == RawFunction::kConstructor) {
728 return true; 729 return true;
729 } 730 }
730 } 731 }
731 return false; 732 return false;
732 } 733 }
733 734
734 intptr_t token_pos() const { 735 intptr_t token_pos() const {
735 return token_pos_; 736 return token_pos_;
736 } 737 }
737 738
738 void AddMember(const MemberDesc& member) { 739 void AddMember(const MemberDesc& member) {
739 members_.Add(member); 740 members_.Add(member);
740 } 741 }
741 742
742 const GrowableArray<MemberDesc>& members() const { 743 const GrowableArray<MemberDesc>& members() const {
743 return members_; 744 return members_;
744 } 745 }
745 746
746 MemberDesc* LookupMember(const String& name) const { 747 MemberDesc* LookupMember(const String& name) const {
747 for (int i = 0; i < members_.length(); i++) { 748 for (int i = 0; i < members_.length(); i++) {
748 if (name.Equals(*members_[i].name)) { 749 if (name.Equals(*members_[i].name)) {
749 return &members_[i]; 750 return &members_[i];
750 } 751 }
751 } 752 }
752 return NULL; 753 return NULL;
753 } 754 }
754 755
756 RawArray* MakeFunctionsArray() {
757 const intptr_t len = functions_.length();
758 const Array& res = Array::Handle(zone_, Array::New(len, Heap::kOld));
759 for (intptr_t i = 0; i < len; i++) {
760 res.SetAt(i, *functions_[i]);
761 }
762 return res.raw();
763 }
764
755 private: 765 private:
766 Zone* zone_;
756 const Class& clazz_; 767 const Class& clazz_;
757 const String& class_name_; 768 const String& class_name_;
758 intptr_t token_pos_; // Token index of "class" keyword. 769 intptr_t token_pos_; // Token index of "class" keyword.
759 GrowableObjectArray& functions_; 770 GrowableArray<const Function*> functions_;
760 GrowableObjectArray& fields_; 771 GrowableArray<const Field*> fields_;
761 GrowableArray<MemberDesc> members_; 772 GrowableArray<MemberDesc> members_;
762 }; 773 };
763 774
764 775
765 struct TopLevel { 776 class TopLevel : public ValueObject {
766 TopLevel() : 777 public:
767 fields(GrowableObjectArray::Handle(GrowableObjectArray::New())), 778 explicit TopLevel(Zone* zone) :
768 functions(GrowableObjectArray::Handle(GrowableObjectArray::New())) { } 779 zone_(zone),
780 fields_(zone, 4),
781 functions_(zone, 4) { }
769 782
770 GrowableObjectArray& fields; 783 void AddField(const Field& field) {
771 GrowableObjectArray& functions; 784 fields_.Add(&Field::ZoneHandle(zone_, field.raw()));
785 }
786
787 void AddFunction(const Function& function) {
788 functions_.Add(&Function::ZoneHandle(zone_, function.raw()));
789 }
790
791 const GrowableArray<const Field*>& fields() const {
792 return fields_;
793 }
794
795 const GrowableArray<const Function*>& functions() const {
796 return functions_;
797 }
798
799 private:
800 Zone* zone_;
801 GrowableArray<const Field*> fields_;
802 GrowableArray<const Function*> functions_;
772 }; 803 };
773 804
774 805
775 void Parser::ParseClass(const Class& cls) { 806 void Parser::ParseClass(const Class& cls) {
776 if (!cls.is_synthesized_class()) { 807 if (!cls.is_synthesized_class()) {
777 Thread* thread = Thread::Current(); 808 Thread* thread = Thread::Current();
778 Zone* zone = thread->zone(); 809 Zone* zone = thread->zone();
779 CSTAT_TIMER_SCOPE(thread, parser_timer); 810 CSTAT_TIMER_SCOPE(thread, parser_timer);
780 ASSERT(thread->long_jump_base()->IsSafeToJump()); 811 ASSERT(thread->long_jump_base()->IsSafeToJump());
781 const Script& script = Script::Handle(zone, cls.script()); 812 const Script& script = Script::Handle(zone, cls.script());
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
1172 const Script& script = Script::Handle( 1203 const Script& script = Script::Handle(
1173 Script::New(uri, source, RawScript::kSourceTag)); 1204 Script::New(uri, source, RawScript::kSourceTag));
1174 const Library& owning_library = Library::Handle(owning_class.library()); 1205 const Library& owning_library = Library::Handle(owning_class.library());
1175 const String& private_key = String::Handle(owning_library.private_key()); 1206 const String& private_key = String::Handle(owning_library.private_key());
1176 script.Tokenize(private_key); 1207 script.Tokenize(private_key);
1177 const intptr_t token_pos = 0; 1208 const intptr_t token_pos = 0;
1178 Parser parser(script, owning_library, token_pos); 1209 Parser parser(script, owning_library, token_pos);
1179 parser.is_top_level_ = true; 1210 parser.is_top_level_ = true;
1180 parser.set_current_class(owning_class); 1211 parser.set_current_class(owning_class);
1181 const String& class_name = String::Handle(owning_class.Name()); 1212 const String& class_name = String::Handle(owning_class.Name());
1182 ClassDesc members(owning_class, class_name, false, token_pos); 1213 ClassDesc members(stack_zone.GetZone(),
1214 owning_class,
1215 class_name,
1216 false, /* is_interface */
1217 token_pos);
1183 const intptr_t metadata_pos = parser.SkipMetadata(); 1218 const intptr_t metadata_pos = parser.SkipMetadata();
1184 parser.ParseClassMemberDefinition(&members, metadata_pos); 1219 parser.ParseClassMemberDefinition(&members, metadata_pos);
1185 ASSERT(members.functions().Length() == 1); 1220 ASSERT(members.functions().length() == 1);
1186 const Function& func = 1221 const Function& func = *members.functions().At(0);
1187 Function::ZoneHandle(Function::RawCast(members.functions().At(0)));
1188 func.set_eval_script(script); 1222 func.set_eval_script(script);
1189 ParsedFunction* parsed_function = new ParsedFunction(thread, func); 1223 ParsedFunction* parsed_function = new ParsedFunction(thread, func);
1190 Parser::ParseFunction(parsed_function); 1224 Parser::ParseFunction(parsed_function);
1191 return func.raw(); 1225 return func.raw();
1192 } else { 1226 } else {
1193 const Error& error = Error::Handle(isolate->object_store()->sticky_error()); 1227 const Error& error = Error::Handle(isolate->object_store()->sticky_error());
1194 isolate->object_store()->clear_sticky_error(); 1228 isolate->object_store()->clear_sticky_error();
1195 return error.raw(); 1229 return error.raw();
1196 } 1230 }
1197 UNREACHABLE(); 1231 UNREACHABLE();
(...skipping 3405 matching lines...) Expand 10 before | Expand all | Expand 10 after
4603 SkipMetadata(); 4637 SkipMetadata();
4604 if (is_patch_source() && 4638 if (is_patch_source() &&
4605 (CurrentToken() == Token::kIDENT) && 4639 (CurrentToken() == Token::kIDENT) &&
4606 CurrentLiteral()->Equals("patch")) { 4640 CurrentLiteral()->Equals("patch")) {
4607 ConsumeToken(); 4641 ConsumeToken();
4608 } else if (CurrentToken() == Token::kABSTRACT) { 4642 } else if (CurrentToken() == Token::kABSTRACT) {
4609 ConsumeToken(); 4643 ConsumeToken();
4610 } 4644 }
4611 ExpectToken(Token::kCLASS); 4645 ExpectToken(Token::kCLASS);
4612 const intptr_t class_pos = TokenPos(); 4646 const intptr_t class_pos = TokenPos();
4613 ClassDesc members(cls, class_name, false, class_pos); 4647 ClassDesc members(Z, cls, class_name, false, class_pos);
4614 while (CurrentToken() != Token::kLBRACE) { 4648 while (CurrentToken() != Token::kLBRACE) {
4615 ConsumeToken(); 4649 ConsumeToken();
4616 } 4650 }
4617 ExpectToken(Token::kLBRACE); 4651 ExpectToken(Token::kLBRACE);
4618 while (CurrentToken() != Token::kRBRACE) { 4652 while (CurrentToken() != Token::kRBRACE) {
4619 intptr_t metadata_pos = SkipMetadata(); 4653 intptr_t metadata_pos = SkipMetadata();
4620 ParseClassMemberDefinition(&members, metadata_pos); 4654 ParseClassMemberDefinition(&members, metadata_pos);
4621 } 4655 }
4622 ExpectToken(Token::kRBRACE); 4656 ExpectToken(Token::kRBRACE);
4623 4657
4624 CheckConstructors(&members); 4658 CheckConstructors(&members);
4625 4659
4626 // Need to compute this here since MakeArray() will clear the 4660 // Need to compute this here since MakeArray() will clear the
4627 // functions array in members. 4661 // functions array in members.
4628 const bool need_implicit_constructor = 4662 const bool need_implicit_constructor =
4629 !members.has_constructor() && !cls.is_patch(); 4663 !members.has_constructor() && !cls.is_patch();
4630 4664
4631 cls.AddFields(members.fields()); 4665 cls.AddFields(members.fields());
4632 4666
4633 // Creating a new array for functions marks the class as parsed. 4667 // Creating a new array for functions marks the class as parsed.
4634 const Array& array = Array::Handle(Z, Array::MakeArray(members.functions())); 4668 Array& array = Array::Handle(Z, members.MakeFunctionsArray());
4635 cls.SetFunctions(array); 4669 cls.SetFunctions(array);
4636 4670
4637 // Add an implicit constructor if no explicit constructor is present. 4671 // Add an implicit constructor if no explicit constructor is present.
4638 // No implicit constructors are needed for patch classes. 4672 // No implicit constructors are needed for patch classes.
4639 if (need_implicit_constructor) { 4673 if (need_implicit_constructor) {
4640 AddImplicitConstructor(cls); 4674 AddImplicitConstructor(cls);
4641 } 4675 }
4642 4676
4643 if (cls.is_patch()) { 4677 if (cls.is_patch()) {
4644 // Apply the changes to the patched class looked up above. 4678 // Apply the changes to the patched class looked up above.
(...skipping 10 matching lines...) Expand all
4655 4689
4656 4690
4657 void Parser::ParseEnumDefinition(const Class& cls) { 4691 void Parser::ParseEnumDefinition(const Class& cls) {
4658 TRACE_PARSER("ParseEnumDefinition"); 4692 TRACE_PARSER("ParseEnumDefinition");
4659 INC_STAT(I, num_classes_compiled, 1); 4693 INC_STAT(I, num_classes_compiled, 1);
4660 4694
4661 SkipMetadata(); 4695 SkipMetadata();
4662 ExpectToken(Token::kENUM); 4696 ExpectToken(Token::kENUM);
4663 4697
4664 const String& enum_name = String::Handle(Z, cls.Name()); 4698 const String& enum_name = String::Handle(Z, cls.Name());
4665 ClassDesc enum_members(cls, enum_name, false, cls.token_pos()); 4699 ClassDesc enum_members(Z, cls, enum_name, false, cls.token_pos());
4666 4700
4667 // Add instance field 'final int index'. 4701 // Add instance field 'final int index'.
4668 Field& index_field = Field::ZoneHandle(Z); 4702 Field& index_field = Field::ZoneHandle(Z);
4669 const Type& int_type = Type::Handle(Z, Type::IntType()); 4703 const Type& int_type = Type::Handle(Z, Type::IntType());
4670 const Type& dynamic_type = Type::Handle(Type::DynamicType()); 4704 const Type& dynamic_type = Type::Handle(Type::DynamicType());
4671 index_field = Field::New(Symbols::Index(), 4705 index_field = Field::New(Symbols::Index(),
4672 false, // Not static. 4706 false, // Not static.
4673 true, // Field is final. 4707 true, // Field is final.
4674 false, // Not const. 4708 false, // Not const.
4675 true, // Is reflectable. 4709 true, // Is reflectable.
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
4813 enum_members.AddFunction(to_string_func); 4847 enum_members.AddFunction(to_string_func);
4814 4848
4815 // Clone the hashCode getter function from the helper class. 4849 // Clone the hashCode getter function from the helper class.
4816 Function& hash_code_func = Function::Handle(I, 4850 Function& hash_code_func = Function::Handle(I,
4817 helper_class.LookupDynamicFunctionAllowPrivate(Symbols::hashCode())); 4851 helper_class.LookupDynamicFunctionAllowPrivate(Symbols::hashCode()));
4818 ASSERT(!hash_code_func.IsNull()); 4852 ASSERT(!hash_code_func.IsNull());
4819 hash_code_func = hash_code_func.Clone(cls); 4853 hash_code_func = hash_code_func.Clone(cls);
4820 enum_members.AddFunction(hash_code_func); 4854 enum_members.AddFunction(hash_code_func);
4821 4855
4822 cls.AddFields(enum_members.fields()); 4856 cls.AddFields(enum_members.fields());
4823 const Array& functions = 4857 const Array& functions = Array::Handle(Z, enum_members.MakeFunctionsArray());
4824 Array::Handle(Z, Array::MakeArray(enum_members.functions()));
4825 cls.SetFunctions(functions); 4858 cls.SetFunctions(functions);
4826 } 4859 }
4827 4860
4828 4861
4829 // Add an implicit constructor to the given class. 4862 // Add an implicit constructor to the given class.
4830 void Parser::AddImplicitConstructor(const Class& cls) { 4863 void Parser::AddImplicitConstructor(const Class& cls) {
4831 // The implicit constructor is unnamed, has no explicit parameter. 4864 // The implicit constructor is unnamed, has no explicit parameter.
4832 String& ctor_name = String::ZoneHandle(Z, cls.Name()); 4865 String& ctor_name = String::ZoneHandle(Z, cls.Name());
4833 ctor_name = Symbols::FromConcat(ctor_name, Symbols::Dot()); 4866 ctor_name = Symbols::FromConcat(ctor_name, Symbols::Dot());
4834 // To indicate that this is an implicit constructor, we set the 4867 // To indicate that this is an implicit constructor, we set the
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after
5390 ReportError(name_pos, "setter for '%s' is already defined", 5423 ReportError(name_pos, "setter for '%s' is already defined",
5391 var_name.ToCString()); 5424 var_name.ToCString());
5392 } 5425 }
5393 5426
5394 const bool is_reflectable = 5427 const bool is_reflectable =
5395 !(library_.is_dart_scheme() && library_.IsPrivate(var_name)); 5428 !(library_.is_dart_scheme() && library_.IsPrivate(var_name));
5396 field = Field::New(var_name, is_static, is_final, is_const, is_reflectable, 5429 field = Field::New(var_name, is_static, is_final, is_const, is_reflectable,
5397 current_class(), name_pos); 5430 current_class(), name_pos);
5398 field.set_type(type); 5431 field.set_type(type);
5399 field.set_value(Object::null_instance()); 5432 field.set_value(Object::null_instance());
5400 top_level->fields.Add(field); 5433 top_level->AddField(field);
5401 library_.AddObject(field, var_name); 5434 library_.AddObject(field, var_name);
5402 if (metadata_pos >= 0) { 5435 if (metadata_pos >= 0) {
5403 library_.AddFieldMetadata(field, metadata_pos); 5436 library_.AddFieldMetadata(field, metadata_pos);
5404 } 5437 }
5405 if (CurrentToken() == Token::kASSIGN) { 5438 if (CurrentToken() == Token::kASSIGN) {
5406 ConsumeToken(); 5439 ConsumeToken();
5407 Instance& field_value = Instance::Handle(Z, Object::sentinel().raw()); 5440 Instance& field_value = Instance::Handle(Z, Object::sentinel().raw());
5408 bool has_simple_literal = false; 5441 bool has_simple_literal = false;
5409 if (LookaheadToken(1) == Token::kSEMICOLON) { 5442 if (LookaheadToken(1) == Token::kSEMICOLON) {
5410 has_simple_literal = IsSimpleLiteral(type, &field_value); 5443 has_simple_literal = IsSimpleLiteral(type, &field_value);
(...skipping 12 matching lines...) Expand all
5423 /* is_abstract = */ false, 5456 /* is_abstract = */ false,
5424 /* is_external = */ false, 5457 /* is_external = */ false,
5425 /* is_native = */ false, 5458 /* is_native = */ false,
5426 current_class(), 5459 current_class(),
5427 name_pos); 5460 name_pos);
5428 getter.set_result_type(type); 5461 getter.set_result_type(type);
5429 getter.set_is_debuggable(false); 5462 getter.set_is_debuggable(false);
5430 if (library_.is_dart_scheme() && library_.IsPrivate(var_name)) { 5463 if (library_.is_dart_scheme() && library_.IsPrivate(var_name)) {
5431 getter.set_is_reflectable(false); 5464 getter.set_is_reflectable(false);
5432 } 5465 }
5433 top_level->functions.Add(getter); 5466 top_level->AddFunction(getter);
5434 } 5467 }
5435 } else if (is_final) { 5468 } else if (is_final) {
5436 ReportError(name_pos, "missing initializer for final or const variable"); 5469 ReportError(name_pos, "missing initializer for final or const variable");
5437 } 5470 }
5438 5471
5439 if (CurrentToken() == Token::kCOMMA) { 5472 if (CurrentToken() == Token::kCOMMA) {
5440 ConsumeToken(); 5473 ConsumeToken();
5441 } else if (CurrentToken() == Token::kSEMICOLON) { 5474 } else if (CurrentToken() == Token::kSEMICOLON) {
5442 ConsumeToken(); 5475 ConsumeToken();
5443 break; 5476 break;
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
5568 is_native, 5601 is_native,
5569 current_class(), 5602 current_class(),
5570 decl_begin_pos)); 5603 decl_begin_pos));
5571 func.set_result_type(result_type); 5604 func.set_result_type(result_type);
5572 func.set_end_token_pos(function_end_pos); 5605 func.set_end_token_pos(function_end_pos);
5573 func.set_modifier(func_modifier); 5606 func.set_modifier(func_modifier);
5574 if (library_.is_dart_scheme() && library_.IsPrivate(func_name)) { 5607 if (library_.is_dart_scheme() && library_.IsPrivate(func_name)) {
5575 func.set_is_reflectable(false); 5608 func.set_is_reflectable(false);
5576 } 5609 }
5577 AddFormalParamsToFunction(&params, func); 5610 AddFormalParamsToFunction(&params, func);
5578 top_level->functions.Add(func); 5611 top_level->AddFunction(func);
5579 if (!is_patch) { 5612 if (!is_patch) {
5580 library_.AddObject(func, func_name); 5613 library_.AddObject(func, func_name);
5581 } else { 5614 } else {
5582 library_.ReplaceObject(func, func_name); 5615 library_.ReplaceObject(func, func_name);
5583 } 5616 }
5584 if (metadata_pos >= 0) { 5617 if (metadata_pos >= 0) {
5585 library_.AddFunctionMetadata(func, metadata_pos); 5618 library_.AddFunctionMetadata(func, metadata_pos);
5586 } 5619 }
5587 } 5620 }
5588 5621
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
5722 func.set_result_type(result_type); 5755 func.set_result_type(result_type);
5723 func.set_end_token_pos(accessor_end_pos); 5756 func.set_end_token_pos(accessor_end_pos);
5724 func.set_modifier(func_modifier); 5757 func.set_modifier(func_modifier);
5725 if (is_native) { 5758 if (is_native) {
5726 func.set_is_debuggable(false); 5759 func.set_is_debuggable(false);
5727 } 5760 }
5728 if (library_.is_dart_scheme() && library_.IsPrivate(accessor_name)) { 5761 if (library_.is_dart_scheme() && library_.IsPrivate(accessor_name)) {
5729 func.set_is_reflectable(false); 5762 func.set_is_reflectable(false);
5730 } 5763 }
5731 AddFormalParamsToFunction(&params, func); 5764 AddFormalParamsToFunction(&params, func);
5732 top_level->functions.Add(func); 5765 top_level->AddFunction(func);
5733 if (!is_patch) { 5766 if (!is_patch) {
5734 library_.AddObject(func, accessor_name); 5767 library_.AddObject(func, accessor_name);
5735 } else { 5768 } else {
5736 library_.ReplaceObject(func, accessor_name); 5769 library_.ReplaceObject(func, accessor_name);
5737 } 5770 }
5738 if (metadata_pos >= 0) { 5771 if (metadata_pos >= 0) {
5739 library_.AddFunctionMetadata(func, metadata_pos); 5772 library_.AddFunctionMetadata(func, metadata_pos);
5740 } 5773 }
5741 } 5774 }
5742 5775
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
6033 void Parser::ParseTopLevel() { 6066 void Parser::ParseTopLevel() {
6034 TRACE_PARSER("ParseTopLevel"); 6067 TRACE_PARSER("ParseTopLevel");
6035 // Collect the classes found at the top level in this growable array. 6068 // Collect the classes found at the top level in this growable array.
6036 // They need to be registered with class finalization after parsing 6069 // They need to be registered with class finalization after parsing
6037 // has been completed. 6070 // has been completed.
6038 ObjectStore* object_store = I->object_store(); 6071 ObjectStore* object_store = I->object_store();
6039 const GrowableObjectArray& pending_classes = 6072 const GrowableObjectArray& pending_classes =
6040 GrowableObjectArray::Handle(Z, object_store->pending_classes()); 6073 GrowableObjectArray::Handle(Z, object_store->pending_classes());
6041 SetPosition(0); 6074 SetPosition(0);
6042 is_top_level_ = true; 6075 is_top_level_ = true;
6043 TopLevel top_level; 6076 TopLevel top_level(Z);
6044 Class& toplevel_class = Class::Handle(Z, 6077 Class& toplevel_class = Class::Handle(Z,
6045 Class::New(Symbols::TopLevel(), script_, TokenPos())); 6078 Class::New(Symbols::TopLevel(), script_, TokenPos()));
6046 toplevel_class.set_library(library_); 6079 toplevel_class.set_library(library_);
6047 6080
6048 if (is_library_source() || is_patch_source()) { 6081 if (is_library_source() || is_patch_source()) {
6049 set_current_class(toplevel_class); 6082 set_current_class(toplevel_class);
6050 ParseLibraryDefinition(); 6083 ParseLibraryDefinition();
6051 } else if (is_part_source()) { 6084 } else if (is_part_source()) {
6052 ParsePartHeader(); 6085 ParsePartHeader();
6053 } 6086 }
(...skipping 26 matching lines...) Expand all
6080 ParseTopLevelAccessor(&top_level, metadata_pos); 6113 ParseTopLevelAccessor(&top_level, metadata_pos);
6081 } else if (CurrentToken() == Token::kEOS) { 6114 } else if (CurrentToken() == Token::kEOS) {
6082 break; 6115 break;
6083 } else { 6116 } else {
6084 UnexpectedToken(); 6117 UnexpectedToken();
6085 } 6118 }
6086 } 6119 }
6087 } 6120 }
6088 6121
6089 if ((library_.num_anonymous_classes() == 0) || 6122 if ((library_.num_anonymous_classes() == 0) ||
6090 (top_level.fields.Length() > 0) || (top_level.functions.Length() > 0)) { 6123 (top_level.fields().length() > 0) ||
6091 toplevel_class.AddFields(top_level.fields); 6124 (top_level.functions().length() > 0)) {
6092 6125 toplevel_class.AddFields(top_level.fields());
6093 const Array& array = Array::Handle(Z, 6126 const intptr_t len = top_level.functions().length();
6094 Array::MakeArray(top_level.functions)); 6127 const Array& array = Array::Handle(Z, Array::New(len, Heap::kOld));
6128 for (intptr_t i = 0; i < len; i++) {
6129 array.SetAt(i, *top_level.functions()[i]);
6130 }
6095 toplevel_class.SetFunctions(array); 6131 toplevel_class.SetFunctions(array);
6096
6097 library_.AddAnonymousClass(toplevel_class); 6132 library_.AddAnonymousClass(toplevel_class);
6098 pending_classes.Add(toplevel_class, Heap::kOld); 6133 pending_classes.Add(toplevel_class, Heap::kOld);
6099 } 6134 }
6100 } 6135 }
6101 6136
6102 6137
6103 void Parser::ChainNewBlock(LocalScope* outer_scope) { 6138 void Parser::ChainNewBlock(LocalScope* outer_scope) {
6104 Block* block = new(Z) Block( 6139 Block* block = new(Z) Block(
6105 current_block_, 6140 current_block_,
6106 outer_scope, 6141 outer_scope,
(...skipping 8176 matching lines...) Expand 10 before | Expand all | Expand 10 after
14283 void Parser::SkipQualIdent() { 14318 void Parser::SkipQualIdent() {
14284 ASSERT(IsIdentifier()); 14319 ASSERT(IsIdentifier());
14285 ConsumeToken(); 14320 ConsumeToken();
14286 if (CurrentToken() == Token::kPERIOD) { 14321 if (CurrentToken() == Token::kPERIOD) {
14287 ConsumeToken(); // Consume the kPERIOD token. 14322 ConsumeToken(); // Consume the kPERIOD token.
14288 ExpectIdentifier("identifier expected after '.'"); 14323 ExpectIdentifier("identifier expected after '.'");
14289 } 14324 }
14290 } 14325 }
14291 14326
14292 } // namespace dart 14327 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698