Quick Search:

Mode

Context

Displaying 3 lines of context. None | Less | More | Full

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.101
 
1.102
 
MAIN:plunky:20121107095159
 
token.c
_>6161 static void endifstmt(void);
 6262 static void ifstmt(void);
 6363 static void cpperror(void);
<>64 -static void pragmastmt(void);
 65 -static void undefstmt(void);
6664 static void cppwarning(void);
<> 65+static void undefstmt(void);
  66+static void pragmastmt(void);
6767 static void elifstmt(void);
<>68 -static int chktg(void);
 69 -static int inpch(void);
 70 -static int inch(void);
7168 
 7269 #define PUTCH(ch) if (!flslvl) putch(ch)
 7370 /* protection against recursion in #include */
 7471 #define MAX_INCLEVEL    100
 7572 static int inclevel;
 7673 
<>77 -/* get next character unaltered */
 78 -#define NXTCH() (ifiles->curptr < ifiles->maxread ? *ifiles->curptr++ : inpch())
 79 -
8074 usch yytext[CPPBUF];
 8175 
 8276 struct includ *ifiles;
     
 !
9892         C_WSNLC_2,    C_SPEC0,      0,      0,      C_2,    C_SPEC,
 9993         0,      0,      0,      C_2,    0,      C_2,    0,      C_SPEC|C_2,
 10094         C_DX,   C_DX,   C_DX,   C_DX,   C_DX,   C_DX,   C_DX,   C_DX,
<>101 -        C_DX,   C_DX,   0,      0,      C_2,    C_2,    C_2,    C_SPEC,
  95+        C_DX,   C_DX,   0,      0,      C_2,    C_2,    C_2,    0,
10296 
 10397         0,      C_IX,   C_IX,   C_IX,   C_IX,   C_IXE,  C_IX,   C_I,
 10498         C_I,    C_I,    C_I,    C_I,    C_I,    C_I,    C_I,    C_I,
 10599         C_IP,   C_I,    C_I,    C_I,    C_I,    C_I,    C_I,    C_I,
<>106 -        C_I,    C_I,    C_I,    0,      C_SPEC0,      0,      C_I,
  100+        C_I,    C_I,    C_I,    0,      0,      0,      0,      C_I,
107101 
 108102         0,      C_IX,   C_IX,   C_IX,   C_IX,   C_IXE,  C_IX,   C_I,
 109103         C_I,    C_I,    C_I,    C_I,    C_I,    C_I,    C_I,    C_I,
 110104         C_IP,   C_I,    C_I,    C_I,    C_I,    C_I,    C_I,    C_I,
 111105         C_I,    C_I,    C_I,    0,      C_2,    0,      0,      0,
 112106 };
 113107 
<> 108+/*
  109+ * fill up the input buffer
  110+ */
  111+static int
  112+inpbuf(void)
  113+{
  114+        int len;
  115+
  116+        if (ifiles->infil == -1)
  117+                return 0;
  118+        len = read(ifiles->infil, ifiles->buffer, CPPBUF);
  119+        if (len == -1)
  120+                error("read error on file %s", ifiles->orgfn);
  121+        if (len > 0) {
  122+                ifiles->buffer[len] = 0;
  123+                ifiles->curptr = ifiles->buffer;
  124+                ifiles->maxread = ifiles->buffer + len;
  125+        }
  126+        return len;
  127+}
  128+
  129+/*
  130+ * return a raw character from the input stream
  131+ */
  132+static inline int
  133+inpch(void)
  134+{
  135+
  136+        do {
  137+                if (ifiles->curptr < ifiles->maxread)
  138+                        return *ifiles->curptr++;
  139+        } while (inpbuf() > 0);
  140+
  141+        return -1;
  142+}
  143+
  144+/*
  145+ * push a character back to the input stream
  146+ */
