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

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

Issue 910313002: Rename IsConstructor to IsGenerativeConstructor. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 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/object.cc ('k') | no next file » | 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 "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 2588 matching lines...) Expand 10 before | Expand all | Expand 10 after
2599 "invalid arguments passed to constructor '%s': %s", 2599 "invalid arguments passed to constructor '%s': %s",
2600 ctor_name.ToCString(), 2600 ctor_name.ToCString(),
2601 error_message.ToCString()); 2601 error_message.ToCString());
2602 } 2602 }
2603 current_block_->statements->Add( 2603 current_block_->statements->Add(
2604 new StaticCallNode(call_pos, redirect_ctor, arguments)); 2604 new StaticCallNode(call_pos, redirect_ctor, arguments));
2605 } 2605 }
2606 2606
2607 2607
2608 SequenceNode* Parser::MakeImplicitConstructor(const Function& func) { 2608 SequenceNode* Parser::MakeImplicitConstructor(const Function& func) {
2609 ASSERT(func.IsConstructor()); 2609 ASSERT(func.IsGenerativeConstructor());
2610 ASSERT(func.Owner() == current_class().raw()); 2610 ASSERT(func.Owner() == current_class().raw());
2611 const intptr_t ctor_pos = TokenPos(); 2611 const intptr_t ctor_pos = TokenPos();
2612 OpenFunctionBlock(func); 2612 OpenFunctionBlock(func);
2613 2613
2614 LocalVariable* receiver = new LocalVariable( 2614 LocalVariable* receiver = new LocalVariable(
2615 Scanner::kNoSourcePos, Symbols::This(), *ReceiverType(current_class())); 2615 Scanner::kNoSourcePos, Symbols::This(), *ReceiverType(current_class()));
2616 current_block_->scope->InsertParameterAt(0, receiver); 2616 current_block_->scope->InsertParameterAt(0, receiver);
2617 2617
2618 LocalVariable* phase_parameter = 2618 LocalVariable* phase_parameter =
2619 new LocalVariable(Scanner::kNoSourcePos, 2619 new LocalVariable(Scanner::kNoSourcePos,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
2700 pending_functions.Add(current_function()); 2700 pending_functions.Add(current_function());
2701 unregister_pending_function_ = true; 2701 unregister_pending_function_ = true;
2702 } 2702 }
2703 2703
2704 2704
2705 // Parser is at the opening parenthesis of the formal parameter declaration 2705 // Parser is at the opening parenthesis of the formal parameter declaration
2706 // of function. Parse the formal parameters, initializers and code. 2706 // of function. Parse the formal parameters, initializers and code.
2707 SequenceNode* Parser::ParseConstructor(const Function& func, 2707 SequenceNode* Parser::ParseConstructor(const Function& func,
2708 Array* default_parameter_values) { 2708 Array* default_parameter_values) {
2709 TRACE_PARSER("ParseConstructor"); 2709 TRACE_PARSER("ParseConstructor");
2710 ASSERT(func.IsConstructor()); 2710 ASSERT(func.IsGenerativeConstructor());
2711 ASSERT(!func.IsFactory()); 2711 ASSERT(!func.IsFactory());
2712 ASSERT(!func.is_static()); 2712 ASSERT(!func.is_static());
2713 ASSERT(!func.IsLocalFunction()); 2713 ASSERT(!func.IsLocalFunction());
2714 const Class& cls = Class::Handle(Z, func.Owner()); 2714 const Class& cls = Class::Handle(Z, func.Owner());
2715 ASSERT(!cls.IsNull()); 2715 ASSERT(!cls.IsNull());
2716 2716
2717 CheckRecursiveInvocation(); 2717 CheckRecursiveInvocation();
2718 2718
2719 if (func.IsImplicitConstructor()) { 2719 if (func.IsImplicitConstructor()) {
2720 // Special case: implicit constructor. 2720 // Special case: implicit constructor.
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
2874 // Look for the super initializer call in the sequence of initializer 2874 // Look for the super initializer call in the sequence of initializer
2875 // statements. If it exists and is not the last initializer statement, 2875 // statements. If it exists and is not the last initializer statement,
2876 // we need to create an implicit super call to the super constructor's 2876 // we need to create an implicit super call to the super constructor's
2877 // body. 2877 // body.
2878 // Thus, iterate over all but the last initializer to see whether 2878 // Thus, iterate over all but the last initializer to see whether
2879 // it's a super constructor call. 2879 // it's a super constructor call.
2880 for (int i = 0; i < init_statements->length() - 1; i++) { 2880 for (int i = 0; i < init_statements->length() - 1; i++) {
2881 if (init_statements->NodeAt(i)->IsStaticCallNode()) { 2881 if (init_statements->NodeAt(i)->IsStaticCallNode()) {
2882 StaticCallNode* static_call = 2882 StaticCallNode* static_call =
2883 init_statements->NodeAt(i)->AsStaticCallNode(); 2883 init_statements->NodeAt(i)->AsStaticCallNode();
2884 if (static_call->function().IsConstructor()) { 2884 if (static_call->function().IsGenerativeConstructor()) {
2885 super_call = static_call; 2885 super_call = static_call;
2886 break; 2886 break;
2887 } 2887 }
2888 } 2888 }
2889 } 2889 }
2890 if (super_call != NULL) { 2890 if (super_call != NULL) {
2891 // Generate an implicit call to the super constructor's body. 2891 // Generate an implicit call to the super constructor's body.
2892 // We need to patch the super _initializer_ call so that it 2892 // We need to patch the super _initializer_ call so that it
2893 // saves the evaluated actual arguments in temporary variables. 2893 // saves the evaluated actual arguments in temporary variables.
2894 // The temporary variables are necessary so that the argument 2894 // The temporary variables are necessary so that the argument
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
3027 3027
3028 // In case of nested async functions we also need to save the currently saved 3028 // In case of nested async functions we also need to save the currently saved
3029 // try context, the corresponding stack variable, and the scope where 3029 // try context, the corresponding stack variable, and the scope where
3030 // temporaries are added. 3030 // temporaries are added.
3031 LocalVariable* saved_saved_try_ctx = parsed_function()->saved_try_ctx(); 3031 LocalVariable* saved_saved_try_ctx = parsed_function()->saved_try_ctx();
3032 const String& saved_async_saved_try_ctx_name = 3032 const String& saved_async_saved_try_ctx_name =
3033 String::Handle(Z, parsed_function()->async_saved_try_ctx_name()); 3033 String::Handle(Z, parsed_function()->async_saved_try_ctx_name());
3034 parsed_function()->reset_saved_try_ctx_vars(); 3034 parsed_function()->reset_saved_try_ctx_vars();
3035 LocalScope* saved_async_temp_scope = async_temp_scope_; 3035 LocalScope* saved_async_temp_scope = async_temp_scope_;
3036 3036
3037 if (func.IsConstructor()) { 3037 if (func.IsGenerativeConstructor()) {
3038 SequenceNode* statements = ParseConstructor(func, default_parameter_values); 3038 SequenceNode* statements = ParseConstructor(func, default_parameter_values);
3039 innermost_function_ = saved_innermost_function.raw(); 3039 innermost_function_ = saved_innermost_function.raw();
3040 last_used_try_index_ = saved_try_index; 3040 last_used_try_index_ = saved_try_index;
3041 return statements; 3041 return statements;
3042 } 3042 }
3043 3043
3044 ASSERT(!func.IsConstructor()); 3044 ASSERT(!func.IsGenerativeConstructor());
3045 OpenFunctionBlock(func); // Build local scope for function. 3045 OpenFunctionBlock(func); // Build local scope for function.
3046 3046
3047 ParamList params; 3047 ParamList params;
3048 // An instance closure function may capture and access the receiver, but via 3048 // An instance closure function may capture and access the receiver, but via
3049 // the context and not via the first formal parameter. 3049 // the context and not via the first formal parameter.
3050 if (func.IsClosureFunction()) { 3050 if (func.IsClosureFunction()) {
3051 // The first parameter of a closure function is the closure object. 3051 // The first parameter of a closure function is the closure object.
3052 ASSERT(!func.is_const()); // Closure functions cannot be const. 3052 ASSERT(!func.is_const()); // Closure functions cannot be const.
3053 params.AddFinalParameter( 3053 params.AddFinalParameter(
3054 TokenPos(), 3054 TokenPos(),
(...skipping 5717 matching lines...) Expand 10 before | Expand all | Expand 10 after
8772 statement = ParseDoWhileStatement(label_name); 8772 statement = ParseDoWhileStatement(label_name);
8773 } else if (token == Token::kSWITCH) { 8773 } else if (token == Token::kSWITCH) {
8774 statement = ParseSwitchStatement(label_name); 8774 statement = ParseSwitchStatement(label_name);
8775 } else if (token == Token::kTRY) { 8775 } else if (token == Token::kTRY) {
8776 statement = ParseTryStatement(label_name); 8776 statement = ParseTryStatement(label_name);
8777 } else if (token == Token::kRETURN) { 8777 } else if (token == Token::kRETURN) {
8778 const intptr_t return_pos = TokenPos(); 8778 const intptr_t return_pos = TokenPos();
8779 ConsumeToken(); 8779 ConsumeToken();
8780 if (CurrentToken() != Token::kSEMICOLON) { 8780 if (CurrentToken() != Token::kSEMICOLON) {
8781 const intptr_t expr_pos = TokenPos(); 8781 const intptr_t expr_pos = TokenPos();
8782 if (current_function().IsConstructor() && 8782 if (current_function().IsGenerativeConstructor() &&
8783 (current_block_->scope->function_level() == 0)) { 8783 (current_block_->scope->function_level() == 0)) {
8784 ReportError(expr_pos, 8784 ReportError(expr_pos,
8785 "return of a value is not allowed in constructors"); 8785 "return of a value is not allowed in constructors");
8786 } else if (current_function().IsGenerator()) { 8786 } else if (current_function().IsGenerator()) {
8787 ReportError(expr_pos, "generator functions may not return a value"); 8787 ReportError(expr_pos, "generator functions may not return a value");
8788 } 8788 }
8789 AstNode* expr = ParseAwaitableExpr(kAllowConst, kConsumeCascades, NULL); 8789 AstNode* expr = ParseAwaitableExpr(kAllowConst, kConsumeCascades, NULL);
8790 statement = new(Z) ReturnNode(statement_pos, expr); 8790 statement = new(Z) ReturnNode(statement_pos, expr);
8791 } else { 8791 } else {
8792 if (current_function().IsSyncGenClosure() && 8792 if (current_function().IsSyncGenClosure() &&
(...skipping 3731 matching lines...) Expand 10 before | Expand all | Expand 10 after
12524 void Parser::SkipQualIdent() { 12524 void Parser::SkipQualIdent() {
12525 ASSERT(IsIdentifier()); 12525 ASSERT(IsIdentifier());
12526 ConsumeToken(); 12526 ConsumeToken();
12527 if (CurrentToken() == Token::kPERIOD) { 12527 if (CurrentToken() == Token::kPERIOD) {
12528 ConsumeToken(); // Consume the kPERIOD token. 12528 ConsumeToken(); // Consume the kPERIOD token.
12529 ExpectIdentifier("identifier expected after '.'"); 12529 ExpectIdentifier("identifier expected after '.'");
12530 } 12530 }
12531 } 12531 }
12532 12532
12533 } // namespace dart 12533 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698