[clang-tools-extra] [clang-doc] [feat] add --repository-line-prefix argument (PR #131280)
Mohamed Emad via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 17 13:49:21 PDT 2025
https://github.com/hulxv updated https://github.com/llvm/llvm-project/pull/131280
>From bf9bd4156cb7f652c9cf0477f537e5c58b470448 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Fri, 14 Mar 2025 07:39:15 +0200
Subject: [PATCH 1/4] [clang-doc] [feat] add `--repository-line-prefix`
argument (fix #59814)
---
clang-tools-extra/clang-doc/HTMLGenerator.cpp | 66 ++++++++++++-------
clang-tools-extra/clang-doc/MDGenerator.cpp | 7 +-
.../clang-doc/Representation.cpp | 4 ++
clang-tools-extra/clang-doc/Representation.h | 5 +-
.../clang-doc/tool/ClangDocMain.cpp | 13 ++--
5 files changed, 64 insertions(+), 31 deletions(-)
diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index 18a0de826630c..967275f93193b 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -491,9 +491,9 @@ genReferencesBlock(const std::vector<Reference> &References,
return Out;
}
-static std::unique_ptr<TagNode>
-writeFileDefinition(const Location &L,
- std::optional<StringRef> RepositoryUrl = std::nullopt) {
+static std::unique_ptr<TagNode> writeFileDefinition(
+ const Location &L, std::optional<StringRef> RepositoryUrl = std::nullopt,
+ std::optional<StringRef> RepositoryLinePrefix = std::nullopt) {
if (!L.IsFileInRootDir && !RepositoryUrl)
return std::make_unique<TagNode>(
HTMLTag::TAG_P, "Defined at line " + std::to_string(L.LineNumber) +
@@ -514,17 +514,21 @@ writeFileDefinition(const Location &L,
Node->Children.emplace_back(std::make_unique<TextNode>("Defined at line "));
auto LocNumberNode =
std::make_unique<TagNode>(HTMLTag::TAG_A, std::to_string(L.LineNumber));
- // The links to a specific line in the source code use the github /
- // googlesource notation so it won't work for all hosting pages.
- // FIXME: we probably should have a configuration setting for line number
- // rendering in the HTML. For example, GitHub uses #L22, while googlesource
- // uses #22 for line numbers.
- LocNumberNode->Attributes.emplace_back(
- "href", (FileURL + "#" + std::to_string(L.LineNumber)).str());
+
+ std::string LineAnchor = "#";
+
+ if (RepositoryLinePrefix)
+ LineAnchor += RepositoryLinePrefix.value().str();
+
+ LineAnchor += std::to_string(L.LineNumber);
+
+ LocNumberNode->Attributes.emplace_back("href", (FileURL + LineAnchor).str());
Node->Children.emplace_back(std::move(LocNumberNode));
Node->Children.emplace_back(std::make_unique<TextNode>(" of file "));
+
auto LocFileNode = std::make_unique<TagNode>(
HTMLTag::TAG_A, llvm::sys::path::filename(FileURL));
+
LocFileNode->Attributes.emplace_back("href", std::string(FileURL));
Node->Children.emplace_back(std::move(LocFileNode));
return Node;
@@ -750,11 +754,15 @@ genHTML(const EnumInfo &I, const ClangDocContext &CDCtx) {
Out.emplace_back(std::move(Table));
if (I.DefLoc) {
- if (!CDCtx.RepositoryUrl)
- Out.emplace_back(writeFileDefinition(*I.DefLoc));
- else
- Out.emplace_back(
- writeFileDefinition(*I.DefLoc, StringRef{*CDCtx.RepositoryUrl}));
+ std::optional<StringRef> RepoUrl;
+ std::optional<StringRef> RepoLinePrefix;
+
+ if (CDCtx.RepositoryUrl)
+ RepoUrl = StringRef{*CDCtx.RepositoryUrl};
+ if (CDCtx.RepositoryLinePrefix)
+ RepoLinePrefix = StringRef{*CDCtx.RepositoryLinePrefix};
+
+ Out.emplace_back(writeFileDefinition(*I.DefLoc, RepoUrl, RepoLinePrefix));
}
std::string Description;
@@ -799,11 +807,15 @@ genHTML(const FunctionInfo &I, const ClangDocContext &CDCtx,
FunctionHeader->Children.emplace_back(std::make_unique<TextNode>(")"));
if (I.DefLoc) {
- if (!CDCtx.RepositoryUrl)
- Out.emplace_back(writeFileDefinition(*I.DefLoc));
- else
- Out.emplace_back(writeFileDefinition(
- *I.DefLoc, StringRef{*CDCtx.RepositoryUrl}));
+ std::optional<StringRef> RepoUrl;
+ std::optional<StringRef> RepoLinePrefix;
+
+ if (CDCtx.RepositoryUrl)
+ RepoUrl = StringRef{*CDCtx.RepositoryUrl};
+ if (CDCtx.RepositoryLinePrefix)
+ RepoLinePrefix = StringRef{*CDCtx.RepositoryLinePrefix};
+
+ Out.emplace_back(writeFileDefinition(*I.DefLoc, RepoUrl, RepoLinePrefix));
}
std::string Description;
@@ -866,11 +878,15 @@ genHTML(const RecordInfo &I, Index &InfoIndex, const ClangDocContext &CDCtx,
Out.emplace_back(std::make_unique<TagNode>(HTMLTag::TAG_H1, InfoTitle));
if (I.DefLoc) {
- if (!CDCtx.RepositoryUrl)
- Out.emplace_back(writeFileDefinition(*I.DefLoc));
- else
- Out.emplace_back(writeFileDefinition(
- *I.DefLoc, StringRef{*CDCtx.RepositoryUrl}));
+ std::optional<StringRef> RepoUrl;
+ std::optional<StringRef> RepoLinePrefix;
+
+ if (CDCtx.RepositoryUrl)
+ RepoUrl = StringRef{*CDCtx.RepositoryUrl};
+ if (CDCtx.RepositoryLinePrefix)
+ RepoLinePrefix = StringRef{*CDCtx.RepositoryLinePrefix};
+
+ Out.emplace_back(writeFileDefinition(*I.DefLoc, RepoUrl, RepoLinePrefix));
}
std::string Description;
diff --git a/clang-tools-extra/clang-doc/MDGenerator.cpp b/clang-tools-extra/clang-doc/MDGenerator.cpp
index 7bef2c0db04d8..a3bade238635c 100644
--- a/clang-tools-extra/clang-doc/MDGenerator.cpp
+++ b/clang-tools-extra/clang-doc/MDGenerator.cpp
@@ -57,7 +57,12 @@ static void writeFileDefinition(const ClangDocContext &CDCtx, const Location &L,
OS << "*Defined at " << L.Filename << "#" << std::to_string(L.LineNumber)
<< "*";
} else {
- OS << "*Defined at [" << L.Filename << "#" << std::to_string(L.LineNumber)
+ OS << "*Defined at [" << L.Filename << "#";
+
+ if (!CDCtx.RepositoryLinePrefix)
+ OS << StringRef{*CDCtx.RepositoryLinePrefix};
+
+ OS << std::to_string(L.LineNumber)
<< "](" << StringRef{*CDCtx.RepositoryUrl}
<< llvm::sys::path::relative_path(L.Filename) << "#"
<< std::to_string(L.LineNumber) << ")"
diff --git a/clang-tools-extra/clang-doc/Representation.cpp b/clang-tools-extra/clang-doc/Representation.cpp
index 4da93b24c131f..74f867dfb9f0c 100644
--- a/clang-tools-extra/clang-doc/Representation.cpp
+++ b/clang-tools-extra/clang-doc/Representation.cpp
@@ -368,6 +368,7 @@ ClangDocContext::ClangDocContext(tooling::ExecutionContext *ECtx,
StringRef ProjectName, bool PublicOnly,
StringRef OutDirectory, StringRef SourceRoot,
StringRef RepositoryUrl,
+ StringRef RepositoryLinePrefix,
std::vector<std::string> UserStylesheets)
: ECtx(ECtx), ProjectName(ProjectName), PublicOnly(PublicOnly),
OutDirectory(OutDirectory), UserStylesheets(UserStylesheets) {
@@ -381,6 +382,9 @@ ClangDocContext::ClangDocContext(tooling::ExecutionContext *ECtx,
if (!RepositoryUrl.empty() && !RepositoryUrl.starts_with("http://") &&
!RepositoryUrl.starts_with("https://"))
this->RepositoryUrl->insert(0, "https://");
+
+ if (!RepositoryLinePrefix.empty())
+ this->RepositoryLinePrefix = std::string(RepositoryLinePrefix);
}
}
diff --git a/clang-tools-extra/clang-doc/Representation.h b/clang-tools-extra/clang-doc/Representation.h
index bb0c534af7b74..88b3e47dfb1ee 100644
--- a/clang-tools-extra/clang-doc/Representation.h
+++ b/clang-tools-extra/clang-doc/Representation.h
@@ -508,6 +508,7 @@ struct ClangDocContext {
ClangDocContext(tooling::ExecutionContext *ECtx, StringRef ProjectName,
bool PublicOnly, StringRef OutDirectory, StringRef SourceRoot,
StringRef RepositoryUrl,
+ StringRef RepositoryCodeLinePrefix,
std::vector<std::string> UserStylesheets);
tooling::ExecutionContext *ECtx;
std::string ProjectName; // Name of project clang-doc is documenting.
@@ -518,10 +519,12 @@ struct ClangDocContext {
// the file is in this dir.
// URL of repository that hosts code used for links to definition locations.
std::optional<std::string> RepositoryUrl;
+ // Prefix of line code for repository.
+ std::optional<std::string> RepositoryLinePrefix;
// Path of CSS stylesheets that will be copied to OutDirectory and used to
// style all HTML files.
std::vector<std::string> UserStylesheets;
- // JavaScript files that will be imported in allHTML file.
+ // JavaScript files that will be imported in all HTML file.
std::vector<std::string> JsScripts;
Index Idx;
};
diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index 2ce707feb3d5e..237f60885b3dd 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -99,6 +99,12 @@ URL of repository that hosts code.
Used for links to definition locations.)"),
llvm::cl::cat(ClangDocCategory));
+static llvm::cl::opt<std::string>
+ RepositoryCodeLinePrefix("repository-line-prefix", llvm::cl::desc(R"(
+Prefix of line code for repository.
+)"),
+ llvm::cl::cat(ClangDocCategory));
+
enum OutputFormatTy {
md,
yaml,
@@ -141,8 +147,7 @@ llvm::Error getAssetFiles(clang::doc::ClangDocContext &CDCtx) {
using DirIt = llvm::sys::fs::directory_iterator;
std::error_code FileErr;
llvm::SmallString<128> FilePath(UserAssetPath);
- for (DirIt DirStart = DirIt(UserAssetPath, FileErr),
- DirEnd;
+ for (DirIt DirStart = DirIt(UserAssetPath, FileErr), DirEnd;
!FileErr && DirStart != DirEnd; DirStart.increment(FileErr)) {
FilePath = DirStart->path();
if (llvm::sys::fs::is_regular_file(FilePath)) {
@@ -268,8 +273,8 @@ Example usage for a project using a compile commands database:
OutDirectory,
SourceRoot,
RepositoryUrl,
- {UserStylesheets.begin(), UserStylesheets.end()}
- };
+ RepositoryCodeLinePrefix,
+ {UserStylesheets.begin(), UserStylesheets.end()}};
if (Format == "html") {
if (auto Err = getHtmlAssetFiles(argv[0], CDCtx)) {
>From fea0a3d818de29fa61c3e9225562271457d4b1d1 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Fri, 14 Mar 2025 07:39:21 +0200
Subject: [PATCH 2/4] [clang-doc][test] reuse `basic-project.test` for testing
`--repository-line-prefix`
---
.../basic-project-with-line-prefix.test | 342 ++++++++++++++++++
1 file changed, 342 insertions(+)
create mode 100644 clang-tools-extra/test/clang-doc/basic-project-with-line-prefix.test
diff --git a/clang-tools-extra/test/clang-doc/basic-project-with-line-prefix.test b/clang-tools-extra/test/clang-doc/basic-project-with-line-prefix.test
new file mode 100644
index 0000000000000..b393e1d12dfba
--- /dev/null
+++ b/clang-tools-extra/test/clang-doc/basic-project-with-line-prefix.test
@@ -0,0 +1,342 @@
+// RUN: rm -rf %t && mkdir -p %t/docs %t/build
+// RUN: sed 's|$test_dir|%/S|g' %S/Inputs/basic-project/database_template.json > %t/build/compile_commands.json
+// RUN: clang-doc --format=html --output=%t/docs --executor=all-TUs %t/build/compile_commands.json --repository=https://repository.com --repository-line-prefix=LLL
+// RUN: FileCheck %s -input-file=%t/docs/index_json.js -check-prefix=JSON-INDEX
+// RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/Shape.html -check-prefix=HTML-SHAPE
+// RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/Calculator.html -check-prefix=HTML-CALC
+// RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/Rectangle.html -check-prefix=HTML-RECTANGLE
+// RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/Circle.html -check-prefix=HTML-CIRCLE
+
+// JSON-INDEX: async function LoadIndex() {
+// JSON-INDEX-NEXT: return{
+// JSON-INDEX-NEXT: "USR": "{{([0-9A-F]{40})}}",
+// JSON-INDEX-NEXT: "Name": "",
+// JSON-INDEX-NEXT: "RefType": "default",
+// JSON-INDEX-NEXT: "Path": "",
+// JSON-INDEX-NEXT: "Children": [
+// JSON-INDEX-NEXT: {
+// JSON-INDEX-NEXT: "USR": "{{([0-9A-F]{40})}}",
+// JSON-INDEX-NEXT: "Name": "GlobalNamespace",
+// JSON-INDEX-NEXT: "RefType": "namespace",
+// JSON-INDEX-NEXT: "Path": "GlobalNamespace",
+// JSON-INDEX-NEXT: "Children": [
+// JSON-INDEX-NEXT: {
+// JSON-INDEX-NEXT: "USR": "{{([0-9A-F]{40})}}",
+// JSON-INDEX-NEXT: "Name": "Calculator",
+// JSON-INDEX-NEXT: "RefType": "record",
+// JSON-INDEX-NEXT: "Path": "GlobalNamespace",
+// JSON-INDEX-NEXT: "Children": []
+// JSON-INDEX-NEXT: },
+// JSON-INDEX-NEXT: {
+// JSON-INDEX-NEXT: "USR": "{{([0-9A-F]{40})}}",
+// JSON-INDEX-NEXT: "Name": "Circle",
+// JSON-INDEX-NEXT: "RefType": "record",
+// JSON-INDEX-NEXT: "Path": "GlobalNamespace",
+// JSON-INDEX-NEXT: "Children": []
+// JSON-INDEX-NEXT: },
+// JSON-INDEX-NEXT: {
+// JSON-INDEX-NEXT: "USR": "{{([0-9A-F]{40})}}",
+// JSON-INDEX-NEXT: "Name": "Rectangle",
+// JSON-INDEX-NEXT: "RefType": "record",
+// JSON-INDEX-NEXT: "Path": "GlobalNamespace",
+// JSON-INDEX-NEXT: "Children": []
+// JSON-INDEX-NEXT: },
+// JSON-INDEX-NEXT: {
+// JSON-INDEX-NEXT: "USR": "{{([0-9A-F]{40})}}",
+// JSON-INDEX-NEXT: "Name": "Shape",
+// JSON-INDEX-NEXT: "RefType": "record",
+// JSON-INDEX-NEXT: "Path": "GlobalNamespace",
+// JSON-INDEX-NEXT: "Children": []
+// JSON-INDEX-NEXT: }
+// JSON-INDEX-NEXT: ]
+// JSON-INDEX-NEXT: }
+// JSON-INDEX-NEXT: ]
+// JSON-INDEX-NEXT: };
+// JSON-INDEX-NEXT: }
+
+// HTML-SHAPE: <h1>class Shape</h1>
+// HTML-SHAPE-NEXT: <p>
+// HTML-SHAPE-NEXT: Defined at line
+// HTML-SHAPE-NEXT: <a href="https://repository.com/./include/Shape.h#LLL8">8</a>
+// HTML-SHAPE-NEXT: of file
+// HTML-SHAPE-NEXT: <a href="https://repository.com/./include/Shape.h">Shape.h</a>
+// HTML-SHAPE-NEXT: </p>
+// HTML-SHAPE: <div>brief</div>
+// HTML-SHAPE: <p> Abstract base class for shapes.</p>
+// HTML-SHAPE: <p> Provides a common interface for different types of shapes.</p>
+// HTML-SHAPE: <h2 id="Functions">Functions</h2>
+// HTML-SHAPE: <h3 id="{{([0-9A-F]{40})}}">area</h3>
+// HTML-SHAPE: <p>public double area()</p>
+// HTML-SHAPE: <div>brief</div>
+// HTML-SHAPE: <p> Calculates the area of the shape.</p>
+// HTML-SHAPE: <h3 id="{{([0-9A-F]{40})}}">perimeter</h3>
+// HTML-SHAPE: <p>public double perimeter()</p>
+// HTML-SHAPE: <div>brief</div>
+// HTML-SHAPE: <p> Calculates the perimeter of the shape.</p>
+// HTML-SHAPE: <div>return</div>
+// HTML-SHAPE: <p> double The perimeter of the shape.</p>
+// HTML-SHAPE: <h3 id="{{([0-9A-F]{40})}}">~Shape</h3>
+// HTML-SHAPE: <p>public void ~Shape()</p>
+// HTML-SHAPE: Defined at line
+// HTML-SHAPE-NEXT: <a href="https://repository.com/./include/Shape.h#LLL13">13</a>
+// HTML-SHAPE-NEXT: of file
+// HTML-SHAPE-NEXT: <a href="https://repository.com/./include/Shape.h">Shape.h</a>
+// HTML-SHAPE: <div>brief</div>
+// HTML-SHAPE: <p> Virtual destructor.</p>
+
+// HTML-CALC: <h1>class Calculator</h1>
+// HTML-CALC-NEXT: <p>
+// HTML-CALC-NEXT: Defined at line
+// HTML-CALC-NEXT: <a href="https://repository.com/./include/Calculator.h#LLL8">8</a>
+// HTML-CALC-NEXT: of file
+// HTML-CALC-NEXT: <a href="https://repository.com/./include/Calculator.h">Calculator.h</a>
+// HTML-CALC-NEXT: </p>
+// HTML-CALC: <div>brief</div>
+// HTML-CALC: <p> A simple calculator class.</p>
+// HTML-CALC: <p> Provides basic arithmetic operations.</p>
+// HTML-CALC: <h2 id="Functions">Functions</h2>
+// HTML-CALC: <h3 id="{{([0-9A-F]{40})}}">add</h3>
+// HTML-CALC: <p>public int add(int a, int b)</p>
+// HTML-CALC: Defined at line
+// HTML-CALC-NEXT: <a href="https://repository.com/./src/Calculator.cpp#LLL3">3</a>
+// HTML-CALC-NEXT: of file
+// HTML-CALC-NEXT: <a href="https://repository.com/./src/Calculator.cpp">Calculator.cpp</a>
+// HTML-CALC: <div>brief</div>
+// HTML-CALC: <p> Adds two integers.</p>
+// HTML-CALC: <div>return</div>
+// HTML-CALC: <p> int The sum of a and b.</p>
+// HTML-CALC: <h3 id="{{([0-9A-F]{40})}}">subtract</h3>
+// HTML-CALC: <p>public int subtract(int a, int b)</p>
+// HTML-CALC: Defined at line
+// HTML-CALC-NEXT: <a href="https://repository.com/./src/Calculator.cpp#LLL7">7</a>
+// HTML-CALC-NEXT: of file
+// HTML-CALC-NEXT: <a href="https://repository.com/./src/Calculator.cpp">Calculator.cpp</a>
+// HTML-CALC: <div>brief</div>
+// HTML-CALC: <p> Subtracts the second integer from the first.</p>
+// HTML-CALC: <div>return</div>
+// HTML-CALC: <p> int The result of a - b.</p>
+// HTML-CALC: <h3 id="{{([0-9A-F]{40})}}">multiply</h3>
+// HTML-CALC: <p>public int multiply(int a, int b)</p>
+// HTML-CALC: Defined at line
+// HTML-CALC-NEXT: <a href="https://repository.com/./src/Calculator.cpp#LLL11">11</a>
+// HTML-CALC-NEXT: of file
+// HTML-CALC-NEXT: <a href="https://repository.com/./src/Calculator.cpp">Calculator.cpp</a>
+// HTML-CALC: <div>brief</div>
+// HTML-CALC: <p> Multiplies two integers.</p>
+// HTML-CALC: <div>return</div>
+// HTML-CALC: <p> int The product of a and b.</p>
+// HTML-CALC: <h3 id="{{([0-9A-F]{40})}}">divide</h3>
+// HTML-CALC: <p>public double divide(int a, int b)</p>
+// HTML-CALC: Defined at line
+// HTML-CALC-NEXT: <a href="https://repository.com/./src/Calculator.cpp#LLL15">15</a>
+// HTML-CALC-NEXT: of file
+// HTML-CALC-NEXT: <a href="https://repository.com/./src/Calculator.cpp">Calculator.cpp</a>
+// HTML-CALC: <div>brief</div>
+// HTML-CALC: <p> Divides the first integer by the second.</p>
+// HTML-CALC: <div>return</div>
+// HTML-CALC: <p> double The result of a / b.</p>
+// HTML-CALC: <div>throw</div>
+// HTML-CALC: <p>if b is zero.</p>
+
+// HTML-RECTANGLE: <h1>class Rectangle</h1>
+// HTML-RECTANGLE-NEXT: <p>
+// HTML-RECTANGLE-NEXT: Defined at line
+// HTML-RECTANGLE-NEXT: <a href="https://repository.com/./include/Rectangle.h#LLL10">10</a>
+// HTML-RECTANGLE-NEXT: of file
+// HTML-RECTANGLE-NEXT: <a href="https://repository.com/./include/Rectangle.h">Rectangle.h</a>
+// HTML-RECTANGLE-NEXT: </p>
+// HTML-RECTANGLE: <p> Represents a rectangle with a given width and height.</p>
+// HTML-RECTANGLE: <p>
+// HTML-RECTANGLE: Inherits from
+// HTML-RECTANGLE: <a href="Shape.html">Shape</a>
+// HTML-RECTANGLE: </p>
+// HTML-RECTANGLE: <h2 id="Members">Members</h2>
+// HTML-RECTANGLE: <p> Width of the rectangle.</p>
+// HTML-RECTANGLE: <div>private double width_</div>
+// HTML-RECTANGLE: <p> Height of the rectangle.</p>
+// HTML-RECTANGLE: <div>private double height_</div>
+// HTML-RECTANGLE: <h2 id="Functions">Functions</h2>
+// HTML-RECTANGLE: <h3 id="{{([0-9A-F]{40})}}">Rectangle</h3>
+// HTML-RECTANGLE: <p>public void Rectangle(double width, double height)</p>
+// HTML-RECTANGLE: Defined at line
+// HTML-RECTANGLE-NEXT: <a href="https://repository.com/./src/Rectangle.cpp#LLL3">3</a>
+// HTML-RECTANGLE-NEXT: of file
+// HTML-RECTANGLE-NEXT: <a href="https://repository.com/./src/Rectangle.cpp">Rectangle.cpp</a>
+// HTML-RECTANGLE: <div>brief</div>
+// HTML-RECTANGLE: <p> Constructs a new Rectangle object.</p>
+// HTML-RECTANGLE: <h3 id="{{([0-9A-F]{40})}}">area</h3>
+// HTML-RECTANGLE: <p>public double area()</p>
+// HTML-RECTANGLE: Defined at line
+// HTML-RECTANGLE-NEXT: <a href="https://repository.com/./src/Rectangle.cpp#LLL6">6</a>
+// HTML-RECTANGLE-NEXT: of file
+// HTML-RECTANGLE-NEXT: <a href="https://repository.com/./src/Rectangle.cpp">Rectangle.cpp</a>
+// HTML-RECTANGLE: <div>brief</div>
+// HTML-RECTANGLE: <p> Calculates the area of the rectangle.</p>
+// HTML-RECTANGLE: <div>return</div>
+// HTML-RECTANGLE: <p> double The area of the rectangle.</p>
+// HTML-RECTANGLE: <h3 id="{{([0-9A-F]{40})}}">perimeter</h3>
+// HTML-RECTANGLE: <p>public double perimeter()</p>
+// HTML-RECTANGLE: Defined at line
+// HTML-RECTANGLE-NEXT: <a href="https://repository.com/./src/Rectangle.cpp#LLL10">10</a>
+// HTML-RECTANGLE-NEXT: of file
+// HTML-RECTANGLE-NEXT: <a href="https://repository.com/./src/Rectangle.cpp">Rectangle.cpp</a>
+// HTML-RECTANGLE: <div>brief</div>
+// HTML-RECTANGLE: <p> Calculates the perimeter of the rectangle.</p>
+// HTML-RECTANGLE: <div>return</div>
+// HTML-RECTANGLE: <p> double The perimeter of the rectangle.</p>
+
+// HTML-CIRCLE: <h1>class Circle</h1>
+// HTML-CIRCLE-NEXT: <p>
+// HTML-CIRCLE-NEXT: Defined at line
+// HTML-CIRCLE-NEXT: <a href="https://repository.com/./include/Circle.h#LLL10">10</a>
+// HTML-CIRCLE-NEXT: of file
+// HTML-CIRCLE-NEXT: <a href="https://repository.com/./include/Circle.h">Circle.h</a>
+// HTML-CIRCLE-NEXT: </p>
+// HTML-CIRCLE: <div>brief</div>
+// HTML-CIRCLE: <p> Circle class derived from Shape.</p>
+// HTML-CIRCLE: <p> Represents a circle with a given radius.</p>
+// HTML-CIRCLE: <p>
+// HTML-CIRCLE: Inherits from
+// HTML-CIRCLE: <a href="Shape.html">Shape</a>
+// HTML-CIRCLE: </p>
+// HTML-CIRCLE: <h2 id="Members">Members</h2>
+// HTML-CIRCLE: <p> Radius of the circle.</p>
+// HTML-CIRCLE: <div>private double radius_</div>
+// HTML-CIRCLE: <h2 id="Functions">Functions</h2>
+// HTML-CIRCLE: <h3 id="{{([0-9A-F]{40})}}">Circle</h3>
+// HTML-CIRCLE: <p>public void Circle(double radius)</p>
+// HTML-CIRCLE: Defined at line
+// HTML-CIRCLE-NEXT: <a href="https://repository.com/./src/Circle.cpp#LLL3">3</a>
+// HTML-CIRCLE-NEXT: of file
+// HTML-CIRCLE-NEXT: <a href="https://repository.com/./src/Circle.cpp">Circle.cpp</a>
+// HTML-CIRCLE: <div>brief</div>
+// HTML-CIRCLE: <p> Constructs a new Circle object.</p>
+// HTML-CIRCLE: <h3 id="{{([0-9A-F]{40})}}">area</h3>
+// HTML-CIRCLE: <p>public double area()</p>
+// HTML-CIRCLE: Defined at line
+// HTML-CIRCLE-NEXT: <a href="https://repository.com/./src/Circle.cpp#LLL5">5</a>
+// HTML-CIRCLE-NEXT: of file
+// HTML-CIRCLE-NEXT: <a href="https://repository.com/./src/Circle.cpp">Circle.cpp</a>
+// HTML-CIRCLE: <div>brief</div>
+// HTML-CIRCLE: <p> Calculates the area of the circle.</p>
+// HTML-CIRCLE: <div>return</div>
+// HTML-CIRCLE: <p> double The area of the circle.</p>
+// HTML-CIRCLE: <h3 id="{{([0-9A-F]{40})}}">perimeter</h3>
+// HTML-CIRCLE: <p>public double perimeter()</p>
+// HTML-CIRCLE: Defined at line
+// HTML-CIRCLE-NEXT: <a href="https://repository.com/./src/Circle.cpp#LLL9">9</a>
+// HTML-CIRCLE-NEXT: of file
+// HTML-CIRCLE-NEXT: <a href="https://repository.com/./src/Circle.cpp">Circle.cpp</a>
+// HTML-CIRCLE: <div>brief</div>
+// HTML-CIRCLE: <p> Calculates the perimeter of the circle.</p>
+// HTML-CIRCLE: <div>return</div>
+// HTML-CIRCLE: <p> double The perimeter of the circle.</p>
+
+// MD-CALC: # class Calculator
+// MD-CALC: *Defined at .{{[\/]}}include{{[\/]}}Calculator.h#LLL8*
+// MD-CALC: **brief** A simple calculator class.
+// MD-CALC: Provides basic arithmetic operations.
+// MD-CALC: ## Functions
+// MD-CALC: ### add
+// MD-CALC: *public int add(int a, int b)*
+// MD-CALC: *Defined at .{{[\/]}}src{{[\/]}}Calculator.cpp#LLL3*
+// MD-CALC: **brief** Adds two integers.
+// MD-CALC: **a** First integer.
+// MD-CALC: **b** Second integer.
+// MD-CALC: **return** int The sum of a and b.
+// MD-CALC: ### subtract
+// MD-CALC: *public int subtract(int a, int b)*
+// MD-CALC: *Defined at .{{[\/]}}src{{[\/]}}Calculator.cpp#LLL7*
+// MD-CALC: **brief** Subtracts the second integer from the first.
+// MD-CALC: **a** First integer.
+// MD-CALC: **b** Second integer.
+// MD-CALC: **return** int The result of a - b.
+// MD-CALC: ### multiply
+// MD-CALC: *public int multiply(int a, int b)*
+// MD-CALC: *Defined at .{{[\/]}}src{{[\/]}}Calculator.cpp#LLL11*
+// MD-CALC: **brief** Multiplies two integers.
+// MD-CALC: **a** First integer.
+// MD-CALC: **b** Second integer.
+// MD-CALC: **return** int The product of a and b.
+// MD-CALC: ### divide
+// MD-CALC: *public double divide(int a, int b)*
+// MD-CALC: *Defined at .{{[\/]}}src{{[\/]}}Calculator.cpp#LLL15*
+// MD-CALC: **brief** Divides the first integer by the second.
+// MD-CALC: **a** First integer.
+// MD-CALC: **b** Second integer.
+// MD-CALC: **return** double The result of a / b.
+// MD-CALC: **throw**if b is zero.
+
+// MD-CIRCLE: # class Circle
+// MD-CIRCLE: *Defined at .{{[\/]}}include{{[\/]}}Circle.h#LLL10*
+// MD-CIRCLE: **brief** Circle class derived from Shape.
+// MD-CIRCLE: Represents a circle with a given radius.
+// MD-CIRCLE: Inherits from Shape
+// MD-CIRCLE: ## Members
+// MD-CIRCLE: private double radius_
+// MD-CIRCLE: ## Functions
+// MD-CIRCLE: ### Circle
+// MD-CIRCLE: *public void Circle(double radius)*
+// MD-CIRCLE: *Defined at .{{[\/]}}src{{[\/]}}Circle.cpp#LLL3*
+// MD-CIRCLE: **brief** Constructs a new Circle object.
+// MD-CIRCLE: **radius** Radius of the circle.
+// MD-CIRCLE: ### area
+// MD-CIRCLE: *public double area()*
+// MD-CIRCLE: *Defined at .{{[\/]}}src{{[\/]}}Circle.cpp#LLL5*
+// MD-CIRCLE: **brief** Calculates the area of the circle.
+// MD-CIRCLE: **return** double The area of the circle.
+// MD-CIRCLE: ### perimeter
+// MD-CIRCLE: *public double perimeter()*
+// MD-CIRCLE: *Defined at .{{[\/]}}src{{[\/]}}Circle.cpp#LLL9*
+// MD-CIRCLE: **brief** Calculates the perimeter of the circle.
+// MD-CIRCLE: **return** double The perimeter of the circle.
+
+// MD-RECTANGLE: # class Rectangle
+// MD-RECTANGLE: *Defined at .{{[\/]}}include{{[\/]}}Rectangle.h#LLL10*
+// MD-RECTANGLE: **brief** Rectangle class derived from Shape.
+// MD-RECTANGLE: Represents a rectangle with a given width and height.
+// MD-RECTANGLE: Inherits from Shape
+// MD-RECTANGLE: ## Members
+// MD-RECTANGLE: private double width_
+// MD-RECTANGLE: private double height_
+// MD-RECTANGLE: ## Functions
+// MD-RECTANGLE: ### Rectangle
+// MD-RECTANGLE: *public void Rectangle(double width, double height)*
+// MD-RECTANGLE: *Defined at .{{[\/]}}src{{[\/]}}Rectangle.cpp#LLL3*
+// MD-RECTANGLE: **brief** Constructs a new Rectangle object.
+// MD-RECTANGLE: **width** Width of the rectangle.
+// MD-RECTANGLE: **height** Height of the rectangle.
+// MD-RECTANGLE: ### area
+// MD-RECTANGLE: *public double area()*
+// MD-RECTANGLE: *Defined at .{{[\/]}}src{{[\/]}}Rectangle.cpp#LLL6*
+// MD-RECTANGLE: **brief** Calculates the area of the rectangle.
+// MD-RECTANGLE: **return** double The area of the rectangle.
+// MD-RECTANGLE: ### perimeter
+// MD-RECTANGLE: *public double perimeter()*
+// MD-RECTANGLE: *Defined at .{{[\/]}}src{{[\/]}}Rectangle.cpp#LLL10*
+// MD-RECTANGLE: **brief** Calculates the perimeter of the rectangle.
+// MD-RECTANGLE: **return** double The perimeter of the rectangle.
+
+// MD-SHAPE: # class Shape
+// MD-SHAPE: *Defined at .{{[\/]}}include{{[\/]}}Shape.h#LLL8*
+// MD-SHAPE: **brief** Abstract base class for shapes.
+// MD-SHAPE: Provides a common interface for different types of shapes.
+// MD-SHAPE: ## Functions
+// MD-SHAPE: ### ~Shape
+// MD-SHAPE: *public void ~Shape()*
+// MD-SHAPE: *Defined at .{{[\/]}}include{{[\/]}}Shape.h#LLL13*
+// MD-SHAPE: **brief** Virtual destructor.
+// MD-SHAPE: ### area
+// MD-SHAPE: *public double area()*
+// MD-SHAPE: **brief** Calculates the area of the shape.
+// MD-SHAPE: **return** double The area of the shape.
+// MD-SHAPE: ### perimeter
+// MD-SHAPE: *public double perimeter()*
+// MD-SHAPE: **brief** Calculates the perimeter of the shape.
+// MD-SHAPE: **return** double The perimeter of the shape.
+
+// MD-ALL-FILES: # All Files
+// MD-ALL-FILES: ## [GlobalNamespace](GlobalNamespace{{[\/]}}index.md)
+
+// MD-INDEX: # C/C++ Reference
+// MD-INDEX: * Namespace: [GlobalNamespace](GlobalNamespace)
>From 4b769dd570ed0a82d007429d941fa3c80af2ad0d Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Mon, 17 Mar 2025 21:59:52 +0200
Subject: [PATCH 3/4] [clang] [chore] revert important notes
---
clang-tools-extra/clang-doc/HTMLGenerator.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index 967275f93193b..9711ca20c56fa 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -514,7 +514,8 @@ static std::unique_ptr<TagNode> writeFileDefinition(
Node->Children.emplace_back(std::make_unique<TextNode>("Defined at line "));
auto LocNumberNode =
std::make_unique<TagNode>(HTMLTag::TAG_A, std::to_string(L.LineNumber));
-
+ // The links to a specific line in the source code use the github /
+ // googlesource notation so it won't work for all hosting pages.
std::string LineAnchor = "#";
if (RepositoryLinePrefix)
>From a7f7f6c16b57d176bda4122a385703239a5817d2 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Mon, 17 Mar 2025 22:10:19 +0200
Subject: [PATCH 4/4] [clang] fix formatting for help of
`--repository-line-prefix`
---
clang-tools-extra/clang-doc/tool/ClangDocMain.cpp | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index 237f60885b3dd..e7713efde2db1 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -99,11 +99,10 @@ URL of repository that hosts code.
Used for links to definition locations.)"),
llvm::cl::cat(ClangDocCategory));
-static llvm::cl::opt<std::string>
- RepositoryCodeLinePrefix("repository-line-prefix", llvm::cl::desc(R"(
-Prefix of line code for repository.
-)"),
- llvm::cl::cat(ClangDocCategory));
+static llvm::cl::opt<std::string> RepositoryCodeLinePrefix(
+ "repository-line-prefix",
+ llvm::cl::desc("Prefix of line code for repository."),
+ llvm::cl::cat(ClangDocCategory));
enum OutputFormatTy {
md,
More information about the cfe-commits
mailing list