treecode.def
上传用户:dgyhgb
上传日期:2007-01-07
资源大小:676k
文件大小:30k
源码类别:

SQL Server

开发平台:

Unix_Linux

  1. /*
  2.  * treecode.def  - description of nodes, used by GNU SQL compiler
  3.  *                 tree library
  4.  *
  5.  *  This file is a part of GNU SQL Server
  6.  *
  7.  *  Copyright (c) 1996, 1997, Free Software Foundation, Inc
  8.  *  Developed at the Institute of System Programming, Russia
  9.  *  This file is written by Michael Kimelman
  10.  *
  11.  *  This program is free software; you can redistribute it and/or modify
  12.  *  it under the terms of the GNU General Public License as published by
  13.  *  the Free Software Foundation; either version 2 of the License, or
  14.  *  (at your option) any later version.
  15.  *
  16.  *  This program is distributed in the hope that it will be useful,
  17.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.  *  GNU General Public License for more details.
  20.  *
  21.  *  You should have received a copy of the GNU General Public License
  22.  *  along with this program; if not, write to the Free Software
  23.  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  24.  *
  25.  *  Contact:  gss@ispras.ru
  26.  *
  27.  */
  28. /* $Id: treecode.def,v 1.245 1997/03/31 03:46:38 kml Exp $ */
  29. /*************************************************************************. 
  30. *     Each used by compiler tree node has to described here in the        *
  31. *  following format                                                       *
  32. *                                                                         *
  33. *    DEF_TOKEN(CODE,"code","prdav",'o',"01S")                             *
  34. *                                                                         *
  35. * where:                                                                  *
  36. *   CODE     -   node code, used as a symbolic constant in compiler       *
  37. *  "code"    -   string, which contains the same literal as a CODE, but   *
  38. *                in a bit more readable form. Used in dumps as image of   *
  39. *                CODE.                                                    *
  40. *         Note: uppercase("code") = "CODE"  - it's important for tree     *
  41. *               recognizer                                                *
  42. *  "prdav" -   node fields' descriptors                                   *
  43. *        p  - posiiton (just source line),                                *
  44. *        r  - reference to the right,                                     *
  45. *        d  - reference to the down ( to subtrees),                       *
  46. *        a  - arity, (generally need for self-testing)                    *
  47. *        v  - reference to the vocabulary (we don't print twice recursive *
  48. *             'v' fields)                                                 *
  49. *        V  - obsolete                                                    *
  50. *        t  - regular tree reference (in addition to 'right' & 'down' )   *
  51. *        s  - reference to stored literal (string)                        *
  52. *        l  - i4_t i4_t                                                    *
  53. *        x  - i4_t i4_t but dumped in hexadecimal format                   *
  54. *        f  - float,                                                      *
  55. *        y  - SQL type descriptor,                                        *
  56. *        R  - compound construction (dumped just as set of i4_t )         *
  57. *        T  - vector of tree references                                   *
  58. *        L  - vector of i4_t ints;                                        *
  59. *  'o'     -   node class                                                 *
  60. *       'o' - OPERATION,                                                  *
  61. *       's' - STATEMENT,                                                  *
  62. *       't' - DB_TABL,                                                    *
  63. *       'i' - DB_OBJ (item),                                              *
  64. *       'K' - Kitty actions,                                              *
  65. *       'C' - struct column    (vocabulary),                              *
  66. *       'T' - struct table     (vocabulary),                              *
  67. *       'R' - struct cursor    (vocabulary),                              *
  68. *       'S' - struct corr_name -- scan name (vocabulary) ,                *
  69. *       'N' - struct constant  (vocabulary) ,                             *
  70. *       'P' - struct parameter (vocabulary);                              *
  71. *  "01S"   - each letter in this string means class of flags applyable to *
  72. *            this node                                                    *
  73. *                                                                         *
  74. '*************************************************************************/
  75. #ifdef DEF_TOKEN
  76.   DEF_TOKEN(UNKNOWN,"UnKnown"  ,"*"      ,' ',"")
  77.   DEF_TOKEN(NIL_CODE,"nil"     ,"*"      ,' ',"")
  78. #endif
  79. /*******==================================================*******
  80. *******             Special tree  nodes                    *******
  81. *******==================================================*******/
  82. #ifdef DEF_TOKEN
  83. /*---------<<  Statements nodes >>----------------------------------*/
  84.   DEF_TOKEN(PREPARED ,"Prepared" ,"prda0s0V",'s',"0v")
  85.   DEF_TOKEN(INSERT ,"Insert" ,"prdal0tV",'s',"0iv")
  86.   DEF_TOKEN(SELECT ,"Select" ,"prdal00V",'s',"0tsv")
  87.   DEF_TOKEN(UPDATE ,"Update" ,"prdalLtV",'s',"0v")
  88.   DEF_TOKEN(DELETE ,"Delete" ,"prdalLtV",'s',"0v")
  89.   /*- - - - - < Cursors processing > - - - - - - - - - - - - - - - -*/
  90.   DEF_TOKEN(CUR_AREA ,"Cur_Area" ,"prdal000",'s',"0v")
  91.   DEF_TOKEN(DECL_CURS ,"Decl_Curs" ,"prda000V",'s',"0v")
  92. #if 0
  93.     /*- - < Not used because the statements below are too easy > - - - -*/
  94.     DEF_TOKEN(CLOSE ,"Close" ,"prdal000",'s',"0v") /* not used */
  95.     DEF_TOKEN(OPEN ,"Open" ,"prdal000",'s',"0v") /* not used */
  96.     /*- - < Not used because replace to direct engine call > - - - - -*/
  97.     DEF_TOKEN(ROLLBACK ,"Rollback" ,"pr00l000",'s',"0v") /* not used */
  98.     DEF_TOKEN(COMMIT ,"Commit" ,"pr00l000",'s',"0v") /* not used */
  99. #endif
  100.   DEF_TOKEN(FETCH ,"Fetch" ,"pr00l00V",'s',"0v") 
  101.   /*- - - - - < Schemes processing > - - - - - - - - - - - - - - - -*/
  102.   DEF_TOKEN(CREATE ,"Create" ,"prt0l00V",'s',"0v") /* v-table pointer */
  103.   DEF_TOKEN(DROP ,"Drop" ,"prt0l00V",'s',"0v") /* v-table pointer */
  104.   DEF_TOKEN(ALTER ,"Alter" ,"prt0l00V",'s',"0v") /* v-table pointer */
  105.   DEF_TOKEN(GRANT ,"Grant" ,"prdal000",'s',"0Gv") 
  106.   DEF_TOKEN(REVOKE ,"Revoke" ,"prdal000",'s',"0Gv") 
  107. #else
  108.   #define Is_Statement(node)      (STRUCT(CODE_TRN(node))=='s' && TstF_TRN(node,HAS_VCB_F))
  109.   #define Is_statement(node)      (STRUCT(CODe_TRN(node))=='s' && Tstf_TRN(node,HAS_VCB_F))
  110.   #define   STMT_NAME(node)       XLTR_TRN(node,5)
  111.   #define   STMT_UID(node)        XLNG_TRN(node,4)
  112.   #define   STMT_VCB(node)        XVCB_TRN(node,7)
  113.   #define   UPD_CURS(node)        XVCB_TRN(node,6)
  114.   #define   UPD_CLMNS(node)       XVEC_TRN(node,5)
  115.   #define   SCAN_PTR(node)        XVCB_TRN(node,6)
  116.   #define   CREATE_OBJ(node)      XVCB_TRN(node,2)
  117.   typedef struct statement{        /****************************/
  118.     enum token code;               /* statement code           */
  119.     MASKTYPE   mask;               /* mask of statement's flag */
  120.     POSITION   line_nmb;           /* source line info         */
  121.     TXTREF     right;              /* next statement           */
  122.     TXTREF     down;               /* chain of childrens       */
  123.     i4_t       arity;              /* number of childrens      */
  124.                                    /****************************/
  125.     i4_t       stmt_nmb;           /* source line number       */
  126.     TXTREF     upd_clmns;          /* vector of numbers of up- */
  127.                                    /* dated columns            */
  128.     VCBREF     cursor;             /* vocabulary reference to  */
  129.                                    /* updated cursor if need   */
  130.     VCBREF     vcbl;               /* local vocabulary chain   */
  131.                                    /****************************/
  132.   } STATEMENT, * PSTATEMENT;
  133. #endif
  134. #ifdef DEF_TOKEN
  135. /*---------<<  Operation nodes >>----------------------------------------*/
  136. /*-----------------------------------------------------------------------*/
  137. /*---------<<  Kitty operations  >>--------------------------------------*/
  138. /*-----------------------------------------------------------------------*/
  139. /* (Rule "rule_name" (pattern) "Cstyle test" [ (action) ...])       */
  140. /* !!!!!!! 0 - is used like STMT_UID in statement                   */
  141.   DEF_TOKEN(RULE ,"Rule" ,"srda0Ps" ,'K',"0R")  
  142.   DEF_TOKEN(RUN_RULE ,"Run" ,"srt" ,'K',"0")  
  143. /* (Op:n "test_routine_name") <-- in pattern                        */
  144. /* or simple (Op:n) in actions (perhaps even without parentheses)   */
  145.   DEF_TOKEN(OPERAND ,"Op" ,"Srda" ,'K',"0")
  146. /* if - operator when kitty is used in C-code directly              */
  147. /* P - pattern, S.1 - reference to tested variable,                 */
  148. /* S.2 - buffer address TXTREF bufer[15] ( for example )            */
  149. /* (? "in_tree" "Ops" (Add {(Const) (Const) })                      */
  150.   DEF_TOKEN(IF                  ,"?"           ,"sr0sP"        ,'K',"0")
  151. /* (C_code "C text with special processing for " . ; ")            */
  152. /* Can be used outside of rules                                     */
  153.   DEF_TOKEN(TRLcmd_CCODE ,"C_code" ,"sr000" ,'K',"0")
  154. /* SET is used for assignment local variables (==Operands)          */
  155. /* Example: (SET:5 (tr_expression))                                 */
  156.   DEF_TOKEN(TRLcmd_SET ,"SET" ,"tr" ,'K',"0")
  157.   DEF_TOKEN(TRLcmd_DOWN ,"DOWN" ,"tr" ,'K',"0")
  158.   DEF_TOKEN(TRLcmd_RIGHT ,"RIGHT" ,"tr" ,'K',"0")
  159.   DEF_TOKEN(TRLcmd_COPY ,"COPY" ,"tr" ,'K',"0")
  160. /* IMAGE returns pointer to image of Op1, which has Op2 node as a   */
  161. /* ancestor, in Op3 tree, which must be a image of Op2 tree         */
  162.   DEF_TOKEN(TRLcmd_IMAGE ,"IMAGE" ,"trtt" ,'K',"0")
  163. /* DELETE deletes operand 0 from list of son1 or from list of OpR   */
  164. /* Example: (DELETE (DOWN (Op:1)) <(RIGHT (Op:3))> )                */
  165.   DEF_TOKEN(TRLcmd_DELETE ,"DELETE" ,"trt" ,'K',"0")
  166. /* INSERT inserts op0 in list of parameters of op2  before or after */
  167. /* op3 or, if op3 is omitted, at the begin or end of the whole list */
  168. /* Example: (INSERT<:before> (Op:1)  (Op:2) <(Op:3)> )              */
  169.   DEF_TOKEN(TRLcmd_INSERT ,"INSERT" ,"trtt" ,'K',"0I")
  170.   DEF_TOKEN(TRLcmd_REPLACE ,"REPLACE" ,"trtt" ,'K',"0")
  171. /* (REMOVE<:tree> (Op:5))                                           */
  172.   DEF_TOKEN(TRLcmd_REMOVE ,"REMOVE" ,"tr" ,'K',"0I")
  173. /* SWITCH define local var CC and set it to 0; than SW executes each*/
  174. /* son and checks value of CC after it. When CC become 1 SW finished*/
  175. /* CC==0 at the end of SW is recognized as a error                  */
  176.   DEF_TOKEN(TRLcmd_SWITCH ,"SWITCH" ,"trda" ,'K',"0a")
  177.   DEF_TOKEN(TRLcmd_CASE ,"CASE" ,"sr" ,'K',"0")
  178. /* SKIP_CODE (or even '-') in pattern means not to compare node     */
  179.   DEF_TOKEN(SKIP_CODE ,"Skip_Code","0r" ,'K',"0")  
  180. /* SKIP_CODES (or '--') means any number of any kind of parameters  */
  181.   DEF_TOKEN(SKIP_CODES ,"Skip_Codes","0r" ,'K',"0")  
  182.   
  183. /*-----------------------------------------------------------------------*/
  184. /*---------<<  SQL tree operations' codes >>-----------------------------*/
  185. /*-----------------------------------------------------------------------*/
  186.   DEF_TOKEN(ORDER  ,"Order"     ,"prda"     ,'o',"0")
  187.   DEF_TOKEN(CHECK  ,"Check"     ,"prda"     ,'o',"0")  /* a equal 1*/
  188.   DEF_TOKEN(UNIQUE ,"Unique"    ,"prdaRRRR" ,'o',"0")
  189.   DEF_TOKEN(PRIMARY ,"Primary"  ,"prdaRRRR" ,'o',"0")
  190.   DEF_TOKEN(INDEX   ,"Index"    ,"prdaRRRR" ,'o',"0")
  191.   DEF_TOKEN(FOREIGN ,"Foreign"  ,"prda"     ,'o',"0")
  192.   DEF_TOKEN(REFERENCE ,"Reference" ,"prda"     ,'o',"0")
  193.   DEF_TOKEN(LOCALLIST ,"LocalList" ,"prda"     ,'o',"0") 
  194.   DEF_TOKEN(PRIVILEGIES ,"Privilegies" ,"prda"     ,'o',"0") 
  195.   DEF_TOKEN(GRANTEES ,"Granties" ,"prda"     ,'o',"0") 
  196.   DEF_TOKEN(CONSTRAINTS ,"Constraints" ,"prda"     ,'o',"0") 
  197.   DEF_TOKEN(NOT    ,"Not"       ,"prday0"   ,'o',"0")  /* a equal 1*/
  198.   DEF_TOKEN(AND    ,"And"       ,"prday0"   ,'o',"0")
  199.   DEF_TOKEN(OR     ,"Or"        ,"prday0"   ,'o',"0")
  200.   DEF_TOKEN(UNION       ,"Union"     ,"prda"     ,'o',"0u") /* ts->u 12.3*/
  201.  /* TBLEXP -- form for expressions QUERY,SUBQUERY etc. */
  202.   DEF_TOKEN(TBLEXP ,"TblExp"    ,"prda00"    ,'o',"0t")
  203.   DEF_TOKEN(SUBQUERY ,"SubQuery" ,"prday0"    ,'o',"0ts")
  204.   DEF_TOKEN(QUERY  ,"Query"     ,"prda00"    ,'o',"0ts")
  205.   DEF_TOKEN(FROM    ,"From" ,"prda"     ,'o',"0")
  206.   DEF_TOKEN(WHERE   ,"Where" ,"prda"     ,'o',"0")  /* a equal 1*/
  207.   DEF_TOKEN(HAVING ,"Having" ,"prda"     ,'o',"0")  /* a equal 1*/
  208.   DEF_TOKEN(GROUP ,"Group" ,"prda"     ,'o',"0")
  209.   DEF_TOKEN(SELECTION ,"Selection" ,"prda"     ,'o',"0")
  210.   /* Result is the same thing as Selection but for subqueries where 'a'    */
  211.   /* be equal 1 */
  212.   DEF_TOKEN(RESULT ,"Result" ,"prda"     ,'o',"0")     
  213.   DEF_TOKEN(IVALUES ,"Ivalues" ,"prda"     ,'o',"0") /* operator INSERT */
  214.   DEF_TOKEN(VALUES ,"Values" ,"prday0"   ,'o',"0") /* predicate IN    */
  215.   /* INTO - param list in SELECT and column list in INSERT */
  216.   DEF_TOKEN(INTO        ,"Into" ,"prda"     ,'o',"0")
  217.   DEF_TOKEN(EQU ,"Equ" ,"prday0"   ,'o',"0o") /* a equal 2*/
  218.   DEF_TOKEN(NE ,"Ne" ,"prday0"   ,'o',"0o") /* a equal 2*/
  219.   DEF_TOKEN(LE ,"Le" ,"prday0"   ,'o',"0o") /* a equal 2*/
  220.   DEF_TOKEN(GE ,"Ge" ,"prday0"   ,'o',"0o") /* a equal 2*/
  221.   DEF_TOKEN(LT ,"Lt" ,"prday0"   ,'o',"0o") /* a equal 2*/
  222.   DEF_TOKEN(GT ,"Gt" ,"prday0"   ,'o',"0o") /* a equal 2*/
  223.   DEF_TOKEN(CALLPR      ,"Callpr"       ,"prday0"   ,'o',"0" )
  224.   DEF_TOKEN(NOOP        ,"Noop"         ,"lrday0"   ,'o',"0" ) /* a equal 1*/
  225.   DEF_TOKEN(EXISTS ,"Exists" ,"prday0"   ,'o',"0")  /* a equal 1*/
  226.   DEF_TOKEN(SOME        ,"Some"         ,"prday0"   ,'o',"0")
  227.   DEF_TOKEN(ALL         ,"All"          ,"prday0"   ,'o',"0")
  228.   DEF_TOKEN(IN ,"In" ,"prday0"   ,'o',"0o") /* a equal 2*/
  229.   DEF_TOKEN(LIKE ,"Like" ,"prday0"   ,'o',"0o") /* a equal 2-3*/
  230.   DEF_TOKEN(BETWEEN ,"Between" ,"prday0"   ,'o',"0o") /* a equal 3*/
  231.   DEF_TOKEN(ISNULL ,"IsNull" ,"prday0"   ,'o',"0o") /* a equal 1*/
  232.   DEF_TOKEN(ISNOTNULL ,"IsNotNull" ,"prday0"   ,'o',"0o") /* a equal 1*/
  233.   DEF_TOKEN(ASSLIST ,"AssList" ,"prda"     ,'o',"0")
  234.   DEF_TOKEN(ASSIGN ,"Assign" ,"prday0"   ,'o',"0")  /* a equal 2*/
  235.   DEF_TOKEN(ADD ,"Add" ,"prday0"   ,'o',"0")
  236.   DEF_TOKEN(SUB ,"Sub" ,"prday0"   ,'o',"0")  /* a equal 2*/
  237.   DEF_TOKEN(MULT ,"Mult" ,"prday0"   ,'o',"0")
  238.   DEF_TOKEN(DIV ,"Div" ,"prday0"   ,'o',"0")  /* a equal 2*/
  239.   DEF_TOKEN(UMINUS ,"Uminus" ,"prday0"   ,'o',"0")  /* a equal 1*/
  240.   DEF_TOKEN(AVG ,"Avg" ,"prday0"   ,'o',"0s") /* a equal 1*/
  241.   DEF_TOKEN(MAX ,"Max" ,"prday0"   ,'o',"0s") /* a equal 1*/
  242.   DEF_TOKEN(MIN ,"Min" ,"prday0"   ,'o',"0s") /* a equal 1*/
  243.   DEF_TOKEN(SUM ,"Sum" ,"prday0"   ,'o',"0s") /* a equal 1*/
  244.   DEF_TOKEN(COUNT ,"Count" ,"prday0"   ,'o',"0s") /* a equal 1*/
  245. #else
  246.  #define   VAL_HOLE(node)          XLNG_TRN(node,5)
  247.  #define   OPRN_TYPE(node)         XOP_TRN(node,4).type
  248.  #define   FUNC_OBJ(node)          XTXT_TRN(node,2)
  249.  #define   IND_INDID(node)      *((Indid*)&(xOp_PARMS(Ptree(node),4,"RRRR")))
  250.  #define Is_TRLService(node)       (STRUCT(CODE_TRN(node))==' ')
  251.  #define Is_Operation(node)        (STRUCT(CODE_TRN(node))=='o')
  252.  #define Is_Predicate(node)        (FLAGS(CODE_TRN(node))[1]=='o')
  253.  #define Is_Function(node)         (AVG<=CODE_TRN(node) && CODE_TRN(node)<=COUNT)
  254.  #define Is_Log_Oper_Code(code)    (NOT <= (code) && (code) <= OR)
  255.  #define Is_Comp_Code(code)        (EQU <= (code) && (code) <= GT)
  256.  #define Is_Arithm_Code(code)      (ADD <= (code) && (code) <= UMINUS)
  257.  #define Is_Predic_Code(code)      (EXISTS <= (code) && (code) <= ISNOTNULL)
  258.  #define Is_SQPredicate_Code(code) ((EXISTS <= (code) && (code) <= ALL) || (code) == SUBQUERY)
  259.  #define Is_Typed_Operation(node)  (FORMAT(CODE_TRN(node))[4]=='y')
  260.  typedef struct operation{        /*==== operation (subtree) ============*/
  261.    enum token code;               /* code of the operation               */
  262.    MASKTYPE   mask;               /* detalizing of the operation         */
  263.    POSITION   line_nmb;           /* source line number                  */
  264.    TXTREF     right;              /* next operation (right brother)      */
  265.    TXTREF     down;               /* reference to the first operand      */
  266.    i4_t       arity;              /* number of operands (children)       */
  267.    sql_type_t type;               /* operation result's type             */
  268.    i4_t       valuehole;          /* pointer to node's value             */
  269.   } OPERATION, * POPERATION;      /*=====================================*/
  270. #endif
  271. #ifdef DEF_TOKEN
  272. /* semantics of array is : [ 0 2 0 1 ] === order by (col 4) (Col 2)      */
  273.   DEF_TOKEN(SORTER,"Sorter"     ,"Lrt"     ,' ',"0s")    
  274. /* T is array of expressions, which computes values of assotiated column */
  275. /* in MakeGroup output table                                             */ 
  276.   DEF_TOKEN(MAKEGROUP ,"MakeGroup","Trt" ,' ',"0")    
  277. /*---------<<  Tree node for table ponters  >>---------------------------*/
  278.   DEF_TOKEN(TBLPTR,"TblPtr"   ,"prt"     ,'t',"0")
  279. #else
  280.  #define   TABL_DESC(node)        XVCB_TRN(node,2)
  281.  #define Is_TblPtr(node)         (STRUCT(CODE_TRN(node))=='t')
  282.  typedef struct db_tabl{          /*=====================================*/
  283.    enum token code;               /* node code                           */
  284.    MASKTYPE   mask;               /* node flags                          */
  285.    POSITION   line_nmb;           /* source line number                  */
  286.    TXTREF     right;              /* next leaf (right brother)           */
  287.    VCBREF     descr;              /* vocabulary reference                */
  288.   } DB_TABL, * PDB_TABL;          /*=====================================*/
  289. #endif
  290. #ifdef DEF_TOKEN
  291. /*---------<<  Tree object nodes >>--------------------------------------*/
  292.   DEF_TOKEN(OPTR     ,"OPtr"      ,"pr0t" ,'i',"0")
  293.   DEF_TOKEN(COLPTR   ,"ColPtr"    ,"pr0t" ,'i',"0")
  294.   DEF_TOKEN(PARMPTR  ,"ParmPtr"   ,"pr0t" ,'i',"0")
  295.   DEF_TOKEN(STAR     ,"Star"      ,"pr"   ,'i',"0")
  296.   DEF_TOKEN(NULL_VL  ,"Null_vl"   ,"pry"  ,'i',"0")
  297.   DEF_TOKEN(SORT_COL ,"Sort_Col"  ,"pr0t" ,'i',"0c")
  298.   DEF_TOKEN(SORT_POS ,"Sort_Pos"  ,"prl"  ,' ',"0c")  /*!!!*/
  299.   DEF_TOKEN(COL      ,"Col"       ,"lr"   ,' ',"0c")  /*!!!*/
  300.   DEF_TOKEN(USERNAME ,"UserName"  ,"prys" ,' ',"0")   /*!!!*/
  301.   DEF_TOKEN(VALUEHOLE,"ValueHole" ,"prs"  ,' ',"0")   /*!!!*/
  302. #else
  303.  #define   OBJ_ADDIT(node)        XTXT_TRN(node,2)
  304.  #define   OBJ_DESC(node)         XVCB_TRN(node,3)
  305.  #define   OBJ_AUX(node)          XVCB_TRN(node,4)
  306.  #define   SORT_CLM(node)         OBJ_DESC(node)
  307.  #define   SORT_IND(node)         XLNG_TRN(node,2)      /* for Sort_Pos  */
  308.  #define   USR_NAME(node)         XLTR_TRN(node,3)      /* for UserName  */
  309.  #define   USR_TYPE(node)         XOP_TRN(node,2).type  /* for UserName  */
  310.  #define   NULL_TYPE(node)        XOP_TRN(node,2).type  /* for Null_vl   */
  311.  #define   HOLE_NAME(node)        XLTR_TRN(node,2)      /* for valuehole */
  312.  #define Is_Object(node)          (STRUCT(CODE_TRN(node))=='i')
  313.  typedef struct db_object{        /*=====================================*/
  314.    enum token code;               /* object type code                    */
  315.    MASKTYPE   mask;               /* detalizing of the object type       */
  316.    POSITION   line_nmb;           /* source line number                  */
  317.    TXTREF     right;              /* next object of the same level       */
  318.    TXTREF     addit;              /* additional tree reference           */
  319.    VCBREF     descr;              /* reference to vocabulary             */
  320.    VCBREF     aux_ref;            /* additional referencnce to vocabulary*/
  321.    } DB_OBJ, * PDB_OBJ ;          /*=====================================*/
  322. #endif
  323. #ifdef DEF_TOKEN
  324. /*---------<<  Column nodes >>-------------------------------------------*/
  325.   DEF_TOKEN(COLUMN ,"Column" ,"srlyvt000" ,'C',"0")
  326.   DEF_TOKEN(SCOLUMN,"SColumn" ,"srlytt0l0" ,'C',"0")  /* scan column    */
  327. #else
  328.  #define   COL_NAME(node)        XLTR_TRN(node,0)
  329.  #define   COL_NEXT(node)        RIGHT_TRN(node)
  330.  #define   COL_NO(node)          XLNG_TRN(node,2)
  331.  #define   COL_TYPE(node)        XOP_TRN(node,3).type
  332.  #define   COL_TBL(node)         XVCB_TRN(node,4)
  333.  #define   COL_DEFAULT(node)     XTXT_TRN(node,5)
  334.  #define   COL_CONSTR(node)      XTXT_TRN(node,6)
  335.  #define   COL_ID(node)          XLNG_TRN(node,7)
  336.  #define   COL_ADR(node)         XTXT_TRN(node,7)
  337.  #define   COL_STAT(node)        XLNG_TRN(node,8)
  338.  #define Is_Column(node)         (STRUCT(CODE_TRN(node))=='C')
  339.  struct column{                   /*===================================*/
  340.           enum token code;        /*                                   */
  341.           MASKTYPE   flags;       /*                                   */
  342.           LTRLREF    name;        /* column name                       */
  343.           VCBREF     pcolumn;     /* next column of the same table     */
  344.           i4_t       column_no;   /* column number in table (DB info)  */
  345.           sql_type_t type;        /* column type                       */
  346.           VCBREF     ptable;      /* reference to the table, containing*/
  347.                                   /* this column                       */
  348.           TXTREF     default_val; /* reference to column default value */
  349.           TXTREF     constraint;  /*                                   */
  350.           i4_t       cl_id;       /* number of the column in           */     
  351.                                   /* the scan (? ? )                    */
  352.           i4_t       col_stat;    /* pointer to structure with statistic *
  353.                                    * info (max & min values in column)   */     
  354.                 };                /*===================================*/
  355. #endif
  356. #ifdef DEF_TOKEN
  357. /*---------<<  table nodes >>--------------------------------------------*/
  358.   DEF_TOKEN(TABLE    ,"Table"    ,"srsNlNRRR0N000l"  ,'T',"0T")
  359.   DEF_TOKEN(TMPTABLE ,"Tmptable" ,"srsNlt000000f000" ,'T',"0T")
  360.   DEF_TOKEN(VIEW     ,"View"     ,"srsNltR00V00000"  ,'T',"0T")
  361. /* code ANY_TBL used for table nodes, which actual type isn't known yet  */
  362. /* and can be seen after parser but before semantic pass only            */
  363.   DEF_TOKEN(ANY_TBL  ,"Any_Tbl"  ,"srsNl00000000000" ,'T',"0T")
  364. #else
  365.  #define   TBL_FNAME(node)       XLTR_TRN(node,0)
  366.  #define   TBL_NAME(node)        XLTR_TRN(node,2)
  367.  #define   TBL_COLS(node)        XVCB_TRN(node,3)
  368.  #define   TBL_NCOLS(node)       XLNG_TRN(node,4)
  369.  #define   VIEW_QUERY(node)      XVCB_TRN(node,5)
  370.  #define   TBL_CONSTR(node)      XVCB_TRN(node,5)
  371.  #define   TBL_TABID(node)       XREL_TRN(node,6)
  372.  #define   VIEW_UNID(node)       XLNG_TRN(node,6)
  373.  #define   VIEW_VCB(node)        XVCB_TRN(node,9) 
  374.  #define   VIEw_VCB(node)        XVCb_TRN(node,9) 
  375.  #define   IND_INFO(node)        XTXT_TRN(node,10)
  376.  #define   TBL_VADR(node)        XTXT_TRN(node,11)
  377.  #define   BUILD_COST(node)      XFLT_TRN(node,12)
  378.  #define   CONSTR_INFO(node)     XLNG_TRN(node,13)
  379.  #define   TBL_NNULCOL(node)     XLNG_TRN(node,14)
  380.  #define   NROWS_EST(node)       XTXT_TRN(node,15)
  381.  #define Is_Table(node)         (STRUCT(CODE_TRN(node))=='T')
  382.  #define Is_table(ptr)          (STRUCT(CODe_TRN( ptr))=='T')
  383.  #include "type.h"
  384.  struct table{                    /*============================*/
  385.           enum token code;        /* code of the node           */
  386.           MASKTYPE   flags;       /*                            */
  387.           LTRLREF    autor_name;  /* table authorization name   */
  388.           VCBREF     next;        /* next vcb entry             */
  389.           LTRLREF    name;        /* table name                 */
  390.           VCBREF     pcolumn;     /* chain of the table columns */
  391.           i4_t       column_no;   /* total number of columns in */
  392.                                   /* the table                  */
  393.           VCBREF     query;       /* query for view or          */
  394.                                   /* constraints for table      */
  395.           Tabid      tblident;    /* table identifier in DB     */
  396.           TXTREF     local_view_vcb; /*                         */
  397.           TXTREF     ind_info;    /* chain of table indexes     */
  398.                                   /* each represented by tree   */
  399.           VADR       tab_vadr;    /* is used by codegen         */
  400.                                   /* - VADR of TABID            */
  401.           float      build_cost;  /* for TMPTABLE: cost of this */
  402.                                   /* table building             */
  403.           i4_t       constr_info; /* pointer to constraints     *
  404.                                    * (is used only by codegen)  */
  405.           i4_t       nnulcolnun;  /* number of first 'NOT NULL' *
  406.                                    * columns of the table       */
  407.                                   /* the table                  */
  408.           i4_t       nrows_est;   /* is used for TMPTABLEs for  */
  409.                                   /* saving of estimated rows count */
  410.           };                /*============================*/
  411. #endif
  412. #ifdef DEF_TOKEN
  413. /*---------<<  scans nodes >>--------------------------------------------*/
  414.   DEF_TOKEN(SCAN  ,"Scan"    ,"srlVt000000v" ,'S',"0T")
  415. #else
  416.  #define   COR_NAME(node)        XLTR_TRN(node,0)
  417.  #define   COR_NEXT(node)        RIGHT_TRN(node)
  418.  #define   COR_COLUMNS(node)     XTXT_TRN(node,3)
  419.  #define   COR_TBL(node)         XVCB_TRN(node,4)
  420.  #define   COR_NO(node)          XLNG_TRN(node,2)
  421.  #define   COR_SCANID(node)      XTXT_TRN(node,5)
  422.  #define   COR_TID(node)         XTXT_TRN(node,6)
  423.  #define   COR_MASK(node)        XLNG_TRN(node,7)
  424.  #define   COR_TAB_SP(node)      XTXT_TRN(node,8)
  425.  #define   COR_IND_SP(node)      XTXT_TRN(node,9)
  426.  #define   IND_CLM_CNT(node)     XLNG_TRN(node,10)
  427.  #define   COR_VIEW(node)        XVCB_TRN(node,11)
  428.  #define Is_Scan(node)          (STRUCT(CODE_TRN(node))=='S')
  429.  struct corr_name{                /*======================================*/
  430.           enum token code;        /* code SCAN stored here                */
  431.           MASKTYPE   flags;       /*                                      */
  432.           LTRLREF    name;        /* corellation name reference           */
  433.           VCBREF     next;        /* next vcb entry (right reference)     */
  434.           i4_t       instance_no; /* table instance number                */
  435.           VCBREF     pcolumn;     /* chain of scaned columns              */
  436.           VCBREF     pvocab;      /* reference to scaned table            */
  437.           TXTREF     scan_id;     /* address of ScanId hole               */
  438.           TXTREF     table_id;    /* address of TabId hole                */
  439.           i4_t       mask;        /*                                      */
  440.           TXTREF     tab_sp;      /* list of simple predicates applied to */
  441.                                   /* scan                                 */
  442.           TXTREF     ind_sp;      /* list of simple predicates applied to */
  443.                                   /* the used index                       */  
  444.                                   /* = NULL, if no index used,            */
  445.                                   /* = 1, if some index used but there    */
  446.                                   /*      aren't any appliable SP for it  */
  447.           i4_t       ind_clm_cnt; /* number of columns in used index      */
  448.           TXTREF     see_via_view;/* scan table throuth this view         */                 
  449.                 };                /*======================================*/
  450. #endif
  451. #ifdef DEF_TOKEN
  452. /*---------<<  Cursors nodes >>------------------------------------------*/
  453.   DEF_TOKEN(CURSOR,"Cursor"   ,"sr0" ,'R',"0r")
  454. #else
  455.  #define   CUR_NAME(node)        XLTR_TRN(node,0)
  456.  #define   CUR_DECL(node)        XTXT_TRN(node,2)
  457.  #define Is_Cursor(node)         (STRUCT(CODE_TRN(node))=='R')
  458.  struct cursor_name{              /*==========================*/
  459.           enum token code;        /* code CURSOR stored here  */
  460.           MASKTYPE   flags;       /*                          */
  461.           LTRLREF    name;        /* reference to cursor name */
  462.           VCBREF     next;        /* next vcb entry           */
  463.           TXTREF     declare;     /*                          */
  464.                 };                /*==========================*/
  465. #endif
  466. #ifdef DEF_TOKEN
  467. /*---------<<  constant nodes >>-----------------------------------------*/
  468.   DEF_TOKEN(CONST    ,"Const"       ,"sryy0" ,'N',"0")
  469. #else
  470.  #define   CNST_NAME(node)       XLTR_TRN(node,0)
  471.  #define   CNST_STYPE(node)      xOp_PARM(Ptree(node),2,'y').type
  472.  #define   CNST_TTYPE(node)      xOp_PARM(Ptree(node),3,'y').type
  473.  #define Is_Constant(node)         (STRUCT(CODE_TRN(node))=='N')
  474.  struct constant {                /*==========================*/
  475.           enum token code;        /* code CONST stored here   */
  476.           MASKTYPE   flags;       /*                          */
  477.           LTRLREF    text;        /* string image of constant */
  478.           VCBREF     next;        /* next vcb entry           */
  479.           sql_type_t type_source; /* original type            */
  480.           sql_type_t type_target; /* required type            */
  481.           TXTREF     valueptr;    /* reference to internal    */
  482.                                   /* representation           */
  483.                 };                /*==========================*/
  484. #endif
  485. #ifdef DEF_TOKEN
  486. /*---------<<  parameters nodes >>---------------------------------------*/
  487.   DEF_TOKEN(PARAMETER,"Parameter" ,"sryy0t" ,'P',"0T")
  488. #else
  489.  #define   PAR_NAME(node)        XLTR_TRN(node,0)
  490.  #define   PAR_STYPE(node)       XOP_TRN(node,2).type
  491.  #define   PAR_TTYPE(node)       XOP_TRN(node,3).type
  492.  #define   PAR_ID(node)          XLNG_TRN(node,4)
  493.  #define   PAR_ADR(node)         XTXT_TRN(node,4)
  494.  #define   PAR_INDICATOR(node)  XTXT_TRN(node,5)
  495.  #define Is_Param(node)          (STRUCT(CODE_TRN(node))=='P')
  496.  struct parameter {               /*==========================*/
  497.           enum token code;        /*code PARAMETER stored here*/
  498.           MASKTYPE   flags;       /*                          */
  499.           LTRLREF    name;        /* reference to par name    */
  500.           VCBREF     next;        /* next vcb entry           */
  501.           sql_type_t type_source; /* source type              */
  502.           sql_type_t type_target; /* required type            */
  503.           i4_t       par_id;      /* unique parameter ident.  */
  504.   TXTREF     indicator;   /* reference to associated  */
  505.                                   /* indicator                */
  506.                 };                /*==========================*/
  507. #endif
  508. /**************************************************************.
  509. *****---------<<  additional nodes description >>----------*****
  510. `**************************************************************/
  511. #ifdef DEF_TOKEN
  512.   /* scan column hole before context search pass              */
  513.   /* (3 names - perhaps partially empty)                      */
  514.   DEF_TOKEN(COLUMN_HOLE,"Column_Hole" ,"sss"  ,' ',"0")
  515. #else
  516.   #define CHOLE_AUTHOR(n)      XLTR_TRN(n,0)
  517.   #define CHOLE_TNAME(n)       XLTR_TRN(n,1)
  518.   #define CHOLE_CNAME(n)       XLTR_TRN(n,2)
  519. #endif
  520. #ifdef DEF_TOKEN
  521.   #undef DEF_TOKEN
  522. #endif