1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1997-1999 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate  * All rights reserved.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate #include <stdio.h>
30*7c478bd9Sstevel@tonic-gate #include <string.h>
31*7c478bd9Sstevel@tonic-gate #include <limits.h>
32*7c478bd9Sstevel@tonic-gate #include <malloc.h>
33*7c478bd9Sstevel@tonic-gate #include "parser.h"
34*7c478bd9Sstevel@tonic-gate #include "trace.h"
35*7c478bd9Sstevel@tonic-gate #include "util.h"
36*7c478bd9Sstevel@tonic-gate #include "symtab.h"
37*7c478bd9Sstevel@tonic-gate #include "errlog.h"
38*7c478bd9Sstevel@tonic-gate 
39*7c478bd9Sstevel@tonic-gate /* Types */
40*7c478bd9Sstevel@tonic-gate enum kind_t { PRIMITIVE = 0, COMPOSITE, VARARG };
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate struct entry_t {
43*7c478bd9Sstevel@tonic-gate 	char	*e_name;
44*7c478bd9Sstevel@tonic-gate 	int	e_valid;
45*7c478bd9Sstevel@tonic-gate 	int	e_line;
46*7c478bd9Sstevel@tonic-gate 	char	*e_file;
47*7c478bd9Sstevel@tonic-gate 	int	e_kind;		/* PRIMITIVE, COMPOSITE... */
48*7c478bd9Sstevel@tonic-gate 	char	*e_type;	/* where kind == PRIMITIVE */
49*7c478bd9Sstevel@tonic-gate 	/* base type, ie. char if e_type is char */
50*7c478bd9Sstevel@tonic-gate 	char	*e_basetype;
51*7c478bd9Sstevel@tonic-gate 	int	e_levels;	/* levels of indirection */
52*7c478bd9Sstevel@tonic-gate 	char	*e_attribute;	/* kind == COMPOSITE or VARARG. */
53*7c478bd9Sstevel@tonic-gate 	char	*e_assertion;	/* reserved for kind == VARARG. */
54*7c478bd9Sstevel@tonic-gate 	char	*e_comment;	/* reserved for per-element comments. */
55*7c478bd9Sstevel@tonic-gate 	int	e_pre_uses;
56*7c478bd9Sstevel@tonic-gate 	int	e_post_uses;
57*7c478bd9Sstevel@tonic-gate };
58*7c478bd9Sstevel@tonic-gate 
59*7c478bd9Sstevel@tonic-gate typedef struct entry_head_t {
60*7c478bd9Sstevel@tonic-gate 	int	used;
61*7c478bd9Sstevel@tonic-gate 	int	n_entries;
62*7c478bd9Sstevel@tonic-gate 	ENTRY	entry[1]; /* Actually entry[n_entries]. */
63*7c478bd9Sstevel@tonic-gate } EHEAD;
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate static struct symtab_t {
66*7c478bd9Sstevel@tonic-gate 	ENTRY	*Function;
67*7c478bd9Sstevel@tonic-gate 	EHEAD	*Args;
68*7c478bd9Sstevel@tonic-gate 	EHEAD	*Varargs;
69*7c478bd9Sstevel@tonic-gate 	EHEAD	*Globals;
70*7c478bd9Sstevel@tonic-gate 	ENTRY	*Errval;
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate 	/* Includes */
73*7c478bd9Sstevel@tonic-gate 	table_t	*Includes;
74*7c478bd9Sstevel@tonic-gate 
75*7c478bd9Sstevel@tonic-gate 	/* Bindings */
76*7c478bd9Sstevel@tonic-gate 	ENTRY	*Exception;
77*7c478bd9Sstevel@tonic-gate 
78*7c478bd9Sstevel@tonic-gate 	/* Types */
79*7c478bd9Sstevel@tonic-gate 	table_t	*Print_Types;
80*7c478bd9Sstevel@tonic-gate 
81*7c478bd9Sstevel@tonic-gate 	/* Error-message information. */
82*7c478bd9Sstevel@tonic-gate 	int	Line;
83*7c478bd9Sstevel@tonic-gate 	char	Filename[MAXLINE];
84*7c478bd9Sstevel@tonic-gate 
85*7c478bd9Sstevel@tonic-gate 	/* Trace additions */
86*7c478bd9Sstevel@tonic-gate 	char	Prototype[MAXLINE];
87*7c478bd9Sstevel@tonic-gate 	char	Formals[MAXLINE];
88*7c478bd9Sstevel@tonic-gate 	char	Actuals[MAXLINE];
89*7c478bd9Sstevel@tonic-gate 	char	Cast[MAXLINE];
90*7c478bd9Sstevel@tonic-gate 	int	Nonreturn;
91*7c478bd9Sstevel@tonic-gate 	int	Skip;
92*7c478bd9Sstevel@tonic-gate 
93*7c478bd9Sstevel@tonic-gate 	/* Adl additions */
94*7c478bd9Sstevel@tonic-gate 	/* various assertions, one hopes */
95*7c478bd9Sstevel@tonic-gate } Symtab;
96*7c478bd9Sstevel@tonic-gate 
97*7c478bd9Sstevel@tonic-gate /* File Globals. */
98*7c478bd9Sstevel@tonic-gate static EHEAD *create_entry_table(int);
99*7c478bd9Sstevel@tonic-gate static EHEAD *add_entry_table(EHEAD *,
100*7c478bd9Sstevel@tonic-gate 	char *, int, char *, int, char *, char *, int, char *, int, int);
101*7c478bd9Sstevel@tonic-gate static ENTRY *get_entry_table(EHEAD *, int);
102*7c478bd9Sstevel@tonic-gate static EHEAD *free_entry_table(EHEAD *);
103*7c478bd9Sstevel@tonic-gate static void clear_entries(EHEAD *, int, int);
104*7c478bd9Sstevel@tonic-gate static ENTRY *allocate_entry(ENTRY *, char *, int, char *, int,
105*7c478bd9Sstevel@tonic-gate     char *, char *, int, char *, int, int);
106*7c478bd9Sstevel@tonic-gate static ENTRY *set_entry(ENTRY *,
107*7c478bd9Sstevel@tonic-gate 	char *, int, char *, int, char *, char *, int, char *, int, int);
108*7c478bd9Sstevel@tonic-gate static ENTRY *free_entry(ENTRY *);
109*7c478bd9Sstevel@tonic-gate static void symtab_clear_varargs(void);
110*7c478bd9Sstevel@tonic-gate static void symtab_clear_globals(void);
111*7c478bd9Sstevel@tonic-gate static void symtab_clear_print_types(void);
112*7c478bd9Sstevel@tonic-gate static void symtab_set_nonreturn(int);
113*7c478bd9Sstevel@tonic-gate static table_t *symtab_free_print_types(table_t *);
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate /*
116*7c478bd9Sstevel@tonic-gate  * symtab_new_function -- clear counts, variables for a new function.
117*7c478bd9Sstevel@tonic-gate  */
118*7c478bd9Sstevel@tonic-gate void
119*7c478bd9Sstevel@tonic-gate symtab_new_function(const int line, const char *file)
120*7c478bd9Sstevel@tonic-gate {
121*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_new_function() {");
122*7c478bd9Sstevel@tonic-gate 	Symtab.Line = line;	/* Set, don't clear. */
123*7c478bd9Sstevel@tonic-gate 	symtab_set_filename(file);
124*7c478bd9Sstevel@tonic-gate 
125*7c478bd9Sstevel@tonic-gate 	symtab_clear_function();
126*7c478bd9Sstevel@tonic-gate 	symtab_clear_varargs();
127*7c478bd9Sstevel@tonic-gate 	symtab_clear_globals();
128*7c478bd9Sstevel@tonic-gate 	symtab_clear_errval();
129*7c478bd9Sstevel@tonic-gate 	symtab_clear_exception();
130*7c478bd9Sstevel@tonic-gate 	symtab_clear_print_types();
131*7c478bd9Sstevel@tonic-gate 
132*7c478bd9Sstevel@tonic-gate 	symtab_set_nonreturn(NO);
133*7c478bd9Sstevel@tonic-gate 	symtab_set_skip(NO);
134*7c478bd9Sstevel@tonic-gate 	errlog(END, "}");
135*7c478bd9Sstevel@tonic-gate }
136*7c478bd9Sstevel@tonic-gate 
137*7c478bd9Sstevel@tonic-gate 
138*7c478bd9Sstevel@tonic-gate /*
139*7c478bd9Sstevel@tonic-gate  * symtab_clear_function -- clear function-prototype-derived
140*7c478bd9Sstevel@tonic-gate  *	values. Called on each prototype line and at beginning
141*7c478bd9Sstevel@tonic-gate  *	of interface.
142*7c478bd9Sstevel@tonic-gate  */
143*7c478bd9Sstevel@tonic-gate void
144*7c478bd9Sstevel@tonic-gate symtab_clear_function(void)
145*7c478bd9Sstevel@tonic-gate {
146*7c478bd9Sstevel@tonic-gate 
147*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_clear_function() {");
148*7c478bd9Sstevel@tonic-gate 	Symtab.Function = free_entry(Symtab.Function);
149*7c478bd9Sstevel@tonic-gate 	Symtab.Args = free_entry_table(Symtab.Args);
150*7c478bd9Sstevel@tonic-gate 	Symtab.Prototype[0] = NULL;
151*7c478bd9Sstevel@tonic-gate 	Symtab.Formals[0] = NULL;
152*7c478bd9Sstevel@tonic-gate 	Symtab.Actuals[0] = NULL;
153*7c478bd9Sstevel@tonic-gate 	Symtab.Cast[0] = NULL;
154*7c478bd9Sstevel@tonic-gate 	errlog(END, "}");
155*7c478bd9Sstevel@tonic-gate }
156*7c478bd9Sstevel@tonic-gate 
157*7c478bd9Sstevel@tonic-gate 
158*7c478bd9Sstevel@tonic-gate /*
159*7c478bd9Sstevel@tonic-gate  * symtab_clear_varargs -- called only at end
160*7c478bd9Sstevel@tonic-gate  */
161*7c478bd9Sstevel@tonic-gate static void
162*7c478bd9Sstevel@tonic-gate symtab_clear_varargs(void)
163*7c478bd9Sstevel@tonic-gate {
164*7c478bd9Sstevel@tonic-gate 
165*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_clear_varargs() {");
166*7c478bd9Sstevel@tonic-gate 	Symtab.Varargs = free_entry_table(Symtab.Varargs);
167*7c478bd9Sstevel@tonic-gate 	errlog(END, "}");
168*7c478bd9Sstevel@tonic-gate }
169*7c478bd9Sstevel@tonic-gate 
170*7c478bd9Sstevel@tonic-gate /*
171*7c478bd9Sstevel@tonic-gate  * symtab_clear_includes -- clear only at end of file (union++)
172*7c478bd9Sstevel@tonic-gate  */
173*7c478bd9Sstevel@tonic-gate void
174*7c478bd9Sstevel@tonic-gate symtab_clear_includes(void)
175*7c478bd9Sstevel@tonic-gate {
176*7c478bd9Sstevel@tonic-gate 
177*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_clear_includes() {");
178*7c478bd9Sstevel@tonic-gate 	Symtab.Includes = free_string_table(Symtab.Includes);
179*7c478bd9Sstevel@tonic-gate 	errlog(END, "}");
180*7c478bd9Sstevel@tonic-gate }
181*7c478bd9Sstevel@tonic-gate 
182*7c478bd9Sstevel@tonic-gate static void
183*7c478bd9Sstevel@tonic-gate symtab_clear_globals(void)
184*7c478bd9Sstevel@tonic-gate {
185*7c478bd9Sstevel@tonic-gate 
186*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_clear_globals() {");
187*7c478bd9Sstevel@tonic-gate 	Symtab.Globals = free_entry_table(Symtab.Globals);
188*7c478bd9Sstevel@tonic-gate 	errlog(END, "}");
189*7c478bd9Sstevel@tonic-gate }
190*7c478bd9Sstevel@tonic-gate 
191*7c478bd9Sstevel@tonic-gate void
192*7c478bd9Sstevel@tonic-gate symtab_clear_errval(void)
193*7c478bd9Sstevel@tonic-gate {
194*7c478bd9Sstevel@tonic-gate 
195*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_clear_errval() {");
196*7c478bd9Sstevel@tonic-gate 	Symtab.Errval = free_entry(Symtab.Errval);
197*7c478bd9Sstevel@tonic-gate 	errlog(END, "}");
198*7c478bd9Sstevel@tonic-gate }
199*7c478bd9Sstevel@tonic-gate 
200*7c478bd9Sstevel@tonic-gate void
201*7c478bd9Sstevel@tonic-gate symtab_clear_exception(void)
202*7c478bd9Sstevel@tonic-gate {
203*7c478bd9Sstevel@tonic-gate 
204*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_clear_exception() {");
205*7c478bd9Sstevel@tonic-gate 	Symtab.Exception = free_entry(Symtab.Exception);
206*7c478bd9Sstevel@tonic-gate 	errlog(END, "}");
207*7c478bd9Sstevel@tonic-gate }
208*7c478bd9Sstevel@tonic-gate 
209*7c478bd9Sstevel@tonic-gate static void
210*7c478bd9Sstevel@tonic-gate symtab_clear_print_types(void)
211*7c478bd9Sstevel@tonic-gate {
212*7c478bd9Sstevel@tonic-gate 
213*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_clear_print_types() {");
214*7c478bd9Sstevel@tonic-gate 	Symtab.Print_Types = symtab_free_print_types(Symtab.Print_Types);
215*7c478bd9Sstevel@tonic-gate 	errlog(END, "}");
216*7c478bd9Sstevel@tonic-gate }
217*7c478bd9Sstevel@tonic-gate 
218*7c478bd9Sstevel@tonic-gate 
219*7c478bd9Sstevel@tonic-gate /* Generated by m4 -- character string values */
220*7c478bd9Sstevel@tonic-gate 
221*7c478bd9Sstevel@tonic-gate void
222*7c478bd9Sstevel@tonic-gate symtab_set_prototype(char *p)
223*7c478bd9Sstevel@tonic-gate {
224*7c478bd9Sstevel@tonic-gate 
225*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_set_prototype(void) {");
226*7c478bd9Sstevel@tonic-gate 	(void) strncpy(Symtab.Prototype, p, sizeof (Symtab.Prototype));
227*7c478bd9Sstevel@tonic-gate 	Symtab.Prototype[sizeof (Symtab.Prototype)-1] = NULL;
228*7c478bd9Sstevel@tonic-gate 	errlog(END, "}");
229*7c478bd9Sstevel@tonic-gate }
230*7c478bd9Sstevel@tonic-gate 
231*7c478bd9Sstevel@tonic-gate char *
232*7c478bd9Sstevel@tonic-gate symtab_get_prototype(void)
233*7c478bd9Sstevel@tonic-gate {
234*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_get_prototype() {"); errlog(END, "}");
235*7c478bd9Sstevel@tonic-gate 	return (Symtab.Prototype);
236*7c478bd9Sstevel@tonic-gate }
237*7c478bd9Sstevel@tonic-gate 
238*7c478bd9Sstevel@tonic-gate void
239*7c478bd9Sstevel@tonic-gate symtab_set_formals(char *p)
240*7c478bd9Sstevel@tonic-gate {
241*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_set_formals() {");
242*7c478bd9Sstevel@tonic-gate 	errlog(VERBOSE, "p = %s", p);
243*7c478bd9Sstevel@tonic-gate 	(void) strncpy(Symtab.Formals, p, sizeof (Symtab.Formals));
244*7c478bd9Sstevel@tonic-gate 	Symtab.Formals[sizeof (Symtab.Formals)-1] = NULL;
245*7c478bd9Sstevel@tonic-gate 	errlog(END, "}");
246*7c478bd9Sstevel@tonic-gate }
247*7c478bd9Sstevel@tonic-gate 
248*7c478bd9Sstevel@tonic-gate char *
249*7c478bd9Sstevel@tonic-gate symtab_get_formals(void)
250*7c478bd9Sstevel@tonic-gate {
251*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_get_formals() {"); errlog(END, "}");
252*7c478bd9Sstevel@tonic-gate 	return (Symtab.Formals);
253*7c478bd9Sstevel@tonic-gate }
254*7c478bd9Sstevel@tonic-gate 
255*7c478bd9Sstevel@tonic-gate void
256*7c478bd9Sstevel@tonic-gate symtab_set_actuals(char *p)
257*7c478bd9Sstevel@tonic-gate {
258*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_set_actuals() {"); errlog(END, "}");
259*7c478bd9Sstevel@tonic-gate 	errlog(VERBOSE, "p = %s", p);
260*7c478bd9Sstevel@tonic-gate 	(void) strncpy(Symtab.Actuals, p, sizeof (Symtab.Actuals));
261*7c478bd9Sstevel@tonic-gate 	Symtab.Actuals[sizeof (Symtab.Actuals)-1] = NULL;
262*7c478bd9Sstevel@tonic-gate }
263*7c478bd9Sstevel@tonic-gate 
264*7c478bd9Sstevel@tonic-gate char *
265*7c478bd9Sstevel@tonic-gate symtab_get_actuals(void)
266*7c478bd9Sstevel@tonic-gate {
267*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_get_actuals() {"); errlog(END, "}");
268*7c478bd9Sstevel@tonic-gate 	return (Symtab.Actuals);
269*7c478bd9Sstevel@tonic-gate }
270*7c478bd9Sstevel@tonic-gate 
271*7c478bd9Sstevel@tonic-gate void
272*7c478bd9Sstevel@tonic-gate symtab_set_cast(char *p)
273*7c478bd9Sstevel@tonic-gate {
274*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_set_cast() {"); errlog(END, "}");
275*7c478bd9Sstevel@tonic-gate 	(void) strncpy(Symtab.Cast, p, sizeof (Symtab.Cast));
276*7c478bd9Sstevel@tonic-gate 	Symtab.Cast[sizeof (Symtab.Cast)-1] = NULL;
277*7c478bd9Sstevel@tonic-gate }
278*7c478bd9Sstevel@tonic-gate 
279*7c478bd9Sstevel@tonic-gate char *
280*7c478bd9Sstevel@tonic-gate symtab_get_cast(void)
281*7c478bd9Sstevel@tonic-gate {
282*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_get_cast() {"); errlog(END, "}");
283*7c478bd9Sstevel@tonic-gate 	return (Symtab.Cast);
284*7c478bd9Sstevel@tonic-gate }
285*7c478bd9Sstevel@tonic-gate 
286*7c478bd9Sstevel@tonic-gate 
287*7c478bd9Sstevel@tonic-gate void
288*7c478bd9Sstevel@tonic-gate symtab_set_filename(const char *p)
289*7c478bd9Sstevel@tonic-gate {
290*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_set_filename() {"); errlog(END, "}");
291*7c478bd9Sstevel@tonic-gate 	(void) strncpy(Symtab.Filename, p, sizeof (Symtab.Filename));
292*7c478bd9Sstevel@tonic-gate 	Symtab.Filename[sizeof (Symtab.Filename)-1] = NULL;
293*7c478bd9Sstevel@tonic-gate }
294*7c478bd9Sstevel@tonic-gate 
295*7c478bd9Sstevel@tonic-gate char *
296*7c478bd9Sstevel@tonic-gate symtab_get_filename(void)
297*7c478bd9Sstevel@tonic-gate {
298*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_get_filename() {"); errlog(END, "}");
299*7c478bd9Sstevel@tonic-gate 	return (Symtab.Filename);
300*7c478bd9Sstevel@tonic-gate }
301*7c478bd9Sstevel@tonic-gate 
302*7c478bd9Sstevel@tonic-gate 
303*7c478bd9Sstevel@tonic-gate /* Generated by m4 -- int values */
304*7c478bd9Sstevel@tonic-gate 
305*7c478bd9Sstevel@tonic-gate static void
306*7c478bd9Sstevel@tonic-gate symtab_set_nonreturn(int val)
307*7c478bd9Sstevel@tonic-gate {
308*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_set_nonreturn() {"); errlog(END, "}");
309*7c478bd9Sstevel@tonic-gate 	Symtab.Nonreturn = val;
310*7c478bd9Sstevel@tonic-gate }
311*7c478bd9Sstevel@tonic-gate 
312*7c478bd9Sstevel@tonic-gate int
313*7c478bd9Sstevel@tonic-gate symtab_get_nonreturn(void)
314*7c478bd9Sstevel@tonic-gate {
315*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_get_nonreturn() {"); errlog(END, "}");
316*7c478bd9Sstevel@tonic-gate 	return (Symtab.Nonreturn);
317*7c478bd9Sstevel@tonic-gate }
318*7c478bd9Sstevel@tonic-gate 
319*7c478bd9Sstevel@tonic-gate void
320*7c478bd9Sstevel@tonic-gate symtab_set_line(int val)
321*7c478bd9Sstevel@tonic-gate {
322*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_set_line() {"); errlog(END, "}");
323*7c478bd9Sstevel@tonic-gate 	Symtab.Line = val;
324*7c478bd9Sstevel@tonic-gate }
325*7c478bd9Sstevel@tonic-gate 
326*7c478bd9Sstevel@tonic-gate int
327*7c478bd9Sstevel@tonic-gate symtab_get_line(void)
328*7c478bd9Sstevel@tonic-gate {
329*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_get_line() {"); errlog(END, "}");
330*7c478bd9Sstevel@tonic-gate 	return (Symtab.Line);
331*7c478bd9Sstevel@tonic-gate }
332*7c478bd9Sstevel@tonic-gate 
333*7c478bd9Sstevel@tonic-gate 
334*7c478bd9Sstevel@tonic-gate void
335*7c478bd9Sstevel@tonic-gate symtab_set_skip(int value)
336*7c478bd9Sstevel@tonic-gate {
337*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_set_skip() {"); errlog(END, "}");
338*7c478bd9Sstevel@tonic-gate 	Symtab.Skip = value;
339*7c478bd9Sstevel@tonic-gate }
340*7c478bd9Sstevel@tonic-gate 
341*7c478bd9Sstevel@tonic-gate int
342*7c478bd9Sstevel@tonic-gate symtab_get_skip(void)
343*7c478bd9Sstevel@tonic-gate {
344*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_get_skip() {"); errlog(END, "}");
345*7c478bd9Sstevel@tonic-gate 	return (Symtab.Skip);
346*7c478bd9Sstevel@tonic-gate }
347*7c478bd9Sstevel@tonic-gate 
348*7c478bd9Sstevel@tonic-gate /*
349*7c478bd9Sstevel@tonic-gate  * Manually written access functions for ENTRY * variables.
350*7c478bd9Sstevel@tonic-gate  */
351*7c478bd9Sstevel@tonic-gate 
352*7c478bd9Sstevel@tonic-gate void
353*7c478bd9Sstevel@tonic-gate symtab_set_function(char *name, int line, char *file,
354*7c478bd9Sstevel@tonic-gate     char *type, char *basetype, int levels)
355*7c478bd9Sstevel@tonic-gate {
356*7c478bd9Sstevel@tonic-gate 
357*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_set_function() {");
358*7c478bd9Sstevel@tonic-gate 	Symtab.Function = allocate_entry(Symtab.Function,
359*7c478bd9Sstevel@tonic-gate 	    name, line, file, PRIMITIVE, type, basetype, levels, "", -1, -1);
360*7c478bd9Sstevel@tonic-gate 	errlog(END, "}");
361*7c478bd9Sstevel@tonic-gate }
362*7c478bd9Sstevel@tonic-gate 
363*7c478bd9Sstevel@tonic-gate ENTRY *
364*7c478bd9Sstevel@tonic-gate symtab_get_function(void)
365*7c478bd9Sstevel@tonic-gate {
366*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_get_function() {"); errlog(END, "}");
367*7c478bd9Sstevel@tonic-gate 	if (Symtab.Function == NULL)
368*7c478bd9Sstevel@tonic-gate 		return (NULL);
369*7c478bd9Sstevel@tonic-gate 	else
370*7c478bd9Sstevel@tonic-gate 		return ((Symtab.Function->e_valid)? Symtab.Function: NULL);
371*7c478bd9Sstevel@tonic-gate }
372*7c478bd9Sstevel@tonic-gate 
373*7c478bd9Sstevel@tonic-gate void
374*7c478bd9Sstevel@tonic-gate symtab_set_exception(char *value, int line, char *file)
375*7c478bd9Sstevel@tonic-gate {
376*7c478bd9Sstevel@tonic-gate 
377*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_set_exception() {");
378*7c478bd9Sstevel@tonic-gate 	Symtab.Exception = allocate_entry(Symtab.Exception,
379*7c478bd9Sstevel@tonic-gate 		value, line, file, COMPOSITE, "", "", 0, "", -1, -1);
380*7c478bd9Sstevel@tonic-gate 	errlog(END, "}");
381*7c478bd9Sstevel@tonic-gate }
382*7c478bd9Sstevel@tonic-gate 
383*7c478bd9Sstevel@tonic-gate ENTRY *
384*7c478bd9Sstevel@tonic-gate symtab_get_exception(void)
385*7c478bd9Sstevel@tonic-gate {
386*7c478bd9Sstevel@tonic-gate 
387*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_get_exception() {"); errlog(END, "}");
388*7c478bd9Sstevel@tonic-gate 	if (Symtab.Exception == NULL)
389*7c478bd9Sstevel@tonic-gate 		return (NULL);
390*7c478bd9Sstevel@tonic-gate 	else
391*7c478bd9Sstevel@tonic-gate 		return ((Symtab.Exception->e_valid)? Symtab.Exception: NULL);
392*7c478bd9Sstevel@tonic-gate }
393*7c478bd9Sstevel@tonic-gate 
394*7c478bd9Sstevel@tonic-gate void
395*7c478bd9Sstevel@tonic-gate symtab_set_errval(char *name, int line, char *file, char *type, char *basetype,
396*7c478bd9Sstevel@tonic-gate     int levels)
397*7c478bd9Sstevel@tonic-gate {
398*7c478bd9Sstevel@tonic-gate 
399*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_set_errval() {");
400*7c478bd9Sstevel@tonic-gate 	Symtab.Errval = allocate_entry(Symtab.Errval,
401*7c478bd9Sstevel@tonic-gate 	    name, line, file, PRIMITIVE, type, basetype, levels,
402*7c478bd9Sstevel@tonic-gate 	    "", -1, -1);
403*7c478bd9Sstevel@tonic-gate 	errlog(END, "}");
404*7c478bd9Sstevel@tonic-gate }
405*7c478bd9Sstevel@tonic-gate 
406*7c478bd9Sstevel@tonic-gate ENTRY *
407*7c478bd9Sstevel@tonic-gate symtab_get_errval(void)
408*7c478bd9Sstevel@tonic-gate {
409*7c478bd9Sstevel@tonic-gate 
410*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_get_errval() {"); errlog(END, "}");
411*7c478bd9Sstevel@tonic-gate 	if (Symtab.Errval == NULL)
412*7c478bd9Sstevel@tonic-gate 		return (NULL);
413*7c478bd9Sstevel@tonic-gate 	else
414*7c478bd9Sstevel@tonic-gate 		return ((Symtab.Errval->e_valid)? Symtab.Errval: NULL);
415*7c478bd9Sstevel@tonic-gate }
416*7c478bd9Sstevel@tonic-gate 
417*7c478bd9Sstevel@tonic-gate /*
418*7c478bd9Sstevel@tonic-gate  * Manually written  access function for tables of ENTRYs
419*7c478bd9Sstevel@tonic-gate  */
420*7c478bd9Sstevel@tonic-gate void
421*7c478bd9Sstevel@tonic-gate symtab_add_args(char *name, int line, char *file,
422*7c478bd9Sstevel@tonic-gate     char *type, char *basetype, int levels)
423*7c478bd9Sstevel@tonic-gate {
424*7c478bd9Sstevel@tonic-gate 
425*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_add_args() {");
426*7c478bd9Sstevel@tonic-gate 	if (Symtab.Args == NULL) {
427*7c478bd9Sstevel@tonic-gate 		Symtab.Args = create_entry_table(10);
428*7c478bd9Sstevel@tonic-gate 	}
429*7c478bd9Sstevel@tonic-gate 	Symtab.Args = add_entry_table(Symtab.Args,
430*7c478bd9Sstevel@tonic-gate 	    name, line, file, PRIMITIVE, type, basetype, levels, "", -1, -1);
431*7c478bd9Sstevel@tonic-gate 	errlog(END, "}");
432*7c478bd9Sstevel@tonic-gate }
433*7c478bd9Sstevel@tonic-gate 
434*7c478bd9Sstevel@tonic-gate static int curr_arg;
435*7c478bd9Sstevel@tonic-gate 
436*7c478bd9Sstevel@tonic-gate ENTRY *
437*7c478bd9Sstevel@tonic-gate symtab_get_first_arg(void)
438*7c478bd9Sstevel@tonic-gate {
439*7c478bd9Sstevel@tonic-gate 
440*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_get_first_arg() {"); errlog(END, "}");
441*7c478bd9Sstevel@tonic-gate 	curr_arg = 1;
442*7c478bd9Sstevel@tonic-gate 	return (get_entry_table(Symtab.Args, 0));
443*7c478bd9Sstevel@tonic-gate }
444*7c478bd9Sstevel@tonic-gate 
445*7c478bd9Sstevel@tonic-gate ENTRY *
446*7c478bd9Sstevel@tonic-gate symtab_get_next_arg(void)
447*7c478bd9Sstevel@tonic-gate {
448*7c478bd9Sstevel@tonic-gate 
449*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_get_next_arg() {"); errlog(END, "}");
450*7c478bd9Sstevel@tonic-gate 	return (get_entry_table(Symtab.Args, curr_arg++));
451*7c478bd9Sstevel@tonic-gate }
452*7c478bd9Sstevel@tonic-gate 
453*7c478bd9Sstevel@tonic-gate ENTRY *
454*7c478bd9Sstevel@tonic-gate symtab_get_last_arg(void)
455*7c478bd9Sstevel@tonic-gate {
456*7c478bd9Sstevel@tonic-gate 
457*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_get_last_arg() {"); errlog(END, "}");
458*7c478bd9Sstevel@tonic-gate 	return (get_entry_table(Symtab.Args, Symtab.Args->used));
459*7c478bd9Sstevel@tonic-gate }
460*7c478bd9Sstevel@tonic-gate 
461*7c478bd9Sstevel@tonic-gate void
462*7c478bd9Sstevel@tonic-gate symtab_add_varargs(char *name, int line, char *file, char *type, char *print)
463*7c478bd9Sstevel@tonic-gate {
464*7c478bd9Sstevel@tonic-gate 
465*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_add_varargs() {");
466*7c478bd9Sstevel@tonic-gate 	if (Symtab.Varargs == NULL) {
467*7c478bd9Sstevel@tonic-gate 		Symtab.Varargs = create_entry_table(10);
468*7c478bd9Sstevel@tonic-gate 	}
469*7c478bd9Sstevel@tonic-gate 	Symtab.Varargs = add_entry_table(Symtab.Varargs,
470*7c478bd9Sstevel@tonic-gate 		name, line, file, PRIMITIVE, type, print, 0, "", -1, -1);
471*7c478bd9Sstevel@tonic-gate 	errlog(END, "}");
472*7c478bd9Sstevel@tonic-gate }
473*7c478bd9Sstevel@tonic-gate 
474*7c478bd9Sstevel@tonic-gate static int curr_vararg;
475*7c478bd9Sstevel@tonic-gate 
476*7c478bd9Sstevel@tonic-gate ENTRY *
477*7c478bd9Sstevel@tonic-gate symtab_get_first_vararg(void)
478*7c478bd9Sstevel@tonic-gate {
479*7c478bd9Sstevel@tonic-gate 
480*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_get_first_vararg() {"); errlog(END, "}");
481*7c478bd9Sstevel@tonic-gate 	curr_vararg = 1;
482*7c478bd9Sstevel@tonic-gate 	return (get_entry_table(Symtab.Varargs, 0));
483*7c478bd9Sstevel@tonic-gate }
484*7c478bd9Sstevel@tonic-gate 
485*7c478bd9Sstevel@tonic-gate ENTRY *
486*7c478bd9Sstevel@tonic-gate symtab_get_next_vararg(void)
487*7c478bd9Sstevel@tonic-gate {
488*7c478bd9Sstevel@tonic-gate 
489*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_get_next_vararg() {"); errlog(END, "}");
490*7c478bd9Sstevel@tonic-gate 	return (get_entry_table(Symtab.Varargs, curr_vararg++));
491*7c478bd9Sstevel@tonic-gate }
492*7c478bd9Sstevel@tonic-gate 
493*7c478bd9Sstevel@tonic-gate void
494*7c478bd9Sstevel@tonic-gate symtab_add_globals(char *name, int line, char *file, char *type,
495*7c478bd9Sstevel@tonic-gate     char *basetype, int levels)
496*7c478bd9Sstevel@tonic-gate {
497*7c478bd9Sstevel@tonic-gate 
498*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_add_globals() {");
499*7c478bd9Sstevel@tonic-gate 	if (Symtab.Globals == NULL) {
500*7c478bd9Sstevel@tonic-gate 		Symtab.Globals = create_entry_table(10);
501*7c478bd9Sstevel@tonic-gate 	}
502*7c478bd9Sstevel@tonic-gate 	Symtab.Globals = add_entry_table(Symtab.Globals,
503*7c478bd9Sstevel@tonic-gate 	    name, line, file, PRIMITIVE, type, basetype, levels, "", -1, -1);
504*7c478bd9Sstevel@tonic-gate 	errlog(END, "}");
505*7c478bd9Sstevel@tonic-gate }
506*7c478bd9Sstevel@tonic-gate 
507*7c478bd9Sstevel@tonic-gate 
508*7c478bd9Sstevel@tonic-gate static int curr_global;
509*7c478bd9Sstevel@tonic-gate 
510*7c478bd9Sstevel@tonic-gate ENTRY *
511*7c478bd9Sstevel@tonic-gate symtab_get_first_global(void)
512*7c478bd9Sstevel@tonic-gate {
513*7c478bd9Sstevel@tonic-gate 
514*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_get_first_global() {"); errlog(END, "}");
515*7c478bd9Sstevel@tonic-gate 	curr_global = 1;
516*7c478bd9Sstevel@tonic-gate 	return (get_entry_table(Symtab.Globals, 0));
517*7c478bd9Sstevel@tonic-gate }
518*7c478bd9Sstevel@tonic-gate 
519*7c478bd9Sstevel@tonic-gate ENTRY *
520*7c478bd9Sstevel@tonic-gate symtab_get_next_global(void)
521*7c478bd9Sstevel@tonic-gate {
522*7c478bd9Sstevel@tonic-gate 
523*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_get_next_global() {"); errlog(END, "}");
524*7c478bd9Sstevel@tonic-gate 	return (get_entry_table(Symtab.Globals, curr_global++));
525*7c478bd9Sstevel@tonic-gate }
526*7c478bd9Sstevel@tonic-gate 
527*7c478bd9Sstevel@tonic-gate /*
528*7c478bd9Sstevel@tonic-gate  * manually written functions for accessing tables of strings
529*7c478bd9Sstevel@tonic-gate  */
530*7c478bd9Sstevel@tonic-gate 
531*7c478bd9Sstevel@tonic-gate /*
532*7c478bd9Sstevel@tonic-gate  * symtab_add_print_types -- add only non-void print types (due to
533*7c478bd9Sstevel@tonic-gate  *	parser errors in collect.c, yuck). Also note trick compare...
534*7c478bd9Sstevel@tonic-gate  *	TBD : common code in db, symtab needs to be
535*7c478bd9Sstevel@tonic-gate  *	pulled out, as they're getting out of sync.
536*7c478bd9Sstevel@tonic-gate  */
537*7c478bd9Sstevel@tonic-gate void
538*7c478bd9Sstevel@tonic-gate symtab_add_print_types(char *print_type, char *c_type)
539*7c478bd9Sstevel@tonic-gate {
540*7c478bd9Sstevel@tonic-gate 	char	buffer[MAXLINE];
541*7c478bd9Sstevel@tonic-gate 
542*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_add_print_types() {");
543*7c478bd9Sstevel@tonic-gate #ifdef notdef
544*7c478bd9Sstevel@tonic-gate 	if (strcmp(print_type, "void") == 0 || *print_type == NULL) {
545*7c478bd9Sstevel@tonic-gate 		errlog(END, "}");
546*7c478bd9Sstevel@tonic-gate 		return;
547*7c478bd9Sstevel@tonic-gate 	}
548*7c478bd9Sstevel@tonic-gate #endif
549*7c478bd9Sstevel@tonic-gate 	(void) snprintf(buffer, sizeof (buffer), "%s, %s", print_type, c_type);
550*7c478bd9Sstevel@tonic-gate 	if (Symtab.Print_Types == NULL) {
551*7c478bd9Sstevel@tonic-gate 	Symtab.Print_Types = create_string_table(50);
552*7c478bd9Sstevel@tonic-gate 	}
553*7c478bd9Sstevel@tonic-gate 	if (in_string_table(Symtab.Print_Types, print_type) == NO) {
554*7c478bd9Sstevel@tonic-gate 		Symtab.Print_Types = add_string_table(Symtab.Print_Types,
555*7c478bd9Sstevel@tonic-gate 					&buffer[0]);
556*7c478bd9Sstevel@tonic-gate 	}
557*7c478bd9Sstevel@tonic-gate 	errlog(END, "}");
558*7c478bd9Sstevel@tonic-gate }
559*7c478bd9Sstevel@tonic-gate 
560*7c478bd9Sstevel@tonic-gate static table_t *
561*7c478bd9Sstevel@tonic-gate symtab_free_print_types(table_t *t)
562*7c478bd9Sstevel@tonic-gate {
563*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_free_print_types() {"); errlog(END, "}");
564*7c478bd9Sstevel@tonic-gate 	return (free_string_table(t));
565*7c478bd9Sstevel@tonic-gate }
566*7c478bd9Sstevel@tonic-gate 
567*7c478bd9Sstevel@tonic-gate 
568*7c478bd9Sstevel@tonic-gate static int curr_print_type;
569*7c478bd9Sstevel@tonic-gate 
570*7c478bd9Sstevel@tonic-gate char *
571*7c478bd9Sstevel@tonic-gate symtab_get_first_print_type(void)
572*7c478bd9Sstevel@tonic-gate {
573*7c478bd9Sstevel@tonic-gate 
574*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_get_first_print_type() {"); errlog(END, "}");
575*7c478bd9Sstevel@tonic-gate 	curr_print_type = 1;
576*7c478bd9Sstevel@tonic-gate 	return (get_string_table(Symtab.Print_Types, 0));
577*7c478bd9Sstevel@tonic-gate }
578*7c478bd9Sstevel@tonic-gate 
579*7c478bd9Sstevel@tonic-gate char *
580*7c478bd9Sstevel@tonic-gate symtab_get_next_print_type(void)
581*7c478bd9Sstevel@tonic-gate {
582*7c478bd9Sstevel@tonic-gate 
583*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_get_next_print_type() {"); errlog(END, "}");
584*7c478bd9Sstevel@tonic-gate 	return (get_string_table(Symtab.Print_Types, curr_print_type++));
585*7c478bd9Sstevel@tonic-gate }
586*7c478bd9Sstevel@tonic-gate 
587*7c478bd9Sstevel@tonic-gate void
588*7c478bd9Sstevel@tonic-gate symtab_add_includes(char *value)
589*7c478bd9Sstevel@tonic-gate {
590*7c478bd9Sstevel@tonic-gate 
591*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_add_includes() {");
592*7c478bd9Sstevel@tonic-gate 	if (Symtab.Includes == NULL) {
593*7c478bd9Sstevel@tonic-gate 		Symtab.Includes = create_string_table(50);
594*7c478bd9Sstevel@tonic-gate 	}
595*7c478bd9Sstevel@tonic-gate 	if (in_string_table(Symtab.Includes, value) == NO) {
596*7c478bd9Sstevel@tonic-gate 		Symtab.Includes = add_string_table(Symtab.Includes, value);
597*7c478bd9Sstevel@tonic-gate 	}
598*7c478bd9Sstevel@tonic-gate 	errlog(END, "}");
599*7c478bd9Sstevel@tonic-gate }
600*7c478bd9Sstevel@tonic-gate 
601*7c478bd9Sstevel@tonic-gate static int curr_include;
602*7c478bd9Sstevel@tonic-gate 
603*7c478bd9Sstevel@tonic-gate char *
604*7c478bd9Sstevel@tonic-gate symtab_get_first_include(void)
605*7c478bd9Sstevel@tonic-gate {
606*7c478bd9Sstevel@tonic-gate 
607*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_get_first_include() {"); errlog(END, "}");
608*7c478bd9Sstevel@tonic-gate 	curr_include = 1;
609*7c478bd9Sstevel@tonic-gate 	return (get_string_table(Symtab.Includes, 0));
610*7c478bd9Sstevel@tonic-gate }
611*7c478bd9Sstevel@tonic-gate 
612*7c478bd9Sstevel@tonic-gate char *
613*7c478bd9Sstevel@tonic-gate symtab_get_next_include(void)
614*7c478bd9Sstevel@tonic-gate {
615*7c478bd9Sstevel@tonic-gate 
616*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_get_next_include() {"); errlog(END, "}");
617*7c478bd9Sstevel@tonic-gate 	return (get_string_table(Symtab.Includes, curr_include++));
618*7c478bd9Sstevel@tonic-gate }
619*7c478bd9Sstevel@tonic-gate 
620*7c478bd9Sstevel@tonic-gate 
621*7c478bd9Sstevel@tonic-gate void
622*7c478bd9Sstevel@tonic-gate symtab_sort_includes(void)
623*7c478bd9Sstevel@tonic-gate {
624*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "symtab_sort_includes() {");
625*7c478bd9Sstevel@tonic-gate 	sort_string_table(Symtab.Includes);
626*7c478bd9Sstevel@tonic-gate 	errlog(END, "}");
627*7c478bd9Sstevel@tonic-gate }
628*7c478bd9Sstevel@tonic-gate 
629*7c478bd9Sstevel@tonic-gate /*
630*7c478bd9Sstevel@tonic-gate  * ENTRYs  -- access functions to contents of an entry.
631*7c478bd9Sstevel@tonic-gate  */
632*7c478bd9Sstevel@tonic-gate 
633*7c478bd9Sstevel@tonic-gate char *
634*7c478bd9Sstevel@tonic-gate name_of(ENTRY *e)
635*7c478bd9Sstevel@tonic-gate {
636*7c478bd9Sstevel@tonic-gate 	return (e->e_name);
637*7c478bd9Sstevel@tonic-gate }
638*7c478bd9Sstevel@tonic-gate 
639*7c478bd9Sstevel@tonic-gate int
640*7c478bd9Sstevel@tonic-gate validity_of(ENTRY *e)
641*7c478bd9Sstevel@tonic-gate {
642*7c478bd9Sstevel@tonic-gate 
643*7c478bd9Sstevel@tonic-gate 	if (e == NULL)
644*7c478bd9Sstevel@tonic-gate 		return (NO);
645*7c478bd9Sstevel@tonic-gate 	else
646*7c478bd9Sstevel@tonic-gate 		return (e->e_valid);
647*7c478bd9Sstevel@tonic-gate }
648*7c478bd9Sstevel@tonic-gate 
649*7c478bd9Sstevel@tonic-gate int
650*7c478bd9Sstevel@tonic-gate line_of(ENTRY *e)
651*7c478bd9Sstevel@tonic-gate {
652*7c478bd9Sstevel@tonic-gate 	return (e->e_line);
653*7c478bd9Sstevel@tonic-gate }
654*7c478bd9Sstevel@tonic-gate 
655*7c478bd9Sstevel@tonic-gate 
656*7c478bd9Sstevel@tonic-gate char *
657*7c478bd9Sstevel@tonic-gate file_of(ENTRY *e)
658*7c478bd9Sstevel@tonic-gate {
659*7c478bd9Sstevel@tonic-gate 	return (e->e_file);
660*7c478bd9Sstevel@tonic-gate }
661*7c478bd9Sstevel@tonic-gate 
662*7c478bd9Sstevel@tonic-gate /*
663*7c478bd9Sstevel@tonic-gate  * x_type_of -- return (type with an extension: an embedded %s where
664*7c478bd9Sstevel@tonic-gate  *	the name goes.
665*7c478bd9Sstevel@tonic-gate  */
666*7c478bd9Sstevel@tonic-gate char *
667*7c478bd9Sstevel@tonic-gate x_type_of(ENTRY *e)
668*7c478bd9Sstevel@tonic-gate {
669*7c478bd9Sstevel@tonic-gate 	if (e != NULL && (e->e_kind == PRIMITIVE || e->e_kind == VARARG))
670*7c478bd9Sstevel@tonic-gate 		return (e->e_type);
671*7c478bd9Sstevel@tonic-gate 	else
672*7c478bd9Sstevel@tonic-gate 		return (NULL);
673*7c478bd9Sstevel@tonic-gate }
674*7c478bd9Sstevel@tonic-gate 
675*7c478bd9Sstevel@tonic-gate 
676*7c478bd9Sstevel@tonic-gate /*
677*7c478bd9Sstevel@tonic-gate  * type_of -- return (just the type, with the %s removed. This is the common
678*7c478bd9Sstevel@tonic-gate  *	case, and its also the slowest... TBD.
679*7c478bd9Sstevel@tonic-gate  */
680*7c478bd9Sstevel@tonic-gate char *
681*7c478bd9Sstevel@tonic-gate type_of(ENTRY *e)
682*7c478bd9Sstevel@tonic-gate {
683*7c478bd9Sstevel@tonic-gate 	static char buffer[MAXLINE];
684*7c478bd9Sstevel@tonic-gate 	char	*p, *q;
685*7c478bd9Sstevel@tonic-gate 
686*7c478bd9Sstevel@tonic-gate 	if (e != NULL && (e->e_kind == PRIMITIVE || e->e_kind == VARARG)) {
687*7c478bd9Sstevel@tonic-gate 		p = e->e_type;
688*7c478bd9Sstevel@tonic-gate 		q = &buffer[0];
689*7c478bd9Sstevel@tonic-gate 		while (*p != NULL) {
690*7c478bd9Sstevel@tonic-gate 			if (*p == '%') {
691*7c478bd9Sstevel@tonic-gate 				p += 2;
692*7c478bd9Sstevel@tonic-gate 			} else {
693*7c478bd9Sstevel@tonic-gate 				*q++ = *p++;
694*7c478bd9Sstevel@tonic-gate 			}
695*7c478bd9Sstevel@tonic-gate 		}
696*7c478bd9Sstevel@tonic-gate 		*q = NULL;
697*7c478bd9Sstevel@tonic-gate 		return (strtrim(&buffer[0]));
698*7c478bd9Sstevel@tonic-gate 	}
699*7c478bd9Sstevel@tonic-gate 	else
700*7c478bd9Sstevel@tonic-gate 		return (NULL);
701*7c478bd9Sstevel@tonic-gate }
702*7c478bd9Sstevel@tonic-gate 
703*7c478bd9Sstevel@tonic-gate char *
704*7c478bd9Sstevel@tonic-gate basetype_of(ENTRY *e)
705*7c478bd9Sstevel@tonic-gate {
706*7c478bd9Sstevel@tonic-gate 	if (e != NULL && (e->e_kind == PRIMITIVE || e->e_kind == VARARG))
707*7c478bd9Sstevel@tonic-gate 		return (e->e_basetype);
708*7c478bd9Sstevel@tonic-gate 	else
709*7c478bd9Sstevel@tonic-gate 		return (NULL);
710*7c478bd9Sstevel@tonic-gate }
711*7c478bd9Sstevel@tonic-gate 
712*7c478bd9Sstevel@tonic-gate int
713*7c478bd9Sstevel@tonic-gate levels_of(ENTRY *e)
714*7c478bd9Sstevel@tonic-gate {
715*7c478bd9Sstevel@tonic-gate 	if (e != NULL && (e->e_kind == PRIMITIVE || e->e_kind == VARARG))
716*7c478bd9Sstevel@tonic-gate 		return (e->e_levels);
717*7c478bd9Sstevel@tonic-gate 	else
718*7c478bd9Sstevel@tonic-gate 		return (NULL);
719*7c478bd9Sstevel@tonic-gate }
720*7c478bd9Sstevel@tonic-gate 
721*7c478bd9Sstevel@tonic-gate char *
722*7c478bd9Sstevel@tonic-gate inverse_of(ENTRY *e)
723*7c478bd9Sstevel@tonic-gate {
724*7c478bd9Sstevel@tonic-gate 
725*7c478bd9Sstevel@tonic-gate 	if (e != NULL && e->e_kind == COMPOSITE)
726*7c478bd9Sstevel@tonic-gate 		return (e->e_attribute);
727*7c478bd9Sstevel@tonic-gate 	else
728*7c478bd9Sstevel@tonic-gate 		return (NULL);
729*7c478bd9Sstevel@tonic-gate }
730*7c478bd9Sstevel@tonic-gate 
731*7c478bd9Sstevel@tonic-gate char *
732*7c478bd9Sstevel@tonic-gate selector_of(ENTRY *e)
733*7c478bd9Sstevel@tonic-gate {
734*7c478bd9Sstevel@tonic-gate 
735*7c478bd9Sstevel@tonic-gate 	if (e != NULL && e->e_kind == VARARG)
736*7c478bd9Sstevel@tonic-gate 		return (e->e_attribute);
737*7c478bd9Sstevel@tonic-gate 	else
738*7c478bd9Sstevel@tonic-gate 		return (NULL);
739*7c478bd9Sstevel@tonic-gate }
740*7c478bd9Sstevel@tonic-gate 
741*7c478bd9Sstevel@tonic-gate int
742*7c478bd9Sstevel@tonic-gate preuses_of(ENTRY *e)
743*7c478bd9Sstevel@tonic-gate {
744*7c478bd9Sstevel@tonic-gate 
745*7c478bd9Sstevel@tonic-gate 	if (e)
746*7c478bd9Sstevel@tonic-gate 		return (e->e_pre_uses);
747*7c478bd9Sstevel@tonic-gate 	else
748*7c478bd9Sstevel@tonic-gate 		return (-1);
749*7c478bd9Sstevel@tonic-gate }
750*7c478bd9Sstevel@tonic-gate 
751*7c478bd9Sstevel@tonic-gate int
752*7c478bd9Sstevel@tonic-gate postuses_of(ENTRY *e)
753*7c478bd9Sstevel@tonic-gate {
754*7c478bd9Sstevel@tonic-gate 
755*7c478bd9Sstevel@tonic-gate 	if (e)
756*7c478bd9Sstevel@tonic-gate 		return (e->e_post_uses);
757*7c478bd9Sstevel@tonic-gate 	else
758*7c478bd9Sstevel@tonic-gate 		return (-1);
759*7c478bd9Sstevel@tonic-gate }
760*7c478bd9Sstevel@tonic-gate 
761*7c478bd9Sstevel@tonic-gate 
762*7c478bd9Sstevel@tonic-gate /*
763*7c478bd9Sstevel@tonic-gate  * allocate_entry -- make a parameter list into a complete
764*7c478bd9Sstevel@tonic-gate  *	ENTRY struct, allocated dynamically.
765*7c478bd9Sstevel@tonic-gate  */
766*7c478bd9Sstevel@tonic-gate 	/* ARGSUSED -- lint bug */
767*7c478bd9Sstevel@tonic-gate static ENTRY *
768*7c478bd9Sstevel@tonic-gate allocate_entry(ENTRY *e,
769*7c478bd9Sstevel@tonic-gate     char *name, int line, char *file,
770*7c478bd9Sstevel@tonic-gate     int kind, char *type, char *basetype, int levels, char *attribute,
771*7c478bd9Sstevel@tonic-gate     int npre, int npost)
772*7c478bd9Sstevel@tonic-gate {
773*7c478bd9Sstevel@tonic-gate 
774*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "allocate_entry() {");
775*7c478bd9Sstevel@tonic-gate 	if (e == NULL) {
776*7c478bd9Sstevel@tonic-gate 		if ((e = (ENTRY *)calloc(1, sizeof (ENTRY))) == NULL) {
777*7c478bd9Sstevel@tonic-gate 			errlog(FATAL, "can't allocate space for an ENTRY");
778*7c478bd9Sstevel@tonic-gate 		}
779*7c478bd9Sstevel@tonic-gate 	}
780*7c478bd9Sstevel@tonic-gate 	errlog(END, "}");
781*7c478bd9Sstevel@tonic-gate 	return (set_entry(e, name, line, file, kind, type, basetype, levels,
782*7c478bd9Sstevel@tonic-gate 			attribute, npre, npost));
783*7c478bd9Sstevel@tonic-gate }
784*7c478bd9Sstevel@tonic-gate 
785*7c478bd9Sstevel@tonic-gate /*
786*7c478bd9Sstevel@tonic-gate  * set_entry -- set a passed-in entry, using
787*7c478bd9Sstevel@tonic-gate  *	passed parameters, to values suitable for a
788*7c478bd9Sstevel@tonic-gate  *	symtab entry
789*7c478bd9Sstevel@tonic-gate  */
790*7c478bd9Sstevel@tonic-gate static ENTRY *
791*7c478bd9Sstevel@tonic-gate set_entry(ENTRY *e,
792*7c478bd9Sstevel@tonic-gate     char *name, int line, char *file,
793*7c478bd9Sstevel@tonic-gate     int kind, char *type, char *basetype, int levels, char *attribute,
794*7c478bd9Sstevel@tonic-gate     int npre, int npost)
795*7c478bd9Sstevel@tonic-gate {
796*7c478bd9Sstevel@tonic-gate 
797*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "set_entry() {");
798*7c478bd9Sstevel@tonic-gate 	if (e == NULL) {
799*7c478bd9Sstevel@tonic-gate 		errlog(FATAL, "programmer error: passed a NULL ENTRY");
800*7c478bd9Sstevel@tonic-gate 	}
801*7c478bd9Sstevel@tonic-gate 	e->e_name = strset(e->e_name, name);
802*7c478bd9Sstevel@tonic-gate 	e->e_valid = YES;
803*7c478bd9Sstevel@tonic-gate 	e->e_line = line,
804*7c478bd9Sstevel@tonic-gate 	e->e_file = strset(e->e_file, file);
805*7c478bd9Sstevel@tonic-gate 	e->e_kind = kind;
806*7c478bd9Sstevel@tonic-gate 	switch (kind) {
807*7c478bd9Sstevel@tonic-gate 	case PRIMITIVE:
808*7c478bd9Sstevel@tonic-gate 		e->e_type = strset(e->e_type, type);
809*7c478bd9Sstevel@tonic-gate 		e->e_basetype = strset(e->e_basetype, basetype);
810*7c478bd9Sstevel@tonic-gate 		e->e_levels = levels;
811*7c478bd9Sstevel@tonic-gate 		break;
812*7c478bd9Sstevel@tonic-gate 	case COMPOSITE:
813*7c478bd9Sstevel@tonic-gate 		e->e_attribute = strset(e->e_attribute, attribute);
814*7c478bd9Sstevel@tonic-gate 		break;
815*7c478bd9Sstevel@tonic-gate 	case VARARG:
816*7c478bd9Sstevel@tonic-gate 		e->e_attribute = strset(e->e_attribute, attribute);
817*7c478bd9Sstevel@tonic-gate 		break;
818*7c478bd9Sstevel@tonic-gate 	default:
819*7c478bd9Sstevel@tonic-gate 		errlog(FATAL, "programmer error: impossible kind of ENTRY");
820*7c478bd9Sstevel@tonic-gate 	}
821*7c478bd9Sstevel@tonic-gate 
822*7c478bd9Sstevel@tonic-gate 	e->e_pre_uses = npre;
823*7c478bd9Sstevel@tonic-gate 	e->e_post_uses = npost;
824*7c478bd9Sstevel@tonic-gate 	errlog(END, "}");
825*7c478bd9Sstevel@tonic-gate 	return (e);
826*7c478bd9Sstevel@tonic-gate }
827*7c478bd9Sstevel@tonic-gate 
828*7c478bd9Sstevel@tonic-gate 
829*7c478bd9Sstevel@tonic-gate /*
830*7c478bd9Sstevel@tonic-gate  * free_entry -- really just mark an entry as invalid
831*7c478bd9Sstevel@tonic-gate  */
832*7c478bd9Sstevel@tonic-gate static ENTRY *
833*7c478bd9Sstevel@tonic-gate free_entry(ENTRY *e)
834*7c478bd9Sstevel@tonic-gate {
835*7c478bd9Sstevel@tonic-gate 	if (e != NULL)
836*7c478bd9Sstevel@tonic-gate 		e->e_valid = NO;
837*7c478bd9Sstevel@tonic-gate 	return (e);
838*7c478bd9Sstevel@tonic-gate }
839*7c478bd9Sstevel@tonic-gate 
840*7c478bd9Sstevel@tonic-gate 
841*7c478bd9Sstevel@tonic-gate /*
842*7c478bd9Sstevel@tonic-gate  * ENTRY tables.
843*7c478bd9Sstevel@tonic-gate  */
844*7c478bd9Sstevel@tonic-gate #define	ENTRY_INCREMENT 10
845*7c478bd9Sstevel@tonic-gate 
846*7c478bd9Sstevel@tonic-gate static EHEAD *
847*7c478bd9Sstevel@tonic-gate create_entry_table(int n)
848*7c478bd9Sstevel@tonic-gate {
849*7c478bd9Sstevel@tonic-gate 	EHEAD	*p;
850*7c478bd9Sstevel@tonic-gate 
851*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "create_entry_table() {");
852*7c478bd9Sstevel@tonic-gate 	if ((p = (EHEAD *)calloc(1,
853*7c478bd9Sstevel@tonic-gate 	    sizeof (EHEAD)+(n*sizeof (ENTRY)))) == NULL) {
854*7c478bd9Sstevel@tonic-gate 		errlog(FATAL, "can't allocate space for an ENTRY table");
855*7c478bd9Sstevel@tonic-gate 	}
856*7c478bd9Sstevel@tonic-gate 	p->used = -1;
857*7c478bd9Sstevel@tonic-gate 	p->n_entries = n;
858*7c478bd9Sstevel@tonic-gate 	errlog(END, "}");
859*7c478bd9Sstevel@tonic-gate 	return (p);
860*7c478bd9Sstevel@tonic-gate }
861*7c478bd9Sstevel@tonic-gate 
862*7c478bd9Sstevel@tonic-gate static EHEAD *
863*7c478bd9Sstevel@tonic-gate add_entry_table(EHEAD *t, char *name, int line, char *file,
864*7c478bd9Sstevel@tonic-gate     int kind, char *type, char *basetype, int levels, char *attribute,
865*7c478bd9Sstevel@tonic-gate     int npre, int npost)
866*7c478bd9Sstevel@tonic-gate {
867*7c478bd9Sstevel@tonic-gate 	EHEAD	*t2;
868*7c478bd9Sstevel@tonic-gate 
869*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "add_entry_table() {");
870*7c478bd9Sstevel@tonic-gate 	if (t == NULL) {
871*7c478bd9Sstevel@tonic-gate 		errlog(FATAL, "programmer error: tried to add to NULL EHEAD");
872*7c478bd9Sstevel@tonic-gate 	}
873*7c478bd9Sstevel@tonic-gate 	t->used++;
874*7c478bd9Sstevel@tonic-gate 	if (t->used >= t->n_entries) {
875*7c478bd9Sstevel@tonic-gate 		if ((t2 = (EHEAD *)realloc(t,
876*7c478bd9Sstevel@tonic-gate 			sizeof (EHEAD)+(sizeof (ENTRY)*
877*7c478bd9Sstevel@tonic-gate 				(t->n_entries+ENTRY_INCREMENT)))) == NULL) {
878*7c478bd9Sstevel@tonic-gate 			errlog(FATAL, "out of memory extending an EHEAD");
879*7c478bd9Sstevel@tonic-gate 		}
880*7c478bd9Sstevel@tonic-gate 		t = t2;
881*7c478bd9Sstevel@tonic-gate 		clear_entries(t, t->n_entries, (t->n_entries+ENTRY_INCREMENT));
882*7c478bd9Sstevel@tonic-gate 		t->n_entries += ENTRY_INCREMENT;
883*7c478bd9Sstevel@tonic-gate 	}
884*7c478bd9Sstevel@tonic-gate 	(void) set_entry(&t->entry[t->used],
885*7c478bd9Sstevel@tonic-gate 	    name, line, file, kind, type, basetype, levels,
886*7c478bd9Sstevel@tonic-gate 	    attribute, npre, npost);
887*7c478bd9Sstevel@tonic-gate 	errlog(END, "}");
888*7c478bd9Sstevel@tonic-gate 	return (t);
889*7c478bd9Sstevel@tonic-gate }
890*7c478bd9Sstevel@tonic-gate 
891*7c478bd9Sstevel@tonic-gate static ENTRY *
892*7c478bd9Sstevel@tonic-gate get_entry_table(EHEAD *t, int index)
893*7c478bd9Sstevel@tonic-gate {
894*7c478bd9Sstevel@tonic-gate 	if (t == NULL)  {
895*7c478bd9Sstevel@tonic-gate 		return (NULL);
896*7c478bd9Sstevel@tonic-gate 	} else if (index > t->used) {
897*7c478bd9Sstevel@tonic-gate 		return (NULL);
898*7c478bd9Sstevel@tonic-gate 	} else {
899*7c478bd9Sstevel@tonic-gate 		return (&(t->entry[index]));
900*7c478bd9Sstevel@tonic-gate 	}
901*7c478bd9Sstevel@tonic-gate }
902*7c478bd9Sstevel@tonic-gate 
903*7c478bd9Sstevel@tonic-gate static EHEAD *
904*7c478bd9Sstevel@tonic-gate free_entry_table(EHEAD *t)
905*7c478bd9Sstevel@tonic-gate {
906*7c478bd9Sstevel@tonic-gate 	if (t != NULL)
907*7c478bd9Sstevel@tonic-gate 		t->used = -1;
908*7c478bd9Sstevel@tonic-gate 	return (t);
909*7c478bd9Sstevel@tonic-gate }
910*7c478bd9Sstevel@tonic-gate 
911*7c478bd9Sstevel@tonic-gate static void
912*7c478bd9Sstevel@tonic-gate clear_entries(EHEAD *t, int start, int end)
913*7c478bd9Sstevel@tonic-gate {
914*7c478bd9Sstevel@tonic-gate 	int	i;
915*7c478bd9Sstevel@tonic-gate 
916*7c478bd9Sstevel@tonic-gate 	for (i = start; i < end; i++) {
917*7c478bd9Sstevel@tonic-gate 		(void) memset(&t->entry[i], 0, sizeof (ENTRY));
918*7c478bd9Sstevel@tonic-gate 	}
919*7c478bd9Sstevel@tonic-gate }
920