10 #include "clang/AST/ASTContext.h" 11 #include "clang/AST/DeclTemplate.h" 12 #include "clang/AST/Type.h" 13 #include "clang/Index/USRGeneration.h" 14 #include "clang/Sema/CodeCompleteConsumer.h" 15 #include "llvm/ADT/None.h" 16 #include "llvm/ADT/STLExtras.h" 22 static const Type *toEquivClass(ASTContext &
Ctx, QualType T) {
23 if (T.isNull() || T->isDependentType())
26 T = T.getCanonicalType().getNonReferenceType();
28 if (T->isBooleanType())
29 return Ctx.BoolTy.getTypePtr();
30 if (T->isIntegerType() && !T->isEnumeralType())
31 return Ctx.IntTy.getTypePtr();
32 if (T->isFloatingType() && !T->isComplexType())
33 return Ctx.FloatTy.getTypePtr();
37 return Ctx.getPointerType(QualType(T->getArrayElementTypeNoTypeQual(), 0))
41 return T.getTypePtr();
44 static llvm::Optional<QualType>
45 typeOfCompletion(
const CodeCompletionResult &R) {
46 const NamedDecl *
D = R.Declaration;
50 if (
auto *Template = dyn_cast<TemplateDecl>(D))
51 D = Template->getTemplatedDecl();
52 auto *VD = dyn_cast<ValueDecl>(
D);
55 auto T = VD->getType();
58 if (
auto FuncT = T->getAs<FunctionType>()) {
63 return FuncT->getReturnType();
69 llvm::Optional<OpaqueType> OpaqueType::encode(ASTContext &Ctx, QualType T) {
72 const Type *C = toEquivClass(Ctx, T);
75 llvm::SmallString<128> Encoded;
76 if (index::generateUSRForType(QualType(C, 0), Ctx, Encoded))
78 return OpaqueType(Encoded.str());
81 OpaqueType::OpaqueType(std::string Data) : Data(std::move(Data)) {}
83 llvm::Optional<OpaqueType> OpaqueType::fromType(ASTContext &Ctx,
85 return encode(Ctx, Type);
88 llvm::Optional<OpaqueType>
89 OpaqueType::fromCompletionResult(ASTContext &Ctx,
90 const CodeCompletionResult &R) {
91 auto T = typeOfCompletion(R);
94 return encode(Ctx, *T);
Documents should not be synced at all.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//