diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-08-26 20:43:21 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-08-26 20:43:21 +0900 |
| commit | b3b3c8bcd07e644fdba9167f927ad8dee4a255db (patch) | |
| tree | bedc96885ce9235a49cb9d7864cf94ff673fd4c7 /src | |
| parent | 467d3de2dea0cb50ab9b6f1a426486c57f64f1b6 (diff) | |
| download | ducc-b3b3c8bcd07e644fdba9167f927ad8dee4a255db.tar.gz ducc-b3b3c8bcd07e644fdba9167f927ad8dee4a255db.tar.zst ducc-b3b3c8bcd07e644fdba9167f927ad8dee4a255db.zip | |
feat: support nop preprocessing directive
Diffstat (limited to 'src')
| -rw-r--r-- | src/preprocess.c | 11 | ||||
| -rw-r--r-- | src/token.c | 2 | ||||
| -rw-r--r-- | src/token.h | 1 |
3 files changed, 14 insertions, 0 deletions
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(<Whitespace>) // macro-arguments ::= '(' <ws> opt(<any-token> <ws> many0(',' <ws> <any-token> <ws>)) ')' 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, |
