Skip to content

Commit 866f229

Browse files
dkearnschrisbra
authored andcommitted
runtime(c): Add missing syntax test files
These were missing from commit c2a967a. closes: #16470 Signed-off-by: Doug Kearns <dougkearns@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 727c567 commit 866f229

10 files changed

Lines changed: 249 additions & 27 deletions

runtime/syntax/testdir/dumps/c_bool_constant_01.dump

Lines changed: 0 additions & 20 deletions
This file was deleted.

runtime/syntax/testdir/dumps/c_integer_constant_01.dump

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
@4|/+0#0000e05&@1| |c|o|r@1|e|c|t| |w|a|y| |t|o| |f|o|r|m| |s|i|g|n|e|d| |v|a|l|u|e| |-|9|2@1|3@1|7|2|0|3|6|8|5|4|7@1|5|8|0|8| +0#0000000&@14
1818
|}| @73
1919
@75
20-
@57|1|8|,|5| @9|5|2|%|
20+
@57|1|8|,|5| @9|4|6|%|
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
| +0&#ffffff0@74
2+
|/+0#0000e05&@1| |T|h|e| |f|o|l@1|o|w|i|n|g| |v|a|r|i|a|b|l|e|s| |a|r|e| |i|n|i|t|i|a|l|i|z|e|d| |t|o| |t|h|e| |s|a|m|e| |v|a|l|u|e|:| +0#0000000&@13
3+
@75
24
|i+0#00e0003&|n|t| +0#0000000&|d| |=| |4+0#e000002&|2|;+0#0000000&| @63
35
|i+0#00e0003&|n|t| +0#0000000&|o| |=| |0+0#e000002&|5|2|;+0#0000000&| @62
4-
|i+0#00e0003&|n|t| +0#0000000&|x| |=| |0+0#e000002&|x|2|a|;+0#0000000&| @61
6+
>i+0#00e0003&|n|t| +0#0000000&|x| |=| |0+0#e000002&|x|2|a|;+0#0000000&| @61
57
|i+0#00e0003&|n|t| +0#0000000&|X| |=| |0+0#e000002&|X|2|A|;+0#0000000&| @61
6-
>i+0#00e0003&|n|t| +0#0000000&|b| |=| |0+0#e000002&|b|1|0|1|0|1|0|;+0#0000000&| |/+0#0000e05&@1| |C|2|3| +0#0000000&@50
8+
|i+0#00e0003&|n|t| +0#0000000&|b| |=| |0+0#e000002&|b|1|0|1|0|1|0|;+0#0000000&| |/+0#0000e05&@1| |C|2|3| +0#0000000&@50
79
@75
8-
|/+0#0000e05&@1| |T|h|e| |f|o|l@1|o|w|i|n|g| |v|a|r|i|a|b|l|e|s| |a|r|e| |a|l|s|o| |i|n|i|t|i|a|l|i|z|e|d| |t|o| |t|h|e| |s|a|m|e| |v|a|l|u|e|:| +0#0000000&@8
10+
|/+0#0000e05&@1| |T|h|e| |f|o|l@1|o|w|i|n|g| |v|a|r|i|a|b|l|e|s| |a|r|e| |a|l|s|o| |i|n|i|t|i|a|l|i|z|e|d| |t|o| |t|h|e| |s|a|m|e| |v|a|l|u|e|:| | +0#0000000&@7
911
@75
1012
|u+0#00e0003&|n|s|i|g|n|e|d| +0#0000000&|l+0#00e0003&|o|n|g| +0#0000000&|l+0#00e0003&|o|n|g| +0#0000000&|l|1| |=| |1+0#e000002&|8|4@1|6|7|4@1|0|7|3|7|0|9|5@1|0|5|9|2|u|l@1|;+0#0000000&| |/+0#0000e05&@1| |C|9@1| +0#0000000&@19
1113
|u+0#00e0003&|n|s|i|g|n|e|d| +0#0000000&|l+0#00e0003&|o|n|g| +0#0000000&|l+0#00e0003&|o|n|g| +0#0000000&|l|2| |=| |1+0#e000002&|8|'|4@1|6|'|7|4@1|'|0|7|3|'|7|0|9|'|5@1|0|'|5|9|2|l@1|u|;+0#0000000&| |/+0#0000e05&@1| |C|2|3| +0#0000000&@13
1214
|u+0#00e0003&|n|s|i|g|n|e|d| +0#0000000&|l+0#00e0003&|o|n|g| +0#0000000&|l+0#00e0003&|o|n|g| +0#0000000&|l|3| |=| |1+0#e000002&|8|4@1|'|6|7|4@1|'|0|7|3|7|'|0|9|5@1|'|0|5|9|2|u|L@1|;+0#0000000&| |/+0#0000e05&@1| |C|2|3| +0#0000000&@15
1315
|u+0#00e0003&|n|s|i|g|n|e|d| +0#0000000&|l+0#00e0003&|o|n|g| +0#0000000&|l+0#00e0003&|o|n|g| +0#0000000&|l|4| |=| |1+0#e000002&|8|4@1|6|7|'|4@1|0|7|3|7|'|0|'|9|5@1|0|5|'|9|2|L@1|U|;+0#0000000&| |/+0#0000e05&@1| |C|2|3| +0#0000000&@15
16+
@75
1417
|~+0#4040ff13&| @73
1518
|~| @73
1619
|~| @73
17-
|~| @73
18-
|~| @73
19-
|~| @73
2020
| +0#0000000&@56|3|4|,|1| @9|B|o|t|
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// C boolean constants
2+
3+
// Source: https://en.cppreference.com/w/c/language/bool_constant
4+
5+
#include <assert.h>
6+
7+
int main()
8+
{
9+
assert(true == 1 && 0 == false);
10+
}
11+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// C character constants
2+
3+
// Source: https://en.cppreference.com/w/c/language/character_constant
4+
5+
#include <stddef.h>
6+
#include <stdio.h>
7+
#include <uchar.h>
8+
9+
int main (void)
10+
{
11+
printf("constant value \n");
12+
printf("-------- ----------\n");
13+
14+
// integer character constants,
15+
int c1='a'; printf("'a':\t %#010x\n", c1);
16+
int c2='🍌'; printf("'🍌':\t %#010x\n\n", c2); // implementation-defined
17+
18+
// multicharacter constant
19+
int c3='ab'; printf("'ab':\t %#010x\n\n", c3); // implementation-defined
20+
21+
// 16-bit wide character constants
22+
char16_t uc1 = u'a'; printf("'a':\t %#010x\n", (int)uc1);
23+
char16_t uc2 = u'¢'; printf("'¢':\t %#010x\n", (int)uc2);
24+
char16_t uc3 = u'猫'; printf("'猫':\t %#010x\n", (int)uc3);
25+
// implementation-defined (🍌 maps to two 16-bit characters)
26+
char16_t uc4 = u'🍌'; printf("'🍌':\t %#010x\n\n", (int)uc4);
27+
28+
// 32-bit wide character constants
29+
char32_t Uc1 = U'a'; printf("'a':\t %#010x\n", (int)Uc1);
30+
char32_t Uc2 = U'¢'; printf("'¢':\t %#010x\n", (int)Uc2);
31+
char32_t Uc3 = U'猫'; printf("'猫':\t %#010x\n", (int)Uc3);
32+
char32_t Uc4 = U'🍌'; printf("'🍌':\t %#010x\n\n", (int)Uc4);
33+
34+
// wide character constants
35+
wchar_t wc1 = L'a'; printf("'a':\t %#010x\n", (int)wc1);
36+
wchar_t wc2 = L'¢'; printf("'¢':\t %#010x\n", (int)wc2);
37+
wchar_t wc3 = L'猫'; printf("'猫':\t %#010x\n", (int)wc3);
38+
wchar_t wc4 = L'🍌'; printf("'🍌':\t %#010x\n\n", (int)wc4);
39+
}
40+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// C integer constants
2+
3+
// Source: https://en.cppreference.com/w/c/language/integer_constant
4+
5+
#include <inttypes.h>
6+
#include <stdio.h>
7+
8+
int main(void)
9+
{
10+
printf("123 = %d\n", 123);
11+
printf("0123 = %d\n", 0123);
12+
printf("0x123 = %d\n", 0x123);
13+
printf("12345678901234567890ull = %llu\n", 12345678901234567890ull);
14+
// the type is a 64-bit type (unsigned long long or possibly unsigned long)
15+
// even without a long suffix
16+
printf("12345678901234567890u = %"PRIu64"\n", 12345678901234567890u );
17+
18+
// printf("%lld\n", -9223372036854775808); // Error:
19+
// the value 9223372036854775808 cannot fit in signed long long, which
20+
// is the biggest type allowed for unsuffixed decimal integer constant
21+
22+
printf("%llu\n", -9223372036854775808ull );
23+
// unary minus applied to unsigned value subtracts it from 2^64,
24+
// this gives unsigned 9223372036854775808
25+
26+
printf("%lld\n", -9223372036854775807ll - 1);
27+
// correct way to form signed value -9223372036854775808
28+
}
29+
30+
// The following variables are initialized to the same value:
31+
32+
int d = 42;
33+
int o = 052;
34+
int x = 0x2a;
35+
int X = 0X2A;
36+
int b = 0b101010; // C23
37+
38+
// The following variables are also initialized to the same value:
39+
40+
unsigned long long l1 = 18446744073709550592ull; // C99
41+
unsigned long long l2 = 18'446'744'073'709'550'592llu; // C23
42+
unsigned long long l3 = 1844'6744'0737'0955'0592uLL; // C23
43+
unsigned long long l4 = 184467'440737'0'95505'92LLU; // C23
44+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// C preprocessor - conditional inclusion
2+
3+
// Source: https://en.cppreference.com/w/c/preprocessor/conditional
4+
5+
#define ABCD 2
6+
#include <stdio.h>
7+
8+
int main(void)
9+
{
10+
11+
#ifdef ABCD
12+
printf("1: yes\n");
13+
#else
14+
printf("1: no\n");
15+
#endif
16+
17+
#ifndef ABCD
18+
printf("2: no1\n");
19+
#elif ABCD == 2
20+
printf("2: yes\n");
21+
#else
22+
printf("2: no2\n");
23+
#endif
24+
25+
#if !defined(DCBA) && (ABCD < 2 * 4 - 3)
26+
printf("3: yes\n");
27+
#endif
28+
29+
// C23 directives #elifdef/#elifndef
30+
#ifdef CPU
31+
printf("4: no1\n");
32+
#elifdef GPU
33+
printf("4: no2\n");
34+
#elifndef RAM
35+
printf("4: yes\n"); // selected in C23 mode, may be selected in pre-C23 mode
36+
#else
37+
printf("4: no3\n"); // may be selected in pre-C23 mode
38+
#endif
39+
}
40+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// C preprocessor - binary resource inclusion
2+
3+
// Source: https://en.cppreference.com/w/c/preprocessor/embed
4+
5+
#include <stdint.h>
6+
#include <stdio.h>
7+
8+
const uint8_t image_data[] = {
9+
#embed "image.png"
10+
};
11+
12+
const char message[] = {
13+
#embed "message.txt" if_empty('M', 'i', 's', 's', 'i', 'n', 'g', '\n')
14+
,'\0' // null terminator
15+
};
16+
17+
void dump(const uint8_t arr[], size_t size)
18+
{
19+
for (size_t i = 0; i != size; ++i)
20+
printf("%02X%c", arr[i], (i + 1) % 16 ? ' ' : '\n');
21+
puts("");
22+
}
23+
24+
int main()
25+
{
26+
puts("image_data[]:");
27+
dump(image_data, sizeof image_data);
28+
puts("message[]:");
29+
dump((const uint8_t*)message, sizeof message);
30+
}
31+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// C preprocessor - diagnostic directives
2+
3+
// Source: https://en.cppreference.com/w/c/preprocessor/error
4+
5+
#if __STDC__ != 1
6+
# error "Not a standard compliant compiler"
7+
#endif
8+
9+
#if __STDC_VERSION__ >= 202311L
10+
# warning "Using #warning as a standard feature"
11+
#endif
12+
13+
#include <stdio.h>
14+
15+
int main (void)
16+
{
17+
printf("The compiler used conforms to the ISO C Standard !!");
18+
}
19+
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// C string literals
2+
3+
// Source: https://en.cppreference.com/w/c/language/string_literal
4+
5+
#include <inttypes.h>
6+
#include <locale.h>
7+
#include <stddef.h>
8+
#include <stdio.h>
9+
#include <stdlib.h>
10+
#include <uchar.h>
11+
12+
int main(void)
13+
{
14+
char s1[] = "a猫🍌"; // or "a\u732B\U0001F34C"
15+
#if __STDC_VERSION__ >= 202311L
16+
char8_t
17+
#else
18+
char
19+
#endif
20+
s2[] = u8"a猫🍌";
21+
char16_t s3[] = u"a猫🍌";
22+
char32_t s4[] = U"a猫🍌";
23+
wchar_t s5[] = L"a猫🍌";
24+
25+
setlocale(LC_ALL, "en_US.utf8");
26+
printf(" \"%s\" is a char[%zu] holding { ", s1, sizeof s1 / sizeof *s1);
27+
for(size_t n = 0; n < sizeof s1 / sizeof *s1; ++n)
28+
printf("0x%02X ", +(unsigned char)s1[n]);
29+
puts("}");
30+
printf(
31+
#if __STDC_VERSION__ >= 202311L
32+
"u8\"%s\" is a char8_t[%zu] holding { "
33+
#else
34+
"u8\"%s\" is a char[%zu] holding { "
35+
#endif
36+
, s2, sizeof s2 / sizeof *s2);
37+
for(size_t n = 0; n < sizeof s2 / sizeof *s2; ++n)
38+
#if __STDC_VERSION__ >= 202311L
39+
printf("0x%02X ", s2[n]);
40+
#else
41+
printf("0x%02X ", +(unsigned char)s2[n]);
42+
#endif
43+
puts("}");
44+
printf(" u\"a猫🍌\" is a char16_t[%zu] holding { ", sizeof s3 / sizeof *s3);
45+
for(size_t n = 0; n < sizeof s3 / sizeof *s3; ++n)
46+
printf("0x%04" PRIXLEAST16" ", s3[n]);
47+
puts("}");
48+
printf(" U\"a猫🍌\" is a char32_t[%zu] holding { ", sizeof s4 / sizeof *s4);
49+
for(size_t n = 0; n < sizeof s4 / sizeof *s4; ++n)
50+
printf("0x%08" PRIXLEAST32" ", s4[n]);
51+
puts("}");
52+
printf(" L\"%ls\" is a wchar_t[%zu] holding { ", s5, sizeof s5 / sizeof *s5);
53+
for(size_t n = 0; n < sizeof s5 / sizeof *s5; ++n)
54+
printf("0x%08X ", (unsigned)s5[n]);
55+
puts("}");
56+
}
57+

0 commit comments

Comments
 (0)