Changeset 12861


Ignore:
Timestamp:
08/05/10 19:16:22 (13 years ago)
Author:
ehuelsmann
Message:

Add documentation and some TODOs.

File:
1 edited

Legend:

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

    r12856 r12861  
    280280                           (:include constant
    281281                                     (tag 7)))
     282  "Structure holding information on a 'class' type item in the constant pool."
    282283  name-index)
    283284
     
    286287                                     (tag index class-index name/type-index))
    287288                                (:include constant))
     289  "Structure holding information on a member reference type item
     290(a field, method or interface method reference) in the constant pool."
    288291  class-index
    289292  name/type-index)
     
    308311                            (:include constant
    309312                                      (tag 8)))
     313  "Structure holding information on a 'string' type item in the constant pool."
    310314  value-index)
    311315
     
    313317                                %make-constant-float/int (tag index value))
    314318                               (:include constant))
     319  "Structure holding information on a 'float' or 'integer' type item
     320in the constant pool."
    315321  value)
    316322
     
    327333                                  %make-constant-double/long (tag index value))
    328334                                 (:include constant))
     335  "Structure holding information on a 'double' or 'long' type item
     336in the constant pool."
    329337  value)
    330338
     
    344352                               (:include constant
    345353                                         (tag 12)))
     354  "Structure holding information on a 'name-and-type' type item in the
     355constant pool; this type of element is used by 'member-ref' type items."
    346356  name-index
    347357  descriptor-index)
     
    350360                          (:include constant
    351361                                    (tag 1)))
     362  "Structure holding information on a 'utf8' type item in the constant pool;
     363
     364This type of item is used for text representation of identifiers
     365and string contents."
    352366  value)
    353367
     
    489503(defstruct (class-file (:constructor
    490504                        !make-class-file (class superclass access-flags)))
     505  "Holds the components of a class file."
    491506  (constants (make-pool))
    492507  access-flags
    493508  class
    494509  superclass
     510  ;; support for implementing interfaces not yet available
    495511  ;; interfaces
    496512  fields
     
    690706
    691707(defstruct (field (:constructor %make-field))
    692   ""
     708  "Holds information on the properties of fields in the class(-file)."
    693709  access-flags
    694710  name
     
    697713
    698714(defun !make-field (name type &key (flags '(:public)))
    699  
     715  "Creates a field for addition to a class file."
    700716  (%make-field :access-flags flags
    701717               :name name
     
    703719
    704720(defun field-add-attribute (field attribute)
     721  "Adds an attribute to a field."
    705722  (push attribute (field-attributes field)))
    706723
    707724(defun field-attribute (field name)
     725  "Retrieves an attribute named `name' of `field'.
     726
     727Returns NIL if the attribute isn't found."
    708728  (find name (field-attributes field)
    709729        :test #'string= :key #'attribute-name))
    710730
    711731(defun finalize-field (field class)
     732  "Prepares `field' for serialization."
    712733  (let ((pool (class-file-constants class)))
    713734    (setf (field-access-flags field)
     
    720741
    721742(defun !write-field (field stream)
     743  "Writes classfile representation of `field' to `stream'."
    722744  (write-u2 (field-access-flags field) stream)
    723745  (write-u2 (field-name field) stream)
     
    727749
    728750(defstruct (method (:constructor %!make-method))
     751  "Holds information on the properties of methods in the class(-file)."
    729752  access-flags
    730753  name
     
    748771
    749772(defun !make-method (name return args &key (flags '(:public)))
     773  "Creates a method for addition to a class file."
    750774  (%!make-method :descriptor (cons return args)
    751775                :access-flags flags
     
    776800
    777801(defun method-attribute (method name)
     802  "Returns the first attribute of `method' with `name'."
    778803  (find name (method-attributes method)
    779804        :test #'string= :key #'attribute-name))
     
    781806
    782807(defun finalize-method (method class)
     808  "Prepares `method' for serialization."
    783809  (let ((pool (class-file-constants class)))
    784810    (setf (method-access-flags method)
     
    792818
    793819(defun !write-method (method stream)
     820  "Write class file representation of `method' to `stream'."
    794821  (write-u2 (method-access-flags method) stream)
    795822  (write-u2 (method-name method) stream)
     
    799826
    800827(defstruct attribute
     828  "Parent attribute structure to be included into other attributes, mainly
     829to define common fields.
     830
     831Having common fields allows common driver code for
     832finalizing and serializing attributes."
    801833  name
    802834
     
    807839
    808840(defun finalize-attributes (attributes att class)
     841  "Prepare `attributes' (a list) of attribute `att' list for serialization."
    809842  (dolist (attribute attributes)
    810843    ;; assure header: make sure 'name' is in the pool
     
    816849
    817850(defun write-attributes (attributes stream)
     851  "Writes the `attributes' to `stream'."
    818852  (write-u2 (length attributes) stream)
    819853  (dolist (attribute attributes)
     
    835869                                     (writer #'!write-code))
    836870                           (:constructor %make-code-attribute))
     871  "The attribute containing the actual JVM byte code;
     872an attribute of a method."
    837873  max-stack
    838874  max-locals
     
    851887
    852888(defun code-label-offset (code label)
     889  "Retrieves the `label' offset within a `code' attribute after the
     890attribute has been finalized."
    853891  (cdr (assoc label (code-labels code))))
    854892
    855893(defun (setf code-label-offset) (offset code label)
     894  "Sets the `label' offset within a `code' attribute after the attribute
     895has been finalized."
    856896  (setf (code-labels code)
    857897        (acons label offset (code-labels code))))
    858898
    859 
    860 
    861899(defun !finalize-code (code parent class)
     900  "Prepares the `code' attribute for serialization, within method `parent'."
    862901  (declare (ignore parent))
    863902  (let ((c (resolve-instructions (coerce (reverse (code-code code)) 'vector))))
     
    885924
    886925(defun !write-code (code stream)
     926  "Writes the attribute `code' to `stream'."
    887927  (sys::%format t "max-stack: ~a~%" (code-max-stack code))
    888928  (write-u2 (code-max-stack code) stream)
     
    918958
    919959(defun code-attribute (code name)
     960  "Returns an attribute of `code' identified by `name'."
    920961  (find name (code-attributes code)
    921962        :test #'string= :key #'attribute-name))
     
    923964
    924965(defun code-add-exception-handler (code start end handler type)
     966  "Adds an exception handler to `code' protecting the region from
     967labels `start' to `end' (inclusive) from exception `type' - where
     968a value of NIL indicates all types. Upon an exception of the given
     969type, control is transferred to label `handler'."
    925970  (push (make-exception :start-pc start
    926971                        :end-pc end
     
    930975
    931976(defstruct exception
     977  "Exception handler information.
     978
     979After finalization, the fields contain offsets instead of labels."
    932980  start-pc    ;; label target
    933981  end-pc      ;; label target
     
    9741022
    9751023
     1024;; ### Can't be used yet: no serialization
    9761025(defstruct (source-file-attribute (:conc-name source-)
    9771026                                  (:include attribute
    9781027                                            (name "SourceFile")))
     1028  "An attribute of the class file indicating which source file
     1029it was compiled from."
    9791030  filename)
    9801031
     1032;; ### Can't be used yet: no serialization
    9811033(defstruct (line-numbers-attribute (:include attribute
    9821034                                             (name "LineNumberTable")))
    983   line-numbers)
     1035  "An attribute of `code-attribute', containing a mapping of offsets
     1036within the code section to the line numbers in the source file."
     1037  line-numbers ;; a list of line-number structures, in reverse order
     1038  )
    9841039
    9851040(defstruct line-number
    986   start-pc
     1041  start-pc  ;; a label, before finalization
    9871042  line)
    9881043
     1044;; ### Can't be used yet: no serialization
    9891045(defstruct (local-variables-attribute (:conc-name local-var-)
    9901046                                      (:include attribute
    9911047                                                (name "LocalVariableTable")))
    992   locals)
     1048  "An attribute of the `code-attribute', containing a table of local variable
     1049names, their type and their scope of validity."
     1050  locals ;; a list of local-variable structures, in reverse order
     1051  )
    9931052
    9941053(defstruct (local-variable (:conc-name local-))
    995   start-pc
     1054  start-pc  ;; a label, before finalization
    9961055  length
    9971056  name
    9981057  descriptor
    999   index)
     1058  index ;; The index of the variable inside the block of locals
     1059  )
    10001060
    10011061#|
Note: See TracChangeset for help on using the changeset viewer.