summaryrefslogtreecommitdiff
path: root/tiger-compiler/tcsh/src/tiger_type.i
blob: 56798733c46b1c67c648aa3a0bc4554dfe28526a (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// -*- C++ -*-

%module tiger_type

%include "std_string.i"

%include "misc/singleton.hh"

%{
  #include "helper.hh"
  #include <type/libtype.hh>
  #include <misc/singleton.hh>

  #include <type/fwd.hh>
  #include <type/type.hh>
  #include <type/array.hh>
  #include <type/builtin-types.hh>
  #include <type/class.hh>
  #include <type/field.hh>
  #include <type/function.hh>
  #include <type/method.hh>
  #include <type/named.hh>
  #include <type/nil.hh>
  #include <type/record.hh>

  #include <type/visitor.hh>
  #include <type/pretty-printer.hh>
%}

%typemap(ret) type::Type* {
  $result = _get_swig_real_type_type(*$1);
}

%warnfilter(401);

%include "type/fwd.hh"
%include "type/type.hh"

%extend type::Type
{
  std::string __str__() const
  {
    std::ostringstream o;
    o << *$self;
    return o.str();
  }
}
%{
namespace {
  using namespace type;
  class SwigTypeVisitor : public ConstVisitor
  {
    public:
      PyObject *result;

#define STHELPER(TYPE) STCONVERT(TYPE, p_type__ ## TYPE)
    STHELPER(Array)
    STHELPER(Class)
    STHELPER(Function)
    STHELPER(Int)
    STHELPER(Method)
    STHELPER(Named)
    STHELPER(Nil)
    STHELPER(Record)
    STHELPER(String)
    STHELPER(Void)
#undef STHELPER
  };
} // namespace
%}
%inline %{
PyObject *_get_swig_real_type_type(const type::Type& e)
{
  SwigTypeVisitor stv;
  e.accept(stv);
  return stv.result;
}
%}


%include "type/array.hh"
%include "type/builtin-types.hh"
%include "type/class.hh"
%include "type/field.hh"
%include "type/function.hh"
%include "type/method.hh"
%include "type/named.hh"
%include "type/nil.hh"
%include "type/record.hh"

%include "type/libtype.hh"