/* 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
Changes:
- $Id: references.h 2181 2005-04-01 16:53:33Z edwin $
+ $Id: references.h 4758 2006-04-12 17:51:10Z edwin $
*/
#include "vm/global.h"
#include "vm/utf8.h"
+
/*----------------------------------------------------------------------------*/
/* References */
/* */
/* forward declarations *******************************************************/
typedef struct classinfo classinfo;
+typedef struct methodinfo methodinfo;
+typedef struct fieldinfo fieldinfo;
typedef struct typedesc typedesc;
typedef struct methoddesc methoddesc;
+
/* structs ********************************************************************/
/* constant_classref **********************************************************/
utf *name; /* name of the class refered to */
} constant_classref;
+
/* classref_or_classinfo ******************************************************/
typedef union {
void *any; /* used for general access (x != NULL,...) */
} classref_or_classinfo;
+
/* parseddesc *****************************************************************/
typedef union parseddesc {
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. */
+ 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 *********************************************************************/
/* a value that never occurrs in classinfo.header.vftbl */
#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_ */