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
201201 unsigned char *buf_end;
202202 int fd;
203203 int line_num; /* current line number - here to simply code */
204+ int *ifdef_stack_ptr; /* ifdef_stack value at the start of the file */
204205 char filename[1024]; /* current filename - here to simplify code */
205206 unsigned char buffer[IO_BUF_SIZE + 1]; /* extra size for CH_EOB char */
206207 } BufferedFile;
@@ -229,7 +230,9 @@ struct BufferedFile *file; · 22 unmodified lines
229230 int ch, ch1, tok, tok1;
230231 CValue tokc, tok1c;
231232 CString tokcstr; /* current parsed string, if any */
232−int 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 */
235+int return_linefeed;
233236
234237 /* sections */
235238 Section **sections;
@@ -1040,7 +1043,7 @@ void skip(int c) · 804 unmodified lines
10401043 next();
10411044 }
10421045
1043−void test_lvalue(void)
1046+static void test_lvalue(void)
10441047 {
10451048 if (!(vtop->r & VT_LVAL))
10461049 expect("lvalue");
@@ -1051,8 +1054,6 @@ TokenSym *tok_alloc(const char *str, int len) · 4 unmodified lines
10511054 TokenSym *ts, **pts, **ptable;
10521055 int h, i;
10531056
1054− if (len <= 0)
1055− len = strlen(str);
10561057 h = 1;
10571058 for(i=0;i<len;i++)
10581059 h = (h * 263 + ((unsigned char *)str)[i]) & (TOK_HASH_SIZE - 1);
@@ -1397,6 +1398,7 @@ BufferedFile *tcc_open(const char *filename) · 338 unmodified lines
13971398 bf->buffer[0] = CH_EOB; /* put eob symbol */
13981399 pstrcpy(bf->filename, sizeof(bf->filename), filename);
13991400 bf->line_num = 1;
1401+ bf->ifdef_stack_ptr = ifdef_stack_ptr;
14001402 // printf("opening '%s'\n", filename);
14011403 return bf;
14021404 }
@@ -1444,7 +1446,10 @@ void handle_eob(void) · 41 unmodified lines
14441446 ch1 = tcc_getc_slow(file);
14451447 if (ch1 != CH_EOF)
14461448 return;
1447−
1449+ if (return_linefeed) {
1450+ ch1 = '\n';
1451+ return;
1452+ }
14481453 if (include_stack_ptr == include_stack)
14491454 return;
14501455 /* add end of include file debug info */
@@ -1732,7 +1737,7 @@ int expr_preprocess(void) · 281 unmodified lines
17321737 TokenString str;
17331738
17341739 tok_str_new(&str);
1735− while (tok != TOK_LINEFEED && tok != TOK_EOF) {
1740+ while (tok != TOK_LINEFEED) {
17361741 next(); /* do macro subst */
17371742 if (tok == TOK_DEFINED) {
17381743 next_nomacro();
@@ -1817,12 +1822,11 @@ void parse_define(void) · 78 unmodified lines
18171822 t = MACRO_FUNC;
18181823 }
18191824 tok_str_new(&str);
1820− while (1) {
1821− skip_spaces();
1822− if (ch == '\n' || ch == CH_EOF)
1823− break;
1824− next_nomacro();
1825+ next_nomacro();
1826+ /* EOF testing necessary for '-D' handling */
1827+ while (tok != TOK_LINEFEED && tok != TOK_EOF) {
18251828 tok_str_add2(&str, tok, &tokc);
1829+ next_nomacro();
18261830 }
18271831 tok_str_add(&str, 0);
18281832 #ifdef PP_DEBUG
@@ -1991,7 +1995,7 @@ void preprocess(void) · 162 unmodified lines
19911995 goto redo;
19921996 }
19931997 } else if (tok == TOK_ENDIF) {
1994− if (ifdef_stack_ptr == ifdef_stack)
1998+ if (ifdef_stack_ptr <= file->ifdef_stack_ptr)
19951999 error("#endif without matching #if");
19962000 ifdef_stack_ptr--;
19972001 } else if (tok == TOK_LINE) {
@@ -2013,7 +2017,7 @@ void preprocess(void) · 15 unmodified lines
20132017 error("#error");
20142018 }
20152019 /* ignore other preprocess commands or #! for C scripts */
2016− while (tok != TOK_LINEFEED && tok != TOK_EOF)
2020+ while (tok != TOK_LINEFEED)
20172021 next_nomacro();
20182022 the_end:
20192023 return_linefeed = 0;
@@ -2640,7 +2644,7 @@ int *macro_twosharps(int *macro_str) · 620 unmodified lines
26402644 pstrcpy(token_buf, sizeof(token_buf), p);
26412645 p = get_tok_str(t, &cval);
26422646 pstrcat(token_buf, sizeof(token_buf), p);
2643− ts = tok_alloc(token_buf, 0);
2647+ ts = tok_alloc(token_buf, strlen(token_buf));
26442648 tok = ts->tok; /* modify current token */
26452649 } else {
26462650 /* cannot merge tokens: skip '##' */
@@ -6652,7 +6656,10 @@ static int tcc_compile(TCCState *s) · 4005 unmodified lines
66526656
66536657 funcname = "";
66546658 include_stack_ptr = include_stack;
6659+ /* XXX: move that before to avoid having to initialize
6660+ file->ifdef_stack_ptr ? */
66556661 ifdef_stack_ptr = ifdef_stack;
6662+ file->ifdef_stack_ptr = ifdef_stack_ptr;
66566663
66576664 /* XXX: not ANSI compliant: bound checking says error */
66586665 vtop = vstack - 1;
@@ -6774,7 +6781,7 @@ void tcc_undefine_symbol(TCCState *s1, const char *sym) · 115 unmodified lines
67746781 {
67756782 TokenSym *ts;
67766783 Sym *s;
6777− ts = tok_alloc(sym, 0);
6784+ ts = tok_alloc(sym, strlen(sym));
67786785 s = sym_find1(&define_stack, tok);
67796786 /* undefine symbol by putting an invalid name */
67806787 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