home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v92.tgz / v92.tar / v92 / src / rtt / rttmisc.c < prev    next >
C/C++ Source or Header  |  1996-03-22  |  2KB  |  115 lines

  1. #include "rtt.h"
  2.  
  3. int n_tmp_str  = 0;
  4. int n_tmp_cset = 0;
  5. struct sym_entry *params = NULL;
  6.  
  7. /*
  8.  * clr_def - clear any information related to definitions.
  9.  */
  10. novalue clr_def()
  11.    {
  12.    struct sym_entry *sym;
  13.  
  14.    n_tmp_str = 0;
  15.    n_tmp_cset = 0;
  16.    while (params != NULL) {
  17.       sym = params;
  18.       params = params->u.param_info.next;
  19.       free_sym(sym);
  20.       }
  21.    free_tend();
  22.    if (v_len != NULL)
  23.       free_sym(v_len);
  24.    v_len = NULL;
  25.    il_indx = 0;
  26.    lbl_num = 0;
  27.    abs_ret = SomeType;
  28.    }
  29.  
  30. /*
  31.  * ttol - convert a token representing an integer constant into a long
  32.  *  integer value.
  33.  */
  34. long ttol(t)
  35. struct token *t;
  36. {
  37.    register long i;
  38.    register char *s;
  39.    int base;
  40.  
  41.    s = t->image;
  42.    i = 0;
  43.    base = 10;
  44.  
  45.    if (*s == '0') {
  46.       base = 8;
  47.       ++s;
  48.       if (*s == 'x') {
  49.          base = 16;
  50.          ++s;
  51.          }
  52.       }
  53.    while (*s != '\0') {
  54.       i *= base;
  55.       if (*s >= '0' && *s <= '9')
  56.          i += *s++ - '0';
  57.       else if (*s >= 'a' && *s <= 'f')
  58.          i += *s++ - 'a' + 10;
  59.       else if (*s >= 'A' && *s <= 'F')
  60.          i += *s++ - 'A' + 10;
  61.       }
  62.    return i;
  63.    }
  64.  
  65. struct token *chk_exct(tok)
  66. struct token *tok;
  67.    {
  68.    struct sym_entry *sym;
  69.  
  70.    sym = sym_lkup(tok->image);
  71.    if (sym->u.typ_indx != int_typ)
  72.       errt2(tok, "exact conversions do not apply  to ", tok->image);
  73.    return tok;
  74.    }
  75.  
  76. /*
  77.  * icn_typ - convert a type node into a type code for the internal
  78.  *   representation of the data base.
  79.  */
  80. int icn_typ(typ)
  81. struct node *typ;
  82.    {
  83.    switch (typ->nd_id) {
  84.       case PrimryNd:
  85.          switch (typ->tok->tok_id) {
  86.             case Any_value:
  87.                return TypAny;
  88.             case Empty_type:
  89.                return TypEmpty;
  90.             case Variable:
  91.                return TypVar;
  92.             case C_Integer:
  93.                return TypCInt;
  94.             case C_Double:
  95.                return TypCDbl;
  96.             case C_String:
  97.                return TypCStr;
  98.             case Tmp_string:
  99.                return TypTStr;
  100.             case Tmp_cset:
  101.                return TypTCset;
  102.             }
  103.  
  104.       case SymNd:
  105.          return typ->u[0].sym->u.typ_indx;
  106.  
  107.       default:  /* must be exact conversion */
  108.          if (typ->tok->tok_id == C_Integer)
  109.             return TypECInt;
  110.          else     /* integer */
  111.             return TypEInt;
  112.       }
  113.    }
  114.  
  115.