DiegoAstiazaran created this revision. DiegoAstiazaran added reviewers: juliehockett, jakehehrlich, lebedev.ri. DiegoAstiazaran added a project: clang-tools-extra.
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 a path was assigned it had that outdirectory at least. The path generation was changed, it's now only 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 object has a valid path, this is false by default and changed to true if a path is assigned to it. https://reviews.llvm.org/D64958 Files: clang-tools-extra/clang-doc/BitcodeReader.cpp clang-tools-extra/clang-doc/BitcodeWriter.cpp clang-tools-extra/clang-doc/BitcodeWriter.h clang-tools-extra/clang-doc/HTMLGenerator.cpp clang-tools-extra/clang-doc/Representation.h clang-tools-extra/clang-doc/YAMLGenerator.cpp clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
Index: clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp =================================================================== --- clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp +++ clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp @@ -115,16 +115,19 @@ - Type: Name: 'int' Path: 'path/to/int' + IsPathValid: true Name: 'X' Access: Private Parents: - Type: Record Name: 'F' Path: 'path/to/F' + IsPathValid: true VirtualParents: - Type: Record Name: 'G' Path: 'path/to/G' + IsPathValid: true ChildRecords: - Type: Record Name: 'ChildStruct' @@ -181,11 +184,13 @@ - Type: Name: 'int' Path: 'path/to/int' + IsPathValid: true Name: 'P' ReturnType: Type: Name: 'void' Path: 'path/to/void' + IsPathValid: true ... )raw"; EXPECT_EQ(Expected, Actual.str()); Index: clang-tools-extra/clang-doc/YAMLGenerator.cpp =================================================================== --- clang-tools-extra/clang-doc/YAMLGenerator.cpp +++ clang-tools-extra/clang-doc/YAMLGenerator.cpp @@ -156,6 +156,7 @@ IO.mapOptional("Name", Ref.Name, SmallString<16>()); IO.mapOptional("USR", Ref.USR, SymbolID()); IO.mapOptional("Path", Ref.Path, SmallString<128>()); + IO.mapOptional("IsPathValid", Ref.IsPathValid, false); } }; Index: clang-tools-extra/clang-doc/Representation.h =================================================================== --- clang-tools-extra/clang-doc/Representation.h +++ clang-tools-extra/clang-doc/Representation.h @@ -114,11 +114,12 @@ struct Reference { Reference() = default; Reference(llvm::StringRef Name) : Name(Name) {} - Reference(llvm::StringRef Name, StringRef Path) : Name(Name), Path(Path) {} + Reference(llvm::StringRef Name, StringRef Path) + : Name(Name), Path(Path), IsPathValid(true) {} Reference(SymbolID USR, StringRef Name, InfoType IT) : USR(USR), Name(Name), RefType(IT) {} 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), IsPathValid(true) {} bool operator==(const Reference &Other) const { return std::tie(USR, Name, RefType) == @@ -130,8 +131,11 @@ 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 + llvm::SmallString<128> + Path; // Path of directory where the clang-doc generated file will be + // saved (possibly unresolved) + bool IsPathValid = false; // Indicates if a value has been assigned to Path, + // it could be an empty string }; // A base struct for TypeInfos Index: clang-tools-extra/clang-doc/HTMLGenerator.cpp =================================================================== --- clang-tools-extra/clang-doc/HTMLGenerator.cpp +++ clang-tools-extra/clang-doc/HTMLGenerator.cpp @@ -249,7 +249,7 @@ static std::unique_ptr<HTMLNode> genTypeReference(const Reference &Type, StringRef CurrentDirectory) { - if (Type.Path.empty()) + if (!Type.IsPathValid) return llvm::make_unique<TextNode>(Type.Name); llvm::SmallString<128> Path = computeRelativePath(Type.Path, CurrentDirectory); Index: clang-tools-extra/clang-doc/BitcodeWriter.h =================================================================== --- clang-tools-extra/clang-doc/BitcodeWriter.h +++ clang-tools-extra/clang-doc/BitcodeWriter.h @@ -109,6 +109,7 @@ REFERENCE_NAME, REFERENCE_TYPE, REFERENCE_PATH, + REFERENCE_IS_PATH_VALID, REFERENCE_FIELD, RI_LAST, RI_FIRST = VERSION Index: clang-tools-extra/clang-doc/BitcodeWriter.cpp =================================================================== --- clang-tools-extra/clang-doc/BitcodeWriter.cpp +++ clang-tools-extra/clang-doc/BitcodeWriter.cpp @@ -172,6 +172,7 @@ {REFERENCE_NAME, {"Name", &StringAbbrev}}, {REFERENCE_TYPE, {"RefType", &IntAbbrev}}, {REFERENCE_PATH, {"Path", &StringAbbrev}}, + {REFERENCE_IS_PATH_VALID, {"IsPathValid", &BoolAbbrev}}, {REFERENCE_FIELD, {"Field", &IntAbbrev}}}; assert(Inits.size() == RecordIdCount); for (const auto &Init : Inits) { @@ -215,7 +216,7 @@ // Reference Block {BI_REFERENCE_BLOCK_ID, {REFERENCE_USR, REFERENCE_NAME, REFERENCE_TYPE, REFERENCE_PATH, - REFERENCE_FIELD}}}; + REFERENCE_IS_PATH_VALID, REFERENCE_FIELD}}}; // AbbreviationMap @@ -387,6 +388,7 @@ emitRecord(R.Name, REFERENCE_NAME); emitRecord((unsigned)R.RefType, REFERENCE_TYPE); emitRecord(R.Path, REFERENCE_PATH); + emitRecord(R.IsPathValid, REFERENCE_IS_PATH_VALID); emitRecord((unsigned)Field, REFERENCE_FIELD); } Index: clang-tools-extra/clang-doc/BitcodeReader.cpp =================================================================== --- clang-tools-extra/clang-doc/BitcodeReader.cpp +++ clang-tools-extra/clang-doc/BitcodeReader.cpp @@ -292,6 +292,8 @@ return decodeRecord(R, I->RefType, Blob); case REFERENCE_PATH: return decodeRecord(R, I->Path, Blob); + case REFERENCE_IS_PATH_VALID: + return decodeRecord(R, I->IsPathValid, Blob); case REFERENCE_FIELD: return decodeRecord(R, F, Blob); default:
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits