mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-12 02:30:30 +09:00
LibCpp: Fix parsing of macro calls
Previously, macro calls with 0 arguments where incorrectly parsed as calls to a macro with a single argument that doesn't contain any tokens.
This commit is contained in:
parent
53c6c36fba
commit
597ca68e2d
Notes:
sideshowbarker
2024-07-17 16:23:45 +09:00
Author: https://github.com/itamar8910
Commit: 597ca68e2d
Pull-request: https://github.com/SerenityOS/serenity/pull/13377
1 changed files with 8 additions and 4 deletions
|
@ -277,7 +277,7 @@ Optional<Preprocessor::MacroCall> Preprocessor::parse_macro_call(Vector<Token> c
|
||||||
++token_index;
|
++token_index;
|
||||||
|
|
||||||
Vector<MacroCall::Argument> arguments;
|
Vector<MacroCall::Argument> arguments;
|
||||||
MacroCall::Argument current_argument;
|
Optional<MacroCall::Argument> current_argument;
|
||||||
|
|
||||||
size_t paren_depth = 1;
|
size_t paren_depth = 1;
|
||||||
for (; token_index < tokens.size(); ++token_index) {
|
for (; token_index < tokens.size(); ++token_index) {
|
||||||
|
@ -288,15 +288,19 @@ Optional<Preprocessor::MacroCall> Preprocessor::parse_macro_call(Vector<Token> c
|
||||||
--paren_depth;
|
--paren_depth;
|
||||||
|
|
||||||
if (paren_depth == 0) {
|
if (paren_depth == 0) {
|
||||||
arguments.append(move(current_argument));
|
if (current_argument.has_value())
|
||||||
|
arguments.append(*current_argument);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (paren_depth == 1 && token.type() == Token::Type::Comma) {
|
if (paren_depth == 1 && token.type() == Token::Type::Comma) {
|
||||||
arguments.append(move(current_argument));
|
if (current_argument.has_value())
|
||||||
|
arguments.append(*current_argument);
|
||||||
current_argument = {};
|
current_argument = {};
|
||||||
} else {
|
} else {
|
||||||
current_argument.tokens.append(token);
|
if (!current_argument.has_value())
|
||||||
|
current_argument = MacroCall::Argument {};
|
||||||
|
current_argument->tokens.append(token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue