* src/vm/jit/i386/codegen.cn (codegen): Use the new functions for
[cacao.git] / src / vm / references.h
index 072287dc665b680fb293cb328233685153fc0cb9..25569b8942f58b2ba934938f47c852898ddc1cf9 100644 (file)
@@ -1,4 +1,4 @@
-/* vm/references.h - references to classes/fields/methods
+/* src/vm/references.h - references to classes/fields/methods
 
    Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
    Contact: cacao@cacaojvm.org
 
    Authors: Edwin Steiner
+            Christian Thalinger
 
-   Changes:
-
-   $Id: references.h 4584 2006-03-11 20:34:21Z edwin $
+   $Id: references.h 6012 2006-11-16 19:45:15Z twisti $
 
 */
 
 #ifndef _REFERENCES_H_
 #define _REFERENCES_H_
 
+/* forward typedefs ***********************************************************/
+
+typedef struct constant_classref constant_classref;
+typedef struct constant_FMIref   constant_FMIref;
+
+
+/* constant_classref **********************************************************/
+
+struct constant_classref {
+       void             *pseudo_vftbl; /* for distinguishing it from classinfo   */
+       struct classinfo *referer;    /* class containing the reference           */
+       struct utf       *name;       /* name of the class refered to             */
+};
+
+
+/* classref_or_classinfo ******************************************************/
+
+typedef union classref_or_classinfo {
+       constant_classref *ref;       /* a symbolic class reference               */
+       struct classinfo  *cls;       /* an already loaded class                  */
+       void              *any;       /* used for general access (x != NULL,...)  */
+} classref_or_classinfo;
+
+
+/* parseddesc *****************************************************************/
+
+typedef union parseddesc {
+       struct typedesc   *fd;        /* parsed field descriptor                  */
+       struct methoddesc *md;        /* parsed method descriptor                 */
+       void              *any;       /* used for simple test against NULL        */
+} parseddesc;
+
+
+#include "config.h"
+#include "vm/types.h"
+
+#include "vm/class.h"
+#include "vm/descriptor.h"
+#include "vm/field.h"
 #include "vm/global.h"
+#include "vm/method.h"
 #include "vm/utf8.h"
 
 
 /*     parseddesc                 describes a field type or a method type     */
 /*----------------------------------------------------------------------------*/
 
-/* forward declarations *******************************************************/
-
-typedef struct classinfo classinfo; 
-typedef struct typedesc typedesc;
-typedef struct methoddesc methoddesc;
-
-
 /* structs ********************************************************************/
 
-/* constant_classref **********************************************************/
-
-typedef struct constant_classref {
-       void      *pseudo_vftbl;      /* for distinguishing it from classinfo     */
-       classinfo *referer;           /* class containing the reference           */
-       utf       *name;              /* name of the class refered to             */
-} constant_classref;
-
-
-/* classref_or_classinfo ******************************************************/
-
-typedef union {
-       constant_classref *ref;       /* a symbolic class reference               */
-       classinfo         *cls;       /* an already loaded class                  */
-       void              *any;       /* used for general access (x != NULL,...)  */
-} classref_or_classinfo;
-
-
-/* parseddesc *****************************************************************/
-
-typedef union parseddesc {
-       typedesc          *fd;        /* parsed field descriptor                  */
-       methoddesc        *md;        /* parsed method descriptor                 */
-       void              *any;       /* used for simple test against NULL        */
-} parseddesc;
-
-
 /* constant_FMIref ************************************************************/
 
-typedef struct {            /* Fieldref, Methodref and InterfaceMethodref     */
-       constant_classref *classref;  /* class containing this field/meth./intfm. */
+struct constant_FMIref{     /* Fieldref, Methodref and InterfaceMethodref     */
+       union {
+               s4                 index;     /* used only within the loader          */
+               constant_classref *classref;  /* class having this field/meth./intfm. */
+               fieldinfo         *field;     /* resolved field                       */
+               methodinfo        *method;    /* resolved method                      */
+       } p;
        utf       *name;        /* field/method/interfacemethod name              */
        utf       *descriptor;  /* field/method/intfmeth. type descriptor string  */
        parseddesc parseddesc;  /* parsed descriptor                              */
-} constant_FMIref;
+};
 
 
 /* macros *********************************************************************/
@@ -112,6 +122,11 @@ typedef struct {            /* Fieldref, Methodref and InterfaceMethodref     */
 #define IS_CLASSREF(reforinfo)  \
        ((reforinfo).ref->pseudo_vftbl == CLASSREF_PSEUDO_VFTBL)
 
+/* macro for testing if a constant_FMIref has been resolved                   */
+/* `fmiref` is only evaluated once                                            */
+#define IS_FMIREF_RESOLVED(fmiref)  \
+       ((fmiref)->p.classref->pseudo_vftbl != CLASSREF_PSEUDO_VFTBL)
+
 /* the same as IS_CLASSREF, but also check against NULL */
 #define IS_XCLASSREF(reforinfo)  \
        ((reforinfo).any && IS_CLASSREF(reforinfo))
@@ -124,6 +139,16 @@ typedef struct {            /* Fieldref, Methodref and InterfaceMethodref     */
 #define CLASSREF_OR_CLASSINFO_NAME(value) \
        (IS_CLASSREF(value) ? (value).ref->name : (value).cls->name)
 
+/* macro for accessing the class name of a method reference                   */
+#define METHODREF_CLASSNAME(fmiref) \
+       (IS_FMIREF_RESOLVED(fmiref) ? (fmiref)->p.method->class->name \
+                                                               : (fmiref)->p.classref->name)
+
+/* macro for accessing the class name of a method reference                   */
+#define FIELDREF_CLASSNAME(fmiref) \
+       (IS_FMIREF_RESOLVED(fmiref) ? (fmiref)->p.field->class->name \
+                                                               : (fmiref)->p.classref->name)
+
 /* initialize a constant_classref with referer `ref` and name `classname`     */
 
 #define CLASSREF_INIT(c,ref,classname) \