]> git.draconx.ca Git - cdecl99.git/blobdiff - src/keywords.gperf
libcdecl: Use macros for packing tokens into bytes.
[cdecl99.git] / src / keywords.gperf
index 22566aa8b84936183195087b6e4927e368addef3..3f8af8410b6b272b0826d3e1b6f53ec2d9fc64ff 100644 (file)
@@ -37,41 +37,41 @@ struct keyword {
        uint_least8_t token;
 };
 %%
-_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     )
+_Complex,        PACK_TOKEN(T_COMPLEX  )
+_Imaginary,      PACK_TOKEN(T_IMAGINARY)
+auto,            PACK_TOKEN(T_AUTO     )
+char,            PACK_TOKEN(T_CHAR     )
+const,           PACK_TOKEN(T_CONST    )
+double,          PACK_TOKEN(T_DOUBLE   )
+enum,            PACK_TOKEN(T_ENUM     )
+extern,          PACK_TOKEN(T_EXTERN   )
+float,           PACK_TOKEN(T_FLOAT    )
+inline,          PACK_TOKEN(T_INLINE   )
+int,             PACK_TOKEN(T_INT      )
+long,            PACK_TOKEN(T_LONG     )
+register,        PACK_TOKEN(T_REGISTER )
+restrict,        PACK_TOKEN(T_RESTRICT )
+short,           PACK_TOKEN(T_SHORT    )
+signed,          PACK_TOKEN(T_SIGNED   )
+static,          PACK_TOKEN(T_STATIC   )
+struct,          PACK_TOKEN(T_STRUCT   )
+typedef,         PACK_TOKEN(T_TYPEDEF  )
+union,           PACK_TOKEN(T_UNION    )
+unsigned,        PACK_TOKEN(T_UNSIGNED )
+void,            PACK_TOKEN(T_VOID     )
+volatile,        PACK_TOKEN(T_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    ) | 0x80
+as,              PACK_TOKEN(T_AS       ) | 0x80
+declare,         PACK_TOKEN(T_DECLARE  ) | 0x80
+function,        PACK_TOKEN(T_FUNCTION ) | 0x80
+of,              PACK_TOKEN(T_OF       ) | 0x80
+pointer,         PACK_TOKEN(T_POINTER  ) | 0x80
+returning,       PACK_TOKEN(T_RETURNING) | 0x80
+to,              PACK_TOKEN(T_TO       ) | 0x80
+type,            PACK_TOKEN(T_TYPE     ) | 0x80
+variable-length, PACK_TOKEN(T_VLA      ) | 0x80
 %%
 int cdecl__to_keyword(const char *s, int len, int english_mode)
 {
@@ -81,9 +81,7 @@ int cdecl__to_keyword(const char *s, int len, int english_mode)
                unsigned x = (k->token & 0x7fu);
 
                if (english_mode || !(k->token & ~0x7fu)) {
-                       if (T_VOID >= 256)
-                               x += 256;
-                       return x;
+                       return UNPACK_TOKEN(x);
                }
        }
 
@@ -96,9 +94,5 @@ static const char *wordlist_func(const struct keyword *k)
 
        if (!x)
                return NULL;
-
-       if (T_VOID >= 256)
-               x += 256;
-
-       return cdecl__token_name(x);
+       return cdecl__token_name(UNPACK_TOKEN(x));
 }