]> git.draconx.ca Git - cdecl99.git/blobdiff - src/cdecl-internal.h
libcdecl: Use macros for packing tokens into bytes.
[cdecl99.git] / src / cdecl-internal.h
index 713e1374e9a92c696e16c2f8ccfc84e12899a511..c85ca6180a781246772a8b0e0b2c45ada19991e6 100644 (file)
 #define _(s) dgettext(PACKAGE, s)
 #define N_(s) s
 
+/*
+ * Pack a parser token into 7 bits.
+ *
+ * Bison normally numbers user-defined tokens sequentially starting from 258.
+ * If api.token,raw is used, then the numbering starts from 3.  As we have
+ * about 50 tokens, the latter case will fit in 7 bits easily; in the former
+ * case the upper bits are constant so we don't need to store them.
+ */
+#define PACK_TOKEN(x) ((x) & 0x7f)
+
+/*
+ * Expand a packed token to its original value.
+ */
+#define UNPACK_TOKEN(x) ((x) | ((T_IDENT > 256) << 8))
+
 struct cdecl_error;
 struct cdecl_declspec;
 
@@ -35,16 +50,24 @@ static inline void cdecl__init_i18n(void)
 }
 #endif
 
-void cdecl__err(unsigned code, const char *fmt, ...);
+void cdecl__err(unsigned code, const char *fmt, const char *arg);
 void cdecl__errmsg(unsigned msg);
 
 struct cdecl_declspec *cdecl__normalize_specs(struct cdecl_declspec *specs);
 
-size_t cdecl__advance_(char **buf, size_t *n, size_t amount);
-size_t cdecl__advance(char **buf, size_t *n, size_t amount);
-size_t cdecl__explain_specs(char *buf, size_t n, struct cdecl_declspec *s,
-                                                 unsigned mask);
-size_t cdecl__explain_pre_specs(char *buf, size_t n, struct cdecl_declspec *s);
-size_t cdecl__explain_post_specs(char *buf, size_t n, struct cdecl_declspec *s);
+struct output_state {
+       char *dst;
+       size_t dstlen;
+       size_t accum;
+};
+
+size_t cdecl__advance(struct output_state *dst, size_t amount);
+size_t cdecl__emit(struct output_state *dst, const char *src);
+
+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);
 
 #endif