]> git.saurik.com Git - bison.git/blame - src/symlist.c
Undo 2005-12-01 tentative license wording change.
[bison.git] / src / symlist.c
CommitLineData
56c47203 1/* Lists of symbols for Bison
17ee7397 2
867a3e00 3 Copyright (C) 2002, 2005 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);
56c47203
AD
37 res->next = NULL;
38 res->sym = sym;
17ee7397 39 res->location = loc;
56c47203
AD
40 res->action = NULL;
41 res->ruleprec = NULL;
676385e2
PH
42 res->dprec = 0;
43 res->merger = 0;
56c47203
AD
44 return res;
45}
46
47
867a3e00
AD
48/*------------------.
49| Print this list. |
50`------------------*/
51
52void
22dda0f0 53symbol_list_print (symbol_list *l, FILE *f)
867a3e00 54{
22dda0f0
AD
55 for (/* Nothing. */; l && l->sym; l = l->next)
56 {
57 symbol_print (l->sym, f);
58 if (l && l->sym)
59 fputc (' ', f);
60 }
867a3e00
AD
61}
62
63
17ee7397
PE
64/*---------------------------------.
65| Prepend SYM at LOC to the LIST. |
66`---------------------------------*/
56c47203 67
17ee7397
PE
68symbol_list *
69symbol_list_prepend (symbol_list *list, symbol *sym, location loc)
56c47203 70{
17ee7397 71 symbol_list *res = symbol_list_new (sym, loc);
56c47203
AD
72 res->next = list;
73 return res;
74}
75
76
77/*-------------------------------------------------.
78| Free the LIST, but not the symbols it contains. |
79`-------------------------------------------------*/
80
81void
17ee7397 82symbol_list_free (symbol_list *list)
56c47203 83{
17ee7397 84 LIST_FREE (symbol_list, list);
56c47203
AD
85}
86
87
dafdc66f
AD
88/*--------------------.
89| Return its length. |
90`--------------------*/
91
92unsigned int
17ee7397 93symbol_list_length (symbol_list *list)
dafdc66f
AD
94{
95 int res = 0;
96 for (/* Nothing. */; list; list = list->next)
97 ++res;
98 return res;
99}
100
101
56c47203
AD
102/*--------------------------------------------------------------.
103| Get the data type (alternative in the union) of the value for |
17ee7397 104| symbol N in symbol list RP. |
56c47203
AD
105`--------------------------------------------------------------*/
106
17ee7397
PE
107uniqstr
108symbol_list_n_type_name_get (symbol_list *rp, location loc, int n)
56c47203
AD
109{
110 int i;
56c47203
AD
111
112 if (n < 0)
113 {
867a3e00 114 complain_at (loc, _("invalid $ value: $%d"), n);
56c47203
AD
115 return NULL;
116 }
117
56c47203
AD
118 i = 0;
119
120 while (i < n)
121 {
122 rp = rp->next;
123 if (rp == NULL || rp->sym == NULL)
124 {
867a3e00 125 complain_at (loc, _("invalid $ value: $%d"), n);
56c47203
AD
126 return NULL;
127 }
128 ++i;
129 }
130
131 return rp->sym->type_name;
132}