summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@gmail.com>2021-07-23 13:06:31 +0100
committerAndreas Kling <kling@serenityos.org>2021-07-31 00:18:11 +0200
commite54531244fc9791ce5adab65e33b4512bd5baaf6 (patch)
treeef07989dcb26369272df75877ceef9f608f125f7 /Userland/Libraries/LibWeb
parentaf045cee228cdbb779ae2d9bfc440f8a24f1fdea (diff)
downloadserenity-e54531244fc9791ce5adab65e33b4512bd5baaf6.zip
LibWeb: Define proper debug symbols for CSS Parser and Tokenizer
You can now turn debug logging for them on using `CSS_PARSER_DEBUG` and `CSS_TOKENIZER_DEBUG`.
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp57
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/Tokenizer.cpp51
2 files changed, 53 insertions, 55 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
index f9d9929f06..121433b6f4 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
@@ -6,6 +6,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <AK/Debug.h>
#include <AK/NonnullRefPtrVector.h>
#include <AK/SourceLocation.h>
#include <LibWeb/CSS/CSSStyleDeclaration.h>
@@ -21,11 +22,9 @@
#include <LibWeb/DOM/Document.h>
#include <LibWeb/Dump.h>
-#define CSS_PARSER_TRACE 1
-
static void log_parse_error(const SourceLocation& location = SourceLocation::current())
{
- dbgln_if(CSS_PARSER_TRACE, "Parse error (CSS) {}", location);
+ dbgln_if(CSS_PARSER_DEBUG, "Parse error (CSS) {}", location);
}
namespace Web::CSS {
@@ -160,7 +159,7 @@ NonnullRefPtr<CSSStyleSheet> Parser::parse_as_stylesheet()
template<typename T>
NonnullRefPtr<CSSStyleSheet> Parser::parse_as_stylesheet(TokenStream<T>& tokens)
{
- dbgln_if(CSS_PARSER_TRACE, "Parser::parse_as_stylesheet");
+ dbgln_if(CSS_PARSER_DEBUG, "Parser::parse_as_stylesheet");
auto parser_rules = consume_a_list_of_rules(tokens, true);
NonnullRefPtrVector<CSSRule> rules;
@@ -184,7 +183,7 @@ NonnullRefPtrVector<Selector> Parser::parse_a_selector()
template<typename T>
NonnullRefPtrVector<Selector> Parser::parse_a_selector(TokenStream<T>& tokens)
{
- dbgln_if(CSS_PARSER_TRACE, "Parser::parse_a_selector");
+ dbgln_if(CSS_PARSER_DEBUG, "Parser::parse_a_selector");
auto comma_separated_lists = parse_as_comma_separated_list_of_component_values(tokens);
NonnullRefPtrVector<Selector> selectors;
@@ -207,7 +206,7 @@ NonnullRefPtrVector<Selector> Parser::parse_a_relative_selector()
template<typename T>
NonnullRefPtrVector<Selector> Parser::parse_a_relative_selector(TokenStream<T>& tokens)
{
- dbgln_if(CSS_PARSER_TRACE, "Parser::parse_a_relative_selector");
+ dbgln_if(CSS_PARSER_DEBUG, "Parser::parse_a_relative_selector");
auto comma_separated_lists = parse_as_comma_separated_list_of_component_values(tokens);
@@ -226,7 +225,7 @@ NonnullRefPtrVector<Selector> Parser::parse_a_relative_selector(TokenStream<T>&
template<typename T>
RefPtr<Selector> Parser::parse_single_selector(TokenStream<T>& tokens, bool is_relative)
{
- dbgln_if(CSS_PARSER_TRACE, "Parser::parse_single_selector");
+ dbgln_if(CSS_PARSER_DEBUG, "Parser::parse_single_selector");
// FIXME: Bring this all in line with the spec. https://www.w3.org/TR/selectors-4/
@@ -572,7 +571,7 @@ NonnullRefPtrVector<StyleRule> Parser::consume_a_list_of_rules(bool top_level)
template<typename T>
NonnullRefPtrVector<StyleRule> Parser::consume_a_list_of_rules(TokenStream<T>& tokens, bool top_level)
{
- dbgln_if(CSS_PARSER_TRACE, "Parser::consume_a_list_of_rules");
+ dbgln_if(CSS_PARSER_DEBUG, "Parser::consume_a_list_of_rules");
NonnullRefPtrVector<StyleRule> rules;
@@ -625,7 +624,7 @@ NonnullRefPtr<StyleRule> Parser::consume_an_at_rule()
template<typename T>
NonnullRefPtr<StyleRule> Parser::consume_an_at_rule(TokenStream<T>& tokens)
{
- dbgln_if(CSS_PARSER_TRACE, "Parser::consume_an_at_rule");
+ dbgln_if(CSS_PARSER_DEBUG, "Parser::consume_an_at_rule");
auto& name_ident = tokens.next_token();
VERIFY(name_ident.is(Token::Type::AtKeyword));
@@ -665,7 +664,7 @@ RefPtr<StyleRule> Parser::consume_a_qualified_rule()
template<typename T>
RefPtr<StyleRule> Parser::consume_a_qualified_rule(TokenStream<T>& tokens)
{
- dbgln_if(CSS_PARSER_TRACE, "Parser::consume_a_qualified_rule");
+ dbgln_if(CSS_PARSER_DEBUG, "Parser::consume_a_qualified_rule");
NonnullRefPtr<StyleRule> rule = create<StyleRule>(StyleRule::Type::Qualified);
@@ -695,7 +694,7 @@ RefPtr<StyleRule> Parser::consume_a_qualified_rule(TokenStream<T>& tokens)
template<>
StyleComponentValueRule Parser::consume_a_component_value(TokenStream<StyleComponentValueRule>& tokens)
{
- dbgln_if(CSS_PARSER_TRACE, "Parser::consume_a_component_value - shortcut: '{}'", tokens.peek_token().to_debug_string());
+ dbgln_if(CSS_PARSER_DEBUG, "Parser::consume_a_component_value - shortcut: '{}'", tokens.peek_token().to_debug_string());
return tokens.next_token();
}
@@ -703,7 +702,7 @@ StyleComponentValueRule Parser::consume_a_component_value(TokenStream<StyleCompo
template<typename T>
StyleComponentValueRule Parser::consume_a_component_value(TokenStream<T>& tokens)
{
- dbgln_if(CSS_PARSER_TRACE, "Parser::consume_a_component_value");
+ dbgln_if(CSS_PARSER_DEBUG, "Parser::consume_a_component_value");
auto& token = tokens.next_token();
@@ -729,7 +728,7 @@ NonnullRefPtr<StyleBlockRule> Parser::consume_a_simple_block()
template<typename T>
NonnullRefPtr<StyleBlockRule> Parser::consume_a_simple_block(TokenStream<T>& tokens)
{
- dbgln_if(CSS_PARSER_TRACE, "Parser::consume_a_simple_block");
+ dbgln_if(CSS_PARSER_DEBUG, "Parser::consume_a_simple_block");
auto ending_token = ((Token)tokens.current_token()).mirror_variant();
@@ -762,7 +761,7 @@ NonnullRefPtr<StyleFunctionRule> Parser::consume_a_function()
template<typename T>
NonnullRefPtr<StyleFunctionRule> Parser::consume_a_function(TokenStream<T>& tokens)
{
- dbgln_if(CSS_PARSER_TRACE, "Parser::consume_a_function");
+ dbgln_if(CSS_PARSER_DEBUG, "Parser::consume_a_function");
auto name_ident = tokens.current_token();
VERIFY(name_ident.is(Token::Type::Function));
@@ -795,7 +794,7 @@ Optional<StyleDeclarationRule> Parser::consume_a_declaration()
template<typename T>
Optional<StyleDeclarationRule> Parser::consume_a_declaration(TokenStream<T>& tokens)
{
- dbgln_if(CSS_PARSER_TRACE, "Parser::consume_a_declaration");
+ dbgln_if(CSS_PARSER_DEBUG, "Parser::consume_a_declaration");
auto& token = tokens.next_token();
@@ -857,7 +856,7 @@ Vector<DeclarationOrAtRule> Parser::consume_a_list_of_declarations()
template<typename T>
Vector<DeclarationOrAtRule> Parser::consume_a_list_of_declarations(TokenStream<T>& tokens)
{
- dbgln_if(CSS_PARSER_TRACE, "Parser::consume_a_list_of_declarations");
+ dbgln_if(CSS_PARSER_DEBUG, "Parser::consume_a_list_of_declarations");
Vector<DeclarationOrAtRule> list;
@@ -920,7 +919,7 @@ RefPtr<CSSRule> Parser::parse_as_rule()
template<typename T>
RefPtr<CSSRule> Parser::parse_as_rule(TokenStream<T>& tokens)
{
- dbgln_if(CSS_PARSER_TRACE, "Parser::parse_as_rule");
+ dbgln_if(CSS_PARSER_DEBUG, "Parser::parse_as_rule");
RefPtr<CSSRule> rule;
@@ -959,7 +958,7 @@ NonnullRefPtrVector<CSSRule> Parser::parse_as_list_of_rules()
template<typename T>
NonnullRefPtrVector<CSSRule> Parser::parse_as_list_of_rules(TokenStream<T>& tokens)
{
- dbgln_if(CSS_PARSER_TRACE, "Parser::parse_as_list_of_rules");
+ dbgln_if(CSS_PARSER_DEBUG, "Parser::parse_as_list_of_rules");
auto parsed_rules = consume_a_list_of_rules(tokens, false);
NonnullRefPtrVector<CSSRule> rules;
@@ -981,7 +980,7 @@ Optional<StyleProperty> Parser::parse_as_declaration()
template<typename T>
Optional<StyleProperty> Parser::parse_as_declaration(TokenStream<T>& tokens)
{
- dbgln_if(CSS_PARSER_TRACE, "Parser::parse_as_declaration");
+ dbgln_if(CSS_PARSER_DEBUG, "Parser::parse_as_declaration");
tokens.skip_whitespace();
@@ -1006,7 +1005,7 @@ RefPtr<CSSStyleDeclaration> Parser::parse_as_list_of_declarations()
template<typename T>
RefPtr<CSSStyleDeclaration> Parser::parse_as_list_of_declarations(TokenStream<T>& tokens)
{
- dbgln_if(CSS_PARSER_TRACE, "Parser::parse_as_list_of_declarations");
+ dbgln_if(CSS_PARSER_DEBUG, "Parser::parse_as_list_of_declarations");
auto declarations_and_at_rules = consume_a_list_of_declarations(tokens);
@@ -1043,7 +1042,7 @@ Optional<StyleComponentValueRule> Parser::parse_as_component_value()
template<typename T>
Optional<StyleComponentValueRule> Parser::parse_as_component_value(TokenStream<T>& tokens)
{
- dbgln_if(CSS_PARSER_TRACE, "Parser::parse_as_component_value");
+ dbgln_if(CSS_PARSER_DEBUG, "Parser::parse_as_component_value");
tokens.skip_whitespace();
@@ -1073,7 +1072,7 @@ Vector<StyleComponentValueRule> Parser::parse_as_list_of_component_values()
template<typename T>
Vector<StyleComponentValueRule> Parser::parse_as_list_of_component_values(TokenStream<T>& tokens)
{
- dbgln_if(CSS_PARSER_TRACE, "Parser::parse_as_list_of_component_values");
+ dbgln_if(CSS_PARSER_DEBUG, "Parser::parse_as_list_of_component_values");
Vector<StyleComponentValueRule> rules;
@@ -1096,7 +1095,7 @@ Vector<Vector<StyleComponentValueRule>> Parser::parse_as_comma_separated_list_of
template<typename T>
Vector<Vector<StyleComponentValueRule>> Parser::parse_as_comma_separated_list_of_component_values(TokenStream<T>& tokens)
{
- dbgln_if(CSS_PARSER_TRACE, "Parser::parse_as_comma_separated_list_of_component_values");
+ dbgln_if(CSS_PARSER_DEBUG, "Parser::parse_as_comma_separated_list_of_component_values");
Vector<Vector<StyleComponentValueRule>> lists;
lists.append({});
@@ -1146,7 +1145,7 @@ Optional<URL> Parser::parse_url_function(ParsingContext const& context, StyleCom
RefPtr<CSSRule> Parser::convert_to_rule(NonnullRefPtr<StyleRule> rule)
{
- dbgln_if(CSS_PARSER_TRACE, "Parser::convert_to_rule");
+ dbgln_if(CSS_PARSER_DEBUG, "Parser::convert_to_rule");
if (rule->m_type == StyleRule::Type::At) {
if (rule->m_name.equals_ignoring_case("import"sv) && !rule->prelude().is_empty()) {
@@ -1192,7 +1191,7 @@ RefPtr<CSSRule> Parser::convert_to_rule(NonnullRefPtr<StyleRule> rule)
RefPtr<CSSStyleDeclaration> Parser::convert_to_declaration(NonnullRefPtr<StyleBlockRule> block)
{
- dbgln_if(CSS_PARSER_TRACE, "Parser::convert_to_declaration");
+ dbgln_if(CSS_PARSER_DEBUG, "Parser::convert_to_declaration");
if (!block->is_curly())
return {};
@@ -1203,7 +1202,7 @@ RefPtr<CSSStyleDeclaration> Parser::convert_to_declaration(NonnullRefPtr<StyleBl
Optional<StyleProperty> Parser::convert_to_style_property(StyleDeclarationRule& declaration)
{
- dbgln_if(CSS_PARSER_TRACE, "Parser::convert_to_style_property");
+ dbgln_if(CSS_PARSER_DEBUG, "Parser::convert_to_style_property");
auto& property_name = declaration.m_name;
auto property_id = property_id_from_string(property_name);
@@ -1634,7 +1633,7 @@ RefPtr<StyleValue> Parser::parse_image_value(ParsingContext const& context, Styl
RefPtr<StyleValue> Parser::parse_css_value(PropertyID property_id, TokenStream<StyleComponentValueRule>& tokens)
{
- dbgln_if(CSS_PARSER_TRACE, "Parser::parse_css_value");
+ dbgln_if(CSS_PARSER_DEBUG, "Parser::parse_css_value");
Vector<StyleComponentValueRule> component_values;
@@ -1663,7 +1662,7 @@ RefPtr<StyleValue> Parser::parse_css_value(PropertyID property_id, TokenStream<S
RefPtr<StyleValue> Parser::parse_css_value(ParsingContext const& context, PropertyID property_id, StyleComponentValueRule const& component_value)
{
- dbgln_if(CSS_PARSER_TRACE, "Parser::parse_css_value '{}'", component_value.to_debug_string());
+ dbgln_if(CSS_PARSER_DEBUG, "Parser::parse_css_value '{}'", component_value.to_debug_string());
// FIXME: Figure out if we still need takes_integer_value, and if so, move this information
// into Properties.json.
auto takes_integer_value = [](PropertyID property_id) -> bool {
@@ -1704,7 +1703,7 @@ RefPtr<StyleValue> Parser::parse_css_value(ParsingContext const& context, Proper
Optional<Selector::SimpleSelector::NthChildPattern> Parser::parse_nth_child_pattern(TokenStream<StyleComponentValueRule>& values)
{
- dbgln_if(CSS_PARSER_TRACE, "Parser::parse_nth_child_pattern");
+ dbgln_if(CSS_PARSER_DEBUG, "Parser::parse_nth_child_pattern");
Selector::SimpleSelector::NthChildPattern pattern;
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Tokenizer.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Tokenizer.cpp
index 4e7d53cdc6..87c51ae0b7 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/Tokenizer.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Parser/Tokenizer.cpp
@@ -5,20 +5,19 @@
*/
#include <AK/CharacterTypes.h>
+#include <AK/Debug.h>
#include <AK/SourceLocation.h>
#include <AK/Vector.h>
#include <LibTextCodec/Decoder.h>
#include <LibWeb/CSS/Parser/Tokenizer.h>
-#define CSS_TOKENIZER_TRACE 0
-
//U+FFFD REPLACEMENT CHARACTER (�)
#define REPLACEMENT_CHARACTER 0xFFFD
static const u32 TOKENIZER_EOF = 0xFFFFFFFF;
static inline void log_parse_error(const SourceLocation& location = SourceLocation::current())
{
- dbgln_if(CSS_TOKENIZER_TRACE, "Parse error (css tokenization) {} ", location);
+ dbgln_if(CSS_TOKENIZER_DEBUG, "Parse error (css tokenization) {} ", location);
}
static inline bool is_eof(u32 code_point)
@@ -219,7 +218,7 @@ u32 Tokenizer::next_code_point()
return TOKENIZER_EOF;
m_prev_utf8_iterator = m_utf8_iterator;
++m_utf8_iterator;
- dbgln_if(CSS_TOKENIZER_TRACE, "(Tokenizer) Next code_point: {:c}", (char)*m_prev_utf8_iterator);
+ dbgln_if(CSS_TOKENIZER_DEBUG, "(Tokenizer) Next code_point: {:c}", (char)*m_prev_utf8_iterator);
return *m_prev_utf8_iterator;
}
@@ -716,7 +715,7 @@ Token Tokenizer::consume_a_token()
}
if (is_whitespace(input)) {
- dbgln_if(CSS_TOKENIZER_TRACE, "is whitespace");
+ dbgln_if(CSS_TOKENIZER_DEBUG, "is whitespace");
auto next = peek_code_point();
while (is_whitespace(next)) {
@@ -728,12 +727,12 @@ Token Tokenizer::consume_a_token()
}
if (is_quotation_mark(input)) {
- dbgln_if(CSS_TOKENIZER_TRACE, "is quotation mark");
+ dbgln_if(CSS_TOKENIZER_DEBUG, "is quotation mark");
return consume_string_token(input);
}
if (is_number_sign(input)) {
- dbgln_if(CSS_TOKENIZER_TRACE, "is number sign");
+ dbgln_if(CSS_TOKENIZER_DEBUG, "is number sign");
auto next_input = peek_code_point();
auto maybe_escape = peek_twin();
@@ -754,22 +753,22 @@ Token Tokenizer::consume_a_token()
}
if (is_apostrophe(input)) {
- dbgln_if(CSS_TOKENIZER_TRACE, "is apostrophe");
+ dbgln_if(CSS_TOKENIZER_DEBUG, "is apostrophe");
return consume_string_token(input);
}
if (is_left_paren(input)) {
- dbgln_if(CSS_TOKENIZER_TRACE, "is left paren");
+ dbgln_if(CSS_TOKENIZER_DEBUG, "is left paren");
return create_new_token(Token::Type::OpenParen);
}
if (is_right_paren(input)) {
- dbgln_if(CSS_TOKENIZER_TRACE, "is right paren");
+ dbgln_if(CSS_TOKENIZER_DEBUG, "is right paren");
return create_new_token(Token::Type::CloseParen);
}
if (is_plus_sign(input)) {
- dbgln_if(CSS_TOKENIZER_TRACE, "is plus sign");
+ dbgln_if(CSS_TOKENIZER_DEBUG, "is plus sign");
if (starts_with_a_number()) {
reconsume_current_input_code_point();
return consume_a_numeric_token();
@@ -779,12 +778,12 @@ Token Tokenizer::consume_a_token()
}
if (is_comma(input)) {
- dbgln_if(CSS_TOKENIZER_TRACE, "is comma");
+ dbgln_if(CSS_TOKENIZER_DEBUG, "is comma");
return create_new_token(Token::Type::Comma);
}
if (is_hyphen_minus(input)) {
- dbgln_if(CSS_TOKENIZER_TRACE, "is hyphen minus");
+ dbgln_if(CSS_TOKENIZER_DEBUG, "is hyphen minus");
if (starts_with_a_number()) {
reconsume_current_input_code_point();
return consume_a_numeric_token();
@@ -807,7 +806,7 @@ Token Tokenizer::consume_a_token()
}
if (is_full_stop(input)) {
- dbgln_if(CSS_TOKENIZER_TRACE, "is full stop");
+ dbgln_if(CSS_TOKENIZER_DEBUG, "is full stop");
if (starts_with_a_number()) {
reconsume_current_input_code_point();
return consume_a_numeric_token();
@@ -817,17 +816,17 @@ Token Tokenizer::consume_a_token()
}
if (is_colon(input)) {
- dbgln_if(CSS_TOKENIZER_TRACE, "is colon");
+ dbgln_if(CSS_TOKENIZER_DEBUG, "is colon");
return create_new_token(Token::Type::Colon);
}
if (is_semicolon(input)) {
- dbgln_if(CSS_TOKENIZER_TRACE, "is semicolon");
+ dbgln_if(CSS_TOKENIZER_DEBUG, "is semicolon");
return create_new_token(Token::Type::Semicolon);
}
if (is_less_than_sign(input)) {
- dbgln_if(CSS_TOKENIZER_TRACE, "is less than");
+ dbgln_if(CSS_TOKENIZER_DEBUG, "is less than");
auto maybe_cdo = peek_triplet();
if (is_exclamation_mark(maybe_cdo.first) && is_hyphen_minus(maybe_cdo.second) && is_hyphen_minus(maybe_cdo.third)) {
@@ -842,7 +841,7 @@ Token Tokenizer::consume_a_token()
}
if (is_at(input)) {
- dbgln_if(CSS_TOKENIZER_TRACE, "is at");
+ dbgln_if(CSS_TOKENIZER_DEBUG, "is at");
if (would_start_an_identifier()) {
auto name = consume_a_name();
@@ -853,12 +852,12 @@ Token Tokenizer::consume_a_token()
}
if (is_open_square_bracket(input)) {
- dbgln_if(CSS_TOKENIZER_TRACE, "is open square");
+ dbgln_if(CSS_TOKENIZER_DEBUG, "is open square");
return create_new_token(Token::Type::OpenSquare);
}
if (is_reverse_solidus(input)) {
- dbgln_if(CSS_TOKENIZER_TRACE, "is reverse solidus");
+ dbgln_if(CSS_TOKENIZER_DEBUG, "is reverse solidus");
if (is_valid_escape_sequence({ input, peek_code_point() })) {
reconsume_current_input_code_point();
return consume_an_ident_like_token();
@@ -869,33 +868,33 @@ Token Tokenizer::consume_a_token()
}
if (is_closed_square_bracket(input)) {
- dbgln_if(CSS_TOKENIZER_TRACE, "is closed square");
+ dbgln_if(CSS_TOKENIZER_DEBUG, "is closed square");
return create_new_token(Token::Type::CloseSquare);
}
if (is_open_curly_bracket(input)) {
- dbgln_if(CSS_TOKENIZER_TRACE, "is open curly");
+ dbgln_if(CSS_TOKENIZER_DEBUG, "is open curly");
return create_new_token(Token::Type::OpenCurly);
}
if (is_closed_curly_bracket(input)) {
- dbgln_if(CSS_TOKENIZER_TRACE, "is closed curly");
+ dbgln_if(CSS_TOKENIZER_DEBUG, "is closed curly");
return create_new_token(Token::Type::CloseCurly);
}
if (is_ascii_digit(input)) {
- dbgln_if(CSS_TOKENIZER_TRACE, "is digit");
+ dbgln_if(CSS_TOKENIZER_DEBUG, "is digit");
reconsume_current_input_code_point();
return consume_a_numeric_token();
}
if (is_name_start_code_point(input)) {
- dbgln_if(CSS_TOKENIZER_TRACE, "is name start");
+ dbgln_if(CSS_TOKENIZER_DEBUG, "is name start");
reconsume_current_input_code_point();
return consume_an_ident_like_token();
}
- dbgln_if(CSS_TOKENIZER_TRACE, "is delimiter");
+ dbgln_if(CSS_TOKENIZER_DEBUG, "is delimiter");
return create_value_token(Token::Type::Delim, input);
}