1: # include   "../ingres.h"
   2: # include   "../tree.h"
   3: # include   "../symbol.h"
   4: # include   "decomp.h"
   5: 
   6: 
   7: extern struct querytree     *need();
   8: 
   9: 
  10: struct querytree *copytree(root, buf)
  11: struct querytree    *root;
  12: char            *buf;
  13: 
  14: /*
  15: **	Make a copy of a tree.
  16: */
  17: 
  18: {
  19:     register struct querytree   *r, *q;
  20:     register int            length;
  21: 
  22:     r = root;
  23: 
  24:     if (!r)
  25:         return (0);
  26: 
  27:     length = r->sym.len & I1MASK;
  28:     q = need(buf, length + 6);
  29:     bmove(&r->sym, &q->sym, length + 2);
  30: 
  31:     q->left = copytree(r->left, buf);
  32:     q->right = copytree(r->right, buf);
  33: 
  34:     return (q);
  35: }
  36: struct querytree *copy_ands(root, buf)
  37: struct querytree    *root;
  38: char            *buf;
  39: 
  40: /*
  41: **	Make a new copy of the root by making
  42: **	new AND nodes and connecting them to the
  43: **	same branches.
  44: */
  45: {
  46:     register struct querytree   *q;
  47:     register struct querytree   *x, *y;
  48:     struct querytree        *newroot;
  49: 
  50: #	ifdef xDTR1
  51:     if (tTf(10, -1))
  52:         printf("COPY_ANDS");
  53: #	endif
  54:     newroot = need(buf, 0);
  55:     y = 0;
  56: 
  57:     for (q=root; q->sym.type != QLEND; q=q->right)
  58:     {
  59:         x = need(buf, q->sym.len + 6);
  60:         x->left = q->left;
  61:         bmove(&q->sym, &x->sym, q->sym.len + 2);
  62:         if (y)
  63:             y->right = x;
  64:         y = x;
  65:     }
  66:     y->right = q;
  67: 
  68: #	ifdef xDTR1
  69:     if (tTf(10, 0))
  70:         printree(newroot, "Newtree");
  71: #	endif
  72:     return(newroot);
  73: }
  74: 
  75: 
  76: 
  77: struct querytree *makroot(buf)
  78: char    *buf;
  79: {
  80:     register struct querytree *s;
  81: 
  82:     s = need(buf, 14);
  83:     s->right = Qle;
  84:     s->left = Tr;
  85:     ((struct qt_root *)s)->rootuser = ((struct qt_root *)s)->lvarm = ((struct qt_root *)s)->rvarm = ((struct qt_root *)s)->tvarc = ((struct qt_root *)s)->lvarc = 0;
  86:     s->sym.type = ROOT;
  87:     s->sym.len = 8;
  88:     return (s);
  89: }
  90: 
  91: 
  92: struct querytree *makresdom(buf, node)
  93: char            *buf;
  94: struct querytree    *node;
  95: {
  96:     register struct querytree   *res, *n;
  97: 
  98:     n = node;
  99:     res = need(buf, 10);
 100:     res->sym.type = RESDOM;
 101:     res->sym.len = 4;
 102:     if (n->sym.type == AOP)
 103:     {
 104:         ((struct qt_var *)res)->frmt = ((struct qt_ag *)n)->agfrmt;
 105:         ((struct qt_var *)res)->frml = ((struct qt_ag *)n)->agfrml;
 106:     }
 107:     else
 108:     {
 109:         ((struct qt_var *)res)->frmt = ((struct qt_var *)n)->frmt;
 110:         ((struct qt_var *)res)->frml = ((struct qt_var *)n)->frml;
 111:     }
 112:     return (res);
 113: }
 114: 
 115: struct querytree *makavar(node, varnum, attnum)
 116: struct querytree    *node;
 117: int         varnum, attnum;
 118: {
 119:     register struct querytree *avar, *n;
 120: 
 121:     n = node;
 122:     avar = need(Qbuf, 12);
 123:     avar->left = avar->right = (struct querytree *) 0;
 124:     ((struct qt_var *)avar)->valptr = (char *) 0;
 125:     avar->sym.type = VAR;
 126:     avar->sym.len = 6;
 127:     ((struct qt_var *)avar)->frmt = ((struct qt_var *)n)->frmt;
 128:     ((struct qt_var *)avar)->frml = ((struct qt_var *)n)->frml;
 129:     ((struct qt_var *)avar)->varno = varnum;
 130:     ((struct qt_var *)avar)->attno = attnum;
 131: #	ifdef xDTR1
 132:     if (tTf(14, 3))
 133:     {
 134:         printf("makavar: node=%l  ", n);
 135:         writenod(avar);
 136:     }
 137: #	endif
 138:     return(avar);
 139: }
Last modified: 1995-04-14
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3130
Valid CSS Valid XHTML 1.0 Strict