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