]> git.draconx.ca Git - cdecl99.git/blob - src/cdecl.h
Add support for pointer declarators.
[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         CDECL_DECL_POINTER,
45 };
46
47 struct cdecl {
48         struct cdecl_declspec {
49                 struct cdecl_declspec *next;
50                 unsigned type;
51                 char *ident;
52         } *specifiers;
53
54         struct cdecl_declarator {
55                 struct cdecl_declarator *next;
56                 unsigned type;
57                 union {
58                         char *ident;
59                         struct cdecl_pointer {
60                                 struct cdecl_declspec   *qualifiers;
61                                 struct cdecl_declarator *declarator;
62                         } pointer;
63                 } u;
64         } *declarators;
65 };
66
67 struct cdecl *cdecl_parse_decl(const char *declstr);
68 void cdecl_free(struct cdecl *decl);
69
70 size_t cdecl_explain(char *buf, size_t n, struct cdecl *decl);
71
72 static inline int cdecl_spec_kind(struct cdecl_declspec *spec)
73 {
74         return spec->type & ~0xffu;
75 }
76
77 #endif