type-utils.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* Utilities for querying and manipulating type trees.
  2. Copyright (C) 2013-2015 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3, or (at your option)
  7. any later version.
  8. GCC is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GCC; see the file COPYING3. If not see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef GCC_CP_TYPE_UTILS_H
  16. #define GCC_CP_TYPE_UTILS_H
  17. /* Returns the first tree within T that is directly matched by PRED. T may be a
  18. type or PARM_DECL and is incrementally decomposed toward its type-specifier
  19. until a match is found. NULL_TREE is returned if PRED does not match any
  20. part of T.
  21. This is primarily intended for detecting whether T uses `auto' or a concept
  22. identifier. Since either of these can only appear as a type-specifier for
  23. the declaration in question, only top-level qualifications are traversed;
  24. find_type_usage does not look through the whole type. */
  25. inline tree
  26. find_type_usage (tree t, bool (*pred) (const_tree))
  27. {
  28. enum tree_code code;
  29. if (pred (t))
  30. return t;
  31. code = TREE_CODE (t);
  32. if (code == POINTER_TYPE || code == REFERENCE_TYPE
  33. || code == PARM_DECL || code == OFFSET_TYPE
  34. || code == FUNCTION_TYPE || code == METHOD_TYPE
  35. || code == ARRAY_TYPE)
  36. return find_type_usage (TREE_TYPE (t), pred);
  37. if (TYPE_PTRMEMFUNC_P (t))
  38. return find_type_usage
  39. (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (t)), pred);
  40. return NULL_TREE;
  41. }
  42. #endif // GCC_CP_TYPE_UTILS_H