1 /* Lists of symbols for Bison
3 Copyright (C) 2002, 2005-2007, 2009-2012 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/>. */
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
;
38 res
->location
= res
->sym_loc
= loc
;
41 res
->midrule_parent_rule
= NULL
;
42 res
->midrule_parent_rhs_index
= 0;
44 code_props_none_init (&res
->action_props
);
50 res
->named_ref
= NULL
;
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
.sem_type
= xmalloc (sizeof (semantic_type
));
69 res
->content
.sem_type
->tag
= type_name
;
70 res
->content
.sem_type
->location
= loc
;
71 res
->content
.sem_type
->status
= undeclared
;
73 res
->location
= res
->sym_loc
= loc
;
74 res
->named_ref
= NULL
;
81 /*----------------------------------------.
82 | Create a list containing a <*> at LOC. |
83 `----------------------------------------*/
86 symbol_list_default_tagged_new (location loc
)
88 symbol_list
*res
= xmalloc (sizeof *res
);
90 res
->content_type
= SYMLIST_DEFAULT_TAGGED
;
91 res
->location
= res
->sym_loc
= loc
;
92 res
->named_ref
= NULL
;
99 /*---------------------------------------.
100 | Create a list containing a <> at LOC. |
101 `---------------------------------------*/
104 symbol_list_default_tagless_new (location loc
)
106 symbol_list
*res
= xmalloc (sizeof *res
);
108 res
->content_type
= SYMLIST_DEFAULT_TAGLESS
;
109 res
->location
= res
->sym_loc
= loc
;
110 res
->named_ref
= NULL
;
117 /*-----------------------------------------------------------------------.
118 | Print this list, for which every content_type must be SYMLIST_SYMBOL. |
119 `-----------------------------------------------------------------------*/
122 symbol_list_syms_print (const symbol_list
*l
, FILE *f
)
124 for (/* Nothing. */; l
&& l
->content
.sym
; l
= l
->next
)
126 symbol_print (l
->content
.sym
, f
);
127 fprintf (stderr
, l
->action_props
.is_value_used
? " used" : " unused");
128 if (l
&& l
->content
.sym
)
134 /*---------------------------.
135 | Prepend NODE to the LIST. |
136 `---------------------------*/
139 symbol_list_prepend (symbol_list
*list
, symbol_list
*node
)
146 /*-----------------------------------------------.
147 | Free the LIST, but not the items it contains. |
148 `-----------------------------------------------*/
151 symbol_list_free (symbol_list
*list
)
153 symbol_list
*node
, *next
;
154 for (node
= list
; node
; node
= next
)
157 named_ref_free (node
->named_ref
);
163 /*--------------------.
164 | Return its length. |
165 `--------------------*/
168 symbol_list_length (symbol_list
const *l
)
172 l
&& !(l
->content_type
== SYMLIST_SYMBOL
&& l
->content
.sym
== NULL
);
179 /*------------------------------.
180 | Get item N in symbol list L. |
181 `------------------------------*/
184 symbol_list_n_get (symbol_list
*l
, int n
)
191 for (i
= 0; i
< n
; ++i
)
195 || (l
->content_type
== SYMLIST_SYMBOL
&& l
->content
.sym
== NULL
))
203 /*--------------------------------------------------------------.
204 | Get the data type (alternative in the union) of the value for |
205 | symbol N in symbol list L. |
206 `--------------------------------------------------------------*/
209 symbol_list_n_type_name_get (symbol_list
*l
, location loc
, int n
)
211 l
= symbol_list_n_get (l
, n
);
214 complain_at (loc
, complaint
, _("invalid $ value: $%d"), n
);
217 aver (l
->content_type
== SYMLIST_SYMBOL
);
218 return l
->content
.sym
->type_name
;
222 symbol_list_null (symbol_list
*node
)
225 (node
->content_type
== SYMLIST_SYMBOL
&& !(node
->content
.sym
));
229 symbol_list_code_props_set (symbol_list
*node
, code_props_type kind
,
230 location loc
, char const *code
)
233 code_props_symbol_action_init (&cprops
, code
, loc
);
234 code_props_translate_code (&cprops
);
235 switch (node
->content_type
)
238 symbol_code_props_set (node
->content
.sym
, kind
, &cprops
);
239 if (node
->content
.sym
->status
== undeclared
)
240 node
->content
.sym
->status
= used
;
243 semantic_type_code_props_set
244 (semantic_type_get (node
->content
.sem_type
->tag
,
245 &node
->content
.sem_type
->location
),
247 if (node
->content
.sem_type
->status
== undeclared
)
248 node
->content
.sem_type
->status
= used
;
250 case SYMLIST_DEFAULT_TAGGED
:
251 default_tagged_code_props_set (kind
, &cprops
);
253 case SYMLIST_DEFAULT_TAGLESS
:
254 default_tagless_code_props_set (kind
, &cprops
);