From 0a07a01b29b05c3947992a1047c1881ff8fc8753 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Fri, 2 Jun 2017 13:12:56 +0200 Subject: [PATCH] mescc: Handle any const, by ignoring. * module/language/c99/compiler.mes (ast-strip-const): New function. (c99-input->ast): Use it. (type->size, type->description, ast->info): Remove const handling. --- module/language/c99/compiler.mes | 41 ++++++++++---------------------- 1 file changed, 12 insertions(+), 29 deletions(-) diff --git a/module/language/c99/compiler.mes b/module/language/c99/compiler.mes index d40c7621..e6353464 100644 --- a/module/language/c99/compiler.mes +++ b/module/language/c99/compiler.mes @@ -93,8 +93,18 @@ (cons (ast-strip-comment h) (ast-strip-comment t)))) (_ o))) +(define (ast-strip-const o) + (pmatch o + ((type-qual ,qual) (if (equal? qual "const") #f o)) + ((decl-spec-list (type-qual ,qual) . ,rest) + (if (equal? qual "const") `(decl-spec-list ,@rest) + `(decl-spec-list (type-qual ,qual) ,@(map ast-strip-const rest)))) + ((,h . ,t) (if (list? o) (filter-map ast-strip-const o) + (cons (ast-strip-const h) (ast-strip-const t)))) + (_ o))) + (define* (c99-input->ast #:key (defines '()) (includes '())) - (ast-strip-comment (c99-input->full-ast #:defines defines #:includes includes))) + ((compose ast-strip-const ast-strip-comment) (c99-input->full-ast #:defines defines #:includes includes))) (define (ast:function? o) (and (pair? o) (eq? (car o) 'fctn-defn))) @@ -976,8 +986,6 @@ (pmatch o ((decl-spec-list (type-spec (fixed-type ,type))) (type->size info type)) - ((decl-spec-list (type-spec (fixed-type ,type)) (type-qual ,qual)) - (type->size info type)) ((decl-spec-list (type-qual ,qual) (type-spec (fixed-type ,type))) (type->size info type)) ((struct-ref (ident ,type)) @@ -1266,8 +1274,6 @@ (pmatch o ((decl-spec-list (type-spec (fixed-type ,type))) (type->description info type)) - ((decl-spec-list (type-spec (fixed-type ,type)) (type-qual ,qual)) - (type->description info type)) ((struct-ref (ident ,type)) (type->description info `("struct" ,type))) (_ (let ((type (get-type (.types info) o))) @@ -1655,16 +1661,6 @@ (initzer->data f g ta t d '(initzer (p-expr (string ,string)))) (list-tail data (+ here ,size))))))))))) - ;; char const *p; - ((decl (decl-spec-list (type-spec (fixed-type ,type)) (type-qual ,qualifier)) (init-declr-list (init-declr (ptr-declr (pointer) (ident ,name))))) - (if (.function info) - (let* ((locals (add-local locals name type 1)) - (info (clone info #:locals locals))) - (append-text info (append (wrap-as (i386:value->accu 0)) - ((accu->ident info) name)))) - (let ((globals (append globals (list (ident->global name type 1 0))))) - (clone info #:globals globals)))) - ;; char *p; ((decl (decl-spec-list (type-spec (fixed-type ,type)) . _) (init-declr-list (init-declr (ptr-declr (pointer) (ident ,name))))) (if (.function info) @@ -2117,10 +2113,6 @@ ((decl (decl-spec-list (type-spec (void))) (init-declr-list (init-declr (ptr-declr (pointer) (ftn-declr (ident ,name) (param-list . ,param-list)))))) (declare name)) - ;; char const* itoa (); - ((decl (decl-spec-list (type-spec (fixed-type ,type)) (type-qual ,qual)) (init-declr-list (init-declr (ptr-declr (pointer) (ftn-declr (ident ,name) (param-list . ,param-list)))))) - (declare name)) - ;; char *strcpy (); ((decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ptr-declr (pointer) (ftn-declr (ident ,name) (param-list . ,param-list)))))) (declare name)) @@ -2154,7 +2146,7 @@ info) ;; ST_DATA const int *macro_ptr; - ((decl (decl-spec-list (stor-spec (extern)) (type-qual ,qual) (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ptr-declr (pointer) (ident ,name))))) + ((decl (decl-spec-list (stor-spec (extern)) (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ptr-declr (pointer) (ident ,name))))) info) ;; ST_DATA TokenSym **table_ident; @@ -2182,10 +2174,6 @@ ((decl (decl-spec-list (stor-spec (extern)) (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ptr-declr (pointer) (ident ,name))))) info) - ;; ST_DATA const int reg_classes[NB_REGS]; - ((decl (decl-spec-list (stor-spec (extern)) (type-qual ,qual) (type-spec (fixed-type ,type))) (init-declr-list (init-declr (array-of (ident ,name) (p-expr (fixed ,size)))))) - info) - ;; int i = 0, j = 0; ((decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ident ,name) . ,initzer) . ,rest)) (let loop ((inits `((init-declr (ident ,name) ,@initzer) ,@rest)) (info info)) @@ -2203,11 +2191,6 @@ `(decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list ,(car inits)))))))) - ;; const char *target; silly notation, const always operates to the LEFT (except when there's no left) - ((decl (decl-spec-list (type-qual ,qual) (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ptr-declr (pointer) (ident ,name))))) - ((ast->info info) - `(decl (decl-spec-list (type-spec (fixed-type ,type)) (type-qual ,qual)) (init-declr-list (init-declr (ptr-declr (pointer) (ident ,name))))))) - ((decl (decl-spec-list (stor-spec (typedef)) (type-spec (struct-ref (ident (,type))))) (init-declr-list (init-declr (ident ,name)))) (clone info #:types (cons (cons name (or (get-type types type) `(typedef ("struct" ,type)))) types)))