From b3b3c8bcd07e644fdba9167f927ad8dee4a255db Mon Sep 17 00:00:00 2001 From: nsfisis Date: Tue, 26 Aug 2025 20:43:21 +0900 Subject: feat: support nop preprocessing directive --- src/preprocess.c | 11 +++++++++++ src/token.c | 2 ++ src/token.h | 1 + 3 files changed, 14 insertions(+) (limited to 'src') diff --git a/src/preprocess.c b/src/preprocess.c index c96c194..2a53059 100644 --- a/src/preprocess.c +++ b/src/preprocess.c @@ -176,6 +176,10 @@ static TokenKind pplexer_tokenize_pp_directive(PpLexer* ppl) { break; infile_next_char(ppl->src); } + // '#' new-line + if (c == '\n') { + return TokenKind_pp_directive_nop; + } SourceLocation pp_directive_name_start_loc = ppl->src->loc; @@ -935,6 +939,11 @@ static void process_pragma_directive(Preprocessor* pp, int directive_token_pos) unimplemented(); } +static void process_nop_directive(Preprocessor* pp, int directive_token_pos) { + next_pp_token(pp); + remove_directive_tokens(pp, directive_token_pos, pp->pos); +} + // ws ::= many0() // macro-arguments ::= '(' opt( many0(',' )) ')' static MacroArgArray* pp_parse_macro_arguments(Preprocessor* pp) { @@ -1047,6 +1056,8 @@ static void process_pp_directive(Preprocessor* pp) { process_error_directive(pp, first_token_pos); } else if (tok->kind == TokenKind_pp_directive_pragma) { process_pragma_directive(pp, first_token_pos); + } else if (tok->kind == TokenKind_pp_directive_nop) { + process_nop_directive(pp, first_token_pos); } else if (tok->kind == TokenKind_ident) { BOOL expanded = expand_macro(pp); if (expanded) { diff --git a/src/token.c b/src/token.c index 40463cd..71eabaf 100644 --- a/src/token.c +++ b/src/token.c @@ -44,6 +44,8 @@ const char* token_kind_stringify(TokenKind k) { return "#include"; else if (k == TokenKind_pp_directive_line) return "#line"; + else if (k == TokenKind_pp_directive_nop) + return "#"; else if (k == TokenKind_pp_directive_pragma) return "#pragma"; else if (k == TokenKind_pp_directive_undef) diff --git a/src/token.h b/src/token.h index 6f5fb2a..034b3b3 100644 --- a/src/token.h +++ b/src/token.h @@ -27,6 +27,7 @@ enum TokenKind { TokenKind_pp_directive_ifndef, TokenKind_pp_directive_include, TokenKind_pp_directive_line, + TokenKind_pp_directive_nop, TokenKind_pp_directive_pragma, TokenKind_pp_directive_undef, TokenKind_pp_directive_warning, -- cgit v1.2.3-70-g09d2