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..663a0388411da09fe2a97270714054ad6a0f1283 |
--- /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. |
titzer
2015/08/21 12:05:51
Can we move the macros to the test file?
bradn
2015/08/21 21:37:08
As they're shared, moved them to a separate header
|
+// 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: |
+ ExpressionTypeCollector(CompilationInfo* info, |
+ ZoneVector<ExpressionTypeEntry>* dst); |
+ void Run(); |
+ |
+ protected: |
+ void VisitExpression(Expression* expression); |
+ |
+ private: |
+ ZoneVector<ExpressionTypeEntry>* result_; |
+}; |
+} |
+} // namespace v8::internal |
+ |
+#endif // V8_EXPRESSION_TYPE_COLLECTOR_H_ |