1 /* Lists of symbols for Bison
3 Copyright (C) 2002, 2005-2007, 2009-2015 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/>. */
26 /*--------------------------------------.
27 | Create a list containing SYM at LOC. |
28 `--------------------------------------*/
31 symbol_list_sym_new (symbol
*sym
, location loc
)
33 symbol_list
*res
= xmalloc (sizeof *res
);
35 res
->content_type
= SYMLIST_SYMBOL
;
36 res
->content
.sym
= sym
;
37 res
->location
= res
->sym_loc
= loc
;
38 res
->named_ref
= NULL
;
41 res
->midrule_parent_rule
= NULL
;
42 res
->midrule_parent_rhs_index
= 0;
44 /* Members used for LHS only. */
46 res
->percent_empty_loc
= empty_location
;
47 code_props_none_init (&res
->action_props
);
49 res
->dprec_location
= empty_location
;
51 res
->merger_declaration_location
= empty_location
;
59 /*--------------------------------------------.
60 | Create a list containing TYPE_NAME at LOC. |
61 `--------------------------------------------*/
64 symbol_list_type_new (uniqstr type_name
, location loc
)
66 symbol_list
*res
= xmalloc (sizeof *res
);
68 res
->content_type
= SYMLIST_TYPE
;
69 res
->content
.sem_type
= xmalloc (sizeof (semantic_type
));
70 res
->content
.sem_type
->tag
= type_name
;
71 res
->content
.sem_type
->location
= loc
;
72 res
->content
.sem_type
->status
= undeclared
;
74 res
->location
= res
->sym_loc
= loc
;
75 res
->named_ref
= NULL
;
82 /*-----------------------------------------------------------------------.
83 | Print this list, for which every content_type must be SYMLIST_SYMBOL. |
84 `-----------------------------------------------------------------------*/
87 symbol_list_syms_print (const symbol_list
*l
, FILE *f
)
90 for (/* Nothing. */; l
&& l
->content
.sym
; l
= l
->next
)
93 fputs (l
->content_type
== SYMLIST_SYMBOL
? "symbol: "
94 : l
->content_type
== SYMLIST_TYPE
? "type: "
95 : "invalid content_type: ",
97 symbol_print (l
->content
.sym
, f
);
98 fputs (l
->action_props
.is_value_used
? " used" : " unused", f
);
104 /*---------------------------.
105 | Prepend NODE to the LIST. |
106 `---------------------------*/
109 symbol_list_prepend (symbol_list
*list
, symbol_list
*node
)
116 /*-------------------------.
117 | Append NODE to the LIST. |
118 `-------------------------*/
121 symbol_list_append (symbol_list
*list
, symbol_list
*node
)
125 symbol_list
*next
= list
;
133 /*-----------------------------------------------.
134 | Free the LIST, but not the items it contains. |
135 `-----------------------------------------------*/
138 symbol_list_free (symbol_list
*list
)
140 symbol_list
*node
, *next
;
141 for (node
= list
; node
; node
= next
)
144 named_ref_free (node
->named_ref
);
145 if (node
->content_type
== SYMLIST_TYPE
)
146 free (node
->content
.sem_type
);
152 /*--------------------.
153 | Return its length. |
154 `--------------------*/
157 symbol_list_length (symbol_list
const *l
)
161 l
&& !(l
->content_type
== SYMLIST_SYMBOL
&& l
->content
.sym
== NULL
);
168 /*------------------------------.
169 | Get item N in symbol list L. |
170 `------------------------------*/
173 symbol_list_n_get (symbol_list
*l
, int n
)
177 for (i
= 0; i
< n
; ++i
)
182 aver (l
->content_type
== SYMLIST_SYMBOL
);
183 aver (l
->content
.sym
);
187 /*--------------------------------------------------------------.
188 | Get the data type (alternative in the union) of the value for |
189 | symbol N in symbol list L. |
190 `--------------------------------------------------------------*/
193 symbol_list_n_type_name_get (symbol_list
*l
, int n
)
195 return symbol_list_n_get (l
, n
)->content
.sym
->type_name
;
199 symbol_list_null (symbol_list
*node
)
202 || (node
->content_type
== SYMLIST_SYMBOL
&& !node
->content
.sym
));
206 symbol_list_code_props_set (symbol_list
*node
, code_props_type kind
,
207 code_props
const *cprops
)
209 switch (node
->content_type
)
212 symbol_code_props_set (node
->content
.sym
, kind
, cprops
);
213 if (node
->content
.sym
->status
== undeclared
)
214 node
->content
.sym
->status
= used
;
217 semantic_type_code_props_set
218 (semantic_type_get (node
->content
.sem_type
->tag
,
219 &node
->content
.sem_type
->location
),
221 if (node
->content
.sem_type
->status
== undeclared
)
222 node
->content
.sem_type
->status
= used
;