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

Unified Diff: runtime/vm/parser.cc

Issue 1037183003: Add the implicit return in the correct sequence node (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/parser.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/parser.cc
===================================================================
--- runtime/vm/parser.cc (revision 44786)
+++ runtime/vm/parser.cc (working copy)
@@ -764,18 +764,6 @@
};
-static bool HasReturnNode(SequenceNode* seq) {
- if (seq->length() == 0) {
- return false;
- } else if ((seq->length()) == 1 &&
- (seq->NodeAt(seq->length() - 1)->IsSequenceNode())) {
- return HasReturnNode(seq->NodeAt(seq->length() - 1)->AsSequenceNode());
- } else {
- return seq->NodeAt(seq->length() - 1)->IsReturnNode();
- }
-}
-
-
void Parser::ParseClass(const Class& cls) {
if (!cls.is_synthesized_class()) {
Isolate* isolate = Isolate::Current();
@@ -906,16 +894,6 @@
UNREACHABLE();
}
- if (!HasReturnNode(node_sequence)) {
- // Add implicit return node. The implicit return value of synchronous
- // generator closures is false, to indicate that there are no more
- // elements in the iterable. In other cases the implicit return value
- // is null.
- AstNode* return_value = func.IsSyncGenClosure()
- ? new LiteralNode(func.end_token_pos(), Bool::False())
- : new LiteralNode(func.end_token_pos(), Instance::ZoneHandle());
- node_sequence->Add(new ReturnNode(func.end_token_pos(), return_value));
- }
if (parsed_function->has_expression_temp_var()) {
node_sequence->scope()->AddVariable(parsed_function->expression_temp_var());
}
@@ -3346,6 +3324,7 @@
} else if (func.IsAsyncGenClosure()) {
body = CloseAsyncGeneratorClosure(body);
}
+ EnsureHasReturnStatement(body, end_token_pos);
current_block_->statements->Add(body);
innermost_function_ = saved_innermost_function.raw();
last_used_try_index_ = saved_try_index;
@@ -6837,6 +6816,22 @@
}
+// Add a return node to the sequence if necessary.
+void Parser::EnsureHasReturnStatement(SequenceNode* seq, intptr_t return_pos) {
+ if ((seq->length() == 0) ||
+ !seq->NodeAt(seq->length() - 1)->IsReturnNode()) {
+ const Function& func = innermost_function();
+ // The implicit return value of synchronous generator closures is false,
+ // to indicate that there are no more elements in the iterable.
+ // In other cases the implicit return value is null.
+ AstNode* return_value = func.IsSyncGenClosure()
+ ? new LiteralNode(return_pos, Bool::False())
+ : new LiteralNode(return_pos, Instance::ZoneHandle());
+ seq->Add(new ReturnNode(return_pos, return_value));
+ }
+}
+
+
SequenceNode* Parser::CloseBlock() {
SequenceNode* statements = current_block_->statements;
if (current_block_->scope != NULL) {
« no previous file with comments | « runtime/vm/parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698