runtime(c): Add missing syntax test files Commit: https://github.com/vim/vim/commit/866f229591eb8114eed2aa44b90f23d1828bf1ee Author: Doug Kearns <dougkea...@gmail.com> Date: Sat Jan 18 10:06:59 2025 +0100
runtime(c): Add missing syntax test files These were missing from commit c2a967a. closes: #16470 Signed-off-by: Doug Kearns <dougkea...@gmail.com> Signed-off-by: Christian Brabandt <c...@256bit.org> diff --git a/runtime/syntax/testdir/dumps/c_bool_constant_01.dump b/runtime/syntax/testdir/dumps/c_bool_constant_01.dump deleted file mode 100644 index b1d4e5732..000000000 --- a/runtime/syntax/testdir/dumps/c_bool_constant_01.dump +++ /dev/null @@ -1,20 +0,0 @@ -> +0&#ffffff0@74 -|~+0#4040ff13&| @73 -|~| @73 -|~| @73 -|~| @73 -|~| @73 -|~| @73 -|~| @73 -|~| @73 -|~| @73 -|~| @73 -|~| @73 -|~| @73 -|~| @73 -|~| @73 -|~| @73 -|~| @73 -|~| @73 -|~| @73 -| +0#0000000&@56|0|,|0|-|1| @8|A|l@1| diff --git a/runtime/syntax/testdir/dumps/c_integer_constant_01.dump b/runtime/syntax/testdir/dumps/c_integer_constant_01.dump index f1ebddd15..920731f70 100644 --- a/runtime/syntax/testdir/dumps/c_integer_constant_01.dump +++ b/runtime/syntax/testdir/dumps/c_integer_constant_01.dump @@ -17,4 +17,4 @@ @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 |}| @73 @75 -@57|1|8|,|5| @9|5|2|%| +@57|1|8|,|5| @9|4|6|%| diff --git a/runtime/syntax/testdir/dumps/c_integer_constant_02.dump b/runtime/syntax/testdir/dumps/c_integer_constant_02.dump index 0fd725164..3b03c7785 100644 --- a/runtime/syntax/testdir/dumps/c_integer_constant_02.dump +++ b/runtime/syntax/testdir/dumps/c_integer_constant_02.dump @@ -1,20 +1,20 @@ | +0&#ffffff0@74 +|/+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 +@75 |i+0#00e0003&|n|t| +0#0000000&|d| |=| |4+0#e000002&|2|;+0#0000000&| @63 |i+0#00e0003&|n|t| +0#0000000&|o| |=| |0+0#e000002&|5|2|;+0#0000000&| @62 -|i+0#00e0003&|n|t| +0#0000000&|x| |=| |0+0#e000002&|x|2|a|;+0#0000000&| @61 +>i+0#00e0003&|n|t| +0#0000000&|x| |=| |0+0#e000002&|x|2|a|;+0#0000000&| @61 |i+0#00e0003&|n|t| +0#0000000&|X| |=| |0+0#e000002&|X|2|A|;+0#0000000&| @61 ->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 +|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 @75 -|/+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 +|/+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 @75 |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 |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 |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 |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 +@75 |~+0#4040ff13&| @73 |~| @73 |~| @73 -|~| @73 -|~| @73 -|~| @73 | +0#0000000&@56|3|4|,|1| @9|B|o|t| diff --git a/runtime/syntax/testdir/input/c_bool_constant.c b/runtime/syntax/testdir/input/c_bool_constant.c new file mode 100644 index 000000000..8c8072886 --- /dev/null +++ b/runtime/syntax/testdir/input/c_bool_constant.c @@ -0,0 +1,11 @@ +// C boolean constants + +// Source: https://en.cppreference.com/w/c/language/bool_constant + +#include <assert.h> + +int main() +{ + assert(true == 1 && 0 == false); +} + diff --git a/runtime/syntax/testdir/input/c_character_constant.c b/runtime/syntax/testdir/input/c_character_constant.c new file mode 100644 index 000000000..0962f9b7e --- /dev/null +++ b/runtime/syntax/testdir/input/c_character_constant.c @@ -0,0 +1,40 @@ +// C character constants + +// Source: https://en.cppreference.com/w/c/language/character_constant + +#include <stddef.h> +#include <stdio.h> +#include <uchar.h> + +int main (void) +{ + printf("constant value "); + printf("-------- ---------- "); + + // integer character constants, + int c1='a'; printf("'a': %#010x ", c1); + int c2='๐'; printf("'๐': %#010x ", c2); // implementation-defined + + // multicharacter constant + int c3='ab'; printf("'ab': %#010x ", c3); // implementation-defined + + // 16-bit wide character constants + char16_t uc1 = u'a'; printf("'a': %#010x ", (int)uc1); + char16_t uc2 = u'ยข'; printf("'ยข': %#010x ", (int)uc2); + char16_t uc3 = u'็ซ'; printf("'็ซ': %#010x ", (int)uc3); + // implementation-defined (๐ maps to two 16-bit characters) + char16_t uc4 = u'๐'; printf("'๐': %#010x ", (int)uc4); + + // 32-bit wide character constants + char32_t Uc1 = U'a'; printf("'a': %#010x ", (int)Uc1); + char32_t Uc2 = U'ยข'; printf("'ยข': %#010x ", (int)Uc2); + char32_t Uc3 = U'็ซ'; printf("'็ซ': %#010x ", (int)Uc3); + char32_t Uc4 = U'๐'; printf("'๐': %#010x ", (int)Uc4); + + // wide character constants + wchar_t wc1 = L'a'; printf("'a': %#010x ", (int)wc1); + wchar_t wc2 = L'ยข'; printf("'ยข': %#010x ", (int)wc2); + wchar_t wc3 = L'็ซ'; printf("'็ซ': %#010x ", (int)wc3); + wchar_t wc4 = L'๐'; printf("'๐': %#010x ", (int)wc4); +} + diff --git a/runtime/syntax/testdir/input/c_integer_constant.c b/runtime/syntax/testdir/input/c_integer_constant.c new file mode 100644 index 000000000..155fd8f74 --- /dev/null +++ b/runtime/syntax/testdir/input/c_integer_constant.c @@ -0,0 +1,44 @@ +// C integer constants + +// Source: https://en.cppreference.com/w/c/language/integer_constant + +#include <inttypes.h> +#include <stdio.h> + +int main(void) +{ + printf("123 = %d ", 123); + printf("0123 = %d ", 0123); + printf("0x123 = %d ", 0x123); + printf("12345678901234567890ull = %llu ", 12345678901234567890ull); + // the type is a 64-bit type (unsigned long long or possibly unsigned long) + // even without a long suffix + printf("12345678901234567890u = %"PRIu64" ", 12345678901234567890u ); + + // printf("%lld ", -9223372036854775808); // Error: + // the value 9223372036854775808 cannot fit in signed long long, which + // is the biggest type allowed for unsuffixed decimal integer constant + + printf("%llu ", -9223372036854775808ull ); + // unary minus applied to unsigned value subtracts it from 2^64, + // this gives unsigned 9223372036854775808 + + printf("%lld ", -9223372036854775807ll - 1); + // correct way to form signed value -9223372036854775808 +} + +// The following variables are initialized to the same value: + +int d = 42; +int o = 052; +int x = 0x2a; +int X = 0X2A; +int b = 0b101010; // C23 + +// The following variables are also initialized to the same value: + +unsigned long long l1 = 18446744073709550592ull; // C99 +unsigned long long l2 = 18'446'744'073'709'550'592llu; // C23 +unsigned long long l3 = 1844'6744'0737'0955'0592uLL; // C23 +unsigned long long l4 = 184467'440737'0'95505'92LLU; // C23 + diff --git a/runtime/syntax/testdir/input/c_preprocessor_conditional.c b/runtime/syntax/testdir/input/c_preprocessor_conditional.c new file mode 100644 index 000000000..8faabcf10 --- /dev/null +++ b/runtime/syntax/testdir/input/c_preprocessor_conditional.c @@ -0,0 +1,40 @@ +// C preprocessor - conditional inclusion + +// Source: https://en.cppreference.com/w/c/preprocessor/conditional + +#define ABCD 2 +#include <stdio.h> + +int main(void) +{ + +#ifdef ABCD + printf("1: yes "); +#else + printf("1: no "); +#endif + +#ifndef ABCD + printf("2: no1 "); +#elif ABCD == 2 + printf("2: yes "); +#else + printf("2: no2 "); +#endif + +#if !defined(DCBA) && (ABCD < 2 * 4 - 3) + printf("3: yes "); +#endif + +// C23 directives #elifdef/#elifndef +#ifdef CPU + printf("4: no1 "); +#elifdef GPU + printf("4: no2 "); +#elifndef RAM + printf("4: yes "); // selected in C23 mode, may be selected in pre-C23 mode +#else + printf("4: no3 "); // may be selected in pre-C23 mode +#endif +} + diff --git a/runtime/syntax/testdir/input/c_preprocessor_embed.c b/runtime/syntax/testdir/input/c_preprocessor_embed.c new file mode 100644 index 000000000..3800cecef --- /dev/null +++ b/runtime/syntax/testdir/input/c_preprocessor_embed.c @@ -0,0 +1,31 @@ +// C preprocessor - binary resource inclusion + +// Source: https://en.cppreference.com/w/c/preprocessor/embed + +#include <stdint.h> +#include <stdio.h> + +const uint8_t image_data[] = { +#embed "image.png" +}; + +const char message[] = { +#embed "message.txt" if_empty('M', 'i', 's', 's', 'i', 'n', 'g', ' ') +,' +}; + +void dump(const uint8_t arr[], size_t size) +{ + for (size_t i = 0; i != size; ++i) + printf("%02X%c", arr[i], (i + 1) % 16 ? ' ' : ' '); + puts(""); +} + +int main() +{ + puts("image_data[]:"); + dump(image_data, sizeof image_data); + puts("message[]:"); + dump((const uint8_t*)message, sizeof message); +} + diff --git a/runtime/syntax/testdir/input/c_preprocessor_error.c b/runtime/syntax/testdir/input/c_preprocessor_error.c new file mode 100644 index 000000000..ea89a31e7 --- /dev/null +++ b/runtime/syntax/testdir/input/c_preprocessor_error.c @@ -0,0 +1,19 @@ +// C preprocessor - diagnostic directives + +// Source: https://en.cppreference.com/w/c/preprocessor/error + +#if __STDC__ != 1 +# error "Not a standard compliant compiler" +#endif + +#if __STDC_VERSION__ >= 202311L +# warning "Using #warning as a standard feature" +#endif + +#include <stdio.h> + +int main (void) +{ + printf("The compiler used conforms to the ISO C Standard !!"); +} + diff --git a/runtime/syntax/testdir/input/c_string_literal.c b/runtime/syntax/testdir/input/c_string_literal.c new file mode 100644 index 000000000..a59d58db6 --- /dev/null +++ b/runtime/syntax/testdir/input/c_string_literal.c @@ -0,0 +1,57 @@ +// C string literals + +// Source: https://en.cppreference.com/w/c/language/string_literal + +#include <inttypes.h> +#include <locale.h> +#include <stddef.h> +#include <stdio.h> +#include <stdlib.h> +#include <uchar.h> + +int main(void) +{ + char s1[] = "a็ซ๐"; // or "a\u732B\U0001F34C" +#if __STDC_VERSION__ >= 202311L + char8_t +#else + char +#endif + s2[] = u8"a็ซ๐"; + char16_t s3[] = u"a็ซ๐"; + char32_t s4[] = U"a็ซ๐"; + wchar_t s5[] = L"a็ซ๐"; + + setlocale(LC_ALL, "en_US.utf8"); + printf(" \"%s\" is a char[%zu] holding { ", s1, sizeof s1 / sizeof *s1); + for(size_t n = 0; n < sizeof s1 / sizeof *s1; ++n) + printf("0x%02X ", +(unsigned char)s1[n]); + puts("}"); + printf( +#if __STDC_VERSION__ >= 202311L + "u8\"%s\" is a char8_t[%zu] holding { " +#else + "u8\"%s\" is a char[%zu] holding { " +#endif +, s2, sizeof s2 / sizeof *s2); + for(size_t n = 0; n < sizeof s2 / sizeof *s2; ++n) +#if __STDC_VERSION__ >= 202311L + printf("0x%02X ", s2[n]); +#else + printf("0x%02X ", +(unsigned char)s2[n]); +#endif + puts("}"); + printf(" u\"a็ซ๐\" is a char16_t[%zu] holding { ", sizeof s3 / sizeof *s3); + for(size_t n = 0; n < sizeof s3 / sizeof *s3; ++n) + printf("0x%04" PRIXLEAST16" ", s3[n]); + puts("}"); + printf(" U\"a็ซ๐\" is a char32_t[%zu] holding { ", sizeof s4 / sizeof *s4); + for(size_t n = 0; n < sizeof s4 / sizeof *s4; ++n) + printf("0x%08" PRIXLEAST32" ", s4[n]); + puts("}"); + printf(" L\"%ls\" is a wchar_t[%zu] holding { ", s5, sizeof s5 / sizeof *s5); + for(size_t n = 0; n < sizeof s5 / sizeof *s5; ++n) + printf("0x%08X ", (unsigned)s5[n]); + puts("}"); +} + -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_dev/E1tZ4v7-002SkF-St%40256bit.org.