Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions clang-tools-extra/clang-doc/Serialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,10 @@ static RecordDecl *getRecordDeclForType(const QualType &T) {
return nullptr;
}

TypeInfo getTypeInfoForType(const QualType &T) {
TypeInfo getTypeInfoForType(const QualType &T, const PrintingPolicy &Policy) {
const TagDecl *TD = getTagDeclForType(T);
if (!TD)
return TypeInfo(Reference(SymbolID(), T.getAsString()));
return TypeInfo(Reference(SymbolID(), T.getAsString(Policy)));

InfoType IT;
if (dyn_cast<EnumDecl>(TD)) {
Expand All @@ -250,7 +250,7 @@ TypeInfo getTypeInfoForType(const QualType &T) {
IT = InfoType::IT_default;
}
return TypeInfo(Reference(getUSRForDecl(TD), TD->getNameAsString(), IT,
T.getAsString(), getInfoRelativePath(TD)));
T.getAsString(Policy), getInfoRelativePath(TD)));
}

static bool isPublic(const clang::AccessSpecifier AS,
Expand Down Expand Up @@ -379,10 +379,11 @@ static void parseFields(RecordInfo &I, const RecordDecl *D, bool PublicOnly,
if (!shouldSerializeInfo(PublicOnly, /*IsInAnonymousNamespace=*/false, F))
continue;

auto &LO = F->getLangOpts();
// Use getAccessUnsafe so that we just get the default AS_none if it's not
// valid, as opposed to an assert.
MemberTypeInfo &NewMember = I.Members.emplace_back(
getTypeInfoForType(F->getTypeSourceInfo()->getType()),
getTypeInfoForType(F->getTypeSourceInfo()->getType(), LO),
F->getNameAsString(),
getFinalAccessSpecifier(Access, F->getAccessUnsafe()));
populateMemberTypeInfo(NewMember, F);
Expand Down Expand Up @@ -412,9 +413,10 @@ static void parseEnumerators(EnumInfo &I, const EnumDecl *D) {
}

static void parseParameters(FunctionInfo &I, const FunctionDecl *D) {
auto &LO = D->getLangOpts();
for (const ParmVarDecl *P : D->parameters()) {
FieldTypeInfo &FieldInfo = I.Params.emplace_back(
getTypeInfoForType(P->getOriginalType()), P->getNameAsString());
getTypeInfoForType(P->getOriginalType(), LO), P->getNameAsString());
FieldInfo.DefaultValue = getSourceCode(D, P->getDefaultArgRange());
}
}
Expand Down Expand Up @@ -541,7 +543,8 @@ static void populateFunctionInfo(FunctionInfo &I, const FunctionDecl *D,
bool &IsInAnonymousNamespace) {
populateSymbolInfo(I, D, FC, LineNumber, Filename, IsFileInRootDir,
IsInAnonymousNamespace);
I.ReturnType = getTypeInfoForType(D->getReturnType());
auto &LO = D->getLangOpts();
I.ReturnType = getTypeInfoForType(D->getReturnType(), LO);
parseParameters(I, D);

PopulateTemplateParameters(I.Template, D);
Expand Down Expand Up @@ -783,7 +786,8 @@ emitInfo(const TypedefDecl *D, const FullComment *FC, int LineNumber,
return {};

Info.DefLoc.emplace(LineNumber, File, IsFileInRootDir);
Info.Underlying = getTypeInfoForType(D->getUnderlyingType());
auto &LO = D->getLangOpts();
Info.Underlying = getTypeInfoForType(D->getUnderlyingType(), LO);
if (Info.Underlying.Type.Name.empty()) {
// Typedef for an unnamed type. This is like "typedef struct { } Foo;"
// The record serializer explicitly checks for this syntax and constructs
Expand All @@ -809,7 +813,8 @@ emitInfo(const TypeAliasDecl *D, const FullComment *FC, int LineNumber,
return {};

Info.DefLoc.emplace(LineNumber, File, IsFileInRootDir);
Info.Underlying = getTypeInfoForType(D->getUnderlyingType());
auto &LO = D->getLangOpts();
Info.Underlying = getTypeInfoForType(D->getUnderlyingType(), LO);
Info.IsUsing = true;

// Info is wrapped in its parent scope so is returned in the second position.
Expand Down
6 changes: 3 additions & 3 deletions clang-tools-extra/test/clang-doc/builtin_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ extern bool b();
// YAML-NEXT: Filename: '{{.*}}'
// YAML-NEXT: ReturnType:
// YAML-NEXT: Type:
// YAML-NEXT: Name: '_Bool'
// YAML-NEXT: QualName: '_Bool'
// YAML-NEXT: Name: 'bool'
// YAML-NEXT: QualName: 'bool'

// MD: ### b
// MD: *_Bool b()*
// MD: *bool b()*

char c();

Expand Down
12 changes: 6 additions & 6 deletions clang-tools-extra/test/clang-doc/templates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ void function<bool, 0>(bool x) {}
// YAML-NEXT: Filename: '{{.*}}'
// YAML-NEXT: Params:
// YAML-NEXT: - Type:
// YAML-NEXT: Name: '_Bool'
// YAML-NEXT: QualName: '_Bool'
// YAML-NEXT: Name: 'bool'
// YAML-NEXT: QualName: 'bool'
// YAML-NEXT: Name: 'x'
// YAML-NEXT: ReturnType:
// YAML-NEXT: Type:
Expand All @@ -95,7 +95,7 @@ void function<bool, 0>(bool x) {}
// YAML-NEXT: - Contents: '0'

// MD: ### function
// MD: *void function(_Bool x)*
// MD: *void function(bool x)*
// MD: *Defined at {{.*}}templates.cpp#[[# @LINE - 26]]*

/// A Tuple type
Expand Down Expand Up @@ -136,21 +136,21 @@ tuple<int,int,bool> func_with_tuple_param(tuple<int,int,bool> t){ return t;}
// YAML-NEXT: - Type:
// YAML-NEXT: Type: Record
// YAML-NEXT: Name: 'tuple'
// YAML-NEXT: QualName: 'tuple<int, int, _Bool>'
// YAML-NEXT: QualName: 'tuple<int, int, bool>'
// YAML-NEXT: USR: '{{([0-9A-F]{40})}}'
// YAML-NEXT: Path: 'GlobalNamespace'
// YAML-NEXT: Name: 't'
// YAML-NEXT: ReturnType:
// YAML-NEXT: Type:
// YAML-NEXT: Type: Record
// YAML-NEXT: Name: 'tuple'
// YAML-NEXT: QualName: 'tuple<int, int, _Bool>'
// YAML-NEXT: QualName: 'tuple<int, int, bool>'
// YAML-NEXT: USR: '{{([0-9A-F]{40})}}'
// YAML-NEXT: Path: 'GlobalNamespace'
// YAML-NEXT: ...

// MD: ### func_with_tuple_param
// MD: *tuple<int, int, _Bool> func_with_tuple_param(tuple<int, int, _Bool> t)*
// MD: *tuple<int, int, bool> func_with_tuple_param(tuple<int, int, bool> t)*
// MD: *Defined at {{.*}}templates.cpp#[[# @LINE - 44]]*
// MD: A function with a tuple parameter
// MD: **t** The input to func_with_tuple_param
Expand Down
6 changes: 4 additions & 2 deletions clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,8 +631,8 @@ TEST(SerializeTests, emitTypedefs) {
TEST(SerializeTests, emitFunctionTemplate) {
EmittedInfoList Infos;
// A template and a specialization.
ExtractInfosFromCode("template<typename T = int> void GetFoo(T);\n"
"template<> void GetFoo<bool>(bool);",
ExtractInfosFromCode("template<typename T = int> bool GetFoo(T);\n"
"template<> bool GetFoo<bool>(bool);",
2,
/*Public=*/false, Infos);

Expand Down Expand Up @@ -666,6 +666,8 @@ TEST(SerializeTests, emitFunctionTemplate) {
ASSERT_EQ(1u, Func2.Template->Specialization->Params.size());
EXPECT_EQ("bool", Func2.Template->Specialization->Params[0].Contents);
EXPECT_EQ(Func1.USR, Func2.Template->Specialization->SpecializationOf);

EXPECT_EQ("bool", Func2.ReturnType.Type.Name);
}

TEST(SerializeTests, emitClassTemplate) {
Expand Down
Loading