xref: /netbsd-src/external/bsd/pcc/dist/pcc/cc/cpp/cpp.h (revision 6a493d6bc668897c91594964a732d38505b70cbb)
1 /*	Id: cpp.h,v 1.55 2011/09/27 08:34:59 plunky Exp 	*/
2 /*	$NetBSD: cpp.h,v 1.1.1.5 2012/01/11 20:33:06 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 obuf */
30 #include <stdlib.h>
31 
32 #include "config.h"
33 
34 typedef unsigned char usch;
35 extern usch yytext[];
36 extern usch *stringbuf;
37 
38 extern	int	trulvl;
39 extern	int	flslvl;
40 extern	int	elflvl;
41 extern	int	elslvl;
42 extern	int	dflag;
43 extern	int	tflag, Cflag, Pflag;
44 extern	int	Mflag, dMflag;
45 extern	usch	*Mfile;
46 extern	int	ofd;
47 
48 /* args for lookup() */
49 #define FIND    0
50 #define ENTER   1
51 
52 /* buffer used internally */
53 #ifndef CPPBUF
54 #if defined(mach_pdp11)
55 #define CPPBUF  BUFSIZ
56 #define	BUF_STACK
57 #elif defined(os_win32)
58 /* winxp seems to fail > 26608 bytes */
59 #define CPPBUF	16384
60 #else
61 #define CPPBUF	(65536*2)
62 #endif
63 #endif
64 
65 #define	MAXARGS	128	/* Max # of args to a macro. Should be enough */
66 
67 #define	NAMEMAX	CPPBUF	/* currently pushbackbuffer */
68 #define	BBUFSZ	(NAMEMAX+CPPBUF+1)
69 
70 #define GCCARG	0xfd	/* has gcc varargs that may be replaced with 0 */
71 #define VARG	0xfe	/* has varargs */
72 #define OBJCT	0xff
73 #define WARN	1	/* SOH, not legal char */
74 #define CONC	2	/* STX, not legal char */
75 #define SNUFF	3	/* ETX, not legal char */
76 #define	EBLOCK	4	/* EOT, not legal char */
77 
78 /* Used in macro expansion */
79 #define RECMAX	10000			/* max # of recursive macros */
80 extern struct symtab *norep[RECMAX];
81 extern int norepptr;
82 extern unsigned short bptr[RECMAX];
83 extern int bidx;
84 #define	MKB(l,h)	(l+((h)<<8))
85 
86 /* quick checks for some characters */
87 #define C_SPEC	001
88 #define C_EP	002
89 #define C_ID	004
90 #define C_I	(C_SPEC|C_ID)
91 #define C_2	010		/* for yylex() tokenizing */
92 #define	C_WSNL	020		/* ' ','\t','\r','\n' */
93 #define	iswsnl(x) (spechr[x] & C_WSNL)
94 extern char spechr[];
95 
96 /* definition for include file info */
97 struct includ {
98 	struct includ *next;
99 	const usch *fname;	/* current fn, changed if #line found */
100 	const usch *orgfn;	/* current fn, not changed */
101 	int lineno;
102 	int infil;
103 	usch *curptr;
104 	usch *maxread;
105 	usch *ostr;
106 	usch *buffer;
107 	int idx;
108 	void *incs;
109 	const usch *fn;
110 #ifdef BUF_STACK
111 	usch bbuf[BBUFSZ];
112 #else
113 	usch *bbuf;
114 #endif
115 } *ifiles;
116 
117 /* Symbol table entry  */
118 struct symtab {
119 	const usch *namep;
120 	const usch *value;
121 	const usch *file;
122 	int line;
123 };
124 
125 struct initar {
126 	struct initar *next;
127 	int type;
128 	char *str;
129 };
130 
131 /*
132  * Struct used in parse tree evaluation.
133  * op is one of:
134  *	- number type (NUMBER, UNUMBER)
135  *	- zero (0) if divided by zero.
136  */
137 struct nd {
138 	int op;
139 	union {
140 		long long val;
141 		unsigned long long uval;
142 	} n;
143 };
144 
145 #define nd_val n.val
146 #define nd_uval n.uval
147 
148 struct symtab *lookup(const usch *namep, int enterf);
149 usch *gotident(struct symtab *nl);
150 int slow;	/* scan slowly for new tokens */
151 int defining;
152 int submac(struct symtab *nl, int);
153 int kfind(struct symtab *nl);
154 int doexp(void);
155 int donex(void);
156 void ppdir(void);
157 
158 void define(void);
159 void include(void);
160 void include_next(void);
161 void line(void);
162 
163 int pushfile(const usch *fname, const usch *fn, int idx, void *incs);
164 void popfile(void);
165 void prtline(void);
166 int yylex(void);
167 int sloscan(void);
168 void cunput(int);
169 int curline(void);
170 char *curfile(void);
171 void setline(int);
172 void setfile(char *);
173 int yyparse(void);
174 void yyerror(const char *);
175 void unpstr(const usch *);
176 usch *savstr(const usch *str);
177 void savch(int c);
178 void mainscan(void);
179 void putch(int);
180 void putstr(const usch *s);
181 void line(void);
182 usch *sheap(const char *fmt, ...);
183 void xwarning(usch *);
184 void xerror(usch *);
185 #ifdef HAVE_CPP_VARARG_MACRO_GCC
186 #define warning(...) xwarning(sheap(__VA_ARGS__))
187 #define error(...) xerror(sheap(__VA_ARGS__))
188 #else
189 #define warning printf
190 #define error printf
191 #endif
192 int cinput(void);
193 void getcmnt(void);
194