]> git.draconx.ca Git - cdecl99.git/blobdiff - src/cdecl.h
libcdecl: Try unsigned __int64 for a 64-bit type.
[cdecl99.git] / src / cdecl.h
index 9b3e5da9a28b2ab7042b0e89d532723a5b040f59..39902f5607e35c3c9365a921fe9ffe71a13613db 100644 (file)
@@ -1,32 +1,52 @@
 /*
- *  Copyright © 2011 Nick Bowler
+ * Copyright © 2011, 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
- *  the Free Software Foundation, either version 3 of the License, or
- *  (at your option) any later version.
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
  *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- *  You should have received a copy of the GNU General Public License
- *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 #ifndef CDECL_H_
 #define CDECL_H_
 
-#include <stddef.h>
-#include <stdint.h>
+#include <stddef.h> /* for size_t */
+
+#if __GNUC__
+#  define CDECL__INLINE __inline
+#else
+#  define CDECL__INLINE inline
+#endif
+
+/* Compatibility typedefs */
+#if HAVE__BOOL
+typedef _Bool cdecl_bool;
+#else
+typedef signed char cdecl_bool;
+#endif
+
+#if HAVE_UNSIGNED_LONG_LONG_INT
+typedef unsigned long long cdecl_uintmax;
+#elif HAVE_UNSIGNED___INT64
+typedef unsigned __int64 cdecl_uintmax;
+#else
+typedef unsigned long cdecl_uintmax;
+#endif
 
 /* Declaration specifier kinds. */
 enum {
-       CDECL_SPEC_TYPE = 0,
-       CDECL_SPEC_STOR = 256,
-       CDECL_SPEC_QUAL = 512,
-       CDECL_SPEC_FUNC = 1024,
+       CDECL_SPEC_TYPE = 256,
+       CDECL_SPEC_STOR = 512,
+       CDECL_SPEC_QUAL = 1024,
+       CDECL_SPEC_FUNC = 2048
 };
 
 enum {
@@ -54,7 +74,7 @@ enum {
        CDECL_QUAL_RESTRICT = CDECL_SPEC_QUAL,
        CDECL_QUAL_VOLATILE,
        CDECL_QUAL_CONST,
-       CDECL_FUNC_INLINE = CDECL_SPEC_FUNC,
+       CDECL_FUNC_INLINE = CDECL_SPEC_FUNC
 };
 
 /* Declarator types. */
@@ -63,7 +83,7 @@ enum {
        CDECL_DECL_IDENT,
        CDECL_DECL_POINTER,
        CDECL_DECL_ARRAY,
-       CDECL_DECL_FUNCTION,
+       CDECL_DECL_FUNCTION
 };
 
 struct cdecl {
@@ -85,24 +105,59 @@ struct cdecl {
                        } pointer;
                        struct cdecl_array {
                                char *vla;
-                               uintmax_t length;
+                               cdecl_uintmax length;
                        } array;
                        struct cdecl_function {
                                struct cdecl *parameters;
-                               _Bool variadic;
+                               cdecl_bool variadic;
                        } function;
                } u;
        } *declarators;
 };
 
 struct cdecl *cdecl_parse_decl(const char *declstr);
+struct cdecl *cdecl_parse_english(const char *english);
 void cdecl_free(struct cdecl *decl);
 
 size_t cdecl_explain(char *buf, size_t n, struct cdecl *decl);
+size_t cdecl_declare(char *buf, size_t n, struct cdecl *decl);
 
-static inline int cdecl_spec_kind(struct cdecl_declspec *spec)
+static CDECL__INLINE int cdecl_spec_kind(const struct cdecl_declspec *spec)
 {
-       return spec->type & ~0xffu;
+       return spec->type & ~(CDECL_SPEC_TYPE-1u);
 }
 
+static CDECL__INLINE int cdecl_is_abstract(const struct cdecl_declarator *d)
+{
+       while (d->child)
+               d = d->child;
+
+       return d->type != CDECL_DECL_IDENT;
+}
+
+/* Error handling. */
+enum {
+       CDECL_ENOMEM = 1,
+       CDECL_ENOPARSE,
+
+       /* Obsolete error codes (no longer returned by the library) */
+       CDECL_EBADARRAY,
+       CDECL_EBADDECL,
+       CDECL_EBADPARAMS,
+       CDECL_EBADPOINTER,
+       CDECL_EBADQUAL,
+       CDECL_EBADRETURN,
+       CDECL_EBADSTOR,
+       CDECL_EBADTYPE,
+       CDECL_ENOTFUNC,
+       CDECL_EVOIDPARAM
+};
+
+struct cdecl_error {
+       unsigned code;
+       const char *str;
+};
+
+const struct cdecl_error *cdecl_get_error(void);
+
 #endif