| 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 3977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3988 // and the alias name of a function type alias. | 3988 // and the alias name of a function type alias. |
| 3989 // Token position remains unchanged. | 3989 // Token position remains unchanged. |
| 3990 bool Parser::IsFunctionTypeAliasName() { | 3990 bool Parser::IsFunctionTypeAliasName() { |
| 3991 if (IsIdentifier() && (LookaheadToken(1) == Token::kLPAREN)) { | 3991 if (IsIdentifier() && (LookaheadToken(1) == Token::kLPAREN)) { |
| 3992 return true; | 3992 return true; |
| 3993 } | 3993 } |
| 3994 const intptr_t saved_pos = TokenPos(); | 3994 const intptr_t saved_pos = TokenPos(); |
| 3995 bool is_alias_name = false; | 3995 bool is_alias_name = false; |
| 3996 if (IsIdentifier() && (LookaheadToken(1) == Token::kLT)) { | 3996 if (IsIdentifier() && (LookaheadToken(1) == Token::kLT)) { |
| 3997 ConsumeToken(); | 3997 ConsumeToken(); |
| 3998 if (TryParseTypeParameter() && (CurrentToken() == Token::kLPAREN)) { | 3998 if (TryParseTypeParameters() && (CurrentToken() == Token::kLPAREN)) { |
| 3999 is_alias_name = true; | 3999 is_alias_name = true; |
| 4000 } | 4000 } |
| 4001 } | 4001 } |
| 4002 SetPosition(saved_pos); | 4002 SetPosition(saved_pos); |
| 4003 return is_alias_name; | 4003 return is_alias_name; |
| 4004 } | 4004 } |
| 4005 | 4005 |
| 4006 | 4006 |
| 4007 // Look ahead to detect if we are seeing ident [ TypeParameters ] "=". | 4007 // Look ahead to detect if we are seeing ident [ TypeParameters ] "=". |
| 4008 // Token position remains unchanged. | 4008 // Token position remains unchanged. |
| 4009 bool Parser::IsMixinTypedef() { | 4009 bool Parser::IsMixinTypedef() { |
| 4010 if (IsIdentifier() && (LookaheadToken(1) == Token::kASSIGN)) { | 4010 if (IsIdentifier() && (LookaheadToken(1) == Token::kASSIGN)) { |
| 4011 return true; | 4011 return true; |
| 4012 } | 4012 } |
| 4013 const intptr_t saved_pos = TokenPos(); | 4013 const intptr_t saved_pos = TokenPos(); |
| 4014 bool is_mixin_def = false; | 4014 bool is_mixin_def = false; |
| 4015 if (IsIdentifier() && (LookaheadToken(1) == Token::kLT)) { | 4015 if (IsIdentifier() && (LookaheadToken(1) == Token::kLT)) { |
| 4016 ConsumeToken(); | 4016 ConsumeToken(); |
| 4017 if (TryParseTypeParameter() && (CurrentToken() == Token::kASSIGN)) { | 4017 if (TryParseTypeParameters() && (CurrentToken() == Token::kASSIGN)) { |
| 4018 is_mixin_def = true; | 4018 is_mixin_def = true; |
| 4019 } | 4019 } |
| 4020 } | 4020 } |
| 4021 SetPosition(saved_pos); | 4021 SetPosition(saved_pos); |
| 4022 return is_mixin_def; | 4022 return is_mixin_def; |
| 4023 } | 4023 } |
| 4024 | 4024 |
| 4025 | 4025 |
| 4026 void Parser::ParseTypedef(const GrowableObjectArray& pending_classes, | 4026 void Parser::ParseTypedef(const GrowableObjectArray& pending_classes, |
| 4027 intptr_t metadata_pos) { | 4027 intptr_t metadata_pos) { |
| (...skipping 1552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5580 } else { | 5580 } else { |
| 5581 AstNode* initialization = | 5581 AstNode* initialization = |
| 5582 new StoreLocalNode(function_pos, function_variable, closure); | 5582 new StoreLocalNode(function_pos, function_variable, closure); |
| 5583 return initialization; | 5583 return initialization; |
| 5584 } | 5584 } |
| 5585 } | 5585 } |
| 5586 | 5586 |
| 5587 | 5587 |
| 5588 // Returns true if the current and next tokens can be parsed as type | 5588 // Returns true if the current and next tokens can be parsed as type |
| 5589 // parameters. Current token position is not saved and restored. | 5589 // parameters. Current token position is not saved and restored. |
| 5590 bool Parser::TryParseTypeParameter() { | 5590 bool Parser::TryParseTypeParameters() { |
| 5591 if (CurrentToken() == Token::kLT) { | 5591 if (CurrentToken() == Token::kLT) { |
| 5592 // We are possibly looking at type parameters. Find closing ">". | 5592 // We are possibly looking at type parameters. Find closing ">". |
| 5593 int nesting_level = 0; | 5593 int nesting_level = 0; |
| 5594 do { | 5594 do { |
| 5595 if (CurrentToken() == Token::kLT) { | 5595 if (CurrentToken() == Token::kLT) { |
| 5596 nesting_level++; | 5596 nesting_level++; |
| 5597 } else if (CurrentToken() == Token::kGT) { | 5597 } else if (CurrentToken() == Token::kGT) { |
| 5598 nesting_level--; | 5598 nesting_level--; |
| 5599 } else if (CurrentToken() == Token::kSHR) { | 5599 } else if (CurrentToken() == Token::kSHR) { |
| 5600 nesting_level -= 2; | 5600 nesting_level -= 2; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5665 return Token::IsIdentifier(CurrentToken()); | 5665 return Token::IsIdentifier(CurrentToken()); |
| 5666 } | 5666 } |
| 5667 | 5667 |
| 5668 | 5668 |
| 5669 // Returns true if the next tokens can be parsed as a type with optional | 5669 // Returns true if the next tokens can be parsed as a type with optional |
| 5670 // type parameters. Current token position is not restored. | 5670 // type parameters. Current token position is not restored. |
| 5671 bool Parser::TryParseOptionalType() { | 5671 bool Parser::TryParseOptionalType() { |
| 5672 if (CurrentToken() == Token::kIDENT) { | 5672 if (CurrentToken() == Token::kIDENT) { |
| 5673 QualIdent type_name; | 5673 QualIdent type_name; |
| 5674 ParseQualIdent(&type_name); | 5674 ParseQualIdent(&type_name); |
| 5675 if ((CurrentToken() == Token::kLT) && !TryParseTypeParameter()) { | 5675 if ((CurrentToken() == Token::kLT) && !TryParseTypeParameters()) { |
| 5676 return false; | 5676 return false; |
| 5677 } | 5677 } |
| 5678 } | 5678 } |
| 5679 return true; | 5679 return true; |
| 5680 } | 5680 } |
| 5681 | 5681 |
| 5682 | 5682 |
| 5683 // Returns true if the next tokens can be parsed as a type with optional | 5683 // Returns true if the next tokens can be parsed as a type with optional |
| 5684 // type parameters, or keyword "void". | 5684 // type parameters, or keyword "void". |
| 5685 // Current token position is not restored. | 5685 // Current token position is not restored. |
| (...skipping 4902 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10588 void Parser::SkipQualIdent() { | 10588 void Parser::SkipQualIdent() { |
| 10589 ASSERT(IsIdentifier()); | 10589 ASSERT(IsIdentifier()); |
| 10590 ConsumeToken(); | 10590 ConsumeToken(); |
| 10591 if (CurrentToken() == Token::kPERIOD) { | 10591 if (CurrentToken() == Token::kPERIOD) { |
| 10592 ConsumeToken(); // Consume the kPERIOD token. | 10592 ConsumeToken(); // Consume the kPERIOD token. |
| 10593 ExpectIdentifier("identifier expected after '.'"); | 10593 ExpectIdentifier("identifier expected after '.'"); |
| 10594 } | 10594 } |
| 10595 } | 10595 } |
| 10596 | 10596 |
| 10597 } // namespace dart | 10597 } // namespace dart |
| OLD | NEW |