]> git.draconx.ca Git - cdecl99.git/blobdiff - src/cdecl-internal.h
libcdecl: Move specifier type determination into scanner.
[cdecl99.git] / src / cdecl-internal.h
index c85ca6180a781246772a8b0e0b2c45ada19991e6..4c5ed0ba1e6203a0343df271110877f528cf56b4 100644 (file)
 #define _(s) dgettext(PACKAGE, s)
 #define N_(s) s
 
+/* Pack the 4 "kind" bits of a valid cdecl specifier value into two bits. */
+#define PACK_KIND(x) ((( ((x>>8) - ((x)>>11)) ) >> 1) & 3)
+
+/* Expand a packed "kind" to its original value. */
+#define UNPACK_KIND(x) (0x100 << (x))
+
+/*
+ * Pack a valid cdecl specifier value (CDECL_TYPE_xxx, CDECL_STOR_xxx, etc.)
+ * into 8 bits.  We do this by encoding the specifier kind in the upper two
+ * bits, and the enumerated sequence in the lower 6 bits. */
+#define PACK_SPEC(x) (((x) & 0x3f) | (PACK_KIND(x) << 6))
+
+/*
+ * Expand a packed specifier to its original value.
+ */
+#define UNPACK_SPEC(x) (UNPACK_KIND((x) >> 6) | ((x) & 0x3f))
+
 /*
  * Pack a parser token into 7 bits.
  *
@@ -68,6 +85,18 @@ const char *cdecl__emit_specs(struct output_state *dst,
                               struct cdecl_declspec *s,
                               unsigned mask);
 
-int cdecl__to_keyword(const char *s, int len, int english_mode);
+/*
+ * If s is a (len bytes long) string corresponding to a declaration
+ * specifier, then:
+ *
+ *   - bits 7:0 (LSB) of the return value is the packed specifier type, and
+ *   - bits 15:8 of the return value is the packed parser token.
+ *
+ * Otherwise, if english_mode is nonzero and s is an "english keyword",
+ * returns the appropriate packed parser token in bits 15:8.
+ *
+ * Otherwise, PACK_TOKEN(T_IDENT) is returned in bits 15:8.
+ */
+unsigned cdecl__to_keyword(const char *s, int len, int english_mode);
 
 #endif