1: #
   2: # include   <stdio.h>
   3: 
   4: # include   "constants.h"
   5: # include   "globals.h"
   6: 
   7: /*
   8: **  RETRIEVE.C -- ret_list struct handlers
   9: **
  10: **	The Ret_list is a structure where references to C variables,
  11: **	and their types, used in a target list of a "tupret" are kept
  12: **	for outputting in the while loop generated.
  13: **
  14: **	Defines:
  15: **		enter_ret()
  16: **		add_ret()
  17: **		w_ret()
  18: **		free_ret()
  19: **
  20: **	Required By:
  21: **		the semantic augments
  22: **
  23: **	Files:
  24: **		globals.h
  25: **		constants.h
  26: **
  27: **	History:
  28: **		6/1/78 -- (marc) written
  29: */
  30: 
  31: /*
  32: **  ENTER_RET -- enter a variable in a ret_list
  33: **	Concatenatest the strings in disp the calls add_ret
  34: **	to add the new string to Ret_list.
  35: **
  36: **	Parameters:
  37: **		disp -- display containing the reference to the variable
  38: **		type -- type of the variable
  39: **
  40: **	Called By:
  41: **		tupret productions
  42: **
  43: **	History:
  44: **		6/1/78 -- (marc) written
  45: */
  46: 
  47: 
  48: enter_ret(disp, type)
  49: struct display      *disp;
  50: int         type;
  51: {
  52:     char            buf [MAXSTRING + 2]; /* &buf [1] is the start
  53: 						      * of the concatenated
  54: 						      * strings
  55: 						      */
  56:     register char       *srce, *dest;
  57:     struct disp_node    *d;
  58:     register        i;
  59: 
  60:     i = 0;
  61:     dest = buf;
  62:     for (d = disp->disp_first; d; d = d->d_next)
  63:     {
  64:         for (srce = d->d_elm; *srce; )
  65:         {
  66:             if (i < MAXSTRING)
  67:             {
  68:                 i += 1;
  69:                 *++dest = *srce++;
  70:             }
  71:             else
  72:                 break;
  73:         }
  74: 
  75:         if (i >= MAXSTRING)
  76:         {
  77:             yysemerr("reference to a variable too long, ']' probably missing from array subscription",
  78:             0);
  79:             break;
  80:         }
  81:     }
  82:     *++dest = '\0';
  83:     add_ret(salloc(&buf [1]), type);
  84: }
  85: 
  86: /*
  87: **  ADD_RET -- add a string (reference to a variable) to the Ret_list
  88: **
  89: **	Parameters:
  90: **		s -- string to add
  91: **		type -- type of variable being added
  92: **
  93: **	Called By:
  94: **		enter_ret()
  95: **
  96: **	History:
  97: **		6/1/78 -- (marc) written
  98: */
  99: 
 100: 
 101: add_ret(s, type)
 102: char        *s;
 103: int     type;
 104: {
 105:     register struct ret_list    *list;
 106:     register struct ret_var     *node;
 107:     extern char         *nalloc();
 108: 
 109:     if (!s)
 110:     {
 111:         s = "ERROR_TOKEN";
 112:         yysemerr("alloc error", s);
 113:     }
 114:     list = &Ret_list;
 115:     node = (struct ret_var *) nalloc(sizeof *node);
 116:     if (!node)
 117:     {
 118:         yysemerr("alloc error", s);
 119:         xfree(s);
 120:         return;
 121:     }
 122:     node->r_elm = s;
 123:     node->r_next = 0;
 124:     node->r_type = type;
 125:     if (list->ret_first == 0)
 126:         list->ret_first = list->ret_last = node;
 127:     else
 128:     {
 129:         list->ret_last->r_next = node;
 130:         list->ret_last = node;
 131:     }
 132: }
 133: 
 134: 
 135: /*
 136: **  W_RET -- Generates the IIn_get() calls for the Ret_list
 137: **
 138: **	Any variable whose type is not string gets an '&'
 139: **	(adress of) operand prepended.
 140: **
 141: **	Called By:
 142: **		"gen_while" production
 143: **
 144: **	History:
 145: **		6/1/78 -- (marc) written
 146: */
 147: 
 148: 
 149: w_ret()
 150: {
 151:     register struct ret_var *node;
 152:     char            type [3];
 153: 
 154:     for (node = Ret_list.ret_first; node; node = node->r_next)
 155:     {
 156:         w_op("IIn_ret(");
 157:         if (node->r_type != opSTRING)
 158:             w_op("&");
 159:         w_op(node->r_elm);
 160:         w_op(",");
 161:         itoa(node->r_type, type);
 162:         w_op(type);
 163:         w_op(");");
 164:     }
 165: }
 166: 
 167: 
 168: /*
 169: **  FRE_RET -- Free up the storage used by the Ret_list
 170: **
 171: **	History:
 172: **		6/1/78 -- (marc) written
 173: **
 174: */
 175: 
 176: 
 177: 
 178: free_ret()
 179: {
 180:     register struct ret_list    *list;
 181:     register struct ret_var     *n, *f;
 182: 
 183:     list = &Ret_list;
 184:     for (f = list->ret_first; f; f = n)
 185:     {
 186:         n = f->r_next;
 187:         xfree(f->r_elm);
 188:         xfree(f);
 189:     }
 190:     list->ret_first = list->ret_last = 0;
 191: }

Defined functions

add_ret defined in line 101; used 1 times
  • in line 83
enter_ret defined in line 48; used 1 times
free_ret defined in line 178; used 1 times
w_ret defined in line 149; used 1 times
Last modified: 1995-04-14
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2545
Valid CSS Valid XHTML 1.0 Strict