chiark / gitweb /
src/c-types-parse.lisp (parse-declarator): Refactor argument list parsing.
authorMark Wooding <mdw@distorted.org.uk>
Wed, 16 Dec 2015 05:57:20 +0000 (05:57 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 29 May 2016 14:09:03 +0000 (15:09 +0100)
The `argument-list' parser is now less monolithic: the work of parsing
individual arguments is given to new functions `arg-decl' and
`argument'.

Also, the interface between `argument-list' and its parent
`postfix-lparen' is changed.  Instead of simply returning its argument
list, `argument-list' now returns a function which can be applied to a
base type to produce the appropriate function type.

None of this changes any externally observable behaviour.

src/c-types-parse.lisp

index c797010762b14ed50eb8611e664cccbfee2dc428..e1a7dcd0e8d55f1740c7bf400e1bbf6397f8326f 100644 (file)
@@ -393,8 +393,24 @@ (defun parse-declarator (scanner base-type &key kernel abstractp)
                 (parse (seq ((name (funcall kernel-parser)))
                          (cons #'identity name))))
 
+              (arg-decl (abstractp)
+                (parse (seq ((base-type (parse-c-type scanner))
+                             (dtor (parse-declarator scanner base-type
+                                                     :abstractp abstractp)))
+                         dtor)))
+
+              (argument ()
+                ;; argument ::= type abstract-declspec
+
+                (parse (seq ((dtor (arg-decl t)))
+                         (make-argument (cdr dtor) (car dtor)))))
+
               (argument-list ()
-                ;; [argument [`,' argument]* [`,' `...']] | `...'
+                ;; argument-list ::=
+                ;;     [argument [`,' argument]* [`,' argument-tail]]
+                ;;   | argument-tail
+                ;;
+                ;; argument-tail ::= `...'
                 ;;
                 ;; The possibility of a trailing `,' `...' means that we
                 ;; can't use the standard `list' parser.  Note that, unlike
@@ -408,11 +424,7 @@ (defun parse-declarator (scanner base-type &key kernel abstractp)
                       (scanner-step scanner)
                       (return))
                     (multiple-value-bind (arg winp consumedp)
-                        (parse (seq ((base-type (parse-c-type scanner))
-                                     (dtor (parse-declarator scanner
-                                                             base-type
-                                                             :abstractp t)))
-                                 (make-argument (cdr dtor) (car dtor))))
+                        (argument)
                       (unless winp
                         (if (or consumedp args)
                             (return-from argument-list (values arg nil t))
@@ -421,16 +433,20 @@ (defun parse-declarator (scanner base-type &key kernel abstractp)
                     (unless (eq (token-type scanner) #\,)
                       (return))
                     (scanner-step scanner))
-                  (values (nreverse args) t args)))
+                  (values (let ((rargs (nreverse args)))
+                            (lambda (ret)
+                              (make-function-type ret rargs)))
+                          t
+                          args)))
 
               (postfix-lparen ()
                 ;; Postfix: `(' argument-list `)'
 
-                (parse (seq (#\( (args (argument-list)) #\))
+                (parse (seq (#\( (make (argument-list)) #\))
                          (postop "()" (state 10)
                            (cons (lambda (type)
                                    (funcall (car state)
-                                            (make-function-type type args)))
+                                            (funcall make type)))
                                  (cdr state))))))
 
               (dimension ()