History

force #if #endif match in same file

bellard committed 24 years ago

Commit 509fa601 parent 405c8811 file · +22 −15Browse files

Unified · Split

tcc.c+22−15
@@ -201,6 +201,7 @@ typedef struct BufferedFile { · 200 unmodified lines
201 unsigned char *buf_end;201 unsigned char *buf_end;
202 int fd;202 int fd;
203 int line_num; /* current line number - here to simply code */203 int line_num; /* current line number - here to simply code */
204 int *ifdef_stack_ptr; /* ifdef_stack value at the start of the file */
204 char filename[1024]; /* current filename - here to simplify code */205 char filename[1024]; /* current filename - here to simplify code */
205 unsigned char buffer[IO_BUF_SIZE + 1]; /* extra size for CH_EOB char */206 unsigned char buffer[IO_BUF_SIZE + 1]; /* extra size for CH_EOB char */
206} BufferedFile;207} BufferedFile;
@@ -229,7 +230,9 @@ struct BufferedFile *file; · 22 unmodified lines
229int ch, ch1, tok, tok1;230int ch, ch1, tok, tok1;
230CValue tokc, tok1c;231CValue tokc, tok1c;
231CString tokcstr; /* current parsed string, if any */232CString tokcstr; /* current parsed string, if any */
232int return_linefeed; /* if true, line feed is returned as a token */233/* if true, line feed is returned as a token. line feed is also
234 returned at eof */
235int return_linefeed;
233 236
234/* sections */237/* sections */
235Section **sections;238Section **sections;
@@ -1040,7 +1043,7 @@ void skip(int c) · 804 unmodified lines
1040 next();1043 next();
1041}1044}
1042 1045
1043void test_lvalue(void)1046static void test_lvalue(void)
1044{1047{
1045 if (!(vtop->r & VT_LVAL))1048 if (!(vtop->r & VT_LVAL))
1046 expect("lvalue");1049 expect("lvalue");
@@ -1051,8 +1054,6 @@ TokenSym *tok_alloc(const char *str, int len) · 4 unmodified lines
1051 TokenSym *ts, **pts, **ptable;1054 TokenSym *ts, **pts, **ptable;
1052 int h, i;1055 int h, i;
1053 1056
1054 if (len <= 0)
1055 len = strlen(str);
1056 h = 1;1057 h = 1;
1057 for(i=0;i<len;i++)1058 for(i=0;i<len;i++)
1058 h = (h * 263 + ((unsigned char *)str)[i]) & (TOK_HASH_SIZE - 1);1059 h = (h * 263 + ((unsigned char *)str)[i]) & (TOK_HASH_SIZE - 1);
@@ -1397,6 +1398,7 @@ BufferedFile *tcc_open(const char *filename) · 338 unmodified lines
1397 bf->buffer[0] = CH_EOB; /* put eob symbol */1398 bf->buffer[0] = CH_EOB; /* put eob symbol */
1398 pstrcpy(bf->filename, sizeof(bf->filename), filename);1399 pstrcpy(bf->filename, sizeof(bf->filename), filename);
1399 bf->line_num = 1;1400 bf->line_num = 1;
1401 bf->ifdef_stack_ptr = ifdef_stack_ptr;
1400 // printf("opening '%s'\n", filename);1402 // printf("opening '%s'\n", filename);
1401 return bf;1403 return bf;
1402}1404}
@@ -1444,7 +1446,10 @@ void handle_eob(void) · 41 unmodified lines
1444 ch1 = tcc_getc_slow(file);1446 ch1 = tcc_getc_slow(file);
1445 if (ch1 != CH_EOF)1447 if (ch1 != CH_EOF)
1446 return;1448 return;
1447 1449 if (return_linefeed) {
1450 ch1 = '\n';
1451 return;
1452 }
1448 if (include_stack_ptr == include_stack)1453 if (include_stack_ptr == include_stack)
1449 return;1454 return;
1450 /* add end of include file debug info */1455 /* add end of include file debug info */
@@ -1732,7 +1737,7 @@ int expr_preprocess(void) · 281 unmodified lines
1732 TokenString str;1737 TokenString str;
1733 1738
1734 tok_str_new(&str);1739 tok_str_new(&str);
1735 while (tok != TOK_LINEFEED && tok != TOK_EOF) {1740 while (tok != TOK_LINEFEED) {
1736 next(); /* do macro subst */1741 next(); /* do macro subst */
1737 if (tok == TOK_DEFINED) {1742 if (tok == TOK_DEFINED) {
1738 next_nomacro();1743 next_nomacro();
@@ -1817,12 +1822,11 @@ void parse_define(void) · 78 unmodified lines
1817 t = MACRO_FUNC;1822 t = MACRO_FUNC;
1818 }1823 }
1819 tok_str_new(&str);1824 tok_str_new(&str);
1820 while (1) {1825 next_nomacro();
1821 skip_spaces();1826 /* EOF testing necessary for '-D' handling */
1822 if (ch == '\n' || ch == CH_EOF)1827 while (tok != TOK_LINEFEED && tok != TOK_EOF) {
1823 break;
1824 next_nomacro();
1825 tok_str_add2(&str, tok, &tokc);1828 tok_str_add2(&str, tok, &tokc);
1829 next_nomacro();
1826 }1830 }
1827 tok_str_add(&str, 0);1831 tok_str_add(&str, 0);
1828#ifdef PP_DEBUG1832#ifdef PP_DEBUG
@@ -1991,7 +1995,7 @@ void preprocess(void) · 162 unmodified lines
1991 goto redo;1995 goto redo;
1992 }1996 }
1993 } else if (tok == TOK_ENDIF) {1997 } else if (tok == TOK_ENDIF) {
1994 if (ifdef_stack_ptr == ifdef_stack)1998 if (ifdef_stack_ptr <= file->ifdef_stack_ptr)
1995 error("#endif without matching #if");1999 error("#endif without matching #if");
1996 ifdef_stack_ptr--;2000 ifdef_stack_ptr--;
1997 } else if (tok == TOK_LINE) {2001 } else if (tok == TOK_LINE) {
@@ -2013,7 +2017,7 @@ void preprocess(void) · 15 unmodified lines
2013 error("#error");2017 error("#error");
2014 }2018 }
2015 /* ignore other preprocess commands or #! for C scripts */2019 /* ignore other preprocess commands or #! for C scripts */
2016 while (tok != TOK_LINEFEED && tok != TOK_EOF)2020 while (tok != TOK_LINEFEED)
2017 next_nomacro();2021 next_nomacro();
2018 the_end:2022 the_end:
2019 return_linefeed = 0;2023 return_linefeed = 0;
@@ -2640,7 +2644,7 @@ int *macro_twosharps(int *macro_str) · 620 unmodified lines
2640 pstrcpy(token_buf, sizeof(token_buf), p);2644 pstrcpy(token_buf, sizeof(token_buf), p);
2641 p = get_tok_str(t, &cval);2645 p = get_tok_str(t, &cval);
2642 pstrcat(token_buf, sizeof(token_buf), p);2646 pstrcat(token_buf, sizeof(token_buf), p);
2643 ts = tok_alloc(token_buf, 0);2647 ts = tok_alloc(token_buf, strlen(token_buf));
2644 tok = ts->tok; /* modify current token */2648 tok = ts->tok; /* modify current token */
2645 } else {2649 } else {
2646 /* cannot merge tokens: skip '##' */2650 /* cannot merge tokens: skip '##' */
@@ -6652,7 +6656,10 @@ static int tcc_compile(TCCState *s) · 4005 unmodified lines
6652 6656
6653 funcname = "";6657 funcname = "";
6654 include_stack_ptr = include_stack;6658 include_stack_ptr = include_stack;
6659 /* XXX: move that before to avoid having to initialize
6660 file->ifdef_stack_ptr ? */
6655 ifdef_stack_ptr = ifdef_stack;6661 ifdef_stack_ptr = ifdef_stack;
6662 file->ifdef_stack_ptr = ifdef_stack_ptr;
6656 6663
6657 /* XXX: not ANSI compliant: bound checking says error */6664 /* XXX: not ANSI compliant: bound checking says error */
6658 vtop = vstack - 1;6665 vtop = vstack - 1;
@@ -6774,7 +6781,7 @@ void tcc_undefine_symbol(TCCState *s1, const char *sym) · 115 unmodified lines
6774{6781{
6775 TokenSym *ts;6782 TokenSym *ts;
6776 Sym *s;6783 Sym *s;
6777 ts = tok_alloc(sym, 0);6784 ts = tok_alloc(sym, strlen(sym));
6778 s = sym_find1(&define_stack, tok);6785 s = sym_find1(&define_stack, tok);
6779 /* undefine symbol by putting an invalid name */6786 /* undefine symbol by putting an invalid name */
6780 if (s)6787 if (s)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t