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

Unified Diff: src/parsing/parameter-initializer-rewriter.cc

Issue 1784893003: ParameterInitializerRewriter must maintain temporary variable order (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Nikolaos comments Created 4 years, 7 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 | « src/ast/scopes.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parsing/parameter-initializer-rewriter.cc
diff --git a/src/parsing/parameter-initializer-rewriter.cc b/src/parsing/parameter-initializer-rewriter.cc
index ed553a7e0b83b59f6dc2ee51e5555bae8749aed0..cbbf8deec7997c0f1bc5665c394c848ac3676baa 100644
--- a/src/parsing/parameter-initializer-rewriter.cc
+++ b/src/parsing/parameter-initializer-rewriter.cc
@@ -4,6 +4,10 @@
#include "src/parsing/parameter-initializer-rewriter.h"
+#include <algorithm>
+#include <utility>
+#include <vector>
+
#include "src/ast/ast.h"
#include "src/ast/ast-expression-visitor.h"
#include "src/ast/scopes.h"
@@ -21,6 +25,7 @@ class Rewriter final : public AstExpressionVisitor {
: AstExpressionVisitor(stack_limit, initializer),
old_scope_(old_scope),
new_scope_(new_scope) {}
+ ~Rewriter();
private:
void VisitExpression(Expression* expr) override {}
@@ -35,8 +40,26 @@ class Rewriter final : public AstExpressionVisitor {
Scope* old_scope_;
Scope* new_scope_;
+ std::vector<std::pair<Variable*, int>> temps_;
+};
+
+struct LessThanSecond {
+ bool operator()(const std::pair<Variable*, int>& left,
+ const std::pair<Variable*, int>& right) {
+ return left.second < right.second;
+ }
};
+Rewriter::~Rewriter() {
+ if (!temps_.empty()) {
+ // Ensure that we add temporaries in the order they appeared in old_scope_.
+ std::sort(temps_.begin(), temps_.end(), LessThanSecond());
+ for (auto var_and_index : temps_) {
+ var_and_index.first->set_scope(new_scope_);
+ new_scope_->AddTemporary(var_and_index.first);
+ }
+ }
+}
void Rewriter::VisitFunctionLiteral(FunctionLiteral* function_literal) {
function_literal->scope()->ReplaceOuterScope(new_scope_);
@@ -67,9 +90,9 @@ void Rewriter::VisitVariableProxy(VariableProxy* proxy) {
if (proxy->is_resolved()) {
Variable* var = proxy->var();
if (var->mode() != TEMPORARY) return;
- if (old_scope_->RemoveTemporary(var)) {
- var->set_scope(new_scope_);
- new_scope_->AddTemporary(var);
+ int index = old_scope_->RemoveTemporary(var);
+ if (index >= 0) {
+ temps_.push_back(std::make_pair(var, index));
}
} else if (old_scope_->RemoveUnresolved(proxy)) {
new_scope_->AddUnresolved(proxy);
« no previous file with comments | « src/ast/scopes.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698