Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:plunky:20120422210740

Diff

Diff from 1.111 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/pcc/pcc/cc/ccom/scan.l

Annotated File View

ragge
1.1
1 %{
plunky
1.111
2 /*      $Id: scan.l,v 1.111 2012/04/22 21:07:41 plunky Exp $    */
ragge
1.1
3
4 /*
5  * Copyright (c) 2002 Anders Magnusson. 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  * 3. The name of the author may not be used to endorse or promote products
16  *    derived from this software without specific prior written permission
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 %}
30
31
32 D                       [0-9]
33 L                       [a-zA-Z_]
34 H                       [a-fA-F0-9]
35 E                       [Ee][+-]?{D}+
ragge
1.56
36 P                       [Pp][+-]?{D}+
ragge
1.88
37 FS                      (f|F|l|L)?i?
ragge
1.1
38 IS                      (u|U|l|L)*
gmcgarry
1.87
39 UL                      ({L}|\\u{H}{H}{H}{H}|\\U{H}{H}{H}{H}{H}{H}{H}{H})
ragge
1.1
40
41 %{
gmcgarry
1.74
42 #include <stdlib.h>
ragge
1.1
43 #include <errno.h>  
44 #include <string.h>
ragge
1.31
45 #include <stdarg.h>
ragge
1.98
46 #include <ctype.h>
ragge
1.1
47
48 #include "pass1.h"
ragge
1.45
49 #include "cgram.h"
ragge
1.1
50
ragge
1.31
51 static NODE *cvtdig(int radix);
52 static NODE *charcon(void);
gmcgarry
1.87
53 static NODE *wcharcon(void);
ragge
1.5
54 static void control(int);
ragge
1.65
55 static void pragma(void);
ragge
1.109
56 int notype, parbal, inattr, parlvl, nodinit, inoso;
ragge
1.81
57 static int resw(TWORD, int);
ragge
1.5
58
59 #define CPP_IDENT       2
60 #define CPP_LINE        3
61 #define CPP_HASH        4
ragge
1.47
62
63 #ifdef STABS
ragge
1.71
64 #define STABS_LINE(x) if (gflag && cftnsp) stabs_line(x)
ragge
1.47
65 #else
66 #define STABS_LINE(x)
67 #endif
ragge
1.93
68 #if defined(FLEX_SCANNER) && YY_FLEX_SUBMINOR_VERSION == 31
ragge
1.73
69 /* Hack to avoid unnecessary warnings */
ragge
1.50
70 FILE *yyget_in  (void);
71 FILE *yyget_out  (void);
ragge
1.93
72 int yyget_leng  (void);
ragge
1.50
73 char *yyget_text  (void);
gmcgarry
1.77
74 void yyset_in (FILE *);
75 void yyset_out (FILE *);
ragge
1.50
76 int yyget_debug  (void);
gmcgarry
1.77
77 void yyset_debug (int);
ragge
1.50
78 int yylex_destroy  (void);
ragge
1.61
79 extern int yyget_lineno (void);
80 extern void yyset_lineno (int);
ragge
1.50
81 #endif
82
ragge
1.1
83 %}
84
85 %%
ragge
1.41
86
ragge
1.55
87 "__func__"              {
88                                 if (cftnsp == NULL)
89                                         uerror("__func__ outside function");
90                                 yylval.strp = cftnsp->sname; /* XXX - not C99 */
91                                 return(C_STRING);
92                         }
ragge
1.21
93 "asm"                   { return(C_ASM); }
ragge
1.83
94 "auto"                  {       return resw(AUTO, C_CLASS); }
ragge
1.96
95 "_Bool"                 {       return resw(BOOL, C_TYPE); }
ragge
1.21
96 "break"                 { return(C_BREAK); }
97 "case"                  { return(C_CASE); }
ragge
1.82
98 "char"                  {       return resw(CHAR, C_TYPE); }
ragge
1.84
99 "_Complex"              {       return resw(COMPLEX, C_TYPE); }
ragge
1.81
100 "const"                 {       return resw(CON, C_QUALIFIER); }
ragge
1.21
101 "continue"              { return(C_CONTINUE); }
102 "default"               { return(C_DEFAULT); }
103 "do"                    { return(C_DO); }
ragge
1.82
104 "double"                {       return resw(DOUBLE, C_TYPE); }
ragge
1.21
105 "else"                  { return(C_ELSE); }
ragge
1.54
106 "enum"                  { notype=1; return(C_ENUM); }
ragge
1.83
107 "extern"                {       return resw(EXTERN, C_CLASS); }
ragge
1.82
108 "float"                 {       return resw(FLOAT, C_TYPE); }
ragge
1.21
109 "for"                   { return(C_FOR); }
ragge
1.91
110 "goto"                  { notype=1; return(C_GOTO); }
ragge
1.21
111 "if"                    { return(C_IF); }
ragge
1.84
112 "_Imaginary"            {       return resw(IMAG, C_TYPE); }
ragge
1.21
113 "inline"                { return(C_FUNSPEC); }
ragge
1.82
114 "int"                   {       return resw(INT, C_TYPE); }
115 "long"                  {       return resw(LONG, C_TYPE); }
ragge
1.83
116 "register"              {       return resw(REGISTER, C_CLASS); }
ragge
1.8
117 "restrict"              { ; /* just ignore */ }
ragge
1.21
118 "return"                { return(C_RETURN); }
ragge
1.82
119 "short"                 {       return resw(SHORT, C_TYPE); }
120 "signed"                {       return resw(SIGNED, C_TYPE); }
ragge
1.21
121 "sizeof"                { return(C_SIZEOF); }
ragge
1.83
122 "static"                {       return resw(STATIC, C_CLASS); }
ragge
1.67
123 "struct"                { yylval.intval = STNAME; notype=1; return(C_STRUCT); }
ragge
1.21
124 "switch"                { return(C_SWITCH); }
ragge
1.83
125 "typedef"               {       return resw(TYPEDEF, C_CLASS); }
ragge
1.67
126 "union"                 { yylval.intval = UNAME; notype=1; return(C_STRUCT); }
ragge
1.82
127 "unsigned"              {       return resw(UNSIGNED, C_TYPE); }
128 "void"                  {       return resw(VOID, C_TYPE); }
ragge
1.81
129 "volatile"              {       return resw(VOL, C_QUALIFIER); }
ragge
1.21
130 "while"                 { return(C_WHILE); }
ragge
1.1
131
gmcgarry
1.87
132 {UL}({UL}|{D})* {       struct symtab *s;
ragge
1.69
133                         int i = 0;
ragge
1.1
134
ragge
1.69
135                         yylval.strp = addname(yytext);
ragge
1.63
136 #ifdef GCC_COMPAT
ragge
1.106
137                         if (doing_init && nodinit == 0) {
ragge
1.104
138                                 /* check for name: for old gcc compat */
ragge
1.106
139                                 while ((i = input()) == ' ' || i == '\t')
ragge
1.104
140                                         ;
ragge
1.106
141                                 if (i == ':')
142                                         return(GCC_DESIG);
ragge
1.104
143                                 unput(i);
144                         }
ragge
1.109
145                         if ((i = gcc_keyword(yylval.strp, &yylval.nodep)) > 0) {
146                                 if (i == PCC_OFFSETOF)
147                                         inoso = 1;
ragge
1.69
148                                 return i;
ragge
1.109
149                         }
ragge
1.63
150 #endif
ragge
1.69
151                         if (i == 0) {
152                                 if (notype)
153                                         return(C_NAME);
154                                 s = lookup(yylval.strp, SNOCREAT);
155                                 return s && s->sclass == TYPEDEF ?
156                                     notype=1, C_TYPENAME : C_NAME;
ragge
1.24
157                         }
ragge
1.69
158                 }
ragge
1.24
159
ragge
1.31
160 0[xX]{H}+{IS}?          { yylval.nodep = cvtdig(16); return(C_ICON); }
161 0{D}+{IS}?              { yylval.nodep = cvtdig(8); return(C_ICON); }
162 {D}+{IS}?               { yylval.nodep = cvtdig(10); return(C_ICON); }
gmcgarry
1.87
163 L'(\\.|[^\\'])+'        { yylval.nodep = wcharcon(); return(C_ICON); }
164 '(\\.|[^\\'])+'         { yylval.nodep = charcon(); return(C_ICON); }
ragge
1.31
165
ragge
1.80
166 {D}+{E}{FS}?            { yylval.nodep = floatcon(yytext); return(C_FCON); }
167 {D}*"."{D}+({E})?{FS}?  { yylval.nodep = floatcon(yytext); return(C_FCON); }
168 {D}+"."{D}*({E})?{FS}?  { yylval.nodep = floatcon(yytext); return(C_FCON); }
169 0[xX]{H}*"."{H}+{P}{FS}? { yylval.nodep = fhexcon(yytext); return(C_FCON); }
170 0[xX]{H}+"."{P}{FS}?    { yylval.nodep = fhexcon(yytext); return(C_FCON); }
171 0[xX]{H}+{P}{FS}?       { yylval.nodep = fhexcon(yytext); return(C_FCON); }
ragge
1.1
172
ragge
1.78
173 L?\"(\\.|[^\\"])*\"     { yylval.strp = yytext; return C_STRING; }
174
ragge
1.21
175 "..."                   { return(C_ELLIPSIS); }
176 ">>="                   { yylval.intval = RSEQ; return(C_ASOP); }
177 "<<="                   { yylval.intval = LSEQ; return(C_ASOP); }
178 "+="                    { yylval.intval = PLUSEQ; return(C_ASOP); }
179 "-="                    { yylval.intval = MINUSEQ; return(C_ASOP); }
180 "*="                    { yylval.intval = MULEQ; return(C_ASOP); }
181 "/="                    { yylval.intval = DIVEQ; return(C_ASOP); }
182 "%="                    { yylval.intval = MODEQ; return(C_ASOP); }
183 "&="                    { yylval.intval = ANDEQ; return(C_ASOP); }
184 "^="                    { yylval.intval = EREQ; return(C_ASOP); }
185 "|="                    { yylval.intval = OREQ; return(C_ASOP); }
186 ">>"                    { yylval.intval = RS; return(C_SHIFTOP); }
187 "<<"                    { yylval.intval = LS; return(C_SHIFTOP); }
188 "++"                    { yylval.intval = INCR; return(C_INCOP); }
189 "--"                    { yylval.intval = DECR; return(C_INCOP); }
ragge
1.25
190 "->"                    { yylval.intval = STREF; return(C_STROP); }
ragge
1.21
191 "&&"                    { yylval.intval = ANDAND; return(C_ANDAND); }
192 "||"                    { yylval.intval = OROR; return(C_OROR); }
193 "<="                    { yylval.intval = LE; return(C_RELOP); }
194 ">="                    { yylval.intval = GE; return(C_RELOP); }
195 "=="                    { yylval.intval = EQ; return(C_EQUOP); }
196 "!="                    { yylval.intval = NE; return(C_EQUOP); }
ragge
1.54
197 ";"                     { notype = 0; return(';'); }
198 ("{"|"<%")              { notype = 0; return('{'); }
ragge
1.68
199 ("}"|"%>")              { if (rpole) notype = 1; return('}'); }
ragge
1.109
200 ","                     { if (parbal && !inoso) notype = 0; return(','); }
ragge
1.106
201 ":"                     { if (doing_init) nodinit--; return(':'); }
ragge
1.22
202 "="                     { return('='); }
ragge
1.54
203 "("                     { parbal++; notype = 0; return('('); }
ragge
1.81
204 ")"                     {       parbal--;
ragge
1.109
205                                 inoso = 0;
ragge
1.81
206                                 if (parbal==0) { notype = 0; }
207                                 if (inattr && parlvl == parbal)
208                                         inattr = 0;
209                                 return(')'); }
ragge
1.22
210 ("["|"<:")              { return('['); }
211 ("]"|":>")              { return(']'); }
ragge
1.25
212 "."                     { yylval.intval = DOT; return(C_STROP); }
ragge
1.22
213 "&"                     { return('&'); }
ragge
1.21
214 "!"                     { yylval.intval = NOT; return(C_UNOP); }
215 "~"                     { yylval.intval = COMPL; return(C_UNOP); }
ragge
1.22
216 "-"                     { return('-'); }
217 "+"                     { return('+'); }
ragge
1.60
218 "*"                     { if (parbal && notype == 0) notype = 1; return('*'); }
ragge
1.21
219 "/"                     { yylval.intval = DIV; return(C_DIVOP); }
220 "%"                     { yylval.intval = MOD; return(C_DIVOP); }
221 "<"                     { yylval.intval = LT; return(C_RELOP); }
222 ">"                     { yylval.intval = GT; return(C_RELOP); }
ragge
1.22
223 "^"                     { return('^'); }
224 "|"                     { return('|'); }
ragge
1.106
225 "?"                     { if (doing_init) nodinit++; return('?'); }
ragge
1.65
226 ^#pragma[ \t].*         { pragma(); }
ragge
1.5
227 ^#ident[ \t].*          { control(CPP_IDENT); }
228 ^#line[ \t].*           { control(CPP_LINE); }
229 ^#.*                    { control(CPP_HASH); }
ragge
1.1
230
231 [ \t\v\f]               { }
ragge
1.47
232 "\n"                    { ++lineno; STABS_LINE(lineno); }
ragge
1.1
233 .                       { /* ignore bad characters */ }
234
235 %%
236
ragge
1.110
237 int lineno, issyshdr;
ragge
1.33
238 char *ftitle = "<stdin>";
ragge
1.30
239
ragge
1.1
240 int
241 yywrap(void)
242 {
ragge
1.50
243         if (0) unput(0); /* quiet gcc */
ragge
1.1
244         return(1);
245 }
246
ragge
1.81
247 int
248 resw(TWORD t, int rv)
249 {
250         if (inattr) {
251                 yylval.strp = addname(yytext);
252                 return C_NAME;
253         }
254
255         switch (rv) {
ragge
1.83
256         case C_CLASS:
257                 yylval.nodep = block(CLASS, NIL, NIL, t, 0, 0);
258                 return rv;
259
ragge
1.81
260         case C_QUALIFIER:
ragge
1.94
261                 yylval.nodep = block(QUALIFIER, NIL, NIL, 0, 0, 0);
262                 yylval.nodep->n_qual = t;
ragge
1.83
263                 return rv;
ragge
1.82
264
265         case C_TYPE:
ragge
1.103
266                 yylval.nodep = mkty(t, 0, 0);
ragge
1.82
267                 notype=1;
ragge
1.83
268                 return(rv);
ragge
1.82
269
ragge
1.81
270         default:
271                 cerror("resw");
272         }
273         return 0;
274 }
275
ragge
1.80
276 #ifndef SOFTFLOAT
ragge
1.101
277
278 static long double
279 typround(long double dc, char *e, TWORD *tw)
280 {
281         int im = 0;
282
283         *tw = DOUBLE;
284         for (; *e; e++) {
285                 switch (*e) {
286                 case 'f':
287                 case 'F':
288                         *tw = FLOAT;
289                         dc = (float)dc;
290                         break;
291                 case 'l':
292                 case 'L':
293                         *tw = LDOUBLE;
294                         break;
295                 case 'i':
296                 case 'I':
297                         im = 1;
298                         break;
299                 }
300         }
301         if (*tw == DOUBLE)
302                 dc = (double)dc;
303 #ifndef NO_COMPLEX
304         if (im)
305                 *tw += (FIMAG-FLOAT);
306 #endif
307         return dc;
308 }
309
ragge
1.56
310 /*
311  * XXX floatcon() and fhexcon() should be in support libraries for
312  * the target floating point.
313  */
314 static NODE *
315 f2(char *str)
ragge
1.1
316 {
ragge
1.36
317         TWORD tw;
ragge
1.31
318         NODE *p;
ragge
1.84
319         long double dc;
ragge
1.1
320         char *eptr;
321
gmcgarry
1.86
322 #ifdef HAVE_STRTOLD
ragge
1.84
323         dc = strtold(str, &eptr); /* XXX - avoid strtod() */
gmcgarry
1.86
324 #else
325         dc = strtod(str, &eptr); /* XXX - avoid strtod() */
326 #endif
ragge
1.101
327         dc = typround(dc, eptr, &tw);
ragge
1.103
328         p = block(FCON, NIL, NIL, tw, 0, 0);
ragge
1.36
329         p->n_dcon = dc;
ragge
1.31
330         return p;
ragge
1.1
331 }
332
ragge
1.56
333 NODE *
ragge
1.80
334 floatcon(char *s)
ragge
1.56
335 {
ragge
1.80
336         return f2(s);
ragge
1.56
337 }
338
339 static int
340 h2n(int ch)
341 {
342         if (ch >= '0' && ch <= '9')
343                 return ch - '0';
344         if (ch >= 'a' && ch <= 'f')
345                 return ch - 'a' + 10;
346         return ch - 'A' + 10;
347         
348 }
349
350 NODE *
ragge
1.80
351 fhexcon(char *c)
ragge
1.56
352 {
ragge
1.101
353         TWORD tw;
354         char *ep;
355         long double d;
356         int i, ed;
357         NODE *p;
ragge
1.56
358
ragge
1.101
359         d = 0.0;
360         ed = 0;
ragge
1.56
361         c+= 2; /* skip 0x */
ragge
1.101
362 #define FSET(n) { d *= 2; if (i & n) d += 1.0; }
363         for (; *c != '.' && *c != 'p' && *c != 'P'; c++) {
364                 i = h2n(*c);
365                 FSET(8); FSET(4); FSET(2); FSET(1);
366         }
ragge
1.56
367         if (*c != '.' && *c != 'p' && *c != 'P')
368                 cerror("fhexcon");
369         if (*c == '.') {
370                 c++;
ragge
1.101
371                 for (; *c != 'p' && *c != 'P'; c++) {
372                         i = h2n(*c);
373                         FSET(8); FSET(4); FSET(2); FSET(1);
374                         ed -= 4;
375                 }
ragge
1.56
376         }
377         if (*c != 'P' && *c != 'p')
378                 cerror("fhexcon2");
379         c++;
ragge
1.101
380         ed += strtol(c, &ep, 10);
381
ragge
1.102
382         /* avoid looping in vain. Idea from Fred J. Tydeman */
383         if (ed > 32769) ed = 32769;
384         if (ed < -32769) ed = -32769;
385
ragge
1.101
386         while (ed > 0)
387                 d *= 2, ed--;
388         while (ed < 0)
389                 d /= 2, ed++;
390         d = typround(d, ep, &tw);
ragge
1.103
391         p = block(FCON, NIL, NIL, tw, 0, 0);
ragge
1.101
392         p->n_dcon = d;
393         return p;
ragge
1.56
394 }
ragge
1.80
395 #endif
ragge
1.56
396
ragge
1.55
397 unsigned int
ragge
1.1
398 esccon(char **sptr)
399 {
400         char *wr = *sptr;
gmcgarry
1.87
401         char *owr;
402         char c;
ragge
1.55
403         unsigned int val;
gmcgarry
1.87
404         int wsz = 4, esccon_warn = 1;
ragge
1.1
405
406         switch (*wr++) {
407         case 'a': val = '\a'; break;
408         case 'b': val = '\b'; break;
409         case 'f': val = '\f'; break;
410         case 'n': val = '\n'; break;
411         case 'r': val = '\r'; break;
412         case 't': val = '\t'; break;
413         case 'v': val = '\v'; break;
ragge
1.42
414         case '\"': val = '\"'; break;
ragge
1.55
415         case 'x': val = strtoul(wr, &wr, 16); break;
gmcgarry
1.87
416         /* ISO/IEC 9099:1999 (E) 6.4.3 */
ragge
1.90
417         case 'U'|(char)0x80:
gmcgarry
1.87
418                 esccon_warn = 0;
419                 /* FALLTHROUGH */
420         case 'U':
421                 wsz = 8;
422                 /* FALLTHROUGH */
423         case 'u':
424                 owr = wr;
425                 while (wr < (owr + wsz))
426                         if (*wr == '\0')
427                                 break;
428                         else
429                                 ++wr;
430                 if (wr != (owr + wsz)) {
431                         /* incomplete */
432                         val = strtoul(owr, &wr, 16);
433                 } else {
434                         c = owr[wsz];
435                         owr[wsz] = '\0'; /* prevent it from reading too much */
436                         val = strtoul(owr, &wr, 16);
437                         owr[wsz] = c;
438                 }
439                 if (wr != (owr + wsz))
440                         werror("incomplete universal character name");
441                 if (wsz == 4)
442                         val &= 0xFFFF;
443                 if (esccon_warn && ((val >= 0xD800 && val <= 0xDFFF) ||
444                     (val < 0xA0 && val != 0x24 && val != 0x40 && val != 0x60)))
445                         werror("invalid universal character name %04X", val);
446                 break;
ragge
1.1
447         case '0': case '1': case '2': case '3': case '4': 
ragge
1.76
448         case '5': case '6': case '7':
449                 val = wr[-1] - '0';
450                 if (*wr >= '0' && *wr <= '7') {
451                         val = (val << 3) + (*wr++ - '0');
452                         if (*wr >= '0' && *wr <= '7')
453                                 val = (val << 3) + (*wr++ - '0');
454                 }
ragge
1.40
455                 break;
ragge
1.1
456         default: val = wr[-1];
457         }
458         *sptr = wr;
459         return val;
460 }
461
ragge
1.31
462 NODE *
ragge
1.1
463 cvtdig(int radix)
464 {
ragge
1.31
465         NODE *p;
ragge
1.105
466         TWORD otype, ntype;
ragge
1.31
467         unsigned long long v;
ragge
1.15
468         char *ch = yytext;
ragge
1.31
469         int n, numl, numu;
ragge
1.1
470
ragge
1.15
471         if (radix == 16)
472                 ch += 2; /* Skip 0x */
473         
ragge
1.31
474         v = 0;
ragge
1.15
475         while ((*ch >= '0' && *ch <= '9') || (*ch >= 'a' && *ch <= 'f') ||
476             (*ch >= 'A' && *ch <= 'F')) {
ragge
1.31
477                 v *= radix;
ragge
1.15
478                 n = *ch;
479                 n = (n <= '9' ? n - '0' : (n > 'F' ? n - 'a' : n - 'A') + 10);
480                 ch++;
ragge
1.31
481                 v += n;
482         }
483         /* Parse trailing chars */
484         ntype = INT;
485         numl = numu = 0;
486         for (n = 0; n < 3; n++) {
487                 if (*ch == 0)
488                         break;
489                 if ((*ch == 'l' || *ch == 'L') && numl < 2)
ragge
1.37
490                         ntype+=2, numl++;
ragge
1.31
491                 else if ((*ch == 'u' || *ch == 'U') && numu < 1)
492                         ntype = ENUNSIGN(ntype), numu++;
493                 else
494                         break;
495                 ch++;
ragge
1.1
496         }
ragge
1.31
497         if (*ch)
498                 uerror("constant has too many '%c'", *ch);
499
ragge
1.105
500         otype = ntype;
501         switch (ntype) {
502         case INT:
503         case LONG:
504         case LONGLONG:
505                 if (radix == 10) {
506                         if (otype == LONGLONG)
507                                 break;
508                         if (v > MAX_LONG) { 
509                                 ntype = LONGLONG;
510                                 if (otype == LONG)
511                                         break;
512                         } else if (v > MAX_INT)
513                                 ntype = LONG;
514                 } else {
515                         if (v > MAX_LONGLONG) {
516                                 ntype = ULONGLONG;
517                                 if (otype == LONGLONG)
518                                         break;
519                         } else if (v > MAX_ULONG) {
520                                 ntype = LONGLONG;
521                         } else if (v > MAX_LONG) {
522                                 ntype = ULONG;
523                                 if (otype == LONG)
524                                         break;
525                         } else if (v > MAX_UNSIGNED) {
526                                 ntype = LONG;
527                         } else if (v > MAX_INT)
528                                 ntype = UNSIGNED;
529                 }
530                 break;
531         case UNSIGNED:
532         case ULONG:
533                 if (v > MAX_ULONG) {
ragge
1.36
534                         ntype = ULONGLONG;
ragge
1.105
535                         if (otype == ULONG)
536                                 break;
537                 } else if (v > MAX_UNSIGNED)
ragge
1.36
538                         ntype = ULONG;
ragge
1.105
539                 break;  
540         }       
541
ragge
1.49
542         ntype = ctype(ntype);
stefan
1.64
543         p = xbcon(v, NULL, ntype);
ragge
1.38
544         ASGLVAL(p->n_slval, v);
ragge
1.31
545
546         return p;
ragge
1.1
547 }
548
549 /*
550  * Convert a character constant to an integer.
551  */
ragge
1.31
552 NODE *
ragge
1.1
553 charcon(void)
554 {
ragge
1.31
555         int lastcon = 0;
ragge
1.1
556         int val, i = 0;
557         char *pp = yytext;
558
559         if (*pp == 'L')
560                 pp++;
561         pp++;
562         while (*pp != '\'') {
563                 if (*pp++ == '\\') {
564                         val = esccon(&pp);
565                 } else
566                         val = pp[-1];
567                 makecc(val, i);
568                 i++;
569         }
570
571         if (i == 0)
572                 uerror("empty character constant");
ragge
1.34
573         if (i > (SZINT/SZCHAR) || (i>1))
574                 werror("too many characters in character constant");
ragge
1.36
575         return bcon(lastcon);
ragge
1.1
576 }
577
gmcgarry
1.87
578 NODE *
579 wcharcon(void)
580 {
581         unsigned int lastcon = 0;
582         unsigned int val, i = 0;
583         char *pp = yytext;
584
585         if (*pp == 'L')
586                 pp++;
587         pp++;
588         while (*pp != '\'') {
589                 if (*pp++ == '\\') {
590                         val = esccon(&pp);
591                 } else
592                         val = pp[-1];
593 #if WCHAR_SIZE == 2
594                 lastcon = (lastcon << 16) | (val & 0xFFFF);
595 #else
596                 lastcon = val;
597 #endif
598                 i++;
599         }
600
601         if (i == 0)
plunky
1.108
602                 uerror("empty wide-character constant");
gmcgarry
1.87
603         if (i > 1)
plunky
1.108
604                 werror("too many characters in wide-character constant");
gmcgarry
1.87
605         return xbcon(lastcon, NULL, ctype(UNSIGNED));
606 }
607
ragge
1.5
608 void
609 control(int t)
610 {
611         char *wr = yytext;
612         char *eptr;
613         int val;
614
615         wr++;   /* Skip initial '#' */
616         switch (t) {
617         case CPP_IDENT:
618                 return; /* Just skip these for now. */
619
620         case CPP_LINE:
621                 wr += 4;
622                 /* FALLTHROUGH */
623         case CPP_HASH:
624                 val = strtol(wr, &eptr, 10);
625                 if (wr == eptr) /* Illegal string */
626                         goto bad;
627                 wr = eptr;
ragge
1.43
628                 lineno = val - 1;
ragge
1.5
629                 while (*wr && *wr != '\"')
630                         wr++;
ragge
1.69
631                 if (*wr == 0)
632                         return;
ragge
1.5
633                 if (*wr++ != '\"')
634                         goto bad;
ragge
1.30
635                 eptr = wr;
ragge
1.5
636                 while (*wr && *wr != '\"')
ragge
1.30
637                         wr++;
638                 if (*wr != '\"')
639                         goto bad;
ragge
1.110
640                 *wr++ = 0;
ragge
1.30
641                 ftitle = addstring(eptr);
ragge
1.110
642                 while (*wr == ' ')
643                         wr++;
644                 issyshdr = 0;
645                 if (*wr == '3')
646                         issyshdr = 1;
ragge
1.46
647 #ifdef STABS
648                 if (gflag)
ragge
1.47
649                         stabs_file(ftitle);
ragge
1.46
650 #endif
ragge
1.5
651         }
652         return;
653 bad:
654         werror("%s: illegal control", yytext);
655 }
ragge
1.62
656
ragge
1.98
657 int pragma_allpacked;
658 int pragma_packed, pragma_aligned;
659 char *pragma_renamed;
660
661 static int
662 pragmas_weak(char *str)
663 {
664         struct symtab *sp;
665         char *s1, *s2;
666
667         if ((s1 = pragtok(NULL)) == NULL)
668                 return 1;
669         if ((s2 = pragtok(NULL)) == NULL) {
670                 sp = lookup(addname(s1), SNORMAL);
671                 sp->sap = attr_add(sp->sap, gcc_attr_parse(bdty(NAME, "weak")));
672         } else if (*s2 == '=') {
673                 if ((s2 = pragtok(NULL)) == NULL)
674                         return 1;
675                 sp = lookup(addname(s2), SNORMAL);
676                 sp->sap = attr_add(sp->sap, gcc_attr_parse(bdty(CALL,
677                     bdty(NAME, "aliasweak"), bdty(STRING, s1, 0))));
678         } else
679                 return 1;
680         return 0;
681 }
682
ragge
1.99
683 char *pragstore;
ragge
1.98
684
685 /* trivial tokenizer for pragmas */
ragge
1.99
686 #define ps pragstore
ragge
1.98
687 char *
688 pragtok(char *sin)
689 {
690         static char ss[2];
691         char *rv;
692
693         if (sin)
694                 ps = sin;
695
ragge
1.100
696         for (; isspace((int)*ps); ps++)
ragge
1.98
697                 ;
698         if (*ps == 0)
699                 return NULL;
ragge
1.100
700         for (rv = ps; isalpha((int)*ps) || isdigit((int)*ps) || *ps == '_'; ps++)
ragge
1.98
701                 ;
702         ss[0] = *ps;
703         if (rv == ps) {
704                 rv = ss, ps++;
705         } else {
706                 *ps = 0;
707                 rv = tmpstrdup(rv);
708                 *ps = ss[0];
709         }
710         return rv;
711 }
712
713 /* return 1 on error */
ragge
1.99
714 int
ragge
1.98
715 eat(int ch)
716 {
717         char *s = pragtok(0);
718         return (s == 0 || *s != ch);
719 }
720
721 static int
722 pragmas_alpack(char *t)
723 {
724         char *s;
725         int ap;
726
727         ap = (s = pragtok(0)) ? atoi(s) : 1;
728         if (strcmp(t, "packed") == 0)
729                 pragma_packed = ap;
730         else
731                 pragma_aligned = ap;
732         return 0;
733 }
734
735
ragge
1.65
736 /*
ragge
1.98
737  * Packing control.
738  * still missing push/pop.
ragge
1.65
739  */
ragge
1.98
740 static int
741 pragmas_pack(char *t)
ragge
1.62
742 {
ragge
1.98
743         char *s;
ragge
1.62
744
ragge
1.98
745         if (eat('('))
746                 return 1;
747         s = pragtok(0);
748         if (*s == ')')
749                 return pragma_allpacked = 0;
750
751         if (*s < '0' || *s > '9') /* no number */
752                 return 1;
753         pragma_allpacked = atoi(s);
754         return eat(')');
ragge
1.62
755 }
756
ragge
1.98
757 static int
758 pragmas_renamed(char *t)
759 {
760         char *f = pragtok(0);
761
762         if (f == 0)
763                 return 1;
764         pragma_renamed = newstring(f, strlen(f));
765         return 0;
766 }
767
768 static int
769 pragmas_stdc(char *t)
770 {
771         return 0; /* Just ignore */
772 }
ragge
1.65
773
ragge
1.98
774 struct pragmas {
775         char *name;
776         int (*fun)(char *);
777 } pragmas[] = {
778         { "pack", pragmas_pack },
779         { "packed", pragmas_alpack },
780         { "aligned", pragmas_alpack },
781         { "rename", pragmas_renamed },
782 #ifdef GCC_COMPAT
783         { "GCC", pragmas_gcc },
784 #endif
785         { "STDC", pragmas_stdc },
786         { "weak", pragmas_weak },
ragge
1.99
787         { "ident", NULL },
ragge
1.98
788         { 0 },
789 };
plunky
1.111
790
ragge
1.62
791 /*
792  * got a full pragma line.  Split it up here.
793  */
ragge
1.65
794 static void
plunky
1.111
795 pragma(void)
ragge
1.62
796 {
ragge
1.98
797         struct pragmas *p;
798         char *t, *pt;
ragge
1.62
799
ragge
1.98
800         if ((t = pragtok(&yytext[7])) != NULL) {
801                 pt = ps;
802                 for (p = pragmas; p->name; p++) {
803                         if (strcmp(t, p->name) == 0) {
ragge
1.99
804                                 if (p->fun && (*p->fun)(t))
ragge
1.98
805                                         uerror("bad argument to #pragma");
806                                 return;
807                         }
808                 }
809                 ps = pt;
810                 if (mypragma(t))
811                         return;
gmcgarry
1.75
812         }
ragge
1.99
813         warner(Wunknown_pragmas, t, ps);
ragge
1.62
814 }
ragge
1.69
815
816 void
817 cunput(char c)
818 {
819         unput(c);
820 }
FishEye: Open Source License registered to PCC.
Your maintenance has expired. You can renew your license at http://www.atlassian.com/fisheye/renew
Atlassian FishEye, CVS analysis. (Version:1.6.3 Build:build-336 2008-11-04) - Administration - Page generated 2014-10-01 02:02 +0200