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