Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 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 | #include "src/v8.h" |
| 6 | |
| 7 | #include "test/cctest/expression-type-collector.h" |
| 8 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 9 | #include "src/ast/ast-type-bounds.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10 | #include "src/ast/ast.h" |
| 11 | #include "src/ast/scopes.h" |
| 12 | #include "src/codegen.h" |
| 13 | |
| 14 | namespace v8 { |
| 15 | namespace internal { |
| 16 | namespace { |
| 17 | |
| 18 | struct { |
| 19 | AstNode::NodeType type; |
| 20 | const char* name; |
| 21 | } NodeTypeNameList[] = { |
| 22 | #define DECLARE_VISIT(type) \ |
| 23 | { AstNode::k##type, #type } \ |
| 24 | , |
| 25 | AST_NODE_LIST(DECLARE_VISIT) |
| 26 | #undef DECLARE_VISIT |
| 27 | }; |
| 28 | |
| 29 | } // namespace |
| 30 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 31 | ExpressionTypeCollector::ExpressionTypeCollector( |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 32 | Isolate* isolate, FunctionLiteral* root, const AstTypeBounds* bounds, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 33 | ZoneVector<ExpressionTypeEntry>* dst) |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 34 | : AstExpressionVisitor(isolate, root), bounds_(bounds), result_(dst) {} |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 35 | |
| 36 | void ExpressionTypeCollector::Run() { |
| 37 | result_->clear(); |
| 38 | AstExpressionVisitor::Run(); |
| 39 | } |
| 40 | |
| 41 | |
| 42 | void ExpressionTypeCollector::VisitExpression(Expression* expression) { |
| 43 | ExpressionTypeEntry e; |
| 44 | e.depth = depth(); |
| 45 | VariableProxy* proxy = expression->AsVariableProxy(); |
| 46 | if (proxy) { |
| 47 | e.name = proxy->raw_name(); |
| 48 | } |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 49 | e.bounds = bounds_->get(expression); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 50 | AstNode::NodeType type = expression->node_type(); |
| 51 | e.kind = "unknown"; |
| 52 | for (size_t i = 0; i < arraysize(NodeTypeNameList); ++i) { |
| 53 | if (NodeTypeNameList[i].type == type) { |
| 54 | e.kind = NodeTypeNameList[i].name; |
| 55 | break; |
| 56 | } |
| 57 | } |
| 58 | result_->push_back(e); |
| 59 | } |
| 60 | |
| 61 | } // namespace internal |
| 62 | } // namespace v8 |