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

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

Issue 10910079: Catch illegally declared constructors (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/language/bad_constructor_test.dart » ('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 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 2313 matching lines...) Expand 10 before | Expand all | Expand 10 after
2324 ErrorMsg(method->name_pos, "'final' not allowed for methods"); 2324 ErrorMsg(method->name_pos, "'final' not allowed for methods");
2325 } 2325 }
2326 if (method->has_abstract && method->has_static) { 2326 if (method->has_abstract && method->has_static) {
2327 ErrorMsg(method->name_pos, 2327 ErrorMsg(method->name_pos,
2328 "static method '%s' cannot be abstract", 2328 "static method '%s' cannot be abstract",
2329 method->name->ToCString()); 2329 method->name->ToCString());
2330 } 2330 }
2331 if (method->has_const && !(method->IsConstructor() || method->IsFactory())) { 2331 if (method->has_const && !(method->IsConstructor() || method->IsFactory())) {
2332 ErrorMsg(method->name_pos, "'const' not allowed for methods"); 2332 ErrorMsg(method->name_pos, "'const' not allowed for methods");
2333 } 2333 }
2334 if (method->IsConstructor() && method->has_static) { 2334 if (method->IsFactoryOrConstructor() && method->has_abstract) {
2335 ErrorMsg(method->name_pos, "constructor cannot be 'static'"); 2335 ErrorMsg(method->name_pos, "constructor cannot be abstract");
2336 } 2336 }
2337 if (method->IsConstructor() && method->has_const) { 2337 if (method->IsConstructor() && method->has_const) {
2338 Class& cls = Class::ZoneHandle(library_.LookupClass(members->class_name())); 2338 Class& cls = Class::ZoneHandle(library_.LookupClass(members->class_name()));
2339 cls.set_is_const(); 2339 cls.set_is_const();
2340 } 2340 }
2341 if (method->has_abstract && members->is_interface()) { 2341 if (method->has_abstract && members->is_interface()) {
2342 ErrorMsg(method->name_pos, 2342 ErrorMsg(method->name_pos,
2343 "'abstract' method only allowed in class definition"); 2343 "'abstract' method only allowed in class definition");
2344 } 2344 }
2345 if (method->has_external && members->is_interface()) { 2345 if (method->has_external && members->is_interface()) {
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
2782 } 2782 }
2783 if (member.has_final) { 2783 if (member.has_final) {
2784 ErrorMsg("identifier expected after 'final'"); 2784 ErrorMsg("identifier expected after 'final'");
2785 } 2785 }
2786 ConsumeToken(); 2786 ConsumeToken();
2787 member.has_var = true; 2787 member.has_var = true;
2788 // The member type is the 'Dynamic' type. 2788 // The member type is the 'Dynamic' type.
2789 member.type = &Type::ZoneHandle(Type::DynamicType()); 2789 member.type = &Type::ZoneHandle(Type::DynamicType());
2790 } else if (CurrentToken() == Token::kFACTORY) { 2790 } else if (CurrentToken() == Token::kFACTORY) {
2791 ConsumeToken(); 2791 ConsumeToken();
2792 if (member.has_static) {
2793 ErrorMsg("factory method cannot be explicitly marked static");
2794 }
2792 member.has_factory = true; 2795 member.has_factory = true;
2793 member.has_static = true; 2796 member.has_static = true;
2794 // The result type depends on the name of the factory method. 2797 // The result type depends on the name of the factory method.
2795 } 2798 }
2796 // Optionally parse a type. 2799 // Optionally parse a type.
2797 if (CurrentToken() == Token::kVOID) { 2800 if (CurrentToken() == Token::kVOID) {
2798 if (member.has_var || member.has_factory) { 2801 if (member.has_var || member.has_factory) {
2799 ErrorMsg("void not expected"); 2802 ErrorMsg("void not expected");
2800 } 2803 }
2801 ConsumeToken(); 2804 ConsumeToken();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2842 } 2845 }
2843 const Object& result_type_class = Object::Handle( 2846 const Object& result_type_class = Object::Handle(
2844 UnresolvedClass::New(lib_prefix, 2847 UnresolvedClass::New(lib_prefix,
2845 *factory_name.ident, 2848 *factory_name.ident,
2846 factory_name.ident_pos)); 2849 factory_name.ident_pos));
2847 // The type arguments of the result type are set during finalization. 2850 // The type arguments of the result type are set during finalization.
2848 member.type = &Type::ZoneHandle(Type::New(result_type_class, 2851 member.type = &Type::ZoneHandle(Type::New(result_type_class,
2849 TypeArguments::Handle(), 2852 TypeArguments::Handle(),
2850 factory_name.ident_pos)); 2853 factory_name.ident_pos));
2851 } else { 2854 } else {
2855 if (member.has_static) {
2856 ErrorMsg("constructor cannot be static");
2857 }
2852 member.name_pos = TokenPos(); 2858 member.name_pos = TokenPos();
2853 member.name = CurrentLiteral(); 2859 member.name = CurrentLiteral();
2854 ConsumeToken(); 2860 ConsumeToken();
2855 } 2861 }
2856 // We must be dealing with a constructor or named constructor. 2862 // We must be dealing with a constructor or named constructor.
2857 member.kind = RawFunction::kConstructor; 2863 member.kind = RawFunction::kConstructor;
2858 String& ctor_suffix = String::ZoneHandle(Symbols::Dot()); 2864 String& ctor_suffix = String::ZoneHandle(Symbols::Dot());
2859 if (CurrentToken() == Token::kPERIOD) { 2865 if (CurrentToken() == Token::kPERIOD) {
2860 // Named constructor. 2866 // Named constructor.
2861 ConsumeToken(); 2867 ConsumeToken();
(...skipping 6507 matching lines...) Expand 10 before | Expand all | Expand 10 after
9369 void Parser::SkipQualIdent() { 9375 void Parser::SkipQualIdent() {
9370 ASSERT(IsIdentifier()); 9376 ASSERT(IsIdentifier());
9371 ConsumeToken(); 9377 ConsumeToken();
9372 if (CurrentToken() == Token::kPERIOD) { 9378 if (CurrentToken() == Token::kPERIOD) {
9373 ConsumeToken(); // Consume the kPERIOD token. 9379 ConsumeToken(); // Consume the kPERIOD token.
9374 ExpectIdentifier("identifier expected after '.'"); 9380 ExpectIdentifier("identifier expected after '.'");
9375 } 9381 }
9376 } 9382 }
9377 9383
9378 } // namespace dart 9384 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | tests/language/bad_constructor_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698