casty 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/CHANGELOG +50 -0
- data/Gemfile +2 -0
- data/LICENSE +22 -0
- data/README.markdown +1948 -0
- data/Rakefile +46 -0
- data/casty.gemspec +22 -0
- data/ext/casty/cast.c +6 -0
- data/ext/casty/cast.h +142 -0
- data/ext/casty/extconf.rb +7 -0
- data/ext/casty/parser.c +287 -0
- data/ext/casty/yylex.re +344 -0
- data/lib/casty.rb +5 -0
- data/lib/casty/c.y +911 -0
- data/lib/casty/c_nodes.rb +1096 -0
- data/lib/casty/inspect.rb +57 -0
- data/lib/casty/node.rb +741 -0
- data/lib/casty/node_list.rb +841 -0
- data/lib/casty/parse.rb +254 -0
- data/lib/casty/preprocessor.rb +92 -0
- data/lib/casty/tempfile.rb +33 -0
- data/lib/casty/to_s.rb +555 -0
- data/lib/casty/version.rb +11 -0
- data/test/all.rb +5 -0
- data/test/c_nodes_test.rb +224 -0
- data/test/lexer_test.rb +355 -0
- data/test/node_list_test.rb +2473 -0
- data/test/node_test.rb +1196 -0
- data/test/parse_test.rb +2066 -0
- data/test/parser_test.rb +3012 -0
- data/test/preprocessor_test.rb +95 -0
- data/test/render_test.rb +2086 -0
- data/test/test_helper.rb +195 -0
- metadata +127 -0
@@ -0,0 +1,95 @@
|
|
1
|
+
######################################################################
|
2
|
+
#
|
3
|
+
# Tests for the preprocessor.
|
4
|
+
#
|
5
|
+
######################################################################
|
6
|
+
|
7
|
+
require 'test_helper'
|
8
|
+
|
9
|
+
# publicize the private methods so we can test them easily
|
10
|
+
class C::Preprocessor
|
11
|
+
public :shellquote, :full_command
|
12
|
+
end
|
13
|
+
class PreprocessorTest < Test::Unit::TestCase
|
14
|
+
attr_accessor :cpp
|
15
|
+
def setup
|
16
|
+
@cpp = C::Preprocessor.new
|
17
|
+
@cpp.include_path << 'dir1' << 'dir 2'
|
18
|
+
@cpp.macros['V'] = nil
|
19
|
+
@cpp.macros['I'] = 5
|
20
|
+
@cpp.macros['S'] = '"blah"'
|
21
|
+
@cpp.macros['SWAP(a,b)'] = 'a ^= b ^= a ^= b'
|
22
|
+
FileUtils.rm_rf(TEST_DIR)
|
23
|
+
FileUtils.mkdir_p(TEST_DIR)
|
24
|
+
end
|
25
|
+
def teardown
|
26
|
+
FileUtils.rm_rf(TEST_DIR)
|
27
|
+
end
|
28
|
+
def test_shellquote
|
29
|
+
assert_equal('a', cpp.shellquote('a'))
|
30
|
+
assert_equal("'a b'", cpp.shellquote('a b'))
|
31
|
+
assert_equal("'a$b'", cpp.shellquote('a$b'))
|
32
|
+
assert_equal("'a\"b'", cpp.shellquote("a\"b"))
|
33
|
+
assert_equal("'\\'", cpp.shellquote("\\"))
|
34
|
+
assert_equal("\"a'b\"", cpp.shellquote("a'b"))
|
35
|
+
assert_equal("\"a\\\\\\$\\\"'\"", cpp.shellquote("a\\$\"'"))
|
36
|
+
end
|
37
|
+
def test_full_command
|
38
|
+
original_command = C::Preprocessor.command
|
39
|
+
C::Preprocessor.command = 'COMMAND'
|
40
|
+
assert_equal("COMMAND -Idir1 '-Idir 2' -DV -DI=5 '-DS=\"blah\"' '-DSWAP(a,b)=a ^= b ^= a ^= b' 'a file.c'",
|
41
|
+
cpp.full_command('a file.c'))
|
42
|
+
ensure
|
43
|
+
C::Preprocessor.command = original_command
|
44
|
+
end
|
45
|
+
def test_preprocess
|
46
|
+
output = cpp.preprocess("I S SWAP(x, y)")
|
47
|
+
assert_match(/5/, output)
|
48
|
+
assert_match(/"blah"/, output)
|
49
|
+
assert_match(/x \^= y \^= x \^= y/, output)
|
50
|
+
end
|
51
|
+
def test_preprocess_include
|
52
|
+
one_h = "#{TEST_DIR}/one.h"
|
53
|
+
two_h = "#{TEST_DIR}/foo/two.h"
|
54
|
+
File.open(one_h, 'w'){|f| f.puts "int one = 1;"}
|
55
|
+
FileUtils.mkdir(File.dirname(two_h))
|
56
|
+
File.open(two_h, 'w'){|f| f.puts "int two = 2;"}
|
57
|
+
output = nil
|
58
|
+
FileUtils.cd(TEST_DIR) do
|
59
|
+
output = cpp.preprocess(<<EOS)
|
60
|
+
#include "one.h"
|
61
|
+
#include "foo/two.h"
|
62
|
+
int three = 3;
|
63
|
+
EOS
|
64
|
+
end
|
65
|
+
assert_match(/int one = 1;/, output)
|
66
|
+
assert_match(/int two = 2;/, output)
|
67
|
+
assert_match(/int three = 3;/, output)
|
68
|
+
end
|
69
|
+
def test_preprocess_file
|
70
|
+
one_h = "#{TEST_DIR}/one.h"
|
71
|
+
two_h = "#{TEST_DIR}/foo/two.h"
|
72
|
+
main_c = "#{TEST_DIR}/main.c"
|
73
|
+
File.open(one_h, 'w'){|f| f.puts "int one = 1;"}
|
74
|
+
FileUtils.mkdir(File.dirname(two_h))
|
75
|
+
File.open(two_h, 'w'){|f| f.puts "int two = 2;"}
|
76
|
+
File.open(main_c, 'w'){|f| f.puts <<EOS}
|
77
|
+
#include "one.h"
|
78
|
+
#include "foo/two.h"
|
79
|
+
int three = 3;
|
80
|
+
EOS
|
81
|
+
output = cpp.preprocess_file(main_c)
|
82
|
+
assert_match(/int one = 1;/, output)
|
83
|
+
assert_match(/int two = 2;/, output)
|
84
|
+
assert_match(/int three = 3;/, output)
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_preprocess_imacros
|
88
|
+
File.open(macro_file = "#{TEST_DIR}/macro.h", 'w'){|f|
|
89
|
+
f.puts "#define some_macro macro_result\n"
|
90
|
+
}
|
91
|
+
@cpp.macros[:@imacros] = macro_file
|
92
|
+
output = cpp.preprocess("some_macro")
|
93
|
+
assert_match(/macro_result/, output)
|
94
|
+
end
|
95
|
+
end
|
data/test/render_test.rb
ADDED
@@ -0,0 +1,2086 @@
|
|
1
|
+
######################################################################
|
2
|
+
#
|
3
|
+
# Tests for the #render method of each Node.
|
4
|
+
#
|
5
|
+
######################################################################
|
6
|
+
|
7
|
+
require 'test_helper'
|
8
|
+
|
9
|
+
class RenderTest < Test::Unit::TestCase
|
10
|
+
def setup
|
11
|
+
@parser = C::Parser.new
|
12
|
+
@parser.type_names << 'T'
|
13
|
+
end
|
14
|
+
|
15
|
+
#
|
16
|
+
# Parse the given string and check that it renders to the same
|
17
|
+
# string.
|
18
|
+
#
|
19
|
+
def check(klass, expected)
|
20
|
+
expected = expected.chomp.gsub(/^ *\|/, '')
|
21
|
+
node = klass.parse(expected, @parser)
|
22
|
+
assert_equal(expected, node.to_s)
|
23
|
+
end
|
24
|
+
|
25
|
+
# ------------------------------------------------------------------
|
26
|
+
# TranslationUnit
|
27
|
+
# ------------------------------------------------------------------
|
28
|
+
|
29
|
+
def test_translation_unit
|
30
|
+
check(C::TranslationUnit, <<-EOS)
|
31
|
+
|int i;
|
32
|
+
|
|
33
|
+
|int j;
|
34
|
+
|
|
35
|
+
|int f() {
|
36
|
+
|}
|
37
|
+
|
|
38
|
+
|int g() {
|
39
|
+
|}
|
40
|
+
EOS
|
41
|
+
end
|
42
|
+
|
43
|
+
# ------------------------------------------------------------------
|
44
|
+
# Declaration
|
45
|
+
# ------------------------------------------------------------------
|
46
|
+
|
47
|
+
def test_declaration
|
48
|
+
check(C::Declaration, <<-EOS)
|
49
|
+
|void f();
|
50
|
+
EOS
|
51
|
+
end
|
52
|
+
def test_declaration_with_specifier
|
53
|
+
check(C::Declaration, <<-EOS)
|
54
|
+
|inline void f();
|
55
|
+
EOS
|
56
|
+
end
|
57
|
+
def test_declaration_with_storage
|
58
|
+
check(C::Declaration, <<-EOS)
|
59
|
+
|static void f();
|
60
|
+
EOS
|
61
|
+
end
|
62
|
+
def test_declaration_static_with_all
|
63
|
+
check(C::Declaration, <<-EOS)
|
64
|
+
|inline static void f();
|
65
|
+
EOS
|
66
|
+
end
|
67
|
+
|
68
|
+
# ------------------------------------------------------------------
|
69
|
+
# Declarator
|
70
|
+
# ------------------------------------------------------------------
|
71
|
+
|
72
|
+
def test_declarator
|
73
|
+
check(C::Declarator, <<-EOS)
|
74
|
+
|i
|
75
|
+
EOS
|
76
|
+
end
|
77
|
+
def test_declarator_with_indirect_type
|
78
|
+
check(C::Declarator, <<-EOS)
|
79
|
+
|*i
|
80
|
+
EOS
|
81
|
+
end
|
82
|
+
def test_declarator_with_init
|
83
|
+
check(C::Declarator, <<-EOS)
|
84
|
+
|i = 1
|
85
|
+
EOS
|
86
|
+
end
|
87
|
+
def test_declarator_with_num_bits
|
88
|
+
check(C::Declarator, <<-EOS)
|
89
|
+
|i : 1
|
90
|
+
EOS
|
91
|
+
end
|
92
|
+
|
93
|
+
# ------------------------------------------------------------------
|
94
|
+
# FunctionDef
|
95
|
+
# ------------------------------------------------------------------
|
96
|
+
|
97
|
+
def test_function_def
|
98
|
+
check(C::FunctionDef, <<-EOS)
|
99
|
+
|void f() {
|
100
|
+
|}
|
101
|
+
EOS
|
102
|
+
end
|
103
|
+
def test_function_def_with_storage
|
104
|
+
check(C::FunctionDef, <<-EOS)
|
105
|
+
|static void f() {
|
106
|
+
|}
|
107
|
+
EOS
|
108
|
+
end
|
109
|
+
def test_function_def_with_inline
|
110
|
+
check(C::FunctionDef, <<-EOS)
|
111
|
+
|inline void f() {
|
112
|
+
|}
|
113
|
+
EOS
|
114
|
+
end
|
115
|
+
def test_function_def_with_no_prototype
|
116
|
+
check(C::FunctionDef, <<-EOS)
|
117
|
+
|static inline void f(i)
|
118
|
+
| int i;
|
119
|
+
|{
|
120
|
+
|}
|
121
|
+
EOS
|
122
|
+
end
|
123
|
+
def test_function_def_with_indirect_return_type
|
124
|
+
check(C::FunctionDef, <<-EOS)
|
125
|
+
|static inline void *f(int *i) {
|
126
|
+
|}
|
127
|
+
EOS
|
128
|
+
end
|
129
|
+
def test_function_def_with_all
|
130
|
+
check(C::FunctionDef, <<-EOS)
|
131
|
+
|static inline void *f(i)
|
132
|
+
| int *i;
|
133
|
+
|{
|
134
|
+
|}
|
135
|
+
EOS
|
136
|
+
end
|
137
|
+
|
138
|
+
# ------------------------------------------------------------------
|
139
|
+
# Parameter
|
140
|
+
# ------------------------------------------------------------------
|
141
|
+
|
142
|
+
def test_parameter
|
143
|
+
check(C::Parameter, <<-EOS)
|
144
|
+
|int i
|
145
|
+
EOS
|
146
|
+
end
|
147
|
+
def test_parameter_with_indirect_type
|
148
|
+
check(C::Parameter, <<-EOS)
|
149
|
+
|int i
|
150
|
+
EOS
|
151
|
+
end
|
152
|
+
def test_parameter_with_no_type
|
153
|
+
check(C::Parameter, <<-EOS)
|
154
|
+
|i
|
155
|
+
EOS
|
156
|
+
end
|
157
|
+
def test_parameter_with_no_name
|
158
|
+
check(C::Parameter, <<-EOS)
|
159
|
+
|int
|
160
|
+
EOS
|
161
|
+
end
|
162
|
+
def test_parameter_with_storage
|
163
|
+
check(C::Parameter, <<-EOS)
|
164
|
+
|register int
|
165
|
+
EOS
|
166
|
+
end
|
167
|
+
|
168
|
+
# ------------------------------------------------------------------
|
169
|
+
# Enumerator
|
170
|
+
# ------------------------------------------------------------------
|
171
|
+
|
172
|
+
def test_enumerator
|
173
|
+
check(C::Enumerator, <<-EOS)
|
174
|
+
|i
|
175
|
+
EOS
|
176
|
+
end
|
177
|
+
def test_enumerator_with_val
|
178
|
+
check(C::Enumerator, <<-EOS)
|
179
|
+
|i = 1
|
180
|
+
EOS
|
181
|
+
end
|
182
|
+
|
183
|
+
# ------------------------------------------------------------------
|
184
|
+
# Member
|
185
|
+
# ------------------------------------------------------------------
|
186
|
+
|
187
|
+
def test_member_init_member
|
188
|
+
check(C::MemberInit, <<-EOS)
|
189
|
+
|.foo = 1
|
190
|
+
EOS
|
191
|
+
end
|
192
|
+
def test_member_init_index
|
193
|
+
check(C::MemberInit, <<-EOS)
|
194
|
+
|[0] = 1
|
195
|
+
EOS
|
196
|
+
end
|
197
|
+
def test_member_init_multi
|
198
|
+
check(C::MemberInit, <<-EOS)
|
199
|
+
|.foo [0] = 1
|
200
|
+
EOS
|
201
|
+
end
|
202
|
+
def test_member
|
203
|
+
check(C::Member, <<-EOS)
|
204
|
+
|foo
|
205
|
+
EOS
|
206
|
+
end
|
207
|
+
|
208
|
+
# ------------------------------------------------------------------
|
209
|
+
# Block
|
210
|
+
# ------------------------------------------------------------------
|
211
|
+
|
212
|
+
# TODO: don't indent unlabelled statements, and have a block
|
213
|
+
# unindent labelled statements
|
214
|
+
def test_block_empty
|
215
|
+
check(C::Block, <<-EOS)
|
216
|
+
| {
|
217
|
+
| }
|
218
|
+
EOS
|
219
|
+
end
|
220
|
+
def test_block_with_statements
|
221
|
+
check(C::Block, <<-EOS)
|
222
|
+
| {
|
223
|
+
| ;
|
224
|
+
| }
|
225
|
+
EOS
|
226
|
+
end
|
227
|
+
def test_block_with_declarations
|
228
|
+
check(C::Block, <<-EOS)
|
229
|
+
| {
|
230
|
+
| int i;
|
231
|
+
| }
|
232
|
+
EOS
|
233
|
+
end
|
234
|
+
def test_block_with_labelled_statements
|
235
|
+
check(C::Block, <<-EOS)
|
236
|
+
| {
|
237
|
+
| one:
|
238
|
+
| ;
|
239
|
+
| }
|
240
|
+
EOS
|
241
|
+
end
|
242
|
+
def test_block_with_labelled_blocks
|
243
|
+
check(C::Block, <<-EOS)
|
244
|
+
| {
|
245
|
+
| one:
|
246
|
+
| {
|
247
|
+
| }
|
248
|
+
| }
|
249
|
+
EOS
|
250
|
+
end
|
251
|
+
def test_block_labelled
|
252
|
+
check(C::Block, <<-EOS)
|
253
|
+
|one:
|
254
|
+
|two:
|
255
|
+
| {
|
256
|
+
| }
|
257
|
+
EOS
|
258
|
+
end
|
259
|
+
|
260
|
+
# ------------------------------------------------------------------
|
261
|
+
# If
|
262
|
+
# ------------------------------------------------------------------
|
263
|
+
|
264
|
+
def test_if_then_with_statements
|
265
|
+
check(C::If, <<-EOS)
|
266
|
+
| if (cond)
|
267
|
+
| ;
|
268
|
+
EOS
|
269
|
+
end
|
270
|
+
def test_if_then_else_with_statements
|
271
|
+
check(C::If, <<-EOS)
|
272
|
+
| if (cond)
|
273
|
+
| ;
|
274
|
+
| else
|
275
|
+
| ;
|
276
|
+
EOS
|
277
|
+
end
|
278
|
+
def test_if_then_elsif_then_with_statements
|
279
|
+
# TODO: handle else-if towers
|
280
|
+
check(C::If, <<-EOS)
|
281
|
+
| if (cond)
|
282
|
+
| ;
|
283
|
+
| else
|
284
|
+
| if (cond)
|
285
|
+
| ;
|
286
|
+
| else
|
287
|
+
| ;
|
288
|
+
EOS
|
289
|
+
end
|
290
|
+
def test_if_with_labelled_statements
|
291
|
+
check(C::If, <<-EOS)
|
292
|
+
| if (cond)
|
293
|
+
| one:
|
294
|
+
| ;
|
295
|
+
| else
|
296
|
+
| if (cond)
|
297
|
+
| two:
|
298
|
+
| ;
|
299
|
+
| else
|
300
|
+
| three:
|
301
|
+
| ;
|
302
|
+
EOS
|
303
|
+
end
|
304
|
+
def test_if_then_with_blocks
|
305
|
+
check(C::If, <<-EOS)
|
306
|
+
| if (cond) {
|
307
|
+
| }
|
308
|
+
EOS
|
309
|
+
end
|
310
|
+
def test_if_then_else_with_blocks
|
311
|
+
check(C::If, <<-EOS)
|
312
|
+
| if (cond) {
|
313
|
+
| } else {
|
314
|
+
| }
|
315
|
+
EOS
|
316
|
+
end
|
317
|
+
def test_if_then_elsif_then_with_blocks
|
318
|
+
# TODO: handle else-if towers
|
319
|
+
check(C::If, <<-EOS)
|
320
|
+
| if (cond) {
|
321
|
+
| } else
|
322
|
+
| if (cond) {
|
323
|
+
| } else {
|
324
|
+
| }
|
325
|
+
EOS
|
326
|
+
end
|
327
|
+
def test_if_with_labelled_blocks
|
328
|
+
check(C::If, <<-EOS)
|
329
|
+
| if (cond)
|
330
|
+
| one:
|
331
|
+
| {
|
332
|
+
| }
|
333
|
+
| else
|
334
|
+
| if (cond)
|
335
|
+
| two:
|
336
|
+
| {
|
337
|
+
| }
|
338
|
+
| else
|
339
|
+
| three:
|
340
|
+
| {
|
341
|
+
| }
|
342
|
+
EOS
|
343
|
+
end
|
344
|
+
def test_if_labelled
|
345
|
+
check(C::If, <<-EOS)
|
346
|
+
|one:
|
347
|
+
|two:
|
348
|
+
| if (cond)
|
349
|
+
| ;
|
350
|
+
EOS
|
351
|
+
end
|
352
|
+
|
353
|
+
# ------------------------------------------------------------------
|
354
|
+
# Switch
|
355
|
+
# ------------------------------------------------------------------
|
356
|
+
|
357
|
+
def test_switch_with_statement
|
358
|
+
check(C::Switch, <<-EOS)
|
359
|
+
| switch (cond)
|
360
|
+
| ;
|
361
|
+
EOS
|
362
|
+
end
|
363
|
+
def test_switch_with_block
|
364
|
+
check(C::Switch, <<-EOS)
|
365
|
+
| switch (cond) {
|
366
|
+
| }
|
367
|
+
EOS
|
368
|
+
end
|
369
|
+
def test_switch_with_labelled_statement
|
370
|
+
check(C::Switch, <<-EOS)
|
371
|
+
| switch (cond)
|
372
|
+
| one:
|
373
|
+
| ;
|
374
|
+
EOS
|
375
|
+
end
|
376
|
+
def test_switch_with_labelled_block
|
377
|
+
check(C::Switch, <<-EOS)
|
378
|
+
| switch (cond)
|
379
|
+
| one:
|
380
|
+
| {
|
381
|
+
| }
|
382
|
+
EOS
|
383
|
+
end
|
384
|
+
def test_switch_labelled
|
385
|
+
check(C::Switch, <<-EOS)
|
386
|
+
|one:
|
387
|
+
|two:
|
388
|
+
| switch (cond) {
|
389
|
+
| }
|
390
|
+
EOS
|
391
|
+
end
|
392
|
+
|
393
|
+
# ------------------------------------------------------------------
|
394
|
+
# While
|
395
|
+
# ------------------------------------------------------------------
|
396
|
+
|
397
|
+
def test_while_with_statement
|
398
|
+
check(C::While, <<-EOS)
|
399
|
+
| while (cond)
|
400
|
+
| ;
|
401
|
+
EOS
|
402
|
+
end
|
403
|
+
def test_while_with_block
|
404
|
+
check(C::While, <<-EOS)
|
405
|
+
| while (cond) {
|
406
|
+
| }
|
407
|
+
EOS
|
408
|
+
end
|
409
|
+
def test_while_with_labelled_statement
|
410
|
+
check(C::While, <<-EOS)
|
411
|
+
| while (cond)
|
412
|
+
| one:
|
413
|
+
| ;
|
414
|
+
EOS
|
415
|
+
end
|
416
|
+
def test_while_with_labelled_block
|
417
|
+
check(C::While, <<-EOS)
|
418
|
+
| while (cond)
|
419
|
+
| one:
|
420
|
+
| {
|
421
|
+
| }
|
422
|
+
EOS
|
423
|
+
end
|
424
|
+
def test_while_labelled
|
425
|
+
check(C::While, <<-EOS)
|
426
|
+
|one:
|
427
|
+
| while (cond)
|
428
|
+
| ;
|
429
|
+
EOS
|
430
|
+
end
|
431
|
+
def test_do_while_with_statement
|
432
|
+
check(C::While, <<-EOS)
|
433
|
+
| do
|
434
|
+
| ;
|
435
|
+
| while (cond);
|
436
|
+
EOS
|
437
|
+
end
|
438
|
+
def test_do_while_with_block
|
439
|
+
check(C::While, <<-EOS)
|
440
|
+
| do {
|
441
|
+
| } while (cond);
|
442
|
+
EOS
|
443
|
+
end
|
444
|
+
def test_do_while_with_labelled_statement
|
445
|
+
check(C::While, <<-EOS)
|
446
|
+
| do
|
447
|
+
| one:
|
448
|
+
| ;
|
449
|
+
| while (cond);
|
450
|
+
EOS
|
451
|
+
end
|
452
|
+
def test_do_while_with_labelled_block
|
453
|
+
check(C::While, <<-EOS)
|
454
|
+
| do
|
455
|
+
| one:
|
456
|
+
| {
|
457
|
+
| }
|
458
|
+
| while (cond);
|
459
|
+
EOS
|
460
|
+
end
|
461
|
+
def test_do_while_labelled
|
462
|
+
check(C::While, <<-EOS)
|
463
|
+
|one:
|
464
|
+
| do
|
465
|
+
| ;
|
466
|
+
| while (cond);
|
467
|
+
EOS
|
468
|
+
end
|
469
|
+
|
470
|
+
# ------------------------------------------------------------------
|
471
|
+
# For
|
472
|
+
# ------------------------------------------------------------------
|
473
|
+
|
474
|
+
def test_for_with_no_header_elements
|
475
|
+
check(C::For, <<-EOS)
|
476
|
+
| for (;;)
|
477
|
+
| ;
|
478
|
+
EOS
|
479
|
+
end
|
480
|
+
def test_for_with_init_expression
|
481
|
+
check(C::For, <<-EOS)
|
482
|
+
| for (i = 0;;)
|
483
|
+
| ;
|
484
|
+
EOS
|
485
|
+
end
|
486
|
+
def test_for_with_init_declaration
|
487
|
+
check(C::For, <<-EOS)
|
488
|
+
| for (int i = 0;;)
|
489
|
+
| ;
|
490
|
+
EOS
|
491
|
+
end
|
492
|
+
def test_for_with_cond
|
493
|
+
check(C::For, <<-EOS)
|
494
|
+
| for (; i < 10;)
|
495
|
+
| ;
|
496
|
+
EOS
|
497
|
+
end
|
498
|
+
def test_for_with_iter
|
499
|
+
check(C::For, <<-EOS)
|
500
|
+
| for (;; ++i)
|
501
|
+
| ;
|
502
|
+
EOS
|
503
|
+
end
|
504
|
+
def test_for_with_all_header_elements
|
505
|
+
check(C::For, <<-EOS)
|
506
|
+
| for (i = 0; i < 10; ++i)
|
507
|
+
| ;
|
508
|
+
EOS
|
509
|
+
end
|
510
|
+
def test_for_with_block
|
511
|
+
check(C::For, <<-EOS)
|
512
|
+
| for (;;) {
|
513
|
+
| }
|
514
|
+
EOS
|
515
|
+
end
|
516
|
+
def test_for_with_labelled_statement
|
517
|
+
check(C::For, <<-EOS)
|
518
|
+
| for (;;)
|
519
|
+
| one:
|
520
|
+
| ;
|
521
|
+
EOS
|
522
|
+
end
|
523
|
+
def test_for_with_labelled_block
|
524
|
+
check(C::For, <<-EOS)
|
525
|
+
| for (;;)
|
526
|
+
| one:
|
527
|
+
| {
|
528
|
+
| }
|
529
|
+
EOS
|
530
|
+
end
|
531
|
+
def test_for_labelled
|
532
|
+
check(C::For, <<-EOS)
|
533
|
+
|one:
|
534
|
+
| for (;;)
|
535
|
+
| ;
|
536
|
+
EOS
|
537
|
+
end
|
538
|
+
|
539
|
+
# ------------------------------------------------------------------
|
540
|
+
# Goto
|
541
|
+
# ------------------------------------------------------------------
|
542
|
+
|
543
|
+
def test_goto
|
544
|
+
check(C::Goto, <<-EOS)
|
545
|
+
| goto one;
|
546
|
+
EOS
|
547
|
+
end
|
548
|
+
def test_goto_labelled
|
549
|
+
check(C::Goto, <<-EOS)
|
550
|
+
|one:
|
551
|
+
| goto two;
|
552
|
+
EOS
|
553
|
+
end
|
554
|
+
|
555
|
+
# ------------------------------------------------------------------
|
556
|
+
# Continue
|
557
|
+
# ------------------------------------------------------------------
|
558
|
+
|
559
|
+
def test_continue
|
560
|
+
check(C::Continue, <<-EOS)
|
561
|
+
| continue;
|
562
|
+
EOS
|
563
|
+
end
|
564
|
+
def test_continue_labelled
|
565
|
+
check(C::Continue, <<-EOS)
|
566
|
+
|one:
|
567
|
+
| continue;
|
568
|
+
EOS
|
569
|
+
end
|
570
|
+
|
571
|
+
# ------------------------------------------------------------------
|
572
|
+
# Break
|
573
|
+
# ------------------------------------------------------------------
|
574
|
+
|
575
|
+
def test_break
|
576
|
+
check(C::Break, <<-EOS)
|
577
|
+
| break;
|
578
|
+
EOS
|
579
|
+
end
|
580
|
+
def test_break_labelled
|
581
|
+
check(C::Break, <<-EOS)
|
582
|
+
|one:
|
583
|
+
| break;
|
584
|
+
EOS
|
585
|
+
end
|
586
|
+
|
587
|
+
# ------------------------------------------------------------------
|
588
|
+
# Return
|
589
|
+
# ------------------------------------------------------------------
|
590
|
+
|
591
|
+
def test_return_with_expression
|
592
|
+
check(C::Return, <<-EOS)
|
593
|
+
| return 0;
|
594
|
+
EOS
|
595
|
+
end
|
596
|
+
def test_return_with_no_expression
|
597
|
+
check(C::Return, <<-EOS)
|
598
|
+
| return;
|
599
|
+
EOS
|
600
|
+
end
|
601
|
+
def test_return_labelled
|
602
|
+
check(C::Return, <<-EOS)
|
603
|
+
|one:
|
604
|
+
| return 0;
|
605
|
+
EOS
|
606
|
+
end
|
607
|
+
|
608
|
+
# ------------------------------------------------------------------
|
609
|
+
# ExpressionStatement
|
610
|
+
# ------------------------------------------------------------------
|
611
|
+
|
612
|
+
def test_expression_statement
|
613
|
+
check(C::ExpressionStatement, <<-EOS)
|
614
|
+
| ;
|
615
|
+
EOS
|
616
|
+
end
|
617
|
+
def test_expression_statement_with_expression
|
618
|
+
check(C::ExpressionStatement, <<-EOS)
|
619
|
+
| 1;
|
620
|
+
EOS
|
621
|
+
end
|
622
|
+
def test_expression_statement_labelled
|
623
|
+
check(C::ExpressionStatement, <<-EOS)
|
624
|
+
|one:
|
625
|
+
| 1;
|
626
|
+
EOS
|
627
|
+
end
|
628
|
+
|
629
|
+
# ------------------------------------------------------------------
|
630
|
+
# PlainLabel
|
631
|
+
# ------------------------------------------------------------------
|
632
|
+
|
633
|
+
def test_plain_label
|
634
|
+
check(C::PlainLabel, <<-EOS)
|
635
|
+
|one:
|
636
|
+
EOS
|
637
|
+
end
|
638
|
+
|
639
|
+
# ------------------------------------------------------------------
|
640
|
+
# Default
|
641
|
+
# ------------------------------------------------------------------
|
642
|
+
|
643
|
+
def test_default
|
644
|
+
check(C::Default, <<-EOS)
|
645
|
+
|default:
|
646
|
+
EOS
|
647
|
+
end
|
648
|
+
|
649
|
+
# ------------------------------------------------------------------
|
650
|
+
# TestCase
|
651
|
+
# ------------------------------------------------------------------
|
652
|
+
|
653
|
+
def test_case
|
654
|
+
check(C::Case, <<-EOS)
|
655
|
+
|case 1:
|
656
|
+
EOS
|
657
|
+
end
|
658
|
+
|
659
|
+
# ------------------------------------------------------------------
|
660
|
+
# Comma
|
661
|
+
# ------------------------------------------------------------------
|
662
|
+
|
663
|
+
def test_comma_two_expressions
|
664
|
+
check(C::Comma, <<-EOS)
|
665
|
+
|1, 2
|
666
|
+
EOS
|
667
|
+
end
|
668
|
+
def test_comma_three_expressions
|
669
|
+
check(C::Comma, <<-EOS)
|
670
|
+
|1, 2, 3
|
671
|
+
EOS
|
672
|
+
end
|
673
|
+
|
674
|
+
# ------------------------------------------------------------------
|
675
|
+
# Conditional
|
676
|
+
# ------------------------------------------------------------------
|
677
|
+
|
678
|
+
def test_conditional
|
679
|
+
check(C::Conditional, <<-EOS)
|
680
|
+
|a ? b : c
|
681
|
+
EOS
|
682
|
+
end
|
683
|
+
def test_conditional_precedences
|
684
|
+
check(C::Or, <<-EOS)
|
685
|
+
|a || (b ? c || d : e && f)
|
686
|
+
EOS
|
687
|
+
end
|
688
|
+
def test_conditional_nested
|
689
|
+
# TODO: handle else-if towers
|
690
|
+
check(C::Conditional, <<-EOS)
|
691
|
+
|(a ? b : c) ? (d ? e : f) : (g ? h : i)
|
692
|
+
EOS
|
693
|
+
end
|
694
|
+
|
695
|
+
# ------------------------------------------------------------------
|
696
|
+
# Variable
|
697
|
+
# ------------------------------------------------------------------
|
698
|
+
|
699
|
+
def test_variable
|
700
|
+
check(C::Variable, <<-EOS)
|
701
|
+
|x
|
702
|
+
EOS
|
703
|
+
end
|
704
|
+
|
705
|
+
# ------------------------------------------------------------------
|
706
|
+
# BlockExpression
|
707
|
+
# ------------------------------------------------------------------
|
708
|
+
|
709
|
+
def test_block_expression
|
710
|
+
@parser.enable_block_expressions
|
711
|
+
check(C::BlockExpression, <<-EOS)
|
712
|
+
|({
|
713
|
+
| ;
|
714
|
+
|})
|
715
|
+
EOS
|
716
|
+
end
|
717
|
+
|
718
|
+
# ------------------------------------------------------------------
|
719
|
+
# Index
|
720
|
+
# ------------------------------------------------------------------
|
721
|
+
|
722
|
+
def test_index
|
723
|
+
check(C::Index, <<-EOS)
|
724
|
+
|a[0]
|
725
|
+
EOS
|
726
|
+
end
|
727
|
+
def test_index_precedences
|
728
|
+
check(C::Index, <<-EOS)
|
729
|
+
|(*a)[*a]
|
730
|
+
EOS
|
731
|
+
end
|
732
|
+
def test_index_nested
|
733
|
+
check(C::Index, <<-EOS)
|
734
|
+
|a[a[0]][0]
|
735
|
+
EOS
|
736
|
+
end
|
737
|
+
|
738
|
+
# ------------------------------------------------------------------
|
739
|
+
# Call
|
740
|
+
# ------------------------------------------------------------------
|
741
|
+
|
742
|
+
def test_call
|
743
|
+
check(C::Call, <<-EOS)
|
744
|
+
|a()
|
745
|
+
EOS
|
746
|
+
end
|
747
|
+
def test_call_with_args
|
748
|
+
check(C::Call, <<-EOS)
|
749
|
+
|a(1, (2, 3))
|
750
|
+
EOS
|
751
|
+
end
|
752
|
+
def test_call_precedences
|
753
|
+
check(C::Call, <<-EOS)
|
754
|
+
|(*a)(*a)
|
755
|
+
EOS
|
756
|
+
end
|
757
|
+
def test_call_nested
|
758
|
+
check(C::Call, <<-EOS)
|
759
|
+
|(*a())(a())
|
760
|
+
EOS
|
761
|
+
end
|
762
|
+
|
763
|
+
# ------------------------------------------------------------------
|
764
|
+
# Dot
|
765
|
+
# ------------------------------------------------------------------
|
766
|
+
|
767
|
+
def test_dot
|
768
|
+
check(C::Dot, <<-EOS)
|
769
|
+
|a.b
|
770
|
+
EOS
|
771
|
+
end
|
772
|
+
def test_dot_precendences
|
773
|
+
check(C::Dot, <<-EOS)
|
774
|
+
|(a ? b : c).d
|
775
|
+
EOS
|
776
|
+
end
|
777
|
+
def test_dot_nested
|
778
|
+
check(C::Dot, <<-EOS)
|
779
|
+
|a.b.c
|
780
|
+
EOS
|
781
|
+
end
|
782
|
+
|
783
|
+
# ------------------------------------------------------------------
|
784
|
+
# Arrow
|
785
|
+
# ------------------------------------------------------------------
|
786
|
+
|
787
|
+
def test_arrow
|
788
|
+
check(C::Arrow, <<-EOS)
|
789
|
+
|a->b
|
790
|
+
EOS
|
791
|
+
end
|
792
|
+
def test_arrow_precedences
|
793
|
+
check(C::Arrow, <<-EOS)
|
794
|
+
|(a ? b : c)->d
|
795
|
+
EOS
|
796
|
+
end
|
797
|
+
def test_arrow_nested
|
798
|
+
check(C::Arrow, <<-EOS)
|
799
|
+
|a->b->c
|
800
|
+
EOS
|
801
|
+
end
|
802
|
+
|
803
|
+
# ------------------------------------------------------------------
|
804
|
+
# PostInc
|
805
|
+
# ------------------------------------------------------------------
|
806
|
+
|
807
|
+
def test_post_inc
|
808
|
+
check(C::PostInc, <<-EOS)
|
809
|
+
|a++
|
810
|
+
EOS
|
811
|
+
end
|
812
|
+
def test_post_inc_precedences
|
813
|
+
check(C::PostInc, <<-EOS)
|
814
|
+
|(a++ ? b++ : c++)++
|
815
|
+
EOS
|
816
|
+
end
|
817
|
+
def test_post_inc_nested
|
818
|
+
check(C::PostInc, <<-EOS)
|
819
|
+
|a++++
|
820
|
+
EOS
|
821
|
+
end
|
822
|
+
|
823
|
+
# ------------------------------------------------------------------
|
824
|
+
# PostDec
|
825
|
+
# ------------------------------------------------------------------
|
826
|
+
|
827
|
+
def test_post_dec
|
828
|
+
check(C::PostDec, <<-EOS)
|
829
|
+
|a--
|
830
|
+
EOS
|
831
|
+
end
|
832
|
+
def test_post_dec_precedences
|
833
|
+
check(C::PostDec, <<-EOS)
|
834
|
+
|(a-- ? b-- : c--)--
|
835
|
+
EOS
|
836
|
+
end
|
837
|
+
def test_post_dec_nested
|
838
|
+
check(C::PostDec, <<-EOS)
|
839
|
+
|a----
|
840
|
+
EOS
|
841
|
+
end
|
842
|
+
|
843
|
+
# ------------------------------------------------------------------
|
844
|
+
# Cast
|
845
|
+
# ------------------------------------------------------------------
|
846
|
+
|
847
|
+
def test_cast
|
848
|
+
check(C::Cast, <<-EOS)
|
849
|
+
|(int)a
|
850
|
+
EOS
|
851
|
+
end
|
852
|
+
def test_cast_precedences
|
853
|
+
check(C::Cast, <<-EOS)
|
854
|
+
|(int)((int)a + (int)b)
|
855
|
+
EOS
|
856
|
+
end
|
857
|
+
def test_cast_nested
|
858
|
+
check(C::Cast, <<-EOS)
|
859
|
+
|(int)(int)a
|
860
|
+
EOS
|
861
|
+
end
|
862
|
+
|
863
|
+
# ------------------------------------------------------------------
|
864
|
+
# Address
|
865
|
+
# ------------------------------------------------------------------
|
866
|
+
|
867
|
+
def test_address
|
868
|
+
check(C::Address, <<-EOS)
|
869
|
+
|&a
|
870
|
+
EOS
|
871
|
+
end
|
872
|
+
def test_address_precedences
|
873
|
+
check(C::Address, <<-EOS)
|
874
|
+
|&(a + 1)
|
875
|
+
EOS
|
876
|
+
end
|
877
|
+
def test_address_nested
|
878
|
+
check(C::Address, <<-EOS)
|
879
|
+
|& &a
|
880
|
+
EOS
|
881
|
+
end
|
882
|
+
|
883
|
+
# ------------------------------------------------------------------
|
884
|
+
# Dereference
|
885
|
+
# ------------------------------------------------------------------
|
886
|
+
|
887
|
+
def test_dereference
|
888
|
+
check(C::Dereference, <<-EOS)
|
889
|
+
|*a
|
890
|
+
EOS
|
891
|
+
end
|
892
|
+
def test_dereference_precedences
|
893
|
+
check(C::Dereference, <<-EOS)
|
894
|
+
|*(a + 1)
|
895
|
+
EOS
|
896
|
+
end
|
897
|
+
def test_dereference_nested
|
898
|
+
check(C::Dereference, <<-EOS)
|
899
|
+
|**a
|
900
|
+
EOS
|
901
|
+
end
|
902
|
+
|
903
|
+
# ------------------------------------------------------------------
|
904
|
+
# Sizeof
|
905
|
+
# ------------------------------------------------------------------
|
906
|
+
|
907
|
+
def test_sizeof
|
908
|
+
check(C::Sizeof, <<-EOS)
|
909
|
+
|sizeof(a)
|
910
|
+
EOS
|
911
|
+
end
|
912
|
+
def test_sizeof_precedences
|
913
|
+
check(C::Index, <<-EOS)
|
914
|
+
|(sizeof(a + 1))[b]
|
915
|
+
EOS
|
916
|
+
end
|
917
|
+
def test_sizeof_nested
|
918
|
+
check(C::Sizeof, <<-EOS)
|
919
|
+
|sizeof(sizeof(a))
|
920
|
+
EOS
|
921
|
+
end
|
922
|
+
|
923
|
+
# ------------------------------------------------------------------
|
924
|
+
# Positive
|
925
|
+
# ------------------------------------------------------------------
|
926
|
+
|
927
|
+
def test_positive
|
928
|
+
check(C::Positive, <<-EOS)
|
929
|
+
|+a
|
930
|
+
EOS
|
931
|
+
end
|
932
|
+
def test_positive_precedences
|
933
|
+
check(C::Add, <<-EOS)
|
934
|
+
|a + +(+a + +b)
|
935
|
+
EOS
|
936
|
+
end
|
937
|
+
def test_positive_nested
|
938
|
+
check(C::Positive, <<-EOS)
|
939
|
+
|+ +a
|
940
|
+
EOS
|
941
|
+
end
|
942
|
+
|
943
|
+
# ------------------------------------------------------------------
|
944
|
+
# Negative
|
945
|
+
# ------------------------------------------------------------------
|
946
|
+
|
947
|
+
def test_negative
|
948
|
+
check(C::Negative, <<-EOS)
|
949
|
+
|-a
|
950
|
+
EOS
|
951
|
+
end
|
952
|
+
def test_negative_precedences
|
953
|
+
check(C::Subtract, <<-EOS)
|
954
|
+
|a - -(-a - -b)
|
955
|
+
EOS
|
956
|
+
end
|
957
|
+
def test_negative_nested
|
958
|
+
check(C::Negative, <<-EOS)
|
959
|
+
|- -a
|
960
|
+
EOS
|
961
|
+
end
|
962
|
+
|
963
|
+
# ------------------------------------------------------------------
|
964
|
+
# PreInc
|
965
|
+
# ------------------------------------------------------------------
|
966
|
+
|
967
|
+
def test_pre_inc
|
968
|
+
check(C::PreInc, <<-EOS)
|
969
|
+
|++a
|
970
|
+
EOS
|
971
|
+
end
|
972
|
+
def test_pre_inc_precedences
|
973
|
+
check(C::Add, <<-EOS)
|
974
|
+
|++a + ++(++b + ++c)
|
975
|
+
EOS
|
976
|
+
end
|
977
|
+
def test_pre_inc_nested
|
978
|
+
check(C::PreInc, <<-EOS)
|
979
|
+
|++++a
|
980
|
+
EOS
|
981
|
+
end
|
982
|
+
|
983
|
+
# ------------------------------------------------------------------
|
984
|
+
# PreDec
|
985
|
+
# ------------------------------------------------------------------
|
986
|
+
|
987
|
+
def test_pre_dec
|
988
|
+
check(C::PreDec, <<-EOS)
|
989
|
+
|--a
|
990
|
+
EOS
|
991
|
+
end
|
992
|
+
def test_pre_dec_precedences
|
993
|
+
check(C::Subtract, <<-EOS)
|
994
|
+
|--a - --(--b - --c)
|
995
|
+
EOS
|
996
|
+
end
|
997
|
+
def test_pre_dec_nested
|
998
|
+
check(C::PreDec, <<-EOS)
|
999
|
+
|----a
|
1000
|
+
EOS
|
1001
|
+
end
|
1002
|
+
|
1003
|
+
# ------------------------------------------------------------------
|
1004
|
+
# BitNot
|
1005
|
+
# ------------------------------------------------------------------
|
1006
|
+
|
1007
|
+
def test_bit_not
|
1008
|
+
check(C::BitNot, <<-EOS)
|
1009
|
+
|~a
|
1010
|
+
EOS
|
1011
|
+
end
|
1012
|
+
def test_bit_not_precedences
|
1013
|
+
check(C::Equal, <<-EOS)
|
1014
|
+
|~a == (~b | ~c)
|
1015
|
+
EOS
|
1016
|
+
end
|
1017
|
+
def test_bit_not_nested
|
1018
|
+
check(C::BitNot, <<-EOS)
|
1019
|
+
|~~a
|
1020
|
+
EOS
|
1021
|
+
end
|
1022
|
+
|
1023
|
+
# ------------------------------------------------------------------
|
1024
|
+
# Not
|
1025
|
+
# ------------------------------------------------------------------
|
1026
|
+
|
1027
|
+
def test_not
|
1028
|
+
check(C::Not, <<-EOS)
|
1029
|
+
|!a
|
1030
|
+
EOS
|
1031
|
+
end
|
1032
|
+
def test_not_precedences
|
1033
|
+
check(C::Equal, <<-EOS)
|
1034
|
+
|!a == !(!b || !c)
|
1035
|
+
EOS
|
1036
|
+
end
|
1037
|
+
def test_not_nested
|
1038
|
+
check(C::Not, <<-EOS)
|
1039
|
+
|!!a
|
1040
|
+
EOS
|
1041
|
+
end
|
1042
|
+
|
1043
|
+
# ------------------------------------------------------------------
|
1044
|
+
# Add
|
1045
|
+
# ------------------------------------------------------------------
|
1046
|
+
|
1047
|
+
def test_add
|
1048
|
+
check(C::Add, <<-EOS)
|
1049
|
+
|a + b
|
1050
|
+
EOS
|
1051
|
+
end
|
1052
|
+
def test_add_precedences
|
1053
|
+
check(C::Add, <<-EOS)
|
1054
|
+
|a * b + (c == d)
|
1055
|
+
EOS
|
1056
|
+
end
|
1057
|
+
def test_add_nested
|
1058
|
+
check(C::Add, <<-EOS)
|
1059
|
+
|a + b + (c + d)
|
1060
|
+
EOS
|
1061
|
+
end
|
1062
|
+
|
1063
|
+
# ------------------------------------------------------------------
|
1064
|
+
# Subtract
|
1065
|
+
# ------------------------------------------------------------------
|
1066
|
+
|
1067
|
+
def test_subtract
|
1068
|
+
check(C::Subtract, <<-EOS)
|
1069
|
+
|a - b
|
1070
|
+
EOS
|
1071
|
+
end
|
1072
|
+
def test_subtract_precedences
|
1073
|
+
check(C::Subtract, <<-EOS)
|
1074
|
+
|a * b - (c == d)
|
1075
|
+
EOS
|
1076
|
+
end
|
1077
|
+
def test_subtract_nested
|
1078
|
+
check(C::Subtract, <<-EOS)
|
1079
|
+
|a - b - (c - d)
|
1080
|
+
EOS
|
1081
|
+
end
|
1082
|
+
|
1083
|
+
# ------------------------------------------------------------------
|
1084
|
+
# Multiply
|
1085
|
+
# ------------------------------------------------------------------
|
1086
|
+
|
1087
|
+
def test_multiply
|
1088
|
+
check(C::Multiply, <<-EOS)
|
1089
|
+
|a * b
|
1090
|
+
EOS
|
1091
|
+
end
|
1092
|
+
def test_multiply_precedences
|
1093
|
+
check(C::Multiply, <<-EOS)
|
1094
|
+
|*a * (b + c)
|
1095
|
+
EOS
|
1096
|
+
end
|
1097
|
+
def test_multiply_nested
|
1098
|
+
check(C::Multiply, <<-EOS)
|
1099
|
+
|a * b * (c * d)
|
1100
|
+
EOS
|
1101
|
+
end
|
1102
|
+
|
1103
|
+
# ------------------------------------------------------------------
|
1104
|
+
# Divide
|
1105
|
+
# ------------------------------------------------------------------
|
1106
|
+
|
1107
|
+
def test_divide
|
1108
|
+
check(C::Divide, <<-EOS)
|
1109
|
+
|a / b
|
1110
|
+
EOS
|
1111
|
+
end
|
1112
|
+
def test_divide_precedences
|
1113
|
+
check(C::Divide, <<-EOS)
|
1114
|
+
|*a / (b + c)
|
1115
|
+
EOS
|
1116
|
+
end
|
1117
|
+
def test_divide_nested
|
1118
|
+
check(C::Divide, <<-EOS)
|
1119
|
+
|a / b / (c / d)
|
1120
|
+
EOS
|
1121
|
+
end
|
1122
|
+
|
1123
|
+
# ------------------------------------------------------------------
|
1124
|
+
# Mod
|
1125
|
+
# ------------------------------------------------------------------
|
1126
|
+
|
1127
|
+
def test_mod
|
1128
|
+
check(C::Mod, <<-EOS)
|
1129
|
+
|a % b
|
1130
|
+
EOS
|
1131
|
+
end
|
1132
|
+
def test_mod_precedences
|
1133
|
+
check(C::Mod, <<-EOS)
|
1134
|
+
|*a % (b + c)
|
1135
|
+
EOS
|
1136
|
+
end
|
1137
|
+
def test_mod_nested
|
1138
|
+
check(C::Mod, <<-EOS)
|
1139
|
+
|a % b % (c % d)
|
1140
|
+
EOS
|
1141
|
+
end
|
1142
|
+
|
1143
|
+
# ------------------------------------------------------------------
|
1144
|
+
# Equal
|
1145
|
+
# ------------------------------------------------------------------
|
1146
|
+
|
1147
|
+
def test_equal
|
1148
|
+
check(C::Equal, <<-EOS)
|
1149
|
+
|a == b
|
1150
|
+
EOS
|
1151
|
+
end
|
1152
|
+
def test_equal_precedences
|
1153
|
+
check(C::Equal, <<-EOS)
|
1154
|
+
|a + b == (c ? d : e)
|
1155
|
+
EOS
|
1156
|
+
end
|
1157
|
+
def test_equal_nested
|
1158
|
+
check(C::Equal, <<-EOS)
|
1159
|
+
|a == b == (c == d)
|
1160
|
+
EOS
|
1161
|
+
end
|
1162
|
+
|
1163
|
+
# ------------------------------------------------------------------
|
1164
|
+
# NotEqual
|
1165
|
+
# ------------------------------------------------------------------
|
1166
|
+
|
1167
|
+
def test_not_equal
|
1168
|
+
check(C::NotEqual, <<-EOS)
|
1169
|
+
|a != b
|
1170
|
+
EOS
|
1171
|
+
end
|
1172
|
+
def test_not_equal_precedences
|
1173
|
+
check(C::NotEqual, <<-EOS)
|
1174
|
+
|a + b != (c ? d : e)
|
1175
|
+
EOS
|
1176
|
+
end
|
1177
|
+
def test_not_equal_nested
|
1178
|
+
check(C::NotEqual, <<-EOS)
|
1179
|
+
|a != b != (c != d)
|
1180
|
+
EOS
|
1181
|
+
end
|
1182
|
+
|
1183
|
+
# ------------------------------------------------------------------
|
1184
|
+
# Less
|
1185
|
+
# ------------------------------------------------------------------
|
1186
|
+
|
1187
|
+
def test_less
|
1188
|
+
check(C::Less, <<-EOS)
|
1189
|
+
|a < b
|
1190
|
+
EOS
|
1191
|
+
end
|
1192
|
+
def test_less_precedences
|
1193
|
+
check(C::Less, <<-EOS)
|
1194
|
+
|a + b < (c ? d : e)
|
1195
|
+
EOS
|
1196
|
+
end
|
1197
|
+
def test_less_nested
|
1198
|
+
check(C::Less, <<-EOS)
|
1199
|
+
|a < b < (c < d)
|
1200
|
+
EOS
|
1201
|
+
end
|
1202
|
+
|
1203
|
+
# ------------------------------------------------------------------
|
1204
|
+
# More
|
1205
|
+
# ------------------------------------------------------------------
|
1206
|
+
|
1207
|
+
def test_more
|
1208
|
+
check(C::More, <<-EOS)
|
1209
|
+
|a > b
|
1210
|
+
EOS
|
1211
|
+
end
|
1212
|
+
def test_more_precedences
|
1213
|
+
check(C::More, <<-EOS)
|
1214
|
+
|a + b > (c ? d : e)
|
1215
|
+
EOS
|
1216
|
+
end
|
1217
|
+
def test_more_nested
|
1218
|
+
check(C::More, <<-EOS)
|
1219
|
+
|a > b > (c > d)
|
1220
|
+
EOS
|
1221
|
+
end
|
1222
|
+
|
1223
|
+
# ------------------------------------------------------------------
|
1224
|
+
# LessOrEqual
|
1225
|
+
# ------------------------------------------------------------------
|
1226
|
+
|
1227
|
+
def test_less_or_equal
|
1228
|
+
check(C::LessOrEqual, <<-EOS)
|
1229
|
+
|a <= b
|
1230
|
+
EOS
|
1231
|
+
end
|
1232
|
+
def test_less_or_equal_precedences
|
1233
|
+
check(C::LessOrEqual, <<-EOS)
|
1234
|
+
|a + b <= (c ? d : e)
|
1235
|
+
EOS
|
1236
|
+
end
|
1237
|
+
def test_less_or_equal_nested
|
1238
|
+
check(C::LessOrEqual, <<-EOS)
|
1239
|
+
|a <= b <= (c <= d)
|
1240
|
+
EOS
|
1241
|
+
end
|
1242
|
+
|
1243
|
+
# ------------------------------------------------------------------
|
1244
|
+
# MoreOrEqual
|
1245
|
+
# ------------------------------------------------------------------
|
1246
|
+
|
1247
|
+
def test_more_or_equal
|
1248
|
+
check(C::MoreOrEqual, <<-EOS)
|
1249
|
+
|a >= b
|
1250
|
+
EOS
|
1251
|
+
end
|
1252
|
+
def test_more_or_equal_precedences
|
1253
|
+
check(C::MoreOrEqual, <<-EOS)
|
1254
|
+
|a + b >= (c ? d : e)
|
1255
|
+
EOS
|
1256
|
+
end
|
1257
|
+
def test_more_or_equal_nested
|
1258
|
+
check(C::MoreOrEqual, <<-EOS)
|
1259
|
+
|a >= b >= (c >= d)
|
1260
|
+
EOS
|
1261
|
+
end
|
1262
|
+
|
1263
|
+
# ------------------------------------------------------------------
|
1264
|
+
# BitAnd
|
1265
|
+
# ------------------------------------------------------------------
|
1266
|
+
|
1267
|
+
def test_bit_and
|
1268
|
+
check(C::BitAnd, <<-EOS)
|
1269
|
+
|a & b
|
1270
|
+
EOS
|
1271
|
+
end
|
1272
|
+
def test_bit_and_precedences
|
1273
|
+
check(C::BitAnd, <<-EOS)
|
1274
|
+
|a + b & (c ? d : e)
|
1275
|
+
EOS
|
1276
|
+
end
|
1277
|
+
def test_bit_and_nested
|
1278
|
+
check(C::BitAnd, <<-EOS)
|
1279
|
+
|a & b & (c & d)
|
1280
|
+
EOS
|
1281
|
+
end
|
1282
|
+
|
1283
|
+
# ------------------------------------------------------------------
|
1284
|
+
# BitOr
|
1285
|
+
# ------------------------------------------------------------------
|
1286
|
+
|
1287
|
+
def test_bit_or
|
1288
|
+
check(C::BitOr, <<-EOS)
|
1289
|
+
|a | b
|
1290
|
+
EOS
|
1291
|
+
end
|
1292
|
+
def test_bit_or_precedences
|
1293
|
+
check(C::BitOr, <<-EOS)
|
1294
|
+
|a + b | (c ? d : e)
|
1295
|
+
EOS
|
1296
|
+
end
|
1297
|
+
def test_bit_or_nested
|
1298
|
+
check(C::BitOr, <<-EOS)
|
1299
|
+
|a | b | (c | d)
|
1300
|
+
EOS
|
1301
|
+
end
|
1302
|
+
|
1303
|
+
# ------------------------------------------------------------------
|
1304
|
+
# BitXor
|
1305
|
+
# ------------------------------------------------------------------
|
1306
|
+
|
1307
|
+
def test_bit_xor
|
1308
|
+
check(C::BitXor, <<-EOS)
|
1309
|
+
|a ^ b
|
1310
|
+
EOS
|
1311
|
+
end
|
1312
|
+
def test_bit_xor_precedences
|
1313
|
+
check(C::BitXor, <<-EOS)
|
1314
|
+
|a + b ^ (c ? d : e)
|
1315
|
+
EOS
|
1316
|
+
end
|
1317
|
+
def test_bit_xor_nested
|
1318
|
+
check(C::BitXor, <<-EOS)
|
1319
|
+
|a ^ b ^ (c ^ d)
|
1320
|
+
EOS
|
1321
|
+
end
|
1322
|
+
|
1323
|
+
# ------------------------------------------------------------------
|
1324
|
+
# ShiftLeft
|
1325
|
+
# ------------------------------------------------------------------
|
1326
|
+
|
1327
|
+
def test_shift_left
|
1328
|
+
check(C::ShiftLeft, <<-EOS)
|
1329
|
+
|a << b
|
1330
|
+
EOS
|
1331
|
+
end
|
1332
|
+
def test_shift_left_precedences
|
1333
|
+
check(C::ShiftLeft, <<-EOS)
|
1334
|
+
|a + b << (c ? d : e)
|
1335
|
+
EOS
|
1336
|
+
end
|
1337
|
+
def test_shift_left_nested
|
1338
|
+
check(C::ShiftLeft, <<-EOS)
|
1339
|
+
|a << b << (c << d)
|
1340
|
+
EOS
|
1341
|
+
end
|
1342
|
+
|
1343
|
+
# ------------------------------------------------------------------
|
1344
|
+
# ShiftRight
|
1345
|
+
# ------------------------------------------------------------------
|
1346
|
+
|
1347
|
+
def test_shift_right
|
1348
|
+
check(C::ShiftRight, <<-EOS)
|
1349
|
+
|a >> b
|
1350
|
+
EOS
|
1351
|
+
end
|
1352
|
+
def test_shift_right_precedences
|
1353
|
+
check(C::ShiftRight, <<-EOS)
|
1354
|
+
|a + b >> (c ? d : e)
|
1355
|
+
EOS
|
1356
|
+
end
|
1357
|
+
def test_shift_right_nested
|
1358
|
+
check(C::ShiftRight, <<-EOS)
|
1359
|
+
|a >> b >> (c >> d)
|
1360
|
+
EOS
|
1361
|
+
end
|
1362
|
+
|
1363
|
+
# ------------------------------------------------------------------
|
1364
|
+
# And
|
1365
|
+
# ------------------------------------------------------------------
|
1366
|
+
|
1367
|
+
def test_and
|
1368
|
+
check(C::And, <<-EOS)
|
1369
|
+
|a && b
|
1370
|
+
EOS
|
1371
|
+
end
|
1372
|
+
def test_and_precedences
|
1373
|
+
check(C::And, <<-EOS)
|
1374
|
+
|a + b && (c ? d : e)
|
1375
|
+
EOS
|
1376
|
+
end
|
1377
|
+
def test_and_nested
|
1378
|
+
check(C::And, <<-EOS)
|
1379
|
+
|a && b && (c && d)
|
1380
|
+
EOS
|
1381
|
+
end
|
1382
|
+
|
1383
|
+
# ------------------------------------------------------------------
|
1384
|
+
# Or
|
1385
|
+
# ------------------------------------------------------------------
|
1386
|
+
|
1387
|
+
def test_or
|
1388
|
+
check(C::Or, <<-EOS)
|
1389
|
+
|a || b
|
1390
|
+
EOS
|
1391
|
+
end
|
1392
|
+
def test_or_precedences
|
1393
|
+
check(C::Or, <<-EOS)
|
1394
|
+
|a + b || (c ? d : e)
|
1395
|
+
EOS
|
1396
|
+
end
|
1397
|
+
def test_or_nested
|
1398
|
+
check(C::Or, <<-EOS)
|
1399
|
+
|a || b || (c || d)
|
1400
|
+
EOS
|
1401
|
+
end
|
1402
|
+
|
1403
|
+
# ------------------------------------------------------------------
|
1404
|
+
# Assign
|
1405
|
+
# ------------------------------------------------------------------
|
1406
|
+
|
1407
|
+
def test_assign
|
1408
|
+
check(C::Assign, <<-EOS)
|
1409
|
+
|a = b
|
1410
|
+
EOS
|
1411
|
+
end
|
1412
|
+
def test_assign_precedences
|
1413
|
+
check(C::Assign, <<-EOS)
|
1414
|
+
|a = b ? c : d
|
1415
|
+
EOS
|
1416
|
+
end
|
1417
|
+
def test_assign_nested
|
1418
|
+
check(C::Assign, <<-EOS)
|
1419
|
+
|a = b = (c, d)
|
1420
|
+
EOS
|
1421
|
+
end
|
1422
|
+
|
1423
|
+
# ------------------------------------------------------------------
|
1424
|
+
# MultiplyAssign
|
1425
|
+
# ------------------------------------------------------------------
|
1426
|
+
|
1427
|
+
def test_multiply_assign
|
1428
|
+
check(C::MultiplyAssign, <<-EOS)
|
1429
|
+
|a *= b
|
1430
|
+
EOS
|
1431
|
+
end
|
1432
|
+
def test_multiply_assign_precedences
|
1433
|
+
check(C::MultiplyAssign, <<-EOS)
|
1434
|
+
|a *= b ? c : d
|
1435
|
+
EOS
|
1436
|
+
end
|
1437
|
+
def test_multiply_assign_nested
|
1438
|
+
check(C::MultiplyAssign, <<-EOS)
|
1439
|
+
|a *= b *= (c, d)
|
1440
|
+
EOS
|
1441
|
+
end
|
1442
|
+
|
1443
|
+
# ------------------------------------------------------------------
|
1444
|
+
# DivideAssign
|
1445
|
+
# ------------------------------------------------------------------
|
1446
|
+
|
1447
|
+
def test_divide_assign
|
1448
|
+
check(C::DivideAssign, <<-EOS)
|
1449
|
+
|a /= b
|
1450
|
+
EOS
|
1451
|
+
end
|
1452
|
+
def test_divide_assign_precedences
|
1453
|
+
check(C::DivideAssign, <<-EOS)
|
1454
|
+
|a /= b ? c : d
|
1455
|
+
EOS
|
1456
|
+
end
|
1457
|
+
def test_divide_assign_nested
|
1458
|
+
check(C::DivideAssign, <<-EOS)
|
1459
|
+
|a /= b /= c
|
1460
|
+
EOS
|
1461
|
+
end
|
1462
|
+
|
1463
|
+
# ------------------------------------------------------------------
|
1464
|
+
# ModAssign
|
1465
|
+
# ------------------------------------------------------------------
|
1466
|
+
|
1467
|
+
def test_mod_assign
|
1468
|
+
check(C::ModAssign, <<-EOS)
|
1469
|
+
|a %= b
|
1470
|
+
EOS
|
1471
|
+
end
|
1472
|
+
def test_mod_assign_precedences
|
1473
|
+
check(C::ModAssign, <<-EOS)
|
1474
|
+
|a %= b ? c : d
|
1475
|
+
EOS
|
1476
|
+
end
|
1477
|
+
def test_mod_assign_nested
|
1478
|
+
check(C::ModAssign, <<-EOS)
|
1479
|
+
|a %= b %= (c, d)
|
1480
|
+
EOS
|
1481
|
+
end
|
1482
|
+
|
1483
|
+
# ------------------------------------------------------------------
|
1484
|
+
# AddAssign
|
1485
|
+
# ------------------------------------------------------------------
|
1486
|
+
|
1487
|
+
def test_add_assign
|
1488
|
+
check(C::AddAssign, <<-EOS)
|
1489
|
+
|a += b
|
1490
|
+
EOS
|
1491
|
+
end
|
1492
|
+
def test_add_assign_precedences
|
1493
|
+
check(C::AddAssign, <<-EOS)
|
1494
|
+
|a += b ? c : d
|
1495
|
+
EOS
|
1496
|
+
end
|
1497
|
+
def test_add_assign_nested
|
1498
|
+
check(C::AddAssign, <<-EOS)
|
1499
|
+
|a += b += (c, d)
|
1500
|
+
EOS
|
1501
|
+
end
|
1502
|
+
|
1503
|
+
# ------------------------------------------------------------------
|
1504
|
+
# SubtractAssign
|
1505
|
+
# ------------------------------------------------------------------
|
1506
|
+
|
1507
|
+
def test_subtract_assign
|
1508
|
+
check(C::SubtractAssign, <<-EOS)
|
1509
|
+
|a -= b
|
1510
|
+
EOS
|
1511
|
+
end
|
1512
|
+
def test_subtract_assign_precedences
|
1513
|
+
check(C::SubtractAssign, <<-EOS)
|
1514
|
+
|a -= b ? c : d
|
1515
|
+
EOS
|
1516
|
+
end
|
1517
|
+
def test_subtract_assign_nested
|
1518
|
+
check(C::SubtractAssign, <<-EOS)
|
1519
|
+
|a -= b -= (c, d)
|
1520
|
+
EOS
|
1521
|
+
end
|
1522
|
+
|
1523
|
+
# ------------------------------------------------------------------
|
1524
|
+
# ShiftLeftAssign
|
1525
|
+
# ------------------------------------------------------------------
|
1526
|
+
|
1527
|
+
def test_shift_left_assign
|
1528
|
+
check(C::ShiftLeftAssign, <<-EOS)
|
1529
|
+
|a <<= b
|
1530
|
+
EOS
|
1531
|
+
end
|
1532
|
+
def test_shift_left_assign_precedences
|
1533
|
+
check(C::ShiftLeftAssign, <<-EOS)
|
1534
|
+
|a <<= b ? c : d
|
1535
|
+
EOS
|
1536
|
+
end
|
1537
|
+
def test_shift_left_assign_nested
|
1538
|
+
check(C::ShiftLeftAssign, <<-EOS)
|
1539
|
+
|a <<= b <<= (c, d)
|
1540
|
+
EOS
|
1541
|
+
end
|
1542
|
+
|
1543
|
+
# ------------------------------------------------------------------
|
1544
|
+
# ShiftRightAssign
|
1545
|
+
# ------------------------------------------------------------------
|
1546
|
+
|
1547
|
+
def test_shift_right_assign
|
1548
|
+
check(C::ShiftRightAssign, <<-EOS)
|
1549
|
+
|a >>= b
|
1550
|
+
EOS
|
1551
|
+
end
|
1552
|
+
def test_shift_right_assign_precedences
|
1553
|
+
check(C::ShiftRightAssign, <<-EOS)
|
1554
|
+
|a >>= b ? c : d
|
1555
|
+
EOS
|
1556
|
+
end
|
1557
|
+
def test_shift_right_assign_nested
|
1558
|
+
check(C::ShiftRightAssign, <<-EOS)
|
1559
|
+
|a >>= b >>= (c, d)
|
1560
|
+
EOS
|
1561
|
+
end
|
1562
|
+
|
1563
|
+
# ------------------------------------------------------------------
|
1564
|
+
# BitAndAssign
|
1565
|
+
# ------------------------------------------------------------------
|
1566
|
+
|
1567
|
+
def test_bit_and_assign
|
1568
|
+
check(C::BitAndAssign, <<-EOS)
|
1569
|
+
|a &= b
|
1570
|
+
EOS
|
1571
|
+
end
|
1572
|
+
def test_bit_and_assign_precedences
|
1573
|
+
check(C::BitAndAssign, <<-EOS)
|
1574
|
+
|a &= b ? c : d
|
1575
|
+
EOS
|
1576
|
+
end
|
1577
|
+
def test_bit_and_assign_nested
|
1578
|
+
check(C::BitAndAssign, <<-EOS)
|
1579
|
+
|a &= b &= (c, d)
|
1580
|
+
EOS
|
1581
|
+
end
|
1582
|
+
|
1583
|
+
# ------------------------------------------------------------------
|
1584
|
+
# BitXorAssign
|
1585
|
+
# ------------------------------------------------------------------
|
1586
|
+
|
1587
|
+
def test_bit_xor_assign
|
1588
|
+
check(C::BitXorAssign, <<-EOS)
|
1589
|
+
|a ^= b
|
1590
|
+
EOS
|
1591
|
+
end
|
1592
|
+
def test_bit_xor_assign_precedences
|
1593
|
+
check(C::BitXorAssign, <<-EOS)
|
1594
|
+
|a ^= b ? c : d
|
1595
|
+
EOS
|
1596
|
+
end
|
1597
|
+
def test_bit_xor_assign_nested
|
1598
|
+
check(C::BitXorAssign, <<-EOS)
|
1599
|
+
|a ^= b ^= (c, d)
|
1600
|
+
EOS
|
1601
|
+
end
|
1602
|
+
|
1603
|
+
# ------------------------------------------------------------------
|
1604
|
+
# BitOrAssign
|
1605
|
+
# ------------------------------------------------------------------
|
1606
|
+
|
1607
|
+
def test_bit_or_assign
|
1608
|
+
check(C::BitOrAssign, <<-EOS)
|
1609
|
+
|a |= b
|
1610
|
+
EOS
|
1611
|
+
end
|
1612
|
+
def test_bit_or_assign_precedences
|
1613
|
+
check(C::BitOrAssign, <<-EOS)
|
1614
|
+
|a |= b ? c : d
|
1615
|
+
EOS
|
1616
|
+
end
|
1617
|
+
def test_bit_or_assign_nested
|
1618
|
+
check(C::BitOrAssign, <<-EOS)
|
1619
|
+
|a |= b |= (c, d)
|
1620
|
+
EOS
|
1621
|
+
end
|
1622
|
+
|
1623
|
+
# ------------------------------------------------------------------
|
1624
|
+
# StringLiteral
|
1625
|
+
# ------------------------------------------------------------------
|
1626
|
+
|
1627
|
+
# TODO: handle unusual characters
|
1628
|
+
# TODO: handle prefixes (wide)
|
1629
|
+
def test_string_literal_empty
|
1630
|
+
check(C::StringLiteral, <<-EOS)
|
1631
|
+
|""
|
1632
|
+
EOS
|
1633
|
+
end
|
1634
|
+
def test_string_literal_simple
|
1635
|
+
check(C::StringLiteral, <<-EOS)
|
1636
|
+
|"hi"
|
1637
|
+
EOS
|
1638
|
+
end
|
1639
|
+
def test_string_literal_complex
|
1640
|
+
check(C::StringLiteral, <<-EOS)
|
1641
|
+
|"\0000\0xfff"
|
1642
|
+
EOS
|
1643
|
+
end
|
1644
|
+
|
1645
|
+
# ------------------------------------------------------------------
|
1646
|
+
# CharLiteral
|
1647
|
+
# ------------------------------------------------------------------
|
1648
|
+
|
1649
|
+
# TODO: handle unusual characters
|
1650
|
+
# TODO: handle prefixes (wide)
|
1651
|
+
def test_char_literal_simple
|
1652
|
+
check(C::CharLiteral, <<-EOS)
|
1653
|
+
|'x'
|
1654
|
+
EOS
|
1655
|
+
end
|
1656
|
+
def test_char_literal_complex
|
1657
|
+
check(C::CharLiteral, <<-EOS)
|
1658
|
+
|'\0000\0xfff'
|
1659
|
+
EOS
|
1660
|
+
end
|
1661
|
+
|
1662
|
+
# ------------------------------------------------------------------
|
1663
|
+
# CompoundLiteral
|
1664
|
+
# ------------------------------------------------------------------
|
1665
|
+
|
1666
|
+
def test_compound_literal_no_type
|
1667
|
+
check(C::CompoundLiteral, <<-EOS)
|
1668
|
+
|{
|
1669
|
+
| 1
|
1670
|
+
|}
|
1671
|
+
EOS
|
1672
|
+
end
|
1673
|
+
def test_compound_literal_type
|
1674
|
+
check(C::CompoundLiteral, <<-EOS)
|
1675
|
+
|(int []) {
|
1676
|
+
| 1
|
1677
|
+
|}
|
1678
|
+
EOS
|
1679
|
+
end
|
1680
|
+
def test_compound_literal_one_member
|
1681
|
+
check(C::CompoundLiteral, <<-EOS)
|
1682
|
+
|(struct s) {
|
1683
|
+
| .one = 1
|
1684
|
+
|}
|
1685
|
+
EOS
|
1686
|
+
end
|
1687
|
+
def test_compound_literal_two_members
|
1688
|
+
check(C::CompoundLiteral, <<-EOS)
|
1689
|
+
|(union u) {
|
1690
|
+
| .one = 1,
|
1691
|
+
| .two = 2
|
1692
|
+
|}
|
1693
|
+
EOS
|
1694
|
+
end
|
1695
|
+
def test_compound_literal_nested
|
1696
|
+
check(C::CompoundLiteral, <<-EOS)
|
1697
|
+
|(T) {
|
1698
|
+
| .one = (T) {
|
1699
|
+
| 2
|
1700
|
+
| }
|
1701
|
+
|}
|
1702
|
+
EOS
|
1703
|
+
end
|
1704
|
+
|
1705
|
+
# ------------------------------------------------------------------
|
1706
|
+
# IntLiteral
|
1707
|
+
# ------------------------------------------------------------------
|
1708
|
+
|
1709
|
+
def test_int_literal_small
|
1710
|
+
check(C::IntLiteral, <<-EOS)
|
1711
|
+
|1
|
1712
|
+
EOS
|
1713
|
+
end
|
1714
|
+
# TODO: handle big ints -- this test fails
|
1715
|
+
def xtest_int_literal_big
|
1716
|
+
check(C::IntLiteral, <<-EOS)
|
1717
|
+
|10000000000
|
1718
|
+
EOS
|
1719
|
+
end
|
1720
|
+
|
1721
|
+
# ------------------------------------------------------------------
|
1722
|
+
# FloatLiteral
|
1723
|
+
# ------------------------------------------------------------------
|
1724
|
+
|
1725
|
+
# TODO: handle precisions properly -- probably need to store string,
|
1726
|
+
# or integer,mantissa,exponent separately
|
1727
|
+
def test_float_literal
|
1728
|
+
check(C::FloatLiteral, <<-EOS)
|
1729
|
+
|1.0
|
1730
|
+
EOS
|
1731
|
+
end
|
1732
|
+
def test_float_literal_precise
|
1733
|
+
check(C::FloatLiteral, <<-EOS)
|
1734
|
+
|1.0000000001
|
1735
|
+
EOS
|
1736
|
+
end
|
1737
|
+
|
1738
|
+
# ------------------------------------------------------------------
|
1739
|
+
# Pointer
|
1740
|
+
# ------------------------------------------------------------------
|
1741
|
+
|
1742
|
+
def test_pointer
|
1743
|
+
check(C::Pointer, <<-EOS)
|
1744
|
+
|int *
|
1745
|
+
EOS
|
1746
|
+
end
|
1747
|
+
def test_pointer_precedences
|
1748
|
+
check(C::Pointer, <<-EOS)
|
1749
|
+
|int *(*)[]
|
1750
|
+
EOS
|
1751
|
+
end
|
1752
|
+
def test_pointer_nested
|
1753
|
+
check(C::Pointer, <<-EOS)
|
1754
|
+
|int **
|
1755
|
+
EOS
|
1756
|
+
end
|
1757
|
+
|
1758
|
+
# ------------------------------------------------------------------
|
1759
|
+
# Array
|
1760
|
+
# ------------------------------------------------------------------
|
1761
|
+
def test_array
|
1762
|
+
check(C::Array, <<-EOS)
|
1763
|
+
|int []
|
1764
|
+
EOS
|
1765
|
+
end
|
1766
|
+
def test_array_precedences
|
1767
|
+
check(C::Pointer, <<-EOS)
|
1768
|
+
|int (*)[]
|
1769
|
+
EOS
|
1770
|
+
end
|
1771
|
+
def test_array_nested
|
1772
|
+
check(C::Array, <<-EOS)
|
1773
|
+
|int [][]
|
1774
|
+
EOS
|
1775
|
+
end
|
1776
|
+
|
1777
|
+
# ------------------------------------------------------------------
|
1778
|
+
# Function
|
1779
|
+
# ------------------------------------------------------------------
|
1780
|
+
|
1781
|
+
def test_function
|
1782
|
+
check(C::Function, <<-EOS)
|
1783
|
+
|int ()
|
1784
|
+
EOS
|
1785
|
+
end
|
1786
|
+
def test_function_no_params
|
1787
|
+
check(C::Function, <<-EOS)
|
1788
|
+
|int (void)
|
1789
|
+
EOS
|
1790
|
+
end
|
1791
|
+
def test_function_params
|
1792
|
+
check(C::Function, <<-EOS)
|
1793
|
+
|int (int, int)
|
1794
|
+
EOS
|
1795
|
+
end
|
1796
|
+
def test_function_precedences
|
1797
|
+
check(C::Pointer, <<-EOS)
|
1798
|
+
|int (*)()
|
1799
|
+
EOS
|
1800
|
+
end
|
1801
|
+
def test_function_nested
|
1802
|
+
check(C::Function, <<-EOS)
|
1803
|
+
|int ()()
|
1804
|
+
EOS
|
1805
|
+
end
|
1806
|
+
|
1807
|
+
# ------------------------------------------------------------------
|
1808
|
+
# Struct
|
1809
|
+
# ------------------------------------------------------------------
|
1810
|
+
|
1811
|
+
def test_struct_basic
|
1812
|
+
check(C::Struct, <<-EOS)
|
1813
|
+
|struct {
|
1814
|
+
| int i;
|
1815
|
+
|}
|
1816
|
+
EOS
|
1817
|
+
end
|
1818
|
+
def test_struct_with_name
|
1819
|
+
check(C::Struct, <<-EOS)
|
1820
|
+
|struct s {
|
1821
|
+
| int i;
|
1822
|
+
|}
|
1823
|
+
EOS
|
1824
|
+
end
|
1825
|
+
def test_struct_with_two_members
|
1826
|
+
check(C::Struct, <<-EOS)
|
1827
|
+
|struct {
|
1828
|
+
| int i;
|
1829
|
+
| int j;
|
1830
|
+
|}
|
1831
|
+
EOS
|
1832
|
+
end
|
1833
|
+
def test_struct_with_all
|
1834
|
+
check(C::Struct, <<-EOS)
|
1835
|
+
|struct s {
|
1836
|
+
| int i;
|
1837
|
+
| int j;
|
1838
|
+
|}
|
1839
|
+
EOS
|
1840
|
+
end
|
1841
|
+
|
1842
|
+
# ------------------------------------------------------------------
|
1843
|
+
# Union
|
1844
|
+
# ------------------------------------------------------------------
|
1845
|
+
|
1846
|
+
def test_union_basic
|
1847
|
+
check(C::Union, <<-EOS)
|
1848
|
+
|union {
|
1849
|
+
| int i;
|
1850
|
+
|}
|
1851
|
+
EOS
|
1852
|
+
end
|
1853
|
+
def test_union_with_name
|
1854
|
+
check(C::Union, <<-EOS)
|
1855
|
+
|union u {
|
1856
|
+
| int i;
|
1857
|
+
|}
|
1858
|
+
EOS
|
1859
|
+
end
|
1860
|
+
def test_union_with_two_members
|
1861
|
+
check(C::Union, <<-EOS)
|
1862
|
+
|union {
|
1863
|
+
| int i;
|
1864
|
+
| int j;
|
1865
|
+
|}
|
1866
|
+
EOS
|
1867
|
+
end
|
1868
|
+
def test_union_with_all
|
1869
|
+
check(C::Union, <<-EOS)
|
1870
|
+
|union u {
|
1871
|
+
| int i;
|
1872
|
+
| int j;
|
1873
|
+
|}
|
1874
|
+
EOS
|
1875
|
+
end
|
1876
|
+
|
1877
|
+
# ------------------------------------------------------------------
|
1878
|
+
# Enum
|
1879
|
+
# ------------------------------------------------------------------
|
1880
|
+
|
1881
|
+
def test_enum_basic
|
1882
|
+
check(C::Enum, <<-EOS)
|
1883
|
+
|enum {
|
1884
|
+
| E1
|
1885
|
+
|}
|
1886
|
+
EOS
|
1887
|
+
end
|
1888
|
+
def test_enum_with_name
|
1889
|
+
check(C::Enum, <<-EOS)
|
1890
|
+
|enum e {
|
1891
|
+
| E1
|
1892
|
+
|}
|
1893
|
+
EOS
|
1894
|
+
end
|
1895
|
+
def test_enum_with_two_members
|
1896
|
+
check(C::Enum, <<-EOS)
|
1897
|
+
|enum {
|
1898
|
+
| E1,
|
1899
|
+
| E2
|
1900
|
+
|}
|
1901
|
+
EOS
|
1902
|
+
end
|
1903
|
+
def test_enum_with_all
|
1904
|
+
check(C::Enum, <<-EOS)
|
1905
|
+
|enum {
|
1906
|
+
| E1,
|
1907
|
+
| E2
|
1908
|
+
|}
|
1909
|
+
EOS
|
1910
|
+
end
|
1911
|
+
|
1912
|
+
# ------------------------------------------------------------------
|
1913
|
+
# CustomType
|
1914
|
+
# ------------------------------------------------------------------
|
1915
|
+
|
1916
|
+
def test_custom_type_unqualified
|
1917
|
+
check(C::CustomType, <<-EOS)
|
1918
|
+
|T
|
1919
|
+
EOS
|
1920
|
+
end
|
1921
|
+
def test_custom_type_qualified
|
1922
|
+
check(C::CustomType, <<-EOS)
|
1923
|
+
|const restrict volatile T
|
1924
|
+
EOS
|
1925
|
+
end
|
1926
|
+
|
1927
|
+
# ------------------------------------------------------------------
|
1928
|
+
# Void
|
1929
|
+
# ------------------------------------------------------------------
|
1930
|
+
|
1931
|
+
def test_void_unqualified
|
1932
|
+
check(C::Void, <<-EOS)
|
1933
|
+
|void
|
1934
|
+
EOS
|
1935
|
+
end
|
1936
|
+
def test_void_qualified
|
1937
|
+
check(C::Void, <<-EOS)
|
1938
|
+
|const restrict volatile void
|
1939
|
+
EOS
|
1940
|
+
end
|
1941
|
+
|
1942
|
+
# ------------------------------------------------------------------
|
1943
|
+
# Int
|
1944
|
+
# ------------------------------------------------------------------
|
1945
|
+
|
1946
|
+
def test_int_unqualified
|
1947
|
+
check(C::Int, <<-EOS)
|
1948
|
+
|int
|
1949
|
+
EOS
|
1950
|
+
end
|
1951
|
+
def test_int_qualified
|
1952
|
+
check(C::Int, <<-EOS)
|
1953
|
+
|const restrict volatile int
|
1954
|
+
EOS
|
1955
|
+
end
|
1956
|
+
def test_int_qualified_short
|
1957
|
+
check(C::Int, <<-EOS)
|
1958
|
+
|const restrict volatile short int
|
1959
|
+
EOS
|
1960
|
+
end
|
1961
|
+
def test_int_qualified_long
|
1962
|
+
check(C::Int, <<-EOS)
|
1963
|
+
|const restrict volatile long int
|
1964
|
+
EOS
|
1965
|
+
end
|
1966
|
+
def test_int_qualified_long_long
|
1967
|
+
check(C::Int, <<-EOS)
|
1968
|
+
|const restrict volatile long long int
|
1969
|
+
EOS
|
1970
|
+
end
|
1971
|
+
|
1972
|
+
# ------------------------------------------------------------------
|
1973
|
+
# Float
|
1974
|
+
# ------------------------------------------------------------------
|
1975
|
+
|
1976
|
+
def test_float_unqualified
|
1977
|
+
check(C::Float, <<-EOS)
|
1978
|
+
|float
|
1979
|
+
EOS
|
1980
|
+
end
|
1981
|
+
def test_float_qualified
|
1982
|
+
check(C::Float, <<-EOS)
|
1983
|
+
|const restrict volatile float
|
1984
|
+
EOS
|
1985
|
+
end
|
1986
|
+
def test_float_qualified_double
|
1987
|
+
check(C::Float, <<-EOS)
|
1988
|
+
|const restrict volatile double
|
1989
|
+
EOS
|
1990
|
+
end
|
1991
|
+
def test_float_qualified_long_double
|
1992
|
+
check(C::Float, <<-EOS)
|
1993
|
+
|const restrict volatile long double
|
1994
|
+
EOS
|
1995
|
+
end
|
1996
|
+
|
1997
|
+
# ------------------------------------------------------------------
|
1998
|
+
# Char
|
1999
|
+
# ------------------------------------------------------------------
|
2000
|
+
|
2001
|
+
def test_char_unqualified
|
2002
|
+
check(C::Char, <<-EOS)
|
2003
|
+
|char
|
2004
|
+
EOS
|
2005
|
+
end
|
2006
|
+
def test_char_qualified
|
2007
|
+
check(C::Char, <<-EOS)
|
2008
|
+
|const restrict volatile char
|
2009
|
+
EOS
|
2010
|
+
end
|
2011
|
+
def test_char_qualified_signed
|
2012
|
+
check(C::Char, <<-EOS)
|
2013
|
+
|const restrict volatile signed char
|
2014
|
+
EOS
|
2015
|
+
end
|
2016
|
+
def test_char_qualified_unsigned
|
2017
|
+
check(C::Char, <<-EOS)
|
2018
|
+
|const restrict volatile unsigned char
|
2019
|
+
EOS
|
2020
|
+
end
|
2021
|
+
|
2022
|
+
# ------------------------------------------------------------------
|
2023
|
+
# Bool
|
2024
|
+
# ------------------------------------------------------------------
|
2025
|
+
|
2026
|
+
def test_bool_unqualified
|
2027
|
+
check(C::Bool, <<-EOS)
|
2028
|
+
|_Bool
|
2029
|
+
EOS
|
2030
|
+
end
|
2031
|
+
def test_bool_qualified
|
2032
|
+
check(C::Bool, <<-EOS)
|
2033
|
+
|const restrict volatile _Bool
|
2034
|
+
EOS
|
2035
|
+
end
|
2036
|
+
|
2037
|
+
# ------------------------------------------------------------------
|
2038
|
+
# Complex
|
2039
|
+
# ------------------------------------------------------------------
|
2040
|
+
|
2041
|
+
def test_complex_unqualified
|
2042
|
+
check(C::Complex, <<-EOS)
|
2043
|
+
|_Complex float
|
2044
|
+
EOS
|
2045
|
+
end
|
2046
|
+
def test_complex_qualified
|
2047
|
+
check(C::Complex, <<-EOS)
|
2048
|
+
|const restrict volatile _Complex float
|
2049
|
+
EOS
|
2050
|
+
end
|
2051
|
+
def test_complex_qualified_double
|
2052
|
+
check(C::Complex, <<-EOS)
|
2053
|
+
|const restrict volatile _Complex double
|
2054
|
+
EOS
|
2055
|
+
end
|
2056
|
+
def test_complex_qualified_long_double
|
2057
|
+
check(C::Complex, <<-EOS)
|
2058
|
+
|const restrict volatile _Complex long double
|
2059
|
+
EOS
|
2060
|
+
end
|
2061
|
+
|
2062
|
+
# ------------------------------------------------------------------
|
2063
|
+
# Imaginary
|
2064
|
+
# ------------------------------------------------------------------
|
2065
|
+
|
2066
|
+
def test_imaginary_unqualified
|
2067
|
+
check(C::Imaginary, <<-EOS)
|
2068
|
+
|_Imaginary float
|
2069
|
+
EOS
|
2070
|
+
end
|
2071
|
+
def test_imaginary_qualified
|
2072
|
+
check(C::Imaginary, <<-EOS)
|
2073
|
+
|const restrict volatile _Imaginary float
|
2074
|
+
EOS
|
2075
|
+
end
|
2076
|
+
def test_imaginary_qualified_double
|
2077
|
+
check(C::Imaginary, <<-EOS)
|
2078
|
+
|const restrict volatile _Imaginary double
|
2079
|
+
EOS
|
2080
|
+
end
|
2081
|
+
def test_imaginary_qualified_long_double
|
2082
|
+
check(C::Imaginary, <<-EOS)
|
2083
|
+
|const restrict volatile _Imaginary long double
|
2084
|
+
EOS
|
2085
|
+
end
|
2086
|
+
end
|