1: # include   "../ingres.h"
   2: # include   "../tree.h"
   3: # include   "../symbol.h"
   4: # include   "decomp.h"
   5: 
   6: /*
   7: ** SETVAR -- Routines to convert a VAR to a constant and back to a VAR
   8: **
   9: **	This file contains the routines for tuple substitution.
  10: **
  11: **	Setvar -- Make a VAR node reference its position in the tuple.
  12: **
  13: **	Clrvar -- Make the VAR node refer back to a VAR
  14: */
  15: 
  16: setvar(tree1, var, intid, tuple)
  17: struct querytree    *tree1;
  18: int         var;
  19: long            *intid;
  20: char            *tuple;
  21: 
  22: /*
  23: ** Setvar -- Var's are changed to reference their values in a tuple.
  24: **	ROOT and AND nodes are changed to update the variable maps.
  25: */
  26: 
  27: {
  28:     register struct querytree   *tree;
  29:     register int            mask, nvc;
  30:     struct descriptor       *readopen();
  31:     extern struct querytree     *ckvar();
  32: 
  33:     tree = tree1;
  34:     if (!tree)
  35:         return;
  36:     switch (tree->sym.type)
  37:     {
  38:       case VAR:
  39:         if (((struct qt_var *)(tree=ckvar(tree)))->varno == var)
  40:         {
  41: #			ifdef xDTR1
  42:             if (tTf(12, 0))
  43:             {
  44:                 printf("setvar:%d;tree:", var);
  45:                 writenod(tree);
  46:             }
  47: #			endif
  48:             if (((struct qt_var *)tree)->attno)
  49:                 ((struct qt_var *)tree)->valptr = tuple +
  50:                     readopen(var)->reloff[((struct qt_var *)tree)->attno];
  51:             else
  52:                 ((struct qt_var *)tree)->valptr = (char *) intid;
  53:         }
  54:         return;
  55: 
  56:       case ROOT:
  57:       case AND:
  58:         mask = 01 << var;
  59:         nvc = ((struct qt_root *)tree)->tvarc;
  60:         if (((struct qt_root *)tree)->lvarm & mask)
  61:         {
  62:             setvar(tree->left, var, intid, tuple);
  63:             ((struct qt_root *)tree)->lvarm &=  ~mask;
  64:             --((struct qt_root *)tree)->lvarc;
  65:             nvc = ((struct qt_root *)tree)->tvarc - 1;
  66:         }
  67:         if (((struct qt_root *)tree)->rvarm & mask)
  68:         {
  69:             setvar(tree->right, var, intid, tuple);
  70:             ((struct qt_root *)tree)->rvarm &=  ~mask;
  71:             nvc = ((struct qt_root *)tree)->tvarc - 1;
  72:         }
  73:         ((struct qt_root *)tree)->tvarc = nvc;
  74:         return;
  75: 
  76:       default:
  77:         setvar(tree->left, var, intid, tuple);
  78:         setvar(tree->right, var, intid, tuple);
  79:         return;
  80:     }
  81: }
  82: 
  83: 
  84: clearvar(tree1, var1)
  85: struct querytree    *tree1;
  86: int         var1;
  87: 
  88: /*
  89: **	Clearvar is the opposite of setvar. For
  90: **	each occurence of var1 in the tree, clear
  91: **	the valptr.
  92: */
  93: 
  94: {
  95:     register struct querytree   *tree;
  96:     int             var;
  97:     extern struct querytree     *ckvar();
  98: 
  99:     tree = tree1;
 100:     if (!tree)
 101:         return;
 102: 
 103:     var = var1;
 104:     if (tree->sym.type == VAR)
 105:     {
 106:         if (((struct qt_var *)(tree = ckvar(tree)))->varno == var)
 107:             ((struct qt_var *)tree)->valptr = 0;
 108:         return;
 109:     }
 110:     clearvar(tree->left, var);
 111:     clearvar(tree->right, var);
 112: }

Defined functions

clearvar defined in line 84; used 4 times
setvar defined in line 16; used 5 times
Last modified: 1995-04-14
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2690
Valid CSS Valid XHTML 1.0 Strict