]> git.draconx.ca Git - cdecl99.git/blob - src/cdecl.h
Add missing copyright headers.
[cdecl99.git] / src / cdecl.h
1 /*
2  *  Copyright © 2011 Nick Bowler
3  *
4  *  This program is free software: you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation, either version 3 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #ifndef CDECL_H_
19 #define CDECL_H_
20
21 #include <stddef.h>
22 #include <stdint.h>
23
24 /* Declaration specifier kinds. */
25 enum {
26         CDECL_SPEC_TYPE = 0,
27         CDECL_SPEC_STOR = 256,
28         CDECL_SPEC_QUAL = 512,
29         CDECL_SPEC_FUNC = 1024,
30 };
31
32 enum {
33         CDECL_TYPE_VOID = CDECL_SPEC_TYPE,
34         CDECL_TYPE_CHAR,
35         CDECL_TYPE_SHORT,
36         CDECL_TYPE_INT,
37         CDECL_TYPE_LONG,
38         CDECL_TYPE_FLOAT,
39         CDECL_TYPE_DOUBLE,
40         CDECL_TYPE_SIGNED,
41         CDECL_TYPE_UNSIGNED,
42         CDECL_TYPE_BOOL,
43         CDECL_TYPE_COMPLEX,
44         CDECL_TYPE_STRUCT,
45         CDECL_TYPE_UNION,
46         CDECL_TYPE_ENUM,
47         CDECL_TYPE_IDENT,
48         CDECL_STOR_TYPEDEF = CDECL_SPEC_STOR,
49         CDECL_STOR_EXTERN,
50         CDECL_STOR_STATIC,
51         CDECL_STOR_AUTO,
52         CDECL_STOR_REGISTER,
53         CDECL_QUAL_RESTRICT = CDECL_SPEC_QUAL,
54         CDECL_QUAL_VOLATILE,
55         CDECL_QUAL_CONST,
56         CDECL_FUNC_INLINE = CDECL_SPEC_FUNC,
57 };
58
59 /* Declarator types. */
60 enum {
61         CDECL_DECL_NULL,
62         CDECL_DECL_IDENT,
63         CDECL_DECL_POINTER,
64         CDECL_DECL_ARRAY,
65 };
66
67 struct cdecl {
68         struct cdecl *next;
69
70         struct cdecl_declspec {
71                 struct cdecl_declspec *next;
72                 unsigned type;
73                 char *ident;
74         } *specifiers;
75
76         struct cdecl_declarator {
77                 struct cdecl_declarator *child;
78                 unsigned type;
79                 union {
80                         char *ident;
81                         struct cdecl_pointer {
82                                 struct cdecl_declspec *qualifiers;
83                         } pointer;
84                         struct cdecl_array {
85                                 char *vla;
86                                 uintmax_t length;
87                         } array;
88                 } u;
89         } *declarators;
90 };
91
92 struct cdecl *cdecl_parse_decl(const char *declstr);
93 void cdecl_free(struct cdecl *decl);
94
95 size_t cdecl_explain(char *buf, size_t n, struct cdecl *decl);
96
97 static inline int cdecl_spec_kind(struct cdecl_declspec *spec)
98 {
99         return spec->type & ~0xffu;
100 }
101
102 #endif