From ff4e398b224974d6283f71aa78daef4210371e32 Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Thu, 26 May 2016 09:26:09 +0100 Subject: [PATCH] src/c-types-proto.lisp, src/c-types-impl.lisp: Qualifier name protocol. Organization: Straylight/Edgeware From: Mark Wooding 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 | 4 ++++ doc/clang.tex | 17 +++++++++++++++++ src/c-types-impl.lisp | 12 ++++++------ src/c-types-proto.lisp | 10 ++++++++++ 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/doc/SYMBOLS b/doc/SYMBOLS index 86ef28d..26b7c02 100644 --- a/doc/SYMBOLS +++ b/doc/SYMBOLS @@ -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 diff --git a/doc/clang.tex b/doc/clang.tex index b94ef95..700033f 100644 --- a/doc/clang.tex +++ b/doc/clang.tex @@ -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 @ @> @} + Return, as a string, the C keyword corresponding to the Lisp @. + + 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 @ @> @} + Returns the @'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 @ @> @} + Return the @'s qualifiers, as a list of C keyword names. +\end{describe} + \subsection{Leaf types} \label{sec:clang.c-types.leaf} diff --git a/src/c-types-impl.lisp b/src/c-types-impl.lisp index e4e9587..ce3aedf 100644 --- a/src/c-types-impl.lisp +++ b/src/c-types-impl.lisp @@ -120,8 +120,8 @@ (defmethod c-type-equal-p and (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))) @@ -262,8 +262,8 @@ (defmethod c-type-equal-p and ((type-a tagged-c-type) (type-b tagged-c-type)) (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))) @@ -309,8 +309,8 @@ (defmethod pprint-c-type ((type c-pointer-type) stream kernel) (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. diff --git a/src/c-types-proto.lisp b/src/c-types-proto.lisp index c8aa72e..1057321 100644 --- a/src/c-types-proto.lisp +++ b/src/c-types-proto.lisp @@ -57,6 +57,16 @@ (defgeneric qualify-c-type (type qualifiers) 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 -- [mdw]