-/* vm/references.h - references to classes/fields/methods
+/* src/vm/references.h - references to classes/fields/methods
- Copyright (C) 1996-2005 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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- 02111-1307, USA.
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
- Contact: cacao@complang.tuwien.ac.at
+*/
- Authors: Edwin Steiner
+#ifndef _REFERENCES_H_
+#define _REFERENCES_H_
- Changes:
+/* forward typedefs ***********************************************************/
- $Id: references.h 2561 2005-06-06 15:21:19Z twisti $
+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.hpp"
+#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))
+
/* macro for casting a classref/classinfo * to a classref_or_classinfo */
#define CLASSREF_OR_CLASSINFO(value) \
(*((classref_or_classinfo *)(&(value))))
+/* macro for accessing the name of a classref/classinfo */
+#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) \