diff --git a/AK/NonnullRefPtr.h b/AK/NonnullRefPtr.h index 426c4f5dca..3710f07534 100644 --- a/AK/NonnullRefPtr.h +++ b/AK/NonnullRefPtr.h @@ -68,7 +68,7 @@ public: template RETURN_TYPESTATE(unconsumed) NonnullRefPtr(const U& object) - : m_ptr(&const_cast(static_cast(object))) + : m_ptr(&const_cast(object)) { m_ptr->ref(); } @@ -85,7 +85,7 @@ public: template RETURN_TYPESTATE(unconsumed) NonnullRefPtr(NonnullRefPtr&& other) - : m_ptr(static_cast(&other.leak_ref())) + : m_ptr(&other.leak_ref()) { } RETURN_TYPESTATE(unconsumed) @@ -97,7 +97,7 @@ public: template RETURN_TYPESTATE(unconsumed) NonnullRefPtr(const NonnullRefPtr& other) - : m_ptr(const_cast(static_cast((other.ptr())))) + : m_ptr(const_cast(other.ptr())) { m_ptr->ref(); } diff --git a/AK/RefPtr.h b/AK/RefPtr.h index 6e5a9554b5..3c69456526 100644 --- a/AK/RefPtr.h +++ b/AK/RefPtr.h @@ -71,20 +71,20 @@ public: } template RefPtr(const NonnullRefPtr& other) - : m_ptr(static_cast(const_cast(other.ptr()))) + : m_ptr(const_cast(other.ptr())) { ASSERT(m_ptr); m_ptr->ref(); } template RefPtr(NonnullRefPtr&& other) - : m_ptr(static_cast(&other.leak_ref())) + : m_ptr(&other.leak_ref()) { ASSERT(m_ptr); } template RefPtr(RefPtr&& other) - : m_ptr(static_cast(other.leak_ref())) + : m_ptr(other.leak_ref()) { } RefPtr(const RefPtr& other) @@ -94,7 +94,7 @@ public: } template RefPtr(const RefPtr& other) - : m_ptr(static_cast(const_cast(other.ptr()))) + : m_ptr(const_cast(other.ptr())) { ref_if_not_null(m_ptr); } @@ -282,6 +282,19 @@ struct Traits> : public GenericTraits> { static bool equals(const RefPtr& a, const RefPtr& b) { return a.ptr() == b.ptr(); } }; +template +inline NonnullRefPtr static_ptr_cast(const NonnullRefPtr& ptr) +{ + return NonnullRefPtr(static_cast(*ptr)); +} + +template +inline RefPtr static_ptr_cast(const RefPtr& ptr) +{ + return RefPtr(static_cast(ptr.ptr())); +} + } using AK::RefPtr; +using AK::static_ptr_cast; diff --git a/Applications/ChanViewer/BoardListModel.h b/Applications/ChanViewer/BoardListModel.h index 6ee6a0bfc7..6c5f158aa3 100644 --- a/Applications/ChanViewer/BoardListModel.h +++ b/Applications/ChanViewer/BoardListModel.h @@ -51,5 +51,5 @@ private: BoardListModel(); JsonArray m_boards; - RefPtr m_pending_job; + RefPtr m_pending_job; }; diff --git a/Applications/ChanViewer/ThreadCatalogModel.h b/Applications/ChanViewer/ThreadCatalogModel.h index 661e3160e5..8ab4046ca1 100644 --- a/Applications/ChanViewer/ThreadCatalogModel.h +++ b/Applications/ChanViewer/ThreadCatalogModel.h @@ -63,5 +63,5 @@ private: String m_board { "g" }; JsonArray m_catalog; - RefPtr m_pending_job; + RefPtr m_pending_job; }; diff --git a/Kernel/FileSystem/TmpFS.cpp b/Kernel/FileSystem/TmpFS.cpp index e916a33980..20f5559488 100644 --- a/Kernel/FileSystem/TmpFS.cpp +++ b/Kernel/FileSystem/TmpFS.cpp @@ -307,8 +307,8 @@ KResult TmpFSInode::add_child(InodeIdentifier child_id, const StringView& name, String owned_name = name; FS::DirectoryEntry entry = { owned_name.characters(), owned_name.length(), child_id, 0 }; - RefPtr child_tmp = fs().get_inode(child_id); - NonnullRefPtr child = static_cast>(child_tmp.release_nonnull()); + auto child_tmp = fs().get_inode(child_id); + auto child = static_ptr_cast(child_tmp.release_nonnull()); m_children.set(owned_name, { entry, move(child) }); set_metadata_dirty(true); diff --git a/Libraries/LibJS/AST.h b/Libraries/LibJS/AST.h index 0c0dfc3dc2..96ded13ea0 100644 --- a/Libraries/LibJS/AST.h +++ b/Libraries/LibJS/AST.h @@ -137,11 +137,11 @@ class Declaration : public Statement { class FunctionNode { public: const FlyString& name() const { return m_name; } - const ScopeNode& body() const { return *m_body; } + const Statement& body() const { return *m_body; } const Vector& parameters() const { return m_parameters; }; protected: - FunctionNode(const FlyString& name, NonnullRefPtr body, Vector parameters = {}) + FunctionNode(const FlyString& name, NonnullRefPtr body, Vector parameters = {}) : m_name(name) , m_body(move(body)) , m_parameters(move(parameters)) @@ -152,7 +152,7 @@ protected: private: FlyString m_name; - NonnullRefPtr m_body; + NonnullRefPtr m_body; const Vector m_parameters; }; @@ -162,7 +162,7 @@ class FunctionDeclaration final public: static bool must_have_name() { return true; } - FunctionDeclaration(String name, NonnullRefPtr body, Vector parameters = {}) + FunctionDeclaration(String name, NonnullRefPtr body, Vector parameters = {}) : FunctionNode(move(name), move(body), move(parameters)) { } @@ -179,7 +179,7 @@ class FunctionExpression final : public Expression public: static bool must_have_name() { return false; } - FunctionExpression(const FlyString& name, NonnullRefPtr body, Vector parameters = {}) + FunctionExpression(const FlyString& name, NonnullRefPtr body, Vector parameters = {}) : FunctionNode(name, move(body), move(parameters)) { } @@ -241,14 +241,14 @@ private: class WhileStatement : public Statement { public: - WhileStatement(NonnullRefPtr test, NonnullRefPtr body) + WhileStatement(NonnullRefPtr test, NonnullRefPtr body) : m_test(move(test)) , m_body(move(body)) { } const Expression& test() const { return *m_test; } - const ScopeNode& body() const { return *m_body; } + const Statement& body() const { return *m_body; } virtual Value execute(Interpreter&) const override; virtual void dump(int indent) const override; @@ -257,19 +257,19 @@ private: virtual const char* class_name() const override { return "WhileStatement"; } NonnullRefPtr m_test; - NonnullRefPtr m_body; + NonnullRefPtr m_body; }; class DoWhileStatement : public Statement { public: - DoWhileStatement(NonnullRefPtr test, NonnullRefPtr body) + DoWhileStatement(NonnullRefPtr test, NonnullRefPtr body) : m_test(move(test)) , m_body(move(body)) { } const Expression& test() const { return *m_test; } - const ScopeNode& body() const { return *m_body; } + const Statement& body() const { return *m_body; } virtual Value execute(Interpreter&) const override; virtual void dump(int indent) const override; @@ -278,12 +278,12 @@ private: virtual const char* class_name() const override { return "DoWhileStatement"; } NonnullRefPtr m_test; - NonnullRefPtr m_body; + NonnullRefPtr m_body; }; class ForStatement : public Statement { public: - ForStatement(RefPtr init, RefPtr test, RefPtr update, NonnullRefPtr body) + ForStatement(RefPtr init, RefPtr test, RefPtr update, NonnullRefPtr body) : m_init(move(init)) , m_test(move(test)) , m_update(move(update)) @@ -294,7 +294,7 @@ public: const ASTNode* init() const { return m_init; } const Expression* test() const { return m_test; } const Expression* update() const { return m_update; } - const ScopeNode& body() const { return *m_body; } + const Statement& body() const { return *m_body; } virtual Value execute(Interpreter&) const override; virtual void dump(int indent) const override; @@ -305,7 +305,7 @@ private: RefPtr m_init; RefPtr m_test; RefPtr m_update; - NonnullRefPtr m_body; + NonnullRefPtr m_body; }; enum class BinaryOp { @@ -569,7 +569,7 @@ private: virtual const char* class_name() const override { return "UpdateExpression"; } UpdateOp m_op; - NonnullRefPtr m_argument; + NonnullRefPtr m_argument; bool m_prefixed; }; diff --git a/Libraries/LibJS/Runtime/ScriptFunction.cpp b/Libraries/LibJS/Runtime/ScriptFunction.cpp index 1a397c96a3..524358ca33 100644 --- a/Libraries/LibJS/Runtime/ScriptFunction.cpp +++ b/Libraries/LibJS/Runtime/ScriptFunction.cpp @@ -33,7 +33,7 @@ namespace JS { -ScriptFunction::ScriptFunction(const ScopeNode& body, Vector parameters) +ScriptFunction::ScriptFunction(const Statement& body, Vector parameters) : m_body(body) , m_parameters(move(parameters)) { diff --git a/Libraries/LibJS/Runtime/ScriptFunction.h b/Libraries/LibJS/Runtime/ScriptFunction.h index 8722dbcd60..cb85dafca9 100644 --- a/Libraries/LibJS/Runtime/ScriptFunction.h +++ b/Libraries/LibJS/Runtime/ScriptFunction.h @@ -32,10 +32,10 @@ namespace JS { class ScriptFunction final : public Function { public: - ScriptFunction(const ScopeNode& body, Vector parameters = {}); + ScriptFunction(const Statement& body, Vector parameters = {}); virtual ~ScriptFunction(); - const ScopeNode& body() const { return m_body; } + const Statement& body() const { return m_body; } const Vector& parameters() const { return m_parameters; }; virtual Value call(Interpreter&) override; @@ -48,7 +48,7 @@ private: static Value length_getter(Interpreter&); static void length_setter(Interpreter&, Value); - NonnullRefPtr m_body; + NonnullRefPtr m_body; const Vector m_parameters; }; diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index 79b6d72cb8..d7fdc1dd5f 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -221,7 +221,7 @@ void Document::layout() if (!m_layout_root) { LayoutTreeBuilder tree_builder; - m_layout_root = tree_builder.build(*this); + m_layout_root = static_ptr_cast(tree_builder.build(*this)); } m_layout_root->layout(); m_layout_root->set_needs_display(); diff --git a/Libraries/LibWeb/Parser/CSSParser.cpp b/Libraries/LibWeb/Parser/CSSParser.cpp index 78495b3ce5..6958b34c3a 100644 --- a/Libraries/LibWeb/Parser/CSSParser.cpp +++ b/Libraries/LibWeb/Parser/CSSParser.cpp @@ -153,39 +153,40 @@ NonnullRefPtr parse_css_value(const StringView& string) return StringStyleValue::create(string); } -RefPtr parse_line_width(const StringView& part) +RefPtr parse_line_width(const StringView& part) { NonnullRefPtr value = parse_css_value(part); if (value->is_length()) - return value; + return static_ptr_cast(value); return nullptr; } -RefPtr parse_color(const StringView& part) +RefPtr parse_color(const StringView& part) { NonnullRefPtr value = parse_css_value(part); if (value->is_color()) - return value; + return static_ptr_cast(value); return nullptr; } -RefPtr parse_line_style(const StringView& part) +RefPtr parse_line_style(const StringView& part) { - NonnullRefPtr value = parse_css_value(part); - if (value->is_string()) { - if (value->to_string() == "dotted") - return value; - if (value->to_string() == "dashed") - return value; - if (value->to_string() == "solid") - return value; - if (value->to_string() == "double") - return value; - if (value->to_string() == "groove") - return value; - if (value->to_string() == "ridge") - return value; - } + NonnullRefPtr parsed_value = parse_css_value(part); + if (!parsed_value->is_string()) + return nullptr; + auto value = static_ptr_cast(parsed_value); + if (value->to_string() == "dotted") + return value; + if (value->to_string() == "dashed") + return value; + if (value->to_string() == "solid") + return value; + if (value->to_string() == "double") + return value; + if (value->to_string() == "groove") + return value; + if (value->to_string() == "ridge") + return value; return nullptr; } diff --git a/Libraries/LibWeb/Parser/CSSParser.h b/Libraries/LibWeb/Parser/CSSParser.h index f62d0891ef..1ec3209740 100644 --- a/Libraries/LibWeb/Parser/CSSParser.h +++ b/Libraries/LibWeb/Parser/CSSParser.h @@ -36,8 +36,8 @@ RefPtr parse_css_declaration(const StringView&); NonnullRefPtr parse_css_value(const StringView&); Optional parse_selector(const StringView&); -RefPtr parse_line_width(const StringView&); -RefPtr parse_color(const StringView&); -RefPtr parse_line_style(const StringView&); +RefPtr parse_line_width(const StringView&); +RefPtr parse_color(const StringView&); +RefPtr parse_line_style(const StringView&); }