Googler | fae1a55 | 2022-03-04 13:02:38 +0000 | [diff] [blame] | 1 | // Part of the Crubit project, under the Apache License v2.0 with LLVM |
| 2 | // Exceptions. See /LICENSE for license information. |
| 3 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 4 | |
| 5 | #include "lifetime_annotations/pointee_type.h" |
| 6 | |
Martin Brænne | 1a207c5 | 2022-04-19 00:05:38 -0700 | [diff] [blame] | 7 | namespace clang { |
| 8 | namespace tidy { |
| 9 | namespace lifetimes { |
Googler | fae1a55 | 2022-03-04 13:02:38 +0000 | [diff] [blame] | 10 | |
Googler | fae1a55 | 2022-03-04 13:02:38 +0000 | [diff] [blame] | 11 | clang::QualType PointeeType(clang::QualType type) { |
Googler | fae1a55 | 2022-03-04 13:02:38 +0000 | [diff] [blame] | 12 | if (auto ptr_type = type->getAs<clang::PointerType>()) { |
| 13 | return ptr_type->getPointeeType(); |
| 14 | } else if (auto ref_type = type->getAs<clang::ReferenceType>()) { |
| 15 | return ref_type->getPointeeType(); |
| 16 | } |
| 17 | |
Googler | fae1a55 | 2022-03-04 13:02:38 +0000 | [diff] [blame] | 18 | return clang::QualType(); |
| 19 | } |
| 20 | |
Martin Brænne | 712b7f4 | 2022-06-23 00:55:17 -0700 | [diff] [blame] | 21 | clang::TypeLoc PointeeTypeLoc(clang::TypeLoc type_loc) { |
| 22 | type_loc = type_loc.getUnqualifiedLoc(); |
| 23 | |
| 24 | if (auto pointer_type_loc = type_loc.getAs<clang::PointerTypeLoc>()) { |
| 25 | return pointer_type_loc.getPointeeLoc(); |
| 26 | } else if (auto reference_type_loc = |
| 27 | type_loc.getAs<clang::ReferenceTypeLoc>()) { |
| 28 | return reference_type_loc.getPointeeLoc(); |
| 29 | } |
| 30 | |
| 31 | return clang::TypeLoc(); |
| 32 | } |
| 33 | |
Martin Brænne | 1a207c5 | 2022-04-19 00:05:38 -0700 | [diff] [blame] | 34 | } // namespace lifetimes |
| 35 | } // namespace tidy |
| 36 | } // namespace clang |