xref: /netbsd/external/bsd/pcc/dist/pcc/cc/cpp/cpp.h (revision 6935091c)
1 /*	Id: cpp.h,v 1.90 2016/02/06 09:39:21 ragge Exp 	*/
2 /*	$NetBSD: cpp.h,v 1.1.1.7 2016/02/09 20:28:42 plunky Exp $	*/
3 
4 /*
5  * Copyright (c) 2004,2010 Anders Magnusson (ragge@ludd.luth.se).
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include <stdio.h>	/* for debug/printf */
30 
31 typedef unsigned char usch;
32 extern usch *stringbuf;
33 
34 extern	int	trulvl;
35 extern	int	flslvl;
36 extern	int	elflvl;
37 extern	int	elslvl;
38 extern	int	dflag;
39 extern	int	tflag, Aflag, Cflag, Pflag;
40 extern	int	Mflag, dMflag, MPflag, MMDflag;
41 extern	char	*Mfile, *MPfile;
42 extern	int	defining;
43 extern	FILE	*of;
44 
45 /* args for lookup() */
46 #define FIND    0
47 #define ENTER   1
48 
49 /* buffer used internally */
50 #ifndef CPPBUF
51 #if defined(mach_pdp11)
52 #define CPPBUF  BUFSIZ
53 #define	BUF_STACK
54 #else
55 #define CPPBUF	16384
56 #endif
57 #endif
58 
59 #define	MAXARGS	128	/* Max # of args to a macro. Should be enough */
60 
61 #define	PBMAX	10	/* min pushbackbuffer size */
62 #define	BBUFSZ	(PBMAX+CPPBUF+1)
63 
64 #define	CTRLOC	0xf8	/* __COUNTER__ */
65 #define	DEFLOC	0xf9	/* defined */
66 #define	PRAGLOC	0xfa	/* _Pragma */
67 #define	LINLOC	0xfb	/* __LINE__ */
68 #define	FILLOC	0xfc	/* __FILE__ */
69 #define GCCARG	0xfd	/* has gcc varargs that may be replaced with 0 */
70 #define VARG	0xfe	/* has varargs */
71 #define OBJCT	0xff
72 #define WARN	1	/* SOH, not legal char */
73 #define CONC	2	/* STX, not legal char */
74 #define SNUFF	3	/* ETX, not legal char */
75 #define	BLKID	4	/* EOT, not legal char */
76 
77 /* Used in macro expansion */
78 #define RECMAX	10000			/* max # of recursive macros */
79 #define	MKB(l,h)	(l+((h)<<8))
80 
81 /* quick checks for some characters */
82 #define C_SPEC	0001		/* for fastscan() parsing */
83 #define C_2	0002		/* for yylex() tokenizing */
84 #define C_WSNL	0004		/* ' ','\t','\r','\n' */
85 #define C_ID	0010		/* [_a-zA-Z0-9] */
86 #define C_ID0	0020		/* [_a-zA-Z] */
87 #define C_EP	0040		/* [epEP] */
88 #define C_DIGIT	0100		/* [0-9] */
89 #define C_HEX	0200		/* [0-9a-fA-F] */
90 
91 extern usch spechr[];
92 
93 #define ISWSNL(x)	(spechr[x] & (C_WSNL))
94 #define ISWS(x)		((x) == '\t' || (x) == ' ')
95 #define ISID(x)		(spechr[x] & C_ID)
96 #define ISID0(x)	(spechr[x] & C_ID0)
97 #define	ISDIGIT(x)	(spechr[x] & C_DIGIT)
98 
99 /*
100  * definition for include file info
101  */
102 struct includ {
103 	struct includ *next;
104 	const usch *fname;	/* current fn, changed if #line found */
105 	const usch *orgfn;	/* current fn, not changed */
106 	int lineno;
107 	int escln;		/* escaped newlines, to be added */
108 	int infil;
109 	usch *curptr;
110 	usch *maxread;
111 	usch *ostr;
112 	usch *buffer;
113 	int idx;
114 	void *incs;
115 	const usch *fn;
116 #ifdef BUF_STACK
117 	usch bbuf[BBUFSZ];
118 #else
119 	usch *bbuf;
120 #endif
121 };
122 #define INCINC 0
123 #define SYSINC 1
124 
125 extern struct includ *ifiles;
126 
127 /* Symbol table entry  */
128 struct symtab {
129 	const usch *namep;
130 	const usch *value;
131 	const usch *file;
132 	int line;
133 };
134 
135 struct initar {
136 	struct initar *next;
137 	int type;
138 	char *str;
139 };
140 
141 /* buffer definition */
142 struct iobuf {
143 	usch *buf;
144 	usch *cptr;
145 	usch *bsz;
146 	int ro:1, inuse:1;
147 };
148 extern struct iobuf *obufp;
149 extern struct iobuf *ibufp;
150 
151 /*
152  * Struct used in parse tree evaluation.
153  * op is one of:
154  *	- number type (NUMBER, UNUMBER)
155  *	- zero (0) if divided by zero.
156  */
157 struct nd {
158 	int op;
159 	union {
160 		long long val;
161 		unsigned long long uval;
162 	} n;
163 };
164 extern struct nd yynode;
165 
166 #define nd_val n.val
167 #define nd_uval n.uval
168 
169 enum { NUMBER = 257, UNUMBER, LS, RS, EQ, NE, STRING, WSPACE, CMNT, IDENT,
170 	OROR, ANDAND, DEFINED, LE, GE };
171 
172 #define	SLO_IGNOREWS	001
173 
174 struct symtab *lookup(const usch *namep, int enterf);
175 struct blocker;
176 struct iobuf *submac(struct symtab *nl, int, struct iobuf *, struct blocker *);
177 int kfind(struct symtab *nl);
178 void ppdir(void);
179 
180 void define(void);
181 void include(void);
182 void include_next(void);
183 void line(void);
184 
185 int pushfile(const usch *fname, const usch *fn, int idx, void *incs);
186 void prtline(int nl);
187 int yylex(void);
188 void cunput(int);
189 int yyparse(void);
190 usch *savstr(const usch *str);
191 void savch(int c);
192 void putch(int);
193 void putstr(const usch *s);
194 usch *sheap(const char *fmt, ...);
195 void warning(const char *fmt, ...);
196 void error(const char *fmt, ...);
197 int cinput(void);
198 int inc2(void);
199 int Ccmnt(void (*d)(int));
200 usch *heapid(int ch);
201 void faststr(int bc, void (*d)(int));
202 int fastnum(int ch, void (*d)(int));
203 
204 
205