]> git.saurik.com Git - bison.git/blame - src/symlist.c
Whether the default %destructor/%printer applies to a particular symbol
[bison.git] / src / symlist.c
CommitLineData
56c47203 1/* Lists of symbols for Bison
17ee7397 2
84866159 3 Copyright (C) 2002, 2005, 2006 Free Software Foundation, Inc.
56c47203
AD
4
5 This file is part of Bison, the GNU Compiler Compiler.
6
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)
10 any later version.
11
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.
16
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
0fb669f9
PE
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
56c47203 21
2cec9080 22#include <config.h>
56c47203 23#include "system.h"
17ee7397 24
9280d3ef 25#include "complain.h"
56c47203
AD
26#include "symlist.h"
27
28
17ee7397
PE
29/*--------------------------------------.
30| Create a list containing SYM at LOC. |
31`--------------------------------------*/
56c47203 32
17ee7397
PE
33symbol_list *
34symbol_list_new (symbol *sym, location loc)
56c47203 35{
da2a7671 36 symbol_list *res = xmalloc (sizeof *res);
affac613 37
56c47203 38 res->sym = sym;
17ee7397 39 res->location = loc;
affac613 40
6ec2c0f2 41 res->midrule = NULL;
ffa4ba3a
JD
42 res->midrule_parent_rule = NULL;
43 res->midrule_parent_rhs_index = 0;
84866159 44
56c47203 45 res->action = NULL;
affac613
AD
46 res->used = false;
47
56c47203 48 res->ruleprec = NULL;
676385e2
PH
49 res->dprec = 0;
50 res->merger = 0;
affac613
AD
51
52 res->next = NULL;
53
56c47203
AD
54 return res;
55}
56
57
867a3e00
AD
58/*------------------.
59| Print this list. |
60`------------------*/
61
62void
378f4bd8 63symbol_list_print (const symbol_list *l, FILE *f)
867a3e00 64{
22dda0f0
AD
65 for (/* Nothing. */; l && l->sym; l = l->next)
66 {
67 symbol_print (l->sym, f);
378f4bd8 68 fprintf (stderr, l->used ? " used" : " unused");
22dda0f0 69 if (l && l->sym)
affac613 70 fprintf (f, ", ");
22dda0f0 71 }
867a3e00
AD
72}
73
74
17ee7397
PE
75/*---------------------------------.
76| Prepend SYM at LOC to the LIST. |
77`---------------------------------*/
56c47203 78
17ee7397
PE
79symbol_list *
80symbol_list_prepend (symbol_list *list, symbol *sym, location loc)
56c47203 81{
17ee7397 82 symbol_list *res = symbol_list_new (sym, loc);
56c47203
AD
83 res->next = list;
84 return res;
85}
86
87
88/*-------------------------------------------------.
89| Free the LIST, but not the symbols it contains. |
90`-------------------------------------------------*/
91
92void
17ee7397 93symbol_list_free (symbol_list *list)
56c47203 94{
17ee7397 95 LIST_FREE (symbol_list, list);
56c47203
AD
96}
97
98
dafdc66f
AD
99/*--------------------.
100| Return its length. |
101`--------------------*/
102
b37acfe1
PE
103int
104symbol_list_length (symbol_list const *l)
dafdc66f
AD
105{
106 int res = 0;
ffa4ba3a 107 for (/* Nothing. */; l && l->sym; l = l->next)
dafdc66f
AD
108 ++res;
109 return res;
110}
111
112
affac613
AD
113/*--------------------------------.
114| Get symbol N in symbol list L. |
115`--------------------------------*/
116
117symbol_list *
118symbol_list_n_get (symbol_list *l, int n)
119{
120 int i;
121
122 if (n < 0)
123 return NULL;
124
125 for (i = 0; i < n; ++i)
126 {
127 l = l->next;
128 if (l == NULL || l->sym == NULL)
129 return NULL;
130 }
131
132 return l;
133}
134
135
56c47203
AD
136/*--------------------------------------------------------------.
137| Get the data type (alternative in the union) of the value for |
affac613 138| symbol N in symbol list L. |
56c47203
AD
139`--------------------------------------------------------------*/
140
17ee7397 141uniqstr
affac613 142symbol_list_n_type_name_get (symbol_list *l, location loc, int n)
56c47203 143{
affac613
AD
144 l = symbol_list_n_get (l, n);
145 if (!l)
56c47203 146 {
867a3e00 147 complain_at (loc, _("invalid $ value: $%d"), n);
56c47203
AD
148 return NULL;
149 }
affac613
AD
150 return l->sym->type_name;
151}
56c47203 152
56c47203 153
affac613
AD
154/*----------------------------------------.
155| The symbol N in symbol list L is USED. |
156`----------------------------------------*/
56c47203 157
affac613
AD
158void
159symbol_list_n_used_set (symbol_list *l, int n, bool used)
160{
161 l = symbol_list_n_get (l, n);
162 if (l)
163 l->used = used;
56c47203 164}