Debian Codegraph @

cc/cpp/cpp.h

raw symbols SCIP
1 /* $Id: cpp.h,v 1.121 2020/02/16 11:19:36 ragge Exp $ */
2
3 /*
4 * Copyright (c) 2004,2010 Anders Magnusson ([email protected]).
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #include <stdio.h> /* for debug/printf */
29 #if LIBVMF
30 #include <vmf.h>
31 #endif
32
33 typedef char usch;
34 #ifdef CHAR_UNSIGNED
35 #define SPECADD 0
36 #else
37 #define SPECADD 128
38 #endif
39
40 extern int trulvl;
41 extern int flslvl;
42 extern int elflvl;
43 extern int elslvl;
44 extern int dflag;
45 extern int tflag, Aflag, Cflag, Pflag;
46 extern int Mflag, dMflag, MPflag, MMDflag;
47 extern char *Mfile, *MPfile;
48 extern int defining, inclevel;
49 extern int escln; /* escaped newlines, to be added */
50
51 /* args for lookup() */
52 #define FIND 0
53 #define ENTER 1
54
55 /* buffer used internally */
56 #if SIZEOF_INT_P == 2 || LIBVMF
57 #define CPPL2 7
58 typedef unsigned short mvtyp;
59 #else
60 #define CPPL2 14
61 typedef unsigned int mvtyp;
62 #endif
63
64 #define CPPBUF (1 << CPPL2)
65 #if CPPBUF < 1024
66 #define MINBUF 1024 /* must be == BYTESPERSEG */
67 #else
68 #define MINBUF CPPBUF
69 #endif
70 #define VALPTR(x) ((x) & (MINBUF-1))
71 #define VALBUF(x) ((x) / MINBUF)
72 #define MKVAL(b, c) (((b) * MINBUF) + (c))
73
74 extern usch pbbeg[], *pbinp, *pbend;
75
76 #define MAXARGS 128 /* Max # of args to a macro. Should be enough */
77 #define MAXIDSZ 63 /* Max length of C99 identifier; 5.2.4.1 */
78
79 #define PBMAX 10 /* min pushbackbuffer size */
80
81 #define FUNLIKE 0
82 #define CTRLOC 1 /* __COUNTER__ */
83 #define DEFLOC 2 /* defined */
84 #define PRAGLOC 3 /* _Pragma */
85 #define LINLOC 4 /* __LINE__ */
86 #define FILLOC 5 /* __FILE__ */
87 #define OBJCT 6
88 #define VARG 7 /* has varargs */
89
90 /* The following must be > MAXARGS since they are following WARN */
91 #define C99ARG 253 /* C99 vararg */
92 #define GCCARG 254 /* gcc vararg that may be replaced with 0 */
93
94 #define WARN 1 /* SOH, not legal char */
95 #define CONC 2 /* STX, not legal char */
96 #define SNUFF 3 /* ETX, not legal char */
97 #define BLKID 4 /* EOT, not legal char */
98 #define BLKID2 5 /* ENQ, not legal char */
99
100 /* Used in macro expansion */
101 #define L2MAX 64 /* max index into blocker pages */
102 #define MKB(l,h) (l+((h)<<8))
103
104 /* quick checks for some characters */
105 #define C_SPEC 0001 /* for fastscan() parsing */
106 #define C_2 0002 /* for yylex() tokenizing */
107 #define C_WSNL 0004 /* [ \t\r\n] */
108 #define C_PACK 0010 /* [\0\\\?\r] */
109 #define C_ID (C_ID0|C_DIGIT) /* [_a-zA-Z0-9] */
110 #define C_ID0 0020 /* [_a-zA-Z] */
111 #define C_Q 0040 /* [\0/] */
112 #define C_DIGIT 0100 /* [0-9] */
113 #define C_ESTR 0200 /* [\0\n\\\'\"] */
114
115 extern short spechr[];
116
117 #define ISSPEC(x) ((SPECADD+spechr)[(int)(x)] & (C_SPEC))
118 #define ISC2(x) ((SPECADD+spechr)[(int)(x)] & (C_2))
119 #define ISWSNL(x) ((SPECADD+spechr)[(int)(x)] & (C_WSNL))
120 #define ISWS(x) ((x) == '\t' || (x) == ' ')
121 #define ISPACK(x) ((SPECADD+spechr)[(int)(x)] & C_PACK)
122 #define ISID(x) ((SPECADD+spechr)[(int)(x)] & C_ID)
123 #define ISID0(x) ((SPECADD+spechr)[(int)(x)] & C_ID0)
124 #define ISDIGIT(x) ((SPECADD+spechr)[(int)(x)] & C_DIGIT)
125 #define ISCQ(x) ((SPECADD+spechr)[(int)(x)] & C_Q)
126 #define ISESTR(x) ((SPECADD+spechr)[(int)(x)] & C_ESTR)
127
128 /* buffer definition */
129 #define BNORMAL 0 /* standard buffer */
130 #define BMAC 1 /* store macro definitions */
131 #define BINBUF 2 /* read data from input files */
132 #define BUTBUF 3 /* write data to stdout */
133 struct iobuf {
134 usch *buf;
135 int cptr; /* current pointer */
136 int bsz; /* bufsize */
137 int ro:1, inuse:1, type:4;
138 };
139 struct iobuf *getobuf(int);
140 void putob(struct iobuf *ob, int ch);
141 void bufree(struct iobuf *iob);
142
143 #define curptr ib->cptr
144 #define maxread ib->bsz
145 #define buffer ib->buf+PBMAX
146 #define bbuf ib->buf
147
148 #if LIBVMF
149 extern struct vspace ibspc, macspc;
150 #endif
151
152 /*
153 * definition for include file info
154 */
155 struct includ {
156 struct includ *next;
157 const usch *fname; /* current fn, changed if #line found */
158 const usch *orgfn; /* current fn, not changed */
159 int lineno;
160 int infil;
161 int opend, oinp;
162 usch *opbeg;
163 int idx;
164 void *incs;
165 const usch *fn;
166 #if LIBVMF
167 struct vseg *vseg;
168 #endif
169 };
170 #define INCINC 0
171 #define SYSINC 1
172
173 extern struct includ *ifiles;
174 extern usch *pbeg, *pend, *outp, *inp;
175
176 /* Symbol table entry */
177 struct symtab {
178 const usch *namep;
179 mvtyp valoff;
180 const usch *file;
181 int line;
182 char type:4, /* macro type */
183 wraps:1; /* macro wraps in buffer */
184 unsigned char narg; /* # of args (if feasible) */
185 };
186
187 /*
188 * Struct used in parse tree evaluation.
189 * op is one of:
190 * - number type (NUMBER, UNUMBER)
191 * - zero (0) if divided by zero.
192 */
193 struct nd {
194 int op;
195 union {
196 long long val;
197 unsigned long long uval;
198 struct iobuf *ob;
199 } n;
200 };
201 extern struct nd yynode;
202
203 #define nd_val n.val
204 #define nd_uval n.uval
205 #define nd_ob n.ob
206
207 enum { NUMBER = 257, UNUMBER, LS, RS, EQ, NE, STRING, WSPACE, CMNT, IDENT,
208 OROR, ANDAND, DEFINED, LE, GE };
209
210 #define SLO_IGNOREWS 001
211
212 struct symtab *lookup(const usch *namep, int enterf);
213 struct blocker;
214 struct iobuf *submac(struct symtab *nl, int, struct iobuf *, int);
215 struct iobuf *kfind(struct symtab *nl);
216 void ppdir(void);
217
218 void define(void);
219 void include(void);
220 void include_next(void);
221 void line(void);
222
223 void pushfile(const usch *fname, const usch *fn, int idx, void *incs);
224 void prtline(int nl);
225 int yylex(void);
226 void cunput(int);
227 int yyparse(void);
228 void putch(int);
229 void putstr(const usch *s);
230 usch *sheap(const char *fmt, ...);
231 struct iobuf *bsheap(struct iobuf *, const char *fmt, ...);
232 struct iobuf *strtobuf(const usch *str, struct iobuf *iob);
233 struct iobuf *buftobuf(struct iobuf *in, struct iobuf *iob);
234 void warning(const char *fmt, ...);
235 void error(const char *fmt, ...);
236 int cinput(void);
237 int inc2(void);
238 void Ccmnt2(struct iobuf *, int);
239 usch *bufid(int ch, struct iobuf *);
240 usch *readid(int ch);
241 void faststr(int bc, struct iobuf *);
242 void *xrealloc(void *p, int sz);
243 void *xmalloc(int sz);
244 void fastscan(void);
245 void cntline(void);
246 int inpbuf(void);