Browse Source

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

Linus Groh 4 years ago
parent
commit
a178255a8b
1 changed files with 23 additions and 25 deletions
  1. 23 25
      Userland/Libraries/LibJS/Lexer.cpp

+ 23 - 25
Userland/Libraries/LibJS/Lexer.cpp

@@ -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
-        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.
         // 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("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 {
         } 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 {
     } 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
-    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;
     return m_current_token;
 }
 }