clang 20.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
15#include "clang/Basic/Module.h"
17
18using namespace clang;
19using namespace extractapi;
20
21const NamedDecl *
23 const NamedDecl *TypeDecl = nullptr;
24
25 const TypedefType *TypedefTy = Type->getAs<TypedefType>();
26 if (TypedefTy)
27 TypeDecl = TypedefTy->getDecl();
28 if (const TagType *TagTy = Type->getAs<TagType>()) {
29 TypeDecl = TagTy->getDecl();
30 } else if (const ObjCInterfaceType *ObjCITy =
32 TypeDecl = ObjCITy->getDecl();
33 }
34
35 if (TypeDecl && TypedefTy) {
36 // if this is a typedef to another typedef, use the typedef's decl for the
37 // USR - this will actually be in the output, unlike a typedef to an
38 // anonymous decl
39 const TypedefNameDecl *TypedefDecl = TypedefTy->getDecl();
42 }
43
44 return TypeDecl;
45}
46
49 APISet &API) const {
50 std::string TypeName = Type.getAsString();
51 SmallString<128> TypeUSR;
53 const TypedefType *TypedefTy = Type->getAs<TypedefType>();
54 StringRef OwningModuleName;
55
56 if (TypeDecl) {
57 if (!TypedefTy)
58 TypeName = TypeDecl->getName().str();
59
61 if (auto *OwningModule = TypeDecl->getImportedOwningModule())
62 OwningModuleName = OwningModule->Name;
63 } else {
64 clang::index::generateUSRForType(Type, Context, TypeUSR);
65 }
66
67 return API.createSymbolReference(TypeName, TypeUSR, OwningModuleName);
68}
69
71 SmallString<128> TypeUSR;
73
74 if (TypeDecl)
76 else
77 clang::index::generateUSRForType(Type, Context, TypeUSR);
78
79 return std::string(TypeUSR);
80}
Defines the clang::Module class, which describes a module in the source code.
This file defines the UnderlyingTypeResolver which is a helper type for resolving the undelrying type...
Module * getImportedOwningModule() const
Get the imported owning module, if this decl is from an imported (non-local) module.
Definition: DeclBase.h:806
This represents a decl that may have a name.
Definition: Decl.h:249
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:276
Interfaces are the core concept in Objective-C for object oriented design.
Definition: Type.h:7343
A (possibly-)qualified type.
Definition: Type.h:941
Represents a declaration of a type.
Definition: Decl.h:3363
The base class of the type hierarchy.
Definition: Type.h:1829
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8540
bool isTypedefNameType() const
Determines whether this type is written as a typedef-name.
Definition: Type.h:8468
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition: Decl.h:3507
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3405
QualType getUnderlyingType() const
Definition: Decl.h:3460
TypedefNameDecl * getDecl() const
Definition: Type.h:5640
APISet holds the set of API records collected from given inputs.
Definition: API.h:1400
SymbolReference createSymbolReference(StringRef Name, StringRef USR, StringRef Source="")
Definition: API.cpp:112
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.
The JSON file list parser is used to communicate input to InstallAPI.
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.