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

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

Issue 10837208: Support new getter syntax (no formal parameter list) (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 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/object.h ('k') | tests/co19/co19-runtime.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 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 2086 matching lines...) Expand 10 before | Expand all | Expand 10 after
2097 // the type of the instance to be allocated. 2097 // the type of the instance to be allocated.
2098 if (!func.is_static() && !func.IsClosureFunction()) { 2098 if (!func.is_static() && !func.IsClosureFunction()) {
2099 ASSERT(current_class().raw() == func.owner()); 2099 ASSERT(current_class().raw() == func.owner());
2100 params.AddReceiver(ReceiverType(TokenPos())); 2100 params.AddReceiver(ReceiverType(TokenPos()));
2101 } else if (func.IsFactory()) { 2101 } else if (func.IsFactory()) {
2102 params.AddFinalParameter( 2102 params.AddFinalParameter(
2103 TokenPos(), 2103 TokenPos(),
2104 &String::ZoneHandle(Symbols::TypeArgumentsParameter()), 2104 &String::ZoneHandle(Symbols::TypeArgumentsParameter()),
2105 &Type::ZoneHandle(Type::DynamicType())); 2105 &Type::ZoneHandle(Type::DynamicType()));
2106 } 2106 }
2107 ASSERT(CurrentToken() == Token::kLPAREN); 2107 ASSERT((CurrentToken() == Token::kLPAREN) || func.IsGetterFunction());
2108 const bool allow_explicit_default_values = true; 2108 const bool allow_explicit_default_values = true;
2109 ParseFormalParameterList(allow_explicit_default_values, &params); 2109 if (!func.IsGetterFunction()) {
2110 ParseFormalParameterList(allow_explicit_default_values, &params);
2111 } else {
2112 // TODO(hausner): Remove this once we no longer support the old
2113 // getter syntax with explicit empty parameter list.
2114 if (CurrentToken() == Token::kLPAREN) {
2115 ConsumeToken();
2116 ExpectToken(Token::kRPAREN);
2117 }
2118 }
2110 2119
2111 // The number of parameters and their type are not yet set in local functions, 2120 // The number of parameters and their type are not yet set in local functions,
2112 // since they are not 'top-level' parsed. 2121 // since they are not 'top-level' parsed.
2113 if (func.IsLocalFunction()) { 2122 if (func.IsLocalFunction()) {
2114 AddFormalParamsToFunction(&params, func); 2123 AddFormalParamsToFunction(&params, func);
2115 } 2124 }
2116 SetupDefaultsForOptionalParams(&params, default_parameter_values); 2125 SetupDefaultsForOptionalParams(&params, default_parameter_values);
2117 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); 2126 ASSERT(AbstractType::Handle(func.result_type()).IsResolved());
2118 ASSERT(func.NumberOfParameters() == params.parameters->length()); 2127 ASSERT(func.NumberOfParameters() == params.parameters->length());
2119 2128
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
2254 ExpectIdentifier("identifier expected after '.'"); 2263 ExpectIdentifier("identifier expected after '.'");
2255 } 2264 }
2256 } 2265 }
2257 } 2266 }
2258 } 2267 }
2259 } 2268 }
2260 2269
2261 2270
2262 void Parser::ParseMethodOrConstructor(ClassDesc* members, MemberDesc* method) { 2271 void Parser::ParseMethodOrConstructor(ClassDesc* members, MemberDesc* method) {
2263 TRACE_PARSER("ParseMethodOrConstructor"); 2272 TRACE_PARSER("ParseMethodOrConstructor");
2264 ASSERT(CurrentToken() == Token::kLPAREN); 2273 ASSERT(CurrentToken() == Token::kLPAREN || method->IsGetter());
2265 intptr_t method_pos = this->TokenPos(); 2274 intptr_t method_pos = this->TokenPos();
2266 ASSERT(method->type != NULL); 2275 ASSERT(method->type != NULL);
2267 ASSERT(method->name_pos > 0); 2276 ASSERT(method->name_pos > 0);
2268 ASSERT(current_member_ == method); 2277 ASSERT(current_member_ == method);
2269 2278
2270 if (method->has_var) { 2279 if (method->has_var) {
2271 ErrorMsg(method->name_pos, "keyword var not allowed for methods"); 2280 ErrorMsg(method->name_pos, "keyword var not allowed for methods");
2272 } 2281 }
2273 if (method->has_final) { 2282 if (method->has_final) {
2274 ErrorMsg(method->name_pos, "'final' not allowed for methods"); 2283 ErrorMsg(method->name_pos, "'final' not allowed for methods");
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2316 // Constructors have an implicit parameter for the construction phase. 2325 // Constructors have an implicit parameter for the construction phase.
2317 if (method->IsConstructor()) { 2326 if (method->IsConstructor()) {
2318 method->params.AddFinalParameter( 2327 method->params.AddFinalParameter(
2319 TokenPos(), 2328 TokenPos(),
2320 &String::ZoneHandle(Symbols::PhaseParameter()), 2329 &String::ZoneHandle(Symbols::PhaseParameter()),
2321 &Type::ZoneHandle(Type::IntInterface())); 2330 &Type::ZoneHandle(Type::IntInterface()));
2322 } 2331 }
2323 if (are_implicitly_final) { 2332 if (are_implicitly_final) {
2324 method->params.SetImplicitlyFinal(); 2333 method->params.SetImplicitlyFinal();
2325 } 2334 }
2326 ParseFormalParameterList(allow_explicit_default_values, &method->params); 2335 if (!method->IsGetter()) {
2336 ParseFormalParameterList(allow_explicit_default_values, &method->params);
2337 } else {
2338 // TODO(hausner): Remove this once the old getter syntax with
2339 // empty parameter list is no longer supported.
2340 if (CurrentToken() == Token::kLPAREN) {
2341 ConsumeToken();
2342 ExpectToken(Token::kRPAREN);
2343 }
2344 }
2327 2345
2328 // Now that we know the parameter list, we can distinguish between the 2346 // Now that we know the parameter list, we can distinguish between the
2329 // unary and binary operator -. 2347 // unary and binary operator -.
2330 if (method->has_operator && 2348 if (method->has_operator &&
2331 ((method->name->Equals(Token::Str(Token::kNEGATE))) || 2349 ((method->name->Equals(Token::Str(Token::kNEGATE))) ||
2332 method->name->Equals("-")) && 2350 method->name->Equals("-")) &&
2333 (method->params.num_fixed_parameters == 1)) { 2351 (method->params.num_fixed_parameters == 1)) {
2334 // Patch up name for unary operator - so it does not clash with the 2352 // Patch up name for unary operator - so it does not clash with the
2335 // name for binary operator -. 2353 // name for binary operator -.
2336 *method->name = Symbols::New("unary-"); 2354 *method->name = Symbols::New("unary-");
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
2807 } 2825 }
2808 } else if ((CurrentToken() == Token::kGET) && !member.has_var && 2826 } else if ((CurrentToken() == Token::kGET) && !member.has_var &&
2809 (LookaheadToken(1) != Token::kLPAREN) && 2827 (LookaheadToken(1) != Token::kLPAREN) &&
2810 (LookaheadToken(1) != Token::kASSIGN) && 2828 (LookaheadToken(1) != Token::kASSIGN) &&
2811 (LookaheadToken(1) != Token::kCOMMA) && 2829 (LookaheadToken(1) != Token::kCOMMA) &&
2812 (LookaheadToken(1) != Token::kSEMICOLON)) { 2830 (LookaheadToken(1) != Token::kSEMICOLON)) {
2813 ConsumeToken(); 2831 ConsumeToken();
2814 member.kind = RawFunction::kGetterFunction; 2832 member.kind = RawFunction::kGetterFunction;
2815 member.name_pos = this->TokenPos(); 2833 member.name_pos = this->TokenPos();
2816 member.name = ExpectIdentifier("identifier expected"); 2834 member.name = ExpectIdentifier("identifier expected");
2817 if (CurrentToken() != Token::kLPAREN) {
2818 ErrorMsg("'(' expected");
2819 }
2820 // If the result type was not specified, it will be set to DynamicType. 2835 // If the result type was not specified, it will be set to DynamicType.
2821 } else if ((CurrentToken() == Token::kSET) && !member.has_var && 2836 } else if ((CurrentToken() == Token::kSET) && !member.has_var &&
2822 (LookaheadToken(1) != Token::kLPAREN) && 2837 (LookaheadToken(1) != Token::kLPAREN) &&
2823 (LookaheadToken(1) != Token::kASSIGN) && 2838 (LookaheadToken(1) != Token::kASSIGN) &&
2824 (LookaheadToken(1) != Token::kCOMMA) && 2839 (LookaheadToken(1) != Token::kCOMMA) &&
2825 (LookaheadToken(1) != Token::kSEMICOLON)) { 2840 (LookaheadToken(1) != Token::kSEMICOLON)) {
2826 ConsumeToken(); 2841 ConsumeToken();
2827 member.kind = RawFunction::kSetterFunction; 2842 member.kind = RawFunction::kSetterFunction;
2828 member.name_pos = this->TokenPos(); 2843 member.name_pos = this->TokenPos();
2829 member.name = ExpectIdentifier("identifier expected"); 2844 member.name = ExpectIdentifier("identifier expected");
(...skipping 26 matching lines...) Expand all
2856 ConsumeToken(); 2871 ConsumeToken();
2857 } else if (IsIdentifier()) { 2872 } else if (IsIdentifier()) {
2858 member.name = CurrentLiteral(); 2873 member.name = CurrentLiteral();
2859 member.name_pos = TokenPos(); 2874 member.name_pos = TokenPos();
2860 ConsumeToken(); 2875 ConsumeToken();
2861 } else { 2876 } else {
2862 ErrorMsg("identifier expected"); 2877 ErrorMsg("identifier expected");
2863 } 2878 }
2864 2879
2865 ASSERT(member.name != NULL); 2880 ASSERT(member.name != NULL);
2866 if (CurrentToken() == Token::kLPAREN) { 2881 if (CurrentToken() == Token::kLPAREN || member.IsGetter()) {
2867 if (members->is_interface() && member.has_static) { 2882 if (members->is_interface() && member.has_static) {
2868 if (member.has_factory) { 2883 if (member.has_factory) {
2869 ErrorMsg("factory constructors are not allowed in interfaces"); 2884 ErrorMsg("factory constructors are not allowed in interfaces");
2870 } else { 2885 } else {
2871 ErrorMsg("static methods are not allowed in interfaces"); 2886 ErrorMsg("static methods are not allowed in interfaces");
2872 } 2887 }
2873 } 2888 }
2874 // Constructor or method. 2889 // Constructor or method.
2875 if (member.type == NULL) { 2890 if (member.type == NULL) {
2876 member.type = &Type::ZoneHandle(Type::DynamicType()); 2891 member.type = &Type::ZoneHandle(Type::DynamicType());
(...skipping 6160 matching lines...) Expand 10 before | Expand all | Expand 10 after
9037 void Parser::SkipQualIdent() { 9052 void Parser::SkipQualIdent() {
9038 ASSERT(IsIdentifier()); 9053 ASSERT(IsIdentifier());
9039 ConsumeToken(); 9054 ConsumeToken();
9040 if (CurrentToken() == Token::kPERIOD) { 9055 if (CurrentToken() == Token::kPERIOD) {
9041 ConsumeToken(); // Consume the kPERIOD token. 9056 ConsumeToken(); // Consume the kPERIOD token.
9042 ExpectIdentifier("identifier expected after '.'"); 9057 ExpectIdentifier("identifier expected after '.'");
9043 } 9058 }
9044 } 9059 }
9045 9060
9046 } // namespace dart 9061 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | tests/co19/co19-runtime.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698