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

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

Issue 9414005: Fix issue 979: operator arity must be verified. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 10 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/parser.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 597 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 new LoadLocalNode(node_sequence->token_index(), *receiver)); 608 new LoadLocalNode(node_sequence->token_index(), *receiver));
609 } 609 }
610 } 610 }
611 611
612 parsed_function->set_default_parameter_values(default_parameter_values); 612 parsed_function->set_default_parameter_values(default_parameter_values);
613 isolate->set_ast_node_id(prev_ast_node_id); 613 isolate->set_ast_node_id(prev_ast_node_id);
614 } 614 }
615 615
616 616
617 SequenceNode* Parser::ParseStaticConstGetter(const Function& func) { 617 SequenceNode* Parser::ParseStaticConstGetter(const Function& func) {
618 TRACE_PARSER("ParseStaticConstGetter");
618 ParamList params; 619 ParamList params;
619 ASSERT(func.num_fixed_parameters() == 0); // static. 620 ASSERT(func.num_fixed_parameters() == 0); // static.
620 ASSERT(func.num_optional_parameters() == 0); 621 ASSERT(func.num_optional_parameters() == 0);
621 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); 622 ASSERT(AbstractType::Handle(func.result_type()).IsResolved());
622 623
623 // Build local scope for function and populate with the formal parameters. 624 // Build local scope for function and populate with the formal parameters.
624 OpenFunctionBlock(func); 625 OpenFunctionBlock(func);
625 AddFormalParamsToScope(&params, current_block_->scope); 626 AddFormalParamsToScope(&params, current_block_->scope);
626 627
627 // Static const fields must have an initializer. 628 // Static const fields must have an initializer.
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
1139 if (signature_class.NumTypeParameters() > 0) { 1140 if (signature_class.NumTypeParameters() > 0) {
1140 CaptureReceiver(); 1141 CaptureReceiver();
1141 } 1142 }
1142 } 1143 }
1143 } 1144 }
1144 return new ClosureNode(token_pos, implicit_closure_function, receiver, NULL); 1145 return new ClosureNode(token_pos, implicit_closure_function, receiver, NULL);
1145 } 1146 }
1146 1147
1147 1148
1148 AstNode* Parser::ParseSuperFieldAccess(const String& field_name) { 1149 AstNode* Parser::ParseSuperFieldAccess(const String& field_name) {
1150 TRACE_PARSER("ParseSuperFieldAccess");
1149 const intptr_t field_pos = token_index_; 1151 const intptr_t field_pos = token_index_;
1150 const Class& super_class = Class::Handle(current_class().SuperClass()); 1152 const Class& super_class = Class::Handle(current_class().SuperClass());
1151 if (super_class.IsNull()) { 1153 if (super_class.IsNull()) {
1152 ErrorMsg("class '%s' does not have a superclass", 1154 ErrorMsg("class '%s' does not have a superclass",
1153 String::Handle(current_class().Name()).ToCString()); 1155 String::Handle(current_class().Name()).ToCString());
1154 } 1156 }
1155 AstNode* implicit_argument = LoadReceiver(field_pos); 1157 AstNode* implicit_argument = LoadReceiver(field_pos);
1156 1158
1157 const String& getter_name = 1159 const String& getter_name =
1158 String::ZoneHandle(Field::GetterName(field_name)); 1160 String::ZoneHandle(Field::GetterName(field_name));
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1352 1354
1353 1355
1354 struct FieldInitExpression { 1356 struct FieldInitExpression {
1355 Field* inst_field; 1357 Field* inst_field;
1356 AstNode* expr; 1358 AstNode* expr;
1357 }; 1359 };
1358 1360
1359 1361
1360 void Parser::ParseInitializedInstanceFields(const Class& cls, 1362 void Parser::ParseInitializedInstanceFields(const Class& cls,
1361 GrowableArray<FieldInitExpression>* initializers) { 1363 GrowableArray<FieldInitExpression>* initializers) {
1364 TRACE_PARSER("ParseInitializedInstanceFields");
1362 const Array& fields = Array::Handle(cls.fields()); 1365 const Array& fields = Array::Handle(cls.fields());
1363 Field& f = Field::Handle(); 1366 Field& f = Field::Handle();
1364 const intptr_t saved_pos = token_index_; 1367 const intptr_t saved_pos = token_index_;
1365 for (int i = 0; i < fields.Length(); i++) { 1368 for (int i = 0; i < fields.Length(); i++) {
1366 f ^= fields.At(i); 1369 f ^= fields.At(i);
1367 if (!f.is_static() && f.has_initializer()) { 1370 if (!f.is_static() && f.has_initializer()) {
1368 Field& field = Field::ZoneHandle(); 1371 Field& field = Field::ZoneHandle();
1369 field ^= fields.At(i); 1372 field ^= fields.At(i);
1370 intptr_t field_pos = field.token_index(); 1373 intptr_t field_pos = field.token_index();
1371 SetPosition(field_pos); 1374 SetPosition(field_pos);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1419 // Generate implicit super() if we haven't seen an explicit super call 1422 // Generate implicit super() if we haven't seen an explicit super call
1420 // or constructor redirection. 1423 // or constructor redirection.
1421 GenerateSuperConstructorCall(cls, receiver); 1424 GenerateSuperConstructorCall(cls, receiver);
1422 } 1425 }
1423 CheckConstFieldsInitialized(cls); 1426 CheckConstFieldsInitialized(cls);
1424 } 1427 }
1425 1428
1426 1429
1427 void Parser::ParseConstructorRedirection(const Class& cls, 1430 void Parser::ParseConstructorRedirection(const Class& cls,
1428 LocalVariable* receiver) { 1431 LocalVariable* receiver) {
1432 TRACE_PARSER("ParseConstructorRedirection");
1429 ASSERT(CurrentToken() == Token::kTHIS); 1433 ASSERT(CurrentToken() == Token::kTHIS);
1430 const intptr_t call_pos = token_index_; 1434 const intptr_t call_pos = token_index_;
1431 ConsumeToken(); 1435 ConsumeToken();
1432 String& ctor_name = String::Handle(cls.Name()); 1436 String& ctor_name = String::Handle(cls.Name());
1433 String& ctor_suffix = String::Handle(String::NewSymbol(".")); 1437 String& ctor_suffix = String::Handle(String::NewSymbol("."));
1434 1438
1435 if (CurrentToken() == Token::kPERIOD) { 1439 if (CurrentToken() == Token::kPERIOD) {
1436 ConsumeToken(); 1440 ConsumeToken();
1437 ctor_suffix = String::Concat( 1441 ctor_suffix = String::Concat(
1438 ctor_suffix, *ExpectIdentifier("constructor name expected")); 1442 ctor_suffix, *ExpectIdentifier("constructor name expected"));
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1512 // Empty constructor body. 1516 // Empty constructor body.
1513 SequenceNode* statements = CloseBlock(); 1517 SequenceNode* statements = CloseBlock();
1514 return statements; 1518 return statements;
1515 } 1519 }
1516 1520
1517 1521
1518 // Parser is at the opening parenthesis of the formal parameter declaration 1522 // Parser is at the opening parenthesis of the formal parameter declaration
1519 // of function. Parse the formal parameters, initializers and code. 1523 // of function. Parse the formal parameters, initializers and code.
1520 SequenceNode* Parser::ParseConstructor(const Function& func, 1524 SequenceNode* Parser::ParseConstructor(const Function& func,
1521 Array& default_parameter_values) { 1525 Array& default_parameter_values) {
1526 TRACE_PARSER("ParseConstructor");
1522 ASSERT(func.IsConstructor()); 1527 ASSERT(func.IsConstructor());
1523 ASSERT(!func.IsFactory()); 1528 ASSERT(!func.IsFactory());
1524 ASSERT(!func.is_static()); 1529 ASSERT(!func.is_static());
1525 ASSERT(!func.IsLocalFunction()); 1530 ASSERT(!func.IsLocalFunction());
1526 const Class& cls = Class::Handle(func.owner()); 1531 const Class& cls = Class::Handle(func.owner());
1527 ASSERT(!cls.IsNull()); 1532 ASSERT(!cls.IsNull());
1528 1533
1529 if (CurrentToken() == Token::kCLASS) { 1534 if (CurrentToken() == Token::kCLASS) {
1530 // Special case: implicit constructor. 1535 // Special case: implicit constructor.
1531 // The parser adds an implicit default constructor when a class 1536 // The parser adds an implicit default constructor when a class
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
1763 SequenceNode* statements = CloseBlock(); 1768 SequenceNode* statements = CloseBlock();
1764 return statements; 1769 return statements;
1765 } 1770 }
1766 1771
1767 1772
1768 // Parser is at the opening parenthesis of the formal parameter 1773 // Parser is at the opening parenthesis of the formal parameter
1769 // declaration of the function or constructor. 1774 // declaration of the function or constructor.
1770 // Parse the formal parameters and code. 1775 // Parse the formal parameters and code.
1771 SequenceNode* Parser::ParseFunc(const Function& func, 1776 SequenceNode* Parser::ParseFunc(const Function& func,
1772 Array& default_parameter_values) { 1777 Array& default_parameter_values) {
1778 TRACE_PARSER("ParseFunc");
1773 if (func.IsConstructor()) { 1779 if (func.IsConstructor()) {
1774 return ParseConstructor(func, default_parameter_values); 1780 return ParseConstructor(func, default_parameter_values);
1775 } 1781 }
1776 1782
1777 ASSERT(!func.IsConstructor()); 1783 ASSERT(!func.IsConstructor());
1778 OpenFunctionBlock(func); // Build local scope for function. 1784 OpenFunctionBlock(func); // Build local scope for function.
1779 1785
1780 ParamList params; 1786 ParamList params;
1781 // Static functions do not have a receiver. 1787 // Static functions do not have a receiver.
1782 // An instance closure may capture and access the receiver, but via the 1788 // An instance closure may capture and access the receiver, but via the
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1893 ExpectToken(Token::kASSIGN); 1899 ExpectToken(Token::kASSIGN);
1894 SetAllowFunctionLiterals(false); 1900 SetAllowFunctionLiterals(false);
1895 SkipExpr(); 1901 SkipExpr();
1896 SetAllowFunctionLiterals(true); 1902 SetAllowFunctionLiterals(true);
1897 } 1903 }
1898 } while (CurrentToken() == Token::kCOMMA); 1904 } while (CurrentToken() == Token::kCOMMA);
1899 } 1905 }
1900 1906
1901 1907
1902 void Parser::ParseQualIdent(QualIdent* qual_ident) { 1908 void Parser::ParseQualIdent(QualIdent* qual_ident) {
1909 TRACE_PARSER("ParseQualIdent");
1903 ASSERT(IsIdentifier()); 1910 ASSERT(IsIdentifier());
1904 ASSERT(!current_class().IsNull()); 1911 ASSERT(!current_class().IsNull());
1905 qual_ident->ident_pos = token_index_; 1912 qual_ident->ident_pos = token_index_;
1906 qual_ident->ident = CurrentLiteral(); 1913 qual_ident->ident = CurrentLiteral();
1907 qual_ident->lib_prefix = NULL; 1914 qual_ident->lib_prefix = NULL;
1908 ConsumeToken(); 1915 ConsumeToken();
1909 if (CurrentToken() == Token::kPERIOD) { 1916 if (CurrentToken() == Token::kPERIOD) {
1910 // An identifier cannot be resolved in a local scope when top level parsing. 1917 // An identifier cannot be resolved in a local scope when top level parsing.
1911 if (is_top_level_ || 1918 if (is_top_level_ ||
1912 !ResolveIdentInLocalScope(qual_ident->ident_pos, 1919 !ResolveIdentInLocalScope(qual_ident->ident_pos,
(...skipping 15 matching lines...) Expand all
1928 qual_ident->ident = 1935 qual_ident->ident =
1929 ExpectIdentifier("identifier expected after '.'"); 1936 ExpectIdentifier("identifier expected after '.'");
1930 } 1937 }
1931 } 1938 }
1932 } 1939 }
1933 } 1940 }
1934 } 1941 }
1935 1942
1936 1943
1937 void Parser::ParseMethodOrConstructor(ClassDesc* members, MemberDesc* method) { 1944 void Parser::ParseMethodOrConstructor(ClassDesc* members, MemberDesc* method) {
1945 TRACE_PARSER("ParseMethodOrConstructor");
1938 ASSERT(CurrentToken() == Token::kLPAREN); 1946 ASSERT(CurrentToken() == Token::kLPAREN);
1939 intptr_t method_pos = this->token_index_; 1947 intptr_t method_pos = this->token_index_;
1940 ASSERT(method->type != NULL); 1948 ASSERT(method->type != NULL);
1941 ASSERT(method->name_pos > 0); 1949 ASSERT(method->name_pos > 0);
1942 ASSERT(current_member_ == method); 1950 ASSERT(current_member_ == method);
1943 1951
1944 if (method->has_var) { 1952 if (method->has_var) {
1945 ErrorMsg(method->name_pos, "keyword var not allowed for methods"); 1953 ErrorMsg(method->name_pos, "keyword var not allowed for methods");
1946 } 1954 }
1947 if (method->has_final) { 1955 if (method->has_final) {
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
2138 func.set_end_token_index(method_end_pos); 2146 func.set_end_token_index(method_end_pos);
2139 2147
2140 // No need to resolve parameter types yet, or add parameters to local scope. 2148 // No need to resolve parameter types yet, or add parameters to local scope.
2141 ASSERT(is_top_level_); 2149 ASSERT(is_top_level_);
2142 AddFormalParamsToFunction(&method->params, func); 2150 AddFormalParamsToFunction(&method->params, func);
2143 members->AddFunction(&func); 2151 members->AddFunction(&func);
2144 } 2152 }
2145 2153
2146 2154
2147 void Parser::ParseFieldDefinition(ClassDesc* members, MemberDesc* field) { 2155 void Parser::ParseFieldDefinition(ClassDesc* members, MemberDesc* field) {
2156 TRACE_PARSER("ParseFieldDefinition");
2148 // The parser has read the first field name and is now at the token 2157 // The parser has read the first field name and is now at the token
2149 // after the field name. 2158 // after the field name.
2150 ASSERT(CurrentToken() == Token::kSEMICOLON || 2159 ASSERT(CurrentToken() == Token::kSEMICOLON ||
2151 CurrentToken() == Token::kCOMMA || 2160 CurrentToken() == Token::kCOMMA ||
2152 CurrentToken() == Token::kASSIGN); 2161 CurrentToken() == Token::kASSIGN);
2153 ASSERT(field->type != NULL); 2162 ASSERT(field->type != NULL);
2154 ASSERT(field->name_pos > 0); 2163 ASSERT(field->name_pos > 0);
2155 ASSERT(current_member_ == field); 2164 ASSERT(current_member_ == field);
2156 2165
2157 if (field->has_const) { 2166 if (field->has_const) {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
2243 break; 2252 break;
2244 } 2253 }
2245 ConsumeToken(); 2254 ConsumeToken();
2246 field->name_pos = this->token_index_; 2255 field->name_pos = this->token_index_;
2247 field->name = ExpectIdentifier("field name expected"); 2256 field->name = ExpectIdentifier("field name expected");
2248 } 2257 }
2249 ExpectSemicolon(); 2258 ExpectSemicolon();
2250 } 2259 }
2251 2260
2252 2261
2262 void Parser::CheckOperatorArity(
2263 const MemberDesc& member, Token::Kind operator_token) {
2264 intptr_t expected_num_parameters; // Includes receiver.
2265 if (operator_token == Token::kASSIGN_INDEX) {
2266 expected_num_parameters = 3;
2267 } else if ((operator_token == Token::kNEGATE) ||
2268 (operator_token == Token::kBIT_NOT)) {
2269 expected_num_parameters = 1;
2270 } else {
2271 expected_num_parameters = 2;
2272 }
2273 if ((member.params.num_optional_parameters > 0) ||
2274 (member.params.has_named_optional_parameters) ||
2275 (member.params.num_fixed_parameters != expected_num_parameters)) {
2276 // Subtract receiver when reporting number of expected arguments.
2277 ErrorMsg(member.name_pos, "operator %s expects %d argument(s)",
2278 member.name->ToCString(), (expected_num_parameters - 1));
2279 }
2280 }
2281
2282
2253 void Parser::ParseClassMemberDefinition(ClassDesc* members) { 2283 void Parser::ParseClassMemberDefinition(ClassDesc* members) {
2284 TRACE_PARSER("ParseClassMemberDefinition");
2254 MemberDesc member; 2285 MemberDesc member;
2255 current_member_ = &member; 2286 current_member_ = &member;
2256 if ((CurrentToken() == Token::kABSTRACT) && 2287 if ((CurrentToken() == Token::kABSTRACT) &&
2257 (LookaheadToken(1) != Token::kLPAREN)) { 2288 (LookaheadToken(1) != Token::kLPAREN)) {
2258 ConsumeToken(); 2289 ConsumeToken();
2259 member.has_abstract = true; 2290 member.has_abstract = true;
2260 } 2291 }
2261 if ((CurrentToken() == Token::kSTATIC) && 2292 if ((CurrentToken() == Token::kSTATIC) &&
2262 (LookaheadToken(1) != Token::kLPAREN)) { 2293 (LookaheadToken(1) != Token::kLPAREN)) {
2263 ConsumeToken(); 2294 ConsumeToken();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2311 ((follower == Token::kPERIOD) && // Qualified class name of type, 2342 ((follower == Token::kPERIOD) && // Qualified class name of type,
2312 (LookaheadToken(3) != Token::kLPAREN))) { // but not a named constr. 2343 (LookaheadToken(3) != Token::kLPAREN))) { // but not a named constr.
2313 ASSERT(is_top_level_); 2344 ASSERT(is_top_level_);
2314 // The declared type of fields is never ignored, even in unchecked mode, 2345 // The declared type of fields is never ignored, even in unchecked mode,
2315 // because getters and setters could be closurized at some time (not 2346 // because getters and setters could be closurized at some time (not
2316 // supported yet). 2347 // supported yet).
2317 member.type = &AbstractType::ZoneHandle(ParseType(kCanResolve)); 2348 member.type = &AbstractType::ZoneHandle(ParseType(kCanResolve));
2318 } 2349 }
2319 } 2350 }
2320 } 2351 }
2352 Token::Kind operator_token = Token::kILLEGAL;
2321 // Optionally parse a (possibly named) constructor name or factory. 2353 // Optionally parse a (possibly named) constructor name or factory.
2322 if (IsIdentifier() && 2354 if (IsIdentifier() &&
2323 (CurrentLiteral()->Equals(members->class_name()) || member.has_factory)) { 2355 (CurrentLiteral()->Equals(members->class_name()) || member.has_factory)) {
2324 if (member.has_factory) { 2356 if (member.has_factory) {
2325 // The factory name may be qualified. 2357 // The factory name may be qualified.
2326 QualIdent factory_name; 2358 QualIdent factory_name;
2327 ParseQualIdent(&factory_name); 2359 ParseQualIdent(&factory_name);
2328 member.name_pos = factory_name.ident_pos; 2360 member.name_pos = factory_name.ident_pos;
2329 member.name = factory_name.ident; // Unqualified identifier. 2361 member.name = factory_name.ident; // Unqualified identifier.
2330 // The class of the factory result type is specified by the factory name. 2362 // The class of the factory result type is specified by the factory name.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2401 (LookaheadToken(1) != Token::kASSIGN) && 2433 (LookaheadToken(1) != Token::kASSIGN) &&
2402 (LookaheadToken(1) != Token::kCOMMA) && 2434 (LookaheadToken(1) != Token::kCOMMA) &&
2403 (LookaheadToken(1) != Token::kSEMICOLON)) { 2435 (LookaheadToken(1) != Token::kSEMICOLON)) {
2404 ConsumeToken(); 2436 ConsumeToken();
2405 if (!Token::CanBeOverloaded(CurrentToken())) { 2437 if (!Token::CanBeOverloaded(CurrentToken())) {
2406 ErrorMsg("invalid operator overloading"); 2438 ErrorMsg("invalid operator overloading");
2407 } 2439 }
2408 if (member.has_static) { 2440 if (member.has_static) {
2409 ErrorMsg("operator overloading functions cannot be static"); 2441 ErrorMsg("operator overloading functions cannot be static");
2410 } 2442 }
2443 operator_token = CurrentToken();
2411 member.kind = RawFunction::kFunction; 2444 member.kind = RawFunction::kFunction;
2412 member.name_pos = this->token_index_; 2445 member.name_pos = this->token_index_;
2413 member.name = 2446 member.name =
2414 &String::ZoneHandle(String::NewSymbol(Token::Str(CurrentToken()))); 2447 &String::ZoneHandle(String::NewSymbol(Token::Str(operator_token)));
2415 ConsumeToken(); 2448 ConsumeToken();
2416 } else if (IsIdentifier()) { 2449 } else if (IsIdentifier()) {
2417 member.name = CurrentLiteral(); 2450 member.name = CurrentLiteral();
2418 member.name_pos = token_index_; 2451 member.name_pos = token_index_;
2419 ConsumeToken(); 2452 ConsumeToken();
2420 } else { 2453 } else {
2421 ErrorMsg("identifier expected"); 2454 ErrorMsg("identifier expected");
2422 } 2455 }
2423 2456
2424 ASSERT(member.name != NULL); 2457 ASSERT(member.name != NULL);
2425 if (CurrentToken() == Token::kLPAREN) { 2458 if (CurrentToken() == Token::kLPAREN) {
2426 if (members->is_interface() && member.has_static) { 2459 if (members->is_interface() && member.has_static) {
2427 if (member.has_factory) { 2460 if (member.has_factory) {
2428 ErrorMsg("factory constructors are not allowed in interfaces"); 2461 ErrorMsg("factory constructors are not allowed in interfaces");
2429 } else { 2462 } else {
2430 ErrorMsg("static methods are not allowed in interfaces"); 2463 ErrorMsg("static methods are not allowed in interfaces");
2431 } 2464 }
2432 } 2465 }
2433 // Constructor or method. 2466 // Constructor or method.
2434 if (member.type == NULL) { 2467 if (member.type == NULL) {
2435 member.type = &Type::ZoneHandle(Type::DynamicType()); 2468 member.type = &Type::ZoneHandle(Type::DynamicType());
2436 } 2469 }
2437 ParseMethodOrConstructor(members, &member); 2470 ParseMethodOrConstructor(members, &member);
2471 if (operator_token != Token::kILLEGAL) {
2472 CheckOperatorArity(member, operator_token);
2473 }
2438 } else if (CurrentToken() == Token::kSEMICOLON || 2474 } else if (CurrentToken() == Token::kSEMICOLON ||
2439 CurrentToken() == Token::kCOMMA || 2475 CurrentToken() == Token::kCOMMA ||
2440 CurrentToken() == Token::kASSIGN) { 2476 CurrentToken() == Token::kASSIGN) {
2441 // Field definition. 2477 // Field definition.
2442 if (member.type == NULL) { 2478 if (member.type == NULL) {
2443 if (member.has_final) { 2479 if (member.has_final) {
2444 member.type = &Type::ZoneHandle(Type::DynamicType()); 2480 member.type = &Type::ZoneHandle(Type::DynamicType());
2445 } else { 2481 } else {
2446 ErrorMsg("missing 'var', 'final' or type in field declaration"); 2482 ErrorMsg("missing 'var', 'final' or type in field declaration");
2447 } 2483 }
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
2859 if (CurrentToken() == Token::kPERIOD) { 2895 if (CurrentToken() == Token::kPERIOD) {
2860 ConsumeToken(); 2896 ConsumeToken();
2861 ExpectIdentifier("name expected"); 2897 ExpectIdentifier("name expected");
2862 } 2898 }
2863 SkipTypeArguments(); 2899 SkipTypeArguments();
2864 } 2900 }
2865 } 2901 }
2866 2902
2867 2903
2868 void Parser::ParseTypeParameters(const Class& cls) { 2904 void Parser::ParseTypeParameters(const Class& cls) {
2905 TRACE_PARSER("ParseTypeParameters");
2869 if (CurrentToken() == Token::kLT) { 2906 if (CurrentToken() == Token::kLT) {
2870 GrowableArray<AbstractType*> type_parameters_array; 2907 GrowableArray<AbstractType*> type_parameters_array;
2871 GrowableArray<AbstractType*> bounds_array; 2908 GrowableArray<AbstractType*> bounds_array;
2872 intptr_t index = 0; 2909 intptr_t index = 0;
2873 do { 2910 do {
2874 ConsumeToken(); 2911 ConsumeToken();
2875 if (CurrentToken() != Token::kIDENT) { 2912 if (CurrentToken() != Token::kIDENT) {
2876 ErrorMsg("type parameter name expected"); 2913 ErrorMsg("type parameter name expected");
2877 } 2914 }
2878 String& type_parameter_name = *CurrentLiteral(); 2915 String& type_parameter_name = *CurrentLiteral();
(...skipping 29 matching lines...) Expand all
2908 bound = bounds.TypeAt(i); 2945 bound = bounds.TypeAt(i);
2909 ResolveTypeFromClass(cls, kCanResolve, &bound); 2946 ResolveTypeFromClass(cls, kCanResolve, &bound);
2910 bounds.SetTypeAt(i, bound); 2947 bounds.SetTypeAt(i, bound);
2911 } 2948 }
2912 } 2949 }
2913 } 2950 }
2914 2951
2915 2952
2916 RawAbstractTypeArguments* Parser::ParseTypeArguments( 2953 RawAbstractTypeArguments* Parser::ParseTypeArguments(
2917 TypeResolution type_resolution) { 2954 TypeResolution type_resolution) {
2955 TRACE_PARSER("ParseTypeArguments");
2918 if (CurrentToken() == Token::kLT) { 2956 if (CurrentToken() == Token::kLT) {
2919 GrowableArray<AbstractType*> types; 2957 GrowableArray<AbstractType*> types;
2920 do { 2958 do {
2921 ConsumeToken(); 2959 ConsumeToken();
2922 AbstractType& type = AbstractType::ZoneHandle(ParseType(type_resolution)); 2960 AbstractType& type = AbstractType::ZoneHandle(ParseType(type_resolution));
2923 types.Add(&type); 2961 types.Add(&type);
2924 } while (CurrentToken() == Token::kCOMMA); 2962 } while (CurrentToken() == Token::kCOMMA);
2925 Token::Kind token = CurrentToken(); 2963 Token::Kind token = CurrentToken();
2926 if ((token == Token::kGT) || (token == Token::kSHR)) { 2964 if ((token == Token::kGT) || (token == Token::kSHR)) {
2927 ConsumeRightAngleBracket(); 2965 ConsumeRightAngleBracket();
2928 } else { 2966 } else {
2929 ErrorMsg("right angle bracket expected"); 2967 ErrorMsg("right angle bracket expected");
2930 } 2968 }
2931 if (type_resolution != kIgnore) { 2969 if (type_resolution != kIgnore) {
2932 return NewTypeArguments(types); 2970 return NewTypeArguments(types);
2933 } 2971 }
2934 } 2972 }
2935 return TypeArguments::null(); 2973 return TypeArguments::null();
2936 } 2974 }
2937 2975
2938 2976
2939 // Parse and return an array of interface types. 2977 // Parse and return an array of interface types.
2940 RawArray* Parser::ParseInterfaceList() { 2978 RawArray* Parser::ParseInterfaceList() {
2979 TRACE_PARSER("ParseInterfaceList");
2941 ASSERT((CurrentToken() == Token::kIMPLEMENTS) || 2980 ASSERT((CurrentToken() == Token::kIMPLEMENTS) ||
2942 (CurrentToken() == Token::kEXTENDS)); 2981 (CurrentToken() == Token::kEXTENDS));
2943 GrowableArray<AbstractType*> interfaces; 2982 GrowableArray<AbstractType*> interfaces;
2944 String& interface_name = String::Handle(); 2983 String& interface_name = String::Handle();
2945 do { 2984 do {
2946 ConsumeToken(); 2985 ConsumeToken();
2947 intptr_t supertype_pos = token_index_; 2986 intptr_t supertype_pos = token_index_;
2948 AbstractType& interface = AbstractType::ZoneHandle(ParseType(kCanResolve)); 2987 AbstractType& interface = AbstractType::ZoneHandle(ParseType(kCanResolve));
2949 interface_name = interface.Name(); 2988 interface_name = interface.Name();
2950 for (int i = 0; i < interfaces.length(); i++) { 2989 for (int i = 0; i < interfaces.length(); i++) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2998 String::Handle(interface.Name()).ToCString(), 3037 String::Handle(interface.Name()).ToCString(),
2999 String::Handle(conflicting.Name()).ToCString()); 3038 String::Handle(conflicting.Name()).ToCString());
3000 } 3039 }
3001 } 3040 }
3002 cls_interfaces = NewArray<AbstractType>(all_interfaces); 3041 cls_interfaces = NewArray<AbstractType>(all_interfaces);
3003 cls.set_interfaces(cls_interfaces); 3042 cls.set_interfaces(cls_interfaces);
3004 } 3043 }
3005 3044
3006 3045
3007 void Parser::ParseTopLevelVariable(TopLevel* top_level) { 3046 void Parser::ParseTopLevelVariable(TopLevel* top_level) {
3047 TRACE_PARSER("ParseTopLevelVariable");
3008 const bool is_final = (CurrentToken() == Token::kFINAL); 3048 const bool is_final = (CurrentToken() == Token::kFINAL);
3009 const bool is_static = true; 3049 const bool is_static = true;
3010 const AbstractType& type = AbstractType::ZoneHandle(ParseFinalVarOrType( 3050 const AbstractType& type = AbstractType::ZoneHandle(ParseFinalVarOrType(
3011 FLAG_enable_type_checks ? kCanResolve : kIgnore)); 3051 FLAG_enable_type_checks ? kCanResolve : kIgnore));
3012 3052
3013 while (true) { 3053 while (true) {
3014 const intptr_t name_pos = token_index_; 3054 const intptr_t name_pos = token_index_;
3015 String& var_name = *ExpectIdentifier("variable name expected"); 3055 String& var_name = *ExpectIdentifier("variable name expected");
3016 3056
3017 if (library_.LookupObject(var_name) != Object::null()) { 3057 if (library_.LookupObject(var_name) != Object::null()) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
3055 ConsumeToken(); 3095 ConsumeToken();
3056 break; 3096 break;
3057 } else { 3097 } else {
3058 ExpectSemicolon(); // Reports error. 3098 ExpectSemicolon(); // Reports error.
3059 } 3099 }
3060 } 3100 }
3061 } 3101 }
3062 3102
3063 3103
3064 void Parser::ParseTopLevelFunction(TopLevel* top_level) { 3104 void Parser::ParseTopLevelFunction(TopLevel* top_level) {
3105 TRACE_PARSER("ParseTopLevelFunction");
3065 AbstractType& result_type = Type::Handle(Type::DynamicType()); 3106 AbstractType& result_type = Type::Handle(Type::DynamicType());
3066 const bool is_static = true; 3107 const bool is_static = true;
3067 if (CurrentToken() == Token::kVOID) { 3108 if (CurrentToken() == Token::kVOID) {
3068 ConsumeToken(); 3109 ConsumeToken();
3069 result_type = Type::VoidType(); 3110 result_type = Type::VoidType();
3070 } else { 3111 } else {
3071 // Parse optional type. 3112 // Parse optional type.
3072 if ((CurrentToken() == Token::kIDENT) && 3113 if ((CurrentToken() == Token::kIDENT) &&
3073 (LookaheadToken(1) != Token::kLPAREN)) { 3114 (LookaheadToken(1) != Token::kLPAREN)) {
3074 result_type = ParseType(kCanResolve); 3115 result_type = ParseType(kCanResolve);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
3118 is_static, false, function_pos)); 3159 is_static, false, function_pos));
3119 func.set_result_type(result_type); 3160 func.set_result_type(result_type);
3120 func.set_end_token_index(function_end_pos); 3161 func.set_end_token_index(function_end_pos);
3121 AddFormalParamsToFunction(&params, func); 3162 AddFormalParamsToFunction(&params, func);
3122 top_level->functions.Add(&func); 3163 top_level->functions.Add(&func);
3123 library_.AddObject(func, func_name); 3164 library_.AddObject(func, func_name);
3124 } 3165 }
3125 3166
3126 3167
3127 void Parser::ParseTopLevelAccessor(TopLevel* top_level) { 3168 void Parser::ParseTopLevelAccessor(TopLevel* top_level) {
3169 TRACE_PARSER("ParseTopLevelAccessor");
3128 const bool is_static = true; 3170 const bool is_static = true;
3129 AbstractType& result_type = AbstractType::Handle(); 3171 AbstractType& result_type = AbstractType::Handle();
3130 bool is_getter = (CurrentToken() == Token::kGET); 3172 bool is_getter = (CurrentToken() == Token::kGET);
3131 if (CurrentToken() == Token::kGET || 3173 if (CurrentToken() == Token::kGET ||
3132 CurrentToken() == Token::kSET) { 3174 CurrentToken() == Token::kSET) {
3133 ConsumeToken(); 3175 ConsumeToken();
3134 result_type = Type::DynamicType(); 3176 result_type = Type::DynamicType();
3135 } else { 3177 } else {
3136 if (CurrentToken() == Token::kVOID) { 3178 if (CurrentToken() == Token::kVOID) {
3137 ConsumeToken(); 3179 ConsumeToken();
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
3198 RawFunction::kSetterFunction, 3240 RawFunction::kSetterFunction,
3199 is_static, false, accessor_pos)); 3241 is_static, false, accessor_pos));
3200 func.set_result_type(result_type); 3242 func.set_result_type(result_type);
3201 AddFormalParamsToFunction(&params, func); 3243 AddFormalParamsToFunction(&params, func);
3202 top_level->functions.Add(&func); 3244 top_level->functions.Add(&func);
3203 library_.AddObject(func, accessor_name); 3245 library_.AddObject(func, accessor_name);
3204 } 3246 }
3205 3247
3206 3248
3207 void Parser::ParseLibraryName() { 3249 void Parser::ParseLibraryName() {
3250 TRACE_PARSER("ParseLibraryName");
3208 if ((script_.kind() == RawScript::kLibrary) && 3251 if ((script_.kind() == RawScript::kLibrary) &&
3209 (CurrentToken() != Token::kLIBRARY)) { 3252 (CurrentToken() != Token::kLIBRARY)) {
3210 // Handle error case early to get consistent error message. 3253 // Handle error case early to get consistent error message.
3211 ExpectToken(Token::kLIBRARY); 3254 ExpectToken(Token::kLIBRARY);
3212 } 3255 }
3213 if (CurrentToken() == Token::kLIBRARY) { 3256 if (CurrentToken() == Token::kLIBRARY) {
3214 ConsumeToken(); 3257 ConsumeToken();
3215 ExpectToken(Token::kLPAREN); 3258 ExpectToken(Token::kLPAREN);
3216 if (CurrentToken() != Token::kSTRING) { 3259 if (CurrentToken() != Token::kSTRING) {
3217 ErrorMsg("library name expected"); 3260 ErrorMsg("library name expected");
(...skipping 20 matching lines...) Expand all
3238 Api::NewLocalHandle(url), 3281 Api::NewLocalHandle(url),
3239 Api::NewLocalHandle(import_map)); 3282 Api::NewLocalHandle(import_map));
3240 if (Dart_IsError(result)) { 3283 if (Dart_IsError(result)) {
3241 ErrorMsg(token_pos, "library handler failed: %s", Dart_GetError(result)); 3284 ErrorMsg(token_pos, "library handler failed: %s", Dart_GetError(result));
3242 } 3285 }
3243 return result; 3286 return result;
3244 } 3287 }
3245 3288
3246 3289
3247 void Parser::ParseLibraryImport() { 3290 void Parser::ParseLibraryImport() {
3291 TRACE_PARSER("ParseLibraryImport");
3248 while (CurrentToken() == Token::kIMPORT) { 3292 while (CurrentToken() == Token::kIMPORT) {
3249 const intptr_t import_pos = token_index_; 3293 const intptr_t import_pos = token_index_;
3250 ConsumeToken(); 3294 ConsumeToken();
3251 ExpectToken(Token::kLPAREN); 3295 ExpectToken(Token::kLPAREN);
3252 if (CurrentToken() != Token::kSTRING) { 3296 if (CurrentToken() != Token::kSTRING) {
3253 ErrorMsg("library url expected"); 3297 ErrorMsg("library url expected");
3254 } 3298 }
3255 const String& url = *ParseImportStringLiteral(); 3299 const String& url = *ParseImportStringLiteral();
3256 String& prefix = String::Handle(); 3300 String& prefix = String::Handle();
3257 if (CurrentToken() == Token::kCOMMA) { 3301 if (CurrentToken() == Token::kCOMMA) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
3303 } else { 3347 } else {
3304 library_prefix = LibraryPrefix::New(prefix, library); 3348 library_prefix = LibraryPrefix::New(prefix, library);
3305 library_.AddObject(library_prefix, prefix); 3349 library_.AddObject(library_prefix, prefix);
3306 } 3350 }
3307 } 3351 }
3308 } 3352 }
3309 } 3353 }
3310 3354
3311 3355
3312 void Parser::ParseLibraryInclude() { 3356 void Parser::ParseLibraryInclude() {
3357 TRACE_PARSER("ParseLibraryInclude");
3313 const Array& import_map = Array::Handle(library_.import_map()); 3358 const Array& import_map = Array::Handle(library_.import_map());
3314 while (CurrentToken() == Token::kSOURCE) { 3359 while (CurrentToken() == Token::kSOURCE) {
3315 const intptr_t source_pos = token_index_; 3360 const intptr_t source_pos = token_index_;
3316 ConsumeToken(); 3361 ConsumeToken();
3317 ExpectToken(Token::kLPAREN); 3362 ExpectToken(Token::kLPAREN);
3318 if (CurrentToken() != Token::kSTRING) { 3363 if (CurrentToken() != Token::kSTRING) {
3319 ErrorMsg("source url expected"); 3364 ErrorMsg("source url expected");
3320 } 3365 }
3321 const String& url = *ParseImportStringLiteral(); 3366 const String& url = *ParseImportStringLiteral();
3322 ExpectToken(Token::kRPAREN); 3367 ExpectToken(Token::kRPAREN);
3323 ExpectToken(Token::kSEMICOLON); 3368 ExpectToken(Token::kSEMICOLON);
3324 Dart_Handle handle = CallLibraryTagHandler(kCanonicalizeUrl, 3369 Dart_Handle handle = CallLibraryTagHandler(kCanonicalizeUrl,
3325 source_pos, 3370 source_pos,
3326 url, 3371 url,
3327 import_map); 3372 import_map);
3328 const String& canon_url = String::CheckedHandle(Api::UnwrapHandle(handle)); 3373 const String& canon_url = String::CheckedHandle(Api::UnwrapHandle(handle));
3329 CallLibraryTagHandler(kSourceTag, source_pos, canon_url, import_map); 3374 CallLibraryTagHandler(kSourceTag, source_pos, canon_url, import_map);
3330 } 3375 }
3331 } 3376 }
3332 3377
3333 3378
3334 void Parser::ParseLibraryDefinition() { 3379 void Parser::ParseLibraryDefinition() {
3380 TRACE_PARSER("ParseLibraryDefinition");
3335 // Handle the script tag. 3381 // Handle the script tag.
3336 if (CurrentToken() == Token::kSCRIPTTAG) { 3382 if (CurrentToken() == Token::kSCRIPTTAG) {
3337 // Nothing to do for script tags except to skip them. 3383 // Nothing to do for script tags except to skip them.
3338 ConsumeToken(); 3384 ConsumeToken();
3339 } 3385 }
3340 3386
3341 ParseLibraryName(); 3387 ParseLibraryName();
3342 ParseLibraryImport(); 3388 ParseLibraryImport();
3343 ParseLibraryInclude(); 3389 ParseLibraryInclude();
3344 } 3390 }
3345 3391
3346 3392
3347 void Parser::ParseTopLevel() { 3393 void Parser::ParseTopLevel() {
3394 TRACE_PARSER("ParseTopLevel");
3348 // Collect the classes found at the top level in this growable array. 3395 // Collect the classes found at the top level in this growable array.
3349 // They need to be registered with class finalization after parsing 3396 // They need to be registered with class finalization after parsing
3350 // has been completed. 3397 // has been completed.
3351 GrowableArray<const Class*> classes; 3398 GrowableArray<const Class*> classes;
3352 SetPosition(0); 3399 SetPosition(0);
3353 is_top_level_ = true; 3400 is_top_level_ = true;
3354 TopLevel top_level; 3401 TopLevel top_level;
3355 Class& toplevel_class = Class::ZoneHandle( 3402 Class& toplevel_class = Class::ZoneHandle(
3356 Class::New(String::ZoneHandle(String::NewSymbol("::")), 3403 Class::New(String::ZoneHandle(String::NewSymbol("::")),
3357 script_, 3404 script_,
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
3519 if (param_desc.is_final) { 3566 if (param_desc.is_final) {
3520 parameter->set_is_final(); 3567 parameter->set_is_final();
3521 } 3568 }
3522 } 3569 }
3523 } 3570 }
3524 3571
3525 3572
3526 // Builds ReturnNode/NativeBodyNode for a native function. 3573 // Builds ReturnNode/NativeBodyNode for a native function.
3527 void Parser::ParseNativeFunctionBlock(const ParamList* params, 3574 void Parser::ParseNativeFunctionBlock(const ParamList* params,
3528 const Function& func) { 3575 const Function& func) {
3576 TRACE_PARSER("ParseNativeFunctionBlock");
3529 const Class& cls = Class::Handle(func.owner()); 3577 const Class& cls = Class::Handle(func.owner());
3530 const int num_parameters = params->parameters->length(); 3578 const int num_parameters = params->parameters->length();
3531 3579
3532 // Parse the function name out. 3580 // Parse the function name out.
3533 const intptr_t native_pos = token_index_; 3581 const intptr_t native_pos = token_index_;
3534 const String& native_name = ParseNativeDeclaration(); 3582 const String& native_name = ParseNativeDeclaration();
3535 3583
3536 // Now resolve the native function to the corresponding native entrypoint. 3584 // Now resolve the native function to the corresponding native entrypoint.
3537 NativeFunction native_function = NativeEntry::ResolveNative(cls, 3585 NativeFunction native_function = NativeEntry::ResolveNative(cls,
3538 native_name, 3586 native_name,
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
3635 variable->set_is_final(); 3683 variable->set_is_final();
3636 } 3684 }
3637 return initialization; 3685 return initialization;
3638 } 3686 }
3639 3687
3640 3688
3641 // Parses ('var' | 'final' [type] | type). 3689 // Parses ('var' | 'final' [type] | type).
3642 // The presence of 'final' must be detected and remembered before the call. 3690 // The presence of 'final' must be detected and remembered before the call.
3643 // If a type is parsed, it is resolved (or not) according to type_resolution. 3691 // If a type is parsed, it is resolved (or not) according to type_resolution.
3644 RawAbstractType* Parser::ParseFinalVarOrType(TypeResolution type_resolution) { 3692 RawAbstractType* Parser::ParseFinalVarOrType(TypeResolution type_resolution) {
3693 TRACE_PARSER("ParseFinalVarOrType");
3645 if (CurrentToken() == Token::kVAR) { 3694 if (CurrentToken() == Token::kVAR) {
3646 ConsumeToken(); 3695 ConsumeToken();
3647 return Type::DynamicType(); 3696 return Type::DynamicType();
3648 } 3697 }
3649 bool type_is_optional = false; 3698 bool type_is_optional = false;
3650 if (CurrentToken() == Token::kFINAL) { 3699 if (CurrentToken() == Token::kFINAL) {
3651 ConsumeToken(); 3700 ConsumeToken();
3652 type_is_optional = true; 3701 type_is_optional = true;
3653 } 3702 }
3654 if (CurrentToken() != Token::kIDENT) { 3703 if (CurrentToken() != Token::kIDENT) {
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after
4345 ExpectToken(Token::kLPAREN); 4394 ExpectToken(Token::kLPAREN);
4346 AstNode* cond_expr = ParseExpr(kAllowConst); 4395 AstNode* cond_expr = ParseExpr(kAllowConst);
4347 ExpectToken(Token::kRPAREN); 4396 ExpectToken(Token::kRPAREN);
4348 ExpectSemicolon(); 4397 ExpectSemicolon();
4349 return new DoWhileNode(do_pos, label, cond_expr, dowhile_body); 4398 return new DoWhileNode(do_pos, label, cond_expr, dowhile_body);
4350 } 4399 }
4351 4400
4352 4401
4353 AstNode* Parser::ParseForInStatement(intptr_t forin_pos, 4402 AstNode* Parser::ParseForInStatement(intptr_t forin_pos,
4354 SourceLabel* label) { 4403 SourceLabel* label) {
4404 TRACE_PARSER("ParseForInStatement");
4355 bool is_final = (CurrentToken() == Token::kFINAL); 4405 bool is_final = (CurrentToken() == Token::kFINAL);
4356 const String* loop_var_name = NULL; 4406 const String* loop_var_name = NULL;
4357 LocalVariable* loop_var = NULL; 4407 LocalVariable* loop_var = NULL;
4358 intptr_t loop_var_pos = 0; 4408 intptr_t loop_var_pos = 0;
4359 if (LookaheadToken(1) == Token::kIN) { 4409 if (LookaheadToken(1) == Token::kIN) {
4360 loop_var_pos = token_index_; 4410 loop_var_pos = token_index_;
4361 loop_var_name = ExpectIdentifier("variable name expected"); 4411 loop_var_name = ExpectIdentifier("variable name expected");
4362 } else { 4412 } else {
4363 // The case without a type is handled above, so require a type here. 4413 // The case without a type is handled above, so require a type here.
4364 const AbstractType& type = AbstractType::ZoneHandle(ParseFinalVarOrType( 4414 const AbstractType& type = AbstractType::ZoneHandle(ParseFinalVarOrType(
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
4568 ArgumentListNode* arguments = new ArgumentListNode(begin); 4618 ArgumentListNode* arguments = new ArgumentListNode(begin);
4569 arguments->Add(new LiteralNode(begin, 4619 arguments->Add(new LiteralNode(begin,
4570 Integer::ZoneHandle(Integer::New(begin)))); 4620 Integer::ZoneHandle(Integer::New(begin))));
4571 arguments->Add(new LiteralNode(end, 4621 arguments->Add(new LiteralNode(end,
4572 Integer::ZoneHandle(Integer::New(end)))); 4622 Integer::ZoneHandle(Integer::New(end))));
4573 return MakeStaticCall(kAssertionErrorName, kThrowNewName, arguments); 4623 return MakeStaticCall(kAssertionErrorName, kThrowNewName, arguments);
4574 } 4624 }
4575 4625
4576 4626
4577 AstNode* Parser::ParseAssertStatement() { 4627 AstNode* Parser::ParseAssertStatement() {
4628 TRACE_PARSER("ParseAssertStatement");
4578 ConsumeToken(); // Consume assert keyword. 4629 ConsumeToken(); // Consume assert keyword.
4579 ExpectToken(Token::kLPAREN); 4630 ExpectToken(Token::kLPAREN);
4580 const intptr_t condition_pos = token_index_; 4631 const intptr_t condition_pos = token_index_;
4581 if (!FLAG_enable_asserts && !FLAG_enable_type_checks) { 4632 if (!FLAG_enable_asserts && !FLAG_enable_type_checks) {
4582 SkipExpr(); 4633 SkipExpr();
4583 ExpectToken(Token::kRPAREN); 4634 ExpectToken(Token::kRPAREN);
4584 return NULL; 4635 return NULL;
4585 } 4636 }
4586 AstNode* condition = ParseExpr(kAllowConst); 4637 AstNode* condition = ParseExpr(kAllowConst);
4587 const intptr_t condition_end = token_index_; 4638 const intptr_t condition_end = token_index_;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
4650 if (!added_to_scope) { 4701 if (!added_to_scope) {
4651 ErrorMsg(stack_trace_param.token_index, 4702 ErrorMsg(stack_trace_param.token_index,
4652 "name '%s' already exists in scope", 4703 "name '%s' already exists in scope",
4653 stack_trace_param.var->ToCString()); 4704 stack_trace_param.var->ToCString());
4654 } 4705 }
4655 } 4706 }
4656 } 4707 }
4657 4708
4658 4709
4659 SequenceNode* Parser::ParseFinallyBlock() { 4710 SequenceNode* Parser::ParseFinallyBlock() {
4711 TRACE_PARSER("ParseFinallyBlock");
4660 OpenBlock(); 4712 OpenBlock();
4661 ExpectToken(Token::kLBRACE); 4713 ExpectToken(Token::kLBRACE);
4662 ParseStatementSequence(); 4714 ParseStatementSequence();
4663 ExpectToken(Token::kRBRACE); 4715 ExpectToken(Token::kRBRACE);
4664 SequenceNode* finally_block = CloseBlock(); 4716 SequenceNode* finally_block = CloseBlock();
4665 return finally_block; 4717 return finally_block;
4666 } 4718 }
4667 4719
4668 4720
4669 void Parser::PushTryBlock(Block* try_block) { 4721 void Parser::PushTryBlock(Block* try_block) {
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
4945 current_block_->statements->Add(try_catch_node); 4997 current_block_->statements->Add(try_catch_node);
4946 SequenceNode* sequence = CloseBlock(); 4998 SequenceNode* sequence = CloseBlock();
4947 sequence->set_label(try_label); 4999 sequence->set_label(try_label);
4948 try_catch_node = sequence; 5000 try_catch_node = sequence;
4949 } 5001 }
4950 return try_catch_node; 5002 return try_catch_node;
4951 } 5003 }
4952 5004
4953 5005
4954 AstNode* Parser::ParseJump(String* label_name) { 5006 AstNode* Parser::ParseJump(String* label_name) {
5007 TRACE_PARSER("ParseJump");
4955 ASSERT(CurrentToken() == Token::kBREAK || CurrentToken() == Token::kCONTINUE); 5008 ASSERT(CurrentToken() == Token::kBREAK || CurrentToken() == Token::kCONTINUE);
4956 Token::Kind jump_kind = CurrentToken(); 5009 Token::Kind jump_kind = CurrentToken();
4957 const intptr_t jump_pos = token_index_; 5010 const intptr_t jump_pos = token_index_;
4958 SourceLabel* target = NULL; 5011 SourceLabel* target = NULL;
4959 ConsumeToken(); 5012 ConsumeToken();
4960 if (IsIdentifier()) { 5013 if (IsIdentifier()) {
4961 // Explicit label after break/continue. 5014 // Explicit label after break/continue.
4962 const String& target_name = *CurrentLiteral(); 5015 const String& target_name = *CurrentLiteral();
4963 ConsumeToken(); 5016 ConsumeToken();
4964 // Handle pathological cases first. 5017 // Handle pathological cases first.
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after
5802 kThrowNewName, 5855 kThrowNewName,
5803 arguments); 5856 arguments);
5804 } 5857 }
5805 } 5858 }
5806 CheckFunctionIsCallable(call_pos, func); 5859 CheckFunctionIsCallable(call_pos, func);
5807 return new StaticCallNode(call_pos, func, arguments); 5860 return new StaticCallNode(call_pos, func, arguments);
5808 } 5861 }
5809 5862
5810 5863
5811 AstNode* Parser::ParseInstanceCall(AstNode* receiver, const String& func_name) { 5864 AstNode* Parser::ParseInstanceCall(AstNode* receiver, const String& func_name) {
5865 TRACE_PARSER("ParseInstanceCall");
5812 const intptr_t call_pos = token_index_; 5866 const intptr_t call_pos = token_index_;
5813 if (CurrentToken() != Token::kLPAREN) { 5867 if (CurrentToken() != Token::kLPAREN) {
5814 ErrorMsg(call_pos, "left parenthesis expected"); 5868 ErrorMsg(call_pos, "left parenthesis expected");
5815 } 5869 }
5816 ArgumentListNode* arguments = ParseActualParameters(NULL, kAllowConst); 5870 ArgumentListNode* arguments = ParseActualParameters(NULL, kAllowConst);
5817 return new InstanceCallNode(call_pos, receiver, func_name, arguments); 5871 return new InstanceCallNode(call_pos, receiver, func_name, arguments);
5818 } 5872 }
5819 5873
5820 5874
5821 AstNode* Parser::ParseClosureCall(AstNode* closure) { 5875 AstNode* Parser::ParseClosureCall(AstNode* closure) {
5876 TRACE_PARSER("ParseClosureCall");
5822 const intptr_t call_pos = token_index_; 5877 const intptr_t call_pos = token_index_;
5823 ASSERT(CurrentToken() == Token::kLPAREN); 5878 ASSERT(CurrentToken() == Token::kLPAREN);
5824 ArgumentListNode* arguments = ParseActualParameters(NULL, kAllowConst); 5879 ArgumentListNode* arguments = ParseActualParameters(NULL, kAllowConst);
5825 return new ClosureCallNode(call_pos, closure, arguments); 5880 return new ClosureCallNode(call_pos, closure, arguments);
5826 } 5881 }
5827 5882
5828 5883
5829 AstNode* Parser::ParseInstanceFieldAccess(AstNode* receiver, 5884 AstNode* Parser::ParseInstanceFieldAccess(AstNode* receiver,
5830 const String& field_name) { 5885 const String& field_name) {
5831 TRACE_PARSER("ParseInstanceFieldAccess"); 5886 TRACE_PARSER("ParseInstanceFieldAccess");
(...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after
6647 } 6702 }
6648 ErrorMsg(ident_pos, "import variable '%s' has not been defined", 6703 ErrorMsg(ident_pos, "import variable '%s' has not been defined",
6649 ident.ToCString()); 6704 ident.ToCString());
6650 return String::null(); 6705 return String::null();
6651 } 6706 }
6652 6707
6653 6708
6654 // Parses type = [ident "."] ident ["<" type { "," type } ">"] and resolve it 6709 // Parses type = [ident "."] ident ["<" type { "," type } ">"] and resolve it
6655 // according to the given type_resolution. 6710 // according to the given type_resolution.
6656 RawAbstractType* Parser::ParseType(TypeResolution type_resolution) { 6711 RawAbstractType* Parser::ParseType(TypeResolution type_resolution) {
6712 TRACE_PARSER("ParseType");
6657 if (CurrentToken() != Token::kIDENT) { 6713 if (CurrentToken() != Token::kIDENT) {
6658 ErrorMsg("type name expected"); 6714 ErrorMsg("type name expected");
6659 } 6715 }
6660 QualIdent type_name; 6716 QualIdent type_name;
6661 if (type_resolution == kIgnore) { 6717 if (type_resolution == kIgnore) {
6662 SkipQualIdent(); 6718 SkipQualIdent();
6663 } else { 6719 } else {
6664 ParseQualIdent(&type_name); 6720 ParseQualIdent(&type_name);
6665 // An identifier cannot be resolved in a local scope when top level parsing. 6721 // An identifier cannot be resolved in a local scope when top level parsing.
6666 if (!is_top_level_ && 6722 if (!is_top_level_ &&
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
7039 factory_param->Add(kv_pairs); 7095 factory_param->Add(kv_pairs);
7040 return new ConstructorCallNode(literal_pos, 7096 return new ConstructorCallNode(literal_pos,
7041 map_type_arguments, 7097 map_type_arguments,
7042 map_literal_factory, 7098 map_literal_factory,
7043 factory_param); 7099 factory_param);
7044 } 7100 }
7045 } 7101 }
7046 7102
7047 7103
7048 AstNode* Parser::ParseCompoundLiteral() { 7104 AstNode* Parser::ParseCompoundLiteral() {
7105 TRACE_PARSER("ParseCompoundLiteral");
7049 bool is_const = false; 7106 bool is_const = false;
7050 if (CurrentToken() == Token::kCONST) { 7107 if (CurrentToken() == Token::kCONST) {
7051 is_const = true; 7108 is_const = true;
7052 ConsumeToken(); 7109 ConsumeToken();
7053 } 7110 }
7054 const intptr_t type_pos = token_index_; 7111 const intptr_t type_pos = token_index_;
7055 AbstractTypeArguments& type_arguments = 7112 AbstractTypeArguments& type_arguments =
7056 AbstractTypeArguments::ZoneHandle(ParseTypeArguments(kMustResolve)); 7113 AbstractTypeArguments::ZoneHandle(ParseTypeArguments(kMustResolve));
7057 AstNode* primary = NULL; 7114 AstNode* primary = NULL;
7058 if ((CurrentToken() == Token::kLBRACK) || 7115 if ((CurrentToken() == Token::kLBRACK) ||
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
7280 7337
7281 7338
7282 // A string literal consists of the concatenation of the next n tokens 7339 // A string literal consists of the concatenation of the next n tokens
7283 // that satisfy the EBNF grammar: 7340 // that satisfy the EBNF grammar:
7284 // literal = kSTRING {{ interpol }+ kSTRING } 7341 // literal = kSTRING {{ interpol }+ kSTRING }
7285 // interpol = kINTERPOL_VAR | (kINTERPOL_START expression kINTERPOL_END) 7342 // interpol = kINTERPOL_VAR | (kINTERPOL_START expression kINTERPOL_END)
7286 // In other words, the scanner breaks down interpolated strings so that 7343 // In other words, the scanner breaks down interpolated strings so that
7287 // a string literal always begins and ends with a kSTRING token, and 7344 // a string literal always begins and ends with a kSTRING token, and
7288 // there are never two kSTRING tokens next to each other. 7345 // there are never two kSTRING tokens next to each other.
7289 AstNode* Parser::ParseStringLiteral() { 7346 AstNode* Parser::ParseStringLiteral() {
7347 TRACE_PARSER("ParseStringLiteral");
7290 AstNode* primary = NULL; 7348 AstNode* primary = NULL;
7291 const intptr_t literal_start = token_index_; 7349 const intptr_t literal_start = token_index_;
7292 if ((CurrentToken() == Token::kSTRING) && 7350 if ((CurrentToken() == Token::kSTRING) &&
7293 (LookaheadToken(1) != Token::kINTERPOL_VAR) && 7351 (LookaheadToken(1) != Token::kINTERPOL_VAR) &&
7294 (LookaheadToken(1) != Token::kINTERPOL_START)) { 7352 (LookaheadToken(1) != Token::kINTERPOL_START)) {
7295 // Common case: no interpolation. 7353 // Common case: no interpolation.
7296 primary = new LiteralNode(literal_start, *CurrentLiteral()); 7354 primary = new LiteralNode(literal_start, *CurrentLiteral());
7297 ConsumeToken(); 7355 ConsumeToken();
7298 return primary; 7356 return primary;
7299 } 7357 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
7335 7393
7336 7394
7337 // An import string literal consists of the concatenation of the next n tokens 7395 // An import string literal consists of the concatenation of the next n tokens
7338 // that satisfy the EBNF grammar: 7396 // that satisfy the EBNF grammar:
7339 // literal = kSTRING {{ interpol }+ kSTRING } 7397 // literal = kSTRING {{ interpol }+ kSTRING }
7340 // interpol = kINTERPOL_VAR 7398 // interpol = kINTERPOL_VAR
7341 // In other words, the scanner breaks down interpolated strings so that 7399 // In other words, the scanner breaks down interpolated strings so that
7342 // a string literal always begins and ends with a kSTRING token, and 7400 // a string literal always begins and ends with a kSTRING token, and
7343 // there are never two kSTRING tokens next to each other. 7401 // there are never two kSTRING tokens next to each other.
7344 String* Parser::ParseImportStringLiteral() { 7402 String* Parser::ParseImportStringLiteral() {
7403 TRACE_PARSER("ParseImportStringLiteral");
7345 if ((CurrentToken() == Token::kSTRING) && 7404 if ((CurrentToken() == Token::kSTRING) &&
7346 (LookaheadToken(1) != Token::kINTERPOL_VAR) && 7405 (LookaheadToken(1) != Token::kINTERPOL_VAR) &&
7347 (LookaheadToken(1) != Token::kINTERPOL_START)) { 7406 (LookaheadToken(1) != Token::kINTERPOL_START)) {
7348 // Common case: no interpolation. 7407 // Common case: no interpolation.
7349 String* result = CurrentLiteral(); 7408 String* result = CurrentLiteral();
7350 ConsumeToken(); 7409 ConsumeToken();
7351 return result; 7410 return result;
7352 } 7411 }
7353 // String interpolation needed. 7412 // String interpolation needed.
7354 String& result = String::ZoneHandle(String::New("")); 7413 String& result = String::ZoneHandle(String::New(""));
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
7788 void Parser::SkipQualIdent() { 7847 void Parser::SkipQualIdent() {
7789 ASSERT(IsIdentifier()); 7848 ASSERT(IsIdentifier());
7790 ConsumeToken(); 7849 ConsumeToken();
7791 if (CurrentToken() == Token::kPERIOD) { 7850 if (CurrentToken() == Token::kPERIOD) {
7792 ConsumeToken(); // Consume the kPERIOD token. 7851 ConsumeToken(); // Consume the kPERIOD token.
7793 ExpectIdentifier("identifier expected after '.'"); 7852 ExpectIdentifier("identifier expected after '.'");
7794 } 7853 }
7795 } 7854 }
7796 7855
7797 } // namespace dart 7856 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/parser.h ('k') | tests/co19/co19-runtime.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698