https://gcc.gnu.org/g:0cf34825923d9fc82e3d015e9bc7d0b253bd9348
commit r16-5616-g0cf34825923d9fc82e3d015e9bc7d0b253bd9348 Author: Soumya AR <[email protected]> Date: Fri Jul 11 05:54:33 2025 -0700 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 <[email protected]> gcc/ChangeLog: * json.h (class object): Add get_map () method. (is_a_helper<json::literal *>, is_a_helper<const json::literal *>): New template specializations. Diff: --- gcc/json.h | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/gcc/json.h b/gcc/json.h index c53715ecb2ca..90b6c601f809 100644 --- a/gcc/json.h +++ b/gcc/json.h @@ -189,6 +189,9 @@ class object : public value public: ~object (); + typedef hash_map <char *, value *, + simple_hashmap_traits<nofree_string_hash, value *> > 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<value> 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<object> clone_as_object () const; private: - typedef hash_map <char *, value *, - simple_hashmap_traits<nofree_string_hash, value *> > map_t; map_t m_map; /* Keep track of order in which keys were inserted. */ @@ -497,6 +499,26 @@ is_a_helper <const json::string *>::test (const json::value *jv) return jv->get_kind () == json::JSON_STRING; } +template <> +template <> +inline bool +is_a_helper<json::literal *>::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<const json::literal *>::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 {
