summaryrefslogtreecommitdiff
path: root/deps/v8/src/torque/declarable.cc
blob: 6768da5474d3096231b3b50cb74bd34c06802a63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright 2018 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.

#include <fstream>
#include <iostream>

#include "src/torque/declarable.h"

namespace v8 {
namespace internal {
namespace torque {

std::ostream& operator<<(std::ostream& os, const Callable& m) {
  os << "callable " << m.name() << "(" << m.signature().parameter_types
     << "): " << *m.signature().return_type;
  return os;
}

std::ostream& operator<<(std::ostream& os, const Variable& v) {
  os << "variable " << v.name() << ": " << *v.type();
  return os;
}

std::ostream& operator<<(std::ostream& os, const Builtin& b) {
  os << "builtin " << *b.signature().return_type << " " << b.name()
     << b.signature().parameter_types;
  return os;
}

std::ostream& operator<<(std::ostream& os, const RuntimeFunction& b) {
  os << "runtime function " << *b.signature().return_type << " " << b.name()
     << b.signature().parameter_types;
  return os;
}

void PrintLabel(std::ostream& os, const Label& l, bool with_names) {
  os << l.name();
  if (l.GetParameterCount() != 0) {
    os << "(";
    if (with_names) {
      PrintCommaSeparatedList(os, l.GetParameters(),
                              [](Variable* v) -> std::string {
                                std::stringstream stream;
                                stream << v->name();
                                stream << ": ";
                                stream << *(v->type());
                                return stream.str();
                              });
    } else {
      PrintCommaSeparatedList(
          os, l.GetParameters(),
          [](Variable* v) -> const Type& { return *(v->type()); });
    }
    os << ")";
  }
}

std::ostream& operator<<(std::ostream& os, const Label& l) {
  PrintLabel(os, l, true);
  return os;
}

std::ostream& operator<<(std::ostream& os, const Generic& g) {
  os << "generic " << g.name() << "<";
  PrintCommaSeparatedList(os, g.declaration()->generic_parameters);
  os << ">";

  return os;
}

size_t Label::next_id_ = 0;

}  // namespace torque
}  // namespace internal
}  // namespace v8