1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 09:17:35 +00:00

LibJS: Use 'if constexpr' / dbgln_if() instead of '#if LEXER_DEBUG'

This commit is contained in:
Linus Groh 2021-04-18 18:13:27 +02:00
parent 87a43fa87c
commit a178255a8b

View file

@ -1,6 +1,6 @@
/* /*
* Copyright (c) 2020, Stephan Unverwerth <s.unverwerth@gmx.de> * Copyright (c) 2020, Stephan Unverwerth <s.unverwerth@gmx.de>
* Copyright (c) 2020, Linus Groh <mail@linusgroh.de> * Copyright (c) 2020-2021, Linus Groh <mail@linusgroh.de>
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -172,18 +172,18 @@ void Lexer::consume()
return; return;
if (is_line_terminator()) { if (is_line_terminator()) {
#if LEXER_DEBUG if constexpr (LEXER_DEBUG) {
String type; String type;
if (m_current_char == '\n') if (m_current_char == '\n')
type = "LINE FEED"; type = "LINE FEED";
else if (m_current_char == '\r') else if (m_current_char == '\r')
type = "CARRIAGE RETURN"; type = "CARRIAGE RETURN";
else if (m_source[m_position + 1] == (char)0xa8) else if (m_source[m_position + 1] == (char)0xa8)
type = "LINE SEPARATOR"; type = "LINE SEPARATOR";
else else
type = "PARAGRAPH SEPARATOR"; type = "PARAGRAPH SEPARATOR";
dbgln("Found a line terminator: {}", type); dbgln("Found a line terminator: {}", type);
#endif }
// This is a three-char line terminator, we need to increase m_position some more. // This is a three-char line terminator, we need to increase m_position some more.
// We might reach EOF and need to check again. // We might reach EOF and need to check again.
if (m_current_char != '\n' && m_current_char != '\r') { if (m_current_char != '\n' && m_current_char != '\r') {
@ -201,11 +201,9 @@ void Lexer::consume()
if (!second_char_of_crlf) { if (!second_char_of_crlf) {
m_line_number++; m_line_number++;
m_line_column = 1; m_line_column = 1;
#if LEXER_DEBUG dbgln_if(LEXER_DEBUG, "Incremented line number, now at: line {}, column 1", m_line_number);
dbgln("Incremented line number, now at: line {}, column 1", m_line_number);
} else { } else {
dbgln("Previous was CR, this is LF - not incrementing line number again."); dbgln_if(LEXER_DEBUG, "Previous was CR, this is LF - not incrementing line number again.");
#endif
} }
} else { } else {
m_line_column++; m_line_column++;
@ -642,14 +640,14 @@ Token Lexer::next()
value_start_line_number, value_start_line_number,
value_start_column_number); value_start_column_number);
#if LEXER_DEBUG if constexpr (LEXER_DEBUG) {
dbgln("------------------------------"); dbgln("------------------------------");
dbgln("Token: {}", m_current_token.name()); dbgln("Token: {}", m_current_token.name());
dbgln("Trivia: _{}_", m_current_token.trivia()); dbgln("Trivia: _{}_", m_current_token.trivia());
dbgln("Value: _{}_", m_current_token.value()); dbgln("Value: _{}_", m_current_token.value());
dbgln("Line: {}, Column: {}", m_current_token.line_number(), m_current_token.line_column()); dbgln("Line: {}, Column: {}", m_current_token.line_number(), m_current_token.line_column());
dbgln("------------------------------"); dbgln("------------------------------");
#endif }
return m_current_token; return m_current_token;
} }