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

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

Issue 9150036: Skip qualified identifiers that are part of ignored types. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/parser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/parser.h" 5 #include "vm/parser.h"
6 6
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/compiler_stats.h" 10 #include "vm/compiler_stats.h"
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 } 815 }
816 // We have not seen a parameter type yet, so we check if the next 816 // We have not seen a parameter type yet, so we check if the next
817 // identifier could represent a type before parsing it. 817 // identifier could represent a type before parsing it.
818 Token::Kind follower = LookaheadToken(1); 818 Token::Kind follower = LookaheadToken(1);
819 // We have an identifier followed by a 'follower' token. 819 // We have an identifier followed by a 'follower' token.
820 // We either parse a type or assume that no type is specified. 820 // We either parse a type or assume that no type is specified.
821 if ((follower == Token::kLT) || // Parameterized type. 821 if ((follower == Token::kLT) || // Parameterized type.
822 (follower == Token::kPERIOD) || // Qualified class name of type. 822 (follower == Token::kPERIOD) || // Qualified class name of type.
823 Token::IsIdentifier(follower) || // Parameter name following a type. 823 Token::IsIdentifier(follower) || // Parameter name following a type.
824 (follower == Token::kTHIS)) { // Field parameter following a type. 824 (follower == Token::kTHIS)) { // Field parameter following a type.
825 // The types of formal parameters are never ignored, even in unchecked
826 // mode, because they are part of the function type of closurized
827 // functions appearing in type tests with typedef's.
hausner 2012/01/19 18:20:35 typedefs
regis 2012/01/19 18:31:33 Done.
825 parameter.type = &AbstractType::ZoneHandle( 828 parameter.type = &AbstractType::ZoneHandle(
826 ParseType(is_top_level_ ? kCanResolve : kMustResolve)); 829 ParseType(is_top_level_ ? kCanResolve : kMustResolve));
827 } else { 830 } else {
828 parameter.type = &Type::ZoneHandle(Type::DynamicType()); 831 parameter.type = &Type::ZoneHandle(Type::DynamicType());
829 } 832 }
830 } 833 }
831 if (!this_seen && (CurrentToken() == Token::kTHIS)) { 834 if (!this_seen && (CurrentToken() == Token::kTHIS)) {
832 ConsumeToken(); 835 ConsumeToken();
833 ExpectToken(Token::kPERIOD); 836 ExpectToken(Token::kPERIOD);
834 this_seen = true; 837 this_seen = true;
(...skipping 1487 matching lines...) Expand 10 before | Expand all | Expand 10 after
2322 // We have an identifier followed by a 'follower' token. 2325 // We have an identifier followed by a 'follower' token.
2323 // We either parse a type or assume that no type is specified. 2326 // We either parse a type or assume that no type is specified.
2324 if ((follower == Token::kLT) || // Parameterized type. 2327 if ((follower == Token::kLT) || // Parameterized type.
2325 (follower == Token::kGET) || // Getter following a type. 2328 (follower == Token::kGET) || // Getter following a type.
2326 (follower == Token::kSET) || // Setter following a type. 2329 (follower == Token::kSET) || // Setter following a type.
2327 (follower == Token::kOPERATOR) || // Operator following a type. 2330 (follower == Token::kOPERATOR) || // Operator following a type.
2328 (Token::IsIdentifier(follower)) || // Member name following a type. 2331 (Token::IsIdentifier(follower)) || // Member name following a type.
2329 ((follower == Token::kPERIOD) && // Qualified class name of type, 2332 ((follower == Token::kPERIOD) && // Qualified class name of type,
2330 (LookaheadToken(3) != Token::kLPAREN))) { // but not a named constr. 2333 (LookaheadToken(3) != Token::kLPAREN))) { // but not a named constr.
2331 ASSERT(is_top_level_); 2334 ASSERT(is_top_level_);
2335 // The declared type of fields is never ignored, even in unchecked mode,
2336 // because getters and setters could be closurized at some time (not
2337 // supported yet).
2332 member.type = &AbstractType::ZoneHandle(ParseType(kCanResolve)); 2338 member.type = &AbstractType::ZoneHandle(ParseType(kCanResolve));
2333 } 2339 }
2334 } 2340 }
2335 } 2341 }
2336 // Optionally parse a (possibly named) constructor name or factory. 2342 // Optionally parse a (possibly named) constructor name or factory.
2337 if (IsIdentifier() && 2343 if (IsIdentifier() &&
2338 (CurrentLiteral()->Equals(members->class_name()) || member.has_factory)) { 2344 (CurrentLiteral()->Equals(members->class_name()) || member.has_factory)) {
2339 member.name = CurrentLiteral(); 2345 member.name = CurrentLiteral();
2340 member.name_pos = this->token_index_; 2346 member.name_pos = this->token_index_;
2341 ConsumeToken(); 2347 ConsumeToken();
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
2656 void Parser::ParseFunctionTypeAlias(GrowableArray<const Class*>* classes) { 2662 void Parser::ParseFunctionTypeAlias(GrowableArray<const Class*>* classes) {
2657 TRACE_PARSER("ParseFunctionTypeAlias"); 2663 TRACE_PARSER("ParseFunctionTypeAlias");
2658 ExpectToken(Token::kTYPEDEF); 2664 ExpectToken(Token::kTYPEDEF);
2659 2665
2660 AbstractType& result_type = Type::Handle(Type::DynamicType()); 2666 AbstractType& result_type = Type::Handle(Type::DynamicType());
2661 const intptr_t result_type_pos = token_index_; 2667 const intptr_t result_type_pos = token_index_;
2662 if (CurrentToken() == Token::kVOID) { 2668 if (CurrentToken() == Token::kVOID) {
2663 ConsumeToken(); 2669 ConsumeToken();
2664 result_type = Type::VoidType(); 2670 result_type = Type::VoidType();
2665 } else if (!IsFunctionTypeAliasName()) { 2671 } else if (!IsFunctionTypeAliasName()) {
2666 result_type = ParseType(kDoNotResolve); // No owner class yet. 2672 // Type annotations in typedef are never ignored, even in unchecked mode.
2673 // Wait until we have an owner class before resolving the result type.
2674 result_type = ParseType(kDoNotResolve);
2667 } 2675 }
2668 2676
2669 const intptr_t alias_name_pos = token_index_; 2677 const intptr_t alias_name_pos = token_index_;
2670 const String* alias_name = 2678 const String* alias_name =
2671 ExpectTypeIdentifier("function alias name expected"); 2679 ExpectTypeIdentifier("function alias name expected");
2672 2680
2673 // Allocate an interface to hold the type parameters and their 'extends' 2681 // Allocate an interface to hold the type parameters and their 'extends'
2674 // constraints. Make it the owner of the function type descriptor. 2682 // constraints. Make it the owner of the function type descriptor.
2675 const Class& alias_owner = Class::Handle( 2683 const Class& alias_owner = Class::Handle(
2676 Class::New(String::Handle(String::NewSymbol(":alias_owner")), 2684 Class::New(String::Handle(String::NewSymbol(":alias_owner")),
(...skipping 3972 matching lines...) Expand 10 before | Expand all | Expand 10 after
6649 // Parses type = [ident "."] ident ["<" type { "," type } ">"]. 6657 // Parses type = [ident "."] ident ["<" type { "," type } ">"].
6650 // Returns the class object if the type can be resolved. Otherwise, either give 6658 // Returns the class object if the type can be resolved. Otherwise, either give
6651 // an error if type resolution was required, or return the unresolved name as a 6659 // an error if type resolution was required, or return the unresolved name as a
6652 // string object. 6660 // string object.
6653 RawAbstractType* Parser::ParseType(TypeResolution type_resolution) { 6661 RawAbstractType* Parser::ParseType(TypeResolution type_resolution) {
6654 if (CurrentToken() != Token::kIDENT) { 6662 if (CurrentToken() != Token::kIDENT) {
6655 ErrorMsg("type name expected"); 6663 ErrorMsg("type name expected");
6656 } 6664 }
6657 QualIdent type_name; 6665 QualIdent type_name;
6658 const intptr_t type_pos = token_index_; 6666 const intptr_t type_pos = token_index_;
6659 ParseQualIdent(&type_name); 6667 if (type_resolution == kIgnore) {
6660 if (type_name.is_local_scope_ident) { 6668 SkipQualIdent();
6661 ErrorMsg(type_pos, "using '%s' in this context is invalid", 6669 } else {
6662 type_name.ident->ToCString()); 6670 ParseQualIdent(&type_name);
6671 if (type_name.is_local_scope_ident) {
6672 ErrorMsg(type_pos, "using '%s' in this context is invalid",
6673 type_name.ident->ToCString());
6674 }
6663 } 6675 }
6664 Class& scope_class = Class::Handle(); 6676 Class& scope_class = Class::Handle();
6665 Object& type_class = Object::Handle(); 6677 Object& type_class = Object::Handle();
6666 if (type_resolution == kIgnore) { 6678 if (type_resolution == kIgnore) {
6667 // Leave type_class as null. 6679 // Leave type_class as null.
6668 } else if (type_resolution == kDoNotResolve) { 6680 } else if (type_resolution == kDoNotResolve) {
6669 String& qualifier = String::Handle(); 6681 String& qualifier = String::Handle();
6670 if (type_name.qualifier != NULL) { 6682 if (type_name.qualifier != NULL) {
6671 qualifier ^= type_name.qualifier->raw(); 6683 qualifier ^= type_name.qualifier->raw();
6672 } 6684 }
(...skipping 1084 matching lines...) Expand 10 before | Expand all | Expand 10 after
7757 } 7769 }
7758 } 7770 }
7759 7771
7760 7772
7761 void Parser::SkipNestedExpr() { 7773 void Parser::SkipNestedExpr() {
7762 const bool saved_mode = SetAllowFunctionLiterals(true); 7774 const bool saved_mode = SetAllowFunctionLiterals(true);
7763 SkipExpr(); 7775 SkipExpr();
7764 SetAllowFunctionLiterals(saved_mode); 7776 SetAllowFunctionLiterals(saved_mode);
7765 } 7777 }
7766 7778
7779
7780 void Parser::SkipQualIdent() {
7781 ASSERT(IsIdentifier());
7782 ConsumeToken();
7783 if (CurrentToken() == Token::kPERIOD) {
7784 ConsumeToken(); // Consume the kPERIOD token.
7785 ExpectIdentifier("identifier expected after '.'");
7786 }
7787 }
7788
7767 } // namespace dart 7789 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698