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

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

Issue 2274663004: Backing out change that removed legacy patch syntax (Closed)
Patch Set: Created 4 years, 3 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
« no previous file with comments | « runtime/vm/dart_api_impl_test.cc ('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 #include "vm/flags.h" 6 #include "vm/flags.h"
7 7
8 #ifndef DART_PRECOMPILED_RUNTIME 8 #ifndef DART_PRECOMPILED_RUNTIME
9 9
10 #include "lib/invocation_mirror.h" 10 #include "lib/invocation_mirror.h"
(...skipping 4616 matching lines...) Expand 10 before | Expand all | Expand 10 after
4627 TokenPosition metadata_pos) { 4627 TokenPosition metadata_pos) {
4628 TRACE_PARSER("ParseClassDeclaration"); 4628 TRACE_PARSER("ParseClassDeclaration");
4629 bool is_patch = false; 4629 bool is_patch = false;
4630 bool is_abstract = false; 4630 bool is_abstract = false;
4631 TokenPosition declaration_pos = 4631 TokenPosition declaration_pos =
4632 metadata_pos.IsReal() ? metadata_pos : TokenPos(); 4632 metadata_pos.IsReal() ? metadata_pos : TokenPos();
4633 if (is_patch_source() && IsPatchAnnotation(metadata_pos)) { 4633 if (is_patch_source() && IsPatchAnnotation(metadata_pos)) {
4634 is_patch = true; 4634 is_patch = true;
4635 metadata_pos = TokenPosition::kNoSource; 4635 metadata_pos = TokenPosition::kNoSource;
4636 declaration_pos = TokenPos(); 4636 declaration_pos = TokenPos();
4637 } else if (is_patch_source() &&
4638 (CurrentToken() == Token::kIDENT) &&
4639 CurrentLiteral()->Equals("patch")) {
4640 if (FLAG_warn_patch) {
4641 ReportWarning("deprecated use of patch 'keyword'");
4642 }
4643 ConsumeToken();
4644 is_patch = true;
4637 } else if (CurrentToken() == Token::kABSTRACT) { 4645 } else if (CurrentToken() == Token::kABSTRACT) {
4638 is_abstract = true; 4646 is_abstract = true;
4639 ConsumeToken(); 4647 ConsumeToken();
4640 } 4648 }
4641 ExpectToken(Token::kCLASS); 4649 ExpectToken(Token::kCLASS);
4642 const TokenPosition classname_pos = TokenPos(); 4650 const TokenPosition classname_pos = TokenPos();
4643 String& class_name = *ExpectUserDefinedTypeIdentifier("class name expected"); 4651 String& class_name = *ExpectUserDefinedTypeIdentifier("class name expected");
4644 if (FLAG_trace_parser) { 4652 if (FLAG_trace_parser) {
4645 OS::Print("TopLevel parsing class '%s'\n", class_name.ToCString()); 4653 OS::Print("TopLevel parsing class '%s'\n", class_name.ToCString());
4646 } 4654 }
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
4811 } 4819 }
4812 4820
4813 4821
4814 void Parser::ParseClassDefinition(const Class& cls) { 4822 void Parser::ParseClassDefinition(const Class& cls) {
4815 TRACE_PARSER("ParseClassDefinition"); 4823 TRACE_PARSER("ParseClassDefinition");
4816 INC_STAT(thread(), num_classes_parsed, 1); 4824 INC_STAT(thread(), num_classes_parsed, 1);
4817 set_current_class(cls); 4825 set_current_class(cls);
4818 is_top_level_ = true; 4826 is_top_level_ = true;
4819 String& class_name = String::Handle(Z, cls.Name()); 4827 String& class_name = String::Handle(Z, cls.Name());
4820 SkipMetadata(); 4828 SkipMetadata();
4821 if (CurrentToken() == Token::kABSTRACT) { 4829 if (is_patch_source() &&
4830 (CurrentToken() == Token::kIDENT) &&
4831 CurrentLiteral()->Equals("patch")) {
4832 ConsumeToken();
4833 } else if (CurrentToken() == Token::kABSTRACT) {
4822 ConsumeToken(); 4834 ConsumeToken();
4823 } 4835 }
4824 ExpectToken(Token::kCLASS); 4836 ExpectToken(Token::kCLASS);
4825 const TokenPosition class_pos = TokenPos(); 4837 const TokenPosition class_pos = TokenPos();
4826 ClassDesc members(Z, cls, class_name, false, class_pos); 4838 ClassDesc members(Z, cls, class_name, false, class_pos);
4827 while (CurrentToken() != Token::kLBRACE) { 4839 while (CurrentToken() != Token::kLBRACE) {
4828 ConsumeToken(); 4840 ConsumeToken();
4829 } 4841 }
4830 ExpectToken(Token::kLBRACE); 4842 ExpectToken(Token::kLBRACE);
4831 while (CurrentToken() != Token::kRBRACE) { 4843 while (CurrentToken() != Token::kRBRACE) {
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after
5688 TokenPosition metadata_pos) { 5700 TokenPosition metadata_pos) {
5689 TRACE_PARSER("ParseTopLevelFunction"); 5701 TRACE_PARSER("ParseTopLevelFunction");
5690 const TokenPosition decl_begin_pos = TokenPos(); 5702 const TokenPosition decl_begin_pos = TokenPos();
5691 AbstractType& result_type = Type::Handle(Z, Type::DynamicType()); 5703 AbstractType& result_type = Type::Handle(Z, Type::DynamicType());
5692 const bool is_static = true; 5704 const bool is_static = true;
5693 bool is_external = false; 5705 bool is_external = false;
5694 bool is_patch = false; 5706 bool is_patch = false;
5695 if (is_patch_source() && IsPatchAnnotation(metadata_pos)) { 5707 if (is_patch_source() && IsPatchAnnotation(metadata_pos)) {
5696 is_patch = true; 5708 is_patch = true;
5697 metadata_pos = TokenPosition::kNoSource; 5709 metadata_pos = TokenPosition::kNoSource;
5710 } else if (is_patch_source() &&
5711 (CurrentToken() == Token::kIDENT) &&
5712 CurrentLiteral()->Equals("patch") &&
5713 (LookaheadToken(1) != Token::kLPAREN)) {
5714 if (FLAG_warn_patch) {
5715 ReportWarning("deprecated use of patch 'keyword'");
5716 }
5717 ConsumeToken();
5718 is_patch = true;
5698 } else if (CurrentToken() == Token::kEXTERNAL) { 5719 } else if (CurrentToken() == Token::kEXTERNAL) {
5699 ConsumeToken(); 5720 ConsumeToken();
5700 is_external = true; 5721 is_external = true;
5701 } 5722 }
5702 if (CurrentToken() == Token::kVOID) { 5723 if (CurrentToken() == Token::kVOID) {
5703 ConsumeToken(); 5724 ConsumeToken();
5704 result_type = Type::VoidType(); 5725 result_type = Type::VoidType();
5705 } else { 5726 } else {
5706 // Parse optional type. 5727 // Parse optional type.
5707 if (IsFunctionReturnType()) { 5728 if (IsFunctionReturnType()) {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
5819 TokenPosition metadata_pos) { 5840 TokenPosition metadata_pos) {
5820 TRACE_PARSER("ParseTopLevelAccessor"); 5841 TRACE_PARSER("ParseTopLevelAccessor");
5821 const TokenPosition decl_begin_pos = TokenPos(); 5842 const TokenPosition decl_begin_pos = TokenPos();
5822 const bool is_static = true; 5843 const bool is_static = true;
5823 bool is_external = false; 5844 bool is_external = false;
5824 bool is_patch = false; 5845 bool is_patch = false;
5825 AbstractType& result_type = AbstractType::Handle(Z); 5846 AbstractType& result_type = AbstractType::Handle(Z);
5826 if (is_patch_source() && IsPatchAnnotation(metadata_pos)) { 5847 if (is_patch_source() && IsPatchAnnotation(metadata_pos)) {
5827 is_patch = true; 5848 is_patch = true;
5828 metadata_pos = TokenPosition::kNoSource; 5849 metadata_pos = TokenPosition::kNoSource;
5850 } else if (is_patch_source() &&
5851 (CurrentToken() == Token::kIDENT) &&
5852 CurrentLiteral()->Equals("patch")) {
5853 if (FLAG_warn_patch) {
5854 ReportWarning("deprecated use of patch 'keyword'");
5855 }
5856 ConsumeToken();
5857 is_patch = true;
5829 } else if (CurrentToken() == Token::kEXTERNAL) { 5858 } else if (CurrentToken() == Token::kEXTERNAL) {
5830 ConsumeToken(); 5859 ConsumeToken();
5831 is_external = true; 5860 is_external = true;
5832 } 5861 }
5833 bool is_getter = (CurrentToken() == Token::kGET); 5862 bool is_getter = (CurrentToken() == Token::kGET);
5834 if (CurrentToken() == Token::kGET || 5863 if (CurrentToken() == Token::kGET ||
5835 CurrentToken() == Token::kSET) { 5864 CurrentToken() == Token::kSET) {
5836 ConsumeToken(); 5865 ConsumeToken();
5837 result_type = Type::DynamicType(); 5866 result_type = Type::DynamicType();
5838 } else { 5867 } else {
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
6362 ParseClassDeclaration(pending_classes, tl_owner, metadata_pos); 6391 ParseClassDeclaration(pending_classes, tl_owner, metadata_pos);
6363 } else if (CurrentToken() == Token::kENUM) { 6392 } else if (CurrentToken() == Token::kENUM) {
6364 ParseEnumDeclaration(pending_classes, tl_owner, metadata_pos); 6393 ParseEnumDeclaration(pending_classes, tl_owner, metadata_pos);
6365 } else if ((CurrentToken() == Token::kTYPEDEF) && 6394 } else if ((CurrentToken() == Token::kTYPEDEF) &&
6366 (LookaheadToken(1) != Token::kLPAREN)) { 6395 (LookaheadToken(1) != Token::kLPAREN)) {
6367 set_current_class(toplevel_class); 6396 set_current_class(toplevel_class);
6368 ParseTypedef(pending_classes, tl_owner, metadata_pos); 6397 ParseTypedef(pending_classes, tl_owner, metadata_pos);
6369 } else if ((CurrentToken() == Token::kABSTRACT) && 6398 } else if ((CurrentToken() == Token::kABSTRACT) &&
6370 (LookaheadToken(1) == Token::kCLASS)) { 6399 (LookaheadToken(1) == Token::kCLASS)) {
6371 ParseClassDeclaration(pending_classes, tl_owner, metadata_pos); 6400 ParseClassDeclaration(pending_classes, tl_owner, metadata_pos);
6401 } else if (is_patch_source() && IsSymbol(Symbols::Patch()) &&
6402 (LookaheadToken(1) == Token::kCLASS)) {
6403 ParseClassDeclaration(pending_classes, tl_owner, metadata_pos);
6372 } else { 6404 } else {
6373 set_current_class(toplevel_class); 6405 set_current_class(toplevel_class);
6374 if (IsVariableDeclaration()) { 6406 if (IsVariableDeclaration()) {
6375 ParseTopLevelVariable(&top_level, tl_owner, metadata_pos); 6407 ParseTopLevelVariable(&top_level, tl_owner, metadata_pos);
6376 } else if (IsFunctionDeclaration()) { 6408 } else if (IsFunctionDeclaration()) {
6377 ParseTopLevelFunction(&top_level, tl_owner, metadata_pos); 6409 ParseTopLevelFunction(&top_level, tl_owner, metadata_pos);
6378 } else if (IsTopLevelAccessor()) { 6410 } else if (IsTopLevelAccessor()) {
6379 ParseTopLevelAccessor(&top_level, tl_owner, metadata_pos); 6411 ParseTopLevelAccessor(&top_level, tl_owner, metadata_pos);
6380 } else if (CurrentToken() == Token::kEOS) { 6412 } else if (CurrentToken() == Token::kEOS) {
6381 break; 6413 break;
(...skipping 1945 matching lines...) Expand 10 before | Expand all | Expand 10 after
8327 return false; 8359 return false;
8328 } 8360 }
8329 8361
8330 8362
8331 // Look ahead to detect whether the next tokens should be parsed as 8363 // Look ahead to detect whether the next tokens should be parsed as
8332 // a function declaration. Token position remains unchanged. 8364 // a function declaration. Token position remains unchanged.
8333 bool Parser::IsFunctionDeclaration() { 8365 bool Parser::IsFunctionDeclaration() {
8334 bool is_external = false; 8366 bool is_external = false;
8335 TokenPosScope decl_pos(this); 8367 TokenPosScope decl_pos(this);
8336 SkipMetadata(); 8368 SkipMetadata();
8337 if ((is_top_level_) && (CurrentToken() == Token::kEXTERNAL)) { 8369 if (is_top_level_) {
8338 // Skip over 'external' for top-level function declarations. 8370 if (is_patch_source() &&
8339 is_external = true; 8371 (CurrentToken() == Token::kIDENT) &&
8340 ConsumeToken(); 8372 CurrentLiteral()->Equals("patch") &&
8373 (LookaheadToken(1) != Token::kLPAREN)) {
8374 // Skip over 'patch' for top-level function declarations in patch sources.
8375 ConsumeToken();
8376 } else if (CurrentToken() == Token::kEXTERNAL) {
8377 // Skip over 'external' for top-level function declarations.
8378 is_external = true;
8379 ConsumeToken();
8380 }
8341 } 8381 }
8342 const TokenPosition type_or_name_pos = TokenPos(); 8382 const TokenPosition type_or_name_pos = TokenPos();
8343 if (TryParseReturnType()) { 8383 if (TryParseReturnType()) {
8344 if (!IsIdentifier()) { 8384 if (!IsIdentifier()) {
8345 SetPosition(type_or_name_pos); 8385 SetPosition(type_or_name_pos);
8346 } 8386 }
8347 } else { 8387 } else {
8348 SetPosition(type_or_name_pos); 8388 SetPosition(type_or_name_pos);
8349 } 8389 }
8350 // Check for function name followed by optional type parameters. 8390 // Check for function name followed by optional type parameters.
(...skipping 19 matching lines...) Expand all
8370 IsSymbol(Symbols::Async()) || 8410 IsSymbol(Symbols::Async()) ||
8371 IsSymbol(Symbols::Sync())) { 8411 IsSymbol(Symbols::Sync())) {
8372 return true; 8412 return true;
8373 } 8413 }
8374 return false; 8414 return false;
8375 } 8415 }
8376 8416
8377 8417
8378 bool Parser::IsTopLevelAccessor() { 8418 bool Parser::IsTopLevelAccessor() {
8379 const TokenPosScope saved_pos(this); 8419 const TokenPosScope saved_pos(this);
8380 if (CurrentToken() == Token::kEXTERNAL) { 8420 if (is_patch_source() && IsSymbol(Symbols::Patch())) {
8421 ConsumeToken();
8422 } else if (CurrentToken() == Token::kEXTERNAL) {
8381 ConsumeToken(); 8423 ConsumeToken();
8382 } 8424 }
8383 if ((CurrentToken() == Token::kGET) || (CurrentToken() == Token::kSET)) { 8425 if ((CurrentToken() == Token::kGET) || (CurrentToken() == Token::kSET)) {
8384 return true; 8426 return true;
8385 } 8427 }
8386 if (TryParseReturnType()) { 8428 if (TryParseReturnType()) {
8387 if ((CurrentToken() == Token::kGET) || (CurrentToken() == Token::kSET)) { 8429 if ((CurrentToken() == Token::kGET) || (CurrentToken() == Token::kSET)) {
8388 if (Token::IsIdentifier(LookaheadToken(1))) { // Accessor name. 8430 if (Token::IsIdentifier(LookaheadToken(1))) { // Accessor name.
8389 return true; 8431 return true;
8390 } 8432 }
(...skipping 6554 matching lines...) Expand 10 before | Expand all | Expand 10 after
14945 const ArgumentListNode& function_args, 14987 const ArgumentListNode& function_args,
14946 const LocalVariable* temp_for_last_arg, 14988 const LocalVariable* temp_for_last_arg,
14947 bool is_super_invocation) { 14989 bool is_super_invocation) {
14948 UNREACHABLE(); 14990 UNREACHABLE();
14949 return NULL; 14991 return NULL;
14950 } 14992 }
14951 14993
14952 } // namespace dart 14994 } // namespace dart
14953 14995
14954 #endif // DART_PRECOMPILED_RUNTIME 14996 #endif // DART_PRECOMPILED_RUNTIME
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698