mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-21 02:08:12 +03:00
LibCpp: Consume attribute specification when parsing
Consume __atribute__(...), without actually parsing its content.
This commit is contained in:
parent
5a7abb8363
commit
5c79297b2c
Notes:
sideshowbarker
2024-07-18 21:46:52 +09:00
Author: https://github.com/itamar8910 Commit: https://github.com/SerenityOS/serenity/commit/5c79297b2c9 Pull-request: https://github.com/SerenityOS/serenity/pull/5591
@ -136,6 +136,8 @@ NonnullRefPtr<FunctionDeclaration> Parser::parse_function_declaration(ASTNode& p
|
||||
func_end = body->end();
|
||||
} else {
|
||||
func_end = position();
|
||||
if (match_attribute_specification())
|
||||
consume_attribute_specification(); // we don't use the value of __attribute__
|
||||
consume(Token::Type::Semicolon);
|
||||
}
|
||||
|
||||
@ -545,6 +547,11 @@ bool Parser::match_function_declaration()
|
||||
if (peek(Token::Type::Semicolon).has_value() || peek(Token::Type::LeftCurly).has_value())
|
||||
return true;
|
||||
|
||||
if (match_attribute_specification()) {
|
||||
consume_attribute_specification();
|
||||
return peek(Token::Type::Semicolon).has_value();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1057,4 +1064,27 @@ Vector<StringView> Parser::parse_type_qualifiers()
|
||||
}
|
||||
return qualifiers;
|
||||
}
|
||||
bool Parser::match_attribute_specification()
|
||||
{
|
||||
return text_of_token(peek()) == "__attribute__";
|
||||
}
|
||||
void Parser::consume_attribute_specification()
|
||||
{
|
||||
consume(); // __attribute__
|
||||
consume(Token::Type::LeftParen);
|
||||
size_t left_count = 1;
|
||||
while (!done()) {
|
||||
auto token = consume();
|
||||
if (token.type() == Token::Type::LeftParen) {
|
||||
++left_count;
|
||||
}
|
||||
if (token.type() == Token::Type::RightParen) {
|
||||
--left_count;
|
||||
}
|
||||
if(left_count == 0)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -161,6 +161,8 @@ private:
|
||||
NonnullRefPtrVector<ASTNode> m_nodes;
|
||||
Vector<String> m_errors;
|
||||
Vector<StringView> parse_type_qualifiers();
|
||||
bool match_attribute_specification();
|
||||
void consume_attribute_specification();
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user