| 1 | /* Deleter objects |
| 2 | Copyright (C) 2020-2025 Free Software Foundation, Inc. |
| 3 | |
| 4 | This file is part of GCC. |
| 5 | |
| 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 |
| 9 | version. |
| 10 | |
| 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 |
| 14 | for more details. |
| 15 | |
| 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/>. */ |
| 19 | |
| 20 | #ifndef CC1_PLUGIN_DELETER_HH |
| 21 | #define CC1_PLUGIN_DELETER_HH |
| 22 | |
| 23 | #include <memory> |
| 24 | |
| 25 | namespace cc1_plugin |
| 26 | { |
| 27 | // Any pointer type requires a deleter object that knows how to |
| 28 | // clean up. These are used in multiple places. |
| 29 | template<typename T> struct deleter; |
| 30 | |
| 31 | template<> |
| 32 | struct deleter<char> |
| 33 | { |
| 34 | void operator() (char *s) |
| 35 | { |
| 36 | delete[] s; |
| 37 | } |
| 38 | }; |
| 39 | |
| 40 | template<> |
| 41 | struct deleter<gcc_type_array> |
| 42 | { |
| 43 | void operator() (gcc_type_array *p) |
| 44 | { |
| 45 | delete[] p->elements; |
| 46 | delete p; |
| 47 | } |
| 48 | }; |
| 49 | |
| 50 | template<typename T> using unique_ptr = std::unique_ptr<T, deleter<T>>; |
| 51 | } |
| 52 | |
| 53 | #endif // CC1_PLUGIN_DELETER_HH |
| 54 | |