| OLD | NEW |
| 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 "lib/invocation_mirror.h" | 7 #include "lib/invocation_mirror.h" |
| 8 #include "vm/bigint_operations.h" | 8 #include "vm/bigint_operations.h" |
| 9 #include "vm/bootstrap.h" | 9 #include "vm/bootstrap.h" |
| 10 #include "vm/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 | 428 |
| 429 struct ParamDesc { | 429 struct ParamDesc { |
| 430 ParamDesc() | 430 ParamDesc() |
| 431 : type(NULL), | 431 : type(NULL), |
| 432 name_pos(0), | 432 name_pos(0), |
| 433 name(NULL), | 433 name(NULL), |
| 434 default_value(NULL), | 434 default_value(NULL), |
| 435 metadata(NULL), | 435 metadata(NULL), |
| 436 var(NULL), | 436 var(NULL), |
| 437 is_final(false), | 437 is_final(false), |
| 438 is_field_initializer(false) { } | 438 is_field_initializer(false), |
| 439 has_explicit_type(false) { } |
| 439 const AbstractType* type; | 440 const AbstractType* type; |
| 440 intptr_t name_pos; | 441 intptr_t name_pos; |
| 441 const String* name; | 442 const String* name; |
| 442 const Object* default_value; // NULL if not an optional parameter. | 443 const Object* default_value; // NULL if not an optional parameter. |
| 443 const Object* metadata; // NULL if no metadata or metadata not evaluated. | 444 const Object* metadata; // NULL if no metadata or metadata not evaluated. |
| 444 LocalVariable* var; // Scope variable allocated for this parameter. | 445 LocalVariable* var; // Scope variable allocated for this parameter. |
| 445 bool is_final; | 446 bool is_final; |
| 446 bool is_field_initializer; | 447 bool is_field_initializer; |
| 448 bool has_explicit_type; |
| 447 }; | 449 }; |
| 448 | 450 |
| 449 | 451 |
| 450 struct ParamList { | 452 struct ParamList { |
| 451 ParamList() { | 453 ParamList() { |
| 452 Clear(); | 454 Clear(); |
| 453 } | 455 } |
| 454 | 456 |
| 455 void Clear() { | 457 void Clear() { |
| 456 num_fixed_parameters = 0; | 458 num_fixed_parameters = 0; |
| (...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1408 SkipMetadata(); | 1410 SkipMetadata(); |
| 1409 } | 1411 } |
| 1410 | 1412 |
| 1411 if (CurrentToken() == Token::kFINAL) { | 1413 if (CurrentToken() == Token::kFINAL) { |
| 1412 ConsumeToken(); | 1414 ConsumeToken(); |
| 1413 parameter.is_final = true; | 1415 parameter.is_final = true; |
| 1414 } else if (CurrentToken() == Token::kVAR) { | 1416 } else if (CurrentToken() == Token::kVAR) { |
| 1415 ConsumeToken(); | 1417 ConsumeToken(); |
| 1416 var_seen = true; | 1418 var_seen = true; |
| 1417 // The parameter type is the 'dynamic' type. | 1419 // The parameter type is the 'dynamic' type. |
| 1420 // If this is an initializing formal, its type will be set to the type of |
| 1421 // the respective field when the constructor is fully parsed. |
| 1418 parameter.type = &Type::ZoneHandle(Type::DynamicType()); | 1422 parameter.type = &Type::ZoneHandle(Type::DynamicType()); |
| 1419 } | 1423 } |
| 1420 if (CurrentToken() == Token::kTHIS) { | 1424 if (CurrentToken() == Token::kTHIS) { |
| 1421 ConsumeToken(); | 1425 ConsumeToken(); |
| 1422 ExpectToken(Token::kPERIOD); | 1426 ExpectToken(Token::kPERIOD); |
| 1423 this_seen = true; | 1427 this_seen = true; |
| 1424 parameter.is_field_initializer = true; | 1428 parameter.is_field_initializer = true; |
| 1425 } | 1429 } |
| 1426 if ((parameter.type == NULL) && (CurrentToken() == Token::kVOID)) { | 1430 if ((parameter.type == NULL) && (CurrentToken() == Token::kVOID)) { |
| 1427 ConsumeToken(); | 1431 ConsumeToken(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1441 Token::Kind follower = LookaheadToken(1); | 1445 Token::Kind follower = LookaheadToken(1); |
| 1442 // We have an identifier followed by a 'follower' token. | 1446 // We have an identifier followed by a 'follower' token. |
| 1443 // We either parse a type or assume that no type is specified. | 1447 // We either parse a type or assume that no type is specified. |
| 1444 if ((follower == Token::kLT) || // Parameterized type. | 1448 if ((follower == Token::kLT) || // Parameterized type. |
| 1445 (follower == Token::kPERIOD) || // Qualified class name of type. | 1449 (follower == Token::kPERIOD) || // Qualified class name of type. |
| 1446 Token::IsIdentifier(follower) || // Parameter name following a type. | 1450 Token::IsIdentifier(follower) || // Parameter name following a type. |
| 1447 (follower == Token::kTHIS)) { // Field parameter following a type. | 1451 (follower == Token::kTHIS)) { // Field parameter following a type. |
| 1448 // The types of formal parameters are never ignored, even in unchecked | 1452 // The types of formal parameters are never ignored, even in unchecked |
| 1449 // mode, because they are part of the function type of closurized | 1453 // mode, because they are part of the function type of closurized |
| 1450 // functions appearing in type tests with typedefs. | 1454 // functions appearing in type tests with typedefs. |
| 1455 parameter.has_explicit_type = true; |
| 1451 parameter.type = &AbstractType::ZoneHandle( | 1456 parameter.type = &AbstractType::ZoneHandle( |
| 1452 ParseType(is_top_level_ ? ClassFinalizer::kResolveTypeParameters : | 1457 ParseType(is_top_level_ ? ClassFinalizer::kResolveTypeParameters : |
| 1453 ClassFinalizer::kCanonicalize)); | 1458 ClassFinalizer::kCanonicalize)); |
| 1454 } else { | 1459 } else { |
| 1460 // If this is an initializing formal, its type will be set to the type of |
| 1461 // the respective field when the constructor is fully parsed. |
| 1455 parameter.type = &Type::ZoneHandle(Type::DynamicType()); | 1462 parameter.type = &Type::ZoneHandle(Type::DynamicType()); |
| 1456 } | 1463 } |
| 1457 } | 1464 } |
| 1458 if (!this_seen && (CurrentToken() == Token::kTHIS)) { | 1465 if (!this_seen && (CurrentToken() == Token::kTHIS)) { |
| 1459 ConsumeToken(); | 1466 ConsumeToken(); |
| 1460 ExpectToken(Token::kPERIOD); | 1467 ExpectToken(Token::kPERIOD); |
| 1461 this_seen = true; | 1468 this_seen = true; |
| 1462 parameter.is_field_initializer = true; | 1469 parameter.is_field_initializer = true; |
| 1463 } | 1470 } |
| 1464 | 1471 |
| (...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2548 ErrorMsg(param.name_pos, | 2555 ErrorMsg(param.name_pos, |
| 2549 "unresolved reference to instance field '%s'", | 2556 "unresolved reference to instance field '%s'", |
| 2550 field_name.ToCString()); | 2557 field_name.ToCString()); |
| 2551 } | 2558 } |
| 2552 if (is_redirecting_constructor) { | 2559 if (is_redirecting_constructor) { |
| 2553 ErrorMsg(param.name_pos, | 2560 ErrorMsg(param.name_pos, |
| 2554 "redirecting constructors may not have " | 2561 "redirecting constructors may not have " |
| 2555 "initializing formal parameters"); | 2562 "initializing formal parameters"); |
| 2556 } | 2563 } |
| 2557 CheckDuplicateFieldInit(param.name_pos, &initialized_fields, &field); | 2564 CheckDuplicateFieldInit(param.name_pos, &initialized_fields, &field); |
| 2565 |
| 2566 if (!param.has_explicit_type) { |
| 2567 const AbstractType& field_type = |
| 2568 AbstractType::ZoneHandle(field.type()); |
| 2569 param.type = &field_type; |
| 2570 // Parameter type was already set to dynamic when parsing the class |
| 2571 // declaration: fix it. |
| 2572 func.SetParameterTypeAt(i, field_type); |
| 2573 } |
| 2574 |
| 2558 AstNode* instance = new LoadLocalNode(param.name_pos, receiver); | 2575 AstNode* instance = new LoadLocalNode(param.name_pos, receiver); |
| 2559 // Initializing formals cannot be used in the explicit initializer | 2576 // Initializing formals cannot be used in the explicit initializer |
| 2560 // list, nor can they be used in the constructor body. | 2577 // list, nor can they be used in the constructor body. |
| 2561 // Thus, they are set to be invisible when added to the scope. | 2578 // Thus, they are set to be invisible when added to the scope. |
| 2562 LocalVariable* p = param.var; | 2579 LocalVariable* p = param.var; |
| 2563 ASSERT(p != NULL); | 2580 ASSERT(p != NULL); |
| 2564 ASSERT(p->is_invisible()); | 2581 ASSERT(p->is_invisible()); |
| 2565 AstNode* value = new LoadLocalNode(param.name_pos, p); | 2582 AstNode* value = new LoadLocalNode(param.name_pos, p); |
| 2566 EnsureExpressionTemp(); | 2583 EnsureExpressionTemp(); |
| 2567 AstNode* initializer = new StoreInstanceFieldNode( | 2584 AstNode* initializer = new StoreInstanceFieldNode( |
| (...skipping 8051 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10619 void Parser::SkipQualIdent() { | 10636 void Parser::SkipQualIdent() { |
| 10620 ASSERT(IsIdentifier()); | 10637 ASSERT(IsIdentifier()); |
| 10621 ConsumeToken(); | 10638 ConsumeToken(); |
| 10622 if (CurrentToken() == Token::kPERIOD) { | 10639 if (CurrentToken() == Token::kPERIOD) { |
| 10623 ConsumeToken(); // Consume the kPERIOD token. | 10640 ConsumeToken(); // Consume the kPERIOD token. |
| 10624 ExpectIdentifier("identifier expected after '.'"); | 10641 ExpectIdentifier("identifier expected after '.'"); |
| 10625 } | 10642 } |
| 10626 } | 10643 } |
| 10627 | 10644 |
| 10628 } // namespace dart | 10645 } // namespace dart |
| OLD | NEW |