mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:27:45 +00:00
AK+LibCpp: Remove DEBUG_SPAM in favour of per-application defines
What happens if one file defines DEBUG_SPAM, and another doesn't, then we link them together and get ODR violations? -- @ADKaster
This commit is contained in:
parent
080f2c0e3e
commit
62af7c4bdf
3 changed files with 35 additions and 34 deletions
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, Denis Campredon <deni_@hotmail.fr>
|
* Copyright (c) 2020, Denis Campredon <deni_@hotmail.fr>
|
||||||
|
* Copyright (c) 2021, the SerenityOS developers.
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -10,9 +11,9 @@
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
template<bool = true>
|
||||||
class ScopeLogger {
|
class ScopeLogger {
|
||||||
public:
|
public:
|
||||||
#ifdef DEBUG_SPAM
|
|
||||||
ScopeLogger(StringView extra, const SourceLocation& location = SourceLocation::current())
|
ScopeLogger(StringView extra, const SourceLocation& location = SourceLocation::current())
|
||||||
: m_location(location)
|
: m_location(location)
|
||||||
, m_extra(extra)
|
, m_extra(extra)
|
||||||
|
@ -49,10 +50,15 @@ private:
|
||||||
static inline size_t m_depth = 0;
|
static inline size_t m_depth = 0;
|
||||||
SourceLocation m_location;
|
SourceLocation m_location;
|
||||||
StringView m_extra;
|
StringView m_extra;
|
||||||
#else
|
|
||||||
ScopeLogger() = default;
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
class ScopeLogger<false> {
|
||||||
|
public:
|
||||||
|
template<typename... Args>
|
||||||
|
ScopeLogger(Args...) { }
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
using AK::ScopeLogger;
|
using AK::ScopeLogger;
|
||||||
|
|
|
@ -167,7 +167,6 @@ set(VOLATILE_PAGE_RANGES_DEBUG ON)
|
||||||
set(WSMESSAGELOOP_DEBUG ON)
|
set(WSMESSAGELOOP_DEBUG ON)
|
||||||
set(GPT_DEBUG ON)
|
set(GPT_DEBUG ON)
|
||||||
set(CPP_DEBUG ON)
|
set(CPP_DEBUG ON)
|
||||||
set(DEBUG_SPAM ON)
|
|
||||||
set(DEBUG_CPP_LANGUAGE_SERVER ON)
|
set(DEBUG_CPP_LANGUAGE_SERVER ON)
|
||||||
set(DEBUG_AUTOCOMPLETE ON)
|
set(DEBUG_AUTOCOMPLETE ON)
|
||||||
set(FILE_WATCHER_DEBUG ON)
|
set(FILE_WATCHER_DEBUG ON)
|
||||||
|
|
|
@ -4,10 +4,6 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef CPP_DEBUG
|
|
||||||
# define DEBUG_SPAM
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "Parser.h"
|
#include "Parser.h"
|
||||||
#include "AST.h"
|
#include "AST.h"
|
||||||
#include <AK/Debug.h>
|
#include <AK/Debug.h>
|
||||||
|
@ -54,7 +50,7 @@ void Parser::initialize_program_tokens(const StringView& program)
|
||||||
|
|
||||||
NonnullRefPtr<TranslationUnit> Parser::parse()
|
NonnullRefPtr<TranslationUnit> Parser::parse()
|
||||||
{
|
{
|
||||||
ScopeLogger logger {};
|
ScopeLogger<CPP_DEBUG> logger;
|
||||||
if (m_tokens.is_empty())
|
if (m_tokens.is_empty())
|
||||||
return create_root_ast_node({}, {});
|
return create_root_ast_node({}, {});
|
||||||
auto unit = create_root_ast_node(m_tokens.first().start(), m_tokens.last().end());
|
auto unit = create_root_ast_node(m_tokens.first().start(), m_tokens.last().end());
|
||||||
|
@ -156,7 +152,7 @@ NonnullRefPtr<FunctionDeclaration> Parser::parse_function_declaration(ASTNode& p
|
||||||
|
|
||||||
NonnullRefPtr<FunctionDefinition> Parser::parse_function_definition(ASTNode& parent)
|
NonnullRefPtr<FunctionDefinition> Parser::parse_function_definition(ASTNode& parent)
|
||||||
{
|
{
|
||||||
ScopeLogger logger {};
|
ScopeLogger<CPP_DEBUG> logger;
|
||||||
auto func = create_ast_node<FunctionDefinition>(parent, position(), {});
|
auto func = create_ast_node<FunctionDefinition>(parent, position(), {});
|
||||||
consume(Token::Type::LeftCurly);
|
consume(Token::Type::LeftCurly);
|
||||||
while (!eof() && peek().type() != Token::Type::RightCurly) {
|
while (!eof() && peek().type() != Token::Type::RightCurly) {
|
||||||
|
@ -170,7 +166,7 @@ NonnullRefPtr<FunctionDefinition> Parser::parse_function_definition(ASTNode& par
|
||||||
|
|
||||||
NonnullRefPtr<Statement> Parser::parse_statement(ASTNode& parent)
|
NonnullRefPtr<Statement> Parser::parse_statement(ASTNode& parent)
|
||||||
{
|
{
|
||||||
ScopeLogger logger {};
|
ScopeLogger<CPP_DEBUG> logger;
|
||||||
ArmedScopeGuard consume_semicolon([this]() {
|
ArmedScopeGuard consume_semicolon([this]() {
|
||||||
consume(Token::Type::Semicolon);
|
consume(Token::Type::Semicolon);
|
||||||
});
|
});
|
||||||
|
@ -222,7 +218,7 @@ bool Parser::match_block_statement()
|
||||||
|
|
||||||
NonnullRefPtr<BlockStatement> Parser::parse_block_statement(ASTNode& parent)
|
NonnullRefPtr<BlockStatement> Parser::parse_block_statement(ASTNode& parent)
|
||||||
{
|
{
|
||||||
ScopeLogger logger {};
|
ScopeLogger<CPP_DEBUG> logger;
|
||||||
auto block_statement = create_ast_node<BlockStatement>(parent, position(), {});
|
auto block_statement = create_ast_node<BlockStatement>(parent, position(), {});
|
||||||
consume(Token::Type::LeftCurly);
|
consume(Token::Type::LeftCurly);
|
||||||
while (!eof() && peek().type() != Token::Type::RightCurly) {
|
while (!eof() && peek().type() != Token::Type::RightCurly) {
|
||||||
|
@ -269,7 +265,7 @@ bool Parser::match_template_arguments()
|
||||||
|
|
||||||
NonnullRefPtrVector<Type> Parser::parse_template_arguments(ASTNode& parent)
|
NonnullRefPtrVector<Type> Parser::parse_template_arguments(ASTNode& parent)
|
||||||
{
|
{
|
||||||
ScopeLogger logger {};
|
ScopeLogger<CPP_DEBUG> logger;
|
||||||
|
|
||||||
consume(Token::Type::Less);
|
consume(Token::Type::Less);
|
||||||
|
|
||||||
|
@ -285,7 +281,7 @@ NonnullRefPtrVector<Type> Parser::parse_template_arguments(ASTNode& parent)
|
||||||
|
|
||||||
bool Parser::match_variable_declaration()
|
bool Parser::match_variable_declaration()
|
||||||
{
|
{
|
||||||
ScopeLogger logger {};
|
ScopeLogger<CPP_DEBUG> logger;
|
||||||
save_state();
|
save_state();
|
||||||
ScopeGuard state_guard = [this] { load_state(); };
|
ScopeGuard state_guard = [this] { load_state(); };
|
||||||
|
|
||||||
|
@ -316,7 +312,7 @@ bool Parser::match_variable_declaration()
|
||||||
|
|
||||||
NonnullRefPtr<VariableDeclaration> Parser::parse_variable_declaration(ASTNode& parent, bool expect_semicolon)
|
NonnullRefPtr<VariableDeclaration> Parser::parse_variable_declaration(ASTNode& parent, bool expect_semicolon)
|
||||||
{
|
{
|
||||||
ScopeLogger logger {};
|
ScopeLogger<CPP_DEBUG> logger;
|
||||||
auto var = create_ast_node<VariableDeclaration>(parent, position(), {});
|
auto var = create_ast_node<VariableDeclaration>(parent, position(), {});
|
||||||
if (!match_variable_declaration()) {
|
if (!match_variable_declaration()) {
|
||||||
error("unexpected token for variable type");
|
error("unexpected token for variable type");
|
||||||
|
@ -344,7 +340,7 @@ NonnullRefPtr<VariableDeclaration> Parser::parse_variable_declaration(ASTNode& p
|
||||||
|
|
||||||
NonnullRefPtr<Expression> Parser::parse_expression(ASTNode& parent)
|
NonnullRefPtr<Expression> Parser::parse_expression(ASTNode& parent)
|
||||||
{
|
{
|
||||||
ScopeLogger logger {};
|
ScopeLogger<CPP_DEBUG> logger;
|
||||||
auto expression = parse_primary_expression(parent);
|
auto expression = parse_primary_expression(parent);
|
||||||
// TODO: remove eof() logic, should still work without it
|
// TODO: remove eof() logic, should still work without it
|
||||||
if (eof() || match(Token::Type::Semicolon)) {
|
if (eof() || match(Token::Type::Semicolon)) {
|
||||||
|
@ -406,7 +402,7 @@ bool Parser::match_secondary_expression()
|
||||||
|
|
||||||
NonnullRefPtr<Expression> Parser::parse_primary_expression(ASTNode& parent)
|
NonnullRefPtr<Expression> Parser::parse_primary_expression(ASTNode& parent)
|
||||||
{
|
{
|
||||||
ScopeLogger logger {};
|
ScopeLogger<CPP_DEBUG> logger;
|
||||||
// TODO: remove eof() logic, should still work without it
|
// TODO: remove eof() logic, should still work without it
|
||||||
if (eof()) {
|
if (eof()) {
|
||||||
auto node = create_ast_node<Identifier>(parent, position(), position());
|
auto node = create_ast_node<Identifier>(parent, position(), position());
|
||||||
|
@ -536,7 +532,7 @@ NonnullRefPtr<Expression> Parser::parse_literal(ASTNode& parent)
|
||||||
|
|
||||||
NonnullRefPtr<Expression> Parser::parse_secondary_expression(ASTNode& parent, NonnullRefPtr<Expression> lhs)
|
NonnullRefPtr<Expression> Parser::parse_secondary_expression(ASTNode& parent, NonnullRefPtr<Expression> lhs)
|
||||||
{
|
{
|
||||||
ScopeLogger logger {};
|
ScopeLogger<CPP_DEBUG> logger;
|
||||||
switch (peek().type()) {
|
switch (peek().type()) {
|
||||||
case Token::Type::Plus:
|
case Token::Type::Plus:
|
||||||
return parse_binary_expression(parent, lhs, BinaryOp::Addition);
|
return parse_binary_expression(parent, lhs, BinaryOp::Addition);
|
||||||
|
@ -689,7 +685,7 @@ bool Parser::match_function_declaration()
|
||||||
|
|
||||||
Optional<NonnullRefPtrVector<Parameter>> Parser::parse_parameter_list(ASTNode& parent)
|
Optional<NonnullRefPtrVector<Parameter>> Parser::parse_parameter_list(ASTNode& parent)
|
||||||
{
|
{
|
||||||
ScopeLogger logger {};
|
ScopeLogger<CPP_DEBUG> logger;
|
||||||
NonnullRefPtrVector<Parameter> parameters;
|
NonnullRefPtrVector<Parameter> parameters;
|
||||||
while (peek().type() != Token::Type::RightParen && !eof()) {
|
while (peek().type() != Token::Type::RightParen && !eof()) {
|
||||||
if (match_ellipsis()) {
|
if (match_ellipsis()) {
|
||||||
|
@ -739,7 +735,7 @@ bool Parser::match_preprocessor()
|
||||||
|
|
||||||
void Parser::consume_preprocessor()
|
void Parser::consume_preprocessor()
|
||||||
{
|
{
|
||||||
ScopeLogger logger {};
|
ScopeLogger<CPP_DEBUG> logger;
|
||||||
switch (peek().type()) {
|
switch (peek().type()) {
|
||||||
case Token::Type::PreprocessorStatement:
|
case Token::Type::PreprocessorStatement:
|
||||||
consume();
|
consume();
|
||||||
|
@ -756,7 +752,7 @@ void Parser::consume_preprocessor()
|
||||||
|
|
||||||
Optional<Token> Parser::consume_whitespace()
|
Optional<Token> Parser::consume_whitespace()
|
||||||
{
|
{
|
||||||
ScopeLogger logger {};
|
ScopeLogger<CPP_DEBUG> logger;
|
||||||
return consume(Token::Type::Whitespace);
|
return consume(Token::Type::Whitespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -832,7 +828,7 @@ String Parser::text_in_range(Position start, Position end) const
|
||||||
|
|
||||||
void Parser::error(StringView message)
|
void Parser::error(StringView message)
|
||||||
{
|
{
|
||||||
ScopeLogger logger {};
|
ScopeLogger<CPP_DEBUG> logger;
|
||||||
if (message.is_null() || message.is_empty())
|
if (message.is_null() || message.is_empty())
|
||||||
message = "<empty>";
|
message = "<empty>";
|
||||||
String formatted_message;
|
String formatted_message;
|
||||||
|
@ -937,7 +933,7 @@ void Parser::print_tokens() const
|
||||||
|
|
||||||
NonnullRefPtr<StringLiteral> Parser::parse_string_literal(ASTNode& parent)
|
NonnullRefPtr<StringLiteral> Parser::parse_string_literal(ASTNode& parent)
|
||||||
{
|
{
|
||||||
ScopeLogger logger {};
|
ScopeLogger<CPP_DEBUG> logger;
|
||||||
Optional<size_t> start_token_index;
|
Optional<size_t> start_token_index;
|
||||||
Optional<size_t> end_token_index;
|
Optional<size_t> end_token_index;
|
||||||
while (!eof()) {
|
while (!eof()) {
|
||||||
|
@ -971,7 +967,7 @@ NonnullRefPtr<StringLiteral> Parser::parse_string_literal(ASTNode& parent)
|
||||||
|
|
||||||
NonnullRefPtr<ReturnStatement> Parser::parse_return_statement(ASTNode& parent)
|
NonnullRefPtr<ReturnStatement> Parser::parse_return_statement(ASTNode& parent)
|
||||||
{
|
{
|
||||||
ScopeLogger logger {};
|
ScopeLogger<CPP_DEBUG> logger;
|
||||||
auto return_statement = create_ast_node<ReturnStatement>(parent, position(), {});
|
auto return_statement = create_ast_node<ReturnStatement>(parent, position(), {});
|
||||||
consume(Token::Type::Keyword);
|
consume(Token::Type::Keyword);
|
||||||
if (!peek(Token::Type::Semicolon).has_value()) {
|
if (!peek(Token::Type::Semicolon).has_value()) {
|
||||||
|
@ -984,7 +980,7 @@ NonnullRefPtr<ReturnStatement> Parser::parse_return_statement(ASTNode& parent)
|
||||||
|
|
||||||
NonnullRefPtr<EnumDeclaration> Parser::parse_enum_declaration(ASTNode& parent)
|
NonnullRefPtr<EnumDeclaration> Parser::parse_enum_declaration(ASTNode& parent)
|
||||||
{
|
{
|
||||||
ScopeLogger logger {};
|
ScopeLogger<CPP_DEBUG> logger;
|
||||||
auto enum_decl = create_ast_node<EnumDeclaration>(parent, position(), {});
|
auto enum_decl = create_ast_node<EnumDeclaration>(parent, position(), {});
|
||||||
consume_keyword("enum");
|
consume_keyword("enum");
|
||||||
auto name_token = consume(Token::Type::Identifier);
|
auto name_token = consume(Token::Type::Identifier);
|
||||||
|
@ -1031,7 +1027,7 @@ bool Parser::match_keyword(const String& keyword)
|
||||||
|
|
||||||
NonnullRefPtr<StructOrClassDeclaration> Parser::parse_struct_or_class_declaration(ASTNode& parent, StructOrClassDeclaration::Type type)
|
NonnullRefPtr<StructOrClassDeclaration> Parser::parse_struct_or_class_declaration(ASTNode& parent, StructOrClassDeclaration::Type type)
|
||||||
{
|
{
|
||||||
ScopeLogger logger {};
|
ScopeLogger<CPP_DEBUG> logger;
|
||||||
auto decl = create_ast_node<StructOrClassDeclaration>(parent, position(), {}, type);
|
auto decl = create_ast_node<StructOrClassDeclaration>(parent, position(), {}, type);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case StructOrClassDeclaration::Type::Struct:
|
case StructOrClassDeclaration::Type::Struct:
|
||||||
|
@ -1058,7 +1054,7 @@ NonnullRefPtr<StructOrClassDeclaration> Parser::parse_struct_or_class_declaratio
|
||||||
|
|
||||||
NonnullRefPtr<MemberDeclaration> Parser::parse_member_declaration(ASTNode& parent)
|
NonnullRefPtr<MemberDeclaration> Parser::parse_member_declaration(ASTNode& parent)
|
||||||
{
|
{
|
||||||
ScopeLogger logger {};
|
ScopeLogger<CPP_DEBUG> logger;
|
||||||
auto member_decl = create_ast_node<MemberDeclaration>(parent, position(), {});
|
auto member_decl = create_ast_node<MemberDeclaration>(parent, position(), {});
|
||||||
member_decl->m_type = parse_type(*member_decl);
|
member_decl->m_type = parse_type(*member_decl);
|
||||||
|
|
||||||
|
@ -1077,7 +1073,7 @@ NonnullRefPtr<MemberDeclaration> Parser::parse_member_declaration(ASTNode& paren
|
||||||
|
|
||||||
NonnullRefPtr<BooleanLiteral> Parser::parse_boolean_literal(ASTNode& parent)
|
NonnullRefPtr<BooleanLiteral> Parser::parse_boolean_literal(ASTNode& parent)
|
||||||
{
|
{
|
||||||
ScopeLogger logger {};
|
ScopeLogger<CPP_DEBUG> logger;
|
||||||
auto token = consume(Token::Type::Keyword);
|
auto token = consume(Token::Type::Keyword);
|
||||||
auto text = text_of_token(token);
|
auto text = text_of_token(token);
|
||||||
// text == "true" || text == "false";
|
// text == "true" || text == "false";
|
||||||
|
@ -1096,7 +1092,7 @@ bool Parser::match_boolean_literal()
|
||||||
|
|
||||||
NonnullRefPtr<Type> Parser::parse_type(ASTNode& parent)
|
NonnullRefPtr<Type> Parser::parse_type(ASTNode& parent)
|
||||||
{
|
{
|
||||||
ScopeLogger logger {};
|
ScopeLogger<CPP_DEBUG> logger;
|
||||||
|
|
||||||
if (!match_type()) {
|
if (!match_type()) {
|
||||||
auto token = consume();
|
auto token = consume();
|
||||||
|
@ -1134,7 +1130,7 @@ NonnullRefPtr<Type> Parser::parse_type(ASTNode& parent)
|
||||||
|
|
||||||
NonnullRefPtr<ForStatement> Parser::parse_for_statement(ASTNode& parent)
|
NonnullRefPtr<ForStatement> Parser::parse_for_statement(ASTNode& parent)
|
||||||
{
|
{
|
||||||
ScopeLogger logger {};
|
ScopeLogger<CPP_DEBUG> logger;
|
||||||
auto for_statement = create_ast_node<ForStatement>(parent, position(), {});
|
auto for_statement = create_ast_node<ForStatement>(parent, position(), {});
|
||||||
consume(Token::Type::Keyword);
|
consume(Token::Type::Keyword);
|
||||||
consume(Token::Type::LeftParen);
|
consume(Token::Type::LeftParen);
|
||||||
|
@ -1158,7 +1154,7 @@ NonnullRefPtr<ForStatement> Parser::parse_for_statement(ASTNode& parent)
|
||||||
|
|
||||||
NonnullRefPtr<IfStatement> Parser::parse_if_statement(ASTNode& parent)
|
NonnullRefPtr<IfStatement> Parser::parse_if_statement(ASTNode& parent)
|
||||||
{
|
{
|
||||||
ScopeLogger logger {};
|
ScopeLogger<CPP_DEBUG> logger;
|
||||||
auto if_statement = create_ast_node<IfStatement>(parent, position(), {});
|
auto if_statement = create_ast_node<IfStatement>(parent, position(), {});
|
||||||
consume(Token::Type::Keyword);
|
consume(Token::Type::Keyword);
|
||||||
consume(Token::Type::LeftParen);
|
consume(Token::Type::LeftParen);
|
||||||
|
@ -1176,7 +1172,7 @@ NonnullRefPtr<IfStatement> Parser::parse_if_statement(ASTNode& parent)
|
||||||
}
|
}
|
||||||
Vector<StringView> Parser::parse_type_qualifiers()
|
Vector<StringView> Parser::parse_type_qualifiers()
|
||||||
{
|
{
|
||||||
ScopeLogger logger {};
|
ScopeLogger<CPP_DEBUG> logger;
|
||||||
Vector<StringView> qualifiers;
|
Vector<StringView> qualifiers;
|
||||||
while (!eof()) {
|
while (!eof()) {
|
||||||
auto token = peek();
|
auto token = peek();
|
||||||
|
@ -1195,7 +1191,7 @@ Vector<StringView> Parser::parse_type_qualifiers()
|
||||||
|
|
||||||
Vector<StringView> Parser::parse_function_qualifiers()
|
Vector<StringView> Parser::parse_function_qualifiers()
|
||||||
{
|
{
|
||||||
ScopeLogger logger {};
|
ScopeLogger<CPP_DEBUG> logger;
|
||||||
Vector<StringView> qualifiers;
|
Vector<StringView> qualifiers;
|
||||||
while (!eof()) {
|
while (!eof()) {
|
||||||
auto token = peek();
|
auto token = peek();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue