chiark / gitweb /
src/c-types-impl.lisp (make-or-intern-c-type): Pull out useful function.
[sod] / src / pset-impl.lisp
1 ;;; -*-lisp-*-
2 ;;;
3 ;;; Implementation for property sets
4 ;;;
5 ;;; (c) 2009 Straylight/Edgeware
6 ;;;
7
8 ;;;----- Licensing notice ---------------------------------------------------
9 ;;;
10 ;;; This file is part of the Sensible Object Design, an object system for C.
11 ;;;
12 ;;; SOD is free software; you can redistribute it and/or modify
13 ;;; it under the terms of the GNU General Public License as published by
14 ;;; the Free Software Foundation; either version 2 of the License, or
15 ;;; (at your option) any later version.
16 ;;;
17 ;;; SOD is distributed in the hope that it will be useful,
18 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ;;; GNU General Public License for more details.
21 ;;;
22 ;;; You should have received a copy of the GNU General Public License
23 ;;; along with SOD; if not, write to the Free Software Foundation,
24 ;;; Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
26 (cl:in-package #:sod)
27
28 ;;;--------------------------------------------------------------------------
29 ;;; Property representation.
30
31 (defmethod file-location ((prop property))
32   (file-location (p-location prop)))
33
34 ;;; Keywords.
35
36 (defmethod coerce-property-value
37     ((value symbol) (type (eql :symbol)) (wanted (eql :keyword)))
38   value)
39
40 (defmethod coerce-property-value
41     ((value string) (type (eql :id)) (wanted (eql :keyword)))
42   (string-to-symbol value :package :keyword))
43
44 (defmethod coerce-property-value
45     ((value string) (type (eql :string)) (wanted (eql :keyword)))
46   (string-to-symbol value :package :keyword :swap-hyphen nil))
47
48 ;;; Symbols.
49
50 (defmethod coerce-property-value
51     ((value string) (type (eql :id)) (wanted (eql :symbol)))
52   (string-to-symbol value))
53
54 (defmethod coerce-property-value
55     ((value string) (type (eql :string)) (wanted (eql :symbol)))
56   (string-to-symbol value :swap-hyphen nil))
57
58 ;;; Identifiers.
59
60 (defmethod coerce-property-value
61     ((value string) (type (eql :string)) (wanted (eql :id)))
62   value)
63
64 (defmethod coerce-property-value
65     ((value symbol) (type (eql :symbol)) (wanted (eql :id)))
66   (frob-identifier (symbol-name value)))
67
68 ;;; Types.
69
70 (defmethod coerce-property-value
71     ((value string) (type (eql :id)) (wanted (eql :type)))
72   (or (gethash value *module-type-map*)
73       (gethash value *declspec-map*)
74       (error "Unknown type `~A'." value)))
75
76 ;;;--------------------------------------------------------------------------
77 ;;; Property sets.
78
79 (defmethod print-object ((pset pset) stream)
80   (print-unreadable-object (pset stream :type t)
81     (pprint-logical-block (stream nil)
82       (let ((firstp t))
83         (pset-map (lambda (prop)
84                     (cond (firstp (setf firstp nil))
85                           (t (write-char #\space stream)
86                              (pprint-newline :linear stream)))
87                     (format stream "~:@<~S ~@_~S ~@_~S~:>"
88                             (p-name prop) (p-type prop) (p-value prop)))
89                   pset)))))
90
91 ;;;----- That's all, folks --------------------------------------------------