1: # include   "../ingres.h"
   2: # include   "../tree.h"
   3: # include   "../symbol.h"
   4: 
   5: /*
   6: **  TRBUILD -- Rebuild a tree in memory
   7: **
   8: **	Trbuild is called with a pointer to the TREE node of
   9: **	a query already in memory. It rebuilds the pointer
  10: **	structure assuming the querytree is in postfix order.
  11: **
  12: **	Parameters:
  13: **		bufptr - a pointer to the TREE node
  14: **
  15: **
  16: **	Returns:
  17: **		NULL - Internal stack overflow (STACKSIZ)
  18: **		pointer to the ROOT node
  19: **
  20: **	Side Effects:
  21: **		All left & right pointers are rebuilt.
  22: **
  23: **	Called By:
  24: **		readq
  25: **
  26: **	Syserrs:
  27: **		syserr if there are too many leaf nodes or too
  28: **		few child nodes
  29: **
  30: **	History:
  31: **		1/18/79 (rse) - written
  32: */
  33: 
  34: 
  35: struct querytree *trbuild(bufptr)
  36: char    *bufptr;
  37: {
  38:     register struct querytree   **stackptr;
  39:     register char           *p; /* really struct querytree * */
  40:     register struct symbol      *s;
  41:     struct querytree        *treestack[STACKSIZ];
  42: 
  43: 
  44:     stackptr = treestack;
  45: 
  46:     for (p = bufptr; ;p += 6 + ((s->len + 1) & 0376))
  47:     {
  48:         s = &(((struct querytree *)p)->sym);
  49:         ((struct querytree *)p)->left = ((struct querytree *)p)->right = 0;
  50: 
  51:         /* reunite p with left and right children on stack, if any*/
  52:         if (!leaf(p))       /* this node has children */
  53:         {
  54:             if (s->type != UOP)
  55:                 if (stackptr <= treestack)
  56:                 {
  57:                 err:
  58:                     syserr("trbuild:too few nodes");
  59:                 }
  60:                 else
  61:                     ((struct querytree *)p)->right = *(--stackptr);
  62:             if (s->type != AOP)
  63:                 if (stackptr <= treestack)
  64:                     goto err;
  65:                 else
  66:                     ((struct querytree *)p)->left = *(--stackptr);
  67:         }
  68: 
  69:         /*
  70: 		** If this is a ROOT node then the tree is complete.
  71: 		** verify that there are no extra nodes in the
  72: 		** treestack.
  73: 		*/
  74:         if (s->type == ROOT)        /* root node */
  75:         {
  76:             if (stackptr != treestack)
  77:                 syserr("trbuild:xtra nodes");
  78:             return ((struct querytree *)p);
  79:         }
  80: 
  81:         /* stack p */
  82:         if (stackptr-treestack >= STACKSIZ)
  83:             return (NULL);  /* error:stack full */
  84:         *(stackptr++) = (struct querytree *)p;
  85: 
  86:     }
  87: }
  88: 
  89: 
  90: leaf(p)
  91: struct querytree *p;
  92: {
  93:     switch (p->sym.type)
  94:     {
  95:       case VAR:
  96:       case TREE:
  97:       case QLEND:
  98:       case INT:
  99:       case FLOAT:
 100:       case CHAR:
 101:       case COP:
 102:         return(1);
 103: 
 104:       default:
 105:         return(0);
 106:     }
 107: }

Defined functions

leaf defined in line 90; used 1 times
  • in line 52
Last modified: 1995-02-12
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2203
Valid CSS Valid XHTML 1.0 Strict