blob: 40ede20a14edd7cc60c542d1d3d865682c18e30d [file] [log] [blame]
Googlerfae1a552022-03-04 13:02:38 +00001// 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ænne1a207c52022-04-19 00:05:38 -07007namespace clang {
8namespace tidy {
9namespace lifetimes {
Googlerfae1a552022-03-04 13:02:38 +000010
Googlerfae1a552022-03-04 13:02:38 +000011clang::QualType PointeeType(clang::QualType type) {
Googlerfae1a552022-03-04 13:02:38 +000012 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
Googlerfae1a552022-03-04 13:02:38 +000018 return clang::QualType();
19}
20
Martin Brænne712b7f42022-06-23 00:55:17 -070021clang::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ænne1a207c52022-04-19 00:05:38 -070034} // namespace lifetimes
35} // namespace tidy
36} // namespace clang