]>
git.saurik.com Git - bison.git/blob - src/symlist.c
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 Bison 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 2, or (at your option)
12 Bison 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 Bison; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
29 /*--------------------------------------.
30 | Create a list containing SYM at LOC. |
31 `--------------------------------------*/
34 symbol_list_sym_new (symbol
*sym
, location loc
)
36 symbol_list
*res
= xmalloc (sizeof *res
);
38 res
->content_type
= SYMLIST_SYMBOL
;
39 res
->content
.sym
= sym
;
43 res
->midrule_parent_rule
= NULL
;
44 res
->midrule_parent_rhs_index
= 0;
46 code_props_none_init (&res
->action_props
);
58 /*--------------------------------------------.
59 | Create a list containing TYPE_NAME at LOC. |
60 `--------------------------------------------*/
63 symbol_list_type_new (uniqstr type_name
, location loc
)
65 symbol_list
*res
= xmalloc (sizeof *res
);
67 res
->content_type
= SYMLIST_TYPE
;
68 res
->content
.type_name
= type_name
;
76 /*----------------------------------------.
77 | Create a list containing a <*> at LOC. |
78 `----------------------------------------*/
81 symbol_list_default_tagged_new (location loc
)
83 symbol_list
*res
= xmalloc (sizeof *res
);
85 res
->content_type
= SYMLIST_DEFAULT_TAGGED
;
93 /*---------------------------------------.
94 | Create a list containing a <> at LOC. |
95 `---------------------------------------*/
98 symbol_list_default_tagless_new (location loc
)
100 symbol_list
*res
= xmalloc (sizeof *res
);
102 res
->content_type
= SYMLIST_DEFAULT_TAGLESS
;
110 /*-----------------------------------------------------------------------.
111 | Print this list, for which every content_type must be SYMLIST_SYMBOL. |
112 `-----------------------------------------------------------------------*/
115 symbol_list_syms_print (const symbol_list
*l
, FILE *f
)
117 for (/* Nothing. */; l
&& l
->content
.sym
; l
= l
->next
)
119 symbol_print (l
->content
.sym
, f
);
120 fprintf (stderr
, l
->action_props
.is_value_used
? " used" : " unused");
121 if (l
&& l
->content
.sym
)
127 /*---------------------------.
128 | Prepend NODE to the LIST. |
129 `---------------------------*/
132 symbol_list_prepend (symbol_list
*list
, symbol_list
*node
)
139 /*-----------------------------------------------.
140 | Free the LIST, but not the items it contains. |
141 `-----------------------------------------------*/
144 symbol_list_free (symbol_list
*list
)
146 LIST_FREE (symbol_list
, list
);
150 /*--------------------.
151 | Return its length. |
152 `--------------------*/
155 symbol_list_length (symbol_list
const *l
)
159 l
&& !(l
->content_type
== SYMLIST_SYMBOL
&& l
->content
.sym
== NULL
);
166 /*------------------------------.
167 | Get item N in symbol list L. |
168 `------------------------------*/
171 symbol_list_n_get (symbol_list
*l
, int n
)
178 for (i
= 0; i
< n
; ++i
)
182 || (l
->content_type
== SYMLIST_SYMBOL
&& l
->content
.sym
== NULL
))
190 /*--------------------------------------------------------------.
191 | Get the data type (alternative in the union) of the value for |
192 | symbol N in symbol list L. |
193 `--------------------------------------------------------------*/
196 symbol_list_n_type_name_get (symbol_list
*l
, location loc
, int n
)
198 l
= symbol_list_n_get (l
, n
);
201 complain_at (loc
, _("invalid $ value: $%d"), n
);
204 aver (l
->content_type
== SYMLIST_SYMBOL
);
205 return l
->content
.sym
->type_name
;
210 symbol_list_destructor_set (symbol_list
*node
, char const *code
, location loc
)
212 code_props destructor
;
213 code_props_symbol_action_init (&destructor
, code
, loc
);
214 code_props_translate_code (&destructor
);
215 switch (node
->content_type
)
218 symbol_destructor_set (node
->content
.sym
, &destructor
);
221 semantic_type_destructor_set (
222 semantic_type_get (node
->content
.type_name
), &destructor
);
224 case SYMLIST_DEFAULT_TAGGED
:
225 default_tagged_destructor_set (&destructor
);
227 case SYMLIST_DEFAULT_TAGLESS
:
228 default_tagless_destructor_set (&destructor
);
234 symbol_list_printer_set (symbol_list
*node
, char const *code
, location loc
)
237 code_props_symbol_action_init (&printer
, code
, loc
);
238 code_props_translate_code (&printer
);
239 switch (node
->content_type
)
242 symbol_printer_set (node
->content
.sym
, &printer
);
245 semantic_type_printer_set (
246 semantic_type_get (node
->content
.type_name
), &printer
);
248 case SYMLIST_DEFAULT_TAGGED
:
249 default_tagged_printer_set (&printer
);
251 case SYMLIST_DEFAULT_TAGLESS
:
252 default_tagless_printer_set (&printer
);