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

Everywhere: Add sv suffix to strings relying on StringView(char const*)

Each of these strings would previously rely on StringView's char const*
constructor overload, which would call __builtin_strlen on the string.
Since we now have operator ""sv, we can replace these with much simpler
versions. This opens the door to being able to remove
StringView(char const*).

No functional changes.
This commit is contained in:
sin-ack 2022-07-11 17:32:29 +00:00 committed by Andreas Kling
parent e5f09ea170
commit 3f3f45580a
762 changed files with 8315 additions and 8316 deletions

View file

@ -85,7 +85,7 @@ String NamedType::to_string() const
if (is_auto())
name = "auto";
else
name = m_name.is_null() ? "" : m_name->full_name();
name = m_name.is_null() ? ""sv : m_name->full_name();
return String::formatted("{}{}", qualifiers_string, name);
}
@ -109,7 +109,7 @@ String Reference::to_string() const
if (m_kind == Kind::Lvalue)
builder.append("&");
else
builder.append("&&");
builder.append("&&"sv);
return builder.to_string();
}
@ -123,7 +123,7 @@ String FunctionType::to_string() const
if (first)
first = false;
else
builder.append(", ");
builder.append(", "sv);
if (parameter.type())
builder.append(parameter.type()->to_string());
if (parameter.name() && !parameter.full_name().is_empty()) {
@ -552,7 +552,7 @@ StringView Name::full_name() const
builder.appendff("{}::", scope.name());
}
}
m_full_name = String::formatted("{}{}", builder.to_string(), m_name.is_null() ? "" : m_name->name());
m_full_name = String::formatted("{}{}", builder.to_string(), m_name.is_null() ? ""sv : m_name->name());
return *m_full_name;
}

View file

