v8/test/cctest/scope-test-helper.h
Marja Hölttä f489f7ab44 [parser] Skipping inner funcs: collect data needed for allocation, not the allocation result.
This pretty much rewrites the preparsed scope data collection. We used to store
the allocation result, but it's faster to just store the raw data which is
needed for deciding it later. (This way we don't need to run the allocation
algorithm for just getting this data.)

For each variable: is_used, maybe_assigned,
has_forced_context_allocation, and for each scope:
inner_scope_calls_eval_.

In addition, this CL moves data handling out of Scope and into
PreParsedScopeData where it belongs and simplifies the API for
PreParsedScopeData.

BUG=v8:5516
R=vogelheim@chromium.org

Change-Id: Ia5a4fa52f585cd4f483ce9a92f2dd7d9754f34ed
Reviewed-on: https://chromium-review.googlesource.com/451273
Commit-Queue: Marja Hölttä <marja@chromium.org>
Reviewed-by: Daniel Vogelheim <vogelheim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#43641}
2017-03-07 14:23:14 +00:00

67 lines
2.3 KiB
C++

// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_CCTEST_SCOPE_TEST_HELPER_H_
#define V8_CCTEST_SCOPE_TEST_HELPER_H_
#include "src/ast/scopes.h"
#include "src/ast/variables.h"
namespace v8 {
namespace internal {
class ScopeTestHelper {
public:
static bool MustAllocateInContext(Variable* var) {
return var->scope()->MustAllocateInContext(var);
}
static void AllocateWithoutVariableResolution(Scope* scope) {
scope->AllocateVariablesRecursively();
}
static void CompareScopes(Scope* baseline, Scope* scope,
bool precise_maybe_assigned) {
if (!scope->is_hidden()) {
for (auto baseline_local = baseline->locals()->begin(),
scope_local = scope->locals()->begin();
baseline_local != baseline->locals()->end();
++baseline_local, ++scope_local) {
if (scope_local->mode() == VAR || scope_local->mode() == LET ||
scope_local->mode() == CONST) {
// Sanity check the variable name. If this fails, the variable order
// is not deterministic.
CHECK_EQ(scope_local->raw_name()->length(),
baseline_local->raw_name()->length());
for (int i = 0; i < scope_local->raw_name()->length(); ++i) {
CHECK_EQ(scope_local->raw_name()->raw_data()[i],
baseline_local->raw_name()->raw_data()[i]);
}
CHECK_EQ(scope_local->location(), baseline_local->location());
if (precise_maybe_assigned) {
CHECK_EQ(scope_local->maybe_assigned(),
baseline_local->maybe_assigned());
} else {
STATIC_ASSERT(kMaybeAssigned > kNotAssigned);
CHECK_GE(scope_local->maybe_assigned(),
baseline_local->maybe_assigned());
}
}
}
}
for (Scope *baseline_inner = baseline->inner_scope(),
*scope_inner = scope->inner_scope();
scope_inner != nullptr; scope_inner = scope_inner->sibling(),
baseline_inner = baseline_inner->sibling()) {
CompareScopes(baseline_inner, scope_inner, precise_maybe_assigned);
}
}
};
} // namespace internal
} // namespace v8
#endif // V8_CCTEST_SCOPE_TEST_HELPER_H_