diff --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp b/clang-tools-extra/clang-doc/BitcodeReader.cpp index da7f6246b029..027272691d03 100644 --- a/clang-tools-extra/clang-doc/BitcodeReader.cpp +++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp @@ -342,8 +342,6 @@ llvm::Error parseRecord(const Record &R, unsigned ID, llvm::StringRef Blob, return decodeRecord(R, I->RefType, Blob); case REFERENCE_PATH: return decodeRecord(R, I->Path, Blob); - case REFERENCE_IS_IN_GLOBAL_NAMESPACE: - return decodeRecord(R, I->IsInGlobalNamespace, Blob); case REFERENCE_FIELD: return decodeRecord(R, F, Blob); default: diff --git a/clang-tools-extra/clang-doc/BitcodeWriter.cpp b/clang-tools-extra/clang-doc/BitcodeWriter.cpp index 993e4ddc9d48..194194aef3e2 100644 --- a/clang-tools-extra/clang-doc/BitcodeWriter.cpp +++ b/clang-tools-extra/clang-doc/BitcodeWriter.cpp @@ -187,8 +187,6 @@ static const llvm::IndexedMap {REFERENCE_NAME, {"Name", &StringAbbrev}}, {REFERENCE_TYPE, {"RefType", &IntAbbrev}}, {REFERENCE_PATH, {"Path", &StringAbbrev}}, - {REFERENCE_IS_IN_GLOBAL_NAMESPACE, - {"IsInGlobalNamespace", &BoolAbbrev}}, {REFERENCE_FIELD, {"Field", &IntAbbrev}}}; assert(Inits.size() == RecordIdCount); for (const auto &Init : Inits) { @@ -239,7 +237,7 @@ static const std::vector>> // Reference Block {BI_REFERENCE_BLOCK_ID, {REFERENCE_USR, REFERENCE_NAME, REFERENCE_TYPE, REFERENCE_PATH, - REFERENCE_IS_IN_GLOBAL_NAMESPACE, REFERENCE_FIELD}}}; + REFERENCE_FIELD}}}; // AbbreviationMap @@ -412,7 +410,6 @@ void ClangDocBitcodeWriter::emitBlock(const Reference &R, FieldId Field) { emitRecord(R.Name, REFERENCE_NAME); emitRecord((unsigned)R.RefType, REFERENCE_TYPE); emitRecord(R.Path, REFERENCE_PATH); - emitRecord(R.IsInGlobalNamespace, REFERENCE_IS_IN_GLOBAL_NAMESPACE); emitRecord((unsigned)Field, REFERENCE_FIELD); } diff --git a/clang-tools-extra/clang-doc/BitcodeWriter.h b/clang-tools-extra/clang-doc/BitcodeWriter.h index 4015c5da35bd..d5aba22db9cf 100644 --- a/clang-tools-extra/clang-doc/BitcodeWriter.h +++ b/clang-tools-extra/clang-doc/BitcodeWriter.h @@ -122,7 +122,6 @@ enum RecordId { REFERENCE_NAME, REFERENCE_TYPE, REFERENCE_PATH, - REFERENCE_IS_IN_GLOBAL_NAMESPACE, REFERENCE_FIELD, RI_LAST, RI_FIRST = VERSION diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp b/clang-tools-extra/clang-doc/HTMLGenerator.cpp index 211cc9ff2053..45f10e0f20dd 100644 --- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp +++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp @@ -308,7 +308,7 @@ static std::unique_ptr genLink(const Twine &Text, const Twine &Link) { static std::unique_ptr genReference(const Reference &Type, StringRef CurrentDirectory, llvm::Optional JumpToSection = None) { - if (Type.Path.empty() && !Type.IsInGlobalNamespace) { + if (Type.Path.empty()) { if (!JumpToSection) return std::make_unique(Type.Name); else diff --git a/clang-tools-extra/clang-doc/Representation.cpp b/clang-tools-extra/clang-doc/Representation.cpp index deb508d9e92b..1e76543525c4 100644 --- a/clang-tools-extra/clang-doc/Representation.cpp +++ b/clang-tools-extra/clang-doc/Representation.cpp @@ -170,8 +170,6 @@ void Reference::merge(Reference &&Other) { Name = Other.Name; if (Path.empty()) Path = Other.Path; - if (!IsInGlobalNamespace) - IsInGlobalNamespace = Other.IsInGlobalNamespace; } void Info::mergeBase(Info &&Other) { diff --git a/clang-tools-extra/clang-doc/Representation.h b/clang-tools-extra/clang-doc/Representation.h index 5385aa96c1f5..39e872358c72 100644 --- a/clang-tools-extra/clang-doc/Representation.h +++ b/clang-tools-extra/clang-doc/Representation.h @@ -114,19 +114,9 @@ struct CommentInfo { }; struct Reference { - Reference() = default; - Reference(llvm::StringRef Name) : Name(Name) {} - // An empty path means the info is in the global namespace because the path is - // a composite of the parent namespaces. - Reference(llvm::StringRef Name, StringRef Path) - : Name(Name), Path(Path), IsInGlobalNamespace(Path.empty()) {} - Reference(SymbolID USR, StringRef Name, InfoType IT) - : USR(USR), Name(Name), RefType(IT) {} - // An empty path means the info is in the global namespace because the path is - // a composite of the parent namespaces. - Reference(SymbolID USR, StringRef Name, InfoType IT, StringRef Path) - : USR(USR), Name(Name), RefType(IT), Path(Path), - IsInGlobalNamespace(Path.empty()) {} + Reference(SymbolID USR = SymbolID(), StringRef Name = StringRef(), + InfoType IT = InfoType::IT_default, StringRef Path = StringRef()) + : USR(USR), Name(Name), RefType(IT), Path(Path) {} bool operator==(const Reference &Other) const { return std::tie(USR, Name, RefType) == @@ -150,9 +140,6 @@ struct Reference { // Path of directory where the clang-doc generated file will be saved // (possibly unresolved) llvm::SmallString<128> Path; - // Indicates if the info's parent is the global namespace, or if the info is - // the global namespace - bool IsInGlobalNamespace = false; }; // A base struct for TypeInfos @@ -160,12 +147,10 @@ struct TypeInfo { TypeInfo() = default; TypeInfo(const Reference &R) : Type(R) {} - TypeInfo(SymbolID Type, StringRef Field, InfoType IT) - : Type(Type, Field, IT) {} - TypeInfo(SymbolID Type, StringRef Field, InfoType IT, StringRef Path) - : Type(Type, Field, IT, Path) {} - TypeInfo(llvm::StringRef RefName) : Type(RefName) {} - TypeInfo(llvm::StringRef RefName, StringRef Path) : Type(RefName, Path) {} + // Convenience constructor for when there is no symbol ID or info type + // (normally used for built-in types in tests). + TypeInfo(StringRef Name, StringRef Path = StringRef()) + : Type(SymbolID(), Name, InfoType::IT_default, Path) {} bool operator==(const TypeInfo &Other) const { return Type == Other.Type; } @@ -178,13 +163,6 @@ struct FieldTypeInfo : public TypeInfo { FieldTypeInfo(const TypeInfo &TI, StringRef Name = StringRef(), StringRef DefaultValue = StringRef()) : TypeInfo(TI), Name(Name), DefaultValue(DefaultValue) {} - FieldTypeInfo(SymbolID Type, StringRef Field, InfoType IT, StringRef Path, - llvm::StringRef Name) - : TypeInfo(Type, Field, IT, Path), Name(Name) {} - FieldTypeInfo(llvm::StringRef RefName, llvm::StringRef Name) - : TypeInfo(RefName), Name(Name) {} - FieldTypeInfo(llvm::StringRef RefName, StringRef Path, llvm::StringRef Name) - : TypeInfo(RefName, Path), Name(Name) {} bool operator==(const FieldTypeInfo &Other) const { return std::tie(Type, Name, DefaultValue) == @@ -203,15 +181,6 @@ struct MemberTypeInfo : public FieldTypeInfo { MemberTypeInfo() = default; MemberTypeInfo(const TypeInfo &TI, StringRef Name, AccessSpecifier Access) : FieldTypeInfo(TI, Name), Access(Access) {} - MemberTypeInfo(SymbolID Type, StringRef Field, InfoType IT, StringRef Path, - llvm::StringRef Name, AccessSpecifier Access) - : FieldTypeInfo(Type, Field, IT, Path, Name), Access(Access) {} - MemberTypeInfo(llvm::StringRef RefName, llvm::StringRef Name, - AccessSpecifier Access) - : FieldTypeInfo(RefName, Name), Access(Access) {} - MemberTypeInfo(llvm::StringRef RefName, StringRef Path, llvm::StringRef Name, - AccessSpecifier Access) - : FieldTypeInfo(RefName, Path, Name), Access(Access) {} bool operator==(const MemberTypeInfo &Other) const { return std::tie(Type, Name, Access, Description) == @@ -228,11 +197,9 @@ struct MemberTypeInfo : public FieldTypeInfo { }; struct Location { - Location() = default; - Location(int LineNumber, SmallString<16> Filename) - : LineNumber(LineNumber), Filename(std::move(Filename)) {} - Location(int LineNumber, SmallString<16> Filename, bool IsFileInRootDir) - : LineNumber(LineNumber), Filename(std::move(Filename)), + Location(int LineNumber = 0, StringRef Filename = StringRef(), + bool IsFileInRootDir = false) + : LineNumber(LineNumber), Filename(Filename), IsFileInRootDir(IsFileInRootDir) {} bool operator==(const Location &Other) const { @@ -249,20 +216,17 @@ struct Location { std::tie(Other.LineNumber, Other.Filename); } - int LineNumber; // Line number of this Location. + int LineNumber = 0; // Line number of this Location. SmallString<32> Filename; // File for this Location. bool IsFileInRootDir = false; // Indicates if file is inside root directory }; /// A base struct for Infos. struct Info { - Info() = default; - Info(InfoType IT) : IT(IT) {} - Info(InfoType IT, SymbolID USR) : USR(USR), IT(IT) {} - Info(InfoType IT, SymbolID USR, StringRef Name) - : USR(USR), IT(IT), Name(Name) {} - Info(InfoType IT, SymbolID USR, StringRef Name, StringRef Path) + Info(InfoType IT = InfoType::IT_default, SymbolID USR = SymbolID(), + StringRef Name = StringRef(), StringRef Path = StringRef()) : USR(USR), IT(IT), Name(Name), Path(Path) {} + Info(const Info &Other) = delete; Info(Info &&Other) = default; @@ -296,11 +260,8 @@ struct Info { // Info for namespaces. struct NamespaceInfo : public Info { - NamespaceInfo() : Info(InfoType::IT_namespace) {} - NamespaceInfo(SymbolID USR) : Info(InfoType::IT_namespace, USR) {} - NamespaceInfo(SymbolID USR, StringRef Name) - : Info(InfoType::IT_namespace, USR, Name) {} - NamespaceInfo(SymbolID USR, StringRef Name, StringRef Path) + NamespaceInfo(SymbolID USR = SymbolID(), StringRef Name = StringRef(), + StringRef Path = StringRef()) : Info(InfoType::IT_namespace, USR, Name, Path) {} void merge(NamespaceInfo &&I); @@ -317,10 +278,8 @@ struct NamespaceInfo : public Info { // Info for symbols. struct SymbolInfo : public Info { - SymbolInfo(InfoType IT) : Info(IT) {} - SymbolInfo(InfoType IT, SymbolID USR) : Info(IT, USR) {} - SymbolInfo(InfoType IT, SymbolID USR, StringRef Name) : Info(IT, USR, Name) {} - SymbolInfo(InfoType IT, SymbolID USR, StringRef Name, StringRef Path) + SymbolInfo(InfoType IT, SymbolID USR = SymbolID(), + StringRef Name = StringRef(), StringRef Path = StringRef()) : Info(IT, USR, Name, Path) {} void merge(SymbolInfo &&I); @@ -332,8 +291,8 @@ struct SymbolInfo : public Info { // TODO: Expand to allow for documenting templating and default args. // Info for functions. struct FunctionInfo : public SymbolInfo { - FunctionInfo() : SymbolInfo(InfoType::IT_function) {} - FunctionInfo(SymbolID USR) : SymbolInfo(InfoType::IT_function, USR) {} + FunctionInfo(SymbolID USR = SymbolID()) + : SymbolInfo(InfoType::IT_function, USR) {} void merge(FunctionInfo &&I); @@ -352,11 +311,8 @@ struct FunctionInfo : public SymbolInfo { // friend classes // Info for types. struct RecordInfo : public SymbolInfo { - RecordInfo() : SymbolInfo(InfoType::IT_record) {} - RecordInfo(SymbolID USR) : SymbolInfo(InfoType::IT_record, USR) {} - RecordInfo(SymbolID USR, StringRef Name) - : SymbolInfo(InfoType::IT_record, USR, Name) {} - RecordInfo(SymbolID USR, StringRef Name, StringRef Path) + RecordInfo(SymbolID USR = SymbolID(), StringRef Name = StringRef(), + StringRef Path = StringRef()) : SymbolInfo(InfoType::IT_record, USR, Name, Path) {} void merge(RecordInfo &&I); @@ -450,9 +406,9 @@ struct EnumInfo : public SymbolInfo { struct Index : public Reference { Index() = default; - Index(StringRef Name) : Reference(Name) {} + Index(StringRef Name) : Reference(SymbolID(), Name) {} Index(StringRef Name, StringRef JumpToSection) - : Reference(Name), JumpToSection(JumpToSection) {} + : Reference(SymbolID(), Name), JumpToSection(JumpToSection) {} Index(SymbolID USR, StringRef Name, InfoType IT, StringRef Path) : Reference(USR, Name, IT, Path) {} // This is used to look for a USR in a vector of Indexes using std::find diff --git a/clang-tools-extra/clang-doc/Serialize.cpp b/clang-tools-extra/clang-doc/Serialize.cpp index 45056061a640..aeade31782ba 100644 --- a/clang-tools-extra/clang-doc/Serialize.cpp +++ b/clang-tools-extra/clang-doc/Serialize.cpp @@ -239,7 +239,7 @@ static RecordDecl *getRecordDeclForType(const QualType &T) { TypeInfo getTypeInfoForType(const QualType &T) { const TagDecl *TD = getTagDeclForType(T); if (!TD) - return TypeInfo(Reference(T.getAsString())); + return TypeInfo(Reference(SymbolID(), T.getAsString())); InfoType IT; if (dyn_cast(TD)) { @@ -360,7 +360,7 @@ static void parseBases(RecordInfo &I, const CXXRecordDecl *D) { I.Parents.emplace_back(getUSRForDecl(P), P->getNameAsString(), InfoType::IT_record, getInfoRelativePath(P)); else - I.Parents.emplace_back(B.getType().getAsString()); + I.Parents.emplace_back(SymbolID(), B.getType().getAsString()); } for (const CXXBaseSpecifier &B : D->vbases()) { if (const RecordDecl *P = getRecordDeclForType(B.getType())) @@ -368,7 +368,7 @@ static void parseBases(RecordInfo &I, const CXXRecordDecl *D) { InfoType::IT_record, getInfoRelativePath(P)); else - I.VirtualParents.emplace_back(B.getType().getAsString()); + I.VirtualParents.emplace_back(SymbolID(), B.getType().getAsString()); } } diff --git a/clang-tools-extra/clang-doc/YAMLGenerator.cpp b/clang-tools-extra/clang-doc/YAMLGenerator.cpp index 14d2c878520d..6406b817f1d4 100644 --- a/clang-tools-extra/clang-doc/YAMLGenerator.cpp +++ b/clang-tools-extra/clang-doc/YAMLGenerator.cpp @@ -174,7 +174,6 @@ template <> struct MappingTraits { IO.mapOptional("Name", Ref.Name, SmallString<16>()); IO.mapOptional("USR", Ref.USR, SymbolID()); IO.mapOptional("Path", Ref.Path, SmallString<128>()); - IO.mapOptional("IsInGlobalNamespace", Ref.IsInGlobalNamespace, false); } }; diff --git a/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp b/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp index 784e85f98eeb..e6933a7237cb 100644 --- a/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp +++ b/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp @@ -78,13 +78,14 @@ TEST(BitcodeTest, emitRecordInfoBitcode) { I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"}); I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"}); - I.Members.emplace_back("int", "X", AccessSpecifier::AS_private); + I.Members.emplace_back(TypeInfo("int"), "X", AccessSpecifier::AS_private); I.TagType = TagTypeKind::TTK_Class; I.IsTypeDef = true; I.Bases.emplace_back(EmptySID, "F", "path/to/F", true, AccessSpecifier::AS_public, true); I.Bases.back().ChildFunctions.emplace_back(); - I.Bases.back().Members.emplace_back("int", "X", AccessSpecifier::AS_private); + I.Bases.back().Members.emplace_back(TypeInfo("int"), "X", + AccessSpecifier::AS_private); I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record); I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record); @@ -119,8 +120,8 @@ TEST(BitcodeTest, emitFunctionInfoBitcode) { I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"}); I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"}); - I.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default); - I.Params.emplace_back("int", "P"); + I.ReturnType = TypeInfo("void"); + I.Params.emplace_back(TypeInfo("int"), "P"); I.Access = AccessSpecifier::AS_none; @@ -139,8 +140,8 @@ TEST(BitcodeTest, emitMethodInfoBitcode) { I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"}); I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"}); - I.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default); - I.Params.emplace_back("int", "P"); + I.ReturnType = TypeInfo("void"); + I.Params.emplace_back(TypeInfo("int"), "P"); I.IsMethod = true; I.Parent = Reference(EmptySID, "Parent", InfoType::IT_record); @@ -174,9 +175,9 @@ TEST(BitcodeTest, emitEnumInfoBitcode) { TEST(SerializeTest, emitInfoWithCommentBitcode) { FunctionInfo F; F.Name = "F"; - F.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default); + F.ReturnType = TypeInfo("void"); F.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"}); - F.Params.emplace_back("int", "I"); + F.Params.emplace_back(TypeInfo("int"), "I"); CommentInfo Top; Top.Kind = "FullComment"; diff --git a/clang-tools-extra/unittests/clang-doc/GeneratorTest.cpp b/clang-tools-extra/unittests/clang-doc/GeneratorTest.cpp index ff0ca069970b..e7f68b405284 100644 --- a/clang-tools-extra/unittests/clang-doc/GeneratorTest.cpp +++ b/clang-tools-extra/unittests/clang-doc/GeneratorTest.cpp @@ -24,7 +24,7 @@ TEST(GeneratorTest, emitIndex) { auto InfoC = std::make_unique(); InfoC->Name = "C"; InfoC->USR = serialize::hashUSR("3"); - Reference RefB = Reference("B"); + Reference RefB = Reference(SymbolID(), "B"); RefB.USR = serialize::hashUSR("2"); InfoC->Namespace = {std::move(RefB)}; Generator::addInfoToIndex(Idx, InfoC.get()); @@ -34,9 +34,9 @@ TEST(GeneratorTest, emitIndex) { auto InfoF = std::make_unique(); InfoF->Name = "F"; InfoF->USR = serialize::hashUSR("6"); - Reference RefD = Reference("D"); + Reference RefD = Reference(SymbolID(), "D"); RefD.USR = serialize::hashUSR("4"); - Reference RefE = Reference("E"); + Reference RefE = Reference(SymbolID(), "E"); RefE.USR = serialize::hashUSR("5"); InfoF->Namespace = {std::move(RefE), std::move(RefD)}; Generator::addInfoToIndex(Idx, InfoF.get()); diff --git a/clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp b/clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp index 880a1af1228a..25ecb55627dc 100644 --- a/clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp +++ b/clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp @@ -152,7 +152,8 @@ TEST(HTMLGeneratorTest, emitRecordHTML) { SmallString<16> PathTo; llvm::sys::path::native("path/to", PathTo); - I.Members.emplace_back("int", "X/Y", "X", AccessSpecifier::AS_private); + I.Members.emplace_back(TypeInfo("int", "X/Y"), "X", + AccessSpecifier::AS_private); I.TagType = TagTypeKind::TTK_Class; I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record, PathTo); I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record); @@ -276,8 +277,9 @@ TEST(HTMLGeneratorTest, emitFunctionHTML) { SmallString<16> PathTo; llvm::sys::path::native("path/to", PathTo); - I.ReturnType = TypeInfo(EmptySID, "float", InfoType::IT_default, PathTo); - I.Params.emplace_back("int", PathTo, "P"); + I.ReturnType = + TypeInfo(Reference(EmptySID, "float", InfoType::IT_default, PathTo)); + I.Params.emplace_back(TypeInfo("int", PathTo), "P"); I.IsMethod = true; I.Parent = Reference(EmptySID, "Parent", InfoType::IT_record); @@ -370,9 +372,9 @@ TEST(HTMLGeneratorTest, emitCommentHTML) { FunctionInfo I; I.Name = "f"; I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"}); - I.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default); - I.Params.emplace_back("int", "I"); - I.Params.emplace_back("int", "J"); + I.ReturnType = TypeInfo("void"); + I.Params.emplace_back(TypeInfo("int"), "I"); + I.Params.emplace_back(TypeInfo("int"), "J"); I.Access = AccessSpecifier::AS_none; CommentInfo Top; diff --git a/clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp b/clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp index 006fde08c5c4..f2a7858f5cb7 100644 --- a/clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp +++ b/clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp @@ -85,7 +85,7 @@ TEST(MDGeneratorTest, emitRecordMD) { I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"}); I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"}); - I.Members.emplace_back("int", "X", AccessSpecifier::AS_private); + I.Members.emplace_back(TypeInfo("int"), "X", AccessSpecifier::AS_private); I.TagType = TagTypeKind::TTK_Class; I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record); I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record); @@ -154,8 +154,8 @@ TEST(MDGeneratorTest, emitFunctionMD) { I.Access = AccessSpecifier::AS_none; - I.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default); - I.Params.emplace_back("int", "P"); + I.ReturnType = TypeInfo("void"); + I.Params.emplace_back(TypeInfo("int"), "P"); I.IsMethod = true; I.Parent = Reference(EmptySID, "Parent", InfoType::IT_record); @@ -211,9 +211,9 @@ TEST(MDGeneratorTest, emitCommentMD) { FunctionInfo I; I.Name = "f"; I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"}); - I.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default); - I.Params.emplace_back("int", "I"); - I.Params.emplace_back("int", "J"); + I.ReturnType = TypeInfo("void"); + I.Params.emplace_back(TypeInfo("int"), "I"); + I.Params.emplace_back(TypeInfo("int"), "J"); I.Access = AccessSpecifier::AS_none; CommentInfo Top; diff --git a/clang-tools-extra/unittests/clang-doc/MergeTest.cpp b/clang-tools-extra/unittests/clang-doc/MergeTest.cpp index 3647ebdbc377..2305bd2bdce3 100644 --- a/clang-tools-extra/unittests/clang-doc/MergeTest.cpp +++ b/clang-tools-extra/unittests/clang-doc/MergeTest.cpp @@ -83,7 +83,7 @@ TEST(MergeTest, mergeRecordInfos) { One.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"}); - One.Members.emplace_back("int", "X", AccessSpecifier::AS_private); + One.Members.emplace_back(TypeInfo("int"), "X", AccessSpecifier::AS_private); One.TagType = TagTypeKind::TTK_Class; One.Parents.emplace_back(EmptySID, "F", InfoType::IT_record); One.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record); @@ -126,7 +126,8 @@ TEST(MergeTest, mergeRecordInfos) { Expected->DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"}); Expected->Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"}); - Expected->Members.emplace_back("int", "X", AccessSpecifier::AS_private); + Expected->Members.emplace_back(TypeInfo("int"), "X", + AccessSpecifier::AS_private); Expected->TagType = TagTypeKind::TTK_Class; Expected->Parents.emplace_back(EmptySID, "F", InfoType::IT_record); Expected->VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record); @@ -180,8 +181,8 @@ TEST(MergeTest, mergeFunctionInfos) { Two.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"}); - Two.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default); - Two.Params.emplace_back("int", "P"); + Two.ReturnType = TypeInfo("void"); + Two.Params.emplace_back(TypeInfo("int"), "P"); Two.Description.emplace_back(); auto TwoFullComment = &Two.Description.back(); @@ -205,8 +206,8 @@ TEST(MergeTest, mergeFunctionInfos) { Expected->DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"}); Expected->Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"}); - Expected->ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default); - Expected->Params.emplace_back("int", "P"); + Expected->ReturnType = TypeInfo("void"); + Expected->Params.emplace_back(TypeInfo("int"), "P"); Expected->IsMethod = true; Expected->Parent = Reference(EmptySID, "Parent", InfoType::IT_namespace); diff --git a/clang-tools-extra/unittests/clang-doc/SerializeTest.cpp b/clang-tools-extra/unittests/clang-doc/SerializeTest.cpp index 49a57aa06320..bc45264a4b82 100644 --- a/clang-tools-extra/unittests/clang-doc/SerializeTest.cpp +++ b/clang-tools-extra/unittests/clang-doc/SerializeTest.cpp @@ -119,7 +119,7 @@ TEST(SerializeTest, emitNamespaceInfo) { NamespaceInfo ExpectedBWithFunction(EmptySID); FunctionInfo F; F.Name = "f"; - F.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default); + F.ReturnType = TypeInfo("void"); F.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"}); F.Namespace.emplace_back(EmptySID, "B", InfoType::IT_namespace); F.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace); @@ -165,7 +165,8 @@ typedef struct {} G;)raw", InfoType::IT_namespace); ExpectedE.TagType = TagTypeKind::TTK_Class; ExpectedE.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"}); - ExpectedE.Members.emplace_back("int", "value", AccessSpecifier::AS_public); + ExpectedE.Members.emplace_back(TypeInfo("int"), "value", + AccessSpecifier::AS_public); // TODO the data member should have the docstring on it: //ExpectedE.Members.back().Description.push_back(MakeOneLineCommentInfo(" Some docs")); CheckRecordInfo(&ExpectedE, E); @@ -175,7 +176,7 @@ typedef struct {} G;)raw", FunctionInfo EConstructor; EConstructor.Name = "E"; EConstructor.Parent = Reference(EmptySID, "E", InfoType::IT_record); - EConstructor.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default); + EConstructor.ReturnType = TypeInfo("void"); EConstructor.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"}); EConstructor.Namespace.emplace_back(EmptySID, "E", InfoType::IT_record); EConstructor.Namespace.emplace_back(EmptySID, "GlobalNamespace", @@ -191,7 +192,7 @@ typedef struct {} G;)raw", FunctionInfo Method; Method.Name = "ProtectedMethod"; Method.Parent = Reference(EmptySID, "E", InfoType::IT_record); - Method.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default); + Method.ReturnType = TypeInfo("void"); Method.Loc.emplace_back(0, llvm::SmallString<16>{"test.cpp"}); Method.Namespace.emplace_back(EmptySID, "E", InfoType::IT_record); Method.Namespace.emplace_back(EmptySID, "GlobalNamespace", @@ -214,7 +215,7 @@ typedef struct {} G;)raw", FunctionInfo TemplateMethod; TemplateMethod.Name = "TemplateMethod"; TemplateMethod.Parent = Reference(EmptySID, "F", InfoType::IT_record); - TemplateMethod.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default); + TemplateMethod.ReturnType = TypeInfo("void"); TemplateMethod.Loc.emplace_back(0, llvm::SmallString<16>{"test.cpp"}); TemplateMethod.Namespace.emplace_back(EmptySID, "F", InfoType::IT_record); TemplateMethod.Namespace.emplace_back(EmptySID, "GlobalNamespace", @@ -231,8 +232,7 @@ typedef struct {} G;)raw", SpecializedTemplateMethod.Name = "TemplateMethod"; SpecializedTemplateMethod.Parent = Reference(EmptySID, "F", InfoType::IT_record); - SpecializedTemplateMethod.ReturnType = - TypeInfo(EmptySID, "void", InfoType::IT_default); + SpecializedTemplateMethod.ReturnType = TypeInfo("void"); SpecializedTemplateMethod.Loc.emplace_back(0, llvm::SmallString<16>{"test.cpp"}); SpecializedTemplateMethod.Namespace.emplace_back(EmptySID, "F", @@ -306,7 +306,8 @@ TEST(SerializeTest, emitRecordMemberInfo) { InfoType::IT_namespace); ExpectedE.TagType = TagTypeKind::TTK_Struct; ExpectedE.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"}); - ExpectedE.Members.emplace_back("int", "I", AccessSpecifier::AS_public); + ExpectedE.Members.emplace_back(TypeInfo("int"), "I", + AccessSpecifier::AS_public); CheckRecordInfo(&ExpectedE, E); } @@ -348,7 +349,7 @@ TEST(SerializeTest, emitPublicFunctionInternalInfo) { NamespaceInfo ExpectedBWithFunction(EmptySID); FunctionInfo F; F.Name = "F"; - F.ReturnType = TypeInfo(EmptySID, "int", InfoType::IT_default); + F.ReturnType = TypeInfo("int"); F.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"}); F.Access = AccessSpecifier::AS_none; ExpectedBWithFunction.ChildFunctions.emplace_back(std::move(F)); @@ -363,9 +364,9 @@ TEST(SerializeTest, emitInlinedFunctionInfo) { NamespaceInfo ExpectedBWithFunction(EmptySID); FunctionInfo F; F.Name = "F"; - F.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default); + F.ReturnType = TypeInfo("void"); F.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"}); - F.Params.emplace_back("int", "I"); + F.Params.emplace_back(TypeInfo("int"), "I"); F.Access = AccessSpecifier::AS_none; ExpectedBWithFunction.ChildFunctions.emplace_back(std::move(F)); CheckNamespaceInfo(&ExpectedBWithFunction, BWithFunction); @@ -396,7 +397,8 @@ class J : public I {} ;)raw", InfoType::IT_namespace); ExpectedG.TagType = TagTypeKind::TTK_Class; ExpectedG.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"}); - ExpectedG.Members.emplace_back("int", "I", AccessSpecifier::AS_protected); + ExpectedG.Members.emplace_back(TypeInfo("int"), "I", + AccessSpecifier::AS_protected); CheckRecordInfo(&ExpectedG, G); RecordInfo *E = InfoAsRecord(Infos[6].get()); @@ -412,9 +414,9 @@ class J : public I {} ;)raw", AccessSpecifier::AS_public, true); FunctionInfo FunctionSet; FunctionSet.Name = "set"; - FunctionSet.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default); + FunctionSet.ReturnType = TypeInfo("void"); FunctionSet.Loc.emplace_back(); - FunctionSet.Params.emplace_back("int", "N"); + FunctionSet.Params.emplace_back(TypeInfo("int"), "N"); FunctionSet.Namespace.emplace_back(EmptySID, "F", InfoType::IT_record); FunctionSet.Namespace.emplace_back(EmptySID, "GlobalNamespace", InfoType::IT_namespace); @@ -426,7 +428,7 @@ class J : public I {} ;)raw", AccessSpecifier::AS_private, true); FunctionInfo FunctionGet; FunctionGet.Name = "get"; - FunctionGet.ReturnType = TypeInfo(EmptySID, "int", InfoType::IT_default); + FunctionGet.ReturnType = TypeInfo("int"); FunctionGet.DefLoc = Location(); FunctionGet.Namespace.emplace_back(EmptySID, "G", InfoType::IT_record); FunctionGet.Namespace.emplace_back(EmptySID, "GlobalNamespace", @@ -434,7 +436,7 @@ class J : public I {} ;)raw", FunctionGet.Access = AccessSpecifier::AS_private; FunctionGet.IsMethod = true; ExpectedE.Bases.back().ChildFunctions.emplace_back(std::move(FunctionGet)); - ExpectedE.Bases.back().Members.emplace_back("int", "I", + ExpectedE.Bases.back().Members.emplace_back(TypeInfo("int"), "I", AccessSpecifier::AS_private); ExpectedE.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"}); ExpectedE.TagType = TagTypeKind::TTK_Class; @@ -458,9 +460,9 @@ class J : public I {} ;)raw", AccessSpecifier::AS_private, false); FunctionInfo FunctionSetNew; FunctionSetNew.Name = "set"; - FunctionSetNew.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default); + FunctionSetNew.ReturnType = TypeInfo("void"); FunctionSetNew.Loc.emplace_back(); - FunctionSetNew.Params.emplace_back("int", "N"); + FunctionSetNew.Params.emplace_back(TypeInfo("int"), "N"); FunctionSetNew.Namespace.emplace_back(EmptySID, "F", InfoType::IT_record); FunctionSetNew.Namespace.emplace_back(EmptySID, "GlobalNamespace", InfoType::IT_namespace); @@ -472,7 +474,7 @@ class J : public I {} ;)raw", AccessSpecifier::AS_private, false); FunctionInfo FunctionGetNew; FunctionGetNew.Name = "get"; - FunctionGetNew.ReturnType = TypeInfo(EmptySID, "int", InfoType::IT_default); + FunctionGetNew.ReturnType = TypeInfo("int"); FunctionGetNew.DefLoc = Location(); FunctionGetNew.Namespace.emplace_back(EmptySID, "G", InfoType::IT_record); FunctionGetNew.Namespace.emplace_back(EmptySID, "GlobalNamespace", @@ -480,7 +482,7 @@ class J : public I {} ;)raw", FunctionGetNew.Access = AccessSpecifier::AS_private; FunctionGetNew.IsMethod = true; ExpectedH.Bases.back().ChildFunctions.emplace_back(std::move(FunctionGetNew)); - ExpectedH.Bases.back().Members.emplace_back("int", "I", + ExpectedH.Bases.back().Members.emplace_back(TypeInfo("int"), "I", AccessSpecifier::AS_private); CheckRecordInfo(&ExpectedH, H); @@ -520,10 +522,10 @@ export double exportedModuleFunction(double y);)raw", NamespaceInfo ExpectedBWithFunction(EmptySID); FunctionInfo F; F.Name = "moduleFunction"; - F.ReturnType = TypeInfo(EmptySID, "int", InfoType::IT_default); + F.ReturnType = TypeInfo("int"); F.Loc.emplace_back(0, llvm::SmallString<16>{"test.cpp"}); - F.Params.emplace_back("int", "x"); - F.Params.emplace_back("double", "d"); + F.Params.emplace_back(TypeInfo("int"), "x"); + F.Params.emplace_back(TypeInfo("double"), "d"); F.Params.back().DefaultValue = "3.2 - 1.0"; F.Access = AccessSpecifier::AS_none; ExpectedBWithFunction.ChildFunctions.emplace_back(std::move(F)); @@ -533,9 +535,10 @@ export double exportedModuleFunction(double y);)raw", NamespaceInfo ExpectedBWithExportedFunction(EmptySID); FunctionInfo ExportedF; ExportedF.Name = "exportedModuleFunction"; - ExportedF.ReturnType = TypeInfo(EmptySID, "double", InfoType::IT_default); + ExportedF.ReturnType = + TypeInfo(Reference(EmptySID, "double", InfoType::IT_default)); ExportedF.Loc.emplace_back(0, llvm::SmallString<16>{"test.cpp"}); - ExportedF.Params.emplace_back("double", "y"); + ExportedF.Params.emplace_back(TypeInfo("double"), "y"); ExportedF.Access = AccessSpecifier::AS_none; ExpectedBWithExportedFunction.ChildFunctions.emplace_back( std::move(ExportedF)); diff --git a/clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp b/clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp index 58643d610734..bf59c2cb7939 100644 --- a/clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp +++ b/clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp @@ -82,7 +82,7 @@ TEST(YAMLGeneratorTest, emitRecordYAML) { I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"}); I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"}); - I.Members.emplace_back("int", "path/to/int", "X", + I.Members.emplace_back(TypeInfo("int", "path/to/int"), "X", AccessSpecifier::AS_private); // Member documentation. @@ -102,7 +102,7 @@ TEST(YAMLGeneratorTest, emitRecordYAML) { AccessSpecifier::AS_public, true); I.Bases.back().ChildFunctions.emplace_back(); I.Bases.back().ChildFunctions.back().Name = "InheritedFunctionOne"; - I.Bases.back().Members.emplace_back("int", "path/to/int", "N", + I.Bases.back().Members.emplace_back(TypeInfo("int", "path/to/int"), "N", AccessSpecifier::AS_private); // F is in the global namespace I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record, ""); @@ -174,7 +174,6 @@ Bases: Parents: - Type: Record Name: 'F' - IsInGlobalNamespace: true VirtualParents: - Type: Record Name: 'G' @@ -206,10 +205,10 @@ TEST(YAMLGeneratorTest, emitFunctionYAML) { I.Access = AccessSpecifier::AS_none; - I.ReturnType = - TypeInfo(EmptySID, "void", InfoType::IT_default, "path/to/void"); - I.Params.emplace_back("int", "path/to/int", "P"); - I.Params.emplace_back("double", "path/to/double", "D"); + I.ReturnType = TypeInfo( + Reference(EmptySID, "void", InfoType::IT_default, "path/to/void")); + I.Params.emplace_back(TypeInfo("int", "path/to/int"), "P"); + I.Params.emplace_back(TypeInfo("double", "path/to/double"), "D"); I.Params.back().DefaultValue = "2.0 * M_PI"; I.IsMethod = true; I.Parent = Reference(EmptySID, "Parent", InfoType::IT_record); @@ -335,9 +334,9 @@ TEST(YAMLGeneratorTest, emitCommentYAML) { FunctionInfo I; I.Name = "f"; I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"}); - I.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default); - I.Params.emplace_back("int", "I"); - I.Params.emplace_back("int", "J"); + I.ReturnType = TypeInfo("void"); + I.Params.emplace_back(TypeInfo("int"), "I"); + I.Params.emplace_back(TypeInfo("int"), "J"); I.Access = AccessSpecifier::AS_none; CommentInfo Top;