1: # include   "../ingres.h"
   2: # include   "../symbol.h"
   3: # include   "../tree.h"
   4: # include   "../aux.h"
   5: # include   "qrymod.h"
   6: 
   7: /*
   8: **  TREEPR -- print tree for debugging
   9: **
  10: **	This module prints a tree for debugging purposes.  There are
  11: **	two interfaces: treepr prints an entire tree, and nodepr
  12: **	prints a single node.
  13: **
  14: **	Defines:
  15: **		treepr -- tree print interface.
  16: **		rcsvtrpr -- the recursive part to traverse the tree.
  17: **		nodepr -- node print interface.
  18: **
  19: **	Requires:
  20: **		ferror -- to get the Qmdname[] vector.
  21: **		Rangev -- to print the range table.
  22: **
  23: **	Required By:
  24: **		treeio.c
  25: **		maybe others.
  26: **
  27: **	Files:
  28: **		none
  29: **
  30: **	Trace Flags:
  31: **		none
  32: **
  33: **	History:
  34: **		2/14/79 -- version 6.2/0 release.
  35: **		1/15/79 (eric) -- made simple before release.
  36: **		3/27/78 (eric) -- prettied up
  37: **		2/24/78 (eric) -- written
  38: */
  39: 
  40: 
  41: 
  42: 
  43: extern char *Qmdname[]; /* defined in util.c */
  44: /*
  45: **  TREEPR -- print tree for debugging
  46: **
  47: **	This routine prints a tree for debugging.
  48: **
  49: **	Parameters:
  50: **		tree -- root of tree to be printed
  51: **		label -- label to print for identifying the tree.  NULL
  52: **			is OK and produces a default label.
  53: **
  54: **	Returns:
  55: **		none
  56: **
  57: **	Side Effects:
  58: **		output to terminal
  59: **
  60: **	Requires:
  61: **		rcsvtrpr -- tree traversal routine.
  62: **		Rangev.
  63: **
  64: **	History:
  65: **		2/24/78 (eric) -- written
  66: */
  67: 
  68: treepr(tree, label)
  69: QTREE   *tree;
  70: char    *label;
  71: {
  72:     register QTREE  *t;
  73:     register char   *l;
  74:     register int    i;
  75: 
  76:     t = tree;
  77:     l = label;
  78: 
  79:     /* print label */
  80:     printf("\n");
  81:     if (l != NULL)
  82:         printf("%s ", l);
  83:     printf("Querytree @ %u:\n", t);
  84: 
  85:     /* print range table */
  86:     for (i = 0; i < MAXVAR + 1; i++)
  87:     {
  88:         if (!Rangev[i].rused)
  89:             continue;
  90:         printf("range of %d is %.12s [O=%.2s, S=%o]\n",
  91:             i, Rangev[i].relid, Rangev[i].rowner, Rangev[i].rstat);
  92:     }
  93: 
  94:     /* print query type */
  95:     if (Qmode >= 0)
  96:         printf("%s ", Qmdname[Qmode]);
  97: 
  98:     /* print result relation if realistic */
  99:     if (Resultvar >= 0)
 100:         printf("Resultvar %d ", Resultvar);
 101:     printf("\n");
 102: 
 103:     /* print tree */
 104:     rcsvtrpr(t);
 105: 
 106:     /* print exciting final stuff */
 107:     printf("\n");
 108: }
 109: /*
 110: **  RCSVTRPR -- traverse and print tree
 111: **
 112: **	This function does the real stuff for treepr.  It recursively
 113: **	traverses the tree in postfix order, printing each node.
 114: **
 115: **	Parameters:
 116: **		tree -- the root of the tree to print.
 117: **
 118: **	Returns:
 119: **		none
 120: **
 121: **	Side Effects:
 122: **		none
 123: **
 124: **	Requires:
 125: **		nodepr -- to actually print the node.
 126: **
 127: **	Called By:
 128: **		treepr
 129: **
 130: **	Trace Flags:
 131: **		none
 132: */
 133: 
 134: rcsvtrpr(tree)
 135: QTREE   *tree;
 136: {
 137:     register QTREE  *t;
 138: 
 139:     t = tree;
 140: 
 141:     while (t != NULL)
 142:     {
 143:         rcsvtrpr(t->left);
 144:         nodepr(t, FALSE);
 145:         t = t->right;
 146:     }
 147: }
 148: /*
 149: **  NODEPR -- print node for debugging
 150: **
 151: **	Parameters:
 152: **		tree -- the node to print.
 153: **
 154: **	Returns:
 155: **		none
 156: **
 157: **	Side Effects:
 158: **		output to terminal
 159: **
 160: **	Requires:
 161: **		none
 162: */
 163: 
 164: 
 165: 
 166: nodepr(tree)
 167: QTREE   *tree;
 168: {
 169:     register QTREE  *t;
 170:     register int    ty;
 171:     int     l;
 172:     char        *cp;
 173: 
 174:     t = tree;
 175:     ty = t->sym.type;
 176:     l = t->sym.len & I1MASK;
 177: 
 178:     printf("%u: %u, %u/ ", t, t->left, t->right);
 179:     printf("%d, %d: ", ty, l);
 180: 
 181:     switch (ty)
 182:     {
 183:       case VAR:
 184:         printf("%d.%d [%d/%d]",
 185:             ((struct qt_var *)t)->varno,
 186:             ((struct qt_var *)t)->attno,
 187:             ((struct qt_var *)t)->frmt,
 188:             ((struct qt_var *)t)->frml & I1MASK);
 189:         break;
 190: 
 191:       case RESDOM:
 192:         printf("%d [%d/%d]",
 193:             ((struct qt_res *)t)->resno,
 194:             ((struct qt_var *)t)->frmt,
 195:             ((struct qt_var *)t)->frml);
 196:         break;
 197: 
 198:       case AOP:
 199:         printf("%d [%d/%d] [%d/%d]",
 200:             ((struct qt_res *)t)->resno,
 201:             ((struct qt_var *)t)->frmt,
 202:             ((struct qt_var *)t)->frml,
 203:             ((struct qt_ag *)t)->agfrmt,
 204:             ((struct qt_ag *)t)->agfrml);
 205:         break;
 206: 
 207:       case UOP:
 208:       case BOP:
 209:       case COP:
 210:       case INT:
 211:         switch (t->sym.len)
 212:         {
 213:           case 1:
 214:           case 2:
 215:             printf("%d", t->sym.value[0]);
 216:             break;
 217: 
 218:           case 4:
 219:             printf("%s", locv(i4deref(t->sym.value)));
 220:             break;
 221:         }
 222:         break;
 223: 
 224:       case FLOAT:
 225:         printf("%.10f", i4deref(t->sym.value));
 226:         break;
 227: 
 228:       case CHAR:
 229:         cp = (char *) t->sym.value;
 230:         while (l--)
 231:             putchar(*cp++);
 232:         break;
 233: 
 234:       case TREE:
 235:       case AND:
 236:       case OR:
 237:       case QLEND:
 238:       case BYHEAD:
 239:       case ROOT:
 240:       case AGHEAD:
 241:         break;
 242: 
 243:       default:
 244:         syserr("nodepr: ty %d", ty);
 245:     }
 246:     printf("/\n");
 247: }
Last modified: 1995-02-19
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1321
Valid CSS Valid XHTML 1.0 Strict