]> git.draconx.ca Git - cdecl99.git/blob - src/cdecl.h
Initial support for explaining declarations.
[cdecl99.git] / src / cdecl.h
1 #ifndef CDECL_H_
2 #define CEDCL_H_
3
4 #include <stddef.h>
5
6 /* Declaration specifier kinds. */
7 enum {
8         CDECL_SPEC_TYPE = 0,
9         CDECL_SPEC_STOR = 256,
10         CDECL_SPEC_QUAL = 512,
11         CDECL_SPEC_FUNC = 1024,
12 };
13
14 enum {
15         CDECL_TYPE_VOID = CDECL_SPEC_TYPE,
16         CDECL_TYPE_CHAR,
17         CDECL_TYPE_SHORT,
18         CDECL_TYPE_INT,
19         CDECL_TYPE_LONG,
20         CDECL_TYPE_FLOAT,
21         CDECL_TYPE_DOUBLE,
22         CDECL_TYPE_SIGNED,
23         CDECL_TYPE_UNSIGNED,
24         CDECL_TYPE_BOOL,
25         CDECL_TYPE_COMPLEX,
26         CDECL_TYPE_STRUCT,
27         CDECL_TYPE_UNION,
28         CDECL_TYPE_ENUM,
29         CDECL_TYPE_IDENT,
30         CDECL_STOR_TYPEDEF = CDECL_SPEC_STOR,
31         CDECL_STOR_EXTERN,
32         CDECL_STOR_STATIC,
33         CDECL_STOR_AUTO,
34         CDECL_STOR_REGISTER,
35         CDECL_QUAL_RESTRICT = CDECL_SPEC_QUAL,
36         CDECL_QUAL_VOLATILE,
37         CDECL_QUAL_CONST,
38         CDECL_FUNC_INLINE = CDECL_SPEC_FUNC,
39 };
40
41 /* Declarator types. */
42 enum {
43         CDECL_DECL_IDENT,
44 };
45
46 struct cdecl {
47         struct cdecl_declspec {
48                 struct cdecl_declspec *next;
49                 unsigned type;
50                 char *ident;
51         } *specifiers;
52
53         struct cdecl_declarator {
54                 struct cdecl_declarator *next;
55                 unsigned type;
56                 char *ident;
57         } *declarators;
58 };
59
60 struct cdecl *cdecl_parse_decl(const char *declstr);
61 void cdecl_free(struct cdecl *decl);
62
63 size_t cdecl_explain(char *buf, size_t n, struct cdecl *decl);
64
65 static inline int cdecl_spec_kind(struct cdecl_declspec *spec)
66 {
67         return spec->type & ~0xffu;
68 }
69
70 #endif