LibCpp: Consume attribute specification when parsing

Consume __atribute__(...), without actually parsing its content.
This commit is contained in:
Itamar 2021-03-01 22:32:42 +02:00 committed by Andreas Kling
parent 5a7abb8363
commit 5c79297b2c
Notes: sideshowbarker 2024-07-18 21:46:52 +09:00
2 changed files with 32 additions and 0 deletions

View File

@ -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;
}
}
}

View File

@ -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();
};
}