Changeset 13755


Ignore:
Timestamp:
01/10/12 23:07:58 (11 years ago)
Author:
astalla
Message:

[jvm-class-file]
Coalesce annotation-element and annotation-element-value into a single struct for simplicity.
Array- and annotation-valued elements.
Small refactor of annotation finalizers and writers.

Location:
trunk/abcl/src/org/armedbear/lisp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/jvm-class-file.lisp

    r13739 r13755  
    13531353  elements)
    13541354
    1355 (defstruct annotation-element (name "value") value)
    1356 
    1357 (defstruct annotation-element-value tag finalizer writer)
    1358 
    1359 (defstruct (primitive-or-string-annotation-element-value
    1360              (:conc-name primitive-or-string-annotation-element-)
    1361              (:include annotation-element-value
     1355(defstruct annotation-element (name "value") tag finalizer writer)
     1356
     1357(defstruct (primitive-or-string-annotation-element
     1358             (:include annotation-element
    13621359                       (finalizer (lambda (self class)
    13631360                                    (let ((value (primitive-or-string-annotation-element-value self)))
    13641361                                      (etypecase value
    13651362                                        (boolean
    1366                                          (setf (annotation-element-value-tag self)
     1363                                         (setf (annotation-element-tag self)
    13671364                                               (char-code #\Z)
    13681365                                               (primitive-or-string-annotation-element-value self)
    13691366                                               (pool-add-int (class-file-constants class) (if value 1 0))))
    13701367                                        (fixnum
    1371                                          (setf (annotation-element-value-tag self)
     1368                                         (setf (annotation-element-tag self)
    13721369                                               (char-code #\I)
    13731370                                               (primitive-or-string-annotation-element-value self)
    13741371                                               (pool-add-int (class-file-constants class) value)))
    13751372                                        (string
    1376                                          (setf (annotation-element-value-tag self)
     1373                                         (setf (annotation-element-tag self)
    13771374                                               (char-code #\s)
    13781375                                               (primitive-or-string-annotation-element-value self)
    13791376                                               (pool-add-utf8 (class-file-constants class) value)))))))
    13801377                       (writer (lambda (self stream)
    1381                                  (write-u1 (annotation-element-value-tag self) stream)
     1378                                 (write-u1 (annotation-element-tag self) stream)
    13821379                                 (write-u2 (primitive-or-string-annotation-element-value self) stream)))))
    13831380  value)
    13841381
    1385 (defstruct (enum-value-annotation-element-value
    1386              (:conc-name enum-value-annotation-element-)
    1387              (:include annotation-element-value
     1382(defstruct (enum-value-annotation-element
     1383             (:include annotation-element
     1384                       (tag (char-code #\e))
    13881385                       (finalizer (lambda (self class)
    1389                                     (setf (annotation-element-value-tag self)
    1390                                           (char-code #\e)
    1391                                           (enum-value-annotation-element-type self)
     1386                                    (setf (enum-value-annotation-element-type self)
    13921387                                          (pool-add-utf8 (class-file-constants class)
    13931388                                                         (enum-value-annotation-element-type self)) ;;Binary name as string
    1394                                           (enum-value-annotation-element-name self)
     1389                                          (enum-value-annotation-element-value self)
    13951390                                          (pool-add-utf8 (class-file-constants class)
    1396                                                          (enum-value-annotation-element-name self)))))
     1391                                                         (enum-value-annotation-element-value self)))))
    13971392                       (writer (lambda (self stream)
    1398                                  (write-u1 (annotation-element-value-tag self) stream)
     1393                                 (write-u1 (annotation-element-tag self) stream)
    13991394                                 (write-u2 (enum-value-annotation-element-type self) stream)
    1400                                  (write-u2 (enum-value-annotation-element-name self) stream)))))
     1395                                 (write-u2 (enum-value-annotation-element-value self) stream)))))
    14011396  type
    1402   name)
     1397  value)
     1398
     1399(defstruct (annotation-value-annotation-element
     1400             (:include annotation-element
     1401                       (tag (char-code #\@))
     1402                       (finalizer (lambda (self class)
     1403                                    (finalize-annotation (annotation-value-annotation-element-value self) class)))
     1404                       (writer (lambda (self stream)
     1405                                 (write-u1 (annotation-element-tag self) stream)
     1406                                 (write-annotation (annotation-value-annotation-element-value self) stream)))))
     1407  value)
     1408
     1409(defstruct (array-annotation-element
     1410             (:include annotation-element
     1411                       (tag (char-code #\[))
     1412                       (finalizer (lambda (self class)
     1413                                    (dolist (elem (array-annotation-element-values self))
     1414                                      (finalize-annotation-element elem class))))
     1415                       (writer (lambda (self stream)
     1416                                 (write-u1 (annotation-element-tag self) stream)
     1417                                 (write-u2 (length (array-annotation-element-values self)) stream)
     1418                                 (dolist (elem (array-annotation-element-values self))
     1419                                   (write-annotation-element elem stream))))))
     1420  values) ;;In proper order
    14031421
    14041422(defstruct (runtime-visible-annotations-attribute
     
    14191437  (declare (ignore code))
    14201438  (dolist (ann (annotations-list annotations))
    1421     (setf (annotation-type ann)
    1422           (pool-add-class (class-file-constants class) (annotation-type ann)))
    1423     (dolist (elem (annotation-elements ann))
    1424       (setf (annotation-element-name elem)
    1425             (pool-add-utf8 (class-file-constants class)
    1426                            (annotation-element-name elem)))
    1427       (funcall (annotation-element-value-finalizer (annotation-element-value elem))
    1428                (annotation-element-value elem) class))))
     1439    (finalize-annotation ann class)))
     1440
     1441(defun finalize-annotation (ann class)
     1442  (setf (annotation-type ann)
     1443        (pool-add-class (class-file-constants class) (annotation-type ann)))
     1444  (dolist (elem (annotation-elements ann))
     1445    (finalize-annotation-element elem class)))
     1446
     1447(defun finalize-annotation-element (elem class)
     1448  (when (annotation-element-name elem)
     1449    (setf (annotation-element-name elem)
     1450          (pool-add-utf8 (class-file-constants class)
     1451                         (annotation-element-name elem))))
     1452  (funcall (annotation-element-finalizer elem)
     1453           elem class))
    14291454
    14301455(defun write-annotations (annotations stream)
    14311456  (write-u2 (length (annotations-list annotations)) stream)
    14321457  (dolist (annotation (reverse (annotations-list annotations)))
    1433     (write-u2 (annotation-type annotation) stream)
    1434     (write-u2 (length (annotation-elements annotation)) stream)
    1435     (dolist (elem (reverse (annotation-elements annotation)))
    1436       (write-u2 (annotation-element-name elem) stream)
    1437       (funcall (annotation-element-value-writer (annotation-element-value elem))
    1438                (annotation-element-value elem) stream))))
     1458    (write-annotation annotation stream)))
     1459
     1460(defun write-annotation (annotation stream)
     1461  (write-u2 (annotation-type annotation) stream)
     1462  (write-u2 (length (annotation-elements annotation)) stream)
     1463  (dolist (elem (reverse (annotation-elements annotation)))
     1464    (write-annotation-element elem stream)))
     1465
     1466(defun write-annotation-element (elem stream)
     1467  (when (annotation-element-name elem)
     1468    (write-u2 (annotation-element-name elem) stream))
     1469  (funcall (annotation-element-writer elem)
     1470           elem stream))
    14391471
    14401472#|
  • trunk/abcl/src/org/armedbear/lisp/runtime-class.lisp

    r13739 r13755  
    144144                 :annotations (list (make-annotation :type "java.lang.Deprecated")
    145145                                    (make-annotation :type "java.lang.annotation.Retention"
    146                                                      :elements (list (make-annotation-element
    147                                                                       :value (make-enum-value-annotation-element-value
    148                                                                               :type "java.lang.annotation.RetentionPolicy"
    149                                                                               :name "RUNTIME"))))
     146                                                     :elements (list (make-enum-value-annotation-element
     147                                                                      :type "java.lang.annotation.RetentionPolicy"
     148                                                                      :value "RUNTIME")))
    150149                                    (make-annotation :type "javax.xml.bind.annotation.XmlAttribute"
    151                                                      :elements (list (make-annotation-element
     150                                                     :elements (list (make-primitive-or-string-annotation-element
    152151                                                                      :name "required"
    153                                                                       :value (make-primitive-or-string-annotation-element-value :value t))))))
     152                                                                      :value t)))))
    154153           (list "bar" :int '("java.lang.Object")
    155154                 (lambda (this that) (print (list this that)) 23))))
Note: See TracChangeset for help on using the changeset viewer.