# 2.11BSD#431 - /usr/src/ucb/pascal/pxp/tree.c

##### Functions

    copystr           X
    inittree          X
    tralloc           X
    tree              X
    trfree            X

##### Variables

    space             X
    spacep            X
    tract             X
    trspace           X
    ttab              X

##### Macros

    TREENMAX          X

##### struct's

    tr                X

       1: #
       2: /*
       3:  * pi - Pascal interpreter code translator
       4:  *
       5:  * Charles Haley, Bill Joy UCB
       6:  * Version 1.2 January 1979
       7:  *
       8:  *
       9:  * pxp - Pascal execution profiler
      10:  *
      11:  * Bill Joy UCB
      12:  * Version 1.2 January 1979
      13:  */
      14:
      15: #include "0.h"
      16:
      17: /*
      18:  * TREE SPACE DECLARATIONS
      19:  */
      20: struct tr {
      21:     int *tr_low;
      22:     int *tr_high;
      23: } ttab[MAXTREE], *tract;
      24:
      25: /*
      26:  * The variable space is the
      27:  * absolute base of the tree segments.
      28:  * (exactly the same as ttab[0].tr_low)
      29:  * Spacep is maintained to point at the
      30:  * beginning of the next tree slot to
      31:  * be allocated for use by the grammar.
      32:  * Spacep is used "extern" by the semantic
      33:  * actions in pas.y.
      34:  * The variable tract is maintained to point
      35:  * at the tree segment out of which we are
      36:  * allocating (the active segment).
      37:  */
      38: int *space, *spacep;
      39:
      40: /*
      41:  * TREENMAX is the maximum width
      42:  * in words that any tree node
      43:  * due to the way in which the parser uses
      44:  * the pointer spacep.
      45:  */
      46: #define TREENMAX    6
      47:
      48: int trspace[ITREE];
      49: int *space  = trspace;
      50: int *spacep = trspace;
      51: struct  tr *tract   = ttab;
      52:
      53: /*
      54:  * Inittree allocates the first tree slot
      55:  * and sets up the first segment descriptor.
      56:  * A lot of this work is actually done statically
      57:  * above.
      58:  */
      59: inittree()
      60: {
      61:
      62:     ttab[0].tr_low = space;
      63:     ttab[0].tr_high = &space[ITREE];
      64: }
      65:
      66: /*
      67:  * Tree builds the nodes in the
      68:  * parse tree. It is rarely called
      69:  * directly, rather calls are made
      70:  * to tree[12345] which supplies the
      71:  * first argument to save space in
      72:  * the code. Tree also guarantees
      73:  * that spacep points to the beginning
      74:  * of the next slot it will return,
      75:  * a property required by the parser
      76:  * which was always true before we
      77:  * segmented the tree space.
      78:  */
      79: int *tree(cnt, a)
      80:     int cnt;
      81: {
      82:     register int *p, *q;
      83:     register int i;
      84:
      85:     i = cnt;
      86:     p = spacep;
      87:     q = &a;
      88:     do
      89:         *p++ = *q++;
      90:     while (--i);
      91:     q = spacep;
      92:     spacep = p;
      93:     if (p+TREENMAX >= tract->tr_high)
      94:         /*
      95: 		 * this peek-ahead should
      96: 		 * save a great number of calls
      97: 		 * to tralloc.
      98: 		 */
      99:         tralloc(TREENMAX);
     100:     return (q);
     101: }
     102:
     103: /*
     104:  * Tralloc preallocates enough
     105:  * space in the tree to allow
     106:  * the grammar to use the variable
     107:  * spacep, as it did before the
     108:  * tree was segmented.
     109:  */
     110: tralloc(howmuch)
     111: {
     112:     register char *cp;
     113:     register i;
     114:
     115:     if (spacep + howmuch >= tract->tr_high) {
     116:         i = TRINC;
     117:         cp = alloc(i*2);
     118:         if (cp == -1) {
     119:             yerror("Ran out of memory (tralloc)");
     120:             pexit(DIED);
     121:         }
     122:         spacep = cp;
     123:         tract++;
     124:         if (tract >= &ttab[MAXTREE]) {
     125:             yerror("Ran out of tree tables");
     126:             pexit(DIED);
     127:         }
     128:         tract->tr_low = cp;
     129:         tract->tr_high = tract->tr_low+i;
     130:     }
     131: }
     132:
     133: extern  int yylacnt;
     134: extern  bottled;
     135: #ifdef PXP
     136: #endif
     137: /*
     138:  * Free up the tree segments
     139:  * at the end of a block.
     140:  * If there is scanner lookahead,
     141:  * i.e. if yylacnt != 0 or there is bottled output, then we
     142:  * cannot free the tree space.
     143:  * This happens only when errors
     144:  * occur and the forward move extends
     145:  * across "units".
     146:  */
     147: trfree()
     148: {
     149:
     150:     if (yylacnt != 0 || bottled != NIL)
     151:         return;
     152: #ifdef PXP
     153:     if (needtree())
     154:         return;
     155: #endif
     156:     spacep = space;
     157:     while (tract->tr_low > spacep || tract->tr_high <= spacep) {
     158:         free(tract->tr_low);
     159:         tract->tr_low = NIL;
     160:         tract->tr_high = NIL;
     161:         tract--;
     162:         if (tract < ttab)
     163:             panic("ttab");
     164:     }
     165: #ifdef PXP
     166:     packtree();
     167: #endif
     168: }
     169:
     170: /*
     171:  * Copystr copies a token from
     172:  * the "token" buffer into the
     173:  * tree space.
     174:  */
     175: copystr(token)
     176:     register char *token;
     177: {
     178:     register char *cp;
     179:     register int i;
     180:
     181:     i = (strlen(token) + 2) & ~1;
     182:     tralloc(i >> 1);
     183:     strcpy(spacep, token);
     184:     cp = spacep;
     185:     spacep = cp + i;
     186:     tralloc(TREENMAX);
     187:     return (cp);
     188: }

#### Defined functions

copystr defined in line 175; used 5 times

- in /usr/src/ucb/pascal/pxp/yycomm.c line 227
- in /usr/src/ucb/pascal/pxp/yylex.c line 130, 138, 176, 212

inittree defined in line 59; used 1 times

- in /usr/src/ucb/pascal/pxp/yymain.c line 56

tralloc defined in line 110; used 3 times

- in line 99, 182-186(2)

tree defined in line 79; used 5 times

- in /usr/src/ucb/pascal/pxp/0.h line 219
- in /usr/src/ucb/pascal/pxp/treen.s line 5, 28
- in /usr/src/ucb/pascal/pxp/yycomm.c line 54
- in /usr/src/ucb/pascal/pxp/yyput.c line 56

trfree defined in line 147; used 4 times

- in /usr/src/ucb/pascal/pxp/pas.y line 158-168(3), 274

#### Defined variables

space defined in line 49; used 3 times

- in line 62-63(2), 156

spacep defined in line 50; used 13 times

- in line 86-92(3), 115, 122, 156-157(3), 183-185(3)
- in /usr/src/ucb/pascal/pxp/yytree.c line 60, 77

tract defined in line 51; used 14 times

- in line 93, 115, 123-129(5), 157-162(7)

trspace defined in line 48; used 2 times

- in line 49-50(2)

ttab defined in line 23; used 5 times

- in line 51, 62-63(2), 124, 162

#### Defined struct's

tr defined in line 20; used 2 times

- in line 51(2)

#### Defined macros

TREENMAX defined in line 46; used 3 times

- in line 93, 99, 186

Last modified: 1986-06-01 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 707 |