| Index: test/cctest/test-ast-expression-visitor.cc
|
| diff --git a/test/cctest/test-ast-expression-visitor.cc b/test/cctest/test-ast-expression-visitor.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..62cb3ac3a6611d95dca8618bf146ee96d0dfc097
|
| --- /dev/null
|
| +++ b/test/cctest/test-ast-expression-visitor.cc
|
| @@ -0,0 +1,196 @@
|
| +// Copyright 2015 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.
|
| +
|
| +#include <stdlib.h>
|
| +
|
| +#include "src/v8.h"
|
| +
|
| +#include "src/ast.h"
|
| +#include "src/ast-expression-visitor.h"
|
| +#include "src/parser.h"
|
| +#include "src/rewriter.h"
|
| +#include "src/scopes.h"
|
| +#include "test/cctest/cctest.h"
|
| +#include "test/cctest/expression-type-collector.h"
|
| +
|
| +using namespace v8::internal;
|
| +
|
| +namespace {
|
| +
|
| +static std::string CollectTypes(const char* source) {
|
| + v8::V8::Initialize();
|
| + HandleAndZoneScope handles;
|
| +
|
| + i::Isolate* isolate = CcTest::i_isolate();
|
| + i::Factory* factory = isolate->factory();
|
| +
|
| + i::Handle<i::String> source_code =
|
| + factory->NewStringFromUtf8(i::CStrVector(source)).ToHandleChecked();
|
| +
|
| + i::Handle<i::Script> script = factory->NewScript(source_code);
|
| +
|
| + i::ParseInfo info(handles.main_zone(), script);
|
| + i::Parser parser(&info);
|
| + parser.set_allow_harmony_arrow_functions(true);
|
| + parser.set_allow_harmony_sloppy(true);
|
| + info.set_global();
|
| + info.set_lazy(false);
|
| + info.set_allow_lazy_parsing(false);
|
| + info.set_toplevel(true);
|
| +
|
| + i::CompilationInfo compilation_info(&info);
|
| + CHECK(i::Compiler::ParseAndAnalyze(&info));
|
| + info.set_literal(
|
| + info.scope()->declarations()->at(0)->AsFunctionDeclaration()->fun());
|
| +
|
| + return ExpressionTypeCollector::Run(&compilation_info);
|
| +}
|
| +}
|
| +
|
| +
|
| +TEST(VisitExpressions) {
|
| + const char test_function[] =
|
| + "function GeometricMean(stdlib, foreign, buffer) {\n"
|
| + " \"use asm\";\n"
|
| + "\n"
|
| + " var exp = stdlib.Math.exp;\n"
|
| + " var log = stdlib.Math.log;\n"
|
| + " var values = new stdlib.Float64Array(buffer);\n"
|
| + "\n"
|
| + " function logSum(start, end) {\n"
|
| + " start = start|0;\n"
|
| + " end = end|0;\n"
|
| + "\n"
|
| + " var sum = 0.0, p = 0, q = 0;\n"
|
| + "\n"
|
| + " // asm.js forces byte addressing of the heap by requiring shifting "
|
| + "by 3\n"
|
| + " for (p = start << 3, q = end << 3; (p|0) < (q|0); p = (p + 8)|0) {\n"
|
| + " sum = sum + +log(values[p>>3]);\n"
|
| + " }\n"
|
| + "\n"
|
| + " return +sum;\n"
|
| + " }\n"
|
| + "\n"
|
| + " function geometricMean(start, end) {\n"
|
| + " start = start|0;\n"
|
| + " end = end|0;\n"
|
| + "\n"
|
| + " return +exp(+logSum(start, end) / +((end - start)|0));\n"
|
| + " }\n"
|
| + "\n"
|
| + " return { geometricMean: geometricMean };\n"
|
| + "}\n";
|
| + const char test_expected[] =
|
| + "FunctionLiteral: Other\n"
|
| + " FunctionLiteral: Other\n"
|
| + " Assignment: Other\n"
|
| + " start: VariableProxy: Other\n"
|
| + " BinaryOperation: Other\n"
|
| + " start: VariableProxy: Other\n"
|
| + " Literal: Other\n"
|
| + " Assignment: Other\n"
|
| + " end: VariableProxy: Other\n"
|
| + " BinaryOperation: Other\n"
|
| + " end: VariableProxy: Other\n"
|
| + " Literal: Other\n"
|
| + " Assignment: Other\n"
|
| + " sum: VariableProxy: Other\n"
|
| + " Literal: Other\n"
|
| + " Assignment: Other\n"
|
| + " p: VariableProxy: Other\n"
|
| + " Literal: Other\n"
|
| + " Assignment: Other\n"
|
| + " q: VariableProxy: Other\n"
|
| + " Literal: Other\n"
|
| + " BinaryOperation: Other\n"
|
| + " Assignment: Other\n"
|
| + " p: VariableProxy: Other\n"
|
| + " BinaryOperation: Other\n"
|
| + " start: VariableProxy: Other\n"
|
| + " Literal: Other\n"
|
| + " Assignment: Other\n"
|
| + " q: VariableProxy: Other\n"
|
| + " BinaryOperation: Other\n"
|
| + " end: VariableProxy: Other\n"
|
| + " Literal: Other\n"
|
| + " CompareOperation: Other\n"
|
| + " BinaryOperation: Other\n"
|
| + " p: VariableProxy: Other\n"
|
| + " Literal: Other\n"
|
| + " BinaryOperation: Other\n"
|
| + " q: VariableProxy: Other\n"
|
| + " Literal: Other\n"
|
| + " Assignment: Other\n"
|
| + " p: VariableProxy: Other\n"
|
| + " BinaryOperation: Other\n"
|
| + " BinaryOperation: Other\n"
|
| + " p: VariableProxy: Other\n"
|
| + " Literal: Other\n"
|
| + " Literal: Other\n"
|
| + " Assignment: Other\n"
|
| + " sum: VariableProxy: Other\n"
|
| + " BinaryOperation: Other\n"
|
| + " sum: VariableProxy: Other\n"
|
| + " BinaryOperation: Other\n"
|
| + " Call: Other\n"
|
| + " log: VariableProxy: Other\n"
|
| + " values: VariableProxy: Other\n"
|
| + " BinaryOperation: Other\n"
|
| + " p: VariableProxy: Other\n"
|
| + " Literal: Other\n"
|
| + " Literal: Other\n"
|
| + " BinaryOperation: Other\n"
|
| + " sum: VariableProxy: Other\n"
|
| + " Literal: Other\n"
|
| + " FunctionLiteral: Other\n"
|
| + " Assignment: Other\n"
|
| + " start: VariableProxy: Other\n"
|
| + " BinaryOperation: Other\n"
|
| + " start: VariableProxy: Other\n"
|
| + " Literal: Other\n"
|
| + " Assignment: Other\n"
|
| + " end: VariableProxy: Other\n"
|
| + " BinaryOperation: Other\n"
|
| + " end: VariableProxy: Other\n"
|
| + " Literal: Other\n"
|
| + " BinaryOperation: Other\n"
|
| + " Call: Other\n"
|
| + " exp: VariableProxy: Other\n"
|
| + " BinaryOperation: Other\n"
|
| + " BinaryOperation: Other\n"
|
| + " Call: Other\n"
|
| + " logSum: VariableProxy: Other\n"
|
| + " start: VariableProxy: Other\n"
|
| + " end: VariableProxy: Other\n"
|
| + " Literal: Other\n"
|
| + " BinaryOperation: Other\n"
|
| + " BinaryOperation: Other\n"
|
| + " BinaryOperation: Other\n"
|
| + " end: VariableProxy: Other\n"
|
| + " start: VariableProxy: Other\n"
|
| + " Literal: Other\n"
|
| + " Literal: Other\n"
|
| + " Literal: Other\n"
|
| + " Literal: Other\n"
|
| + " Assignment: Other\n"
|
| + " exp: VariableProxy: Other\n"
|
| + " stdlib: VariableProxy: Other\n"
|
| + " Literal: Other\n"
|
| + " Literal: Other\n"
|
| + " Assignment: Other\n"
|
| + " log: VariableProxy: Other\n"
|
| + " stdlib: VariableProxy: Other\n"
|
| + " Literal: Other\n"
|
| + " Literal: Other\n"
|
| + " Assignment: Other\n"
|
| + " values: VariableProxy: Other\n"
|
| + " CallNew: Other\n"
|
| + " stdlib: VariableProxy: Other\n"
|
| + " Literal: Other\n"
|
| + " buffer: VariableProxy: Other\n"
|
| + " ObjectLiteral: Other\n"
|
| + " geometricMean: VariableProxy: Other\n";
|
| + CHECK_EQ(test_expected, CollectTypes(test_function));
|
| +}
|
|
|