aboutsummaryrefslogtreecommitdiff
path: root/Examples/test-suite/fragments.i
blob: e7bcae2a0b98e4775454a0a74d0126b0eeea36cf (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
%module fragments


%fragment("Hello","header") %{
/* hello!!! */
int foobar(int a)
{
  return a;
}  
%}

/*
 this fragment include the previous fragment if needed.
*/

%fragment("Hi","header",fragment="Hello") %{
/* hi!!! */
int bar(int a)
{
  return foobar(a);
}  
%}

%typemap(in,fragment="Hi") int hola "$1 = 123;"


%inline %{

int bar(int a);

int foo(int hola) 
{
  return bar(hola);
}

%}

/* Instantiate multiple fragments at once using fragments in comma separated list */
typedef int comma_frag3;

%fragment("comma_frag1","header", noblock=1) {
typedef int comma_frag1;
}

%fragment("comma_frag2","header", noblock=1, noblock=1) {
typedef comma_frag1 comma_frag2;
}

%fragment("comma_frag3","header",
          fragment="comma_frag1,comma_frag2")
%{typedef comma_frag2 comma_frag3;%}

%fragment("comma_frag3");
%inline %{
comma_frag3 my_comma_frag_int = 0;
%}


/* Instantiate multiple fragments at once using multiple keywords */
typedef int explicit_frag3;

%fragment("explicit_frag1","header", noblock=1) {
typedef int explicit_frag1;
}

%fragment("explicit_frag2","header", noblock=1) {
typedef explicit_frag1 explicit_frag2;
}

%fragment("explicit_frag3","header",
          fragment="explicit_frag1", fragment="explicit_frag2")
%{typedef explicit_frag2 explicit_frag3;%}

%fragment("explicit_frag3");
%inline %{
explicit_frag3 my_int = 0;
%}

/* Test typemap's ability to instantiate multiple fragments on demand */
typedef int int_infrag1;
typedef int int_infrag2;
typedef int int_outfrag1;
typedef int int_outfrag2;
typedef int int_outfrag3;

%fragment("infrag2","runtime") %{
typedef int_infrag1 int_infrag2;
%}

%fragment("infrag1","runtime") %{
typedef int int_infrag1;
%}
%fragment("infrag2","runtime") %{
__second_infrag2_fragment_is_ignored_this_will_not_compile_if_emitted_
typedef int_infrag1 int_infrag2;
%}

%fragment("outfrag1","runtime") %{
typedef int int_outfrag1;
%}
%fragment("outfrag2","runtime") %{
typedef int_outfrag1 int_outfrag2;
%}

%fragment("tcfrag1","runtime") %{
typedef int int_tcfrag1;
%}
%fragment("tcfrag2","runtime") %{
typedef int_tcfrag1 int_tcfrag2;
%}

%fragment("outspecial"{bool},"runtime") %{
typedef int int_outfrag3_temp;
%}
%fragment("outfrag3","runtime") %{
typedef int_outfrag3_temp int_outfrag3;
%}

%typemap(in, fragment="infrag1", fragment="infrag2") int_infrag2
%{$typemap(in,int)%}

%typemap(check, fragment="tcfrag1", noblock=1, fragment="tcfrag2") int_infrag2
{(void)sizeof(int_tcfrag2);}

%typemap(out, fragment="outfrag1", fragment="outfrag2", noblock=1) int_outfrag2
{$typemap(out,int)}

/* Test another permutation of keyword order */
%typemap(out, noblock=1, fragment="outfrag1", fragment="outfrag2") int_outfrag1
{$typemap(out,int)}

/* Test fragment specialization */
%typemap(out, noblock=1, fragment="outspecial"{bool}, fragment="outfrag3") int_outfrag3
{$typemap(out,int)}

%inline %{
int identity_in(int_infrag2 inp) { return inp; }
int_outfrag2 identity_out(int inp) { return inp; }
int_outfrag3 identity_out_2(int inp) { return inp; }
%}