home *** CD-ROM | disk | FTP | other *** search
/ Java 1996 August / Java - Summer 1996.iso / kaffe-0.2 / kaffeh / sigs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-17  |  2.0 KB  |  138 lines

  1. /*
  2.  * sigs.c
  3.  * Translate a class into stubs.
  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. #include <stdio.h>
  15.  
  16. /*
  17.  * Translate signature into argument count.
  18.  */
  19. char*
  20. translateSig(char* str, FILE* fp, int* argp)
  21. {
  22.     int j;
  23.     int arg;
  24.  
  25.     switch (*str++) {
  26.     case 'L':
  27.         arg = 1;
  28.         fprintf(fp, "struct H");
  29.         for (j = 0; str[j] != ';'; j++) {
  30.             if (str[j] == '/') {
  31.                 fputc('_', fp);
  32.             }
  33.             else {
  34.                 fputc(str[j], fp);
  35.             }
  36.         }
  37.         fputc('*', fp);
  38.         str += j + 1;
  39.         break;
  40.     case '[':
  41.         arg = 1;
  42.         fprintf(fp, "HArray*");
  43.         if (*str++ == 'L') {
  44.             while (*str != ';') {
  45.                 str++;
  46.             }
  47.             str++;
  48.         }
  49.         break;
  50.     case 'B':
  51.         arg = 1;
  52.         fprintf(fp, "long /* byte */");
  53.         break;
  54.     case 'C':
  55.         arg = 1;
  56.         fprintf(fp, "long /* char */");
  57.         break;
  58.     case 'D':
  59.         arg = 2;
  60.         fprintf(fp, "double");
  61.         break;
  62.     case 'F':
  63.         arg = 1;
  64.         fprintf(fp, "float");
  65.         break;
  66.     case 'I':
  67.         arg = 1;
  68.         fprintf(fp, "long");
  69.         break;
  70.     case 'J':
  71.         arg = 2;
  72.         fprintf(fp, "long long");
  73.         break;
  74.     case 'S':
  75.         arg = 1;
  76.         fprintf(fp, "long /* short */");
  77.         break;
  78.     case 'Z':
  79.         arg = 1;
  80.         fprintf(fp, "long /* bool */");
  81.         break;
  82.     case 'V':
  83.         arg = 0;
  84.         fprintf(fp, "void");
  85.         break;
  86.     default:
  87.         abort();
  88.     }
  89.  
  90.     if (argp != 0) {
  91.         (*argp) += arg;
  92.     }
  93.  
  94.     return (str);
  95. }
  96.  
  97. /*
  98.  * Translate signature to union type.
  99.  */
  100. char*
  101. translateSigType(char* str, char* type)
  102. {
  103.     switch (*str++) {
  104.     case 'L':
  105.         type[0] = 'p';
  106.         while (*str != ';') {
  107.             str++;
  108.         }
  109.         str++;
  110.         break;
  111.     case '[':
  112.         type[0] = 'p';
  113.         if (*str++ == 'L') {
  114.             while (*str != ';') {
  115.                 str++;
  116.             }
  117.             str++;
  118.         }
  119.         break;
  120.     case 'B': case 'C': case 'I': case 'S': case 'Z':
  121.         type[0] = 'i';
  122.         break;
  123.     case 'D':
  124.         type[0] = 'd';
  125.         break;
  126.     case 'F':
  127.         type[0] = 'f';
  128.         break;
  129.     case 'J':
  130.         type[0] = 'l';
  131.         break;
  132.     case 'V':
  133.         type[0] = 'v';
  134.         break;
  135.     }
  136.     return (str);
  137. }
  138.