]> git.draconx.ca Git - cdecl99.git/blobdiff - src/cdecl.h
Forbid arrays of functions.
[cdecl99.git] / src / cdecl.h
index 90a8804d3210aadbd5677fbbfabc9045d9bcf6d9..29dab352297848524708f925e907ff095db7086e 100644 (file)
@@ -1,5 +1,25 @@
+/*
+ *  Copyright © 2011 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
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #ifndef CDECL_H_
-#define CEDCL_H_
+#define CDECL_H_
+
+#include <stddef.h>
+#include <stdint.h>
 
 /* Declaration specifier kinds. */
 enum {
@@ -21,6 +41,7 @@ enum {
        CDECL_TYPE_UNSIGNED,
        CDECL_TYPE_BOOL,
        CDECL_TYPE_COMPLEX,
+       CDECL_TYPE_IMAGINARY,
        CDECL_TYPE_STRUCT,
        CDECL_TYPE_UNION,
        CDECL_TYPE_ENUM,
@@ -38,10 +59,16 @@ enum {
 
 /* Declarator types. */
 enum {
+       CDECL_DECL_NULL,
        CDECL_DECL_IDENT,
+       CDECL_DECL_POINTER,
+       CDECL_DECL_ARRAY,
+       CDECL_DECL_FUNCTION,
 };
 
 struct cdecl {
+       struct cdecl *next;
+
        struct cdecl_declspec {
                struct cdecl_declspec *next;
                unsigned type;
@@ -49,15 +76,31 @@ struct cdecl {
        } *specifiers;
 
        struct cdecl_declarator {
-               struct cdecl_declarator *next;
+               struct cdecl_declarator *child;
                unsigned type;
-               char *ident;
+               union {
+                       char *ident;
+                       struct cdecl_pointer {
+                               struct cdecl_declspec *qualifiers;
+                       } pointer;
+                       struct cdecl_array {
+                               char *vla;
+                               uintmax_t length;
+                       } array;
+                       struct cdecl_function {
+                               struct cdecl *parameters;
+                               _Bool variadic;
+                       } function;
+               } u;
        } *declarators;
 };
 
 struct cdecl *cdecl_parse_decl(const char *declstr);
 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)
 {
        return spec->type & ~0xffu;