| 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 10525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10536 // javascript warnings are desired and identical is not invoked from a patch | 10536 // javascript warnings are desired and identical is not invoked from a patch |
| 10537 // source. | 10537 // source. |
| 10538 if (!FLAG_warn_on_javascript_compatibility || is_patch_source()) { | 10538 if (!FLAG_warn_on_javascript_compatibility || is_patch_source()) { |
| 10539 ASSERT(num_arguments == 2); | 10539 ASSERT(num_arguments == 2); |
| 10540 return new(Z) ComparisonNode(ident_pos, | 10540 return new(Z) ComparisonNode(ident_pos, |
| 10541 Token::kEQ_STRICT, | 10541 Token::kEQ_STRICT, |
| 10542 arguments->NodeAt(0), | 10542 arguments->NodeAt(0), |
| 10543 arguments->NodeAt(1)); | 10543 arguments->NodeAt(1)); |
| 10544 } | 10544 } |
| 10545 } | 10545 } |
| 10546 return new(Z) StaticCallNode(call_pos, func, arguments); | 10546 return new(Z) StaticCallNode(ident_pos, func, arguments); |
| 10547 } | 10547 } |
| 10548 | 10548 |
| 10549 | 10549 |
| 10550 AstNode* Parser::ParseInstanceCall(AstNode* receiver, const String& func_name) { | 10550 AstNode* Parser::ParseInstanceCall(AstNode* receiver, |
| 10551 const String& func_name, |
| 10552 intptr_t ident_pos) { |
| 10551 TRACE_PARSER("ParseInstanceCall"); | 10553 TRACE_PARSER("ParseInstanceCall"); |
| 10552 const intptr_t call_pos = TokenPos(); | |
| 10553 CheckToken(Token::kLPAREN); | 10554 CheckToken(Token::kLPAREN); |
| 10554 ArgumentListNode* arguments = ParseActualParameters(NULL, kAllowConst); | 10555 ArgumentListNode* arguments = ParseActualParameters(NULL, kAllowConst); |
| 10555 return new(Z) InstanceCallNode(call_pos, receiver, func_name, arguments); | 10556 return new(Z) InstanceCallNode(ident_pos, receiver, func_name, arguments); |
| 10556 } | 10557 } |
| 10557 | 10558 |
| 10558 | 10559 |
| 10559 AstNode* Parser::ParseClosureCall(AstNode* closure) { | 10560 AstNode* Parser::ParseClosureCall(AstNode* closure) { |
| 10560 TRACE_PARSER("ParseClosureCall"); | 10561 TRACE_PARSER("ParseClosureCall"); |
| 10561 const intptr_t call_pos = TokenPos(); | 10562 const intptr_t call_pos = TokenPos(); |
| 10562 ASSERT(CurrentToken() == Token::kLPAREN); | 10563 ASSERT(CurrentToken() == Token::kLPAREN); |
| 10563 ArgumentListNode* arguments = ParseActualParameters(NULL, kAllowConst); | 10564 ArgumentListNode* arguments = ParseActualParameters(NULL, kAllowConst); |
| 10564 return BuildClosureCall(call_pos, closure, arguments); | 10565 return BuildClosureCall(call_pos, closure, arguments); |
| 10565 } | 10566 } |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10745 const intptr_t ident_pos = TokenPos(); | 10746 const intptr_t ident_pos = TokenPos(); |
| 10746 String* ident = ExpectIdentifier("identifier expected"); | 10747 String* ident = ExpectIdentifier("identifier expected"); |
| 10747 if (CurrentToken() == Token::kLPAREN) { | 10748 if (CurrentToken() == Token::kLPAREN) { |
| 10748 // Identifier followed by a opening paren: method call. | 10749 // Identifier followed by a opening paren: method call. |
| 10749 if (left->IsPrimaryNode() && | 10750 if (left->IsPrimaryNode() && |
| 10750 left->AsPrimaryNode()->primary().IsClass()) { | 10751 left->AsPrimaryNode()->primary().IsClass()) { |
| 10751 // Static method call prefixed with class name. | 10752 // Static method call prefixed with class name. |
| 10752 const Class& cls = Class::Cast(left->AsPrimaryNode()->primary()); | 10753 const Class& cls = Class::Cast(left->AsPrimaryNode()->primary()); |
| 10753 selector = ParseStaticCall(cls, *ident, ident_pos); | 10754 selector = ParseStaticCall(cls, *ident, ident_pos); |
| 10754 } else { | 10755 } else { |
| 10755 selector = ParseInstanceCall(left, *ident); | 10756 selector = ParseInstanceCall(left, *ident, ident_pos); |
| 10756 } | 10757 } |
| 10757 } else { | 10758 } else { |
| 10758 // Field access. | 10759 // Field access. |
| 10759 Class& cls = Class::Handle(Z); | 10760 Class& cls = Class::Handle(Z); |
| 10760 if (left->IsPrimaryNode()) { | 10761 if (left->IsPrimaryNode()) { |
| 10761 PrimaryNode* primary_node = left->AsPrimaryNode(); | 10762 PrimaryNode* primary_node = left->AsPrimaryNode(); |
| 10762 if (primary_node->primary().IsClass()) { | 10763 if (primary_node->primary().IsClass()) { |
| 10763 // If the primary node referred to a class we are loading a | 10764 // If the primary node referred to a class we are loading a |
| 10764 // qualified static field. | 10765 // qualified static field. |
| 10765 cls ^= primary_node->primary().raw(); | 10766 cls ^= primary_node->primary().raw(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10839 Class& cls = Class::Handle(Z, func.Owner()); | 10840 Class& cls = Class::Handle(Z, func.Owner()); |
| 10840 selector = ParseStaticCall(cls, func_name, primary_pos); | 10841 selector = ParseStaticCall(cls, func_name, primary_pos); |
| 10841 } else { | 10842 } else { |
| 10842 // Dynamic function call on implicit "this" parameter. | 10843 // Dynamic function call on implicit "this" parameter. |
| 10843 if (current_function().is_static()) { | 10844 if (current_function().is_static()) { |
| 10844 ReportError(primary_pos, | 10845 ReportError(primary_pos, |
| 10845 "cannot access instance method '%s' " | 10846 "cannot access instance method '%s' " |
| 10846 "from static function", | 10847 "from static function", |
| 10847 func_name.ToCString()); | 10848 func_name.ToCString()); |
| 10848 } | 10849 } |
| 10849 selector = ParseInstanceCall(LoadReceiver(primary_pos), func_name); | 10850 selector = ParseInstanceCall(LoadReceiver(primary_pos), |
| 10851 func_name, |
| 10852 primary_pos); |
| 10850 } | 10853 } |
| 10851 } else if (primary_node->primary().IsString()) { | 10854 } else if (primary_node->primary().IsString()) { |
| 10852 // Primary is an unresolved name. | 10855 // Primary is an unresolved name. |
| 10853 if (primary_node->IsSuper()) { | 10856 if (primary_node->IsSuper()) { |
| 10854 ReportError(primary_pos, "illegal use of super"); | 10857 ReportError(primary_pos, "illegal use of super"); |
| 10855 } | 10858 } |
| 10856 String& name = String::CheckedZoneHandle( | 10859 String& name = String::CheckedZoneHandle( |
| 10857 primary_node->primary().raw()); | 10860 primary_node->primary().raw()); |
| 10858 if (current_function().is_static()) { | 10861 if (current_function().is_static()) { |
| 10859 selector = ThrowNoSuchMethodError(primary_pos, | 10862 selector = ThrowNoSuchMethodError(primary_pos, |
| 10860 current_class(), | 10863 current_class(), |
| 10861 name, | 10864 name, |
| 10862 NULL, // No arguments. | 10865 NULL, // No arguments. |
| 10863 InvocationMirror::kStatic, | 10866 InvocationMirror::kStatic, |
| 10864 InvocationMirror::kMethod, | 10867 InvocationMirror::kMethod, |
| 10865 NULL); // No existing function. | 10868 NULL); // No existing function. |
| 10866 } else { | 10869 } else { |
| 10867 // Treat as call to unresolved (instance) method. | 10870 // Treat as call to unresolved (instance) method. |
| 10868 selector = ParseInstanceCall(LoadReceiver(primary_pos), name); | 10871 selector = ParseInstanceCall(LoadReceiver(primary_pos), |
| 10872 name, |
| 10873 primary_pos); |
| 10869 } | 10874 } |
| 10870 } else if (primary_node->primary().IsTypeParameter()) { | 10875 } else if (primary_node->primary().IsTypeParameter()) { |
| 10871 const String& name = String::ZoneHandle(Z, | 10876 const String& name = String::ZoneHandle(Z, |
| 10872 TypeParameter::Cast(primary_node->primary()).name()); | 10877 TypeParameter::Cast(primary_node->primary()).name()); |
| 10873 if (ParsingStaticMember()) { | 10878 if (ParsingStaticMember()) { |
| 10874 // Treat as this.T(), because T is in scope. | 10879 // Treat as this.T(), because T is in scope. |
| 10875 ReportError(primary_pos, | 10880 ReportError(primary_pos, |
| 10876 "cannot access type parameter '%s' " | 10881 "cannot access type parameter '%s' " |
| 10877 "from static function", | 10882 "from static function", |
| 10878 name.ToCString()); | 10883 name.ToCString()); |
| 10879 } else { | 10884 } else { |
| 10880 // Treat as call to unresolved (instance) method. | 10885 // Treat as call to unresolved (instance) method. |
| 10881 selector = ParseInstanceCall(LoadReceiver(primary_pos), name); | 10886 selector = ParseInstanceCall(LoadReceiver(primary_pos), |
| 10887 name, |
| 10888 primary_pos); |
| 10882 } | 10889 } |
| 10883 } else if (primary_node->primary().IsClass()) { | 10890 } else if (primary_node->primary().IsClass()) { |
| 10884 const Class& type_class = Class::Cast(primary_node->primary()); | 10891 const Class& type_class = Class::Cast(primary_node->primary()); |
| 10885 AbstractType& type = Type::ZoneHandle(Z, Type::New( | 10892 AbstractType& type = Type::ZoneHandle(Z, Type::New( |
| 10886 type_class, TypeArguments::Handle(Z), primary_pos)); | 10893 type_class, TypeArguments::Handle(Z), primary_pos)); |
| 10887 type ^= ClassFinalizer::FinalizeType( | 10894 type ^= ClassFinalizer::FinalizeType( |
| 10888 current_class(), type, ClassFinalizer::kCanonicalize); | 10895 current_class(), type, ClassFinalizer::kCanonicalize); |
| 10889 // Type may be malbounded, but not malformed. | 10896 // Type may be malbounded, but not malformed. |
| 10890 ASSERT(!type.IsMalformed()); | 10897 ASSERT(!type.IsMalformed()); |
| 10891 selector = new(Z) TypeNode(primary_pos, type); | 10898 selector = new(Z) TypeNode(primary_pos, type); |
| (...skipping 2316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13208 void Parser::SkipQualIdent() { | 13215 void Parser::SkipQualIdent() { |
| 13209 ASSERT(IsIdentifier()); | 13216 ASSERT(IsIdentifier()); |
| 13210 ConsumeToken(); | 13217 ConsumeToken(); |
| 13211 if (CurrentToken() == Token::kPERIOD) { | 13218 if (CurrentToken() == Token::kPERIOD) { |
| 13212 ConsumeToken(); // Consume the kPERIOD token. | 13219 ConsumeToken(); // Consume the kPERIOD token. |
| 13213 ExpectIdentifier("identifier expected after '.'"); | 13220 ExpectIdentifier("identifier expected after '.'"); |
| 13214 } | 13221 } |
| 13215 } | 13222 } |
| 13216 | 13223 |
| 13217 } // namespace dart | 13224 } // namespace dart |
| OLD | NEW |