1 /* Lists of symbols for Bison
3 Copyright (C) 2002, 2005, 2006, 2007 Free Software Foundation, Inc.
5 This file is part of Bison, the GNU Compiler Compiler.
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /*--------------------------------------.
28 | Create a list containing SYM at LOC. |
29 `--------------------------------------*/
32 symbol_list_sym_new (symbol
*sym
, location loc
)
34 symbol_list
*res
= xmalloc (sizeof *res
);
36 res
->content_type
= SYMLIST_SYMBOL
;
37 res
->content
.sym
= sym
;
41 res
->midrule_parent_rule
= NULL
;
42 res
->midrule_parent_rhs_index
= 0;
44 code_props_none_init (&res
->action_props
);
56 /*--------------------------------------------.
57 | Create a list containing TYPE_NAME at LOC. |
58 `--------------------------------------------*/
61 symbol_list_type_new (uniqstr type_name
, location loc
)
63 symbol_list
*res
= xmalloc (sizeof *res
);
65 res
->content_type
= SYMLIST_TYPE
;
66 res
->content
.type_name
= type_name
;
74 /*----------------------------------------.
75 | Create a list containing a <*> at LOC. |
76 `----------------------------------------*/
79 symbol_list_default_tagged_new (location loc
)
81 symbol_list
*res
= xmalloc (sizeof *res
);
83 res
->content_type
= SYMLIST_DEFAULT_TAGGED
;
91 /*---------------------------------------.
92 | Create a list containing a <> at LOC. |
93 `---------------------------------------*/
96 symbol_list_default_tagless_new (location loc
)
98 symbol_list
*res
= xmalloc (sizeof *res
);
100 res
->content_type
= SYMLIST_DEFAULT_TAGLESS
;
108 /*-----------------------------------------------------------------------.
109 | Print this list, for which every content_type must be SYMLIST_SYMBOL. |
110 `-----------------------------------------------------------------------*/
113 symbol_list_syms_print (const symbol_list
*l
, FILE *f
)
115 for (/* Nothing. */; l
&& l
->content
.sym
; l
= l
->next
)
117 symbol_print (l
->content
.sym
, f
);
118 fprintf (stderr
, l
->action_props
.is_value_used
? " used" : " unused");
119 if (l
&& l
->content
.sym
)
125 /*---------------------------.
126 | Prepend NODE to the LIST. |
127 `---------------------------*/
130 symbol_list_prepend (symbol_list
*list
, symbol_list
*node
)
137 /*-----------------------------------------------.
138 | Free the LIST, but not the items it contains. |
139 `-----------------------------------------------*/
142 symbol_list_free (symbol_list
*list
)
144 LIST_FREE (symbol_list
, list
);
148 /*--------------------.
149 | Return its length. |
150 `--------------------*/
153 symbol_list_length (symbol_list
const *l
)
157 l
&& !(l
->content_type
== SYMLIST_SYMBOL
&& l
->content
.sym
== NULL
);
164 /*------------------------------.
165 | Get item N in symbol list L. |
166 `------------------------------*/
169 symbol_list_n_get (symbol_list
*l
, int n
)
176 for (i
= 0; i
< n
; ++i
)
180 || (l
->content_type
== SYMLIST_SYMBOL
&& l
->content
.sym
== NULL
))
188 /*--------------------------------------------------------------.
189 | Get the data type (alternative in the union) of the value for |
190 | symbol N in symbol list L. |
191 `--------------------------------------------------------------*/
194 symbol_list_n_type_name_get (symbol_list
*l
, location loc
, int n
)
196 l
= symbol_list_n_get (l
, n
);
199 complain_at (loc
, _("invalid $ value: $%d"), n
);
202 aver (l
->content_type
== SYMLIST_SYMBOL
);
203 return l
->content
.sym
->type_name
;
208 symbol_list_destructor_set (symbol_list
*node
, char const *code
, location loc
)
210 code_props destructor
;
211 code_props_symbol_action_init (&destructor
, code
, loc
);
212 code_props_translate_code (&destructor
);
213 switch (node
->content_type
)
216 symbol_destructor_set (node
->content
.sym
, &destructor
);
219 semantic_type_destructor_set (
220 semantic_type_get (node
->content
.type_name
), &destructor
);
222 case SYMLIST_DEFAULT_TAGGED
:
223 default_tagged_destructor_set (&destructor
);
225 case SYMLIST_DEFAULT_TAGLESS
:
226 default_tagless_destructor_set (&destructor
);
232 symbol_list_printer_set (symbol_list
*node
, char const *code
, location loc
)
235 code_props_symbol_action_init (&printer
, code
, loc
);
236 code_props_translate_code (&printer
);
237 switch (node
->content_type
)
240 symbol_printer_set (node
->content
.sym
, &printer
);
243 semantic_type_printer_set (
244 semantic_type_get (node
->content
.type_name
), &printer
);
246 case SYMLIST_DEFAULT_TAGGED
:
247 default_tagged_printer_set (&printer
);
249 case SYMLIST_DEFAULT_TAGLESS
:
250 default_tagless_printer_set (&printer
);