| 1 | <?php |
| 2 | namespace Std\Lib\Syntax; |
| 3 | |
| 4 | class C extends Language { |
| 5 | protected bool $preprocessor = true; |
| 6 | protected array $headerDirectives = ['include', 'include_next', 'embed']; |
| 7 | |
| 8 | protected array $tokens = [ |
| 9 | 'keyword' => [ |
| 10 | // C23 |
| 11 | 'alignas', 'alignof', 'bool', 'constexpr', 'false', 'nullptr', 'static_assert', 'thread_local', 'true', 'typeof', 'typeof_unqual', |
| 12 | '_BitInt', '_Decimal128', '_Decimal32', '_Decimal64', |
| 13 | // C11 |
| 14 | '_Alignas', '_Alignof', '_Atomic', '_Generic', '_Noreturn', '_Static_assert', '_Thread_local', |
| 15 | // C99 |
| 16 | 'inline', 'restrict', '_Bool', '_Complex', '_Imaginary', |
| 17 | // C89 |
| 18 | 'asm', 'auto', 'break', 'case', 'char', 'const', 'continue', 'default', 'do', 'double', 'else', 'enum', 'extern', 'float', 'fortran', 'for', 'goto', 'if', 'inline', |
| 19 | 'int', 'long', 'noreturn', 'register', 'return', 'short', 'signed', 'sizeof', 'static', 'struct', 'switch', 'typedef', 'union', 'unsigned', 'void', 'volatile', 'while', |
| 20 | // ISO |
| 21 | 'FILE', |
| 22 | ], |
| 23 | 'builtin' => [ |
| 24 | // ISO C |
| 25 | 'assert.h' => [ // C89 |
| 26 | 'assert', |
| 27 | ], |
| 28 | 'complex.h' => [ // C99 |
| 29 | 'cabs', 'cabsf', 'cabsl', 'cacos', 'cacosf', 'cacosl', 'cacosh', 'cacoshf', 'cacoshl', 'carg', 'cargf', 'cargl', 'casin', 'casinf', 'casinl', 'casinh', 'casinhf', 'casinhl', 'catan', 'catanf', 'catanl', 'catanh', 'catanhf', 'catanhl', 'ccos', 'ccosf', 'ccosl', 'ccosh', 'ccoshf', 'ccoshl', 'cexp', 'cexpf', 'cexpl', |
| 30 | 'cimag', 'cimagf', 'cimagl', 'clog', 'clogf', 'clogl', 'conj', 'conjf', 'conjl', 'cpow', 'cpowf', 'cpowl', 'cproj', 'cprojf', 'cprojl', 'creal', 'crealf', 'creall', |
| 31 | 'csqrt', 'csqrtf', 'csqrtl', 'csin', 'csinf', 'csinl', 'csinh', 'csinhf', 'csinhl', 'ctan', 'ctanf', 'ctanl', 'ctanh', 'ctanhf', 'ctanhl', |
| 32 | ], |
| 33 | 'ctype.h' => [ // C89 |
| 34 | 'isalnum', 'isalpha', 'isblank', 'iscntrl', 'isdigit', 'isgraph', 'islower', 'isprint', 'ispunct', 'isspace', 'isupper', 'isxdigit', 'tolower', 'toupper', |
| 35 | ], |
| 36 | 'errno.h' => [ // C89 |
| 37 | 'errno', |
| 38 | ], |
| 39 | 'fenv.h' => [ // C99 |
| 40 | 'feclearexcept', 'fegetround', 'fegetenv', 'fegetexpectflag', 'feholdexcept', 'feraiseexcept', 'fesetround', 'fesetenv', 'fesetexpectflag', 'fetestexcept', |
| 41 | 'feupdateenv', |
| 42 | // __STDC_IEC_60559_DFP__ |
| 43 | 'fe_dec_getround', 'fe_dec_setround', |
| 44 | ], |
| 45 | 'inttypes.h' => [ // C99 |
| 46 | 'imaxabs', 'imaxdiv', 'strtoimax', 'strtoumax', 'wcstoimax', 'wcstoumax', |
| 47 | ], |
| 48 | 'locale.h' => [ // C89 |
| 49 | 'localeconv', 'setlocale', |
| 50 | ], |
| 51 | 'math.h' => [ // C89 |
| 52 | 'acos', 'acosf', 'acosl', 'acosh', 'acoshf', 'acoshl', 'asin', 'asinf', 'asinl', 'asinh', 'asinhf', 'asinhl', 'atan', 'atanf', 'atanl', 'atanh', 'atanhf', 'atanhl', |
| 53 | 'atan2', 'atan2f', 'atan2l', 'cbrt', 'cbrtf', 'cbrtl', 'ceil', 'ceilf', 'ceill', 'copysign', 'copysignf', 'copysignl', 'cos', 'cosf', 'cosl', 'erf', 'erff', 'erfl', |
| 54 | 'erfc', 'erfcf', 'erfcl', 'exp', 'expf', 'expl', 'exp2', 'exp2f', 'exp2l', 'expml', 'expmlf', 'expmll', 'fabs', 'fabsf', 'fabsl', 'fdim', 'fdimf', 'fdiml', |
| 55 | 'floor', 'floorf', 'floorl', 'fma', 'fmaf', 'fmal', 'fmax', 'fmaxf', 'fmaxl', 'fmin', 'fminf', 'fminl', 'fpclassify', 'frexp', 'frexpf', 'frexpl', |
| 56 | 'hypot', 'hypotf', 'hypotl', 'ilogb', 'ilogbf', 'ilogbl', 'isfinite', 'isgreater', 'isgreaterequal', 'isinf', 'isless', 'islessequal', 'islessgreater', 'isnan', |
| 57 | 'isnormal', 'isunordered', 'ldexp', 'ldexpf', 'ldexpl', 'lgamma', 'lgammaf', 'lgammal', 'log', 'logf', 'logl', 'log10', 'log10f', 'log10l', 'log2', 'log2f', 'log2l', |
| 58 | 'logb', 'logbf', 'logbl', 'loglp', 'loglpf', 'loglpl', 'lrint', 'lrintf', 'lrintl', 'llrint', 'llrintf', 'llrintl', 'lround', 'lroundf', 'lroundl', 'llround', 'llroundf', 'llroundl', 'modf', 'modff', 'modfl', 'nan', 'nanf', 'nanl', 'nearbyint', 'nearbyintf', 'nearbyintl', 'nextafter', 'nextafterf', 'nextafterl', |
| 59 | 'nexttoward', 'nexttowardf', 'nexttowardl', 'pow', 'powf', 'powl', 'remainder', 'remainderf', 'remainderl', 'remquo', 'remquof', 'remquol', 'rint', 'rintf', 'rintl', |
| 60 | 'round', 'roundf', 'roundl', 'scalbn', 'scalbnf', 'scalbnl', 'scalbln', 'scalblnf', 'scalblnl', 'signbit', 'sin', 'sinf', 'sinl', 'sinh', 'sinhf', 'sinhl', |
| 61 | 'sqrt', 'sqrtf', 'sqrtl', 'tan', 'tanf', 'tanl', 'tanh', 'tanhf', 'tanhl', 'tgamma', 'tgammaf', 'tgammal', 'trunc', 'truncf', 'truncl', |
| 62 | ], |
| 63 | 'setjmp.h' => [ // C89 |
| 64 | 'longjmp', 'setjmp', |
| 65 | ], |
| 66 | 'signal.h' => [ // C89 |
| 67 | 'raise', 'signal', |
| 68 | ], |
| 69 | 'stdarg.h' => [ // C89 |
| 70 | 'va_arg', 'va_copy', 'va_end', 'va_start', |
| 71 | ], |
| 72 | 'stdatomic.h' => [ // C11 |
| 73 | 'atomic_fetch_add', 'atomic_fetch_add_explicit', 'atomic_fetch_and', 'atomic_fetch_and_explicit', 'atomic_fetch_or', 'atomic_fetch_or_explicit', |
| 74 | 'atomic_fetch_sub', 'atomic_fetch_sub_explicit', 'atomic_fetch_xor', 'atomic_fetch_xor_explicit', 'atomic_flag', 'atomic_flag_clear', 'atomic_flag_clear_explicit', |
| 75 | 'atomic_flag_test_and_set', 'atomic_flag_test_and_set_explicit', 'atomic_init', 'atomic_is_lock_free', 'atomic_load', 'atomic_load_explicit', 'atomic_signal_fence', |
| 76 | 'atomic_store', 'atomic_store_explicit', 'atomic_thread_fence', 'kill_dependency', 'memory_order', |
| 77 | ], |
| 78 | 'stdbit.h' => [ // C23 |
| 79 | 'stdc_bit_ceil_uc', 'stdc_bit_ceil_us', 'stdc_bit_ceil_ui', 'stdc_bit_ceil_ul', 'stdc_bit_ceil_ull', 'stdc_bit_ceil', |
| 80 | 'stdc_bit_floor_uc', 'stdc_bit_floor_us', 'stdc_bit_floor_ui', 'stdc_bit_floor_ul', 'stdc_bit_floor_ull', 'stdc_bit_floor', |
| 81 | 'stdc_bit_width_uc', 'stdc_bit_width_us', 'stdc_bit_width_ui', 'stdc_bit_width_ul', 'stdc_bit_width_ull', 'stdc_bit_width', |
| 82 | 'stdc_count_ones_uc', 'stdc_count_ones_us', 'stdc_count_ones_ui', 'stdc_count_ones_ul', 'stdc_count_ones_ull', 'stdc_count_ones', |
| 83 | 'stdc_count_zeros_uc', 'stdc_count_zeros_us', 'stdc_count_zeros_ui', 'stdc_count_zeros_ul', 'stdc_count_zeros_ull', 'stdc_count_zeros', |
| 84 | 'stdc_first_leading_ones_uc', 'stdc_first_leading_ones_us', 'stdc_first_leading_ones_ui', 'stdc_first_leading_ones_ul', 'stdc_first_leading_ones_ull', |
| 85 | 'stdc_first_leading_ones', |
| 86 | 'stdc_first_leading_zeros_uc', 'stdc_first_leading_zeros_us', 'stdc_first_leading_zeros_ui', 'stdc_first_leading_zeros_ul', 'stdc_first_leading_zeros_ull', |
| 87 | 'stdc_first_leading_zeros', |
| 88 | 'stdc_first_trailing_ones_uc', 'stdc_first_trailing_ones_us', 'stdc_first_trailing_ones_ui', 'stdc_first_trailing_ones_ul', 'stdc_first_trailing_ones_ull', |
| 89 | 'stdc_first_trailing_ones', |
| 90 | 'stdc_first_trailing_zeros_uc', 'stdc_first_trailing_zeros_us', 'stdc_first_trailing_zeros_ui', 'stdc_first_trailing_zeros_ul', 'stdc_first_trailing_zeros_ull', |
| 91 | 'stdc_first_trailing_zeros', |
| 92 | 'stdc_has_single_bit_uc', 'stdc_has_single_bit_us', 'stdc_has_single_bit_ui', 'stdc_has_single_bit_ul', 'stdc_has_single_bit_ull', 'stdc_has_single_bit', |
| 93 | 'stdc_leading_ones_uc', 'stdc_leading_ones_us', 'stdc_leading_ones_ui', 'stdc_leading_ones_ul', 'stdc_leading_ones_ull', 'stdc_leading_ones', |
| 94 | 'stdc_leading_zeros_uc', 'stdc_leading_zeros_us', 'stdc_leading_zeros_ui', 'stdc_leading_zeros_ul', 'stdc_leading_zeros_ull', 'stdc_leading_zeros', |
| 95 | 'stdc_trailing_ones_uc', 'stdc_trailing_ones_us', 'stdc_trailing_ones_ui', 'stdc_trailing_ones_ul', 'stdc_trailing_ones_ull', 'stdc_trailing_ones', |
| 96 | 'stdc_trailing_zeros_uc', 'stdc_trailing_zeros_us', 'stdc_trailing_zeros_ui', 'stdc_trailing_zeros_ul', 'stdc_trailing_zeros_ull', 'stdc_trailing_zeros', |
| 97 | 'stdc_rotate_left_uc', 'stdc_rotate_left_us', 'stdc_rotate_left_ui', 'stdc_rotate_left_ul', 'stdc_rotate_left_ull', 'stdc_rotate_left', |
| 98 | 'stdc_rotate_right_uc', 'stdc_rotate_right_us', 'stdc_rotate_right_ui', 'stdc_rotate_right_ul', 'stdc_rotate_right_ull', 'stdc_rotate_right', |
| 99 | ], |
| 100 | 'stdckdint.h' => [ // C23 |
| 101 | 'ckd_add', 'ckd_sub', 'ckd_mul', |
| 102 | ], |
| 103 | 'stdio.h' => [ // C89 |
| 104 | 'clearerr', 'fclose', 'feof', 'ferror', 'fflush', 'fgetc', 'fgetpos', 'fgets', 'fopen', 'fprintf', 'fputc', 'fputs', 'fread', 'freopen', 'fscanf', 'fseek', |
| 105 | 'fseekpos', 'fsetpos', 'ftell', 'fwrite', 'getc', 'getchar', 'perror', 'printf', 'putc', 'putchar', 'puts', 'remove', 'rename', 'rewind', 'scanf', 'setbuf', |
| 106 | 'setvbuf', 'snprintf', 'sprintf', 'sscanf', 'tmpfile', 'tmpnam', 'ungetc', 'vfprintf', 'vfscanf', 'vprintf', 'vscanf', 'vsnprintf', 'vsprintf', 'vsscanf', |
| 107 | // __STDC_WANT_LIB_EXT1__ |
| 108 | 'fopen_s', 'fprintf_s', 'freopen_s', 'fscanf_s', 'gets_s', 'printf_s', 'scanf_s', 'snprintf_s', 'sprintf_s', 'sscanf_s', 'tmpfile_s', 'tmpnam_s', |
| 109 | 'vfprintf_s', 'vfscanf_s', 'vprintf_s', 'vscanf_s', 'vsnprintf_s', 'vsprintf_s', 'vsscanf_s', |
| 110 | ], |
| 111 | 'stdlib.h' => [ // C89 |
| 112 | 'abort', 'abs', 'aligned_alloc', 'at_quick_exit', 'atexit', 'atof', 'atoi', 'atol', 'atoll', 'bsearch', 'calloc', 'div', 'exit', '_Exit', 'free', 'free_sized', |
| 113 | 'free_aligned_sized', 'labs', 'llabs', 'ldiv', 'lldiv', 'malloc', 'mblen', 'mbtowc', 'mbstowcs', 'memalignment', 'qsort', 'quick_exit', 'rand', 'realloc', 'srand', |
| 114 | 'strfromd', 'strfromf', 'strfroml', 'strtod', 'strtof', 'strtold', 'strtol', 'strtoll', 'strtoul', 'strtoull', 'system', 'wctomb', 'wcstombs', |
| 115 | // __STDC_IEC_60559_DFP__ |
| 116 | 'strfromd32', 'strfromd64', 'strfromd128', 'strtod32', 'strtod64', 'strtod128', |
| 117 | // __STDC_WANT_IEC_60559_TYPES_EXT__ |
| 118 | 'strfromdN', 'strfromdNx', 'strfromencfN', 'strfromencdecdN', 'strfromencbindN', 'strfromfN', 'strfromfNx', 'strtodN', 'strtodNx', 'strtofN', 'strtofNx', |
| 119 | 'strtoencfN', 'strtoencdecdN', 'strtoencbindN', |
| 120 | // __STDC_WANT_LIB_EXT1__ |
| 121 | 'abort_handler_s', 'bsearch_s', 'getenv_s', 'ignore_handler_s', 'mbstowcs_s', 'qsort_s', 'set_constraint_handler_s', 'wcstomb_s', 'wcstombs_s', |
| 122 | ], |
| 123 | 'stdmchar.h' => [ // C29 |
| 124 | 'stdc_mcnrtoc16n', 'stdc_mcnrtoc32n', 'stdc_mcnrtoc8n', 'stdc_mcnrtomcn', 'stdc_mcnrtomwcn', 'stdc_mcsnrtoc16sn', 'stdc_mcsnrtoc32sn', 'stdc_mcsnrtoc8sn', |
| 125 | 'stdc_mwcnrtomcn', 'stdc_mcsnrtomcsn', 'stdc_mwcnrtomwcn', 'stdc_mcsnrtomwcsn', 'stdc_mwcnrtoc16n', 'stdc_mwcnrtoc32n', 'stdc_mwcnrtoc8n', 'stdc_mwcsnrtoc16sn', |
| 126 | 'stdc_mwcsnrtoc32sn', 'stdc_mwcsnrtoc8sn', 'stdc_mwcsnrtomcsn', 'stdc_mwcsnrtomwcsn', 'stdc_c16nrtoc16n', 'stdc_c16nrtoc32n', 'stdc_c16nrtoc8n', 'stdc_c16nrtomcn', |
| 127 | 'stdc_c16nrtomwcn', 'stdc_c16snrtoc8sn', 'stdc_c16snrtoc16sn', 'stdc_c16snrtoc32sn', 'stdc_c16snrtomwcsn', 'stdc_c16snrtomcsn', 'stdc_c32nrtoc16n', 'stdc_c32nrtoc32n', |
| 128 | 'stdc_c32nrtoc8n', 'stdc_c32nrtomcn', 'stdc_c32nrtomwcn', 'stdc_c32snrtoc16sn', 'stdc_c32snrtoc32sn', 'stdc_c32snrtoc8sn', 'stdc_c32snrtomcsn', 'stdc_c32snrtomwcsn', |
| 129 | 'stdc_c8nrtoc16n', 'stdc_c8nrtoc32n', 'stdc_c8nrtoc8n', 'stdc_c8nrtomcn', 'stdc_c8nrtomwcn', 'stdc_c8snrtoc16sn', 'stdc_c8snrtoc32sn', 'stdc_c8snrtoc8sn', 'stdc_c8snrtomwcsn', 'stdc_c8snrtomcsn', |
| 130 | ], |
| 131 | 'string.h' => [ // C89 |
| 132 | 'memccpy', 'memchr', 'memcmp', 'memcpy', 'memcpy_s', 'memmove', 'memmove_s', 'memset', 'memset_explicit', 'memset_s', |
| 133 | 'strcat', 'strcat_s', 'strchr', 'strcmp', 'strcoll', 'strcpy', 'strcpy_s', 'strcspn', 'strdup', 'strlen', 'strncat', 'strncat_s', 'strncmp', 'strncpy', 'strncpy_s', |
| 134 | 'strndup', 'strnlen_s', 'strpbrk', 'strrchr', 'strspn', 'strstr', 'strtok', 'strtok_s', 'strxfrm', |
| 135 | // __STD_WANT_LIB_EXT1__ |
| 136 | 'memcpy_s', 'memmove_s', 'memset_s', 'strcat_s', 'strcpy_s', 'strerror_s', 'strerrorlen_s', 'strncat_s', 'strncpy_s', 'strnlen_s', 'strtok_s', |
| 137 | ], |
| 138 | 'threads.h' => [ // C11 |
| 139 | 'call_once', 'cnd_broadcast', 'cnd_destroy', 'cnd_init', 'cnd_signal', 'cnd_timedwait', 'cnd_wait', |
| 140 | 'mtx_destroy', 'mtx_init', 'mtx_lock', 'mtx_timedlock', 'mtx_trylock', 'mtx_unlock', |
| 141 | 'thrd_create', 'thrd_current', 'thrd_detach', 'thrd_equal', 'thrd_exit', 'thrd_join', 'thrd_sleep', 'thrd_yield', 'tss_create', 'tss_delete', 'tss_get', 'tss_set', |
| 142 | ], |
| 143 | 'time.h' => [ // C89 |
| 144 | 'asctime', 'clock', 'ctime', 'difftime', 'gmtime', 'gmtime_r', 'localtime', 'localtime_r', 'mktime', |
| 145 | 'strftime', 'time', 'timegm', |
| 146 | // __STD_WANT_LIB_EXT1__ |
| 147 | 'asctime_s', 'ctime_s', 'gmtime_s', 'localtime_s', |
| 148 | ], |
| 149 | 'uchar.h' => [ // C11 |
| 150 | 'c8rtomb', 'c16rtomb', 'c32rtomb', 'mbrtoc8', 'mbrtoc16', 'mbrtoc32', |
| 151 | ], |
| 152 | 'wchar.h' => [ // C95 |
| 153 | 'wcscat', 'wcscat_s', 'wcschr', 'wcscmp', 'wcscpy', 'wcscpy_s', 'wcscroll', 'wcscroll', 'wcscspn', 'wcslen', 'wcsncpy', 'wcsncpy_s', 'wcsncat', 'wcsncat_s', |
| 154 | 'wcsncmp', 'wcsnlen_s', 'wcsrchr', 'wcspbrk', 'wcsstr', 'wcstok', 'wcstok_s', 'wcsxfrm', |
| 155 | 'wmemchr', 'wmemcmp', 'wmemcpy', 'wmemcpy_s', 'wmemmove', 'wmemmove_s', 'wmemset', |
| 156 | // __STDC_IEC_60559_DFP__ |
| 157 | 'wcstod32', 'wcstod64', 'wcstod128', |
| 158 | // __STDC_IEC_60559_TYPES__ |
| 159 | 'encptr', 'nptr', |
| 160 | // __STDC_WANT_LIB_EXT1__ |
| 161 | 'fwprintf_s', 'fwscanf_s', 'mvsrtowcs_s', 'snwprinf_s', 'swprintf_s', 'swscanf_s', 'vfwprintf_s', 'vfwscanf_s', 'vsnwprinf_s', 'vswprintf_s', 'vswscanf_s', |
| 162 | 'wcrtomb_s', 'wcscat_s', 'wcsncat_s', 'wcstok_s', 'wcsnlen_s', 'wcscpy_s', 'wcsncpy_s', 'wcsrtombs_s', 'wmemcpy_s', 'wmemmove_s', 'wprintf_s', 'wscanf_s', |
| 163 | ], |
| 164 | 'wctype.h' => [ // C95 |
| 165 | 'iswalnum', 'iswalpha', 'iswblank', 'iswcntrl', 'iswctype', 'iswdigit', 'iswgraph', 'iswlower', 'iswprint', 'iswpunct', 'iswspace', 'iswupper', 'iswxdigit', |
| 166 | 'towctrans', 'towlower', 'towupper', |
| 167 | 'wctrans', 'cwtype', |
| 168 | ], |
| 169 | ], |
| 170 | 'preprocessor' => [ |
| 171 | // C23 |
| 172 | '#elifdef', '#elifndef', '#embed', '#warning', '__has_include', '__has_embed', '__has_c_attribute', |
| 173 | // C99 |
| 174 | '#_Pragma', |
| 175 | // C89 |
| 176 | '#if', '#elif', '#else', '#endif', '#ifdef', '#ifndef', '#define', '#undef', '#include', '#line', '#error', '#pragma', '#defined', |
| 177 | ], |
| 178 | 'type' => [ |
| 179 | 'errno.h' => [ |
| 180 | 'errno_t', |
| 181 | ], |
| 182 | 'inttypes.h' => [ |
| 183 | 'intmax_t', 'uintmax_t', 'imaxdiv_t', |
| 184 | ], |
| 185 | 'iso646.h' => [ |
| 186 | 'and'/*&&*/, 'and_eq'/*&=*/, 'bitand'/*&*/, 'bitor'/*|*/, 'compl'/*~*/, 'not'/*!*/, 'not_eq'/*!=*/, 'or'/*||*/, 'or_eq',/*|=*/ 'xor'/*^*/, 'xor_eq'/*^=*/, |
| 187 | ], |
| 188 | 'setjmp.h' => [ |
| 189 | 'jmp_buf', |
| 190 | ], |
| 191 | 'signal.h' => [ |
| 192 | 'sig_atomic_t', |
| 193 | ], |
| 194 | 'stdatomic.h' => [ |
| 195 | 'atomic_bool', 'atomic_char', 'atomic_schar', 'atomic_uchar', 'atomic_short', 'atomic_ushort', 'atomic_int', 'atomic_uint', 'atomic_long', 'atomic_ulong', |
| 196 | 'atomic_llong', 'atomic_ullong', 'atomic_char8_t', 'atomic_char16_t', 'atomic_char32_t', 'atomic_wchar_t', 'atomic_int_least8_t', 'atomic_uint_least8_t', |
| 197 | 'atomic_int_least16_t', 'atomic_uint_least16_t', 'atomic_int_least32_t', 'atomic_uint_least32_t', 'atomic_int_least64_t', 'atomic_uint_least64_t', 'atomic_int_fast8_t', |
| 198 | 'atomic_uint_fast8_t', 'atomic_int_fast16_t', 'atomic_uint_fast16_t', 'atomic_int_fast32_t', 'atomic_uint_fast32_t', 'atomic_int_fast64_t', 'atomic_uint_fast64_t', |
| 199 | 'atomic_intptr_t', 'atomic_uintptr_t', 'atomic_size_t', 'atomic_ptrdiff_t', 'atomic_intmax_t', 'atomic_uintmax_t', |
| 200 | ], |
| 201 | 'stddef.h' => [ |
| 202 | 'max_align_t', 'nullptr', 'ptrdiff_t', 'size_t', |
| 203 | ], |
| 204 | 'stdio.h' => [ |
| 205 | 'FILE', 'size_t', 'fpos_t', |
| 206 | ], |
| 207 | 'stdint.h' => [ |
| 208 | 'int8_t', 'int16_t', 'int32_t', 'int64_t', |
| 209 | 'uint8_t', 'uint16_t', 'uint32_t', 'uint64_t', |
| 210 | 'fpos_t', 'intptr_t', 'intmax_t', 'uintptr_t', 'uintmax_t', |
| 211 | 'int_least8_t', 'int_least16_t', 'int_least32_t', 'int_least64_t', |
| 212 | 'uint_least8_t', 'uint_least16_t', 'uint_least32_t', 'uint_least64_t', |
| 213 | 'int_fast8_t', 'int_fast16_t', 'int_fast32_t', 'int_fast64_t', |
| 214 | 'uint_fast8_t', 'uint_fast16_t', 'uint_fast32_t', 'uint_fast64_t', |
| 215 | ], |
| 216 | 'stdmchar.h' => [ |
| 217 | 'stdc_mcerr', |
| 218 | ], |
| 219 | 'stdarg.h' => [ |
| 220 | 'va_list', |
| 221 | ], |
| 222 | 'threads.h' => [ |
| 223 | 'cnd_t', |
| 224 | 'mtx_t', |
| 225 | 'thrd_t', |
| 226 | 'thrd_start_t', |
| 227 | 'tss_t', |
| 228 | 'tss_dtor_t', |
| 229 | ], |
| 230 | 'time.h' => [ |
| 231 | 'rsize_t', 'clock_t', 'time_t', |
| 232 | ], |
| 233 | 'uchar.h' => [ |
| 234 | 'char8_t', 'char16_t', 'char32_t', 'mbstate_t', |
| 235 | ], |
| 236 | 'wchar.h' => [ |
| 237 | 'wchar_t', 'wint_t', |
| 238 | ], |
| 239 | 'wctype.h' => [ |
| 240 | 'wctrans_t', 'wctype_t', |
| 241 | ], |
| 242 | ], |
| 243 | ]; |
| 244 | |
| 245 | /** @var array よく使う定数(ヘッダーに関係なく色を付ける) */ |
| 246 | protected array $constants = [ |
| 247 | 'NULL', 'EOF', 'stdin', 'stdout', 'stderr', 'EXIT_SUCCESS', 'EXIT_FAILURE', 'RAND_MAX', |
| 248 | 'CHAR_BIT', 'CHAR_MIN', 'CHAR_MAX', 'SCHAR_MIN', 'SCHAR_MAX', 'UCHAR_MAX', 'SHRT_MIN', 'SHRT_MAX', 'USHRT_MAX', |
| 249 | 'INT_MIN', 'INT_MAX', 'UINT_MAX', 'LONG_MIN', 'LONG_MAX', 'ULONG_MAX', 'LLONG_MIN', 'LLONG_MAX', 'ULLONG_MAX', |
| 250 | 'INT8_MIN', 'INT8_MAX', 'INT16_MIN', 'INT16_MAX', 'INT32_MIN', 'INT32_MAX', 'INT64_MIN', 'INT64_MAX', |
| 251 | 'UINT8_MAX', 'UINT16_MAX', 'UINT32_MAX', 'UINT64_MAX', 'SIZE_MAX', 'PTRDIFF_MIN', 'PTRDIFF_MAX', |
| 252 | 'FLT_MAX', 'FLT_MIN', 'FLT_EPSILON', 'DBL_MAX', 'DBL_MIN', 'DBL_EPSILON', 'HUGE_VAL', 'INFINITY', 'NAN', |
| 253 | 'M_PI', 'M_E', 'SEEK_SET', 'SEEK_CUR', 'SEEK_END', 'BUFSIZ', 'FILENAME_MAX', |
| 254 | '__FILE__', '__LINE__', '__DATE__', '__TIME__', '__func__', '__STDC__', '__STDC_VERSION__', |
| 255 | ]; |
| 256 | |
| 257 | /** |
| 258 | * #includeされたヘッダーの関数と型だけに色を付ける |
| 259 | * #includeが1つも無い場合(ブログの抜粋等)は全部に色を付ける |
| 260 | */ |
| 261 | public function prepare(string $code): void { |
| 262 | $tokens = $this->tokens; |
| 263 | preg_match_all('~^[ \t]*#[ \t]*include[ \t]*[<"]([^>"\n]+)[>"]~m', $code, $m); |
| 264 | if (!empty($m[1])) { |
| 265 | $inc = array_flip(array_map('trim', $m[1])); |
| 266 | foreach (['builtin', 'type'] as $k) { |
| 267 | if (isset($tokens[$k])) $tokens[$k] = array_intersect_key($tokens[$k], $inc); |
| 268 | } |
| 269 | } |
| 270 | $this->words = $this->buildWords(['constant' => $this->constants] + $tokens); |
| 271 | } |
| 272 | } |