-/* 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,
- E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
- J. Wenninger, Institut f. Computersprachen - TU Wien
+ Copyright (C) 1996-2005, 2006, 2007, 2008
+ CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
This file is part of CACAO.
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- Contact: cacao@cacaojvm.org
+*/
- Authors: Edwin Steiner
+#ifndef _REFERENCES_H_
+#define _REFERENCES_H_
- Changes:
+/* forward typedefs ***********************************************************/
- $Id: references.h 4583 2006-03-11 20:32:53Z edwin $
+typedef struct constant_classref constant_classref;
+typedef struct constant_FMIref constant_FMIref;
-*/
-#ifndef _REFERENCES_H_
-#define _REFERENCES_H_
+/* 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_t ***************************************************************/
+
+typedef union parseddesc {
+ struct typedesc *fd; /* parsed field descriptor */
+ struct methoddesc *md; /* parsed method descriptor */
+ void *any; /* used for simple test against NULL */
+} parseddesc_t;
+
+
+#include "config.h"
+#include "vm/types.h"
+#include "vm/class.hpp"
+#include "vm/descriptor.h"
+#include "vm/field.hpp"
#include "vm/global.h"
+#include "vm/method.hpp"
#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. */
- utf *name; /* field/method/interfacemethod name */
- utf *descriptor; /* field/method/intfmeth. type descriptor string */
- parseddesc parseddesc; /* parsed descriptor */
-} constant_FMIref;
+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_t parseddesc; /* parsed descriptor */
+};
/* macros *********************************************************************/
#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))
#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->clazz->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->clazz->name \
+ : (fmiref)->p.classref->name)
+
/* initialize a constant_classref with referer `ref` and name `classname` */
#define CLASSREF_INIT(c,ref,classname) \