clang 17.0.0git
TypedefUnderlyingTypeResolver.cpp
Go to the documentation of this file.
1//===- ExtractAPI/TypedefUnderlyingTypeResolver.cpp -------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file implements UnderlyingTypeResolver.
11///
12//===----------------------------------------------------------------------===//
13
16
17using namespace clang;
18using namespace extractapi;
19
20const NamedDecl *
22 const NamedDecl *TypeDecl = nullptr;
23
24 const TypedefType *TypedefTy = Type->getAs<TypedefType>();
25 if (TypedefTy)
26 TypeDecl = TypedefTy->getDecl();
27 if (const TagType *TagTy = Type->getAs<TagType>()) {
28 TypeDecl = TagTy->getDecl();
29 } else if (const ObjCInterfaceType *ObjCITy =
31 TypeDecl = ObjCITy->getDecl();
32 }
33
34 if (TypeDecl && TypedefTy) {
35 // if this is a typedef to another typedef, use the typedef's decl for the
36 // USR - this will actually be in the output, unlike a typedef to an
37 // anonymous decl
38 const TypedefNameDecl *TypedefDecl = TypedefTy->getDecl();
41 }
42
43 return TypeDecl;
44}
45
48 APISet &API) const {
49 std::string TypeName = Type.getAsString();
50 SmallString<128> TypeUSR;
52 const TypedefType *TypedefTy = Type->getAs<TypedefType>();
53
54 if (TypeDecl) {
55 if (!TypedefTy)
56 TypeName = TypeDecl->getName().str();
57
59 } else {
60 clang::index::generateUSRForType(Type, Context, TypeUSR);
61 }
62
63 return {API.copyString(TypeName), API.copyString(TypeUSR)};
64}
65
67 SmallString<128> TypeUSR;
69
70 if (TypeDecl)
72 else
73 clang::index::generateUSRForType(Type, Context, TypeUSR);
74
75 return std::string(TypeUSR);
76}
This file defines the UnderlyingTypeResolver which is a helper type for resolving the undelrying type...
This represents a decl that may have a name.
Definition: Decl.h:247
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:274
Interfaces are the core concept in Objective-C for object oriented design.
Definition: Type.h:6256
A (possibly-)qualified type.
Definition: Type.h:736
Represents a declaration of a type.
Definition: Decl.h:3262
The base class of the type hierarchy.
Definition: Type.h:1568
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7430
bool isTypedefNameType() const
Determines whether this type is written as a typedef-name.
Definition: Type.h:7358
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition: Decl.h:3406
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3304
QualType getUnderlyingType() const
Definition: Decl.h:3359
TypedefNameDecl * getDecl() const
Definition: Type.h:4580
APISet holds the set of API records collected from given inputs.
Definition: API.h:596
StringRef copyString(StringRef String)
Copy String into the Allocator in this APISet.
Definition: API.cpp:271
bool generateUSRForType(QualType T, ASTContext &Ctx, SmallVectorImpl< char > &Buf)
Generates a USR for a type.
bool generateUSRForDecl(const Decl *D, SmallVectorImpl< char > &Buf)
Generate a USR for a Decl, including the USR prefix.
This represents a reference to another symbol that might come from external sources.
Definition: API.h:428
SymbolReference getSymbolReferenceForType(QualType Type, APISet &API) const
Get a SymbolReference for the given type.
std::string getUSRForType(QualType Type) const
Get a USR for the given type.
const NamedDecl * getUnderlyingTypeDecl(QualType Type) const
Gets the underlying type declaration.