Chromium Code Reviews| Index: test/cctest/expression-type-collector.h |
| diff --git a/test/cctest/expression-type-collector.h b/test/cctest/expression-type-collector.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cab55e8a7c3a06015cdb4046cf501a4e05afb748 |
| --- /dev/null |
| +++ b/test/cctest/expression-type-collector.h |
| @@ -0,0 +1,81 @@ |
| +// 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. |
| + |
| +#ifndef V8_EXPRESSION_TYPE_COLLECTOR_H_ |
| +#define V8_EXPRESSION_TYPE_COLLECTOR_H_ |
| + |
| +#include "src/ast-expression-visitor.h" |
| + |
| +namespace v8 { |
| +namespace internal { |
| + |
| +// Macros to define checking of a tree walk. |
|
rossberg
2015/08/20 16:34:27
That's some fancy macro fu there! :)
bradn
2015/08/20 21:35:47
Not sure whether that's a compliment of an insult
rossberg
2015/08/21 12:36:51
Can't make up my mind. :) I think it's fine and us
|
| +// Assumes: |
| +// * type walk result in "types" |
| +// * HandlesAndZoneScope in "handles" |
| +// |
| +// Usage: |
| +// CHECK_TYPES_BEGIN { |
| +// CHECK_EXPR(Assignment, OTHER) { |
| +// CHECK_VAR(a, OTHER); |
| +// CHECK_VAR(b, OTHER); |
| +// } |
| +// } CHECK_TYPES_END |
| + |
| +#define CHECK_TYPES_BEGIN \ |
| + { \ |
| + size_t index = 0; \ |
| + int depth = 0; |
| + |
| +#define CHECK_TYPES_END \ |
| + CHECK_EQ(index, types.size()); \ |
| + } |
| + |
| +#define DEFAULT_TYPE Bounds::Unbounded(handles.main_zone()) |
| +#define INT32_TYPE \ |
| + Bounds(Type::Signed32(handles.main_zone()), \ |
| + Type::Signed32(handles.main_zone())) |
| + |
| +#define CHECK_EXPR(ekind, type) \ |
| + CHECK_LT(index, types.size()); \ |
| + CHECK(strcmp(#ekind, types[index].kind) == 0); \ |
| + CHECK_EQ(depth, types[index].depth); \ |
| + CHECK(type.lower->Is(types[index].bounds.lower)); \ |
| + CHECK(type.upper->Is(types[index].bounds.upper)); \ |
| + for (int j = (++depth, ++index, 0); j < 1 ? 1 : (--depth, 0); ++j) |
| + |
| +#define CHECK_VAR(vname, type) \ |
| + CHECK_EXPR(VariableProxy, type); \ |
| + CHECK_EQ(#vname, std::string(types[index - 1].name->raw_data(), \ |
| + types[index - 1].name->raw_data() + \ |
| + types[index - 1].name->byte_length())); |
| + |
| +// A Visitor over a CompilationInfo's AST that collects |
| +// a human readable string summarizing structure and types. |
| +// Used for testing of the typing information attached to the |
| +// expression nodes of an AST. |
| + |
| +struct ExpressionTypeEntry { |
| + int depth; |
| + const char* kind; |
| + const AstRawString* name; |
| + Bounds bounds; |
| +}; |
| + |
| +class ExpressionTypeCollector : public AstExpressionVisitor { |
| + public: |
| + static void Run(CompilationInfo* info, ZoneVector<ExpressionTypeEntry>* dst); |
| + |
| + protected: |
| + void VisitExpression(Expression* expression); |
| + |
| + private: |
| + explicit ExpressionTypeCollector(CompilationInfo* info); |
| + |
| + ZoneVector<ExpressionTypeEntry>* result_; |
| +}; |
| +} |
| +} // namespace v8::internal |
| + |
| +#endif // V8_EXPRESSION_TYPE_COLLECTOR_H_ |