home *** CD-ROM | disk | FTP | other *** search
/ PC World 1998 October / PCWorld_1998-10_cd.bin / software / prehled / inprise / JRUNTIME.Z / reflect.h < prev    next >
C/C++ Source or Header  |  1998-05-08  |  7KB  |  250 lines

  1. /*
  2.  * @(#)reflect.h    1.23 97/01/03
  3.  * 
  4.  * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  * CopyrightVersion 1.1_beta
  20.  * 
  21.  */
  22.  
  23. #ifndef    _REFLECT_H
  24. #define    _REFLECT_H
  25.  
  26. #include "oobj.h"
  27. #include "native.h"
  28.  
  29. /*
  30.  * Keep consistent with constants in java.lang.reflect.Member
  31.  */
  32. enum { MEMBER_PUBLIC, MEMBER_DECLARED };
  33.  
  34. extern HObject *    reflect_field(ClassClass *, char *, long);
  35. extern HArrayOfObject *    reflect_fields(ClassClass *, long);
  36.  
  37. extern HObject *    reflect_method(ClassClass *, char *, HArrayOfObject *,
  38.                 long);
  39. extern HArrayOfObject *    reflect_methods(ClassClass *, long);
  40.  
  41. extern HObject *    reflect_constructor(ClassClass *, HArrayOfObject *,
  42.                 long);
  43. extern HArrayOfObject *    reflect_constructors(ClassClass *, long);
  44.  
  45. extern ClassClass *    reflect_find_class(char *, ClassClass *, char **);
  46. extern bool_t        reflect_check_access(ExecEnv *, ClassClass *, int,
  47.                 ClassClass *);
  48. extern HObject *    reflect_new_array(ClassClass *, int);
  49. extern HArrayOfObject *    reflect_new_class_array(int);
  50. extern bool_t        reflect_is_assignable(ClassClass *, ClassClass *,
  51.                 ExecEnv *);
  52.  
  53. /*
  54.  * Implementation
  55.  */
  56.  
  57. #ifdef _REFLECT_IMPL
  58.  
  59. /*
  60.  * "Generic" accessors for Field, Method, Constructor
  61.  */
  62. #define    member_class(h)        (unhand(h)->clazz)
  63. #define    member_slot(h)        (unhand(h)->slot)
  64. #define    member_name(h)        (unhand(h)->name)
  65. #define    member_type(h)        (unhand(h)->type)
  66. #define    member_returnType(h)    (unhand(h)->returnType)
  67. #define    member_parameterTypes(h)(unhand(h)->parameterTypes)
  68. #define    member_exceptionTypes(h)(unhand(h)->exceptionTypes)
  69.  
  70.  
  71. #define    REFLECT_GET(p, pCode, v, packed)                \
  72. if (TRUE)                                \
  73. {                                    \
  74.     switch (pCode) {                            \
  75.     case T_BOOLEAN:                            \
  76.     case T_BYTE:                            \
  77.     if (packed) { v.i = *(char *) (p); break; }            \
  78.     case T_CHAR:                            \
  79.     if (packed) { v.i = *(unicode *) (p); break; }            \
  80.     case T_SHORT:                            \
  81.     if (packed) { v.i = *(short *) (p); break; }            \
  82.     case T_INT:                                \
  83.     v.i = *(long *) (p); break;                    \
  84.     case T_FLOAT:                            \
  85.     v.f = *(float *) (p); break;                    \
  86.     case T_LONG:                            \
  87.     v.l = GET_INT64(v, p); break;                    \
  88.     case T_DOUBLE:                            \
  89.     v.d = GET_DOUBLE(v, p); break;                    \
  90.     default:                                \
  91.     v.h = *(HObject **) (p);                    \
  92.     }                                    \
  93. } else
  94.  
  95. #define    REFLECT_SET(p, pCode, v, packed)                \
  96. if (TRUE)                                \
  97. {                                    \
  98.     switch (pCode) {                            \
  99.     case T_BOOLEAN:                            \
  100.     case T_BYTE:                            \
  101.     if (packed) { *(char *) (p) = v.i; break; }            \
  102.     case T_CHAR:                            \
  103.     if (packed) { *(unicode *) (p) = v.i; break; }            \
  104.     case T_SHORT:                            \
  105.     if (packed) { *(short *) (p) = v.i; break; }            \
  106.     case T_INT:                                \
  107.     *(long *) (p) = v.i ; break;                    \
  108.     case T_FLOAT:                            \
  109.     *(float *) (p) = v.f; break;                    \
  110.     case T_LONG:                            \
  111.     SET_INT64(v, p, v.l); break;                    \
  112.     case T_DOUBLE:                            \
  113.     SET_DOUBLE(v, p, v.d); break;                    \
  114.     default:                                \
  115.     *(HObject **) (p) = v.h;                    \
  116.     }                                    \
  117. } else
  118.  
  119. #define    REFLECT_WIDEN(v, vCode, wCode, fail)                \
  120. if (TRUE)                                \
  121. {                                    \
  122.     switch(wCode) {                            \
  123.     case T_BOOLEAN:                            \
  124.     case T_BYTE:                            \
  125.     case T_CHAR:                            \
  126.     goto fail;                            \
  127.     case T_SHORT:                            \
  128.     switch (vCode) {                        \
  129.     case T_BYTE:                            \
  130.         break;                            \
  131.     default:                            \
  132.         goto fail;                            \
  133.     }                                \
  134.     break;                                \
  135.     case T_INT:                                \
  136.     switch (vCode) {                        \
  137.     case T_BYTE:                            \
  138.     case T_CHAR:                            \
  139.     case T_SHORT:                            \
  140.         break;                            \
  141.     default:                            \
  142.         goto fail;                            \
  143.     }                                \
  144.     break;                                \
  145.     case T_LONG:                            \
  146.     switch (vCode) {                        \
  147.     case T_BYTE:                            \
  148.     case T_CHAR:                            \
  149.     case T_SHORT:                            \
  150.     case T_INT:                            \
  151.         v.l = int2ll(v.i); break;                        \
  152.     default:                            \
  153.         goto fail;                            \
  154.     }                                \
  155.     break;                                \
  156.     case T_FLOAT:                            \
  157.     switch (vCode) {                        \
  158.     case T_BYTE:                            \
  159.     case T_CHAR:                            \
  160.     case T_SHORT:                            \
  161.     case T_INT:                            \
  162.         v.f = (float) v.i; break;                    \
  163.     case T_LONG:                            \
  164.         v.f = (float) ll2float(v.l); break;                    \
  165.     default:                            \
  166.         goto fail;                            \
  167.     }                                \
  168.     break;                                \
  169.     case T_DOUBLE:                            \
  170.     switch (vCode) {                        \
  171.     case T_BYTE:                            \
  172.     case T_CHAR:                            \
  173.     case T_SHORT:                            \
  174.     case T_INT:                            \
  175.         v.d = (double) v.i; break;                    \
  176.     case T_FLOAT:                            \
  177.         v.d = (double) v.f; break;                    \
  178.     case T_LONG:                            \
  179.         v.d = (double) ll2double(v.l); break;                    \
  180.     default:                            \
  181.         goto fail;                            \
  182.     }                                \
  183.     break;                                \
  184.     default:                                \
  185.     goto fail;                            \
  186.     }                                    \
  187. } else
  188.  
  189. /*
  190.  *
  191.  */
  192.  
  193. #define    REFLECT_ERROR(nm, det)                        \
  194.     SignalError(0, JAVAPKG #nm, det)
  195.  
  196. #define    OutOfMemoryError()                        \
  197.     REFLECT_ERROR(OutOfMemoryError, 0)
  198.  
  199. #define    NullPointerException()                        \
  200.     REFLECT_ERROR(NullPointerException, 0)
  201.  
  202. #define    InternalError(det)                        \
  203.     REFLECT_ERROR(InternalError, det)
  204.  
  205. /*
  206.  *
  207.  */
  208.  
  209. #define    ENSURE_RESOLVED(cb)                        \
  210.     if (!CCIs(cb, Resolved)) {                        \
  211.     char   *detail = NULL;                        \
  212.     char   *exception = ResolveClass(cb, &detail);            \
  213.     if (exception != NULL) {                    \
  214.         SignalError(0, exception, detail);                \
  215.         return NULL;                        \
  216.     }                                \
  217.     }
  218.  
  219. /*
  220.  *
  221.  */
  222.  
  223. #define    fbClass(fb)    (fb->clazz)
  224. #define    fbName(fb)    (fb->name)
  225. #define    fbSig(fb)    (fb->signature)
  226. #define    fbAccess(fb)    (fb->access)
  227. #define    fbID(fb)    (fb->ID)
  228. #define    fbIsArray(fb)    (fbSig(fb)[0] == SIGNATURE_ARRAY)
  229. #define    fbIsClass(fb)    (fbSig(fb)[0] == SIGNATURE_CLASS)
  230. #define    fbIsPublic(fb)    ((fbAccess(fb) & ACC_PUBLIC) != 0)
  231. #define    fbIsStatic(fb)    ((fbAccess(fb) & ACC_STATIC) != 0)
  232. #define    fbIsFinal(fb)    ((fbAccess(fb) & ACC_FINAL) != 0)
  233. #define    fbOffset(fb)    (fb->u.offset)
  234.  
  235. #define    mbFb(mb)    (&mb->fb)
  236. #define    mbClass(mb)    (mb->fb.clazz)
  237. #define    mbName(mb)    (mb->fb.name)
  238. #define    mbSig(mb)    (mb->fb.signature)
  239. #define    mbAccess(mb)    (mb->fb.access)
  240. #define    mbOffset(mb)    (mb->fb.u.offset)
  241. #define    mbID(mb)    (mb->fb.ID)
  242. #define    mbArgsSize(mb)    (mb->args_size)
  243. #define    mbIsSpecial(mb)    (mbName(mb)[0] == '<')
  244. #define    mbIsPublic(mb)    ((mbAccess(mb) & ACC_PUBLIC) != 0)
  245. #define    mbIsStatic(mb)    ((mbAccess(mb) & ACC_STATIC) != 0)
  246.  
  247. #endif /* _REFLECT_IMPL */
  248.  
  249. #endif /* _REFLECT_H */
  250.