Changeset 11805 for trunk/source/level-1


Ignore:
Timestamp:
Mar 10, 2009, 12:52:19 PM (11 years ago)
Author:
gz
Message:

Make the compiler scan format strings for possible errors. ccl::*format-arg-functions* is the alist of functions that should be scanned (so setting this to nil is a way to disable the scanning). The code to actually do the scanning is in format.lisp. It doesn't seem to slow down the compiler in any noticable way. It finds some cases of insufficient args in format strings in ccl sources, I'll fix those in a separate checkin later.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/level-1/l1-format.lisp

    r10942 r11805  
    321321
    322322(defun format-no-flags (colon atsign)
    323   (when (or colon atsign) (format-error "Flags not allowed")))
     323  (cond ((and colon atsign)
     324         (format-error "Flags not allowed"))
     325        (colon
     326         (format-error ": flag not allowed"))
     327        (atsign
     328         (format-error "@ flag not allowed"))))
    324329
    325330;Redefined later
     
    340345;Final version
    341346(defformat #\% format-% (stream colon atsign &optional repeat-count)
     347  (format-no-flags colon atsign)
    342348  (cond ((or (not repeat-count)
    343             (and repeat-count (fixnump repeat-count)
    344                  (> repeat-count -1)))
    345          (format-no-flags colon atsign)
     349             (and (fixnump repeat-count)
     350                  (> repeat-count -1)))
    346351         (dotimes (i (or repeat-count 1)) (declare (fixnum i)) (terpri stream)))
    347352        (t (format-error "Bad repeat-count."))))
     
    350355(defformat #\& format-& (stream colon atsign &optional repeat-count)
    351356  (format-no-flags colon atsign)
    352   (unless (eq repeat-count 0)
    353     (fresh-line stream)
    354     (dotimes (i (1- (or repeat-count 1))) (declare (fixnum i)) (terpri stream))))
     357  (cond ((or (not repeat-count)
     358             (and (fixnump repeat-count)
     359                  (> repeat-count -1)))
     360         (unless (eq repeat-count 0)
     361           (fresh-line stream)
     362           (dotimes (i (1- (or repeat-count 1))) (declare (fixnum i)) (terpri stream))))
     363        (t (format-error "Bad repeat-count."))))
    355364
    356365;Final version
    357366(defformat #\~ format-~ (stream colon atsign &optional repeat-count)
    358367  (format-no-flags colon atsign)
    359   (dotimes (i (or repeat-count 1)) (declare (fixnum i)) (write-char #\~ stream)))
     368  (cond ((or (not repeat-count)
     369             (and (fixnump repeat-count)
     370                  (> repeat-count -1)))
     371         (dotimes (i (or repeat-count 1)) (declare (fixnum i)) (write-char #\~ stream)))
     372        (t (format-error "Bad repeat-count."))))
    360373
    361374;Final version
     
    382395                   (list-length *format-arguments*)))
    383396         (to (if atsign
    384                (or count 0) ; absolute
     397               (progn
     398                 (format-no-flags colon nil)
     399                 (or count 0)) ; absolute
    385400               (progn
    386401                 (when (null count)(setq count 1))
     
    408423            (not (whitespacep (schar s i))))
    409424        (setq *format-index* (1- i)))))
    410        
     425
    411426(defun nthcdr-no-overflow (count list)
    412   "If cdr beyond end of list return :error" 
    413427  (if (or (> count (list-length list)) (< count 0))
    414     nil ;:error
     428    (format-error "non-existent target for ~*")
    415429    (nthcdr count list)))
    416430
Note: See TracChangeset for help on using the changeset viewer.