X-Git-Url: https://git.draconx.ca/gitweb/cdecl99.git/blobdiff_plain/c4d0ba7251867ee9bdb8466357cba5a9fa352b76..HEAD:/src/keywords.gperf diff --git a/src/keywords.gperf b/src/keywords.gperf index 88b2476..97f8a8f 100644 --- a/src/keywords.gperf +++ b/src/keywords.gperf @@ -1,6 +1,6 @@ %{ /* - * Copyright © 2023 Nick Bowler + * Copyright © 2023-2024 Nick Bowler * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,71 +20,81 @@ #include #include #include "cdecl-internal.h" +#include "cdecl.h" #include "parse.h" static const struct keyword *in_word_set(); %} -%struct-type %readonly-tables %language=ANSI-C -%global-table -%pic +%7bit + +/* Note: the following options enable gperf-wordwrap.awk to do its thing */ +%define word-array-name wordlist_wrapped +%null-strings +%struct-type struct keyword { - int_least16_t name; - uint_least8_t token; + uint_least16_t val; }; %% -_Bool, (T_BOOL & 0x7f) -_Complex, (T_COMPLEX & 0x7f) -_Imaginary, (T_IMAGINARY & 0x7f) -auto, (T_AUTO & 0x7f) -char, (T_CHAR & 0x7f) -const, (T_CONST & 0x7f) -double, (T_DOUBLE & 0x7f) -enum, (T_ENUM & 0x7f) -extern, (T_EXTERN & 0x7f) -float, (T_FLOAT & 0x7f) -inline, (T_INLINE & 0x7f) -int, (T_INT & 0x7f) -long, (T_LONG & 0x7f) -register, (T_REGISTER & 0x7f) -restrict, (T_RESTRICT & 0x7f) -short, (T_SHORT & 0x7f) -signed, (T_SIGNED & 0x7f) -static, (T_STATIC & 0x7f) -struct, (T_STRUCT & 0x7f) -typedef, (T_TYPEDEF & 0x7f) -union, (T_UNION & 0x7f) -unsigned, (T_UNSIGNED & 0x7f) -void, (T_VOID & 0x7f) -volatile, (T_VOLATILE & 0x7f) +_Bool, (PACK_TOKEN(T_BOOL )<<8) | PACK_SPEC(CDECL_TYPE_BOOL) +_Complex, (PACK_TOKEN(T_COMPLEX )<<8) | PACK_SPEC(CDECL_TYPE_COMPLEX) +_Imaginary, (PACK_TOKEN(T_IMAGINARY)<<8) | PACK_SPEC(CDECL_TYPE_IMAGINARY) +auto, (PACK_TOKEN(T_AUTO )<<8) | PACK_SPEC(CDECL_STOR_AUTO) +char, (PACK_TOKEN(T_CHAR )<<8) | PACK_SPEC(CDECL_TYPE_CHAR) +const, (PACK_TOKEN(T_CONST )<<8) | PACK_SPEC(CDECL_QUAL_CONST) +double, (PACK_TOKEN(T_DOUBLE )<<8) | PACK_SPEC(CDECL_TYPE_DOUBLE) +enum, (PACK_TOKEN(T_ENUM )<<8) | PACK_SPEC(CDECL_TYPE_ENUM) +extern, (PACK_TOKEN(T_EXTERN )<<8) | PACK_SPEC(CDECL_STOR_EXTERN) +float, (PACK_TOKEN(T_FLOAT )<<8) | PACK_SPEC(CDECL_TYPE_FLOAT) +inline, (PACK_TOKEN(T_INLINE )<<8) | PACK_SPEC(CDECL_FUNC_INLINE) +int, (PACK_TOKEN(T_INT )<<8) | PACK_SPEC(CDECL_TYPE_INT) +long, (PACK_TOKEN(T_LONG )<<8) | PACK_SPEC(CDECL_TYPE_LONG) +register, (PACK_TOKEN(T_REGISTER )<<8) | PACK_SPEC(CDECL_STOR_REGISTER) +restrict, (PACK_TOKEN(T_RESTRICT )<<8) | PACK_SPEC(CDECL_QUAL_RESTRICT) +short, (PACK_TOKEN(T_SHORT )<<8) | PACK_SPEC(CDECL_TYPE_SHORT) +signed, (PACK_TOKEN(T_SIGNED )<<8) | PACK_SPEC(CDECL_TYPE_SIGNED) +static, (PACK_TOKEN(T_STATIC )<<8) | PACK_SPEC(CDECL_STOR_STATIC) +struct, (PACK_TOKEN(T_STRUCT )<<8) | PACK_SPEC(CDECL_TYPE_STRUCT) +typedef, (PACK_TOKEN(T_TYPEDEF )<<8) | PACK_SPEC(CDECL_STOR_TYPEDEF) +union, (PACK_TOKEN(T_UNION )<<8) | PACK_SPEC(CDECL_TYPE_UNION) +unsigned, (PACK_TOKEN(T_UNSIGNED )<<8) | PACK_SPEC(CDECL_TYPE_UNSIGNED) +void, (PACK_TOKEN(T_VOID )<<8) | PACK_SPEC(CDECL_TYPE_VOID) +volatile, (PACK_TOKEN(T_VOLATILE )<<8) | PACK_SPEC(CDECL_QUAL_VOLATILE) # english keywords -array, (T_ARRAY & 0x7f) | 0x80 -as, (T_AS & 0x7f) | 0x80 -declare, (T_DECLARE & 0x7f) | 0x80 -function, (T_FUNCTION & 0x7f) | 0x80 -of, (T_OF & 0x7f) | 0x80 -pointer, (T_POINTER & 0x7f) | 0x80 -returning, (T_RETURNING & 0x7f) | 0x80 -to, (T_TO & 0x7f) | 0x80 -type, (T_TYPE & 0x7f) | 0x80 -variable-length, (T_VLA & 0x7f) | 0x80 +array, (PACK_TOKEN(T_ARRAY )<<8) | 0x8000 +as, (PACK_TOKEN(T_AS )<<8) | 0x8000 +declare, (PACK_TOKEN(T_DECLARE )<<8) | 0x8000 +function, (PACK_TOKEN(T_FUNCTION )<<8) | 0x8000 +of, (PACK_TOKEN(T_OF )<<8) | 0x8000 +pointer, (PACK_TOKEN(T_POINTER )<<8) | 0x8000 +returning, (PACK_TOKEN(T_RETURNING)<<8) | 0x8000 +to, (PACK_TOKEN(T_TO )<<8) | 0x8000 +type, (PACK_TOKEN(T_TYPE )<<8) | 0x8000 +variable-length, (PACK_TOKEN(T_VLA )<<8) | 0x8000 %% -int cdecl__to_keyword(const char *s, int len, int english_mode) +unsigned cdecl__to_keyword(const char *s, int len, int english_mode) { const struct keyword *k; if ((k = in_word_set(s, len))) { - unsigned x = (k->token & 0x7fu); + uint_least16_t x = k->val; - if (english_mode || !(k->token & ~0x7fu)) { - if (T_VOID >= 256) - x += 256; - return x; + if (english_mode || !(x & 0x8000)) { + return x & 0x7fff; } } - return T_IDENT; + return (PACK_TOKEN(T_IDENT)<<8); +} + +static const char *wordlist_func(const struct keyword *k) +{ + unsigned x = (k->val >> 8) & 0x7f; + + if (!x) + return NULL; + return cdecl__token_name(UNPACK_TOKEN(x)); }