comparison lwcc/lex.c @ 305:54f213c8fb81 ccdev

Various bugfixes and output tuning Tuned output of preprocessor to include line markers similar to the ones added by the gcc preprocessor. Also, many fixes for various bits of dumbosity leading to misbehaviour and crashing.
author William Astle <lost@l-w.ca>
date Wed, 18 Sep 2013 19:17:52 -0600
parents d85d173ba120
children b08787e5b9f3
comparison
equal deleted inserted replaced
304:d85d173ba120 305:54f213c8fb81
189 189
190 /* This function puts a byte back onto the front of the input stream used 190 /* This function puts a byte back onto the front of the input stream used
191 by fetch_byte(). Theoretically, an unlimited number of characters can 191 by fetch_byte(). Theoretically, an unlimited number of characters can
192 be unfetched. Line and column counting may be incorrect if unfetched 192 be unfetched. Line and column counting may be incorrect if unfetched
193 characters cross a token boundary. */ 193 characters cross a token boundary. */
194 static void preproc_lex_unfetch_byte(struct preproc_info *pp, int c) 194 void preproc_lex_unfetch_byte(struct preproc_info *pp, int c)
195 { 195 {
196 if (pp -> ungetbufl >= pp -> ungetbufs) 196 if (pp -> ungetbufl >= pp -> ungetbufs)
197 { 197 {
198 pp -> ungetbufs += 100; 198 pp -> ungetbufs += 100;
199 pp -> ungetbuf = lw_realloc(pp -> ungetbuf, pp -> ungetbufs); 199 pp -> ungetbuf = lw_realloc(pp -> ungetbuf, pp -> ungetbufs);
273 * backslash-newline will be interpreted 273 * backslash-newline will be interpreted
274 * any instance of CR, LF, CRLF, or LFCR will be interpreted as TOK_EOL 274 * any instance of CR, LF, CRLF, or LFCR will be interpreted as TOK_EOL
275 */ 275 */
276 276
277 277
278 static int preproc_lex_fetch_byte(struct preproc_info *pp) 278 int preproc_lex_fetch_byte(struct preproc_info *pp)
279 { 279 {
280 int c; 280 int c;
281 c = fetch_byte(pp); 281 c = fetch_byte(pp);
282 if (c == CPP_EOF && pp -> eolseen == 0) 282 if (c == CPP_EOF && pp -> eolseen == 0)
283 { 283 {
316 /* block comment */ 316 /* block comment */
317 c = ' '; 317 c = ' ';
318 for (;;) 318 for (;;)
319 { 319 {
320 c2 = fetch_byte(pp); 320 c2 = fetch_byte(pp);
321 if (c2 == CPP_EOL || c2 == CPP_EOF) 321 if (c2 == CPP_EOF)
322 { 322 {
323 preproc_lex_unfetch_byte(pp, c); 323 preproc_lex_unfetch_byte(pp, c);
324 break; 324 break;
325 } 325 }
326 if (c2 == '*') 326 if (c2 == '*')
360 if (pp -> nlseen == 0) 360 if (pp -> nlseen == 0)
361 { 361 {
362 c = CPP_EOL; 362 c = CPP_EOL;
363 } 363 }
364 } 364 }
365
366 if (pp -> lineno != sline)
367 {
368 sline = pp -> lineno;
369 scol = pp -> column;
370 }
365 371
366 if (c == CPP_EOF) 372 if (c == CPP_EOF)
367 { 373 {
368 /* check if we fell off the end of an include file */ 374 /* check if we fell off the end of an include file */
369 if (pp -> filestack) 375 if (pp -> filestack)
637 643
638 case '"': 644 case '"':
639 strlit: 645 strlit:
640 /* string literal */ 646 /* string literal */
641 strbuf = strbuf_new(); 647 strbuf = strbuf_new();
648 strbuf_add(strbuf, '"');
642 for (;;) 649 for (;;)
643 { 650 {
644 c = preproc_lex_fetch_byte(pp); 651 c = preproc_lex_fetch_byte(pp);
645 if (c == CPP_EOF || c == CPP_EOL) 652 if (c == CPP_EOF || c == CPP_EOL)
646 { 653 {
668 strbuf_add(strbuf, c); 675 strbuf_add(strbuf, c);
669 continue; 676 continue;
670 } 677 }
671 strbuf_add(strbuf, c); 678 strbuf_add(strbuf, c);
672 } 679 }
680 strbuf_add(strbuf, '"');
673 strval = strbuf_end(strbuf); 681 strval = strbuf_end(strbuf);
674 ttype = TOK_STR_LIT; 682 ttype = TOK_STR_LIT;
675 goto out; 683 goto out;
676 684
677 case 'L': 685 case 'L':