xref: /titanic_41/usr/src/cmd/sgs/yacc/common/dextern.h (revision 5fbb41393be5d63f75952b1d72d4df2642d22557)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /* Copyright (c) 1988 AT&T */
27 /* All Rights Reserved */
28 
29 #ifndef _DEXTERN_H
30 #define	_DEXTERN_H
31 
32 #pragma ident	"%Z%%M%	%I%	%E% SMI"
33 
34 #include <stdio.h>
35 #include <inttypes.h>
36 #include <ctype.h>
37 #include <memory.h>
38 #include <string.h>
39 #include <malloc.h>
40 #include <values.h>
41 #include <widec.h>
42 #include <unistd.h>
43 #include <stdlib.h>
44 #include <wctype.h>
45 
46 #ifdef	__cplusplus
47 extern "C" {
48 #endif
49 
50 	/*  MANIFEST CONSTANT DEFINITIONS */
51 #if u3b || u3b15 || u3b2 || vax || uts || sparc
52 #define	WORD32
53 #endif
54 #include <libintl.h>
55 
56 	/* base of nonterminal internal numbers */
57 
58 #define	NTBASE (10000000)
59 
60 	/* internal codes for error and accept actions */
61 
62 #define	ERRCODE  8190
63 #define	ACCEPTCODE 8191
64 
65 	/* sizes and limits */
66 
67 #define	ACTSIZE 4000
68 #define	MEMSIZE 2000
69 #define	PSTSIZE 1024
70 #define	NSTATES 1000
71 #define	NTERMS 127
72 #define	NPROD 300
73 #define	NNONTERM 600
74 #define	TEMPSIZE 800
75 #define	CNAMSZ 1000
76 #define	LSETSIZE 950
77 #define	WSETSIZE 850
78 
79 #define	NAMESIZE 50
80 #define	NTYPES 1000
81 
82 #define	NMBCHARSZ 100
83 #define	LKFACTOR 5
84 
85 #ifdef WORD32
86 	/* bit packing macros (may be machine dependent) */
87 #define	BIT(a, i) ((a)[(i)>>5] & (1<<((i)&037)))
88 #define	SETBIT(a, i) ((a)[(i)>>5] |= (1<<((i)&037)))
89 
90 	/* number of words needed to hold n+1 bits */
91 #define	NWORDS(n) (((n)+32)/32)
92 
93 #else
94 
95 	/* bit packing macros (may be machine dependent) */
96 #define	BIT(a, i) ((a)[(i)>>4] & (1<<((i)&017)))
97 #define	SETBIT(a, i) ((a)[(i)>>4] |= (1<<((i)&017)))
98 
99 	/* number of words needed to hold n+1 bits */
100 #define	NWORDS(n) (((n)+16)/16)
101 #endif
102 
103 	/*
104 	 * relationships which must hold:
105 	 * TBITSET ints must hold NTERMS+1 bits...
106 	 * WSETSIZE >= NNONTERM
107 	 * LSETSIZE >= NNONTERM
108 	 * TEMPSIZE >= NTERMS + NNONTERMs + 1
109 	 * TEMPSIZE >= NSTATES
110 	 */
111 
112 	/* associativities */
113 
114 #define	NOASC 0  /* no assoc. */
115 #define	LASC 1  /* left assoc. */
116 #define	RASC 2  /* right assoc. */
117 #define	BASC 3  /* binary assoc. */
118 
119 	/* flags for state generation */
120 
121 #define	DONE 0
122 #define	MUSTDO 1
123 #define	MUSTLOOKAHEAD 2
124 
125 	/* flags for a rule having an action, and being reduced */
126 
127 #define	ACTFLAG 04
128 #define	REDFLAG 010
129 
130 	/* output parser flags */
131 #define	YYFLAG1 (-10000000)
132 
133 	/* macros for getting associativity and precedence levels */
134 
135 #define	ASSOC(i) ((i)&07)
136 #define	PLEVEL(i) (((i)>>4)&077)
137 #define	TYPE(i)  ((i>>10)&077)
138 
139 	/* macros for setting associativity and precedence levels */
140 
141 #define	SETASC(i, j) i |= j
142 #define	SETPLEV(i, j) i |= (j<<4)
143 #define	SETTYPE(i, j) i |= (j<<10)
144 
145 	/* looping macros */
146 
147 #define	TLOOP(i) for (i = 1; i <= ntokens; ++i)
148 #define	NTLOOP(i) for (i = 0; i <= nnonter; ++i)
149 #define	PLOOP(s, i) for (i = s; i < nprod; ++i)
150 #define	SLOOP(i) for (i = 0; i < nstate; ++i)
151 #define	WSBUMP(x) ++x
152 #define	WSLOOP(s, j) for (j = s; j < &wsets[cwp]; ++j)
153 #define	ITMLOOP(i, p, q) q = pstate[i+1]; for (p = pstate[i]; p < q; ++p)
154 #define	SETLOOP(i) for (i = 0; i < tbitset; ++i)
155 
156 	/* I/O descriptors */
157 
158 extern FILE *finput;		/* input file */
159 extern FILE *faction;		/* file for saving actions */
160 extern FILE *fdefine;		/* file for #defines */
161 extern FILE *ftable;		/* y.tab.c file */
162 extern FILE *ftemp;		/* tempfile to pass 2 */
163 extern FILE *fdebug;		/* tempfile for two debugging info arrays */
164 extern FILE *foutput;		/* y.output file */
165 
166 	/* structure declarations */
167 
168 typedef struct looksets {
169 	int *lset;
170 } LOOKSETS;
171 
172 typedef struct item {
173 	int *pitem;
174 	LOOKSETS *look;
175 } ITEM;
176 
177 typedef struct toksymb {
178 	wchar_t *name;
179 	int value;
180 } TOKSYMB;
181 
182 typedef struct mbclit {
183 	wchar_t character;
184 	int tvalue; /* token issued for the character */
185 } MBCLIT;
186 
187 typedef struct ntsymb {
188 	wchar_t *name;
189 	int tvalue;
190 } NTSYMB;
191 
192 typedef struct wset {
193 	int *pitem;
194 	int flag;
195 	LOOKSETS ws;
196 } WSET;
197 
198 	/* token information */
199 
200 extern int ntokens;	/* number of tokens */
201 extern TOKSYMB *tokset;
202 extern int ntoksz;
203 
204 	/*
205 	 * multibyte (c > 255) character literals are
206 	 * handled as though they were tokens except
207 	 * that it generates a separate mapping table.
208 	 */
209 extern int nmbchars;	/* number of mb literals */
210 extern MBCLIT *mbchars;
211 extern int nmbcharsz;
212 
213 	/* nonterminal information */
214 
215 extern int nnonter;	/* the number of nonterminals */
216 extern NTSYMB *nontrst;
217 extern int nnontersz;
218 
219 	/* grammar rule information */
220 
221 extern int nprod;	/* number of productions */
222 extern int **prdptr;	/* pointers to descriptions of productions */
223 extern int *levprd;	/* contains production levels to break conflicts */
224 extern wchar_t *had_act; /* set if reduction has associated action code */
225 
226 	/* state information */
227 
228 extern int nstate;		/* number of states */
229 extern ITEM **pstate;	/* pointers to the descriptions of the states */
230 extern int *tystate;	/* contains type information about the states */
231 extern int *defact;	/* the default action of the state */
232 
233 extern int size;
234 
235 	/* lookahead set information */
236 
237 extern int TBITSET;
238 extern LOOKSETS *lkst;
239 extern int nolook;  /* flag to turn off lookahead computations */
240 
241 	/* working set information */
242 
243 extern WSET *wsets;
244 
245 	/* storage for productions */
246 
247 extern int *mem0;
248 extern int *mem;
249 extern int *tracemem;
250 extern int new_memsize;
251 
252 	/* storage for action table */
253 
254 extern int *amem;
255 extern int *memp;		/* next free action table position */
256 extern int *indgo;		/* index to the stored goto table */
257 extern int new_actsize;
258 
259 	/* temporary vector, indexable by states, terms, or ntokens */
260 
261 extern int *temp1;
262 extern int lineno; /* current line number */
263 
264 	/* statistics collection variables */
265 
266 extern int zzgoent;
267 extern int zzgobest;
268 extern int zzacent;
269 extern int zzexcp;
270 extern int zzrrconf;
271 extern int zzsrconf;
272 
273 	/* define external functions */
274 
275 extern void setup(int, char *[]);
276 extern void closure(int);
277 extern void output(void);
278 extern void aryfil(int *, int, int);
279 extern void error(char *, ...);
280 extern void warning(int, char *, ...);
281 extern void putitem(int *, LOOKSETS *);
282 extern void go2out(void);
283 extern void hideprod(void);
284 extern void callopt(void);
285 extern void warray(wchar_t *, int *, int);
286 extern wchar_t *symnam(int);
287 extern wchar_t *writem(int *);
288 extern void exp_mem(int);
289 extern void exp_act(int **);
290 extern int apack(int *, int);
291 extern int state(int);
292 extern void fprintf3(FILE *, const char *, const wchar_t *, const char *, ...);
293 extern void error3(const char *, const wchar_t *, const char *, ...);
294 
295 extern wchar_t *wscpy(wchar_t *, const wchar_t *);
296 extern size_t wslen(const wchar_t *);
297 extern int wscmp(const wchar_t *, const wchar_t *);
298 
299 
300 	/* yaccpar location */
301 
302 extern char *parser;
303 
304 	/* default settings for a number of macros */
305 
306 	/* name of yacc tempfiles */
307 
308 #ifndef TEMPNAME
309 #define	TEMPNAME "yacc.tmp"
310 #endif
311 
312 #ifndef ACTNAME
313 #define	ACTNAME "yacc.acts"
314 #endif
315 
316 #ifndef DEBUGNAME
317 #define	DEBUGNAME "yacc.debug"
318 #endif
319 
320 	/* command to clobber tempfiles after use */
321 
322 #ifndef ZAPFILE
323 #define	ZAPFILE(x) (void)unlink(x)
324 #endif
325 
326 #ifndef PARSER
327 #define	PARSER "/usr/share/lib/ccs/yaccpar"
328 #endif
329 
330 /*
331  * Lint is unable to properly handle formats with wide strings
332  * (e.g. %ws) and misdiagnoses them as being malformed.
333  * This macro is used to work around that, by substituting
334  * a pointer to a null string when compiled by lint. This
335  * trick works because lint is not able to evaluate the
336  * variable.
337  *
338  * When lint is able to handle %ws, it would be appropriate
339  * to come back through and remove the use of this macro.
340  */
341 #if defined(__lint)
342 static const char *lint_ws_fmt = "";
343 #define	WSFMT(_fmt) lint_ws_fmt
344 #else
345 #define	WSFMT(_fmt) _fmt
346 #endif
347 
348 #ifdef	__cplusplus
349 }
350 #endif
351 
352 #endif /* _DEXTERN_H */
353