From a178255a8b358b2c89014dc789203a81c3d213a5 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sun, 18 Apr 2021 18:13:27 +0200 Subject: [PATCH] LibJS: Use 'if constexpr' / dbgln_if() instead of '#if LEXER_DEBUG' --- Userland/Libraries/LibJS/Lexer.cpp | 48 ++++++++++++++---------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/Userland/Libraries/LibJS/Lexer.cpp b/Userland/Libraries/LibJS/Lexer.cpp index 8a9a3d27f3..35cbc2f0a2 100644 --- a/Userland/Libraries/LibJS/Lexer.cpp +++ b/Userland/Libraries/LibJS/Lexer.cpp @@ -1,6 +1,6 @@ /* * Copyright (c) 2020, Stephan Unverwerth - * Copyright (c) 2020, Linus Groh + * Copyright (c) 2020-2021, Linus Groh * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -172,18 +172,18 @@ void Lexer::consume() return; if (is_line_terminator()) { -#if LEXER_DEBUG - String type; - if (m_current_char == '\n') - type = "LINE FEED"; - else if (m_current_char == '\r') - type = "CARRIAGE RETURN"; - else if (m_source[m_position + 1] == (char)0xa8) - type = "LINE SEPARATOR"; - else - type = "PARAGRAPH SEPARATOR"; - dbgln("Found a line terminator: {}", type); -#endif + if constexpr (LEXER_DEBUG) { + String type; + if (m_current_char == '\n') + type = "LINE FEED"; + else if (m_current_char == '\r') + type = "CARRIAGE RETURN"; + else if (m_source[m_position + 1] == (char)0xa8) + type = "LINE SEPARATOR"; + else + type = "PARAGRAPH SEPARATOR"; + dbgln("Found a line terminator: {}", type); + } // This is a three-char line terminator, we need to increase m_position some more. // We might reach EOF and need to check again. if (m_current_char != '\n' && m_current_char != '\r') { @@ -201,11 +201,9 @@ void Lexer::consume() if (!second_char_of_crlf) { m_line_number++; m_line_column = 1; -#if LEXER_DEBUG - dbgln("Incremented line number, now at: line {}, column 1", m_line_number); + dbgln_if(LEXER_DEBUG, "Incremented line number, now at: line {}, column 1", m_line_number); } else { - dbgln("Previous was CR, this is LF - not incrementing line number again."); -#endif + dbgln_if(LEXER_DEBUG, "Previous was CR, this is LF - not incrementing line number again."); } } else { m_line_column++; @@ -642,14 +640,14 @@ Token Lexer::next() value_start_line_number, value_start_column_number); -#if LEXER_DEBUG - dbgln("------------------------------"); - dbgln("Token: {}", m_current_token.name()); - dbgln("Trivia: _{}_", m_current_token.trivia()); - dbgln("Value: _{}_", m_current_token.value()); - dbgln("Line: {}, Column: {}", m_current_token.line_number(), m_current_token.line_column()); - dbgln("------------------------------"); -#endif + if constexpr (LEXER_DEBUG) { + dbgln("------------------------------"); + dbgln("Token: {}", m_current_token.name()); + dbgln("Trivia: _{}_", m_current_token.trivia()); + dbgln("Value: _{}_", m_current_token.value()); + dbgln("Line: {}, Column: {}", m_current_token.line_number(), m_current_token.line_column()); + dbgln("------------------------------"); + } return m_current_token; }