From: Soumya AR Date: Fri, 11 Jul 2025 12:54:33 +0000 (-0700) Subject: json: Add get_map() method to JSON object class X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0cf34825923d9fc82e3d015e9bc7d0b253bd9348;p=thirdparty%2Fgcc.git json: Add get_map() method to JSON object class This patch adds a get_map () method to the JSON object class to provide access to the underlying hash map that stores the JSON key-value pairs. To do this, we expose the map_t typedef, the return type of get_map(). This change is needed to allow traversal of key-value pairs when parsing user-provided JSON tuning data. Additionally, is_a_helper template specializations for json::literal * and const json::literal * were added to make dynamic casting in the next patch easier. This patch was bootstrapped and regtested on aarch64-linux-gnu, no regression. Signed-off-by: Soumya AR gcc/ChangeLog: * json.h (class object): Add get_map () method. (is_a_helper, is_a_helper): New template specializations. --- diff --git a/gcc/json.h b/gcc/json.h index c53715ecb2c..90b6c601f80 100644 --- a/gcc/json.h +++ b/gcc/json.h @@ -189,6 +189,9 @@ class object : public value public: ~object (); + typedef hash_map > map_t; + enum kind get_kind () const final override { return JSON_OBJECT; } void print (pretty_printer *pp, bool formatted) const final override; std::unique_ptr clone () const final override; @@ -214,6 +217,7 @@ class object : public value } value *get (const char *key) const; + const map_t &get_map () const { return m_map; } void set_string (const char *key, const char *utf8_value); void set_integer (const char *key, long v); @@ -243,8 +247,6 @@ class object : public value std::unique_ptr clone_as_object () const; private: - typedef hash_map > map_t; map_t m_map; /* Keep track of order in which keys were inserted. */ @@ -497,6 +499,26 @@ is_a_helper ::test (const json::value *jv) return jv->get_kind () == json::JSON_STRING; } +template <> +template <> +inline bool +is_a_helper::test (json::value *jv) +{ + return (jv->get_kind () == json::JSON_TRUE + || jv->get_kind () == json::JSON_FALSE + || jv->get_kind () == json::JSON_NULL); +} + +template <> +template <> +inline bool +is_a_helper::test (const json::value *jv) +{ + return (jv->get_kind () == json::JSON_TRUE + || jv->get_kind () == json::JSON_FALSE + || jv->get_kind () == json::JSON_NULL); +} + #if CHECKING_P namespace selftest {