Skip to content

Commit

Permalink
Preprocessor: ignore newlines before func-like macro left paren
Browse files Browse the repository at this point in the history
  • Loading branch information
ehaas committed Jul 26, 2024
1 parent e6fe13a commit 0d8bfae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
16 changes: 13 additions & 3 deletions src/aro/Preprocessor.zig
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ fn readExpandNewline(pp: *Preprocessor) Error!PreprocessorToken {
return pp.readExpand();
},
.func => {
if (!try pp.next(.l_paren)) return tok;
if (!try pp.getMacroLParen()) return tok;
const arg_tokens_start = pp.macro_arg_tokens.items.len;
defer pp.macro_arg_tokens.items.len = arg_tokens_start;
const macro_args_start = pp.macro_args.items.len;
Expand Down Expand Up @@ -1129,6 +1129,17 @@ fn next(pp: *Preprocessor, id: Tokenizer.Token.Id) !bool {
return false;
}

fn getMacroLParen(pp: *Preprocessor) !bool {
while (true) {
const tok = pp.getToken();
if (tok.id == .nl) continue;

if (tok.id == .l_paren) return true;
try pp.ungetToken(tok);
return false;
}
}

/// Returns true for vararg function-like macro, false otherwise
fn readFunclikeMacroParams(pp: *Preprocessor, name: PreprocessorToken, l_paren: PreprocessorToken, params: *ParamMap) !bool {
_ = name;
Expand Down Expand Up @@ -2017,7 +2028,7 @@ pub fn prettyPrintTokens(pp: *Preprocessor, w: anytype) !void {

try pp.printLinemarker(w, line_col.line_no, source, .@"resume");
last_nl = true;
},
},
else => try pp.prettyPrintToken(w, cur),
}
}
Expand Down Expand Up @@ -2065,7 +2076,6 @@ fn printLinemarker(
try w.writeByte('\n');
}


fn prettyPrintToken(pp: *Preprocessor, w: anytype, tok: Token) !void {
if (tok.flags.is_bol) {
try w.writeByte('\n');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1);
f(2 * (2+(3,4)-0,1)) | f(2 * (\~{ } 5)) & f(2 * (0,1))
^m(0,1);
int i[] = { 1, 23, 4, 5, };
f(2 * (2+(3,4)-0,1)) | f(2 * (\~{ } 5)) & f(2 * (0,1))^m(0,1);
int i[] = { 1, 23, 4, 5, };
char c[2][6] = { "hello", "" };

0 comments on commit 0d8bfae

Please sign in to comment.