src/c-types-proto.lisp, src/c-types-impl.lisp: Qualifier name protocol.
authorMark Wooding <mdw@distorted.org.uk>
Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 29 May 2016 14:08:43 +0000 (15:08 +0100)
Add a new generic function `c-qualifier-keyword' to convert a Lisp
qualifier (confusingly, a Lisp keyword) into its C equivalent.
Currently, this just lowercases the name, but future keywords won't
necessarily have such simple mappings.

Also add `c-type-qualifier-keywords' to collect and convert the list of
keywords attached to a type, and use it in the type printing functions.
Take the opportunity to add more discretionary newlines in the pretty-
printing.

doc/SYMBOLS
doc/clang.tex
src/c-types-impl.lisp
src/c-types-proto.lisp

index 86ef28d..26b7c02 100644 (file)
@@ -145,9 +145,11 @@ c-types-proto.lisp
   argument-type                                 function
   argumentp                                     function
   c-name-case                                   function
+  c-qualifier-keyword                           generic
   c-type                                        macro class
   c-type-alias                                  macro
   c-type-equal-p                                generic
+  c-type-qualifier-keywords                     function
   c-type-qualifiers                             generic
   c-type-space                                  function
   c-type-subtype                                generic
@@ -681,6 +683,8 @@ c-fragment-text
   c-fragment
 c-function-arguments
   c-function-type
+c-qualifier-keyword
+  cl:symbol
 c-tagged-type-kind
   c-enum-type
   c-struct-type
index b94ef95..700033f 100644 (file)
@@ -343,6 +343,23 @@ argument lists for methods.  This is done by @|c-type-equal-p|.
   non-null then the final character of the returned string will be a space.
 \end{describe}
 
+\begin{describe}{gf}{c-qualifier-keyword @<qualifier> @> @<string>}
+  Return, as a string, the C keyword corresponding to the Lisp @<qualifier>.
+
+  There is a standard method, which deals with many qualifiers.  Additional
+  methods exist for qualifier keywords which need special handling, such as
+  @|:atomic|; they are not listed here explicitly.
+
+  \begin{describe}{meth}{c-qualifier-keyword @<keyword> @> @<string>}
+    Returns the @<keyword>'s print-name, in lower case.  This is sufficient
+    for the standard qualifiers @|:const|, @|:restrict|, and @|:volatile|.
+  \end{describe}
+\end{describe}
+
+\begin{describe}{fun}{c-type-qualifier-keywords @<c-type> @> @<list>}
+  Return the @<c-type>'s qualifiers, as a list of C keyword names.
+\end{describe}
+
 
 \subsection{Leaf types} \label{sec:clang.c-types.leaf}
 
index e4e9587..ce3aedf 100644 (file)
 
 (defmethod pprint-c-type ((type simple-c-type) stream kernel)
   (pprint-logical-block (stream nil)
-    (format stream "~{~(~A~) ~@_~}~A"
-           (c-type-qualifiers type)
+    (format stream "~{~A ~@_~}~A"
+           (c-type-qualifier-keywords type)
            (c-type-name type))
     (funcall kernel stream 0 t)))
 
 
 (defmethod pprint-c-type ((type tagged-c-type) stream kernel)
   (pprint-logical-block (stream nil)
-    (format stream "~{~(~A~) ~@_~}~(~A~) ~A"
-           (c-type-qualifiers type)
+    (format stream "~{~A ~@_~}~(~A~) ~A"
+           (c-type-qualifier-keywords type)
            (c-tagged-type-kind type)
            (c-type-tag type))
     (funcall kernel stream 0 t)))
                 (lambda (stream prio spacep)
                   (when spacep (c-type-space stream))
                   (maybe-in-parens (stream (> prio 1))
-                    (format stream "*~{~(~A~)~^ ~@_~}"
-                            (c-type-qualifiers type))
+                    (format stream "*~{~A~^ ~@_~}"
+                            (c-type-qualifier-keywords type))
                     (funcall kernel stream 1 (c-type-qualifiers type))))))
 
 ;; S-expression notation protocol.
index c8aa72e..1057321 100644 (file)
    The qualifiers of the returned type are the union of the requested
    QUALIFIERS and the qualifiers already applied to TYPE."))
 
+(export 'c-qualifier-keyword)
+(defgeneric c-qualifier-keyword (qualifier)
+  (:documentation "Return the C keyword for the QUALIFIER (a Lisp keyword).")
+  (:method ((qualifier symbol)) (string-downcase qualifier)))
+
+(export 'c-type-qualifier-keywords)
+(defun c-type-qualifier-keywords (c-type)
+  "Return the type's qualifiers, as a list of C keyword names."
+  (mapcar #'c-qualifier-keyword (c-type-qualifiers c-type)))
+
 (export 'c-type-subtype)
 (defgeneric c-type-subtype (type)
   (:documentation