Skip to content

Commit

Permalink
Fix macro call argument issue
Browse files Browse the repository at this point in the history
  • Loading branch information
gjcoram committed Jul 14, 2024
1 parent 47df3de commit f170b6e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion openvaf/preprocessor/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use ahash::AHashMap;
use stdx::{impl_debug_display, impl_idx_from};
use text_size::{TextRange, TextSize};
use tokens::parser::SyntaxKind;
use tokens::SyntaxKind::{L_PAREN, R_PAREN};
// use tracing::{debug, debug_span, trace};
use typed_index_collections::{TiSlice, TiVec};
use vfs::{FileId, VfsPath};
Expand Down Expand Up @@ -166,12 +167,23 @@ impl<'a> Processor<'a> {
})
.collect();

if new_args.len() == def.arg_cnt {
if new_args.len() == def.arg_cnt || def.arg_cnt == 0 {
let ctx = self.source_map.add_ctx(def.span.to_file_span(&self.source_map), span);
for ParsedToken { kind, range } in &def.body {
let span = CtxSpan { range: range - def.span.range.start(), ctx };
self.process_macro_token(kind, span, &new_args, dst, errors)
}
if new_args.len() > def.arg_cnt {
// macro definition has no arguments, but some were parsed as part of the call
// so put the arguments back
dst.push( Token { kind:L_PAREN, span } );
for arg in new_args {
for tok in arg {
dst.push(tok)
}
}
dst.push( Token { kind:R_PAREN, span } );
}
} else {
errors.push(MacroArgumentCountMismatch {
expected: def.arg_cnt,
Expand Down

0 comments on commit f170b6e

Please sign in to comment.