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