@ -52,155 +52,155 @@ constexpr bool is_valid_nonfirst_character_of_identifier(char ch)
}
constexpr StringView s_known_keywords[] = {
"alignas",
"alignof",
"and",
"and_eq",
"asm",
"bitand",
"bitor",
"break",
"case",
"catch",
"class",
"compl",
"const",
"const_cast",
"constexpr",
"continue",
"decltype",
"default",
"delete",
"do",
"dynamic_cast",
"else",
"enum",
"explicit",
"export",
"extern",
"false",
"final",
"for",
"friend",
"goto",
"if",
"inline",
"mutable",
"namespace",
"new",
"noexcept",
"not",
"not_eq",
"nullptr",
"operator",
"or",
"or_eq",
"override",
"private",
"protected",
"public",
"register",
"reinterpret_cast",
"return",
"signed",
"sizeof",
"static",
"static_assert",
"static_cast",
"struct",
"switch",
"template",
"this",
"thread_local",
"throw",
"true",
"try",
"typedef",
"typeid",
"typename",
"union",
"using",
"virtual",
"volatile",
"while",
"xor",
"xor_eq"
"alignas"sv,
"alignof"sv,
"and"sv,
"and_eq"sv,
"asm"sv,
"bitand"sv,
"bitor"sv,
"break"sv,
"case"sv,
"catch"sv,
"class"sv,
"compl"sv,
"const"sv,
"const_cast"sv,
"constexpr"sv,
"continue"sv,
"decltype"sv,
"default"sv,
"delete"sv,
"do"sv,
"dynamic_cast"sv,
"else"sv,
"enum"sv,
"explicit"sv,
"export"sv,
"extern"sv,
"false"sv,
"final"sv,
"for"sv,
"friend"sv,
"goto"sv,
"if"sv,
"inline"sv,
"mutable"sv,
"namespace"sv,
"new"sv,
"noexcept"sv,
"not"sv,
"not_eq"sv,
"nullptr"sv,
"operator"sv,
"or"sv,
"or_eq"sv,
"override"sv,
"private"sv,
"protected"sv,
"public"sv,
"register"sv,
"reinterpret_cast"sv,
"return"sv,
"signed"sv,
"sizeof"sv,
"static"sv,
"static_assert"sv,
"static_cast"sv,
"struct"sv,
"switch"sv,
"template"sv,
"this"sv,
"thread_local"sv,
"throw"sv,
"true"sv,
"try"sv,
"typedef"sv,
"typeid"sv,
"typename"sv,
"union"sv,
"using"sv,
"virtual"sv,
"volatile"sv,
"while"sv,
"xor"sv,
"xor_eq"sv
};
constexpr StringView s_known_types[] = {
"Array",
"Array",
"Badge",
"Bitmap",
"ByteBuffer",
"Bytes",
"Checked",
"CircularDeque",
"CircularQueue",
"Deque",
"DoublyLinkedList",
"Error",
"ErrorOr",
"FlyString",
"Function",
"HashMap",
"HashTable",
"IPv4Address",
"IntrusiveList",
"IntrusiveList",
"JsonArray",
"JsonObject",
"JsonValue",
"LexicalPath",
"MappedFile",
"NetworkOrdered",
"NeverDestroyed",
"NonnullOwnPtr",
"NonnullOwnPtrVector",
"NonnullRefPtr",
"NonnullRefPtrVector",
"Optional",
"OwnPtr",
"ReadonlyBytes",
"RedBlackTree",
"RefPtr",
"Result",
"ScopeGuard",
"Singleton",
"SinglyLinkedList",
"Span",
"String",
"StringBuilder",
"StringImpl",
"StringView",
"Utf8View",
"Variant",
"Vector",
"WeakPtr",
"auto",
"bool",
"char",
"char16_t",
"char32_t",
"char8_t",
"double",
"float",
"i16",
"i32",
"i64",
"i8",
"int",
"int",
"long",
"short",
"signed",
"u16",
"u32",
"u64",
"u8",
"unsigned",
"void",
"wchar_t",
"Array"sv,
"Array"sv,
"Badge"sv,
"Bitmap"sv,
"ByteBuffer"sv,
"Bytes"sv,
"Checked"sv,
"CircularDeque"sv,
"CircularQueue"sv,
"Deque"sv,
"DoublyLinkedList"sv,
"Error"sv,
"ErrorOr"sv,
"FlyString"sv,
"Function"sv,
"HashMap"sv,
"HashTable"sv,
"IPv4Address"sv,
"IntrusiveList"sv,
"IntrusiveList"sv,
"JsonArray"sv,
"JsonObject"sv,
"JsonValue"sv,
"LexicalPath"sv,
"MappedFile"sv,
"NetworkOrdered"sv,
"NeverDestroyed"sv,
"NonnullOwnPtr"sv,
"NonnullOwnPtrVector"sv,
"NonnullRefPtr"sv,
"NonnullRefPtrVector"sv,
"Optional"sv,
"OwnPtr"sv,
"ReadonlyBytes"sv,
"RedBlackTree"sv,
"RefPtr"sv,
"Result"sv,
"ScopeGuard"sv,
"Singleton"sv,
"SinglyLinkedList"sv,
"Span"sv,
"String"sv,
"StringBuilder"sv,
"StringImpl"sv,
"StringView"sv,
"Utf8View"sv,
"Variant"sv,
"Vector"sv,
"WeakPtr"sv,
"auto"sv,
"bool"sv,
"char"sv,
"char16_t"sv,
"char32_t"sv,
"char8_t"sv,
"double"sv,
"float"sv,
"i16"sv,
"i32"sv,
"i64"sv,
"i8"sv,
"int"sv,
"int"sv,
"long"sv,
"short"sv,
"signed"sv,
"u16"sv,
"u32"sv,
"u64"sv,
"u8"sv,
"unsigned"sv,
"void"sv,
"wchar_t"sv,
};
static bool is_keyword(StringView string)

View file

