| Index: test/cctest/test-typing-reset.cc
|
| diff --git a/test/cctest/test-typing-reset.cc b/test/cctest/test-typing-reset.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..683706d3386b557b187dea4a3bbb1a0d04936b6f
|
| --- /dev/null
|
| +++ b/test/cctest/test-typing-reset.cc
|
| @@ -0,0 +1,235 @@
|
| +// 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 "src/typing-reset.h"
|
| +#include "test/cctest/cctest.h"
|
| +#include "test/cctest/compiler/function-tester.h"
|
| +#include "test/cctest/expression-type-collector.h"
|
| +
|
| +using namespace v8::internal;
|
| +
|
| +namespace {
|
| +
|
| +class TypeSetter : public AstExpressionVisitor {
|
| + public:
|
| + static void Run(CompilationInfo* info) {
|
| + TypeSetter* visitor = new (info->zone()) TypeSetter(info);
|
| + visitor->VisitAll();
|
| + }
|
| +
|
| + protected:
|
| + void VisitExpression(Expression* expression) {
|
| + expression->set_bounds(Bounds(Type::Integral32()));
|
| + }
|
| +
|
| + private:
|
| + explicit TypeSetter(CompilationInfo* info) : AstExpressionVisitor(info) {}
|
| +};
|
| +
|
| +static void TypeCheckAndReset(const char* source, const char* expected_typed,
|
| + const char* expected_reset) {
|
| + 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());
|
| +
|
| + // Core of the test.
|
| + CHECK_EQ(expected_reset, ExpressionTypeCollector::Run(&compilation_info));
|
| + TypeSetter::Run(&compilation_info);
|
| + CHECK_EQ(expected_typed, ExpressionTypeCollector::Run(&compilation_info));
|
| + TypingReseter::Run(&compilation_info);
|
| + CHECK_EQ(expected_reset, ExpressionTypeCollector::Run(&compilation_info));
|
| +}
|
| +
|
| +std::string ReplaceAll(const std::string& s, const std::string& from,
|
| + const std::string& to) {
|
| + std::string ret = s;
|
| + size_t i = 0;
|
| + for (;;) {
|
| + i = ret.find(from, i);
|
| + if (i == std::string::npos) break;
|
| + ret.replace(i, from.length(), to);
|
| + i += to.length();
|
| + }
|
| + return ret;
|
| +}
|
| +}
|
| +
|
| +
|
| +TEST(ResetTypingInfo) {
|
| + 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 reset_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";
|
| + std::string typed_expected =
|
| + ReplaceAll(reset_expected, "Other", "Integral32");
|
| + TypeCheckAndReset(test_function, typed_expected.c_str(), reset_expected);
|
| +}
|
|
|