|
|
|
@ -3,7 +3,7 @@
|
|
|
|
|
% This is a nuweb document.
|
|
|
|
|
% nuweb is available by anon. ftp from cs.rice.edu in /public/preston.
|
|
|
|
|
%
|
|
|
|
|
% Author: Lars Thomas Hansen (lth@cs.uoregon.edu)
|
|
|
|
|
% Author: Lars Thomas Hansen (lth@@cs.uoregon.edu)
|
|
|
|
|
%
|
|
|
|
|
% Copyright (C) 1996 The University of Oregon. All rights reserved.
|
|
|
|
|
%
|
|
|
|
@ -435,16 +435,21 @@ for the structure.
|
|
|
|
|
|
|
|
|
|
@d dump structs and unions
|
|
|
|
|
@{(define (dump-struct/union-def structure qualifier name)
|
|
|
|
|
(let* ((funcname (if (string=? qualifier "")
|
|
|
|
|
name
|
|
|
|
|
(string-append qualifier "_" name)))
|
|
|
|
|
(cast (if (string=? qualifier "")
|
|
|
|
|
name
|
|
|
|
|
(string-append qualifier " " name))))
|
|
|
|
|
(generate-constructor-and-destructor structure funcname cast)
|
|
|
|
|
(generate-accessors-and-mutators structure funcname cast "")))
|
|
|
|
|
(if (not (null? (fields structure)))
|
|
|
|
|
(let* ((funcname (if (string=? qualifier "")
|
|
|
|
|
name
|
|
|
|
|
(string-append qualifier "_" name)))
|
|
|
|
|
(cast (if (string=? qualifier "")
|
|
|
|
|
name
|
|
|
|
|
(string-append qualifier " " name))))
|
|
|
|
|
(generate-constructor-and-destructor structure funcname cast)
|
|
|
|
|
(generate-accessors-and-mutators structure funcname cast ""))))
|
|
|
|
|
@| dump-struct/union-def @}
|
|
|
|
|
|
|
|
|
|
Constructors, destructors, accessors and mutators are generated only if
|
|
|
|
|
the field list for the structure is non-empty, as an empty field lists
|
|
|
|
|
implies that the structure has merely been declared.
|
|
|
|
|
|
|
|
|
|
\subsubsection{Constructors and destructors}
|
|
|
|
|
|
|
|
|
|
The procedure \verb|generate-constructor-and-destructor| generates
|
|
|
|
@ -925,7 +930,7 @@ issue; here are our encodings:
|
|
|
|
|
(signed-char . "signed char")
|
|
|
|
|
(unsigned-char . "unsigned char")
|
|
|
|
|
(short . "short")
|
|
|
|
|
(unsigned-short "unsigned short")
|
|
|
|
|
(unsigned-short . "unsigned short")
|
|
|
|
|
(int . "int")
|
|
|
|
|
(enum . "int")
|
|
|
|
|
(unsigned . "unsigned")
|
|
|
|
@ -954,10 +959,25 @@ refers to the structure, and that name should be used instead.
|
|
|
|
|
|
|
|
|
|
@d utility functions
|
|
|
|
|
@{(define (c-cast-expression type)
|
|
|
|
|
(define (function-cast stars ftype)
|
|
|
|
|
(string-append (c-cast-expression (rett ftype))
|
|
|
|
|
"(" stars ")("
|
|
|
|
|
(apply string-append
|
|
|
|
|
(insert
|
|
|
|
|
","
|
|
|
|
|
(map c-cast-expression (arglist ftype))))
|
|
|
|
|
")"))
|
|
|
|
|
|
|
|
|
|
(cond ((primitive-type? type)
|
|
|
|
|
(basic-type-name type))
|
|
|
|
|
((pointer-type? type)
|
|
|
|
|
(string-append (c-cast-expression (cadr type)) "*"))
|
|
|
|
|
(let loop ((t (cadr type)) (stars "*"))
|
|
|
|
|
(cond ((eq? 'function (record-tag t))
|
|
|
|
|
(function-cast stars t))
|
|
|
|
|
((eq? 'pointer (record-tag t))
|
|
|
|
|
(loop (cadr t) (string-append "*" stars)))
|
|
|
|
|
(else
|
|
|
|
|
(string-append (c-cast-expression (cadr type)) "*")))))
|
|
|
|
|
((eq? (record-tag type) 'enum-ref)
|
|
|
|
|
(basic-type-name '(int ())))
|
|
|
|
|
((memq (record-tag type) '(struct-ref union-ref))
|
|
|
|
@ -976,7 +996,17 @@ refers to the structure, and that name should be used instead.
|
|
|
|
|
(else
|
|
|
|
|
(warn "c-cast-expression: Too complicated: " type)
|
|
|
|
|
"unknown")))
|
|
|
|
|
@| c-cast-expression @}
|
|
|
|
|
|
|
|
|
|
(define (insert x l)
|
|
|
|
|
(define (loop l)
|
|
|
|
|
(if (null? (cdr l))
|
|
|
|
|
l
|
|
|
|
|
(cons (car l) (cons x (loop (cdr l))))))
|
|
|
|
|
(if (or (null? l)
|
|
|
|
|
(null? (cdr l)))
|
|
|
|
|
l
|
|
|
|
|
(loop l)))
|
|
|
|
|
@| c-cast-expression insert @}
|
|
|
|
|
|
|
|
|
|
\verb|String-prefix=?| takes a string and a prefix and tests whether the
|
|
|
|
|
prefix matches the string.
|
|
|
|
|