dextern.h revision 6951:59445bec7ef4
1276478Sngie/*
2272343Sngie * CDDL HEADER START
3272343Sngie *
4272343Sngie * The contents of this file are subject to the terms of the
5272343Sngie * Common Development and Distribution License (the "License").
6272343Sngie * You may not use this file except in compliance with the License.
7272343Sngie *
8272343Sngie * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9272343Sngie * or http://www.opensolaris.org/os/licensing.
10272343Sngie * See the License for the specific language governing permissions
11272343Sngie * and limitations under the License.
12272343Sngie *
13272343Sngie * When distributing Covered Code, include this CDDL HEADER in each
14272343Sngie * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15272343Sngie * If applicable, add the following below this CDDL HEADER, with the
16272343Sngie * fields enclosed by brackets "[]" replaced with your own identifying
17272343Sngie * information: Portions Copyright [yyyy] [name of copyright owner]
18272343Sngie *
19272343Sngie * CDDL HEADER END
20272343Sngie */
21272343Sngie/*
22272343Sngie * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23272343Sngie * Use is subject to license terms.
24272343Sngie */
25272343Sngie
26272343Sngie/* Copyright (c) 1988 AT&T */
27272343Sngie/* All Rights Reserved */
28272343Sngie
29272343Sngie#ifndef _DEXTERN_H
30272343Sngie#define	_DEXTERN_H
31272343Sngie
32276478Sngie#pragma ident	"%Z%%M%	%I%	%E% SMI"
33272343Sngie
34272343Sngie#include <stdio.h>
35272343Sngie#include <inttypes.h>
36272343Sngie#include <ctype.h>
37272343Sngie#include <memory.h>
38272343Sngie#include <string.h>
39272343Sngie#include <malloc.h>
40272343Sngie#include <values.h>
41272343Sngie#include <widec.h>
42272343Sngie#include <unistd.h>
43272343Sngie#include <stdlib.h>
44276478Sngie#include <wctype.h>
45272343Sngie
46276478Sngie#ifdef	__cplusplus
47276478Sngieextern "C" {
48276478Sngie#endif
49272343Sngie
50272343Sngie	/*  MANIFEST CONSTANT DEFINITIONS */
51272343Sngie#if u3b || u3b15 || u3b2 || vax || uts || sparc
52272343Sngie#define	WORD32
53276478Sngie#endif
54276478Sngie#include <libintl.h>
55276478Sngie
56272343Sngie	/* base of nonterminal internal numbers */
57276478Sngie
58272343Sngie#define	NTBASE (10000000)
59272343Sngie
60272343Sngie	/* internal codes for error and accept actions */
61272343Sngie
62272343Sngie#define	ERRCODE  8190
63272343Sngie#define	ACCEPTCODE 8191
64272343Sngie
65272343Sngie	/* sizes and limits */
66272343Sngie
67272343Sngie#define	ACTSIZE 4000
68272343Sngie#define	MEMSIZE 2000
69272343Sngie#define	PSTSIZE 1024
70272343Sngie#define	NSTATES 1000
71272343Sngie#define	NTERMS 127
72272343Sngie#define	NPROD 300
73272343Sngie#define	NNONTERM 600
74272343Sngie#define	TEMPSIZE 800
75272343Sngie#define	CNAMSZ 1000
76272343Sngie#define	LSETSIZE 950
77272343Sngie#define	WSETSIZE 850
78272343Sngie
79272343Sngie#define	NAMESIZE 50
80272343Sngie#define	NTYPES 1000
81272343Sngie
82272343Sngie#define	NMBCHARSZ 100
83272343Sngie#define	LKFACTOR 5
84272343Sngie
85272343Sngie#ifdef WORD32
86272343Sngie	/* bit packing macros (may be machine dependent) */
87272343Sngie#define	BIT(a, i) ((a)[(i)>>5] & (1<<((i)&037)))
88272343Sngie#define	SETBIT(a, i) ((a)[(i)>>5] |= (1<<((i)&037)))
89272343Sngie
90276478Sngie	/* number of words needed to hold n+1 bits */
91276478Sngie#define	NWORDS(n) (((n)+32)/32)
92276478Sngie
93272343Sngie#else
94276478Sngie
95272343Sngie	/* bit packing macros (may be machine dependent) */
96272343Sngie#define	BIT(a, i) ((a)[(i)>>4] & (1<<((i)&017)))
97272343Sngie#define	SETBIT(a, i) ((a)[(i)>>4] |= (1<<((i)&017)))
98272343Sngie
99272343Sngie	/* number of words needed to hold n+1 bits */
100272343Sngie#define	NWORDS(n) (((n)+16)/16)
101272343Sngie#endif
102272343Sngie
103272343Sngie	/*
104272343Sngie	 * relationships which must hold:
105272343Sngie	 * TBITSET ints must hold NTERMS+1 bits...
106272343Sngie	 * WSETSIZE >= NNONTERM
107272343Sngie	 * LSETSIZE >= NNONTERM
108272343Sngie	 * TEMPSIZE >= NTERMS + NNONTERMs + 1
109272343Sngie	 * TEMPSIZE >= NSTATES
110272343Sngie	 */
111272343Sngie
112272343Sngie	/* associativities */
113272343Sngie
114272343Sngie#define	NOASC 0  /* no assoc. */
115272343Sngie#define	LASC 1  /* left assoc. */
116272343Sngie#define	RASC 2  /* right assoc. */
117272343Sngie#define	BASC 3  /* binary assoc. */
118272343Sngie
119272343Sngie	/* flags for state generation */
120272343Sngie
121272343Sngie#define	DONE 0
122272343Sngie#define	MUSTDO 1
123272343Sngie#define	MUSTLOOKAHEAD 2
124272343Sngie
125272343Sngie	/* flags for a rule having an action, and being reduced */
126272343Sngie
127272343Sngie#define	ACTFLAG 04
128272343Sngie#define	REDFLAG 010
129272343Sngie
130272343Sngie	/* output parser flags */
131272343Sngie#define	YYFLAG1 (-10000000)
132272343Sngie
133272343Sngie	/* macros for getting associativity and precedence levels */
134272343Sngie
135272343Sngie#define	ASSOC(i) ((i)&07)
136272343Sngie#define	PLEVEL(i) (((i)>>4)&077)
137272343Sngie#define	TYPE(i)  ((i>>10)&077)
138272343Sngie
139272343Sngie	/* macros for setting associativity and precedence levels */
140272343Sngie
141272343Sngie#define	SETASC(i, j) i |= j
142272343Sngie#define	SETPLEV(i, j) i |= (j<<4)
143272343Sngie#define	SETTYPE(i, j) i |= (j<<10)
144272343Sngie
145272343Sngie	/* looping macros */
146272343Sngie
147272343Sngie#define	TLOOP(i) for (i = 1; i <= ntokens; ++i)
148272343Sngie#define	NTLOOP(i) for (i = 0; i <= nnonter; ++i)
149272343Sngie#define	PLOOP(s, i) for (i = s; i < nprod; ++i)
150272343Sngie#define	SLOOP(i) for (i = 0; i < nstate; ++i)
151272343Sngie#define	WSBUMP(x) ++x
152272343Sngie#define	WSLOOP(s, j) for (j = s; j < &wsets[cwp]; ++j)
153272343Sngie#define	ITMLOOP(i, p, q) q = pstate[i+1]; for (p = pstate[i]; p < q; ++p)
154272343Sngie#define	SETLOOP(i) for (i = 0; i < tbitset; ++i)
155272343Sngie
156272343Sngie	/* I/O descriptors */
157272343Sngie
158272343Sngieextern FILE *finput;		/* input file */
159272343Sngieextern FILE *faction;		/* file for saving actions */
160272343Sngieextern FILE *fdefine;		/* file for #defines */
161272343Sngieextern FILE *ftable;		/* y.tab.c file */
162272343Sngieextern FILE *ftemp;		/* tempfile to pass 2 */
163272343Sngieextern FILE *fdebug;		/* tempfile for two debugging info arrays */
164272343Sngieextern FILE *foutput;		/* y.output file */
165272343Sngie
166	/* structure declarations */
167
168typedef struct looksets {
169	int *lset;
170} LOOKSETS;
171
172typedef struct item {
173	int *pitem;
174	LOOKSETS *look;
175} ITEM;
176
177typedef struct toksymb {
178	wchar_t *name;
179	int value;
180} TOKSYMB;
181
182typedef struct mbclit {
183	wchar_t character;
184	int tvalue; /* token issued for the character */
185} MBCLIT;
186
187typedef struct ntsymb {
188	wchar_t *name;
189	int tvalue;
190} NTSYMB;
191
192typedef struct wset {
193	int *pitem;
194	int flag;
195	LOOKSETS ws;
196} WSET;
197
198	/* token information */
199
200extern int ntokens;	/* number of tokens */
201extern TOKSYMB *tokset;
202extern 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	 */
209extern int nmbchars;	/* number of mb literals */
210extern MBCLIT *mbchars;
211extern int nmbcharsz;
212
213	/* nonterminal information */
214
215extern int nnonter;	/* the number of nonterminals */
216extern NTSYMB *nontrst;
217extern int nnontersz;
218
219	/* grammar rule information */
220
221extern int nprod;	/* number of productions */
222extern int **prdptr;	/* pointers to descriptions of productions */
223extern int *levprd;	/* contains production levels to break conflicts */
224extern wchar_t *had_act; /* set if reduction has associated action code */
225
226	/* state information */
227
228extern int nstate;		/* number of states */
229extern ITEM **pstate;	/* pointers to the descriptions of the states */
230extern int *tystate;	/* contains type information about the states */
231extern int *defact;	/* the default action of the state */
232
233extern int size;
234
235	/* lookahead set information */
236
237extern int TBITSET;
238extern LOOKSETS *lkst;
239extern int nolook;  /* flag to turn off lookahead computations */
240
241	/* working set information */
242
243extern WSET *wsets;
244
245	/* storage for productions */
246
247extern int *mem0;
248extern int *mem;
249extern int *tracemem;
250extern int new_memsize;
251
252	/* storage for action table */
253
254extern int *amem;
255extern int *memp;		/* next free action table position */
256extern int *indgo;		/* index to the stored goto table */
257extern int new_actsize;
258
259	/* temporary vector, indexable by states, terms, or ntokens */
260
261extern int *temp1;
262extern int lineno; /* current line number */
263
264	/* statistics collection variables */
265
266extern int zzgoent;
267extern int zzgobest;
268extern int zzacent;
269extern int zzexcp;
270extern int zzrrconf;
271extern int zzsrconf;
272
273	/* define external functions */
274
275extern void setup(int, char *[]);
276extern void closure(int);
277extern void output(void);
278extern void aryfil(int *, int, int);
279extern void error(char *, ...);
280extern void warning(int, char *, ...);
281extern void putitem(int *, LOOKSETS *);
282extern void go2out(void);
283extern void hideprod(void);
284extern void callopt(void);
285extern void warray(wchar_t *, int *, int);
286extern wchar_t *symnam(int);
287extern wchar_t *writem(int *);
288extern void exp_mem(int);
289extern void exp_act(int **);
290extern int apack(int *, int);
291extern int state(int);
292extern void fprintf3(FILE *, const char *, const wchar_t *, const char *, ...);
293extern void error3(const char *, const wchar_t *, const char *, ...);
294
295extern wchar_t *wscpy(wchar_t *, const wchar_t *);
296extern size_t wslen(const wchar_t *);
297extern int wscmp(const wchar_t *, const wchar_t *);
298
299
300	/* yaccpar location */
301
302extern 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)
342static 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