114147 static void
 115148 unch(int c)
 116149 {
 117150         if (c == -1)
 118151                 return;
 119152                 
<>120 -        --ifiles->curptr;
  153+        ifiles->curptr--;
121154         if (ifiles->curptr < ifiles->bbuf)
 122155                 error("pushback buffer full");
 123156         *ifiles->curptr = (usch)c;
 124157 }
 125158 
<> 159+/*
  160+ * Check for (and convert) trigraphs.
  161+ */
  162+static int
  163+chktg(void)
  164+{
  165+        int ch;
  166+
  167+        if ((ch = inpch()) != '?') {
  168+                unch(ch);
  169+                return 0;
  170+        }
  171+
  172+        switch (ch = inpch()) {
  173+        case '='return '#';
  174+        case '('return '[';
  175+        case ')'return ']';
  176+        case '<'return '{';
  177+        case '>'return '}';
  178+        case '/'return '\\';
  179+        case '\'': return '^';
  180+        case '!'return '|';
  181+        case '-'return '~';
  182+        }
  183+
  184+        unch(ch);
  185+        unch('?');
  186+        return 0;
  187+}
  188+
  189+/*
  190+ * check for (and eat) end-of-line
  191+ */
  192+static int
  193+chkeol(void)
  194+{
  195+        int ch;
  196+
  197+        ch = inpch();
  198+        if (ch == '\r') {
  199+                ch = inpch();
  200+                if (ch == '\n')
  201+                        return '\n';
  202+
  203+                unch(ch);
  204+                unch('\r');
  205+                return 0;
  206+        }
  207+        if (ch == '\n')
  208+                return '\n';
  209+
  210+        unch(ch);
  211+        return 0;
  212+}
  213+
  214+/*
  215+ * return next char, after converting trigraphs and
  216+ * skipping escaped line endings
  217+ */
  218+static inline int
  219+inch(void)
  220+{
  221+        int ch;
  222+
  223+        for (;;) {
  224+                ch = inpch();
  225+                if (ch == '?' && (ch = chktg()) == 0)
  226+                        return '?';
  227+                if (ch != '\\' || chkeol() == 0)
  228+                        return ch;
  229+                ifiles->escln++;
  230+        }
  231+}
  232+
