home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / kaffe-0.5p4-src.tgz / tar.out / contrib / kaffe / kaffevm / readClassConfig.h < prev    next >
C/C++ Source or Header  |  1996-09-28  |  3KB  |  107 lines

  1. /*
  2.  * readClassConfig.h
  3.  * Configure the class reader.
  4.  *
  5.  * Copyright (c) 1996 Systems Architecture Research Centre,
  6.  *           City University, London, UK.
  7.  *
  8.  * See the file "license.terms" for information on usage and redistribution
  9.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  10.  *
  11.  * Written by Tim Wilkinson <tim@sarc.city.ac.uk>, February 1996.
  12.  */
  13.  
  14. #ifndef __readclassconfig_h
  15. #define __readclassconfig_h
  16.  
  17. #include "classMethod.h"
  18. #include "errors.h"
  19. #include "lookup.h"
  20. #include "exception.h"
  21. #include "code.h"
  22. #include "slots.h"
  23.  
  24. /*
  25.  * Add a class to the system.
  26.  */
  27. #define    ADDCLASS(this, super, access, constants)            \
  28.     classThis = addClass(this, super, access, constants);        \
  29.     if (classThis == 0) {                        \
  30.                 throwException(ClassFormatError);            \
  31.     }
  32.  
  33. /*
  34.  * Add the interfaces.
  35.  */
  36. #define    READINTERFACES(fp, this, count)                    \
  37.     do {                                \
  38.         createInfo cinfo;                    \
  39.         classes** interfaces;                    \
  40.         u2 iface;                        \
  41.         int i;                            \
  42.         if (count == 0) {                    \
  43.             return;                        \
  44.         }                            \
  45.         interfaces = (classes**)calloc(sizeof(classes**), count);\
  46.         if (interfaces == 0) {                    \
  47.                         throwException(OutOfMemoryError);        \
  48.         }                            \
  49.         for (i = 0; i < count; i++) {                \
  50.             readu2(&iface, fp);                \
  51.             getClass(iface, this->constants, &cinfo);    \
  52.             interfaces[i] = cinfo.class;            \
  53.         }                            \
  54.         addInterfaces(this, count, interfaces);            \
  55.     } while(0)
  56.  
  57. /*
  58.  * Read in a field.
  59.  */
  60. #define    READFIELD(fp, this)                        \
  61.     do {                                \
  62.         field_info f;                        \
  63.         readu2(&f.access_flags, fp);                \
  64.         readu2(&f.name_index, fp);                \
  65.         readu2(&f.signature_index, fp);                \
  66.         addField(this, &f);                    \
  67.     } while (0)
  68.  
  69. /*
  70.  * Read in a method.
  71.  */
  72. #define    READMETHOD(fp, this)                        \
  73.     do {                                \
  74.         method_info m;                        \
  75.         readu2(&m.access_flags, fp);                \
  76.         readu2(&m.name_index, fp);                \
  77.         readu2(&m.signature_index, fp);                \
  78.         methodThis = addMethod(this, &m);            \
  79.     } while(0)
  80.  
  81. /*
  82.  * Finished reading in methods.
  83.  */
  84. #define    READMETHOD_END()                        \
  85.     finishClassMethods(this)
  86.  
  87. /*
  88.  * Process the attributes.
  89.  */
  90. #define    READATTRIBUTE(fp, this, method)                    \
  91.     do {                                \
  92.         u2 idx;                            \
  93.         u2 len;                            \
  94.         readu2(&idx, fp);                    \
  95.         readu4(&len, fp);                    \
  96. DBG(        printf("Attribute '%s'\n", this->constants->data[idx].v.tstr); )\
  97.         if (this->constants->tags[idx] == CONSTANT_Utf8 &&    \
  98.             strcmp(this->constants->data[idx].v.tstr, "Code") == 0) {\
  99.             addCode(method, len, fp);            \
  100.         }                            \
  101.         else {                            \
  102.             seekm(fp, len);                    \
  103.         }                            \
  104.     } while(0)
  105.  
  106. #endif
  107.