Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef V8_EXPRESSION_TYPE_COLLECTOR_H_ | |
| 6 #define V8_EXPRESSION_TYPE_COLLECTOR_H_ | |
| 7 | |
| 8 #include "src/ast-expression-visitor.h" | |
| 9 | |
| 10 namespace v8 { | |
| 11 namespace internal { | |
| 12 | |
| 13 // 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
| |
| 14 // Assumes: | |
| 15 // * type walk result in "types" | |
| 16 // * HandlesAndZoneScope in "handles" | |
| 17 // | |
| 18 // Usage: | |
| 19 // CHECK_TYPES_BEGIN { | |
| 20 // CHECK_EXPR(Assignment, OTHER) { | |
| 21 // CHECK_VAR(a, OTHER); | |
| 22 // CHECK_VAR(b, OTHER); | |
| 23 // } | |
| 24 // } CHECK_TYPES_END | |
| 25 | |
| 26 #define CHECK_TYPES_BEGIN \ | |
| 27 { \ | |
| 28 size_t index = 0; \ | |
| 29 int depth = 0; | |
| 30 | |
| 31 #define CHECK_TYPES_END \ | |
| 32 CHECK_EQ(index, types.size()); \ | |
| 33 } | |
| 34 | |
| 35 #define DEFAULT_TYPE Bounds::Unbounded(handles.main_zone()) | |
| 36 #define INT32_TYPE \ | |
| 37 Bounds(Type::Signed32(handles.main_zone()), \ | |
| 38 Type::Signed32(handles.main_zone())) | |
| 39 | |
| 40 #define CHECK_EXPR(ekind, type) \ | |
| 41 CHECK_LT(index, types.size()); \ | |
| 42 CHECK(strcmp(#ekind, types[index].kind) == 0); \ | |
| 43 CHECK_EQ(depth, types[index].depth); \ | |
| 44 CHECK(type.lower->Is(types[index].bounds.lower)); \ | |
| 45 CHECK(type.upper->Is(types[index].bounds.upper)); \ | |
| 46 for (int j = (++depth, ++index, 0); j < 1 ? 1 : (--depth, 0); ++j) | |
| 47 | |
| 48 #define CHECK_VAR(vname, type) \ | |
| 49 CHECK_EXPR(VariableProxy, type); \ | |
| 50 CHECK_EQ(#vname, std::string(types[index - 1].name->raw_data(), \ | |
| 51 types[index - 1].name->raw_data() + \ | |
| 52 types[index - 1].name->byte_length())); | |
| 53 | |
| 54 // A Visitor over a CompilationInfo's AST that collects | |
| 55 // a human readable string summarizing structure and types. | |
| 56 // Used for testing of the typing information attached to the | |
| 57 // expression nodes of an AST. | |
| 58 | |
| 59 struct ExpressionTypeEntry { | |
| 60 int depth; | |
| 61 const char* kind; | |
| 62 const AstRawString* name; | |
| 63 Bounds bounds; | |
| 64 }; | |
| 65 | |
| 66 class ExpressionTypeCollector : public AstExpressionVisitor { | |
| 67 public: | |
| 68 static void Run(CompilationInfo* info, ZoneVector<ExpressionTypeEntry>* dst); | |
| 69 | |
| 70 protected: | |
| 71 void VisitExpression(Expression* expression); | |
| 72 | |
| 73 private: | |
| 74 explicit ExpressionTypeCollector(CompilationInfo* info); | |
| 75 | |
| 76 ZoneVector<ExpressionTypeEntry>* result_; | |
| 77 }; | |
| 78 } | |
| 79 } // namespace v8::internal | |
| 80 | |
| 81 #endif // V8_EXPRESSION_TYPE_COLLECTOR_H_ | |
| OLD | NEW |