Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20140703173031

Diff

Diff from 1.122 to:

Annotations

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

Annotated File View

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