-/* 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 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
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
+ Contact: cacao@cacaojvm.org
Authors: Edwin Steiner
+ Christian Thalinger
- Changes:
-
- $Id: references.h 2181 2005-04-01 16:53:33Z 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"
+
/*----------------------------------------------------------------------------*/
/* References */
/* */
/* 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 */
- classinfo *class; /* class containing this field/method/intfmeth. */ /* XXX remove */
- 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 *********************************************************************/
#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->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) \
- do { (c).pseudo_vftbl = CLASSREF_PSEUDO_VFTBL; \
- (c).referer = (ref); \
- (c).name = (classname); } while (0)
+
+#define CLASSREF_INIT(c,ref,classname) \
+ do { \
+ (c).pseudo_vftbl = CLASSREF_PSEUDO_VFTBL; \
+ (c).referer = (ref); \
+ (c).name = (classname); \
+ } while (0)
#endif /* _REFERENCES_H_ */