/[bison]/bison/src/state.c
ViewVC logotype

Diff of /bison/src/state.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.17 by akim, Tue Jul 2 13:51:27 2002 UTC revision 1.18 by akim, Wed Jul 3 06:51:43 2002 UTC
# Line 74  transitions_to (transitions_t *shifts, s Line 74  transitions_to (transitions_t *shifts, s
74  | Create a new array of N errs.  |  | Create a new array of N errs.  |
75  `-------------------------------*/  `-------------------------------*/
76    
77  #define ERRS_ALLOC(Nerrs)                                               \  #define ERRS_ALLOC(Nerrs)                               \
78    (errs_t *) xcalloc ((unsigned) (sizeof (errs_t)                       \    (errs_t *) xcalloc ((sizeof (errs_t)                  \
79                                    + (Nerrs - 1) * sizeof (symbol_number_t)), 1)                        + (Nerrs - 1) * sizeof (symbol_number_t)), 1)
80    
81    
82  errs_t *  errs_t *
83  errs_new (int n)  errs_new (int num, symbol_number_t *tokens)
84  {  {
85    errs_t *res = ERRS_ALLOC (n);    errs_t *res = ERRS_ALLOC (num);
86    res->num = n;    res->num = num;
87    return res;    memcpy (res->symbols, tokens, num * sizeof (tokens[0]));
 }  
   
   
 errs_t *  
 errs_dup (errs_t *src)  
 {  
   errs_t *res = errs_new (src->num);  
   memcpy (res->symbols, src->symbols, src->num * sizeof (src->symbols[0]));  
88    return res;    return res;
89  }  }
90    
# Line 108  errs_dup (errs_t *src) Line 100  errs_dup (errs_t *src)
100  | Create a new array of N reductions.  |  | Create a new array of N reductions.  |
101  `-------------------------------------*/  `-------------------------------------*/
102    
103  #define REDUCTIONS_ALLOC(Nreductions)                                   \  #define REDUCTIONS_ALLOC(Nreductions)                           \
104    (reductions_t *) xcalloc ((unsigned) (sizeof (reductions_t)           \    (reductions_t *) xcalloc ((sizeof (reductions_t)              \
105                                    + (Nreductions - 1) * sizeof (rule_number_t)), 1)                              + (Nreductions - 1) * sizeof (rule_number_t)), 1)
106    
107  static reductions_t *  static reductions_t *
108  reductions_new (int nreductions, short *reductions)  reductions_new (int num, rule_number_t *reductions)
109  {  {
110    reductions_t *res = REDUCTIONS_ALLOC (nreductions);    reductions_t *res = REDUCTIONS_ALLOC (num);
111    res->num = nreductions;    res->num = num;
112    memcpy (res->rules, reductions, nreductions * sizeof (reductions[0]));    memcpy (res->rules, reductions, num * sizeof (reductions[0]));
113    return res;    return res;
114  }  }
115    
# Line 137  state_t *final_state = NULL; Line 129  state_t *final_state = NULL;
129    (state_t *) xcalloc ((unsigned) (sizeof (state_t)                     \    (state_t *) xcalloc ((unsigned) (sizeof (state_t)                     \
130                                    + (Nitems - 1) * sizeof (item_number_t)), 1)                                    + (Nitems - 1) * sizeof (item_number_t)), 1)
131    
132  /*------------------------------------------------------------.  /*------------------------------------------------------------------.
133  | Create a new state with ACCESSING_SYMBOL, for those items.  |  | Create a new state with ACCESSING_SYMBOL, for those items.  Store |
134  `------------------------------------------------------------*/  | it in the state hash table.                                       |
135    `------------------------------------------------------------------*/
136    
137  state_t *  state_t *
138  state_new (symbol_number_t accessing_symbol,  state_new (symbol_number_t accessing_symbol,
# Line 159  state_new (symbol_number_t accessing_sym Line 152  state_new (symbol_number_t accessing_sym
152    res->nitems = core_size;    res->nitems = core_size;
153    memcpy (res->items, core, core_size * sizeof (core[0]));    memcpy (res->items, core, core_size * sizeof (core[0]));
154    
155      state_hash_insert (res);
156    
157    return res;    return res;
158  }  }
159    
160    
161  /*--------------------------.  /*-------------.
162  | Set the shifts of STATE.  |  | Free STATE.  |
163  `--------------------------*/  `-------------*/
164    
165    static void
166    state_free (state_t *state)
167    {
168      free (state->transitions);
169      free (state->reductions);
170      free (state->errs);
171      free (state);
172    }
173    
174    
175    /*-------------------------------.
176    | Set the transitions of STATE.  |
177    `-------------------------------*/
178    
179  void  void
180  state_transitions_set (state_t *state, int nshifts, state_number_t *shifts)  state_transitions_set (state_t *state, int num, state_number_t *transitions)
181  {  {
182    state->shifts = transitions_new (nshifts, shifts);    assert (!state->transitions);
183      state->transitions = transitions_new (num, transitions);
184  }  }
185    
186    
# Line 179  state_transitions_set (state_t *state, i Line 189  state_transitions_set (state_t *state, i
189  `------------------------------*/  `------------------------------*/
190    
191  void  void
192  state_reductions_set (state_t *state, int nreductions, short *reductions)  state_reductions_set (state_t *state, int num, rule_number_t *reductions)
193  {  {
194    state->reductions = reductions_new (nreductions, reductions);    assert (!state->reductions);
195      state->reductions = reductions_new (num, reductions);
196    }
197    
198    
199    /*------------------------.
200    | Set the errs of STATE.  |
201    `------------------------*/
202    
203    void
204    state_errs_set (state_t *state, int num, symbol_number_t *tokens)
205    {
206      assert (!state->errs);
207      state->errs = errs_new (num, tokens);
208  }  }
209    
210    
# Line 322  void Line 345  void
345  states_free (void)  states_free (void)
346  {  {
347    state_number_t i;    state_number_t i;
   
348    for (i = 0; i < nstates; ++i)    for (i = 0; i < nstates; ++i)
349      {      state_free (states[i]);
350        free (states[i]->shifts);    free (states);
       XFREE (states[i]->reductions);  
       free (states[i]->errs);  
       free (states[i]);  
     }  
   XFREE (states);  
351  }  }

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.18

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26