Prechádzať zdrojové kódy

AK+LibC: Add TODO() as an alternative to ASSERT_NOT_REACHED()

I've been using this in the new HTML parser and it makes it much easier
to understand the state of unfinished code branches.

TODO() is for places where it's okay to end up but we need to implement
something there.

ASSERT_NOT_REACHED() is for places where it's not okay to end up, and
something has gone wrong.
Andreas Kling 5 rokov pred
rodič
commit
1ef5d609d9

+ 1 - 0
AK/Assertions.h

@@ -36,6 +36,7 @@
 #            define ASSERT assert
 #            define ASSERT_NOT_REACHED() assert(false)
 #            define RELEASE_ASSERT assert
+#            define TODO ASSERT_NOT_REACHED
 #        endif
 #    endif
 

+ 1 - 0
AK/TestSuite.h

@@ -37,6 +37,7 @@
 
 #define ASSERT_NOT_REACHED() fprintf(stderr, "\033[31;1mASSERT_NOT_REACHED\033[0m\n");
 #define RELEASE_ASSERT ASSERT
+#define TODO ASSERT_NOT_REACHED
 
 #include <AK/Function.h>
 #include <AK/NonnullRefPtrVector.h>

+ 1 - 0
Kernel/Assertions.h

@@ -47,3 +47,4 @@
     } while (0)
 #define ASSERT_INTERRUPTS_DISABLED() ASSERT(!(cpu_flags() & 0x200))
 #define ASSERT_INTERRUPTS_ENABLED() ASSERT(cpu_flags() & 0x200)
+#define TODO ASSERT_NOT_REACHED

+ 1 - 0
Libraries/LibC/assert.h

@@ -51,5 +51,6 @@ __attribute__((noreturn)) void __assertion_failed(const char* msg);
     } while (0)
 #define ASSERT assert
 #define RELEASE_ASSERT assert
+#define TODO ASSERT_NOT_REACHED
 
 __END_DECLS

+ 0 - 5
Libraries/LibWeb/Parser/HTMLDocumentParser.cpp

@@ -39,11 +39,6 @@
 #include <LibWeb/Parser/HTMLDocumentParser.h>
 #include <LibWeb/Parser/HTMLToken.h>
 
-#define TODO()                \
-    do {                      \
-        ASSERT_NOT_REACHED(); \
-    } while (0)
-
 #define PARSE_ERROR()                                                         \
     do {                                                                      \
         dbg() << "Parse error! " << __PRETTY_FUNCTION__ << " @ " << __LINE__; \

+ 0 - 6
Libraries/LibWeb/Parser/HTMLTokenizer.cpp

@@ -37,12 +37,6 @@
 #define CONSUME_NEXT_INPUT_CHARACTER \
     current_input_character = next_codepoint();
 
-#define TODO()                                                                                              \
-    do {                                                                                                    \
-        dbg() << "[TODO: " << state_name(m_state) << "] '" << (char)current_input_character.value() << "'"; \
-        ASSERT_NOT_REACHED();                                                                               \
-    } while (0)
-
 #define SWITCH_TO(new_state)              \
     do {                                  \
         will_switch_to(State::new_state); \