repos
/
smoke
/ annotate_shade
summary
|
shortlog
|
log
|
tree
|
commit
|
commitdiff
|
headdiff
|
annotate
|
headblob
|
headfilediff
|
filehistory
normal
|
plain
|
shade
|
zebra
Fix infinite loop when showing candidate functions.
Annotate for file src/overload-resolution.lisp
2009-04-17 tobias
1
;;; C++ overload resolution
15:26:55 '
2
;;; See: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2800.pdf
'
3
'
4
(in-package :smoke)
'
5
2009-07-22 tobias
6
(defun cstring= (string1 string2)
22:26:05 '
7
"Returns T when the C strings STRING1 and STRING2 are equal
'
8
and NIL otherwise."
'
9
(declare (optimize (speed 3) (safety 0)))
'
10
(dotimes (i array-total-size-limit)
'
11
(let ((char1 (mem-aref string1 :char i))
'
12
(char2 (mem-aref string2 :char i)))
'
13
(when (/= char1 char2)
'
14
(return-from cstring= nil))
'
15
(when (or (= 0 char1)
'
16
(= 0 char2))
'
17
(return-from cstring= (= char1 char2))))))
'
18
2009-06-22 tobias
19
(declaim (inline cmp))
12:18:08 '
20
(defun cmp (a b)
2009-07-22 tobias
21
"Returns -1 if a < b; 0 if a = b and 1 if a > b"
22:26:05 '
22
(declare (values (integer -1 1)))
'
23
(if (< a b)
'
24
-1
'
25
(if (> a b)
'
26
1
'
27
0)))
2009-06-22 tobias
28
2009-07-22 tobias
29
(declaim (inline cstring-cmp))
22:26:05 '
30
(defun cstring-cmp (string1 string2)
'
31
"Compares the C strings STRING1 and STRING2."
'
32
(declare (foreign-pointer string1 string2)
'
33
(values (integer -1 1))
'
34
(optimize (speed 3)))
'
35
(dotimes (i array-total-size-limit (error "omg"))
'
36
(let ((char1 (mem-aref string1 :char i))
'
37
(char2 (mem-aref string2 :char i)))
'
38
(when (/= char1 char2)
'
39
(return-from cstring-cmp (if (< char1 char2) -1 1)))
'
40
(when (= 0 char1) ;; <=> (= 0 char2)
'
41
(return-from cstring-cmp 0)))))
2009-04-17 tobias
42
2009-06-22 tobias
43
(defun cstring/= (string1 string2)
12:18:08 '
44
"Returns T when the C strings STRING1 and STRING2 are not equal
'
45
and NIL otherwise."
2009-07-22 tobias
46
(declare (optimize (speed 3)))
22:26:05 '
47
(dotimes (i array-total-size-limit)
'
48
(let ((char1 (mem-aref string1 :char i))
'
49
(char2 (mem-aref string2 :char i)))
'
50
(when (/= char1 char2)
'
51
(return-from cstring/= i))
'
52
(when (= 0 char1)
'
53
(return-from cstring/= nil)))))
'
54
'
55
(declaim (inline smoke-method-name))
'
56
(defun smoke-method-name (method)
'
57
(mem-aref (smoke-array-pointer (smoke-module-method-names
'
58
(smoke-method-smoke method)))
'
59
:pointer
'
60
(the (smoke-index 0)
'
61
(method-slot-value method 'name))))
2009-04-17 tobias
62
2009-06-22 tobias
63
(defun method-cmp (method class-id name)
12:18:08 '
64
"Compares METHOD to the method with NAME of class CLASS-ID."
'
65
(declare (foreign-pointer name)
'
66
(type (smoke-index 0) class-id)
'
67
(smoke-method method)
2009-07-22 tobias
68
(values (integer -1 1))
2009-06-22 tobias
69
(optimize (speed 3) (debug 0) (safety 0)))
12:18:08 '
70
(let ((id-cmp (cmp (the (smoke-index 0) (method-slot-value method 'class))
'
71
(the (smoke-index 0) class-id))))
2009-07-22 tobias
72
(declare (type (integer -1 1) id-cmp)
22:26:05 '
73
(dynamic-extent id-cmp))
2009-06-22 tobias
74
(if (/= 0 id-cmp)
12:18:08 '
75
id-cmp
2009-07-22 tobias
76
(cstring-cmp (smoke-method-name method)
2009-06-22 tobias
77
name))))
12:18:08 '
78
'
79
(defun first-unabigious-index (smoke index)
'
80
(declare (type smoke-index index)
2009-04-17 tobias
81
(optimize (speed 3)))
2009-06-22 tobias
82
(if (>= index 0)
12:18:08 '
83
index
'
84
(mem-aref (smoke-module-ambiguous-method-list smoke)
'
85
'smoke-index
'
86
(- index))))
2009-04-17 tobias
87
2009-06-22 tobias
88
(defun find-method-for-class (name class)
12:18:08 '
89
"Returns the index of a method with name NAME for class CLASS."
'
90
(declare (type foreign-pointer name)
'
91
(type smoke-class class)
'
92
(optimize (speed 3)))
'
93
(let* ((start 1) ;; 0 is "no method"
2009-06-30 tobias
94
(class-id (id class))
22:47:39 '
95
(smoke (smoke class))
2009-07-03 tobias
96
(end (smoke-array-length (smoke-module-method-maps smoke))))
2009-07-08 tobias
97
(declare (type (smoke-index 0) start end))
2009-06-22 tobias
98
(loop until (> start end) do
12:18:08 '
99
(let* ((index (the smoke-index (floor (+ end start) 2)))
'
100
(method (make-smoke-method
'
101
:smoke smoke
'
102
:id (the (smoke-index 0)
'
103
(first-unabigious-index
'
104
smoke
'
105
(foreign-slot-value
'
106
(mem-aref (smoke-array-pointer
'
107
(smoke-module-method-maps
'
108
smoke))
'
109
'smoke-method-map index)
'
110
'smoke-method-map
'
111
'method)))))
2009-07-22 tobias
112
(cmp (the (integer -1 1) (method-cmp method class-id name))))
22:26:05 '
113
(declare (type (integer -1 1) cmp)
2009-07-08 tobias
114
(dynamic-extent method index cmp))
2009-07-22 tobias
115
(ecase cmp
22:26:05 '
116
(-1 (setf start (1+ index)))
'
117
(0 (return-from find-method-for-class index))
'
118
(1 (setf end (1- index)))))))
2009-06-22 tobias
119
-1)
2009-04-17 tobias
120
2009-08-27 tobias
121
(defmacro push-candidate-method (index name argument-count class methods)
2009-06-22 tobias
122
(with-gensyms (method-map method-index method ambig-index i smoke)
12:18:08 '
123
`(let* ((,smoke (smoke ,class))
'
124
(,method-map (mem-aref
'
125
(smoke-array-pointer
'
126
(smoke-module-method-maps ,smoke))
'
127
'smoke-method-map
2009-07-22 tobias
128
,index))
2009-06-22 tobias
129
(,method-index (foreign-slot-value ,method-map 'smoke-method-map 'method))
12:18:08 '
130
(,method (make-smoke-method
'
131
:smoke ,smoke
'
132
:id (first-unabigious-index
'
133
,smoke
'
134
,method-index))))
'
135
(declare (type smoke-index ,method-index))
'
136
(if (cstring/= ,name
'
137
(smoke-method-name ,method))
'
138
nil
'
139
(progn
'
140
(when (= (the smoke-index ,argument-count)
'
141
(the smoke-index (get-arguments-length ,method)))
'
142
(if (< ,method-index 0)
'
143
(let ((,ambig-index (- ,method-index)))
'
144
(declare (type smoke-index ,ambig-index))
'
145
(loop as ,i = (the smoke-index
'
146
(mem-aref (smoke-module-ambiguous-method-list
'
147
,smoke)
'
148
'smoke-index
'
149
,ambig-index))
'
150
while (> (the smoke-index ,i) 0) do
2009-08-27 tobias
151
(incf ,ambig-index)
11:43:13 '
152
(push (make-smoke-method :smoke ,smoke
'
153
:id ,i)
'
154
,methods)))
'
155
(push ,method ,methods)))
2009-06-22 tobias
156
t)))))
2009-05-11 tobias
157
2009-08-30 tobias
158
(defun all-smoke-superclasses (class)
14:12:44 '
159
"Returns a list of all super-classes of CLASS and CLASS itself."
'
160
(declare (optimize (speed 3)))
'
161
(let ((classes (list class)))
'
162
(dolist (class (closer-mop:class-direct-superclasses class) classes)
'
163
(when (typep class 'smoke-standard-class)
'
164
(setf classes (append (all-smoke-superclasses class) classes))))))
'
165
2009-08-27 tobias
166
(defun viable-functions (name argument-count class)
11:43:13 '
167
"Returns a list of methods named NAME that take ARGUMENT-COUNT methods."
'
168
;; 13.3.2
'
169
;; FIXME make a lazy map-viable-functions to allow returning early,
'
170
;; when an exact match is found.
2009-06-22 tobias
171
(declare (optimize (speed 3)))
12:18:08 '
172
(with-foreign-string (name name)
2009-07-22 tobias
173
(let ((methods)
22:26:05 '
174
(smoke (smoke class)))
2009-08-27 tobias
175
(dolist (class (all-smoke-superclasses class))
2009-07-22 tobias
176
(let ((start-index (find-method-for-class name class)))
22:26:05 '
177
(declare (type smoke-index start-index))
'
178
(loop for index from start-index downto 1
'
179
while (push-candidate-method index name argument-count class
'
180
methods))
'
181
(loop for index from (1+ start-index)
'
182
to (the smoke-index (smoke-array-length
'
183
(smoke-module-method-maps smoke)))
'
184
while (push-candidate-method index name argument-count class
'
185
methods))))
2009-06-22 tobias
186
methods)))
12:18:08 '
187
2009-07-22 tobias
188
(eval-when (:compile-toplevel :load-toplevel :execute)
22:26:05 '
189
(defconstant +exact-match+ 0)
'
190
(defconstant +promotion+ 1)
'
191
(defconstant +conversion+ 2))
'
192
2009-07-08 tobias
193
(defclass std-conversion ()
20:41:19 '
194
((function-name :accessor conversion-function-name
'
195
:initarg :conversion-function-name))
'
196
(:documentation "A conversion"))
2009-04-17 tobias
197
2009-07-08 tobias
198
(defclass exact-match (std-conversion)
20:41:19 '
199
((rank :reader rank
'
200
:allocation :class
'
201
:type fixnum
'
202
:initform +exact-match+)))
2009-04-17 tobias
203
2009-07-08 tobias
204
(defclass promotion (std-conversion)
20:41:19 '
205
((rank :reader rank
'
206
:allocation :class
'
207
:type fixnum
'
208
:initform +promotion+)))
2009-04-17 tobias
209
2009-07-08 tobias
210
(defclass number-conversion (std-conversion)
20:41:19 '
211
((rank :reader rank
'
212
:allocation :class
'
213
:type fixnum
'
214
:initform +conversion+)))
2009-04-17 tobias
215
2009-07-08 tobias
216
(defclass pointer-conversion (std-conversion)
20:41:19 '
217
((rank :reader rank
'
218
:allocation :class
'
219
:type fixnum
'
220
:initform (1+ +conversion+))
'
221
(from :reader from
'
222
:initarg :from)
'
223
(to :reader to
'
224
:initarg :to)))
2009-04-17 tobias
225
2009-07-08 tobias
226
(defclass boolean-conversion (std-conversion)
20:41:19 '
227
((rank :reader rank
'
228
:allocation :class
'
229
:type fixnum
'
230
:initform (+ 2 +conversion+))))
2009-04-17 tobias
231
2009-07-08 tobias
232
(defclass user-conversion (std-conversion)
20:41:19 '
233
((rank :reader rank
'
234
:allocation :class
'
235
:type fixnum
'
236
:initform (+ 3 +conversion+))))
2009-04-17 tobias
237
2009-08-27 tobias
238
(defgeneric conversion< (conversion1 conversion2)
11:43:13 '
239
(:documentation
'
240
"Returns true when CONVERSION1 is better than CONVERSION2.")
2009-04-17 tobias
241
;; 13.3.3.2 Ranking implicit conversion sequences
15:26:55 '
242
;; 4
'
243
(:method (conversion1 conversion2)
2009-06-22 tobias
244
(declare (optimize (speed 3)))
2009-08-27 tobias
245
(or (null conversion2)
2009-07-08 tobias
246
(< (the fixnum (rank conversion1))
20:41:19 '
247
(the fixnum (rank conversion2)))))
2009-04-17 tobias
248
(:method ((conversion1 pointer-conversion) (conversion2 pointer-conversion))
2009-06-22 tobias
249
(declare (optimize (speed 3)))
2009-07-08 tobias
250
(if (eq (from conversion1) (from conversion2))
2009-04-17 tobias
251
;; A->B < A->C <=> B subclass of C
2009-07-08 tobias
252
(subtypep (to conversion1) (to conversion2))
20:41:19 '
253
(if (eq (to conversion1) (to conversion2))
2009-04-17 tobias
254
;; B->A < C->A <=> B subclass of C
2009-07-08 tobias
255
(subtypep (from conversion1) (from conversion2))
2009-04-17 tobias
256
nil))))
15:26:55 '
257
'
258
(defgeneric conversion= (conversion1 conversion2)
2009-08-27 tobias
259
(:documentation
11:43:13 '
260
"Returns true when the standard conversion sequence CONVERSION1
'
261
is indistinguishable from CONVERSION2.")
2009-04-17 tobias
262
(:method (conversion1 conversion2)
2009-07-08 tobias
263
(= (rank conversion1) (rank conversion2)))
2009-05-11 tobias
264
(:method ((conversion1 (eql nil)) (conversion2 (eql nil)))
2009-07-22 tobias
265
t)
22:26:05 '
266
(:method ((conversion1 pointer-conversion) (conversion2 pointer-conversion))
'
267
(and (not (conversion< conversion1 conversion2))
'
268
(not (conversion< conversion2 conversion1)))))
2009-04-17 tobias
269
15:26:55 '
270
(defun max-conversion (conversion1 conversion2)
2009-05-11 tobias
271
"Returns the greater conversion of CONVERSION1 and CONVERSION2."
2009-04-17 tobias
272
(if (null conversion2)
15:26:55 '
273
conversion1
2009-08-27 tobias
274
(if (conversion< conversion1 conversion2)
2009-04-17 tobias
275
conversion2
15:26:55 '
276
conversion1)))
2009-05-11 tobias
277
2010-02-20 tobias
278
(eval-when (:compile-toplevel :load-toplevel :execute)
17:24:36 '
279
(defun conversion-function (name &optional arg)
'
280
(if arg
'
281
`(if (using-typep)
'
282
`(,,name
'
283
(find-class ',(class-name ,arg)))
'
284
#'(lambda (object)
'
285
(funcall (fdefinition ,name)
'
286
object ,arg)))
'
287
`(if (using-typep)
'
288
,name
'
289
(fdefinition ,name)))))
'
290
2009-09-01 tobias
291
(defmacro make-match (type &optional (name ''identity)
11:44:21 '
292
(argument nil)
2009-05-11 tobias
293
&rest args)
2009-07-08 tobias
294
`(make-instance ,type
20:41:19 '
295
:conversion-function-name ,(conversion-function name argument)
'
296
2009-09-01 tobias
297
,@args))
2009-04-17 tobias
298
2009-05-11 tobias
299
(defun+using-type get-conversion-sequence object (object type &optional user)
2009-07-01 tobias
300
"Retrains a conversion sequence to convert a instance of type CLASS
2009-05-11 tobias
301
to an instance of type TYPE. When USER is true user conversions are considered."
2009-07-08 tobias
302
(if-let
14:56:52 '
303
(match (call-using-type exact-match object type))
'
304
(if (eql t match)
'
305
(make-match 'exact-match)
'
306
(make-match 'exact-match match))
'
307
(or (call-using-type promotion object type)
'
308
(call-using-type conversion object type)
'
309
(and user
'
310
(call-using-type user-conversion object type)))))
2009-04-17 tobias
311
2009-05-11 tobias
312
(defun+using-types standard-conversion-sequence (method classes &optional user)
11:07:39 '
313
"Returns the conversion sequences to convert the arguments of types CLASSES
'
314
to the types required by METHOD."
2009-08-27 tobias
315
(let ((max-rank)
11:43:13 '
316
(conversions))
'
317
(loop for type in (arguments method)
'
318
for class in classes do
'
319
(let ((rank (call-using-type get-conversion-sequence class type user)))
'
320
(when (null rank)
'
321
(setf max-rank nil)
'
322
(return nil))
'
323
(setf max-rank (max-conversion rank max-rank))
'
324
(push (conversion-function-name rank) conversions)))
'
325
(values max-rank (reverse conversions))))
2009-04-17 tobias
326
2009-05-11 tobias
327
(defun+using-types conversion-sequence (method classes)
11:07:39 '
328
(call-using-types standard-conversion-sequence method classes t))
2009-04-17 tobias
329
2009-08-27 tobias
330
(defun+using-types find-best-viable-function (name arguments class)
2009-05-11 tobias
331
"Returns the method named NAME of class CLASS that can be called
11:07:39 '
332
using arguments of types TYPES with the lowest conversion sequence."
'
333
(call-using-types find-best-viable-function2
'
334
(function-using-types conversion-sequence)
2009-08-27 tobias
335
name arguments class))
2009-04-17 tobias
336
2009-08-27 tobias
337
(defun+using-types find-best-viable-function2 (get-sequence name objects class)
11:43:13 '
338
(declare (type (function (t list) (values t function)) get-sequence))
2009-05-11 tobias
339
(when (and (using-typep)
11:07:39 '
340
(not (typep class 'smoke-standard-class)))
'
341
(throw 'unspecific-type class))
2009-05-11 tobias
342
(let ((viable-functions (viable-functions name (length objects)
2009-08-27 tobias
343
class))
2009-05-11 tobias
344
(best-rank)
2009-04-17 tobias
345
(best-method)
15:26:55 '
346
(conversions))
2009-08-27 tobias
347
(loop for method in viable-functions do
11:43:13 '
348
(multiple-value-bind (rank method-conversions)
'
349
(funcall get-sequence method objects)
'
350
;; FIXME test for ambiguous overload #'conversion=
'
351
(when (and rank (conversion< rank best-rank))
'
352
(setf best-rank rank)
'
353
(setf best-method method)
'
354
(setf conversions method-conversions)
'
355
(when (conversion= rank (make-match 'exact-match))
'
356
(return)))))
'
357
(values best-method conversions)))
2009-04-17 tobias
358
2009-05-11 tobias
359
(defvar *from-lisp-translations* (make-hash-table :test 'equal))
11:07:39 '
360
'
361
(defmacro define-from-lisp-translation (type-names lisp-type
'
362
&optional
'
363
(conversion-function-name 'identity))
2009-05-11 tobias
364
"Defines a translation from LISP-TYPE to the C++ types TYPE-NAMES using
14:11:35 '
365
the function CONVERSION-FUNCTION-NAME."
2009-05-11 tobias
366
`(progn ,@(loop for type-name in (ensure-list type-names)
2009-05-11 tobias
367
collect `(setf (gethash ,type-name *from-lisp-translations*)
2009-09-02 tobias
368
#'(lambda (type)
11:49:34 '
369
(and (subtypep type ',lisp-type)
2009-05-11 tobias
370
',conversion-function-name))))))
11:07:39 '
371
'
372
(define-from-lisp-translation ("void*" "const void*" "void**" "const void**")
'
373
foreign-pointer)
'
374
'
375
;; FIXME grovel this?
'
376
(deftype c-integer (ctype)
'
377
(let ((bits (* 8 (foreign-type-size ctype))))
2009-05-11 tobias
378
(if (starts-with-subseq
2009-05-11 tobias
379
(symbol-name :unsigned)
11:07:39 '
380
(symbol-name ctype))
'
381
`(unsigned-byte ,bits)
'
382
`(signed-byte ,bits))))
'
383
'
384
'
385
(defun+using-type exact-match object (object type)
'
386
"Test for an exact match."
2009-04-17 tobias
387
(case (type-id type)
2009-06-22 tobias
388
(0 (when-let (test (gethash (name type) *from-lisp-translations*))
2009-09-02 tobias
389
(funcall test (object.type-of))))
2009-05-11 tobias
390
(1 (object.typep 'boolean))
11:07:39 '
391
(2 (object.typep 'standard-char))
'
392
(3 (object.typep '(c-integer :unsigned-char)))
'
393
(4 (object.typep '(c-integer :short)))
'
394
(5 (object.typep '(c-integer :unsigned-short)))
'
395
(6 (object.typep '(c-integer :int)))
'
396
(7 (object.typep '(c-integer :unsigned-int)))
'
397
(10 (object.typep 'single-float))
'
398
(11 (object.typep 'double-float))
2010-01-25 tobias
399
(12 (object.typep 'enum)) ;; FIXME enum-type
2009-09-09 tobias
400
(13 (and (object.typep 'smoke-standard-object)
13:22:32 '
401
(smoke-type= (get-class type) (object.type-of))))))
2009-05-11 tobias
402
11:07:39 '
403
'
404
(defun make-cleanup-pointer (pointer cleanup-function)
2009-05-26 tobias
405
"Returns a pointer that calls CLEANUP-FUNCTION with pointer as argument
09:54:47 '
406
when it is finalized."
2009-05-11 tobias
407
(let ((address (pointer-address pointer)))
11:07:39 '
408
(tg:finalize pointer #'(lambda ()
'
409
(funcall cleanup-function
'
410
(make-pointer address))))))
'
411
2009-04-17 tobias
412
(defun make-auto-pointer (pointer)
15:26:55 '
413
"Returns a pointer that frees the memory at POINTER when it is finalized."
2009-05-26 tobias
414
(make-cleanup-pointer pointer #'foreign-free))
2009-04-17 tobias
415
2009-05-11 tobias
416
(defun coerce-c-string (string)
11:07:39 '
417
(make-auto-pointer (foreign-string-alloc string)))
'
418
2010-02-20 tobias
419
(defun coerce-enum (enum)
2009-05-11 tobias
420
(cxx-support:value enum))
11:07:39 '
421
'
422
(defun+using-type promotion object (object type)
2009-04-17 tobias
423
(declare (smoke-type type))
15:26:55 '
424
(case (type-id type)
2009-05-11 tobias
425
(0 (when (and (string= (name type) "const char*")
11:07:39 '
426
(object.typep 'string))
'
427
(make-match 'promotion 'coerce-c-string)))
'
428
(6 (when (object.typep 'enum)
2010-02-20 tobias
429
(make-match 'promotion 'coerce-enum)))
2009-05-11 tobias
430
(7 (when (object.typep 'enum)
2009-07-02 tobias
431
(make-match 'promotion 'coerce-enum)))))
2009-04-17 tobias
432
2009-05-26 tobias
433
(declaim (inline coerce-to-class))
2009-05-11 tobias
434
(defun coerce-cast (object to-class)
11:07:39 '
435
(cast object to-class))
2009-04-17 tobias
436
2009-05-11 tobias
437
(defun coerce-to-void (object)
11:07:39 '
438
object)
2009-04-17 tobias
439
2009-05-11 tobias
440
(defun+using-type conversion-cast object (object type)
11:07:39 '
441
(when (and (class-p type)
'
442
(object.typep 'smoke-standard-object)
2009-08-27 tobias
443
(derived-p (object.type-of) (get-class type)))
2009-05-11 tobias
444
(make-match 'pointer-conversion
11:07:39 '
445
'coerce-cast
'
446
(find-smoke-class (get-class type))
'
447
:from (object.type-of)
'
448
:to (find-smoke-class (get-class type)))))
'
449
'
450
(defun+using-type conversion-void object (object type)
'
451
(when (and (string= (name type) "void*")
'
452
(object.typep 'smoke-standard-object))
'
453
(make-match 'pointer-conversion
'
454
'coerce-void
'
455
nil
'
456
:from (object.type-of)
'
457
:to (find-class 't))))
'
458
'
459
(defun+using-type conversion-pointer object (object type)
2009-07-22 tobias
460
;; Not using pointer-p to allow passing a raw pointer for
22:26:05 '
461
;; objects on the stack and references
2009-05-24 tobias
462
;; (e.g.: for qInstallMsgHandler(QtMsgHandler) )
21:28:44 '
463
;;
2009-07-22 tobias
464
;; FIXME this breaks passing pointers to references
22:26:05 '
465
;; e.g.: calling the function foo(QByteArray& foo)
'
466
;; with (foo pointer) assumes pointer to point to a QByteArray,
'
467
;; but actually the conversion sequence QByteArray(pointer) should be used.
'
468
;; When pointer is a null pointer it fails horribly!.
2009-05-24 tobias
469
(when (and (or (= 0 (type-id type)) ; voidp
21:28:44 '
470
(= 13 (type-id type))) ; class
2009-05-11 tobias
471
(object.typep 'foreign-pointer))
11:07:39 '
472
(make-match 'pointer-conversion 'identity nil
2009-08-02 tobias
473
:from (find-class 't)
10:12:41 '
474
:to (find-class 't)))) ;; FIXME get the class when applicable
2009-05-11 tobias
475
11:07:39 '
476
'
477
(defun+using-type conversion object (object type)
'
478
(or (call-using-type conversion-cast object type)
'
479
(call-using-type conversion-void object type)
'
480
(call-using-type conversion-pointer object type)))
'
481
'
482
(defun+using-type user-conversion object (object type)
'
483
(or (call-using-type operator-conversion object type)
'
484
(call-using-type constructor-conversion object type)))
'
485
'
486
(defun+using-type operator-conversion object (object type)
'
487
(when (object.typep 'smoke-standard-object)
'
488
(let ((method (find-smoke-method (object.type-of)
2009-07-24 tobias
489
(format nil "operator ~A"
13:32:23 '
490
(if (class-p type)
'
491
(name (get-class type))
'
492
(name type))))))
2009-05-11 tobias
493
(when (valid-p method)
2009-08-27 tobias
494
(assert (not (void-p type))
11:43:13 '
495
()
'
496
"Conversion operators not supported by Smoke.
'
497
Update to Smoke >= r955426.")
2009-07-24 tobias
498
(make-match 'user-conversion
13:32:23 '
499
(lispify (name method) :cxx))))))
2009-05-11 tobias
500
2009-05-26 tobias
501
(declaim (inline coerce-to-class))
2009-05-11 tobias
502
(defun coerce-to-class (object to-class)
11:07:39 '
503
(make-instance to-class
'
504
:args (list object)))
'
505
'
506
(defun+using-type constructor-conversion object (object type)
'
507
(when (class-p type)
2009-08-27 tobias
508
(let ((to-class (find-smoke-class (get-class type))))
11:43:13 '
509
(when (call-using-types find-best-viable-function2
'
510
(if (using-typep)
'
511
#'standard-conversion-sequence-using-types
'
512
#'standard-conversion-sequence)
2009-07-22 tobias
513
(format nil "~A" (name (get-class type)))
2009-08-27 tobias
514
(list object) to-class)
2010-01-10 tobias
515
(make-match 'user-conversion
17:31:42 '
516
'coerce-to-class
'
517
to-class)))))
2009-04-17 tobias
518
15:26:55 '
519
(defun call-sequence (method object sequence &rest args)
'
520
(s-call method object
2009-05-11 tobias
521
(mapcar #'(lambda (conversion argument)
11:07:39 '
522
(funcall conversion argument))
'
523
sequence args)))
2009-05-27 tobias
524
17:47:28 '
525
(defun format-no-applicable-cxx-method (stream name class arguments)
'
526
(format stream
'
527
"No applicable method ~S of ~A for ~S.
2009-07-02 tobias
528
Candidates are:~{~T~A~%~}."
2009-05-27 tobias
529
name class arguments
17:47:28 '
530
(mapcar #'signature
'
531
(viable-functions name
'
532
(length arguments)
'
533
(smoke-class-of class)))))
'
534
'
535
(define-condition no-applicable-cxx-method (error)
'
536
((method :initarg :method :reader condition-method)
'
537
(class :initarg :class :reader condition-class)
'
538
(arguments :initarg :arguments :reader condition-arguments))
'
539
(:report (lambda (condition stream)
'
540
(format-no-applicable-cxx-method stream
'
541
(condition-method condition)
'
542
(condition-class condition)
'
543
(condition-arguments condition)))))
2009-09-01 tobias
544
2009-04-17 tobias
545
(defun call-using-args (object-or-class name arguments)
2009-06-22 tobias
546
"Calls the method NAME of OBJECT-OR-CLASS with ARGUMENTS."
2009-09-09 tobias
547
(declare (optimize (speed 3)))
2009-08-27 tobias
548
(if (null arguments)
11:43:13 '
549
(let ((method (find-smoke-method (smoke-class-of object-or-class)
'
550
name)))
'
551
(unless (valid-p method)
'
552
(error (make-condition 'no-applicable-cxx-method
'
553
:method name
'
554
:class object-or-class
'
555
:arguments arguments)))
'
556
(if (static-p method)
'
557
(s-call method (null-pointer))
'
558
(s-call method (cast object-or-class (get-class method)))))
'
559
(multiple-value-bind (method sequence)
'
560
(find-best-viable-function name
'
561
arguments
'
562
(smoke-class-of object-or-class))
'
563
(when (null method)
'
564
(error (make-condition 'no-applicable-cxx-method
'
565
:method name
'
566
:class object-or-class
'
567
:arguments arguments)))
'
568
(if (static-p method)
'
569
(apply #'call-sequence method (null-pointer) sequence arguments)
'
570
(apply #'call-sequence method (cast object-or-class (get-class method))
'
571
sequence arguments)))))