blob: 68d69481d9c58e83dc7437920376d368709287d3 [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// 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
3// found in the LICENSE file.
4
5#ifndef V8_EXPRESSION_TYPE_COLLECTOR_MACROS_H_
6#define V8_EXPRESSION_TYPE_COLLECTOR_MACROS_H_
7
8#define CHECK_TYPES_BEGIN \
9 { \
10 size_t index = 0; \
11 int depth = 0;
12
13#define CHECK_TYPES_END \
14 CHECK_EQ(index, types.size()); \
15 }
16
17#ifdef DEBUG
18#define CHECK_TYPE(type) \
19 if (!types[index].bounds.Narrows(type)) { \
20 fprintf(stderr, "Expected:\n"); \
21 fprintf(stderr, " lower: "); \
22 type.lower->Print(); \
23 fprintf(stderr, " upper: "); \
24 type.upper->Print(); \
25 fprintf(stderr, "Actual:\n"); \
26 fprintf(stderr, " lower: "); \
27 types[index].bounds.lower->Print(); \
28 fprintf(stderr, " upper: "); \
29 types[index].bounds.upper->Print(); \
30 } \
31 CHECK(types[index].bounds.Narrows(type));
32#else
33#define CHECK_TYPE(type) CHECK(types[index].bounds.Narrows(type));
34#endif
35
36#define CHECK_EXPR(ekind, type) \
37 CHECK_LT(index, types.size()); \
38 CHECK(strcmp(#ekind, types[index].kind) == 0); \
39 CHECK_EQ(depth, types[index].depth); \
40 CHECK_TYPE(type); \
41 for (int j = (++depth, ++index, 0); j < 1 ? 1 : (--depth, 0); ++j)
42
43#define CHECK_VAR(vname, type) \
44 CHECK_EXPR(VariableProxy, type); \
45 CHECK_EQ(#vname, std::string(types[index - 1].name->raw_data(), \
46 types[index - 1].name->raw_data() + \
47 types[index - 1].name->byte_length()));
48
49#define CHECK_SKIP() \
50 { \
51 ++index; \
52 while (index < types.size() && types[index].depth > depth) { \
53 ++index; \
54 } \
55 }
56
57#endif // V8_EXPRESSION_TYPE_COLLECTOR_MACROS_H_