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

Side by Side Diff: test/cctest/test-typing-reset.cc

Issue 1319983004: Refactor type collector testing macros. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: merge Created 5 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdlib.h> 5 #include <stdlib.h>
6 6
7 #include "src/v8.h" 7 #include "src/v8.h"
8 8
9 #include "src/ast.h" 9 #include "src/ast.h"
10 #include "src/ast-expression-visitor.h" 10 #include "src/ast-expression-visitor.h"
11 #include "src/parser.h" 11 #include "src/parser.h"
12 #include "src/rewriter.h" 12 #include "src/rewriter.h"
13 #include "src/scopes.h" 13 #include "src/scopes.h"
14 #include "src/typing-reset.h" 14 #include "src/typing-reset.h"
15 #include "test/cctest/cctest.h" 15 #include "test/cctest/cctest.h"
16 #include "test/cctest/compiler/function-tester.h" 16 #include "test/cctest/compiler/function-tester.h"
17 #include "test/cctest/expression-type-collector.h" 17 #include "test/cctest/expression-type-collector.h"
18 #include "test/cctest/expression-type-collector-macros.h" 18 #include "test/cctest/expression-type-collector-macros.h"
19 19
20 #define INT32_TYPE Bounds(Type::Signed32(), Type::Signed32())
21
20 using namespace v8::internal; 22 using namespace v8::internal;
21 23
22 namespace { 24 namespace {
23 25
24 class TypeSetter : public AstExpressionVisitor { 26 class TypeSetter : public AstExpressionVisitor {
25 public: 27 public:
26 explicit TypeSetter(CompilationInfo* info) : AstExpressionVisitor(info) {} 28 explicit TypeSetter(CompilationInfo* info) : AstExpressionVisitor(info) {}
27 29
28 protected: 30 protected:
29 void VisitExpression(Expression* expression) { 31 void VisitExpression(Expression* expression) {
30 expression->set_bounds(Bounds(Type::Integral32())); 32 expression->set_bounds(INT32_TYPE);
31 } 33 }
32 }; 34 };
33 35
34 36
35 void CheckAllSame(ZoneVector<ExpressionTypeEntry>& types, 37 void CheckAllSame(ZoneVector<ExpressionTypeEntry>& types,
36 Bounds expected_type) { 38 Bounds expected_type) {
37 HandleAndZoneScope handles;
38 CHECK_TYPES_BEGIN { 39 CHECK_TYPES_BEGIN {
39 // function logSum 40 // function logSum
40 CHECK_EXPR(FunctionLiteral, expected_type) { 41 CHECK_EXPR(FunctionLiteral, expected_type) {
41 CHECK_EXPR(FunctionLiteral, expected_type) { 42 CHECK_EXPR(FunctionLiteral, expected_type) {
42 CHECK_EXPR(Assignment, expected_type) { 43 CHECK_EXPR(Assignment, expected_type) {
43 CHECK_VAR(start, expected_type); 44 CHECK_VAR(start, expected_type);
44 CHECK_EXPR(BinaryOperation, expected_type) { 45 CHECK_EXPR(BinaryOperation, expected_type) {
45 CHECK_VAR(start, expected_type); 46 CHECK_VAR(start, expected_type);
46 CHECK_EXPR(Literal, expected_type); 47 CHECK_EXPR(Literal, expected_type);
47 } 48 }
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 " end = end|0;\n" 250 " end = end|0;\n"
250 "\n" 251 "\n"
251 " return +exp(+logSum(start, end) / +((end - start)|0));\n" 252 " return +exp(+logSum(start, end) / +((end - start)|0));\n"
252 " }\n" 253 " }\n"
253 "\n" 254 "\n"
254 " return { geometricMean: geometricMean };\n" 255 " return { geometricMean: geometricMean };\n"
255 "}\n"; 256 "}\n";
256 257
257 v8::V8::Initialize(); 258 v8::V8::Initialize();
258 HandleAndZoneScope handles; 259 HandleAndZoneScope handles;
260 Zone* zone = handles.main_zone();
259 261
260 i::Isolate* isolate = CcTest::i_isolate(); 262 i::Isolate* isolate = CcTest::i_isolate();
261 i::Factory* factory = isolate->factory(); 263 i::Factory* factory = isolate->factory();
262 264
263 i::Handle<i::String> source_code = 265 i::Handle<i::String> source_code =
264 factory->NewStringFromUtf8(i::CStrVector(test_function)) 266 factory->NewStringFromUtf8(i::CStrVector(test_function))
265 .ToHandleChecked(); 267 .ToHandleChecked();
266 268
267 i::Handle<i::Script> script = factory->NewScript(source_code); 269 i::Handle<i::Script> script = factory->NewScript(source_code);
268 270
269 i::ParseInfo info(handles.main_zone(), script); 271 i::ParseInfo info(zone, script);
270 i::Parser parser(&info); 272 i::Parser parser(&info);
271 parser.set_allow_harmony_arrow_functions(true); 273 parser.set_allow_harmony_arrow_functions(true);
272 parser.set_allow_harmony_sloppy(true); 274 parser.set_allow_harmony_sloppy(true);
273 info.set_global(); 275 info.set_global();
274 info.set_lazy(false); 276 info.set_lazy(false);
275 info.set_allow_lazy_parsing(false); 277 info.set_allow_lazy_parsing(false);
276 info.set_toplevel(true); 278 info.set_toplevel(true);
277 279
278 i::CompilationInfo compilation_info(&info); 280 i::CompilationInfo compilation_info(&info);
279 CHECK(i::Compiler::ParseAndAnalyze(&info)); 281 CHECK(i::Compiler::ParseAndAnalyze(&info));
280 info.set_literal( 282 info.set_literal(
281 info.scope()->declarations()->at(0)->AsFunctionDeclaration()->fun()); 283 info.scope()->declarations()->at(0)->AsFunctionDeclaration()->fun());
282 284
283 // Core of the test. 285 // Core of the test.
284 ZoneVector<ExpressionTypeEntry> types(handles.main_zone()); 286 ZoneVector<ExpressionTypeEntry> types(zone);
285 ExpressionTypeCollector(&compilation_info, &types).Run(); 287 ExpressionTypeCollector(&compilation_info, &types).Run();
286 CheckAllSame(types, DEFAULT_TYPE); 288 CheckAllSame(types, DEFAULT_TYPE);
287 289
288 TypeSetter(&compilation_info).Run(); 290 TypeSetter(&compilation_info).Run();
289 291
290 ExpressionTypeCollector(&compilation_info, &types).Run(); 292 ExpressionTypeCollector(&compilation_info, &types).Run();
291 CheckAllSame(types, INT32_TYPE); 293 CheckAllSame(types, INT32_TYPE);
292 294
293 TypingReseter(&compilation_info).Run(); 295 TypingReseter(&compilation_info).Run();
294 296
295 ExpressionTypeCollector(&compilation_info, &types).Run(); 297 ExpressionTypeCollector(&compilation_info, &types).Run();
296 CheckAllSame(types, DEFAULT_TYPE); 298 CheckAllSame(types, DEFAULT_TYPE);
297 } 299 }
OLDNEW
« test/cctest/test-ast-expression-visitor.cc ('K') | « test/cctest/test-ast-expression-visitor.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698