@ -45,7 +45,7 @@ NonnullRefPtrVector<Declaration> Parser::parse_declarations_in_translation_unit(
if (declaration) {
declarations.append(declaration.release_nonnull());
} else {
error("unexpected token");
error("unexpected token"sv);
consume();
}
}
@ -92,7 +92,7 @@ NonnullRefPtr<Declaration> Parser::parse_declaration(ASTNode& parent, Declaratio
case DeclarationType::Destructor:
return parse_destructor(parent);
default:
error("unexpected declaration type");
error("unexpected declaration type"sv);
return create_ast_node<InvalidDeclaration>(parent, position(), position());
}
}
@ -181,7 +181,7 @@ NonnullRefPtr<Statement> Parser::parse_statement(ASTNode& parent)
consume_semicolon.disarm();
return parse_if_statement(parent);
} else {
error("unexpected statement type");
error("unexpected statement type"sv);
consume_semicolon.disarm();
consume();
return create_ast_node<InvalidStatement>(parent, position(), position());
@ -295,7 +295,7 @@ bool Parser::match_variable_declaration()
if (match(Token::Type::Equals)) {
consume(Token::Type::Equals);
if (!match_expression()) {
error("initial value of variable is not an expression");
error("initial value of variable is not an expression"sv);
return false;
}
return true;
@ -312,7 +312,7 @@ NonnullRefPtr<VariableDeclaration> Parser::parse_variable_declaration(ASTNode& p
LOG_SCOPE();
auto var = create_ast_node<VariableDeclaration>(parent, position(), {});
if (!match_variable_declaration()) {
error("unexpected token for variable type");
error("unexpected token for variable type"sv);
var->set_end(position());
return var;
}
@ -432,7 +432,7 @@ NonnullRefPtr<Expression> Parser::parse_primary_expression(ASTNode& parent)
return parse_name(parent);
}
error("could not parse primary expression");
error("could not parse primary expression"sv);
auto token = consume();
return create_ast_node<InvalidExpression>(parent, token.start(), token.end());
}
@ -523,7 +523,7 @@ NonnullRefPtr<Expression> Parser::parse_literal(ASTNode& parent)
[[fallthrough]];
}
default: {
error("could not parse literal");
error("could not parse literal"sv);
auto token = consume();
return create_ast_node<InvalidExpression>(parent, token.start(), token.end());
}
@ -805,7 +805,7 @@ void Parser::consume_preprocessor()
consume(Token::Type::IncludePath);
break;
default:
error("unexpected token while parsing preprocessor statement");
error("unexpected token while parsing preprocessor statement"sv);
consume();
}
}
@ -832,7 +832,7 @@ bool Parser::match(Token::Type type)
Token Parser::consume()
{
if (eof()) {
error("C++ Parser: out of tokens");
error("C++ Parser: out of tokens"sv);
return { Token::Type::EOF_TOKEN, position(), position(), {} };
}
return m_tokens[m_state.token_index++];
@ -905,14 +905,14 @@ void Parser::error(StringView message)
return;
if (message.is_null() || message.is_empty())
message = "<empty>";
message = "<empty>"sv;
String formatted_message;
if (m_state.token_index >= m_tokens.size()) {
formatted_message = String::formatted("C++ Parsed error on EOF.{}", message);
} else {
formatted_message = String::formatted("C++ Parser error: {}. token: {} ({}:{})",
message,
m_state.token_index < m_tokens.size() ? text_of_token(m_tokens[m_state.token_index]) : "EOF",
m_state.token_index < m_tokens.size() ? text_of_token(m_tokens[m_state.token_index]) : "EOF"sv,
m_tokens[m_state.token_index].start().line,
m_tokens[m_state.token_index].start().column);
}
@ -1017,7 +1017,7 @@ Vector<CodeComprehension::TodoEntry> Parser::get_todo_entries() const
Vector<CodeComprehension::TodoEntry> ret;
for (auto& token : m_tokens) {
if (token.type() == Token::Type::Comment) {
if (token.text().contains("TODO") || token.text().contains("FIXME")) {
if (token.text().contains("TODO"sv) || token.text().contains("FIXME"sv)) {
ret.append({ token.text(), m_filename, token.start().line, token.start().column });
}
}
@ -1206,7 +1206,7 @@ NonnullRefPtr<Type> Parser::parse_type(ASTNode& parent)
LOG_SCOPE();
if (!match_named_type()) {
error("expected named named_type");
error("expected named named_type"sv);
auto token = consume();
return create_ast_node<NamedType>(parent, token.start(), token.end());
}
@ -1412,7 +1412,7 @@ NonnullRefPtr<NamespaceDeclaration> Parser::parse_namespace_declaration(ASTNode&
if (declaration) {
namespace_decl->add_declaration(declaration.release_nonnull());
} else {
error("unexpected token");
error("unexpected token"sv);
consume();
}
}
@ -1577,7 +1577,7 @@ NonnullRefPtrVector<Declaration> Parser::parse_class_members(StructOrClassDeclar
if (member_type.has_value()) {
members.append(parse_declaration(parent, member_type.value()));
} else {
error("Expected class member");
error("Expected class member"sv);
consume();
}
}
@ -1661,7 +1661,7 @@ void Parser::parse_constructor_or_destructor_impl(FunctionDeclaration& func, Cto
auto parameters = parse_parameter_list(func);
if (parameters.has_value()) {
if (type == CtorOrDtor::Dtor && !parameters->is_empty())
error("Destructor declaration that takes parameters");
error("Destructor declaration that takes parameters"sv);
else
func.set_parameters(parameters.value());
}