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

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

Issue 1410383020: Eliminate all but one top-level class per library. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Address Review Comments Created 5 years 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') | 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 #include "vm/flags.h" 6 #include "vm/flags.h"
7 7
8 #ifndef DART_PRECOMPILED 8 #ifndef DART_PRECOMPILED
9 9
10 #include "lib/invocation_mirror.h" 10 #include "lib/invocation_mirror.h"
(...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after
1001 instantiator = parser.LookupReceiver(node_sequence->scope(), kTestOnly); 1001 instantiator = parser.LookupReceiver(node_sequence->scope(), kTestOnly);
1002 } 1002 }
1003 if (!parser.current_function().IsLocalFunction() || 1003 if (!parser.current_function().IsLocalFunction() ||
1004 ((instantiator != NULL) && instantiator->is_captured())) { 1004 ((instantiator != NULL) && instantiator->is_captured())) {
1005 parsed_function->set_instantiator(instantiator); 1005 parsed_function->set_instantiator(instantiator);
1006 } 1006 }
1007 } 1007 }
1008 } 1008 }
1009 1009
1010 1010
1011 RawObject* Parser::ParseMetadata(const Class& cls, intptr_t token_pos) { 1011 RawObject* Parser::ParseMetadata(const Field& meta_data) {
1012 LongJumpScope jump; 1012 LongJumpScope jump;
1013 if (setjmp(*jump.Set()) == 0) { 1013 if (setjmp(*jump.Set()) == 0) {
1014 Thread* thread = Thread::Current(); 1014 Thread* thread = Thread::Current();
1015 StackZone stack_zone(thread); 1015 StackZone stack_zone(thread);
1016 Zone* zone = stack_zone.GetZone(); 1016 Zone* zone = stack_zone.GetZone();
1017 const Script& script = Script::Handle(zone, cls.script()); 1017 const Class& owner_class = Class::Handle(zone, meta_data.owner());
1018 const Script& script = Script::Handle(zone, meta_data.script());
1019 const intptr_t token_pos = meta_data.token_pos();
1018 // Parsing metadata can involve following paths in the parser that are 1020 // Parsing metadata can involve following paths in the parser that are
1019 // normally used for expressions and assume current_function is non-null, 1021 // normally used for expressions and assume current_function is non-null,
1020 // so we create a fake function to use as the current_function rather than 1022 // so we create a fake function to use as the current_function rather than
1021 // scattering special cases throughout the parser. 1023 // scattering special cases throughout the parser.
1022 const Function& fake_function = Function::ZoneHandle(zone, Function::New( 1024 const Function& fake_function = Function::ZoneHandle(zone, Function::New(
1023 Symbols::At(), 1025 Symbols::At(),
1024 RawFunction::kRegularFunction, 1026 RawFunction::kRegularFunction,
1025 true, // is_static 1027 true, // is_static
1026 false, // is_const 1028 false, // is_const
1027 false, // is_abstract 1029 false, // is_abstract
1028 false, // is_external 1030 false, // is_external
1029 false, // is_native 1031 false, // is_native
1030 cls, 1032 Object::Handle(zone, meta_data.RawOwner()),
1031 token_pos)); 1033 token_pos));
1032 fake_function.set_is_debuggable(false); 1034 fake_function.set_is_debuggable(false);
1033 ParsedFunction* parsed_function = 1035 ParsedFunction* parsed_function =
1034 new ParsedFunction(thread, fake_function); 1036 new ParsedFunction(thread, fake_function);
1035 Parser parser(script, parsed_function, token_pos); 1037 Parser parser(script, parsed_function, token_pos);
1036 parser.set_current_class(cls); 1038 parser.set_current_class(owner_class);
1037 1039
1038 RawObject* metadata = parser.EvaluateMetadata(); 1040 RawObject* metadata = parser.EvaluateMetadata();
1039 return metadata; 1041 return metadata;
1040 } else { 1042 } else {
1041 Thread* thread = Thread::Current(); 1043 Thread* thread = Thread::Current();
1042 Isolate* isolate = thread->isolate(); 1044 Isolate* isolate = thread->isolate();
1043 StackZone stack_zone(thread); 1045 StackZone stack_zone(thread);
1044 Zone* zone = stack_zone.GetZone(); 1046 Zone* zone = stack_zone.GetZone();
1045 Error& error = Error::Handle(zone); 1047 Error& error = Error::Handle(zone);
1046 error = isolate->object_store()->sticky_error(); 1048 error = isolate->object_store()->sticky_error();
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1142 return CloseBlock(); 1144 return CloseBlock();
1143 } 1145 }
1144 1146
1145 1147
1146 ParsedFunction* Parser::ParseStaticFieldInitializer(const Field& field) { 1148 ParsedFunction* Parser::ParseStaticFieldInitializer(const Field& field) {
1147 ASSERT(field.is_static()); 1149 ASSERT(field.is_static());
1148 Thread* thread = Thread::Current(); 1150 Thread* thread = Thread::Current();
1149 // TODO(koda): Should there be a StackZone here? 1151 // TODO(koda): Should there be a StackZone here?
1150 Zone* zone = thread->zone(); 1152 Zone* zone = thread->zone();
1151 1153
1152 const Class& script_cls = Class::Handle(zone, field.origin());
1153 const Script& script = Script::Handle(zone, script_cls.script());
1154
1155 const String& field_name = String::Handle(zone, field.name()); 1154 const String& field_name = String::Handle(zone, field.name());
1156 String& init_name = String::Handle(zone, 1155 String& init_name = String::Handle(zone,
1157 Symbols::FromConcat(Symbols::InitPrefix(), field_name)); 1156 Symbols::FromConcat(Symbols::InitPrefix(), field_name));
1158 1157
1158 const Script& script = Script::Handle(zone, field.script());
1159 Object& initializer_owner = Object::Handle(field.owner()); 1159 Object& initializer_owner = Object::Handle(field.owner());
1160 if (field.owner() != field.origin()) { 1160 initializer_owner =
1161 initializer_owner = 1161 PatchClass::New(Class::Handle(field.owner()), script);
1162 PatchClass::New(Class::Handle(field.owner()), script_cls);
1163 }
1164 1162
1165 const Function& initializer = Function::ZoneHandle(zone, 1163 const Function& initializer = Function::ZoneHandle(zone,
1166 Function::New(init_name, 1164 Function::New(init_name,
1167 RawFunction::kImplicitStaticFinalGetter, 1165 RawFunction::kImplicitStaticFinalGetter,
1168 true, // static 1166 true, // static
1169 false, // !const 1167 false, // !const
1170 false, // !abstract 1168 false, // !abstract
1171 false, // !external 1169 false, // !external
1172 false, // !native 1170 false, // !native
1173 initializer_owner, 1171 initializer_owner,
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after
1844 1842
1845 // Add implicit closure object parameter. 1843 // Add implicit closure object parameter.
1846 func_params.AddFinalParameter( 1844 func_params.AddFinalParameter(
1847 TokenPos(), 1845 TokenPos(),
1848 &Symbols::ClosureParameter(), 1846 &Symbols::ClosureParameter(),
1849 &Type::ZoneHandle(Z, Type::DynamicType())); 1847 &Type::ZoneHandle(Z, Type::DynamicType()));
1850 1848
1851 const bool no_explicit_default_values = false; 1849 const bool no_explicit_default_values = false;
1852 ParseFormalParameterList(no_explicit_default_values, false, &func_params); 1850 ParseFormalParameterList(no_explicit_default_values, false, &func_params);
1853 1851
1852 // In top-level and mixin functions, the source may be in a different
1853 // script than the script of the current class.
1854 Object& sig_func_owner = Object::Handle(Z, current_class().raw());
1855 if (current_class().script() != script_.raw()) {
1856 sig_func_owner = PatchClass::New(current_class(), script_);
1857 }
1858
1854 // The field 'is_static' has no meaning for signature functions. 1859 // The field 'is_static' has no meaning for signature functions.
1855 const Function& signature_function = Function::Handle(Z, 1860 const Function& signature_function = Function::Handle(Z,
1856 Function::New(*parameter.name, 1861 Function::New(*parameter.name,
1857 RawFunction::kSignatureFunction, 1862 RawFunction::kSignatureFunction,
1858 /* is_static = */ false, 1863 /* is_static = */ false,
1859 /* is_const = */ false, 1864 /* is_const = */ false,
1860 /* is_abstract = */ false, 1865 /* is_abstract = */ false,
1861 /* is_external = */ false, 1866 /* is_external = */ false,
1862 /* is_native = */ false, 1867 /* is_native = */ false,
1863 current_class(), 1868 sig_func_owner,
1864 parameter.name_pos)); 1869 parameter.name_pos));
1865 signature_function.set_result_type(result_type); 1870 signature_function.set_result_type(result_type);
1866 signature_function.set_is_debuggable(false); 1871 signature_function.set_is_debuggable(false);
1867 AddFormalParamsToFunction(&func_params, signature_function); 1872 AddFormalParamsToFunction(&func_params, signature_function);
1868 const String& signature = String::Handle(Z, 1873 const String& signature =
1869 signature_function.Signature()); 1874 String::Handle(Z, signature_function.Signature());
1870 // Lookup the signature class, i.e. the class whose name is the signature. 1875 // Lookup the signature class, i.e. the class whose name is the signature.
1871 // We only lookup in the current library, but not in its imports, and only 1876 // We only lookup in the current library, but not in its imports, and only
1872 // create a new canonical signature class if it does not exist yet. 1877 // create a new canonical signature class if it does not exist yet.
1873 Class& signature_class = Class::ZoneHandle(Z, 1878 Class& signature_class =
1874 library_.LookupLocalClass(signature)); 1879 Class::ZoneHandle(Z, library_.LookupLocalClass(signature));
1875 if (signature_class.IsNull()) { 1880 if (signature_class.IsNull()) {
1876 signature_class = Class::NewSignatureClass(signature, 1881 signature_class = Class::NewSignatureClass(signature,
1877 signature_function, 1882 signature_function,
1878 script_, 1883 script_,
1879 parameter.name_pos); 1884 parameter.name_pos);
1880 // Record the function signature class in the current library, unless 1885 // Record the function signature class in the current library, unless
1881 // we are currently skipping a formal parameter list, in which case 1886 // we are currently skipping a formal parameter list, in which case
1882 // the signature class could remain unfinalized. 1887 // the signature class could remain unfinalized.
1883 if (!params->skipped) { 1888 if (!params->skipped) {
1884 library_.AddClass(signature_class); 1889 library_.AddClass(signature_class);
(...skipping 2526 matching lines...) Expand 10 before | Expand all | Expand 10 after
4411 } else { 4416 } else {
4412 UnexpectedToken(); 4417 UnexpectedToken();
4413 } 4418 }
4414 current_member_ = NULL; 4419 current_member_ = NULL;
4415 CheckMemberNameConflict(members, &member); 4420 CheckMemberNameConflict(members, &member);
4416 members->AddMember(member); 4421 members->AddMember(member);
4417 } 4422 }
4418 4423
4419 4424
4420 void Parser::ParseEnumDeclaration(const GrowableObjectArray& pending_classes, 4425 void Parser::ParseEnumDeclaration(const GrowableObjectArray& pending_classes,
4421 const Class& toplevel_class, 4426 const Object& tl_owner,
4422 intptr_t metadata_pos) { 4427 intptr_t metadata_pos) {
4423 TRACE_PARSER("ParseEnumDeclaration"); 4428 TRACE_PARSER("ParseEnumDeclaration");
4424 const intptr_t declaration_pos = (metadata_pos > 0) ? metadata_pos 4429 const intptr_t declaration_pos = (metadata_pos > 0) ? metadata_pos
4425 : TokenPos(); 4430 : TokenPos();
4426 ConsumeToken(); 4431 ConsumeToken();
4427 const intptr_t name_pos = TokenPos(); 4432 const intptr_t name_pos = TokenPos();
4428 String* enum_name = 4433 String* enum_name =
4429 ExpectUserDefinedTypeIdentifier("enum type name expected"); 4434 ExpectUserDefinedTypeIdentifier("enum type name expected");
4430 if (FLAG_trace_parser) { 4435 if (FLAG_trace_parser) {
4431 OS::Print("TopLevel parsing enum '%s'\n", enum_name->ToCString()); 4436 OS::Print("TopLevel parsing enum '%s'\n", enum_name->ToCString());
(...skipping 21 matching lines...) Expand all
4453 if (!obj.IsNull()) { 4458 if (!obj.IsNull()) {
4454 ReportError(name_pos, "'%s' is already defined", enum_name->ToCString()); 4459 ReportError(name_pos, "'%s' is already defined", enum_name->ToCString());
4455 } 4460 }
4456 Class& cls = Class::Handle(Z); 4461 Class& cls = Class::Handle(Z);
4457 cls = Class::New(*enum_name, script_, declaration_pos); 4462 cls = Class::New(*enum_name, script_, declaration_pos);
4458 cls.set_library(library_); 4463 cls.set_library(library_);
4459 library_.AddClass(cls); 4464 library_.AddClass(cls);
4460 cls.set_is_synthesized_class(); 4465 cls.set_is_synthesized_class();
4461 cls.set_is_enum_class(); 4466 cls.set_is_enum_class();
4462 if (metadata_pos >= 0) { 4467 if (metadata_pos >= 0) {
4463 library_.AddClassMetadata(cls, toplevel_class, metadata_pos); 4468 library_.AddClassMetadata(cls, tl_owner, metadata_pos);
4464 } 4469 }
4465 cls.set_super_type(Type::Handle(Z, Type::ObjectType())); 4470 cls.set_super_type(Type::Handle(Z, Type::ObjectType()));
4466 pending_classes.Add(cls, Heap::kOld); 4471 pending_classes.Add(cls, Heap::kOld);
4467 } 4472 }
4468 4473
4469 4474
4470 void Parser::ParseClassDeclaration(const GrowableObjectArray& pending_classes, 4475 void Parser::ParseClassDeclaration(const GrowableObjectArray& pending_classes,
4471 const Class& toplevel_class, 4476 const Object& tl_owner,
4472 intptr_t metadata_pos) { 4477 intptr_t metadata_pos) {
4473 TRACE_PARSER("ParseClassDeclaration"); 4478 TRACE_PARSER("ParseClassDeclaration");
4474 bool is_patch = false; 4479 bool is_patch = false;
4475 bool is_abstract = false; 4480 bool is_abstract = false;
4476 intptr_t declaration_pos = (metadata_pos > 0) ? metadata_pos : TokenPos(); 4481 intptr_t declaration_pos = (metadata_pos > 0) ? metadata_pos : TokenPos();
4477 if (is_patch_source() && 4482 if (is_patch_source() &&
4478 (CurrentToken() == Token::kIDENT) && 4483 (CurrentToken() == Token::kIDENT) &&
4479 CurrentLiteral()->Equals("patch")) { 4484 CurrentLiteral()->Equals("patch")) {
4480 ConsumeToken(); 4485 ConsumeToken();
4481 is_patch = true; 4486 is_patch = true;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
4576 String::Handle(orig_bound.UserVisibleName()).ToCString()); 4581 String::Handle(orig_bound.UserVisibleName()).ToCString());
4577 } 4582 }
4578 } 4583 }
4579 cls.set_type_parameters(orig_type_parameters); 4584 cls.set_type_parameters(orig_type_parameters);
4580 } 4585 }
4581 4586
4582 if (is_abstract) { 4587 if (is_abstract) {
4583 cls.set_is_abstract(); 4588 cls.set_is_abstract();
4584 } 4589 }
4585 if (metadata_pos >= 0) { 4590 if (metadata_pos >= 0) {
4586 library_.AddClassMetadata(cls, toplevel_class, metadata_pos); 4591 library_.AddClassMetadata(cls, tl_owner, metadata_pos);
4587 } 4592 }
4588 4593
4589 const bool is_mixin_declaration = (CurrentToken() == Token::kASSIGN); 4594 const bool is_mixin_declaration = (CurrentToken() == Token::kASSIGN);
4590 if (is_mixin_declaration && is_patch) { 4595 if (is_mixin_declaration && is_patch) {
4591 ReportError(classname_pos, 4596 ReportError(classname_pos,
4592 "mixin application '%s' may not be a patch class", 4597 "mixin application '%s' may not be a patch class",
4593 class_name.ToCString()); 4598 class_name.ToCString());
4594 } 4599 }
4595 4600
4596 AbstractType& super_type = Type::Handle(Z); 4601 AbstractType& super_type = Type::Handle(Z);
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
4956 // compiled. 4961 // compiled.
4957 ctors.Add(member); 4962 ctors.Add(member);
4958 member = class_desc->LookupMember(*member->redirect_name); 4963 member = class_desc->LookupMember(*member->redirect_name);
4959 } 4964 }
4960 } 4965 }
4961 } 4966 }
4962 4967
4963 4968
4964 void Parser::ParseMixinAppAlias( 4969 void Parser::ParseMixinAppAlias(
4965 const GrowableObjectArray& pending_classes, 4970 const GrowableObjectArray& pending_classes,
4966 const Class& toplevel_class, 4971 const Object& tl_owner,
4967 intptr_t metadata_pos) { 4972 intptr_t metadata_pos) {
4968 TRACE_PARSER("ParseMixinAppAlias"); 4973 TRACE_PARSER("ParseMixinAppAlias");
4969 const intptr_t classname_pos = TokenPos(); 4974 const intptr_t classname_pos = TokenPos();
4970 String& class_name = *ExpectUserDefinedTypeIdentifier("class name expected"); 4975 String& class_name = *ExpectUserDefinedTypeIdentifier("class name expected");
4971 if (FLAG_trace_parser) { 4976 if (FLAG_trace_parser) {
4972 OS::Print("toplevel parsing mixin application alias class '%s'\n", 4977 OS::Print("toplevel parsing mixin application alias class '%s'\n",
4973 class_name.ToCString()); 4978 class_name.ToCString());
4974 } 4979 }
4975 const Object& obj = Object::Handle(Z, library_.LookupLocalObject(class_name)); 4980 const Object& obj = Object::Handle(Z, library_.LookupLocalObject(class_name));
4976 if (!obj.IsNull()) { 4981 if (!obj.IsNull()) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
5010 5015
5011 // This mixin application alias needs an implicit constructor, but it is 5016 // This mixin application alias needs an implicit constructor, but it is
5012 // too early to call 'AddImplicitConstructor(mixin_application)' here, 5017 // too early to call 'AddImplicitConstructor(mixin_application)' here,
5013 // because this class should be lazily compiled. 5018 // because this class should be lazily compiled.
5014 if (CurrentToken() == Token::kIMPLEMENTS) { 5019 if (CurrentToken() == Token::kIMPLEMENTS) {
5015 ParseInterfaceList(mixin_application); 5020 ParseInterfaceList(mixin_application);
5016 } 5021 }
5017 ExpectSemicolon(); 5022 ExpectSemicolon();
5018 pending_classes.Add(mixin_application, Heap::kOld); 5023 pending_classes.Add(mixin_application, Heap::kOld);
5019 if (metadata_pos >= 0) { 5024 if (metadata_pos >= 0) {
5020 library_.AddClassMetadata(mixin_application, toplevel_class, metadata_pos); 5025 library_.AddClassMetadata(mixin_application, tl_owner, metadata_pos);
5021 } 5026 }
5022 } 5027 }
5023 5028
5024 5029
5025 // Look ahead to detect if we are seeing ident [ TypeParameters ] "(". 5030 // Look ahead to detect if we are seeing ident [ TypeParameters ] "(".
5026 // We need this lookahead to distinguish between the optional return type 5031 // We need this lookahead to distinguish between the optional return type
5027 // and the alias name of a function type alias. 5032 // and the alias name of a function type alias.
5028 // Token position remains unchanged. 5033 // Token position remains unchanged.
5029 bool Parser::IsFunctionTypeAliasName() { 5034 bool Parser::IsFunctionTypeAliasName() {
5030 if (IsIdentifier() && (LookaheadToken(1) == Token::kLPAREN)) { 5035 if (IsIdentifier() && (LookaheadToken(1) == Token::kLPAREN)) {
(...skipping 25 matching lines...) Expand all
5056 if (TryParseTypeParameters() && (CurrentToken() == Token::kASSIGN)) { 5061 if (TryParseTypeParameters() && (CurrentToken() == Token::kASSIGN)) {
5057 is_mixin_def = true; 5062 is_mixin_def = true;
5058 } 5063 }
5059 } 5064 }
5060 SetPosition(saved_pos); 5065 SetPosition(saved_pos);
5061 return is_mixin_def; 5066 return is_mixin_def;
5062 } 5067 }
5063 5068
5064 5069
5065 void Parser::ParseTypedef(const GrowableObjectArray& pending_classes, 5070 void Parser::ParseTypedef(const GrowableObjectArray& pending_classes,
5066 const Class& toplevel_class, 5071 const Object& tl_owner,
5067 intptr_t metadata_pos) { 5072 intptr_t metadata_pos) {
5068 TRACE_PARSER("ParseTypedef"); 5073 TRACE_PARSER("ParseTypedef");
5069 intptr_t declaration_pos = (metadata_pos > 0) ? metadata_pos : TokenPos(); 5074 intptr_t declaration_pos = (metadata_pos > 0) ? metadata_pos : TokenPos();
5070 ExpectToken(Token::kTYPEDEF); 5075 ExpectToken(Token::kTYPEDEF);
5071 5076
5072 if (IsMixinAppAlias()) { 5077 if (IsMixinAppAlias()) {
5073 if (FLAG_warn_mixin_typedef) { 5078 if (FLAG_warn_mixin_typedef) {
5074 ReportWarning(TokenPos(), "deprecated mixin application typedef"); 5079 ReportWarning(TokenPos(), "deprecated mixin application typedef");
5075 } 5080 }
5076 ParseMixinAppAlias(pending_classes, toplevel_class, metadata_pos); 5081 ParseMixinAppAlias(pending_classes, tl_owner, metadata_pos);
5077 return; 5082 return;
5078 } 5083 }
5079 5084
5080 // Parse the result type of the function type. 5085 // Parse the result type of the function type.
5081 AbstractType& result_type = Type::Handle(Z, Type::DynamicType()); 5086 AbstractType& result_type = Type::Handle(Z, Type::DynamicType());
5082 if (CurrentToken() == Token::kVOID) { 5087 if (CurrentToken() == Token::kVOID) {
5083 ConsumeToken(); 5088 ConsumeToken();
5084 result_type = Type::VoidType(); 5089 result_type = Type::VoidType();
5085 } else if (!IsFunctionTypeAliasName()) { 5090 } else if (!IsFunctionTypeAliasName()) {
5086 // Type annotations in typedef are never ignored, even in production mode. 5091 // Type annotations in typedef are never ignored, even in production mode.
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
5177 } 5182 }
5178 ASSERT(signature_function.signature_class() == signature_class.raw()); 5183 ASSERT(signature_function.signature_class() == signature_class.raw());
5179 5184
5180 // The alias should not be marked as finalized yet, since it needs to be 5185 // The alias should not be marked as finalized yet, since it needs to be
5181 // checked in the class finalizer for illegal self references. 5186 // checked in the class finalizer for illegal self references.
5182 ASSERT(!function_type_alias.IsCanonicalSignatureClass()); 5187 ASSERT(!function_type_alias.IsCanonicalSignatureClass());
5183 ASSERT(!function_type_alias.is_finalized()); 5188 ASSERT(!function_type_alias.is_finalized());
5184 pending_classes.Add(function_type_alias, Heap::kOld); 5189 pending_classes.Add(function_type_alias, Heap::kOld);
5185 if (metadata_pos >= 0) { 5190 if (metadata_pos >= 0) {
5186 library_.AddClassMetadata(function_type_alias, 5191 library_.AddClassMetadata(function_type_alias,
5187 toplevel_class, 5192 tl_owner,
5188 metadata_pos); 5193 metadata_pos);
5189 } 5194 }
5190 } 5195 }
5191 5196
5192 5197
5193 // Consumes exactly one right angle bracket. If the current token is a single 5198 // Consumes exactly one right angle bracket. If the current token is a single
5194 // bracket token, it is consumed normally. However, if it is a double or triple 5199 // bracket token, it is consumed normally. However, if it is a double or triple
5195 // bracket, it is replaced by a single or double bracket token without 5200 // bracket, it is replaced by a single or double bracket token without
5196 // incrementing the token index. 5201 // incrementing the token index.
5197 void Parser::ConsumeRightAngleBracket() { 5202 void Parser::ConsumeRightAngleBracket() {
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
5414 String::Handle(Z, mixin_type.UserVisibleName()).ToCString()); 5419 String::Handle(Z, mixin_type.UserVisibleName()).ToCString());
5415 } 5420 }
5416 mixin_types.Add(mixin_type); 5421 mixin_types.Add(mixin_type);
5417 } while (CurrentToken() == Token::kCOMMA); 5422 } while (CurrentToken() == Token::kCOMMA);
5418 return MixinAppType::New(super_type, 5423 return MixinAppType::New(super_type,
5419 Array::Handle(Z, Array::MakeArray(mixin_types))); 5424 Array::Handle(Z, Array::MakeArray(mixin_types)));
5420 } 5425 }
5421 5426
5422 5427
5423 void Parser::ParseTopLevelVariable(TopLevel* top_level, 5428 void Parser::ParseTopLevelVariable(TopLevel* top_level,
5429 const Object& owner,
5424 intptr_t metadata_pos) { 5430 intptr_t metadata_pos) {
5425 TRACE_PARSER("ParseTopLevelVariable"); 5431 TRACE_PARSER("ParseTopLevelVariable");
5426 const bool is_const = (CurrentToken() == Token::kCONST); 5432 const bool is_const = (CurrentToken() == Token::kCONST);
5427 // Const fields are implicitly final. 5433 // Const fields are implicitly final.
5428 const bool is_final = is_const || (CurrentToken() == Token::kFINAL); 5434 const bool is_final = is_const || (CurrentToken() == Token::kFINAL);
5429 const bool is_static = true; 5435 const bool is_static = true;
5430 const AbstractType& type = AbstractType::ZoneHandle(Z, 5436 const AbstractType& type = AbstractType::ZoneHandle(Z,
5431 ParseConstFinalVarOrType(ClassFinalizer::kResolveTypeParameters)); 5437 ParseConstFinalVarOrType(ClassFinalizer::kResolveTypeParameters));
5432 Field& field = Field::Handle(Z); 5438 Field& field = Field::Handle(Z);
5433 Function& getter = Function::Handle(Z); 5439 Function& getter = Function::Handle(Z);
(...skipping 15 matching lines...) Expand all
5449 var_name.ToCString()); 5455 var_name.ToCString());
5450 } 5456 }
5451 accessor_name = Field::SetterName(var_name); 5457 accessor_name = Field::SetterName(var_name);
5452 if (library_.LookupLocalObject(accessor_name) != Object::null()) { 5458 if (library_.LookupLocalObject(accessor_name) != Object::null()) {
5453 ReportError(name_pos, "setter for '%s' is already defined", 5459 ReportError(name_pos, "setter for '%s' is already defined",
5454 var_name.ToCString()); 5460 var_name.ToCString());
5455 } 5461 }
5456 5462
5457 const bool is_reflectable = 5463 const bool is_reflectable =
5458 !(library_.is_dart_scheme() && library_.IsPrivate(var_name)); 5464 !(library_.is_dart_scheme() && library_.IsPrivate(var_name));
5459 field = Field::New(var_name, is_static, is_final, is_const, is_reflectable, 5465
5460 current_class(), type, name_pos); 5466 field = Field::NewTopLevel(var_name, is_final, is_const, owner, name_pos);
5467 field.SetFieldType(type);
5468 field.set_is_reflectable(is_reflectable);
5461 field.SetStaticValue(Object::null_instance(), true); 5469 field.SetStaticValue(Object::null_instance(), true);
5462 top_level->AddField(field); 5470 top_level->AddField(field);
5463 library_.AddObject(field, var_name); 5471 library_.AddObject(field, var_name);
5464 if (metadata_pos >= 0) { 5472 if (metadata_pos >= 0) {
5465 library_.AddFieldMetadata(field, metadata_pos); 5473 library_.AddFieldMetadata(field, metadata_pos);
5466 } 5474 }
5467 if (CurrentToken() == Token::kASSIGN) { 5475 if (CurrentToken() == Token::kASSIGN) {
5468 ConsumeToken(); 5476 ConsumeToken();
5469 Instance& field_value = Instance::Handle(Z, Object::sentinel().raw()); 5477 Instance& field_value = Instance::Handle(Z, Object::sentinel().raw());
5470 bool has_simple_literal = false; 5478 bool has_simple_literal = false;
5471 if (LookaheadToken(1) == Token::kSEMICOLON) { 5479 if (LookaheadToken(1) == Token::kSEMICOLON) {
5472 has_simple_literal = IsSimpleLiteral(type, &field_value); 5480 has_simple_literal = IsSimpleLiteral(type, &field_value);
5473 } 5481 }
5474 SkipExpr(); 5482 SkipExpr();
5475 field.SetStaticValue(field_value, true); 5483 field.SetStaticValue(field_value, true);
5476 field.set_has_initializer(true); 5484 field.set_has_initializer(true);
5477 5485
5478 if (!has_simple_literal) { 5486 if (!has_simple_literal) {
5479 // Create a static final getter. 5487 // Create a static final getter.
5480 String& getter_name = String::Handle(Z, Field::GetterSymbol(var_name)); 5488 String& getter_name = String::Handle(Z, Field::GetterSymbol(var_name));
5481 getter = Function::New(getter_name, 5489 getter = Function::New(getter_name,
5482 RawFunction::kImplicitStaticFinalGetter, 5490 RawFunction::kImplicitStaticFinalGetter,
5483 is_static, 5491 is_static,
5484 is_const, 5492 is_const,
5485 /* is_abstract = */ false, 5493 /* is_abstract = */ false,
5486 /* is_external = */ false, 5494 /* is_external = */ false,
5487 /* is_native = */ false, 5495 /* is_native = */ false,
5488 current_class(), 5496 owner,
5489 name_pos); 5497 name_pos);
5490 getter.set_result_type(type); 5498 getter.set_result_type(type);
5491 getter.set_is_debuggable(false); 5499 getter.set_is_debuggable(false);
5492 if (library_.is_dart_scheme() && library_.IsPrivate(var_name)) { 5500 getter.set_is_reflectable(is_reflectable);
5493 getter.set_is_reflectable(false);
5494 }
5495 top_level->AddFunction(getter); 5501 top_level->AddFunction(getter);
5496 } 5502 }
5497 } else if (is_final) { 5503 } else if (is_final) {
5498 ReportError(name_pos, "missing initializer for final or const variable"); 5504 ReportError(name_pos, "missing initializer for final or const variable");
5499 } 5505 }
5500 5506
5501 if (CurrentToken() == Token::kCOMMA) { 5507 if (CurrentToken() == Token::kCOMMA) {
5502 ConsumeToken(); 5508 ConsumeToken();
5503 } else if (CurrentToken() == Token::kSEMICOLON) { 5509 } else if (CurrentToken() == Token::kSEMICOLON) {
5504 ConsumeToken(); 5510 ConsumeToken();
(...skipping 26 matching lines...) Expand all
5531 } 5537 }
5532 ConsumeToken(); 5538 ConsumeToken();
5533 ConsumeToken(); 5539 ConsumeToken();
5534 return RawFunction::kSyncGen; 5540 return RawFunction::kSyncGen;
5535 } 5541 }
5536 return RawFunction::kNoModifier; 5542 return RawFunction::kNoModifier;
5537 } 5543 }
5538 5544
5539 5545
5540 void Parser::ParseTopLevelFunction(TopLevel* top_level, 5546 void Parser::ParseTopLevelFunction(TopLevel* top_level,
5547 const Object& owner,
5541 intptr_t metadata_pos) { 5548 intptr_t metadata_pos) {
5542 TRACE_PARSER("ParseTopLevelFunction"); 5549 TRACE_PARSER("ParseTopLevelFunction");
5543 const intptr_t decl_begin_pos = TokenPos(); 5550 const intptr_t decl_begin_pos = TokenPos();
5544 AbstractType& result_type = Type::Handle(Z, Type::DynamicType()); 5551 AbstractType& result_type = Type::Handle(Z, Type::DynamicType());
5545 const bool is_static = true; 5552 const bool is_static = true;
5546 bool is_external = false; 5553 bool is_external = false;
5547 bool is_patch = false; 5554 bool is_patch = false;
5548 if (is_patch_source() && 5555 if (is_patch_source() &&
5549 (CurrentToken() == Token::kIDENT) && 5556 (CurrentToken() == Token::kIDENT) &&
5550 CurrentLiteral()->Equals("patch") && 5557 CurrentLiteral()->Equals("patch") &&
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
5622 ReportError("function block expected"); 5629 ReportError("function block expected");
5623 } 5630 }
5624 Function& func = Function::Handle(Z, 5631 Function& func = Function::Handle(Z,
5625 Function::New(func_name, 5632 Function::New(func_name,
5626 RawFunction::kRegularFunction, 5633 RawFunction::kRegularFunction,
5627 is_static, 5634 is_static,
5628 /* is_const = */ false, 5635 /* is_const = */ false,
5629 /* is_abstract = */ false, 5636 /* is_abstract = */ false,
5630 is_external, 5637 is_external,
5631 is_native, 5638 is_native,
5632 current_class(), 5639 owner,
5633 decl_begin_pos)); 5640 decl_begin_pos));
5634 func.set_result_type(result_type); 5641 func.set_result_type(result_type);
5635 func.set_end_token_pos(function_end_pos); 5642 func.set_end_token_pos(function_end_pos);
5636 func.set_modifier(func_modifier); 5643 func.set_modifier(func_modifier);
5637 if (library_.is_dart_scheme() && library_.IsPrivate(func_name)) { 5644 if (library_.is_dart_scheme() && library_.IsPrivate(func_name)) {
5638 func.set_is_reflectable(false); 5645 func.set_is_reflectable(false);
5639 } 5646 }
5640 if (is_native) { 5647 if (is_native) {
5641 func.set_native_name(*native_name); 5648 func.set_native_name(*native_name);
5642 } 5649 }
5643 AddFormalParamsToFunction(&params, func); 5650 AddFormalParamsToFunction(&params, func);
5644 top_level->AddFunction(func); 5651 top_level->AddFunction(func);
5645 if (!is_patch) { 5652 if (!is_patch) {
5646 library_.AddObject(func, func_name); 5653 library_.AddObject(func, func_name);
5647 } else { 5654 } else {
5655 // Need to remove the previously added function that is being patched.
5656 const Class& toplevel_cls = Class::Handle(Z, library_.toplevel_class());
5657 const Function& replaced_func =
5658 Function::Handle(Z, toplevel_cls.LookupStaticFunction(func_name));
5659 ASSERT(!replaced_func.IsNull());
5660 toplevel_cls.RemoveFunction(replaced_func);
5648 library_.ReplaceObject(func, func_name); 5661 library_.ReplaceObject(func, func_name);
5649 } 5662 }
5650 if (metadata_pos >= 0) { 5663 if (metadata_pos >= 0) {
5651 library_.AddFunctionMetadata(func, metadata_pos); 5664 library_.AddFunctionMetadata(func, metadata_pos);
5652 } 5665 }
5653 } 5666 }
5654 5667
5655 5668
5656 void Parser::ParseTopLevelAccessor(TopLevel* top_level, 5669 void Parser::ParseTopLevelAccessor(TopLevel* top_level,
5670 const Object& owner,
5657 intptr_t metadata_pos) { 5671 intptr_t metadata_pos) {
5658 TRACE_PARSER("ParseTopLevelAccessor"); 5672 TRACE_PARSER("ParseTopLevelAccessor");
5659 const intptr_t decl_begin_pos = TokenPos(); 5673 const intptr_t decl_begin_pos = TokenPos();
5660 const bool is_static = true; 5674 const bool is_static = true;
5661 bool is_external = false; 5675 bool is_external = false;
5662 bool is_patch = false; 5676 bool is_patch = false;
5663 AbstractType& result_type = AbstractType::Handle(Z); 5677 AbstractType& result_type = AbstractType::Handle(Z);
5664 if (is_patch_source() && 5678 if (is_patch_source() &&
5665 (CurrentToken() == Token::kIDENT) && 5679 (CurrentToken() == Token::kIDENT) &&
5666 CurrentLiteral()->Equals("patch")) { 5680 CurrentLiteral()->Equals("patch")) {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
5777 } 5791 }
5778 Function& func = Function::Handle(Z, 5792 Function& func = Function::Handle(Z,
5779 Function::New(accessor_name, 5793 Function::New(accessor_name,
5780 is_getter ? RawFunction::kGetterFunction : 5794 is_getter ? RawFunction::kGetterFunction :
5781 RawFunction::kSetterFunction, 5795 RawFunction::kSetterFunction,
5782 is_static, 5796 is_static,
5783 /* is_const = */ false, 5797 /* is_const = */ false,
5784 /* is_abstract = */ false, 5798 /* is_abstract = */ false,
5785 is_external, 5799 is_external,
5786 is_native, 5800 is_native,
5787 current_class(), 5801 owner,
5788 decl_begin_pos)); 5802 decl_begin_pos));
5789 func.set_result_type(result_type); 5803 func.set_result_type(result_type);
5790 func.set_end_token_pos(accessor_end_pos); 5804 func.set_end_token_pos(accessor_end_pos);
5791 func.set_modifier(func_modifier); 5805 func.set_modifier(func_modifier);
5792 if (is_native) { 5806 if (is_native) {
5793 func.set_is_debuggable(false); 5807 func.set_is_debuggable(false);
5794 func.set_native_name(*native_name); 5808 func.set_native_name(*native_name);
5795 } 5809 }
5796 if (library_.is_dart_scheme() && library_.IsPrivate(accessor_name)) { 5810 if (library_.is_dart_scheme() && library_.IsPrivate(accessor_name)) {
5797 func.set_is_reflectable(false); 5811 func.set_is_reflectable(false);
5798 } 5812 }
5799 AddFormalParamsToFunction(&params, func); 5813 AddFormalParamsToFunction(&params, func);
5800 top_level->AddFunction(func); 5814 top_level->AddFunction(func);
5801 if (!is_patch) { 5815 if (!is_patch) {
5802 library_.AddObject(func, accessor_name); 5816 library_.AddObject(func, accessor_name);
5803 } else { 5817 } else {
5818 // Need to remove the previously added accessor that is being patched.
5819 const Class& toplevel_cls = Class::Handle(Z,
5820 owner.IsClass() ? Class::Cast(owner).raw()
5821 : PatchClass::Cast(owner).patched_class());
5822 const Function& replaced_func =
5823 Function::Handle(Z, toplevel_cls.LookupFunction(accessor_name));
5824 ASSERT(!replaced_func.IsNull());
5825 toplevel_cls.RemoveFunction(replaced_func);
5804 library_.ReplaceObject(func, accessor_name); 5826 library_.ReplaceObject(func, accessor_name);
5805 } 5827 }
5806 if (metadata_pos >= 0) { 5828 if (metadata_pos >= 0) {
5807 library_.AddFunctionMetadata(func, metadata_pos); 5829 library_.AddFunctionMetadata(func, metadata_pos);
5808 } 5830 }
5809 } 5831 }
5810 5832
5811 5833
5812 RawObject* Parser::CallLibraryTagHandler(Dart_LibraryTag tag, 5834 RawObject* Parser::CallLibraryTagHandler(Dart_LibraryTag tag,
5813 intptr_t token_pos, 5835 intptr_t token_pos,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
5873 names->Add(*CurrentLiteral()); 5895 names->Add(*CurrentLiteral());
5874 ConsumeToken(); // Identifier. 5896 ConsumeToken(); // Identifier.
5875 if (CurrentToken() != Token::kCOMMA) { 5897 if (CurrentToken() != Token::kCOMMA) {
5876 return; 5898 return;
5877 } 5899 }
5878 ConsumeToken(); // Comma. 5900 ConsumeToken(); // Comma.
5879 } 5901 }
5880 } 5902 }
5881 5903
5882 5904
5883 void Parser::ParseLibraryImportExport(intptr_t metadata_pos) { 5905 void Parser::ParseLibraryImportExport(const Object& tl_owner,
5906 intptr_t metadata_pos) {
5884 bool is_import = (CurrentToken() == Token::kIMPORT); 5907 bool is_import = (CurrentToken() == Token::kIMPORT);
5885 bool is_export = (CurrentToken() == Token::kEXPORT); 5908 bool is_export = (CurrentToken() == Token::kEXPORT);
5886 ASSERT(is_import || is_export); 5909 ASSERT(is_import || is_export);
5887 const intptr_t import_pos = TokenPos(); 5910 const intptr_t import_pos = TokenPos();
5888 ConsumeToken(); 5911 ConsumeToken();
5889 CheckToken(Token::kSTRING, "library url expected"); 5912 CheckToken(Token::kSTRING, "library url expected");
5890 AstNode* url_literal = ParseStringLiteral(false); 5913 AstNode* url_literal = ParseStringLiteral(false);
5891 ASSERT(url_literal->IsLiteralNode()); 5914 ASSERT(url_literal->IsLiteralNode());
5892 ASSERT(url_literal->AsLiteralNode()->literal().IsString()); 5915 ASSERT(url_literal->AsLiteralNode()->literal().IsString());
5893 const String& url = String::Cast(url_literal->AsLiteralNode()->literal()); 5916 const String& url = String::Cast(url_literal->AsLiteralNode()->literal());
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
5958 // the library. 5981 // the library.
5959 if (library.LoadNotStarted() && 5982 if (library.LoadNotStarted() &&
5960 (!is_deferred_import || FLAG_load_deferred_eagerly)) { 5983 (!is_deferred_import || FLAG_load_deferred_eagerly)) {
5961 library.SetLoadRequested(); 5984 library.SetLoadRequested();
5962 CallLibraryTagHandler(Dart_kImportTag, import_pos, canon_url); 5985 CallLibraryTagHandler(Dart_kImportTag, import_pos, canon_url);
5963 } 5986 }
5964 5987
5965 Namespace& ns = Namespace::Handle(Z, 5988 Namespace& ns = Namespace::Handle(Z,
5966 Namespace::New(library, show_names, hide_names)); 5989 Namespace::New(library, show_names, hide_names));
5967 if (metadata_pos >= 0) { 5990 if (metadata_pos >= 0) {
5968 ns.AddMetadata(metadata_pos, current_class()); 5991 ns.AddMetadata(tl_owner, metadata_pos);
5969 } 5992 }
5970 5993
5971 // Ensure that private dart:_ libraries are only imported into dart: 5994 // Ensure that private dart:_ libraries are only imported into dart:
5972 // libraries, including indirectly through exports. 5995 // libraries, including indirectly through exports.
5973 const String& lib_url = String::Handle(Z, library_.url()); 5996 const String& lib_url = String::Handle(Z, library_.url());
5974 if (canon_url.StartsWith(Symbols::DartSchemePrivate()) && 5997 if (canon_url.StartsWith(Symbols::DartSchemePrivate()) &&
5975 !lib_url.StartsWith(Symbols::DartScheme())) { 5998 !lib_url.StartsWith(Symbols::DartScheme())) {
5976 ReportError(import_pos, "private library is not accessible"); 5999 ReportError(import_pos, "private library is not accessible");
5977 } 6000 }
5978 6001
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
6021 ASSERT(url_literal->IsLiteralNode()); 6044 ASSERT(url_literal->IsLiteralNode());
6022 ASSERT(url_literal->AsLiteralNode()->literal().IsString()); 6045 ASSERT(url_literal->AsLiteralNode()->literal().IsString());
6023 const String& url = String::Cast(url_literal->AsLiteralNode()->literal()); 6046 const String& url = String::Cast(url_literal->AsLiteralNode()->literal());
6024 ExpectSemicolon(); 6047 ExpectSemicolon();
6025 const String& canon_url = String::CheckedHandle( 6048 const String& canon_url = String::CheckedHandle(
6026 CallLibraryTagHandler(Dart_kCanonicalizeUrl, source_pos, url)); 6049 CallLibraryTagHandler(Dart_kCanonicalizeUrl, source_pos, url));
6027 CallLibraryTagHandler(Dart_kSourceTag, source_pos, canon_url); 6050 CallLibraryTagHandler(Dart_kSourceTag, source_pos, canon_url);
6028 } 6051 }
6029 6052
6030 6053
6031 void Parser::ParseLibraryDefinition() { 6054 void Parser::ParseLibraryDefinition(const Object& tl_owner) {
6032 TRACE_PARSER("ParseLibraryDefinition"); 6055 TRACE_PARSER("ParseLibraryDefinition");
6033 6056
6034 // Handle the script tag. 6057 // Handle the script tag.
6035 if (CurrentToken() == Token::kSCRIPTTAG) { 6058 if (CurrentToken() == Token::kSCRIPTTAG) {
6036 // Nothing to do for script tags except to skip them. 6059 // Nothing to do for script tags except to skip them.
6037 ConsumeToken(); 6060 ConsumeToken();
6038 } 6061 }
6039 6062
6040 ASSERT(script_.kind() != RawScript::kSourceTag); 6063 ASSERT(script_.kind() != RawScript::kSourceTag);
6041 6064
6042 // We may read metadata tokens that are part of the toplevel 6065 // We may read metadata tokens that are part of the toplevel
6043 // declaration that follows the library definitions. Therefore, we 6066 // declaration that follows the library definitions. Therefore, we
6044 // need to remember the position of the last token that was 6067 // need to remember the position of the last token that was
6045 // successfully consumed. 6068 // successfully consumed.
6046 intptr_t rewind_pos = TokenPos(); 6069 intptr_t rewind_pos = TokenPos();
6047 intptr_t metadata_pos = SkipMetadata(); 6070 intptr_t metadata_pos = SkipMetadata();
6048 if (CurrentToken() == Token::kLIBRARY) { 6071 if (CurrentToken() == Token::kLIBRARY) {
6049 if (is_patch_source()) { 6072 if (is_patch_source()) {
6050 ReportError("patch cannot override library name"); 6073 ReportError("patch cannot override library name");
6051 } 6074 }
6052 ParseLibraryName(); 6075 ParseLibraryName();
6053 if (metadata_pos >= 0) { 6076 if (metadata_pos >= 0) {
6054 library_.AddLibraryMetadata(current_class(), metadata_pos); 6077 library_.AddLibraryMetadata(tl_owner, metadata_pos);
6055 } 6078 }
6056 rewind_pos = TokenPos(); 6079 rewind_pos = TokenPos();
6057 metadata_pos = SkipMetadata(); 6080 metadata_pos = SkipMetadata();
6058 } 6081 }
6059 while ((CurrentToken() == Token::kIMPORT) || 6082 while ((CurrentToken() == Token::kIMPORT) ||
6060 (CurrentToken() == Token::kEXPORT)) { 6083 (CurrentToken() == Token::kEXPORT)) {
6061 ParseLibraryImportExport(metadata_pos); 6084 ParseLibraryImportExport(tl_owner, metadata_pos);
6062 rewind_pos = TokenPos(); 6085 rewind_pos = TokenPos();
6063 metadata_pos = SkipMetadata(); 6086 metadata_pos = SkipMetadata();
6064 } 6087 }
6065 // Core lib has not been explicitly imported, so we implicitly 6088 // Core lib has not been explicitly imported, so we implicitly
6066 // import it here. 6089 // import it here.
6067 if (!library_.ImportsCorelib()) { 6090 if (!library_.ImportsCorelib()) {
6068 Library& core_lib = Library::Handle(Z, Library::CoreLibrary()); 6091 Library& core_lib = Library::Handle(Z, Library::CoreLibrary());
6069 ASSERT(!core_lib.IsNull()); 6092 ASSERT(!core_lib.IsNull());
6070 const Namespace& core_ns = Namespace::Handle(Z, 6093 const Namespace& core_ns = Namespace::Handle(Z,
6071 Namespace::New(core_lib, Object::null_array(), Object::null_array())); 6094 Namespace::New(core_lib, Object::null_array(), Object::null_array()));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
6103 TRACE_PARSER("ParseTopLevel"); 6126 TRACE_PARSER("ParseTopLevel");
6104 // Collect the classes found at the top level in this growable array. 6127 // Collect the classes found at the top level in this growable array.
6105 // They need to be registered with class finalization after parsing 6128 // They need to be registered with class finalization after parsing
6106 // has been completed. 6129 // has been completed.
6107 ObjectStore* object_store = I->object_store(); 6130 ObjectStore* object_store = I->object_store();
6108 const GrowableObjectArray& pending_classes = 6131 const GrowableObjectArray& pending_classes =
6109 GrowableObjectArray::Handle(Z, object_store->pending_classes()); 6132 GrowableObjectArray::Handle(Z, object_store->pending_classes());
6110 SetPosition(0); 6133 SetPosition(0);
6111 is_top_level_ = true; 6134 is_top_level_ = true;
6112 TopLevel top_level(Z); 6135 TopLevel top_level(Z);
6113 Class& toplevel_class = Class::Handle(Z, 6136
6114 Class::New(Symbols::TopLevel(), script_, TokenPos())); 6137 Object& tl_owner = Object::Handle(Z);
6115 toplevel_class.set_library(library_); 6138 Class& toplevel_class = Class::Handle(Z, library_.toplevel_class());
6139 if (toplevel_class.IsNull()) {
6140 toplevel_class = Class::New(Symbols::TopLevel(), script_, TokenPos());
6141 toplevel_class.set_library(library_);
6142 library_.set_toplevel_class(toplevel_class);
6143 tl_owner = toplevel_class.raw();
6144 } else {
6145 tl_owner = PatchClass::New(toplevel_class, script_);
6146 }
6116 6147
6117 if (is_library_source() || is_patch_source()) { 6148 if (is_library_source() || is_patch_source()) {
6118 set_current_class(toplevel_class); 6149 set_current_class(toplevel_class);
6119 ParseLibraryDefinition(); 6150 ParseLibraryDefinition(tl_owner);
6120 } else if (is_part_source()) { 6151 } else if (is_part_source()) {
6121 ParsePartHeader(); 6152 ParsePartHeader();
6122 } 6153 }
6123 6154
6124 const Class& cls = Class::Handle(Z); 6155 const Class& cls = Class::Handle(Z);
6125 while (true) { 6156 while (true) {
6126 set_current_class(cls); // No current class. 6157 set_current_class(cls); // No current class.
6127 intptr_t metadata_pos = SkipMetadata(); 6158 intptr_t metadata_pos = SkipMetadata();
6128 if (CurrentToken() == Token::kCLASS) { 6159 if (CurrentToken() == Token::kCLASS) {
6129 ParseClassDeclaration(pending_classes, toplevel_class, metadata_pos); 6160 ParseClassDeclaration(pending_classes, tl_owner, metadata_pos);
6130 } else if (CurrentToken() == Token::kENUM) { 6161 } else if (CurrentToken() == Token::kENUM) {
6131 ParseEnumDeclaration(pending_classes, toplevel_class, metadata_pos); 6162 ParseEnumDeclaration(pending_classes, tl_owner, metadata_pos);
6132 } else if ((CurrentToken() == Token::kTYPEDEF) && 6163 } else if ((CurrentToken() == Token::kTYPEDEF) &&
6133 (LookaheadToken(1) != Token::kLPAREN)) { 6164 (LookaheadToken(1) != Token::kLPAREN)) {
6134 set_current_class(toplevel_class); 6165 set_current_class(toplevel_class);
6135 ParseTypedef(pending_classes, toplevel_class, metadata_pos); 6166 ParseTypedef(pending_classes, tl_owner, metadata_pos);
6136 } else if ((CurrentToken() == Token::kABSTRACT) && 6167 } else if ((CurrentToken() == Token::kABSTRACT) &&
6137 (LookaheadToken(1) == Token::kCLASS)) { 6168 (LookaheadToken(1) == Token::kCLASS)) {
6138 ParseClassDeclaration(pending_classes, toplevel_class, metadata_pos); 6169 ParseClassDeclaration(pending_classes, tl_owner, metadata_pos);
6139 } else if (is_patch_source() && IsSymbol(Symbols::Patch()) && 6170 } else if (is_patch_source() && IsSymbol(Symbols::Patch()) &&
6140 (LookaheadToken(1) == Token::kCLASS)) { 6171 (LookaheadToken(1) == Token::kCLASS)) {
6141 ParseClassDeclaration(pending_classes, toplevel_class, metadata_pos); 6172 ParseClassDeclaration(pending_classes, tl_owner, metadata_pos);
6142 } else { 6173 } else {
6143 set_current_class(toplevel_class); 6174 set_current_class(toplevel_class);
6144 if (IsVariableDeclaration()) { 6175 if (IsVariableDeclaration()) {
6145 ParseTopLevelVariable(&top_level, metadata_pos); 6176 ParseTopLevelVariable(&top_level, tl_owner, metadata_pos);
6146 } else if (IsFunctionDeclaration()) { 6177 } else if (IsFunctionDeclaration()) {
6147 ParseTopLevelFunction(&top_level, metadata_pos); 6178 ParseTopLevelFunction(&top_level, tl_owner, metadata_pos);
6148 } else if (IsTopLevelAccessor()) { 6179 } else if (IsTopLevelAccessor()) {
6149 ParseTopLevelAccessor(&top_level, metadata_pos); 6180 ParseTopLevelAccessor(&top_level, tl_owner, metadata_pos);
6150 } else if (CurrentToken() == Token::kEOS) { 6181 } else if (CurrentToken() == Token::kEOS) {
6151 break; 6182 break;
6152 } else { 6183 } else {
6153 UnexpectedToken(); 6184 UnexpectedToken();
6154 } 6185 }
6155 } 6186 }
6156 } 6187 }
6157 6188
6158 if ((library_.num_anonymous_classes() == 0) || 6189 if (top_level.fields().length() > 0) {
6159 (top_level.fields().length() > 0) ||
6160 (top_level.functions().length() > 0)) {
6161 toplevel_class.AddFields(top_level.fields()); 6190 toplevel_class.AddFields(top_level.fields());
6162 const intptr_t len = top_level.functions().length();
6163 const Array& array = Array::Handle(Z, Array::New(len, Heap::kOld));
6164 for (intptr_t i = 0; i < len; i++) {
6165 array.SetAt(i, *top_level.functions()[i]);
6166 }
6167 toplevel_class.SetFunctions(array);
6168 library_.AddAnonymousClass(toplevel_class);
6169 pending_classes.Add(toplevel_class, Heap::kOld);
6170 } 6191 }
6192 for (intptr_t i = 0; i < top_level.functions().length(); i++) {
6193 toplevel_class.AddFunction(*top_level.functions()[i]);
6194 }
6195 pending_classes.Add(toplevel_class, Heap::kOld);
6171 } 6196 }
6172 6197
6173 6198
6174 void Parser::ChainNewBlock(LocalScope* outer_scope) { 6199 void Parser::ChainNewBlock(LocalScope* outer_scope) {
6175 Block* block = new(Z) Block( 6200 Block* block = new(Z) Block(
6176 current_block_, 6201 current_block_,
6177 outer_scope, 6202 outer_scope,
6178 new(Z) SequenceNode(TokenPos(), outer_scope)); 6203 new(Z) SequenceNode(TokenPos(), outer_scope));
6179 current_block_ = block; 6204 current_block_ = block;
6180 } 6205 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
6219 new(Z) LocalScope(current_block_->scope, 6244 new(Z) LocalScope(current_block_->scope,
6220 current_block_->scope->function_level() + 1, 6245 current_block_->scope->function_level() + 1,
6221 0); 6246 0);
6222 } 6247 }
6223 ChainNewBlock(outer_scope); 6248 ChainNewBlock(outer_scope);
6224 } 6249 }
6225 6250
6226 6251
6227 void Parser::OpenAsyncClosure() { 6252 void Parser::OpenAsyncClosure() {
6228 TRACE_PARSER("OpenAsyncClosure"); 6253 TRACE_PARSER("OpenAsyncClosure");
6229
6230 async_temp_scope_ = current_block_->scope; 6254 async_temp_scope_ = current_block_->scope;
6231
6232 OpenAsyncTryBlock(); 6255 OpenAsyncTryBlock();
6233 } 6256 }
6234 6257
6235 6258
6236 SequenceNode* Parser::CloseAsyncGeneratorTryBlock(SequenceNode *body) { 6259 SequenceNode* Parser::CloseAsyncGeneratorTryBlock(SequenceNode *body) {
6237 TRACE_PARSER("CloseAsyncGeneratorTryBlock"); 6260 TRACE_PARSER("CloseAsyncGeneratorTryBlock");
6238 // The generated try-catch-finally that wraps the async generator function 6261 // The generated try-catch-finally that wraps the async generator function
6239 // body is the outermost try statement. 6262 // body is the outermost try statement.
6240 ASSERT(try_stack_ != NULL); 6263 ASSERT(try_stack_ != NULL);
6241 ASSERT(try_stack_->outer_try() == NULL); 6264 ASSERT(try_stack_->outer_try() == NULL);
(...skipping 8158 matching lines...) Expand 10 before | Expand all | Expand 10 after
14400 UNREACHABLE(); 14423 UNREACHABLE();
14401 return Object::null(); 14424 return Object::null();
14402 } 14425 }
14403 14426
14404 14427
14405 void Parser::ParseFunction(ParsedFunction* parsed_function) { 14428 void Parser::ParseFunction(ParsedFunction* parsed_function) {
14406 UNREACHABLE(); 14429 UNREACHABLE();
14407 } 14430 }
14408 14431
14409 14432
14410 RawObject* Parser::ParseMetadata(const Class& cls, intptr_t token_pos) { 14433 RawObject* Parser::ParseMetadata(const Field& meta_data) {
14411 UNREACHABLE(); 14434 UNREACHABLE();
14412 return Object::null(); 14435 return Object::null();
14413 } 14436 }
14414 14437
14415 14438
14416 ParsedFunction* Parser::ParseStaticFieldInitializer(const Field& field) { 14439 ParsedFunction* Parser::ParseStaticFieldInitializer(const Field& field) {
14417 UNREACHABLE(); 14440 UNREACHABLE();
14418 return NULL; 14441 return NULL;
14419 } 14442 }
14420 14443
14421 14444
14422 ArgumentListNode* Parser::BuildNoSuchMethodArguments( 14445 ArgumentListNode* Parser::BuildNoSuchMethodArguments(
14423 intptr_t call_pos, 14446 intptr_t call_pos,
14424 const String& function_name, 14447 const String& function_name,
14425 const ArgumentListNode& function_args, 14448 const ArgumentListNode& function_args,
14426 const LocalVariable* temp_for_last_arg, 14449 const LocalVariable* temp_for_last_arg,
14427 bool is_super_invocation) { 14450 bool is_super_invocation) {
14428 UNREACHABLE(); 14451 UNREACHABLE();
14429 return NULL; 14452 return NULL;
14430 } 14453 }
14431 14454
14432 } // namespace dart 14455 } // namespace dart
14433 14456
14434 #endif // DART_PRECOMPILED 14457 #endif // DART_PRECOMPILED
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