126233 static void
 127234 eatcmnt(void)
 128235 {
     
 !
133240                 ch = inch();
 134241                 if (ch == '\n') {
 135242                         ifiles->lineno++;
<>136 -                        if (!Cflag) PUTCH('\n');
  243+                        putch('\n');
  244+                        continue;
137245                 }
 138246                 if (ch == -1)
 139247                         break;
     
 !
168276 fastscan(void)
 169277 {
 170278         struct symtab *nl;
<>171 -        int ch, i = 0;
 172 -        int nnl = 0;
  279+        int ch, i;
173280         usch *cp;
 174281 
 175282         goto run;
 176283         for (;;) {
<>177 -                ch = NXTCH();
  284+                ch = inch();
178285 xloop:          if (ch == -1)
 179286                         return;
 180287 #ifdef PCC_DEBUG
     
 !
202309                                 goto xloop;
 203310                         } else if (ch == '*') {
 204311                                 eatcmnt();
<>205 -                                continue;
206312                         } else {
 207313                                 PUTCH('/');
 208314                                 goto xloop;
 209315                         }
 210316                         break;
 211317 
<>212 -                case '?'/* trigraphs */
 213 -                        if ((ch = chktg()))
 214 -                                goto xloop;
 215 -                        PUTCH('?');
 216 -                        break;
 217 -
 218 -                case '\\':
 219 -                        if ((ch = NXTCH()) == '\n') {
 220 -                                ifiles->lineno++;
 221 -                                continue;
 222 -                        }
 223 -                        PUTCH('\\');
 224 -                        goto xloop;
 225 -
226318                 case '\n': /* newlines, for pp directives */
<>227 -                        while (nnl > 0) { PUTCH('\n'); nnl--; ifiles->lineno++; }
 228 -run2:                   ifiles->lineno++;
 229 -                        do {
 230 -                                PUTCH(ch);
 231 -run:                            ch = NXTCH();
  319+                        i = ifiles->escln + 1;
  320+                        ifiles->lineno += i;
  321+                        ifiles->escln = 0;
  322+                        while (i-- > 0)
  323+                                putch('\n');
  324+run:                    for(;;) {
  325+                                ch = inch();
232326                                 if (ch == '/') {
<>233 -                                        ch = NXTCH();
  327+                                        ch = inch();
234328                                         if (ch == '/')
 235329                                                 goto cppcmt;
 236330                                         if (ch == '*') {
 237331                                                 eatcmnt();
<>238 -                                                goto run;
  332+                                                continue;
239333                                         }
 240334                                         unch(ch);
 241335                                         ch = '/';
 242336                                 }
<>243 -                        } while (ch == ' ' || ch == '\t');
 244 -                        if (ch == '\\') {
 245 -                                ch = NXTCH();
 246 -                                if (ch == '\n')
 247 -                                        goto run2;
 248 -                                unch(ch);
 249 -                                ch = '\\';
  337+                                if (ch != ' ' && ch != '\t')
  338+                                        break;
  339+                                PUTCH(ch);
250340                         }
 251341                         if (ch == '#') {
 252342                                 ppdir();
 253343                                 continue;
 254344                         } else if (ch == '%') {
<>255 -                                ch = NXTCH();
  345+                                ch = inch();
256346                                 if (ch == ':') {
 257347                                         ppdir();
 258348                                         continue;
 259349                                 }
 260350                                 unch(ch);
 261351                                 ch = '%';
<>262 -                        } else if (ch == '?') {
 263 -                                if ((ch = chktg()) == '#') {
 264 -                                        ppdir();
 265 -                                        continue;
 266 -                                } else if (ch == 0)
 267 -                                        ch = '?';
268352                         }
 269353                         goto xloop;
 270354 
 271355                 case '\"': /* strings */
 272356 str:                    PUTCH(ch);
<>273 -                        while ((ch = NXTCH()) != '\"') {
  357+                        while ((ch = inch()) != '\"') {
  358+                                if (ch == '\\') {
  359+                                        PUTCH('\\');
  360+                                        ch = inch();
  361+                                }
274362                                 if (ch == '\n')
 275363                                         goto xloop;
<>276 -                                if (ch == '\\') {
 277 -                                        if ((ch = NXTCH()) != '\n') {
 278 -                                                PUTCH('\\');
 279 -                                                PUTCH(ch);
 280 -                                        } else
 281 -                                                nnl++;
 282 -                                        continue;
 283 -                                }
284364                                 if (ch == -1)
 285365                                         return;
 286366                                 PUTCH(ch);
     
 !
290370 
 291371                 case '.'/* for pp-number */
 292372                         PUTCH(ch);
<>293 -                        ch = NXTCH();
  373+                        ch = inch();
294374                         if (ch < '0' || ch > '9')
 295375                                 goto xloop;
<> 376+
296377                         /* FALLTHROUGH */
 297378                 case '0': case '1': case '2': case '3': case '4':
 298379                 case '5': case '6': case '7': case '8': case '9':
 299380                         do {
 300381 nxp:                            PUTCH(ch);
<>301 -nxt:                            ch = NXTCH();
 302 -                                if (ch == '\\') {
 303 -                                        ch = NXTCH();
 304 -                                        if (ch == '\n') {
 305 -                                                nnl++;
 306 -                                                goto nxt;
 307 -                                        }
 308 -                                        unch(ch);
 309 -                                        ch = '\\';
 310 -                                }
  382+                                ch = inch();
311383                                 if (ch == -1)
 312384                                         return;
 313385                                 if (spechr[ch] & C_EP) {
 314386                                         PUTCH(ch);
<>315 -                                        ch = NXTCH();
  387+                                        ch = inch();
316388                                         if (ch == '-' || ch == '+')
 317389                                                 goto nxp;
 318390                                         if (ch == -1)
     
 !
324396                 case '\'': /* character literal */
 325397 con:                    PUTCH(ch);
 326398                         if (tflag)
<>327 -                                continue; /* character constants ignored */
 328 -                        while ((ch = NXTCH()) != '\'') {
 329 -                                if (ch == '\n')
 330 -                                        goto xloop;
  399+                                break; /* character constants ignored */
  400+                        while ((ch = inch()) != '\'') {
331401                                 if (ch == '\\') {
<>332 -                                        if ((ch = NXTCH()) != '\n') {
 333 -                                                PUTCH('\\');
 334 -                                                PUTCH(ch);
 335 -                                        } else
 336 -                                                nnl++;
 337 -                                        continue;
  402+                                        PUTCH('\\');
  403+                                        ch = inch();
338404                                 }
<> 405+                                if (ch == '\n')
  406+                                        goto xloop;
339407                                 if (ch == -1)
 340408                                         return;
 341409                                 PUTCH(ch);
     
 !
344412                         break;
 345413 
 346414                 case 'L':
<>347 -                        ch = NXTCH();
  415+                        ch = inch();
348416                         if (ch == '\"') {
 349417                                 PUTCH('L');
 350418                                 goto str;
     
 !
355423                         }
 356424                         unch(ch);
 357425                         ch = 'L';
<> 426+
358427                         /* FALLTHROUGH */
 359428                 default:
<> 429+#ifdef PCC_DEBUG
360430                         if ((spechr[ch] & C_ID) == 0)
 361431                                 error("fastscan");
<>362 -                        if (flslvl) {
 363 -                                while (ch != -1 && (spechr[ch] & C_ID))
 364 -                                        ch = NXTCH();
 365 -                                goto xloop;
 366 -                        }
  432+#endif
367433                         i = 0;
 368434                         do {
 369435                                 yytext[i++] = (usch)ch;
<>370 -                                ch = NXTCH();
 371 -                                if (ch == '\\') {
 372 -                                        ch = NXTCH();
 373 -                                        if (ch != '\n') {
 374 -                                                unch(ch);
 375 -                                                ch = '\\';
 376 -                                        } else {
 377 -                                                putch('\n');
 378 -                                                ifiles->lineno++;
 379 -                                                ch = NXTCH();
 380 -                                        }
 381 -                                }
 382 -                                if (ch == -1)
 383 -                                        return;
 384 -                        } while (spechr[ch] & C_ID);
  436+                                ch = inch();
  437+                        } while (ch != -1 && (spechr[ch] & C_ID));
385438 
<> 439+                        if (flslvl)
  440+                                goto xloop;
  441+
386442                         yytext[i] = 0;
 387443                         unch(ch);
 388444 
     
 !
614670         while ((ch = sloscan()) == WSPACE)
 615671                 ;
 616672         if (ch < 128 && (spechr[ch] & C_2))
<>617 -                c2 = inpch();
  673+                c2 = inch();
618674         else
 619675                 c2 = 0;
 620676 
     
 !
650706                         break;
 651707                 /* Found comment that need to be skipped */
 652708                 for (;;) {
<>653 -                        ch = inpch();
  709+                        ch = inch();
654710                 c1:     if (ch != '*')
 655711                                 continue;
<>656 -                        if ((ch = inpch()) == '/')
  712+                        if ((ch = inch()) == '/')
657713                                 break;
 658714                         goto c1;
 659715                 }
     
 !
707763         return ch;
 708764 }
 709765 
<>710 -static int
 711 -inpch(void)
 712 -{
 713 -        int len;
 714 -
 715 -        if (ifiles->curptr < ifiles->maxread)
 716 -                return *ifiles->curptr++;
 717 -
 718 -        if (ifiles->infil == -1)
 719 -                return -1;
 720 -        if ((len = read(ifiles->infil, ifiles->buffer, CPPBUF)) < 0)
 721 -                error("read error on file %s", ifiles->orgfn);
 722 -        if (len == 0)
 723 -                return -1;
 724 -        ifiles->buffer[len] = 0;
 725 -        ifiles->curptr = ifiles->buffer;
 726 -        ifiles->maxread = ifiles->buffer + len;
 727 -        return inpch();
 728 -}
 729 -
 730 -static int
 731 -inch(void)
 732 -{
 733 -        int c;
 734 -
 735 -again:  switch (c = inpch()) {
 736 -        case '\\': /* continued lines */
 737 -msdos:          if ((c = inpch()) == '\n') {
 738 -                        ifiles->lineno++;
 739 -                        putch('\n');
 740 -                        goto again;
 741 -                } else if (c == '\r')
 742 -                        goto msdos;
 743 -                unch(c);
 744 -                return '\\';
 745 -        case '?': /* trigraphs */
 746 -                if ((c = chktg())) {
 747 -                        unch(c);
 748 -                        goto again;
 749 -                }
 750 -                return '?';
 751 -        default:
 752 -                return c;
 753 -        }
 754 -}
 755 -
756766 /*
 757767  * Let the command-line args be faked defines at beginning of file.
 758768  */
     
 !
816826                         return -1;
 817827                 ic->orgfn = ic->fname = file;
 818828                 if (++inclevel > MAX_INCLEVEL)
<>819 -                        error("Limit for nested includes exceeded");
  829+                        error("limit for nested includes exceeded");
820830         } else {
 821831                 ic->infil = 0;
 822832                 ic->orgfn = ic->fname = (const usch *)"<stdin>";
     
 !
828838         ic->curptr = ic->buffer;
 829839         ifiles = ic;
 830840         ic->lineno = 1;
<> 841+        ic->escln = 0;
831842         ic->maxread = ic->curptr;
 832843         ic->idx = idx;
 833844         ic->incs = incs;
     
 !
929940                 rv = rv * rad + dig2num(c);
 930941                 /* check overflow */
 931942                 if (rv / rad < rv2)
<>932 -                        error("Constant \"%s\" is out of range", yytext);
  943+                        error("constant \"%s\" is out of range", yytext);
933944                 rv2 = rv;
 934945                 c = *y++;
 935946         }
     
 !
942953                 yylval.node.op = UNUMBER;
 943954         if (yylval.node.op == NUMBER && yylval.node.nd_val < 0)
 944955                 /* too large for signed, see 6.4.4.1 */
<>945 -                error("Constant \"%s\" is out of range", yytext);
  956+                error("constant \"%s\" is out of range", yytext);
946957 }
 947958 
 948959 static int
     
 !
10181029         if (flslvl) {
 10191030                 if (elflvl > trulvl)
 10201031                         ;
<>1021 -                else if (--flslvl!=0) {
  1032+                else if (--flslvl!=0)
10221033                         flslvl++;
<>1023 -                } else {
  1034+                else
10241035                         trulvl++;
<>1025 -                        prtline();
 1026 -                }
10271036         } else if (trulvl) {
 10281037                 flslvl++;
 10291038                 trulvl--;
 10301039         } else
<>1031 -                error("If-less else");
  1040+                error("#else in non-conditional section");
10321041         if (elslvl==trulvl+flslvl)
<>1033 -                error("Too many else");
  1042+                error("too many #else");
10341043         elslvl=trulvl+flslvl;
 10351044         chknl(1);
 10361045 }
     
 !
10641073         while (t == WSPACE);
 10651074         if (t != IDENT)
 10661075                 error("bad #ifdef");
<>1067 -        if (lookup(yytext, FIND) == NULL) {
 1068 -                putch('\n');
  1076+        if (lookup(yytext, FIND) == NULL)
10691077                 flslvl++;
<>1070 -        } else
  1078+        else
10711079                 trulvl++;
 10721080         chknl(0);
 10731081 }
     
 !
10871095         while (t == WSPACE);
 10881096         if (t != IDENT)
 10891097                 error("bad #ifndef");
<>1090 -        if (lookup(yytext, FIND) != NULL) {
 1091 -                putch('\n');
  1098+        if (lookup(yytext, FIND) != NULL)
10921099                 flslvl++;
<>1093 -        } else
  1100+        else
10941101                 trulvl++;
 10951102         chknl(0);
 10961103 }
 10971104 
 10981105 static void
 10991106 endifstmt(void)         
 11001107 {
<>1101 -        if (flslvl) {
  1108+        if (flslvl)
11021109                 flslvl--;
<>1103 -                if (flslvl == 0) {
 1104 -                        putch('\n');
 1105 -                        prtline();
 1106 -                }
 1107 -        } else if (trulvl)
  1110+        else if (trulvl)
11081111                 trulvl--;
 11091112         else
<>1110 -                error("If-less endif");
  1113+                error("#endif in non-conditional section");
11111114         if (flslvl == 0)
 11121115                 elflvl = 0;
 11131116         elslvl = 0;
     
 !
11171120 static void
 11181121 ifstmt(void)
 11191122 {
<>1120 -        if (flslvl == 0) {
 1121 -                if (yyparse() == 0) {
 1122 -                        putch('\n');
 1123 -                        ++flslvl;
 1124 -                } else
 1125 -                        ++trulvl;
 1126 -        } else
 1127 -                ++flslvl;
  1123+        if (flslvl || yyparse() == 0)
  1124+                flslvl++;
  1125+        else
  1126+                trulvl++;
11281127 }
 11291128 
 11301129 static void
     
 !
11361135                 if (elflvl > trulvl)
 11371136                         ;
 11381137                 else if (--flslvl!=0)
<>1139 -                        ++flslvl;
 1140 -                else {
 1141 -                        if (yyparse()) {
 1142 -                                ++trulvl;
 1143 -                                prtline();
 1144 -                        } else {
 1145 -                                putch('\n');
 1146 -                                ++flslvl;
 1147 -                        }
  1138+                        flslvl++;
  1139+                else if (yyparse())
  1140+                        trulvl++;
  1141+                else
  1142+                        flslvl++;
11481143                 }
 11491144         } else if (trulvl) {
<>1150 -                ++flslvl;
 1151 -                --trulvl;
  1145+                flslvl++;
  1146+                trulvl--;
11521147         } else
<>1153 -                error("If-less elif");
  1148+                error("#elif in non-conditional section");
11541149 }
 11551150 
 11561151 /* save line into stringbuf */
     
 !
12391234         return inch();
 12401235 }
 12411236 
<>1242 -/*
 1243 - * Check for (and convert) trigraphs.
 1244 - */
 1245 -int
 1246 -chktg(void)
 1247 -{
 1248 -        int c;
 1249 -
 1250 -        if ((c = inpch()) != '?') {
 1251 -                unch(c);
 1252 -                return 0;
 1253 -        }
 1254 -        switch (c = inpch()) {
 1255 -        case '=': c = '#'; break;
 1256 -        case '(': c = '['; break;
 1257 -        case ')': c = ']'; break;
 1258 -        case '<': c = '{'; break;
 1259 -        case '>': c = '}'; break;
 1260 -        case '/': c = '\\'; break;
 1261 -        case '\'': c = '^'; break;
 1262 -        case '!': c = '|'; break;
 1263 -        case '-': c = '~'; break;
 1264 -        default:
 1265 -                unch(c);
 1266 -                unch('?');
 1267 -                c = 0;
 1268 -        }
 1269 -        return c;
 1270 -}
 1271 -
<_12721237 static struct {
 12731238         const char *name;
 12741239         void (*fun)(void);
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 17:42 +0100