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