Skip to content

Commit 21d9a61

Browse files
committed
Rework inclusion path tokenization
1 parent 8dad2a8 commit 21d9a61

File tree

8 files changed

+240
-279
lines changed

8 files changed

+240
-279
lines changed

src/defs.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,7 @@ typedef enum {
200200
T_newline,
201201
T_backslash,
202202
T_whitespace,
203-
T_tab,
204-
T_inclusion_path
203+
T_tab
205204
} token_kind_t;
206205

207206
/* Source location tracking for better error reporting */

src/globals.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
*/
77

88
#pragma once
9+
#ifndef __SHECC_
910
#include <stdbool.h>
1011
#include <stdio.h>
1112
#include <stdlib.h>
1213
#include <string.h>
14+
#endif
1315

1416
#include "defs.h"
1517

@@ -1617,9 +1619,6 @@ void dbg_token(token_t *token)
16171619
case T_backslash:
16181620
name = "T_backslash";
16191621
break;
1620-
case T_inclusion_path:
1621-
name = "T_inclusion_path";
1622-
break;
16231622
default:
16241623
name = "<unknown>";
16251624
break;

src/lexer.c

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
* file "LICENSE" for information on usage and redistribution of this file.
66
*/
77

8+
#ifndef __SHECC_
89
#include <stdbool.h>
10+
#endif
911

1012
#include "defs.h"
1113
#include "globals.c"
@@ -301,30 +303,6 @@ token_t *lex_token_nt(strbuf_t *buf, source_location_t *loc, token_t *prev)
301303

302304
loc->pos = buf->size;
303305

304-
/* Special treatment on file inclusion path syntax */
305-
if (prev && prev->kind == T_cppd_include && (ch == '<' || ch == '"')) {
306-
int sz = 0;
307-
char closed_ch = ch;
308-
309-
ch = read(buf);
310-
311-
while (ch && ch != closed_ch) {
312-
token_buffer[sz++] = ch;
313-
ch = read(buf);
314-
}
315-
316-
if (!ch)
317-
error_at("Unenclosed inclusion path", loc);
318-
319-
read(buf);
320-
token_buffer[sz] = '\0';
321-
322-
token = new_token(T_inclusion_path, loc, sz + 2);
323-
token->literal = arena_strdup(TOKEN_ARENA, token_buffer);
324-
loc->column += sz + 2;
325-
return token;
326-
}
327-
328306
if (ch == '#') {
329307
if (loc->column != 1)
330308
error_at("Directive must be on the start of line", loc);

src/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
* file "LICENSE" for information on usage and redistribution of this file.
66
*/
77

8+
#ifndef __SHECC_
89
#include <stdbool.h>
910
#include <stdio.h>
1011
#include <stdlib.h>
1112
#include <string.h>
13+
#endif
1214

1315
/* Define target machine */
1416
#include "../config"

src/parser.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
* file "LICENSE" for information on usage and redistribution of this file.
66
*/
77

8+
#ifndef __SHECC_
89
#include <stdbool.h>
910
#include <stdio.h>
1011
#include <stdlib.h>
12+
#endif
1113

1214
#include "../config"
1315
#include "defs.h"

src/peephole.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
* file "LICENSE" for information on usage and redistribution of this file.
66
*/
77

8+
#ifndef __SHECC_
89
#include <stdbool.h>
10+
#endif
911

1012
#include "defs.h"
1113
#include "globals.c"

0 commit comments

Comments
 (0)