Author: diegoastiazaran Date: Mon Aug 5 17:11:34 2019 New Revision: 367958
URL: http://llvm.org/viewvc/llvm-project?rev=367958&view=rev Log: [clang-doc] Fix link generation Before making a link to a reference it is required to check that the reference has a path (eg. primitives won't have paths). This was done by checking if the path was empty; that worked because when generating paths the outdirectory was included, so if the path was assigned it had that outdirectory at least. The path generation was changed, it's now only the composite of the namespaces without the outdirectory. So if the info is in the global namespace the path would be empty and the old check wouldn't work as expected. A new attribute has been added to the Reference struct that indicates if the info's parent is the global namespace. Paths generation now fails if the path is empty and if the info is not in the global namespace. Differential Revision: https://reviews.llvm.org/D64958 Modified: clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp clang-tools-extra/trunk/clang-doc/BitcodeWriter.h clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp clang-tools-extra/trunk/clang-doc/Representation.h clang-tools-extra/trunk/clang-doc/YAMLGenerator.cpp clang-tools-extra/trunk/unittests/clang-doc/YAMLGeneratorTest.cpp Modified: clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp?rev=367958&r1=367957&r2=367958&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp (original) +++ clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp Mon Aug 5 17:11:34 2019 @@ -292,6 +292,8 @@ llvm::Error parseRecord(Record R, unsign 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: Modified: clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp?rev=367958&r1=367957&r2=367958&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp (original) +++ clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp Mon Aug 5 17:11:34 2019 @@ -172,6 +172,8 @@ static const llvm::IndexedMap<RecordIdDs {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) { @@ -215,7 +217,7 @@ static const std::vector<std::pair<Block // Reference Block {BI_REFERENCE_BLOCK_ID, {REFERENCE_USR, REFERENCE_NAME, REFERENCE_TYPE, REFERENCE_PATH, - REFERENCE_FIELD}}}; + REFERENCE_IS_IN_GLOBAL_NAMESPACE, REFERENCE_FIELD}}}; // AbbreviationMap @@ -387,6 +389,7 @@ void ClangDocBitcodeWriter::emitBlock(co 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); } Modified: clang-tools-extra/trunk/clang-doc/BitcodeWriter.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/BitcodeWriter.h?rev=367958&r1=367957&r2=367958&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-doc/BitcodeWriter.h (original) +++ clang-tools-extra/trunk/clang-doc/BitcodeWriter.h Mon Aug 5 17:11:34 2019 @@ -109,6 +109,7 @@ enum RecordId { REFERENCE_NAME, REFERENCE_TYPE, REFERENCE_PATH, + REFERENCE_IS_IN_GLOBAL_NAMESPACE, REFERENCE_FIELD, RI_LAST, RI_FIRST = VERSION Modified: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp?rev=367958&r1=367957&r2=367958&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp (original) +++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp Mon Aug 5 17:11:34 2019 @@ -247,7 +247,7 @@ static std::unique_ptr<TagNode> genLink( static std::unique_ptr<HTMLNode> genTypeReference(const Reference &Type, StringRef CurrentDirectory) { - if (Type.Path.empty()) + if (Type.Path.empty() && !Type.IsInGlobalNamespace) return llvm::make_unique<TextNode>(Type.Name); llvm::SmallString<128> Path = computeRelativePath(Type.Path, CurrentDirectory); Modified: clang-tools-extra/trunk/clang-doc/Representation.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/Representation.h?rev=367958&r1=367957&r2=367958&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-doc/Representation.h (original) +++ clang-tools-extra/trunk/clang-doc/Representation.h Mon Aug 5 17:11:34 2019 @@ -114,11 +114,17 @@ struct CommentInfo { struct Reference { Reference() = default; Reference(llvm::StringRef Name) : Name(Name) {} - Reference(llvm::StringRef Name, StringRef Path) : Name(Name), Path(Path) {} + // 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) {} + : USR(USR), Name(Name), RefType(IT), Path(Path), + IsInGlobalNamespace(Path.empty()) {} bool operator==(const Reference &Other) const { return std::tie(USR, Name, RefType) == @@ -130,8 +136,12 @@ struct Reference { InfoType RefType = InfoType::IT_default; // Indicates the type of this // Reference (namespace, record, // function, enum, default). - llvm::SmallString<128> Path; // Path of directory where the clang-doc - // generated file will be saved + // 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 Modified: clang-tools-extra/trunk/clang-doc/YAMLGenerator.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/YAMLGenerator.cpp?rev=367958&r1=367957&r2=367958&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-doc/YAMLGenerator.cpp (original) +++ clang-tools-extra/trunk/clang-doc/YAMLGenerator.cpp Mon Aug 5 17:11:34 2019 @@ -156,6 +156,7 @@ template <> struct MappingTraits<Referen 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); } }; Modified: clang-tools-extra/trunk/unittests/clang-doc/YAMLGeneratorTest.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-doc/YAMLGeneratorTest.cpp?rev=367958&r1=367957&r2=367958&view=diff ============================================================================== --- clang-tools-extra/trunk/unittests/clang-doc/YAMLGeneratorTest.cpp (original) +++ clang-tools-extra/trunk/unittests/clang-doc/YAMLGeneratorTest.cpp Mon Aug 5 17:11:34 2019 @@ -80,7 +80,8 @@ TEST(YAMLGeneratorTest, emitRecordYAML) I.Members.emplace_back("int", "path/to/int", "X", AccessSpecifier::AS_private); I.TagType = TagTypeKind::TTK_Class; - I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record, "path/to/F"); + // F is in the global namespace + I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record, ""); I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record, "path/to/G"); @@ -120,7 +121,7 @@ Members: Parents: - Type: Record Name: 'F' - Path: 'path/to/F' + IsInGlobalNamespace: true VirtualParents: - Type: Record Name: 'G' _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits