]>
git.saurik.com Git - bison.git/blob - src/symlist.c
1 /* Lists of symbols for Bison
3 Copyright (C) 2002, 2005-2007, 2009-2010 Free Software Foundation,
6 This file is part of Bison, the GNU Compiler Compiler.
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
28 /*--------------------------------------.
29 | Create a list containing SYM at LOC. |
30 `--------------------------------------*/
33 symbol_list_sym_new (symbol
*sym
, location loc
)
35 symbol_list
*res
= xmalloc (sizeof *res
);
37 res
->content_type
= SYMLIST_SYMBOL
;
38 res
->content
.sym
= sym
;
42 res
->midrule_parent_rule
= NULL
;
43 res
->midrule_parent_rhs_index
= 0;
45 code_props_none_init (&res
->action_props
);
57 /*--------------------------------------------.
58 | Create a list containing TYPE_NAME at LOC. |
59 `--------------------------------------------*/
62 symbol_list_type_new (uniqstr type_name
, location loc
)
64 symbol_list
*res
= xmalloc (sizeof *res
);
66 res
->content_type
= SYMLIST_TYPE
;
67 res
->content
.type_name
= type_name
;
75 /*----------------------------------------.
76 | Create a list containing a <*> at LOC. |
77 `----------------------------------------*/
80 symbol_list_default_tagged_new (location loc
)
82 symbol_list
*res
= xmalloc (sizeof *res
);
84 res
->content_type
= SYMLIST_DEFAULT_TAGGED
;
92 /*---------------------------------------.
93 | Create a list containing a <> at LOC. |
94 `---------------------------------------*/
97 symbol_list_default_tagless_new (location loc
)
99 symbol_list
*res
= xmalloc (sizeof *res
);
101 res
->content_type
= SYMLIST_DEFAULT_TAGLESS
;
109 /*-----------------------------------------------------------------------.
110 | Print this list, for which every content_type must be SYMLIST_SYMBOL. |
111 `-----------------------------------------------------------------------*/
114 symbol_list_syms_print (const symbol_list
*l
, FILE *f
)
116 for (/* Nothing. */; l
&& l
->content
.sym
; l
= l
->next
)
118 symbol_print (l
->content
.sym
, f
);
119 fprintf (stderr
, l
->action_props
.is_value_used
? " used" : " unused");
120 if (l
&& l
->content
.sym
)
126 /*---------------------------.
127 | Prepend NODE to the LIST. |
128 `---------------------------*/
131 symbol_list_prepend (symbol_list
*list
, symbol_list
*node
)
138 /*-----------------------------------------------.
139 | Free the LIST, but not the items it contains. |
140 `-----------------------------------------------*/
143 symbol_list_free (symbol_list
*list
)
145 LIST_FREE (symbol_list
, list
);
149 /*--------------------.
150 | Return its length. |
151 `--------------------*/
154 symbol_list_length (symbol_list
const *l
)
158 l
&& !(l
->content_type
== SYMLIST_SYMBOL
&& l
->content
.sym
== NULL
);
165 /*------------------------------.
166 | Get item N in symbol list L. |
167 `------------------------------*/
170 symbol_list_n_get (symbol_list
*l
, int n
)
177 for (i
= 0; i
< n
; ++i
)
181 || (l
->content_type
== SYMLIST_SYMBOL
&& l
->content
.sym
== NULL
))
189 /*--------------------------------------------------------------.
190 | Get the data type (alternative in the union) of the value for |
191 | symbol N in symbol list L. |
192 `--------------------------------------------------------------*/
195 symbol_list_n_type_name_get (symbol_list
*l
, location loc
, int n
)
197 l
= symbol_list_n_get (l
, n
);
200 complain_at (loc
, _("invalid $ value: $%d"), n
);
203 aver (l
->content_type
== SYMLIST_SYMBOL
);
204 return l
->content
.sym
->type_name
;
209 symbol_list_destructor_set (symbol_list
*node
, char const *code
, location loc
)
211 code_props destructor
;
212 code_props_symbol_action_init (&destructor
, code
, loc
);
213 code_props_translate_code (&destructor
);
214 switch (node
->content_type
)
217 symbol_destructor_set (node
->content
.sym
, &destructor
);
220 semantic_type_destructor_set (
221 semantic_type_get (node
->content
.type_name
), &destructor
);
223 case SYMLIST_DEFAULT_TAGGED
:
224 default_tagged_destructor_set (&destructor
);
226 case SYMLIST_DEFAULT_TAGLESS
:
227 default_tagless_destructor_set (&destructor
);
233 symbol_list_printer_set (symbol_list
*node
, char const *code
, location loc
)
236 code_props_symbol_action_init (&printer
, code
, loc
);
237 code_props_translate_code (&printer
);
238 switch (node
->content_type
)
241 symbol_printer_set (node
->content
.sym
, &printer
);
244 semantic_type_printer_set (
245 semantic_type_get (node
->content
.type_name
), &printer
);
247 case SYMLIST_DEFAULT_TAGGED
:
248 default_tagged_printer_set (&printer
);
250 case SYMLIST_DEFAULT_TAGLESS
:
251 default_tagless_printer_set (&printer
);