]>
Commit | Line | Data |
---|---|---|
1a11a94f | 1 | /* Utilities for querying and manipulating type trees. |
a945c346 | 2 | Copyright (C) 2013-2024 Free Software Foundation, Inc. |
1a11a94f AB |
3 | |
4 | This file is part of GCC. | |
5 | ||
6 | GCC is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 3, or (at your option) | |
9 | any later version. | |
10 | ||
11 | GCC is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License 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 GCC_CP_TYPE_UTILS_H | |
21 | #define GCC_CP_TYPE_UTILS_H | |
22 | ||
6bd409cf PP |
23 | /* Returns the first tree within T that is directly matched by PRED. T may be a |
24 | type or PARM_DECL and is incrementally decomposed toward its type-specifier | |
25 | until a match is found. NULL is returned if PRED does not match any | |
26 | part of T. | |
1a11a94f | 27 | |
6bd409cf | 28 | This is primarily intended for detecting whether T uses `auto' or a concept |
1a11a94f AB |
29 | identifier. Since either of these can only appear as a type-specifier for |
30 | the declaration in question, only top-level qualifications are traversed; | |
31 | find_type_usage does not look through the whole type. */ | |
32 | ||
6bd409cf PP |
33 | inline tree |
34 | find_type_usage (tree t, bool (*pred) (const_tree)) | |
1a11a94f | 35 | { |
1a11a94f | 36 | if (pred (t)) |
6bd409cf | 37 | return t; |
1a11a94f | 38 | |
a6ee556c | 39 | enum tree_code code = TREE_CODE (t); |
1a11a94f AB |
40 | |
41 | if (code == POINTER_TYPE || code == REFERENCE_TYPE | |
42 | || code == PARM_DECL || code == OFFSET_TYPE | |
43 | || code == FUNCTION_TYPE || code == METHOD_TYPE | |
44 | || code == ARRAY_TYPE) | |
6bd409cf | 45 | return find_type_usage (TREE_TYPE (t), pred); |
1a11a94f AB |
46 | |
47 | if (TYPE_PTRMEMFUNC_P (t)) | |
48 | return find_type_usage | |
6bd409cf | 49 | (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (t)), pred); |
1a11a94f | 50 | |
6bd409cf | 51 | return NULL_TREE; |
1a11a94f AB |
52 | } |
53 | ||
54 | #endif // GCC_CP_TYPE_UTILS_H |