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

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

Issue 2607173002: - report tear offs using the x#y syntax as a compilation error (Closed)
Patch Set: run formatter. Created 3 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
« no previous file with comments | « runtime/vm/isolate_reload_test.cc ('k') | tests/co19/co19-dartium.status » ('j') | 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 26 matching lines...) Expand all
37 #include "vm/symbols.h" 37 #include "vm/symbols.h"
38 #include "vm/tags.h" 38 #include "vm/tags.h"
39 #include "vm/timeline.h" 39 #include "vm/timeline.h"
40 #include "vm/timer.h" 40 #include "vm/timer.h"
41 #include "vm/zone.h" 41 #include "vm/zone.h"
42 42
43 namespace dart { 43 namespace dart {
44 44
45 DEFINE_FLAG(bool, enable_debug_break, false, "Allow use of break \"message\"."); 45 DEFINE_FLAG(bool, enable_debug_break, false, "Allow use of break \"message\".");
46 DEFINE_FLAG(bool, trace_parser, false, "Trace parser operations."); 46 DEFINE_FLAG(bool, trace_parser, false, "Trace parser operations.");
47 DEFINE_FLAG(bool, warn_new_tearoff_syntax, true, "Warning on new tear off."); 47 DEFINE_FLAG(bool,
48 support_deprecated_tearoff_syntax,
49 false,
50 "Support new tear-off syntax.");
48 // TODO(floitsch): remove the conditional-directive flag, once we publicly 51 // TODO(floitsch): remove the conditional-directive flag, once we publicly
49 // committed to the current version. 52 // committed to the current version.
50 DEFINE_FLAG(bool, 53 DEFINE_FLAG(bool,
51 conditional_directives, 54 conditional_directives,
52 true, 55 true,
53 "Enable conditional directives"); 56 "Enable conditional directives");
54 DEFINE_FLAG(bool, generic_method_syntax, true, "Enable generic functions."); 57 DEFINE_FLAG(bool, generic_method_syntax, true, "Enable generic functions.");
55 DEFINE_FLAG(bool, 58 DEFINE_FLAG(bool,
56 initializing_formal_access, 59 initializing_formal_access,
57 true, 60 true,
(...skipping 11639 matching lines...) Expand 10 before | Expand all | Expand 10 after
11697 return left; 11700 return left;
11698 } 11701 }
11699 ASSERT(selector != NULL); 11702 ASSERT(selector != NULL);
11700 left = selector; 11703 left = selector;
11701 } 11704 }
11702 } 11705 }
11703 11706
11704 11707
11705 // Closurization e#m of getter, setter, method or operator. 11708 // Closurization e#m of getter, setter, method or operator.
11706 AstNode* Parser::ParseClosurization(AstNode* primary) { 11709 AstNode* Parser::ParseClosurization(AstNode* primary) {
11707 if (FLAG_warn_new_tearoff_syntax) { 11710 if (!FLAG_support_deprecated_tearoff_syntax) {
11708 ReportWarning( 11711 ReportError("tear-off using the x#id syntax is a deprecated feature");
11709 "Tear-offs using the x#id syntax is a deprecated feature," 11712 return NULL;
11710 "it will not be supported in the next release");
11711 } 11713 }
11712 ExpectToken(Token::kHASH); 11714 ExpectToken(Token::kHASH);
11713 TokenPosition property_pos = TokenPos(); 11715 TokenPosition property_pos = TokenPos();
11714 bool is_setter_name = false; 11716 bool is_setter_name = false;
11715 11717
11716 String& extractor_name = String::ZoneHandle(Z); 11718 String& extractor_name = String::ZoneHandle(Z);
11717 if (IsIdentifier()) { 11719 if (IsIdentifier()) {
11718 extractor_name = CurrentLiteral()->raw(); 11720 extractor_name = CurrentLiteral()->raw();
11719 ConsumeToken(); 11721 ConsumeToken();
11720 if (CurrentToken() == Token::kASSIGN) { 11722 if (CurrentToken() == Token::kASSIGN) {
(...skipping 21 matching lines...) Expand all
11742 const bool is_private_name = 11744 const bool is_private_name =
11743 (extractor_name.CharAt(0) == Library::kPrivateIdentifierStart); 11745 (extractor_name.CharAt(0) == Library::kPrivateIdentifierStart);
11744 if (!is_private_name) { 11746 if (!is_private_name) {
11745 // Private names are not exported by libraries. The name mangling 11747 // Private names are not exported by libraries. The name mangling
11746 // of private names with a library-specific suffix usually ensures 11748 // of private names with a library-specific suffix usually ensures
11747 // that _x in library A is not found when looked up from library B. 11749 // that _x in library A is not found when looked up from library B.
11748 // In the pathological case where a library imports itself with 11750 // In the pathological case where a library imports itself with
11749 // a prefix, the name mangling does not help in hiding the private 11751 // a prefix, the name mangling does not help in hiding the private
11750 // name, so we explicitly prevent lookup of private names here. 11752 // name, so we explicitly prevent lookup of private names here.
11751 if (is_setter_name) { 11753 if (is_setter_name) {
11752 String& setter_name = 11754 const String& setter_name =
11753 String::Handle(Z, Field::SetterName(extractor_name)); 11755 String::Handle(Z, Field::SetterName(extractor_name));
11754 obj = prefix.LookupObject(setter_name); 11756 obj = prefix.LookupObject(setter_name);
11755 } 11757 }
11756 if (obj.IsNull()) { 11758 if (obj.IsNull()) {
11757 obj = prefix.LookupObject(extractor_name); 11759 obj = prefix.LookupObject(extractor_name);
11758 } 11760 }
11759 } 11761 }
11760 if (!prefix.is_loaded() && (parsed_function() != NULL) && 11762 if (!prefix.is_loaded() && (parsed_function() != NULL) &&
11761 !FLAG_load_deferred_eagerly) { 11763 !FLAG_load_deferred_eagerly) {
11762 // Remember that this function depends on an import prefix of an 11764 // Remember that this function depends on an import prefix of an
11763 // unloaded deferred library. 11765 // unloaded deferred library.
11764 parsed_function()->AddDeferredPrefix(prefix); 11766 parsed_function()->AddDeferredPrefix(prefix);
11765 } 11767 }
11766 11768
11767 if (obj.IsFunction()) { 11769 if (obj.IsFunction()) {
11768 const Function& func = Function::Cast(obj); 11770 const Function& func = Function::Cast(obj);
11769 if (!func.IsSetterFunction() || is_setter_name) { 11771 if (!func.IsSetterFunction() || is_setter_name) {
11770 return CreateImplicitClosureNode(func, property_pos, NULL); 11772 return CreateImplicitClosureNode(func, property_pos, NULL);
11771 } 11773 }
11772 } else if (obj.IsField()) { 11774 } else if (obj.IsField()) {
11773 const Field& field = Field::Cast(obj); 11775 const Field& field = Field::Cast(obj);
11774 if (is_setter_name && !field.is_final()) { 11776 if (is_setter_name && !field.is_final()) {
11775 Instance& setter_closure = Instance::ZoneHandle(field.SetterClosure()); 11777 const Instance& setter_closure =
11778 Instance::ZoneHandle(field.SetterClosure());
11776 return new (Z) LiteralNode(property_pos, setter_closure); 11779 return new (Z) LiteralNode(property_pos, setter_closure);
11777 } 11780 }
11778 if (!is_setter_name) { 11781 if (!is_setter_name) {
11779 Instance& getter_closure = Instance::ZoneHandle(field.GetterClosure()); 11782 const Instance& getter_closure =
11783 Instance::ZoneHandle(field.GetterClosure());
11780 return new (Z) LiteralNode(property_pos, getter_closure); 11784 return new (Z) LiteralNode(property_pos, getter_closure);
11781 } 11785 }
11782 } 11786 }
11783 return ThrowNoSuchMethodError( 11787 return ThrowNoSuchMethodError(
11784 property_pos, current_class(), extractor_name, 11788 property_pos, current_class(), extractor_name,
11785 NULL, // No arguments. 11789 NULL, // No arguments.
11786 InvocationMirror::kTopLevel, 11790 InvocationMirror::kTopLevel,
11787 is_setter_name ? InvocationMirror::kSetter : InvocationMirror::kMethod, 11791 is_setter_name ? InvocationMirror::kSetter : InvocationMirror::kMethod,
11788 NULL); // No existing function. 11792 NULL); // No existing function.
11789 } 11793 }
(...skipping 1551 matching lines...) Expand 10 before | Expand all | Expand 10 after
13341 (la3 == Token::kLT) || (la3 == Token::kPERIOD) || (la3 == Token::kHASH); 13345 (la3 == Token::kLT) || (la3 == Token::kPERIOD) || (la3 == Token::kHASH);
13342 LibraryPrefix& prefix = LibraryPrefix::ZoneHandle(Z); 13346 LibraryPrefix& prefix = LibraryPrefix::ZoneHandle(Z);
13343 AbstractType& type = 13347 AbstractType& type =
13344 AbstractType::Handle(Z, ParseType(ClassFinalizer::kCanonicalizeWellFormed, 13348 AbstractType::Handle(Z, ParseType(ClassFinalizer::kCanonicalizeWellFormed,
13345 true, // allow deferred type 13349 true, // allow deferred type
13346 consume_unresolved_prefix, &prefix)); 13350 consume_unresolved_prefix, &prefix));
13347 // A constructor tear-off closure can only have been created for a 13351 // A constructor tear-off closure can only have been created for a
13348 // type that is loaded. 13352 // type that is loaded.
13349 ASSERT(prefix.IsNull() || prefix.is_loaded()); 13353 ASSERT(prefix.IsNull() || prefix.is_loaded());
13350 ASSERT(!type.IsMalformed() && !type.IsTypeParameter()); 13354 ASSERT(!type.IsMalformed() && !type.IsTypeParameter());
13351 if (FLAG_warn_new_tearoff_syntax) { 13355 if (!FLAG_support_deprecated_tearoff_syntax) {
13352 ReportWarning( 13356 ReportError("tear-off using the x#id syntax is a deprecated feature");
13353 "Tear-offs using the x#id syntax is a deprecated feature," 13357 return;
13354 "it will not be supported in the next release");
13355 } 13358 }
13356 ExpectToken(Token::kHASH); 13359 ExpectToken(Token::kHASH);
13357 String* named_constructor = NULL; 13360 String* named_constructor = NULL;
13358 if (IsIdentifier()) { 13361 if (IsIdentifier()) {
13359 named_constructor = CurrentLiteral(); 13362 named_constructor = CurrentLiteral();
13360 ConsumeToken(); 13363 ConsumeToken();
13361 } 13364 }
13362 // Resolve the type and optional identifier to a constructor or factory. 13365 // Resolve the type and optional identifier to a constructor or factory.
13363 Class& type_class = Class::Handle(Z, type.type_class()); 13366 Class& type_class = Class::Handle(Z, type.type_class());
13364 String& type_class_name = String::Handle(Z, type_class.Name()); 13367 String& type_class_name = String::Handle(Z, type_class.Name());
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
13441 String::Handle(Z, type_class.Name()).ToCString()); 13444 String::Handle(Z, type_class.Name()).ToCString());
13442 } 13445 }
13443 13446
13444 // The type can be followed by an optional named constructor identifier. 13447 // The type can be followed by an optional named constructor identifier.
13445 // Note that we tell ParseType() above not to consume it as part of 13448 // Note that we tell ParseType() above not to consume it as part of
13446 // a misinterpreted qualified identifier. Only a valid library 13449 // a misinterpreted qualified identifier. Only a valid library
13447 // prefix is accepted as qualifier. 13450 // prefix is accepted as qualifier.
13448 String* named_constructor = NULL; 13451 String* named_constructor = NULL;
13449 const bool is_tearoff_expression = (CurrentToken() == Token::kHASH); 13452 const bool is_tearoff_expression = (CurrentToken() == Token::kHASH);
13450 if (is_tearoff_expression) { 13453 if (is_tearoff_expression) {
13454 if (!FLAG_support_deprecated_tearoff_syntax) {
13455 ReportError("tear-off using the x#id syntax is a deprecated feature");
13456 }
13451 if (is_const) { 13457 if (is_const) {
13452 ReportError("tear-off closure not allowed with const allocation"); 13458 ReportError("tear-off closure not allowed with const allocation");
13453 } 13459 }
13454 if (FLAG_warn_new_tearoff_syntax) {
13455 ReportWarning(
13456 "Tear-offs using the x#id syntax is a deprecated feature,"
13457 "and will not be supported in the next release");
13458 }
13459 ConsumeToken(); 13460 ConsumeToken();
13460 if (IsIdentifier()) { 13461 if (IsIdentifier()) {
13461 named_constructor = ExpectIdentifier("name of constructor expected"); 13462 named_constructor = ExpectIdentifier("name of constructor expected");
13462 } 13463 }
13463 } else if (CurrentToken() == Token::kPERIOD) { 13464 } else if (CurrentToken() == Token::kPERIOD) {
13464 ConsumeToken(); 13465 ConsumeToken();
13465 named_constructor = ExpectIdentifier("name of constructor expected"); 13466 named_constructor = ExpectIdentifier("name of constructor expected");
13466 } 13467 }
13467 13468
13468 // Parse constructor parameters. 13469 // Parse constructor parameters.
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
13886 ASSERT(!is_top_level_); 13887 ASSERT(!is_top_level_);
13887 AstNode* primary = NULL; 13888 AstNode* primary = NULL;
13888 const Token::Kind token = CurrentToken(); 13889 const Token::Kind token = CurrentToken();
13889 if (IsFunctionLiteral()) { 13890 if (IsFunctionLiteral()) {
13890 primary = ParseFunctionStatement(true); 13891 primary = ParseFunctionStatement(true);
13891 } else if (IsIdentifier()) { 13892 } else if (IsIdentifier()) {
13892 TokenPosition qual_ident_pos = TokenPos(); 13893 TokenPosition qual_ident_pos = TokenPos();
13893 const LibraryPrefix& prefix = LibraryPrefix::ZoneHandle(Z, ParsePrefix()); 13894 const LibraryPrefix& prefix = LibraryPrefix::ZoneHandle(Z, ParsePrefix());
13894 if (!prefix.IsNull()) { 13895 if (!prefix.IsNull()) {
13895 if (CurrentToken() == Token::kHASH) { 13896 if (CurrentToken() == Token::kHASH) {
13896 if (FLAG_warn_new_tearoff_syntax) { 13897 if (!FLAG_support_deprecated_tearoff_syntax) {
13897 ReportWarning( 13898 ReportError("tear-off using the x#id syntax is a deprecated feature");
13898 "Tear-offs using the x#id syntax is a deprecated feature,"
13899 "it will not be supported in the next release");
13900 } 13899 }
13901 // Closurization of top-level entity in prefix scope. 13900 // Closurization of top-level entity in prefix scope.
13902 return new (Z) LiteralNode(qual_ident_pos, prefix); 13901 return new (Z) LiteralNode(qual_ident_pos, prefix);
13903 } else { 13902 } else {
13904 ExpectToken(Token::kPERIOD); 13903 ExpectToken(Token::kPERIOD);
13905 } 13904 }
13906 } 13905 }
13907 String& ident = *CurrentLiteral(); 13906 String& ident = *CurrentLiteral();
13908 ConsumeToken(); 13907 ConsumeToken();
13909 if (prefix.IsNull()) { 13908 if (prefix.IsNull()) {
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after
14594 const ArgumentListNode& function_args, 14593 const ArgumentListNode& function_args,
14595 const LocalVariable* temp_for_last_arg, 14594 const LocalVariable* temp_for_last_arg,
14596 bool is_super_invocation) { 14595 bool is_super_invocation) {
14597 UNREACHABLE(); 14596 UNREACHABLE();
14598 return NULL; 14597 return NULL;
14599 } 14598 }
14600 14599
14601 } // namespace dart 14600 } // namespace dart
14602 14601
14603 #endif // DART_PRECOMPILED_RUNTIME 14602 #endif // DART_PRECOMPILED_RUNTIME
OLDNEW
« no previous file with comments | « runtime/vm/isolate_reload_test.cc ('k') | tests/co19/co19-dartium.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698