Commit 009e8b11 authored by marja's avatar marja Committed by Commit bot

[parser/test] Move cctest/PreParserScopeAnalysis into a new file.

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

Review-Url: https://codereview.chromium.org/2683573002
Cr-Commit-Position: refs/heads/master@{#42986}
parent 7d15175a
......@@ -92,12 +92,14 @@ v8_executable("cctest") {
"libplatform/test-tracing.cc",
"libsampler/test-sampler.cc",
"parsing/test-parse-decision.cc",
"parsing/test-preparser.cc",
"parsing/test-scanner-streams.cc",
"parsing/test-scanner.cc",
"print-extension.cc",
"print-extension.h",
"profiler-extension.cc",
"profiler-extension.h",
"scope-test-helper.h",
"test-access-checks.cc",
"test-accessor-assembler.cc",
"test-accessors.cc",
......@@ -184,6 +186,7 @@ v8_executable("cctest") {
"trace-extension.cc",
"trace-extension.h",
"types-fuzz.h",
"unicode-helpers.h",
"wasm/test-managed.cc",
"wasm/test-run-wasm-64.cc",
"wasm/test-run-wasm-asmjs.cc",
......
......@@ -113,12 +113,14 @@
'libplatform/test-tracing.cc',
'libsampler/test-sampler.cc',
'parsing/test-parse-decision.cc',
'parsing/test-preparser.cc',
'parsing/test-scanner-streams.cc',
'parsing/test-scanner.cc',
'print-extension.cc',
'print-extension.h',
'profiler-extension.cc',
'profiler-extension.h',
'scope-test-helper.h',
'test-access-checks.cc',
'test-accessor-assembler.cc',
'test-accessors.cc',
......@@ -205,6 +207,7 @@
'trace-extension.cc',
'trace-extension.h',
'types-fuzz.h',
'unicode-helpers.h',
'wasm/test-managed.cc',
'wasm/test-run-wasm.cc',
'wasm/test-run-wasm-64.cc',
......
This diff is collapsed.
// 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);
}
// True if the scope is and its entire subscope tree are hidden.
static bool ScopeTreeIsHidden(Scope* scope) {
if (!scope->is_hidden()) {
return false;
}
for (Scope* inner = scope->inner_scope(); inner != nullptr;
inner = inner->sibling()) {
if (!ScopeTreeIsHidden(inner)) {
return false;
}
}
return true;
}
static void CompareScopeToData(Scope* scope, const PreParsedScopeData* data,
size_t& index) {
CHECK_EQ(data->backing_store_[index++], scope->scope_type());
CHECK_EQ(data->backing_store_[index++], scope->start_position());
CHECK_EQ(data->backing_store_[index++], scope->end_position());
int inner_scope_count = 0;
for (Scope* inner = scope->inner_scope(); inner != nullptr;
inner = inner->sibling()) {
// FIXME(marja): This is probably not the right condition for knowing what
// scopes are present in the preparse data.
if (!ScopeTreeIsHidden(inner)) {
++inner_scope_count;
}
}
CHECK_EQ(data->backing_store_[index++], inner_scope_count);
int variable_count = 0;
for (Variable* local : scope->locals_) {
if (local->mode() == VAR || local->mode() == LET ||
local->mode() == CONST) {
++variable_count;
}
}
CHECK_EQ(data->backing_store_[index++], variable_count);
for (Variable* local : scope->locals_) {
if (local->mode() == VAR || local->mode() == LET ||
local->mode() == CONST) {
#ifdef DEBUG
const AstRawString* local_name = local->raw_name();
int name_length = data->backing_store_[index++];
CHECK_EQ(name_length, local_name->length());
for (int i = 0; i < name_length; ++i) {
CHECK_EQ(data->backing_store_[index++], local_name->raw_data()[i]);
}
#endif
CHECK_EQ(data->backing_store_[index++], local->location());
CHECK_EQ(data->backing_store_[index++], local->maybe_assigned());
}
}
for (Scope* inner = scope->inner_scope(); inner != nullptr;
inner = inner->sibling()) {
if (!ScopeTreeIsHidden(inner)) {
CompareScopeToData(inner, data, index);
}
}
}
};
} // namespace internal
} // namespace v8
#endif // V8_CCTEST_SCOPE_TEST_HELPER_H_
This diff is collapsed.
// 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_UNICODE_HELPERS_H_
#define V8_CCTEST_UNICODE_HELPERS_H_
#include "src/unicode.h"
static int Ucs2CharLength(unibrow::uchar c) {
if (c == unibrow::Utf8::kIncomplete || c == unibrow::Utf8::kBufferEmpty) {
return 0;
} else if (c < 0xffff) {
return 1;
} else {
return 2;
}
}
static int Utf8LengthHelper(const char* s) {
unibrow::Utf8::Utf8IncrementalBuffer buffer(unibrow::Utf8::kBufferEmpty);
int length = 0;
for (; *s != '\0'; s++) {
unibrow::uchar tmp = unibrow::Utf8::ValueOfIncremental(*s, &buffer);
length += Ucs2CharLength(tmp);
}
unibrow::uchar tmp = unibrow::Utf8::ValueOfIncrementalFinish(&buffer);
length += Ucs2CharLength(tmp);
return length;
}
#endif // V8_CCTEST_UNICODE_HELPERS_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment