| 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 "platform/utils.h" | 8 #include "platform/utils.h" |
| 9 #include "vm/ast_transformer.h" | 9 #include "vm/ast_transformer.h" |
| 10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
| (...skipping 2135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2146 } | 2146 } |
| 2147 } | 2147 } |
| 2148 return new StaticGetterNode( | 2148 return new StaticGetterNode( |
| 2149 field_pos, implicit_argument, true, super_class, field_name); | 2149 field_pos, implicit_argument, true, super_class, field_name); |
| 2150 } | 2150 } |
| 2151 | 2151 |
| 2152 | 2152 |
| 2153 void Parser::GenerateSuperConstructorCall(const Class& cls, | 2153 void Parser::GenerateSuperConstructorCall(const Class& cls, |
| 2154 intptr_t supercall_pos, | 2154 intptr_t supercall_pos, |
| 2155 LocalVariable* receiver, | 2155 LocalVariable* receiver, |
| 2156 AstNode* phase_parameter, |
| 2156 ArgumentListNode* forwarding_args) { | 2157 ArgumentListNode* forwarding_args) { |
| 2157 const Class& super_class = Class::Handle(Z, cls.SuperClass()); | 2158 const Class& super_class = Class::Handle(Z, cls.SuperClass()); |
| 2158 // Omit the implicit super() if there is no super class (i.e. | 2159 // Omit the implicit super() if there is no super class (i.e. |
| 2159 // we're not compiling class Object), or if the super class is an | 2160 // we're not compiling class Object), or if the super class is an |
| 2160 // artificially generated "wrapper class" that has no constructor. | 2161 // artificially generated "wrapper class" that has no constructor. |
| 2161 if (super_class.IsNull() || | 2162 if (super_class.IsNull() || |
| 2162 (super_class.num_native_fields() > 0 && | 2163 (super_class.num_native_fields() > 0 && |
| 2163 Class::Handle(Z, super_class.SuperClass()).IsObjectClass())) { | 2164 Class::Handle(Z, super_class.SuperClass()).IsObjectClass())) { |
| 2164 return; | 2165 return; |
| 2165 } | 2166 } |
| 2166 String& super_ctor_name = String::Handle(Z, super_class.Name()); | 2167 String& super_ctor_name = String::Handle(Z, super_class.Name()); |
| 2167 super_ctor_name = String::Concat(super_ctor_name, Symbols::Dot()); | 2168 super_ctor_name = String::Concat(super_ctor_name, Symbols::Dot()); |
| 2168 | 2169 |
| 2169 ArgumentListNode* arguments = new ArgumentListNode(supercall_pos); | 2170 ArgumentListNode* arguments = new ArgumentListNode(supercall_pos); |
| 2170 // Implicit 'this' parameter is the first argument. | 2171 // Implicit 'this' parameter is the first argument. |
| 2171 AstNode* implicit_argument = new LoadLocalNode(supercall_pos, receiver); | 2172 AstNode* implicit_argument = new LoadLocalNode(supercall_pos, receiver); |
| 2172 arguments->Add(implicit_argument); | 2173 arguments->Add(implicit_argument); |
| 2173 // Implicit construction phase parameter is second argument. | 2174 // Implicit construction phase parameter is second argument. |
| 2174 AstNode* phase_parameter = | |
| 2175 new LiteralNode(supercall_pos, | |
| 2176 Smi::ZoneHandle(Z, Smi::New(Function::kCtorPhaseAll))); | |
| 2177 arguments->Add(phase_parameter); | 2175 arguments->Add(phase_parameter); |
| 2178 | 2176 |
| 2179 // If this is a super call in a forwarding constructor, add the user- | 2177 // If this is a super call in a forwarding constructor, add the user- |
| 2180 // defined arguments to the super call and adjust the the super | 2178 // defined arguments to the super call and adjust the the super |
| 2181 // constructor name to the respective named constructor if necessary. | 2179 // constructor name to the respective named constructor if necessary. |
| 2182 if (forwarding_args != NULL) { | 2180 if (forwarding_args != NULL) { |
| 2183 for (int i = 0; i < forwarding_args->length(); i++) { | 2181 for (int i = 0; i < forwarding_args->length(); i++) { |
| 2184 arguments->Add(forwarding_args->NodeAt(i)); | 2182 arguments->Add(forwarding_args->NodeAt(i)); |
| 2185 } | 2183 } |
| 2186 String& ctor_name = String::Handle(Z, current_function().name()); | 2184 String& ctor_name = String::Handle(Z, current_function().name()); |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2557 super_init_seen = true; | 2555 super_init_seen = true; |
| 2558 } else { | 2556 } else { |
| 2559 init_statement = ParseInitializer(cls, receiver, initialized_fields); | 2557 init_statement = ParseInitializer(cls, receiver, initialized_fields); |
| 2560 } | 2558 } |
| 2561 current_block_->statements->Add(init_statement); | 2559 current_block_->statements->Add(init_statement); |
| 2562 } while (CurrentToken() == Token::kCOMMA); | 2560 } while (CurrentToken() == Token::kCOMMA); |
| 2563 } | 2561 } |
| 2564 if (!super_init_seen) { | 2562 if (!super_init_seen) { |
| 2565 // Generate implicit super() if we haven't seen an explicit super call | 2563 // Generate implicit super() if we haven't seen an explicit super call |
| 2566 // or constructor redirection. | 2564 // or constructor redirection. |
| 2567 GenerateSuperConstructorCall(cls, TokenPos(), receiver, NULL); | 2565 AstNode* phase_parameter = new LiteralNode( |
| 2566 TokenPos(), Smi::ZoneHandle(Z, Smi::New(Function::kCtorPhaseAll))); |
| 2567 GenerateSuperConstructorCall( |
| 2568 cls, TokenPos(), receiver, phase_parameter, NULL); |
| 2568 } | 2569 } |
| 2569 CheckFieldsInitialized(cls); | 2570 CheckFieldsInitialized(cls); |
| 2570 } | 2571 } |
| 2571 | 2572 |
| 2572 | 2573 |
| 2573 void Parser::ParseConstructorRedirection(const Class& cls, | 2574 void Parser::ParseConstructorRedirection(const Class& cls, |
| 2574 LocalVariable* receiver) { | 2575 LocalVariable* receiver) { |
| 2575 TRACE_PARSER("ParseConstructorRedirection"); | 2576 TRACE_PARSER("ParseConstructorRedirection"); |
| 2576 ExpectToken(Token::kCOLON); | 2577 ExpectToken(Token::kCOLON); |
| 2577 ASSERT(CurrentToken() == Token::kTHIS); | 2578 ASSERT(CurrentToken() == Token::kTHIS); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2679 for (int i = 2; i < func.NumParameters(); i++) { | 2680 for (int i = 2; i < func.NumParameters(); i++) { |
| 2680 LocalVariable* param = new LocalVariable( | 2681 LocalVariable* param = new LocalVariable( |
| 2681 Scanner::kNoSourcePos, | 2682 Scanner::kNoSourcePos, |
| 2682 String::ZoneHandle(Z, func.ParameterNameAt(i)), | 2683 String::ZoneHandle(Z, func.ParameterNameAt(i)), |
| 2683 Type::ZoneHandle(Z, Type::DynamicType())); | 2684 Type::ZoneHandle(Z, Type::DynamicType())); |
| 2684 current_block_->scope->InsertParameterAt(i, param); | 2685 current_block_->scope->InsertParameterAt(i, param); |
| 2685 forwarding_args->Add(new LoadLocalNode(Scanner::kNoSourcePos, param)); | 2686 forwarding_args->Add(new LoadLocalNode(Scanner::kNoSourcePos, param)); |
| 2686 } | 2687 } |
| 2687 } | 2688 } |
| 2688 | 2689 |
| 2689 GenerateSuperConstructorCall(current_class(), | 2690 GenerateSuperConstructorCall( |
| 2690 Scanner::kNoSourcePos, | 2691 current_class(), |
| 2691 receiver, | 2692 Scanner::kNoSourcePos, |
| 2692 forwarding_args); | 2693 receiver, |
| 2694 new LoadLocalNode(Scanner::kNoSourcePos, phase_parameter), |
| 2695 forwarding_args); |
| 2693 CheckFieldsInitialized(current_class()); | 2696 CheckFieldsInitialized(current_class()); |
| 2694 | 2697 |
| 2695 // Empty constructor body. | 2698 // Empty constructor body. |
| 2696 current_block_->statements->Add(new ReturnNode(Scanner::kNoSourcePos)); | 2699 current_block_->statements->Add(new ReturnNode(Scanner::kNoSourcePos)); |
| 2697 SequenceNode* statements = CloseBlock(); | 2700 SequenceNode* statements = CloseBlock(); |
| 2698 return statements; | 2701 return statements; |
| 2699 } | 2702 } |
| 2700 | 2703 |
| 2701 | 2704 |
| 2702 void Parser::CheckRecursiveInvocation() { | 2705 void Parser::CheckRecursiveInvocation() { |
| (...skipping 10493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13196 void Parser::SkipQualIdent() { | 13199 void Parser::SkipQualIdent() { |
| 13197 ASSERT(IsIdentifier()); | 13200 ASSERT(IsIdentifier()); |
| 13198 ConsumeToken(); | 13201 ConsumeToken(); |
| 13199 if (CurrentToken() == Token::kPERIOD) { | 13202 if (CurrentToken() == Token::kPERIOD) { |
| 13200 ConsumeToken(); // Consume the kPERIOD token. | 13203 ConsumeToken(); // Consume the kPERIOD token. |
| 13201 ExpectIdentifier("identifier expected after '.'"); | 13204 ExpectIdentifier("identifier expected after '.'"); |
| 13202 } | 13205 } |
| 13203 } | 13206 } |
| 13204 | 13207 |
| 13205 } // namespace dart | 13208 } // namespace dart |
| OLD | NEW |