1 /* Callback management.
2 Copyright (C) 2014-2021 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #include <cc1plugin-config.h>
23 #include "callbacks.hh"
24 #include "libiberty.h"
26 // An entry in the hash table.
30 cc1_plugin::callback_ftype
*func
;
33 // Hash function for struct method.
35 hash_method (const void *a
)
37 const struct method
*m
= (const struct method
*) a
;
39 return htab_hash_string (m
->name
);
42 // Equality function for struct method.
44 eq_method (const void *a
, const void *b
)
46 const struct method
*ma
= (const struct method
*) a
;
47 const struct method
*mb
= (const struct method
*) b
;
49 return strcmp (ma
->name
, mb
->name
) == 0;
52 cc1_plugin::callbacks::callbacks ()
53 : m_registry (htab_create_alloc (10, hash_method
, eq_method
,
58 cc1_plugin::callbacks::~callbacks ()
60 htab_delete (m_registry
);
64 cc1_plugin::callbacks::add_callback (const char *name
,
65 cc1_plugin::callback_ftype
*func
)
73 slot
= (method
**) htab_find_slot (m_registry
, &m
, INSERT
);
74 *slot
= XNEW (method
);
78 cc1_plugin::callback_ftype
*
79 cc1_plugin::callbacks::find_callback (const char *name
)
85 found
= (method
*) htab_find (m_registry
, &m
);