mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:37:45 +00:00
Everywhere: Turn #if *_DEBUG into dbgln_if/if constexpr
This commit is contained in:
parent
4e6f03a860
commit
6cf59b6ae9
58 changed files with 315 additions and 469 deletions
|
@ -10,8 +10,6 @@
|
|||
#include "LibRegex/RegexMatcher.h"
|
||||
#include <AK/Debug.h>
|
||||
|
||||
#if REGEX_DEBUG
|
||||
|
||||
namespace regex {
|
||||
|
||||
class RegexDebug {
|
||||
|
@ -131,5 +129,3 @@ private:
|
|||
}
|
||||
|
||||
using regex::RegexDebug;
|
||||
|
||||
#endif
|
||||
|
|
|
@ -130,9 +130,8 @@ Token Lexer::next()
|
|||
case '\\':
|
||||
return 2;
|
||||
default:
|
||||
#if REGEX_DEBUG
|
||||
fprintf(stderr, "[LEXER] Found invalid escape sequence: \\%c (the parser will have to deal with this!)\n", peek(1));
|
||||
#endif
|
||||
if constexpr (REGEX_DEBUG)
|
||||
fprintf(stderr, "[LEXER] Found invalid escape sequence: \\%c (the parser will have to deal with this!)\n", peek(1));
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -148,9 +148,8 @@ Parser::Result Parser::parse(Optional<AllOptions> regex_options)
|
|||
else
|
||||
set_error(Error::InvalidPattern);
|
||||
|
||||
#if REGEX_DEBUG
|
||||
fprintf(stderr, "[PARSER] Produced bytecode with %lu entries (opcodes + arguments)\n", m_parser_state.bytecode.size());
|
||||
#endif
|
||||
if constexpr (REGEX_DEBUG)
|
||||
fprintf(stderr, "[PARSER] Produced bytecode with %lu entries (opcodes + arguments)\n", m_parser_state.bytecode.size());
|
||||
return {
|
||||
move(m_parser_state.bytecode),
|
||||
move(m_parser_state.capture_groups_count),
|
||||
|
@ -461,9 +460,8 @@ ALWAYS_INLINE bool PosixExtendedParser::parse_sub_expression(ByteCode& stack, si
|
|||
if (match(TokenType::EscapeSequence)) {
|
||||
length = 1;
|
||||
Token t = consume();
|
||||
#if REGEX_DEBUG
|
||||
printf("[PARSER] EscapeSequence with substring %s\n", String(t.value()).characters());
|
||||
#endif
|
||||
if constexpr (REGEX_DEBUG)
|
||||
printf("[PARSER] EscapeSequence with substring %s\n", String(t.value()).characters());
|
||||
|
||||
bytecode.insert_bytecode_compare_values({ { CharacterCompareType::Char, (u32)t.value().characters_without_null_termination()[1] } });
|
||||
should_parse_repetition_symbol = true;
|
||||
|
|
|
@ -356,21 +356,21 @@ TEST_CASE(ini_file_entries)
|
|||
Regex<PosixExtended> re("[[:alpha:]]*=([[:digit:]]*)|\\[(.*)\\]");
|
||||
RegexResult result;
|
||||
|
||||
#if REGEX_DEBUG
|
||||
RegexDebug regex_dbg(stderr);
|
||||
regex_dbg.print_raw_bytecode(re);
|
||||
regex_dbg.print_header();
|
||||
regex_dbg.print_bytecode(re);
|
||||
#endif
|
||||
if constexpr (REGEX_DEBUG) {
|
||||
RegexDebug regex_dbg(stderr);
|
||||
regex_dbg.print_raw_bytecode(re);
|
||||
regex_dbg.print_header();
|
||||
regex_dbg.print_bytecode(re);
|
||||
}
|
||||
|
||||
String haystack = "[Window]\nOpacity=255\nAudibleBeep=0\n";
|
||||
EXPECT_EQ(re.search(haystack.view(), result, PosixFlags::Multiline), true);
|
||||
EXPECT_EQ(result.count, 3u);
|
||||
|
||||
#if REGEX_DEBUG
|
||||
for (auto& v : result.matches)
|
||||
fprintf(stderr, "%s\n", v.view.to_string().characters());
|
||||
#endif
|
||||
if constexpr (REGEX_DEBUG) {
|
||||
for (auto& v : result.matches)
|
||||
fprintf(stderr, "%s\n", v.view.to_string().characters());
|
||||
}
|
||||
|
||||
EXPECT_EQ(result.matches.at(0).view, "[Window]");
|
||||
EXPECT_EQ(result.capture_group_matches.at(0).at(0).view, "Window");
|
||||
|
@ -405,12 +405,12 @@ TEST_CASE(named_capture_group)
|
|||
Regex<PosixExtended> re("[[:alpha:]]*=(?<Test>[[:digit:]]*)");
|
||||
RegexResult result;
|
||||
|
||||
#if REGEX_DEBUG
|
||||
RegexDebug regex_dbg(stderr);
|
||||
regex_dbg.print_raw_bytecode(re);
|
||||
regex_dbg.print_header();
|
||||
regex_dbg.print_bytecode(re);
|
||||
#endif
|
||||
if constexpr (REGEX_DEBUG) {
|
||||
RegexDebug regex_dbg(stderr);
|
||||
regex_dbg.print_raw_bytecode(re);
|
||||
regex_dbg.print_header();
|
||||
regex_dbg.print_bytecode(re);
|
||||
}
|
||||
|
||||
String haystack = "[Window]\nOpacity=255\nAudibleBeep=0\n";
|
||||
EXPECT_EQ(re.search(haystack, result, PosixFlags::Multiline), true);
|
||||
|
@ -426,12 +426,12 @@ TEST_CASE(a_star)
|
|||
Regex<PosixExtended> re("a*");
|
||||
RegexResult result;
|
||||
|
||||
#if REGEX_DEBUG
|
||||
RegexDebug regex_dbg(stderr);
|
||||
regex_dbg.print_raw_bytecode(re);
|
||||
regex_dbg.print_header();
|
||||
regex_dbg.print_bytecode(re);
|
||||
#endif
|
||||
if constexpr (REGEX_DEBUG) {
|
||||
RegexDebug regex_dbg(stderr);
|
||||
regex_dbg.print_raw_bytecode(re);
|
||||
regex_dbg.print_header();
|
||||
regex_dbg.print_bytecode(re);
|
||||
}
|
||||
|
||||
String haystack = "[Window]\nOpacity=255\nAudibleBeep=0\n";
|
||||
EXPECT_EQ(re.search(haystack.view(), result, PosixFlags::Multiline), true);
|
||||
|
@ -488,14 +488,14 @@ TEST_CASE(ECMA262_parse)
|
|||
for (auto& test : tests) {
|
||||
Regex<ECMA262> re(test.pattern);
|
||||
EXPECT_EQ(re.parser_result.error, test.expected_error);
|
||||
#if REGEX_DEBUG
|
||||
dbgln("\n");
|
||||
RegexDebug regex_dbg(stderr);
|
||||
regex_dbg.print_raw_bytecode(re);
|
||||
regex_dbg.print_header();
|
||||
regex_dbg.print_bytecode(re);
|
||||
dbgln("\n");
|
||||
#endif
|
||||
if constexpr (REGEX_DEBUG) {
|
||||
dbgln("\n");
|
||||
RegexDebug regex_dbg(stderr);
|
||||
regex_dbg.print_raw_bytecode(re);
|
||||
regex_dbg.print_header();
|
||||
regex_dbg.print_bytecode(re);
|
||||
dbgln("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -550,14 +550,14 @@ TEST_CASE(ECMA262_match)
|
|||
|
||||
for (auto& test : tests) {
|
||||
Regex<ECMA262> re(test.pattern, test.options);
|
||||
#if REGEX_DEBUG
|
||||
dbgln("\n");
|
||||
RegexDebug regex_dbg(stderr);
|
||||
regex_dbg.print_raw_bytecode(re);
|
||||
regex_dbg.print_header();
|
||||
regex_dbg.print_bytecode(re);
|
||||
dbgln("\n");
|
||||
#endif
|
||||
if constexpr (REGEX_DEBUG) {
|
||||
dbgln("\n");
|
||||
RegexDebug regex_dbg(stderr);
|
||||
regex_dbg.print_raw_bytecode(re);
|
||||
regex_dbg.print_header();
|
||||
regex_dbg.print_bytecode(re);
|
||||
dbgln("\n");
|
||||
}
|
||||
EXPECT_EQ(re.parser_result.error, Error::NoError);
|
||||
EXPECT_EQ(re.match(test.subject).success, test.matches);
|
||||
}
|
||||
|
@ -583,14 +583,14 @@ TEST_CASE(replace)
|
|||
|
||||
for (auto& test : tests) {
|
||||
Regex<ECMA262> re(test.pattern, test.options);
|
||||
#if REGEX_DEBUG
|
||||
dbgln("\n");
|
||||
RegexDebug regex_dbg(stderr);
|
||||
regex_dbg.print_raw_bytecode(re);
|
||||
regex_dbg.print_header();
|
||||
regex_dbg.print_bytecode(re);
|
||||
dbgln("\n");
|
||||
#endif
|
||||
if constexpr (REGEX_DEBUG) {
|
||||
dbgln("\n");
|
||||
RegexDebug regex_dbg(stderr);
|
||||
regex_dbg.print_raw_bytecode(re);
|
||||
regex_dbg.print_header();
|
||||
regex_dbg.print_bytecode(re);
|
||||
dbgln("\n");
|
||||
}
|
||||
EXPECT_EQ(re.parser_result.error, Error::NoError);
|
||||
EXPECT_EQ(re.replace(test.subject, test.replacement), test.expected);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue