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 "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" |
11 #include "vm/dart_api_impl.h" | 11 #include "vm/dart_api_impl.h" |
12 #include "vm/dart_entry.h" | 12 #include "vm/dart_entry.h" |
13 #include "vm/flags.h" | 13 #include "vm/flags.h" |
14 #include "vm/growable_array.h" | 14 #include "vm/growable_array.h" |
15 #include "vm/longjump.h" | 15 #include "vm/longjump.h" |
16 #include "vm/native_entry.h" | 16 #include "vm/native_entry.h" |
17 #include "vm/object.h" | 17 #include "vm/object.h" |
18 #include "vm/object_store.h" | 18 #include "vm/object_store.h" |
19 #include "vm/resolver.h" | 19 #include "vm/resolver.h" |
20 #include "vm/scopes.h" | 20 #include "vm/scopes.h" |
| 21 #include "vm/symbols.h" |
21 | 22 |
22 namespace dart { | 23 namespace dart { |
23 | 24 |
24 DEFINE_FLAG(bool, enable_asserts, false, "Enable assert statements."); | 25 DEFINE_FLAG(bool, enable_asserts, false, "Enable assert statements."); |
25 DEFINE_FLAG(bool, enable_type_checks, false, "Enable type checks."); | 26 DEFINE_FLAG(bool, enable_type_checks, false, "Enable type checks."); |
26 DEFINE_FLAG(bool, trace_parser, false, "Trace parser operations."); | 27 DEFINE_FLAG(bool, trace_parser, false, "Trace parser operations."); |
27 DEFINE_FLAG(bool, warning_as_error, false, "Treat warnings as errors."); | 28 DEFINE_FLAG(bool, warning_as_error, false, "Treat warnings as errors."); |
28 DEFINE_FLAG(bool, silent_warnings, false, "Silence warnings."); | 29 DEFINE_FLAG(bool, silent_warnings, false, "Silence warnings."); |
29 | 30 |
30 static void CheckedModeHandler(bool value) { | 31 static void CheckedModeHandler(bool value) { |
(...skipping 1490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1521 LocalVariable* receiver) { | 1522 LocalVariable* receiver) { |
1522 const intptr_t supercall_pos = TokenPos(); | 1523 const intptr_t supercall_pos = TokenPos(); |
1523 const Class& super_class = Class::Handle(cls.SuperClass()); | 1524 const Class& super_class = Class::Handle(cls.SuperClass()); |
1524 // Omit the implicit super() if there is no super class (i.e. | 1525 // Omit the implicit super() if there is no super class (i.e. |
1525 // we're not compiling class Object), or if the super class is an | 1526 // we're not compiling class Object), or if the super class is an |
1526 // artificially generated "wrapper class" that has no constructor. | 1527 // artificially generated "wrapper class" that has no constructor. |
1527 if (super_class.IsNull() || (super_class.num_native_fields() > 0)) { | 1528 if (super_class.IsNull() || (super_class.num_native_fields() > 0)) { |
1528 return; | 1529 return; |
1529 } | 1530 } |
1530 String& ctor_name = String::Handle(super_class.Name()); | 1531 String& ctor_name = String::Handle(super_class.Name()); |
1531 String& ctor_suffix = String::Handle(String::NewSymbol(".")); | 1532 String& ctor_suffix = String::Handle(Symbols::Dot()); |
1532 ctor_name = String::Concat(ctor_name, ctor_suffix); | 1533 ctor_name = String::Concat(ctor_name, ctor_suffix); |
1533 ArgumentListNode* arguments = new ArgumentListNode(supercall_pos); | 1534 ArgumentListNode* arguments = new ArgumentListNode(supercall_pos); |
1534 // Implicit 'this' parameter is the first argument. | 1535 // Implicit 'this' parameter is the first argument. |
1535 AstNode* implicit_argument = new LoadLocalNode(supercall_pos, *receiver); | 1536 AstNode* implicit_argument = new LoadLocalNode(supercall_pos, *receiver); |
1536 arguments->Add(implicit_argument); | 1537 arguments->Add(implicit_argument); |
1537 // Implicit construction phase parameter is second argument. | 1538 // Implicit construction phase parameter is second argument. |
1538 AstNode* phase_parameter = | 1539 AstNode* phase_parameter = |
1539 new LiteralNode(supercall_pos, | 1540 new LiteralNode(supercall_pos, |
1540 Smi::ZoneHandle(Smi::New(Function::kCtorPhaseAll))); | 1541 Smi::ZoneHandle(Smi::New(Function::kCtorPhaseAll))); |
1541 arguments->Add(phase_parameter); | 1542 arguments->Add(phase_parameter); |
(...skipping 21 matching lines...) Expand all Loading... |
1563 | 1564 |
1564 AstNode* Parser::ParseSuperInitializer(const Class& cls, | 1565 AstNode* Parser::ParseSuperInitializer(const Class& cls, |
1565 LocalVariable* receiver) { | 1566 LocalVariable* receiver) { |
1566 TRACE_PARSER("ParseSuperInitializer"); | 1567 TRACE_PARSER("ParseSuperInitializer"); |
1567 ASSERT(CurrentToken() == Token::kSUPER); | 1568 ASSERT(CurrentToken() == Token::kSUPER); |
1568 const intptr_t supercall_pos = TokenPos(); | 1569 const intptr_t supercall_pos = TokenPos(); |
1569 ConsumeToken(); | 1570 ConsumeToken(); |
1570 const Class& super_class = Class::Handle(cls.SuperClass()); | 1571 const Class& super_class = Class::Handle(cls.SuperClass()); |
1571 ASSERT(!super_class.IsNull()); | 1572 ASSERT(!super_class.IsNull()); |
1572 String& ctor_name = String::Handle(super_class.Name()); | 1573 String& ctor_name = String::Handle(super_class.Name()); |
1573 String& ctor_suffix = String::Handle(String::NewSymbol(".")); | 1574 String& ctor_suffix = String::Handle(Symbols::Dot()); |
1574 if (CurrentToken() == Token::kPERIOD) { | 1575 if (CurrentToken() == Token::kPERIOD) { |
1575 ConsumeToken(); | 1576 ConsumeToken(); |
1576 ctor_suffix = String::Concat( | 1577 ctor_suffix = String::Concat( |
1577 ctor_suffix, *ExpectIdentifier("constructor name expected")); | 1578 ctor_suffix, *ExpectIdentifier("constructor name expected")); |
1578 } | 1579 } |
1579 ctor_name = String::Concat(ctor_name, ctor_suffix); | 1580 ctor_name = String::Concat(ctor_name, ctor_suffix); |
1580 if (CurrentToken() != Token::kLPAREN) { | 1581 if (CurrentToken() != Token::kLPAREN) { |
1581 ErrorMsg("parameter list expected"); | 1582 ErrorMsg("parameter list expected"); |
1582 } | 1583 } |
1583 | 1584 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1749 } | 1750 } |
1750 | 1751 |
1751 | 1752 |
1752 void Parser::ParseConstructorRedirection(const Class& cls, | 1753 void Parser::ParseConstructorRedirection(const Class& cls, |
1753 LocalVariable* receiver) { | 1754 LocalVariable* receiver) { |
1754 TRACE_PARSER("ParseConstructorRedirection"); | 1755 TRACE_PARSER("ParseConstructorRedirection"); |
1755 ASSERT(CurrentToken() == Token::kTHIS); | 1756 ASSERT(CurrentToken() == Token::kTHIS); |
1756 const intptr_t call_pos = TokenPos(); | 1757 const intptr_t call_pos = TokenPos(); |
1757 ConsumeToken(); | 1758 ConsumeToken(); |
1758 String& ctor_name = String::Handle(cls.Name()); | 1759 String& ctor_name = String::Handle(cls.Name()); |
1759 String& ctor_suffix = String::Handle(String::NewSymbol(".")); | 1760 String& ctor_suffix = String::Handle(Symbols::Dot()); |
1760 | 1761 |
1761 if (CurrentToken() == Token::kPERIOD) { | 1762 if (CurrentToken() == Token::kPERIOD) { |
1762 ConsumeToken(); | 1763 ConsumeToken(); |
1763 ctor_suffix = String::Concat( | 1764 ctor_suffix = String::Concat( |
1764 ctor_suffix, *ExpectIdentifier("constructor name expected")); | 1765 ctor_suffix, *ExpectIdentifier("constructor name expected")); |
1765 } | 1766 } |
1766 ctor_name = String::Concat(ctor_name, ctor_suffix); | 1767 ctor_name = String::Concat(ctor_name, ctor_suffix); |
1767 if (CurrentToken() != Token::kLPAREN) { | 1768 if (CurrentToken() != Token::kLPAREN) { |
1768 ErrorMsg("parameter list expected"); | 1769 ErrorMsg("parameter list expected"); |
1769 } | 1770 } |
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2368 if (method->params.has_field_initializer) { | 2369 if (method->params.has_field_initializer) { |
2369 // Constructors that redirect to another constructor must not | 2370 // Constructors that redirect to another constructor must not |
2370 // initialize any fields using field initializer parameters. | 2371 // initialize any fields using field initializer parameters. |
2371 ErrorMsg(formal_param_pos, "Redirecting constructor " | 2372 ErrorMsg(formal_param_pos, "Redirecting constructor " |
2372 "may not use field initializer parameters"); | 2373 "may not use field initializer parameters"); |
2373 } | 2374 } |
2374 ConsumeToken(); // Colon. | 2375 ConsumeToken(); // Colon. |
2375 ExpectToken(Token::kTHIS); | 2376 ExpectToken(Token::kTHIS); |
2376 String& redir_name = String::ZoneHandle( | 2377 String& redir_name = String::ZoneHandle( |
2377 String::Concat(members->class_name(), | 2378 String::Concat(members->class_name(), |
2378 String::Handle(String::NewSymbol(".")))); | 2379 String::Handle(Symbols::Dot()))); |
2379 if (CurrentToken() == Token::kPERIOD) { | 2380 if (CurrentToken() == Token::kPERIOD) { |
2380 ConsumeToken(); | 2381 ConsumeToken(); |
2381 redir_name = String::Concat(redir_name, | 2382 redir_name = String::Concat(redir_name, |
2382 *ExpectIdentifier("constructor name expected")); | 2383 *ExpectIdentifier("constructor name expected")); |
2383 } | 2384 } |
2384 method->redirect_name = &redir_name; | 2385 method->redirect_name = &redir_name; |
2385 if (CurrentToken() != Token::kLPAREN) { | 2386 if (CurrentToken() != Token::kLPAREN) { |
2386 ErrorMsg("'(' expected"); | 2387 ErrorMsg("'(' expected"); |
2387 } | 2388 } |
2388 SkipToMatchingParenthesis(); | 2389 SkipToMatchingParenthesis(); |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2704 member.type = &Type::ZoneHandle(Type::New(result_type_class, | 2705 member.type = &Type::ZoneHandle(Type::New(result_type_class, |
2705 TypeArguments::Handle(), | 2706 TypeArguments::Handle(), |
2706 factory_name.ident_pos)); | 2707 factory_name.ident_pos)); |
2707 } else { | 2708 } else { |
2708 member.name_pos = TokenPos(); | 2709 member.name_pos = TokenPos(); |
2709 member.name = CurrentLiteral(); | 2710 member.name = CurrentLiteral(); |
2710 ConsumeToken(); | 2711 ConsumeToken(); |
2711 } | 2712 } |
2712 // We must be dealing with a constructor or named constructor. | 2713 // We must be dealing with a constructor or named constructor. |
2713 member.kind = RawFunction::kConstructor; | 2714 member.kind = RawFunction::kConstructor; |
2714 String& ctor_suffix = String::ZoneHandle(String::NewSymbol(".")); | 2715 String& ctor_suffix = String::ZoneHandle(Symbols::Dot()); |
2715 if (CurrentToken() == Token::kPERIOD) { | 2716 if (CurrentToken() == Token::kPERIOD) { |
2716 // Named constructor. | 2717 // Named constructor. |
2717 ConsumeToken(); | 2718 ConsumeToken(); |
2718 const String* name = ExpectIdentifier("identifier expected"); | 2719 const String* name = ExpectIdentifier("identifier expected"); |
2719 ctor_suffix = String::Concat(ctor_suffix, *name); | 2720 ctor_suffix = String::Concat(ctor_suffix, *name); |
2720 } | 2721 } |
2721 *member.name = String::Concat(*member.name, ctor_suffix); | 2722 *member.name = String::Concat(*member.name, ctor_suffix); |
2722 // Ensure that names are symbols. | 2723 // Ensure that names are symbols. |
2723 *member.name = String::NewSymbol(*member.name); | 2724 *member.name = String::NewSymbol(*member.name); |
2724 if (member.type == NULL) { | 2725 if (member.type == NULL) { |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2920 | 2921 |
2921 // 1. Add an implicit constructor if no explicit constructor is present. | 2922 // 1. Add an implicit constructor if no explicit constructor is present. |
2922 // 2. Check for cycles in constructor redirection. | 2923 // 2. Check for cycles in constructor redirection. |
2923 void Parser::CheckConstructors(ClassDesc* class_desc) { | 2924 void Parser::CheckConstructors(ClassDesc* class_desc) { |
2924 // Add an implicit constructor if no explicit constructor is present. | 2925 // Add an implicit constructor if no explicit constructor is present. |
2925 if (!class_desc->has_constructor()) { | 2926 if (!class_desc->has_constructor()) { |
2926 // The implicit constructor is unnamed, has no explicit parameter, | 2927 // The implicit constructor is unnamed, has no explicit parameter, |
2927 // and contains a supercall in the initializer list. | 2928 // and contains a supercall in the initializer list. |
2928 String& ctor_name = String::ZoneHandle( | 2929 String& ctor_name = String::ZoneHandle( |
2929 String::Concat(class_desc->class_name(), | 2930 String::Concat(class_desc->class_name(), |
2930 String::Handle(String::NewSymbol(".")))); | 2931 String::Handle(Symbols::Dot()))); |
2931 ctor_name = String::NewSymbol(ctor_name); | 2932 ctor_name = String::NewSymbol(ctor_name); |
2932 // The token position for the implicit constructor is the 'class' | 2933 // The token position for the implicit constructor is the 'class' |
2933 // keyword of the constructor's class. | 2934 // keyword of the constructor's class. |
2934 Function& ctor = Function::Handle( | 2935 Function& ctor = Function::Handle( |
2935 Function::New(ctor_name, | 2936 Function::New(ctor_name, |
2936 RawFunction::kConstructor, | 2937 RawFunction::kConstructor, |
2937 /* is_static = */ false, | 2938 /* is_static = */ false, |
2938 /* is_const = */ false, | 2939 /* is_const = */ false, |
2939 class_desc->token_pos())); | 2940 class_desc->token_pos())); |
2940 ParamList params; | 2941 ParamList params; |
(...skipping 4908 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7849 return primary; | 7850 return primary; |
7850 } | 7851 } |
7851 | 7852 |
7852 | 7853 |
7853 static const String& BuildConstructorName(const String& type_class_name, | 7854 static const String& BuildConstructorName(const String& type_class_name, |
7854 const String* named_constructor) { | 7855 const String* named_constructor) { |
7855 // By convention, the static function implementing a named constructor 'C' | 7856 // By convention, the static function implementing a named constructor 'C' |
7856 // for class 'A' is labeled 'A.C', and the static function implementing the | 7857 // for class 'A' is labeled 'A.C', and the static function implementing the |
7857 // unnamed constructor for class 'A' is labeled 'A.'. | 7858 // unnamed constructor for class 'A' is labeled 'A.'. |
7858 // This convention prevents users from explicitly calling constructors. | 7859 // This convention prevents users from explicitly calling constructors. |
7859 const String& period = String::Handle(String::NewSymbol(".")); | 7860 const String& period = String::Handle(Symbols::Dot()); |
7860 String& constructor_name = | 7861 String& constructor_name = |
7861 String::Handle(String::Concat(type_class_name, period)); | 7862 String::Handle(String::Concat(type_class_name, period)); |
7862 if (named_constructor != NULL) { | 7863 if (named_constructor != NULL) { |
7863 constructor_name = String::Concat(constructor_name, *named_constructor); | 7864 constructor_name = String::Concat(constructor_name, *named_constructor); |
7864 } | 7865 } |
7865 return constructor_name; | 7866 return constructor_name; |
7866 } | 7867 } |
7867 | 7868 |
7868 | 7869 |
7869 AstNode* Parser::ParseNewOperator() { | 7870 AstNode* Parser::ParseNewOperator() { |
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8659 void Parser::SkipQualIdent() { | 8660 void Parser::SkipQualIdent() { |
8660 ASSERT(IsIdentifier()); | 8661 ASSERT(IsIdentifier()); |
8661 ConsumeToken(); | 8662 ConsumeToken(); |
8662 if (CurrentToken() == Token::kPERIOD) { | 8663 if (CurrentToken() == Token::kPERIOD) { |
8663 ConsumeToken(); // Consume the kPERIOD token. | 8664 ConsumeToken(); // Consume the kPERIOD token. |
8664 ExpectIdentifier("identifier expected after '.'"); | 8665 ExpectIdentifier("identifier expected after '.'"); |
8665 } | 8666 } |
8666 } | 8667 } |
8667 | 8668 |
8668 } // namespace dart | 8669 } // namespace dart |
OLD | NEW |