manual: CI check with nitunit
[nit.git] / benchmarks / languages / benches / bench_typetest_fts_nesting.nit
1 #!/usr/bin/env nit
2 # This file is part of NIT ( http://www.nitlanguage.org ).
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 import bench_base
17
18 class TypeTestFtsNestingGenerator
19 super Generator
20
21 fun clanit(i: Int): String
22 do
23 var s = new FlatBuffer
24 s.append("{classes[i]}[")
25 s.append("{classes.first}[" * (dept-1))
26 s.append("Root")
27 s.append("]" * dept)
28 return s.to_s
29 end
30
31 redef fun initnit(res)
32 do
33 for i in [0..dept[ do
34 res.add "new {clanit(i)}"
35 end
36
37 end
38
39 redef fun testnit
40 do
41 return "a isa {clanit(middle)}"
42 end
43
44 fun clajava(i: Int): String
45 do
46 var s = new FlatBuffer
47 s.append("{classes[i]}<")
48 s.append("{classes.first}<" * (dept-1))
49 s.append("Root")
50 s.append(">" * dept)
51 return s.to_s
52 end
53
54 redef fun initcsharp(res, interfaces)
55 do
56 var tagc = ""
57 if interfaces then tagc = "X"
58 for i in [0..dept[ do
59 res.add "new {tagc}{clajava(i)}()"
60 end
61 end
62
63 redef fun testcsharp(interfaces)
64 do
65 return "a is {clajava(middle)}"
66 end
67
68 fun clacpp(i: Int): String
69 do
70 var s = new FlatBuffer
71 s.append("{classes[i]}<")
72 s.append("{classes.first}<" * (dept-1))
73 s.append("Root")
74 s.append("*>" * dept)
75 return s.to_s
76 end
77
78 redef fun initcpp(res)
79 do
80 for i in [0..dept[ do
81 res.add "new {clacpp(i)}()"
82 end
83 end
84
85 redef fun testcpp
86 do
87 write "\t\t\t{clacpp(middle)} *to = dynamic_cast<{clacpp(middle)}*>(a);"
88 return "to != 0"
89 end
90
91 fun clae(i: Int): String
92 do
93 var s = new FlatBuffer
94 s.append("{classes[i]}[")
95 s.append("{classes.first}[" * (dept-1))
96 s.append("ROOT")
97 s.append("]" * dept)
98 return s.to_s
99 end
100
101 redef fun inite(res, se)
102 do
103 for i in [0..dept[ do
104 res.add "create \{{clae(i)}\}"
105 end
106 end
107
108 redef fun teste(se)
109 do
110 write "\t\t\t\t\tto ?= a"
111 return "to /= Void"
112 end
113
114 redef fun locale(se)
115 do
116 write "\t\t\tto: detachable {clae(middle)}"
117 end
118 end
119
120 var g = new TypeTestFtsNestingGenerator
121 g.genall