]> git.draconx.ca Git - cdecl99.git/blobdiff - src/cdecl-internal.h
Port to use getline.h from dxcommon.
[cdecl99.git] / src / cdecl-internal.h
index a5f3272298a20aeb3422ce685849cf223f0ee730..335094c47511d7629564591a963dcc85d7a71a27 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Internal declarations for libcdecl.
- * Copyright © 2021, 2023 Nick Bowler
+ * Copyright © 2021, 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,6 +20,9 @@
 
 #include <stddef.h>
 #include <gettext.h>
+#include "cdecl.h"
+
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
 
 #define _(s) dgettext(PACKAGE, s)
 #define N_(s) s
@@ -67,7 +70,7 @@ static inline void cdecl__init_i18n(void)
 }
 #endif
 
-void cdecl__err(unsigned code, const char *fmt, const char *arg);
+void cdecl__err(const char *fmt, const char *arg);
 void cdecl__errmsg(unsigned msg);
 
 struct cdecl_declspec *cdecl__normalize_specs(struct cdecl_declspec *specs);
@@ -80,6 +83,7 @@ struct output_state {
 
 size_t cdecl__advance(struct output_state *dst, size_t amount);
 size_t cdecl__emit(struct output_state *dst, const char *src);
+size_t cdecl__emit_uint(struct output_state *dst, cdecl_uintmax val);
 size_t cdecl__strlcpy(char *dst, const char *src, size_t len);
 
 const char *cdecl__emit_specs(struct output_state *dst,
@@ -100,4 +104,58 @@ const char *cdecl__emit_specs(struct output_state *dst,
  */
 unsigned cdecl__to_keyword(const char *s, int len, int english_mode);
 
+/* Container for an allocated parser token's value */
+struct parse_item {
+       union {
+               struct cdecl_declarator declarator;
+               struct cdecl_declspec   declspec;
+               struct cdecl            decl;
+       } u;
+
+       char s[FLEXIBLE_ARRAY_MEMBER];
+};
+
+struct parse_item *cdecl__alloc_item(size_t s_sz);
+
+/*
+ * GCC enables -finline-small-functions in most optimization modes; this works
+ * on a highlevel estimate of how big a function actually is and occasionally
+ * this produces really bad results.
+ *
+ * While old versions of GCC do not support this attribute the result seems
+ * to be merely a warning so hopefully we can get away with this check and
+ * save a configure test.
+ */
+#ifndef CDECL__NOINLINE
+#  if __GNUC__
+#    define CDECL__NOINLINE __attribute__((__noinline__))
+#  else
+#    define CDECL__NOINLINE /**/
+#  endif
+#endif
+
+/*
+ * Build-time hook for white-box testing of memory allocation behaviour.
+ */
+#if TEST_MALLOC_HOOK
+void *test_realloc_hook(void *, size_t);
+
+static inline void *test_wrap_malloc(size_t n)
+{
+       return test_realloc_hook(0, n);
+}
+
+static inline void test_wrap_free(void *p)
+{
+       test_realloc_hook(p, 0);
+}
+
+#undef  realloc
+#define realloc test_realloc_hook
+#undef  malloc
+#define malloc test_wrap_malloc
+#undef  free
+#define free test_wrap_free
+#endif
+
 #endif