X-Git-Url: https://git.draconx.ca/gitweb/cdecl99.git/blobdiff_plain/363f15bd4b53bd90b86610b143695762037ae706..779cb9b02891e3f9fc8b9620bb630cf529d76c67:/src/cdecl.h diff --git a/src/cdecl.h b/src/cdecl.h index 9b3e5da..20a94f2 100644 --- a/src/cdecl.h +++ b/src/cdecl.h @@ -1,5 +1,5 @@ /* - * Copyright © 2011 Nick Bowler + * Copyright © 2011, 2021, 2023 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 @@ -23,10 +23,10 @@ /* 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 { @@ -96,13 +96,48 @@ struct cdecl { }; 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 inline int cdecl_spec_kind(const struct cdecl_declspec *spec) { - return spec->type & ~0xffu; + return spec->type & ~(CDECL_SPEC_TYPE-1u); } +static inline _Bool 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