annotate libcc1/callbacks.cc @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Callback management.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 Copyright (C) 2014-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 This file is part of GCC.
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
7 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
8 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
9 version.
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
14 for more details.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
17 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
18 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 #include <cc1plugin-config.h>
kono
parents:
diff changeset
21 #include <string.h>
kono
parents:
diff changeset
22 #include <stdlib.h>
kono
parents:
diff changeset
23 #include "callbacks.hh"
kono
parents:
diff changeset
24 #include "libiberty.h"
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 // An entry in the hash table.
kono
parents:
diff changeset
27 struct method
kono
parents:
diff changeset
28 {
kono
parents:
diff changeset
29 const char *name;
kono
parents:
diff changeset
30 cc1_plugin::callback_ftype *func;
kono
parents:
diff changeset
31 };
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 // Hash function for struct method.
kono
parents:
diff changeset
34 static hashval_t
kono
parents:
diff changeset
35 hash_method (const void *a)
kono
parents:
diff changeset
36 {
kono
parents:
diff changeset
37 const struct method *m = (const struct method *) a;
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 return htab_hash_string (m->name);
kono
parents:
diff changeset
40 }
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 // Equality function for struct method.
kono
parents:
diff changeset
43 static int
kono
parents:
diff changeset
44 eq_method (const void *a, const void *b)
kono
parents:
diff changeset
45 {
kono
parents:
diff changeset
46 const struct method *ma = (const struct method *) a;
kono
parents:
diff changeset
47 const struct method *mb = (const struct method *) b;
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 return strcmp (ma->name, mb->name) == 0;
kono
parents:
diff changeset
50 }
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 cc1_plugin::callbacks::callbacks ()
kono
parents:
diff changeset
53 : m_registry (htab_create_alloc (10, hash_method, eq_method,
kono
parents:
diff changeset
54 free, xcalloc, free))
kono
parents:
diff changeset
55 {
kono
parents:
diff changeset
56 }
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 cc1_plugin::callbacks::~callbacks ()
kono
parents:
diff changeset
59 {
kono
parents:
diff changeset
60 htab_delete (m_registry);
kono
parents:
diff changeset
61 }
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 void
kono
parents:
diff changeset
64 cc1_plugin::callbacks::add_callback (const char *name,
kono
parents:
diff changeset
65 cc1_plugin::callback_ftype *func)
kono
parents:
diff changeset
66 {
kono
parents:
diff changeset
67 method m;
kono
parents:
diff changeset
68 method **slot;
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 m.name = name;
kono
parents:
diff changeset
71 m.func = func;
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 slot = (method **) htab_find_slot (m_registry, &m, INSERT);
kono
parents:
diff changeset
74 *slot = XNEW (method);
kono
parents:
diff changeset
75 **slot = m;
kono
parents:
diff changeset
76 }
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 cc1_plugin::callback_ftype *
kono
parents:
diff changeset
79 cc1_plugin::callbacks::find_callback (const char *name)
kono
parents:
diff changeset
80 {
kono
parents:
diff changeset
81 method m, *found;
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 m.name = name;
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 found = (method *) htab_find (m_registry, &m);
kono
parents:
diff changeset
86 if (found == NULL)
kono
parents:
diff changeset
87 return NULL;
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 return found->func;
kono
parents:
diff changeset
90 }