blob: f1289a77653ba74250371f78f36e7833028b0892 [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// 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 Murdochc5610432016-08-08 18:44:38 +01009#include "src/ast/ast-type-bounds.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010#include "src/ast/ast.h"
11#include "src/ast/scopes.h"
12#include "src/codegen.h"
13
14namespace v8 {
15namespace internal {
16namespace {
17
18struct {
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 Murdoch4a90d5f2016-03-22 12:00:34 +000031ExpressionTypeCollector::ExpressionTypeCollector(
Ben Murdochc5610432016-08-08 18:44:38 +010032 Isolate* isolate, FunctionLiteral* root, const AstTypeBounds* bounds,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000033 ZoneVector<ExpressionTypeEntry>* dst)
Ben Murdochc5610432016-08-08 18:44:38 +010034 : AstExpressionVisitor(isolate, root), bounds_(bounds), result_(dst) {}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000035
36void ExpressionTypeCollector::Run() {
37 result_->clear();
38 AstExpressionVisitor::Run();
39}
40
41
42void 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 Murdochc5610432016-08-08 18:44:38 +010049 e.bounds = bounds_->get(expression);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000050 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