| 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 "vm/bigint_operations.h" | 8 #include "vm/bigint_operations.h" |
| 9 #include "vm/bootstrap.h" | 9 #include "vm/bootstrap.h" |
| 10 #include "vm/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
| (...skipping 3806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3817 // which the current one redirects, we ignore the unresolved | 3817 // which the current one redirects, we ignore the unresolved |
| 3818 // reference. We'll catch it later when the constructor gets | 3818 // reference. We'll catch it later when the constructor gets |
| 3819 // compiled. | 3819 // compiled. |
| 3820 ctors.Add(member); | 3820 ctors.Add(member); |
| 3821 member = class_desc->LookupMember(*member->redirect_name); | 3821 member = class_desc->LookupMember(*member->redirect_name); |
| 3822 } | 3822 } |
| 3823 } | 3823 } |
| 3824 } | 3824 } |
| 3825 | 3825 |
| 3826 | 3826 |
| 3827 void Parser::ParseMixinTypedef(const GrowableObjectArray& pending_classes) { | 3827 void Parser::ParseMixinTypedef(const GrowableObjectArray& pending_classes, |
| 3828 intptr_t metadata_pos) { |
| 3828 TRACE_PARSER("ParseMixinTypedef"); | 3829 TRACE_PARSER("ParseMixinTypedef"); |
| 3829 const intptr_t classname_pos = TokenPos(); | 3830 const intptr_t classname_pos = TokenPos(); |
| 3830 String& class_name = *ExpectUserDefinedTypeIdentifier("class name expected"); | 3831 String& class_name = *ExpectUserDefinedTypeIdentifier("class name expected"); |
| 3831 if (FLAG_trace_parser) { | 3832 if (FLAG_trace_parser) { |
| 3832 OS::Print("toplevel parsing typedef class '%s'\n", class_name.ToCString()); | 3833 OS::Print("toplevel parsing typedef class '%s'\n", class_name.ToCString()); |
| 3833 } | 3834 } |
| 3834 const Object& obj = Object::Handle(library_.LookupLocalObject(class_name)); | 3835 const Object& obj = Object::Handle(library_.LookupLocalObject(class_name)); |
| 3835 if (!obj.IsNull()) { | 3836 if (!obj.IsNull()) { |
| 3836 ErrorMsg(classname_pos, "'%s' is already defined", | 3837 ErrorMsg(classname_pos, "'%s' is already defined", |
| 3837 class_name.ToCString()); | 3838 class_name.ToCString()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3870 mixin_application.set_is_synthesized_class(); | 3871 mixin_application.set_is_synthesized_class(); |
| 3871 | 3872 |
| 3872 // This mixin application typedef needs an implicit constructor, but it is | 3873 // This mixin application typedef needs an implicit constructor, but it is |
| 3873 // too early to call 'AddImplicitConstructor(mixin_application)' here, | 3874 // too early to call 'AddImplicitConstructor(mixin_application)' here, |
| 3874 // because this class should be lazily compiled. | 3875 // because this class should be lazily compiled. |
| 3875 if (CurrentToken() == Token::kIMPLEMENTS) { | 3876 if (CurrentToken() == Token::kIMPLEMENTS) { |
| 3876 ParseInterfaceList(mixin_application); | 3877 ParseInterfaceList(mixin_application); |
| 3877 } | 3878 } |
| 3878 ExpectSemicolon(); | 3879 ExpectSemicolon(); |
| 3879 pending_classes.Add(mixin_application, Heap::kOld); | 3880 pending_classes.Add(mixin_application, Heap::kOld); |
| 3881 if (metadata_pos >= 0) { |
| 3882 library_.AddClassMetadata(mixin_application, metadata_pos); |
| 3883 } |
| 3880 } | 3884 } |
| 3881 | 3885 |
| 3882 | 3886 |
| 3883 // Look ahead to detect if we are seeing ident [ TypeParameters ] "(". | 3887 // Look ahead to detect if we are seeing ident [ TypeParameters ] "(". |
| 3884 // We need this lookahead to distinguish between the optional return type | 3888 // We need this lookahead to distinguish between the optional return type |
| 3885 // and the alias name of a function type alias. | 3889 // and the alias name of a function type alias. |
| 3886 // Token position remains unchanged. | 3890 // Token position remains unchanged. |
| 3887 bool Parser::IsFunctionTypeAliasName() { | 3891 bool Parser::IsFunctionTypeAliasName() { |
| 3888 if (IsIdentifier() && (LookaheadToken(1) == Token::kLPAREN)) { | 3892 if (IsIdentifier() && (LookaheadToken(1) == Token::kLPAREN)) { |
| 3889 return true; | 3893 return true; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 3913 ConsumeToken(); | 3917 ConsumeToken(); |
| 3914 if (TryParseTypeParameter() && (CurrentToken() == Token::kASSIGN)) { | 3918 if (TryParseTypeParameter() && (CurrentToken() == Token::kASSIGN)) { |
| 3915 is_mixin_def = true; | 3919 is_mixin_def = true; |
| 3916 } | 3920 } |
| 3917 } | 3921 } |
| 3918 SetPosition(saved_pos); | 3922 SetPosition(saved_pos); |
| 3919 return is_mixin_def; | 3923 return is_mixin_def; |
| 3920 } | 3924 } |
| 3921 | 3925 |
| 3922 | 3926 |
| 3923 void Parser::ParseTypedef(const GrowableObjectArray& pending_classes) { | 3927 void Parser::ParseTypedef(const GrowableObjectArray& pending_classes, |
| 3928 intptr_t metadata_pos) { |
| 3924 TRACE_PARSER("ParseTypedef"); | 3929 TRACE_PARSER("ParseTypedef"); |
| 3925 ExpectToken(Token::kTYPEDEF); | 3930 ExpectToken(Token::kTYPEDEF); |
| 3926 | 3931 |
| 3927 if (IsMixinTypedef()) { | 3932 if (IsMixinTypedef()) { |
| 3928 ParseMixinTypedef(pending_classes); | 3933 ParseMixinTypedef(pending_classes, metadata_pos); |
| 3929 return; | 3934 return; |
| 3930 } | 3935 } |
| 3931 | 3936 |
| 3932 // Parse the result type of the function type. | 3937 // Parse the result type of the function type. |
| 3933 AbstractType& result_type = Type::Handle(Type::DynamicType()); | 3938 AbstractType& result_type = Type::Handle(Type::DynamicType()); |
| 3934 if (CurrentToken() == Token::kVOID) { | 3939 if (CurrentToken() == Token::kVOID) { |
| 3935 ConsumeToken(); | 3940 ConsumeToken(); |
| 3936 result_type = Type::VoidType(); | 3941 result_type = Type::VoidType(); |
| 3937 } else if (!IsFunctionTypeAliasName()) { | 3942 } else if (!IsFunctionTypeAliasName()) { |
| 3938 // Type annotations in typedef are never ignored, even in unchecked mode. | 3943 // Type annotations in typedef are never ignored, even in unchecked mode. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4025 signature_function = signature_class.signature_function(); | 4030 signature_function = signature_class.signature_function(); |
| 4026 function_type_alias.PatchSignatureFunction(signature_function); | 4031 function_type_alias.PatchSignatureFunction(signature_function); |
| 4027 } | 4032 } |
| 4028 ASSERT(signature_function.signature_class() == signature_class.raw()); | 4033 ASSERT(signature_function.signature_class() == signature_class.raw()); |
| 4029 | 4034 |
| 4030 // The alias should not be marked as finalized yet, since it needs to be | 4035 // The alias should not be marked as finalized yet, since it needs to be |
| 4031 // checked in the class finalizer for illegal self references. | 4036 // checked in the class finalizer for illegal self references. |
| 4032 ASSERT(!function_type_alias.IsCanonicalSignatureClass()); | 4037 ASSERT(!function_type_alias.IsCanonicalSignatureClass()); |
| 4033 ASSERT(!function_type_alias.is_finalized()); | 4038 ASSERT(!function_type_alias.is_finalized()); |
| 4034 pending_classes.Add(function_type_alias, Heap::kOld); | 4039 pending_classes.Add(function_type_alias, Heap::kOld); |
| 4040 if (metadata_pos >= 0) { |
| 4041 library_.AddClassMetadata(function_type_alias, metadata_pos); |
| 4042 } |
| 4035 } | 4043 } |
| 4036 | 4044 |
| 4037 | 4045 |
| 4038 // Consumes exactly one right angle bracket. If the current token is a single | 4046 // Consumes exactly one right angle bracket. If the current token is a single |
| 4039 // bracket token, it is consumed normally. However, if it is a double or triple | 4047 // bracket token, it is consumed normally. However, if it is a double or triple |
| 4040 // bracket, it is replaced by a single or double bracket token without | 4048 // bracket, it is replaced by a single or double bracket token without |
| 4041 // incrementing the token index. | 4049 // incrementing the token index. |
| 4042 void Parser::ConsumeRightAngleBracket() { | 4050 void Parser::ConsumeRightAngleBracket() { |
| 4043 if (token_kind_ == Token::kGT) { | 4051 if (token_kind_ == Token::kGT) { |
| 4044 ConsumeToken(); | 4052 ConsumeToken(); |
| (...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4879 | 4887 |
| 4880 const Class& cls = Class::Handle(isolate()); | 4888 const Class& cls = Class::Handle(isolate()); |
| 4881 while (true) { | 4889 while (true) { |
| 4882 set_current_class(cls); // No current class. | 4890 set_current_class(cls); // No current class. |
| 4883 intptr_t metadata_pos = SkipMetadata(); | 4891 intptr_t metadata_pos = SkipMetadata(); |
| 4884 if (CurrentToken() == Token::kCLASS) { | 4892 if (CurrentToken() == Token::kCLASS) { |
| 4885 ParseClassDeclaration(pending_classes, metadata_pos); | 4893 ParseClassDeclaration(pending_classes, metadata_pos); |
| 4886 } else if ((CurrentToken() == Token::kTYPEDEF) && | 4894 } else if ((CurrentToken() == Token::kTYPEDEF) && |
| 4887 (LookaheadToken(1) != Token::kLPAREN)) { | 4895 (LookaheadToken(1) != Token::kLPAREN)) { |
| 4888 set_current_class(toplevel_class); | 4896 set_current_class(toplevel_class); |
| 4889 ParseTypedef(pending_classes); | 4897 ParseTypedef(pending_classes, metadata_pos); |
| 4890 } else if ((CurrentToken() == Token::kABSTRACT) && | 4898 } else if ((CurrentToken() == Token::kABSTRACT) && |
| 4891 (LookaheadToken(1) == Token::kCLASS)) { | 4899 (LookaheadToken(1) == Token::kCLASS)) { |
| 4892 ParseClassDeclaration(pending_classes, metadata_pos); | 4900 ParseClassDeclaration(pending_classes, metadata_pos); |
| 4893 } else if (is_patch_source() && IsLiteral("patch") && | 4901 } else if (is_patch_source() && IsLiteral("patch") && |
| 4894 (LookaheadToken(1) == Token::kCLASS)) { | 4902 (LookaheadToken(1) == Token::kCLASS)) { |
| 4895 ParseClassDeclaration(pending_classes, metadata_pos); | 4903 ParseClassDeclaration(pending_classes, metadata_pos); |
| 4896 } else { | 4904 } else { |
| 4897 set_current_class(toplevel_class); | 4905 set_current_class(toplevel_class); |
| 4898 if (IsVariableDeclaration()) { | 4906 if (IsVariableDeclaration()) { |
| 4899 ParseTopLevelVariable(&top_level, metadata_pos); | 4907 ParseTopLevelVariable(&top_level, metadata_pos); |
| (...skipping 5520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10420 void Parser::SkipQualIdent() { | 10428 void Parser::SkipQualIdent() { |
| 10421 ASSERT(IsIdentifier()); | 10429 ASSERT(IsIdentifier()); |
| 10422 ConsumeToken(); | 10430 ConsumeToken(); |
| 10423 if (CurrentToken() == Token::kPERIOD) { | 10431 if (CurrentToken() == Token::kPERIOD) { |
| 10424 ConsumeToken(); // Consume the kPERIOD token. | 10432 ConsumeToken(); // Consume the kPERIOD token. |
| 10425 ExpectIdentifier("identifier expected after '.'"); | 10433 ExpectIdentifier("identifier expected after '.'"); |
| 10426 } | 10434 } |
| 10427 } | 10435 } |
| 10428 | 10436 |
| 10429 } // namespace dart | 10437 } // namespace dart |
| OLD | NEW |