[clang-doc] Make --repository change the HTML output by ilovepi · Pull Request #122566 · llvm/llvm-project (original) (raw)

@llvm/pr-subscribers-clang-tools-extra

Author: Paul Kirth (ilovepi)

Changes

The current check in writeFileDefinition() is incorrect, and prevents us
from ever emitting the URL from the clang-doc tool. The unit tests do
test this, but call the API directly circumventing the check.

This is the first step towards addressing #59814.


Full diff: https://github.com/llvm/llvm-project/pull/122566.diff

4 Files Affected:

diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp b/clang-tools-extra/clang-doc/HTMLGenerator.cpp index e3532559a32fcc..a400d2e9cbd184 100644 --- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp +++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp @@ -494,7 +494,7 @@ genReferencesBlock(const std::vector &References, static std::unique_ptr writeFileDefinition(const Location &L, std::optional RepositoryUrl = std::nullopt) {

diff --git a/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Circle.cpp b/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Circle.cpp index 823384a4d97e86..3ddb2fd9ff563e 100644 --- a/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Circle.cpp +++ b/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Circle.cpp @@ -8,4 +8,5 @@ double Circle::area() const {

double Circle::perimeter() const { return 3.141 * radius_; -} \ No newline at end of file +} + diff --git a/clang-tools-extra/test/clang-doc/basic-project.test b/clang-tools-extra/test/clang-doc/basic-project.test index b6b43bb82bb15d..1f5ba8bdc0703d 100644 --- a/clang-tools-extra/test/clang-doc/basic-project.test +++ b/clang-tools-extra/test/clang-doc/basic-project.test @@ -54,130 +54,183 @@ // JSON-INDEX-NEXT: }; // JSON-INDEX-NEXT: }

-// HTML-SHAPE:

class Shape

-// HTML-SHAPE:

Defined at line 8 of file {{.}}Shape.h

-// HTML-SHAPE:
brief
-// HTML-SHAPE:

Abstract base class for shapes.

-// HTML-SHAPE:

Provides a common interface for different types of shapes.

-// HTML-SHAPE:

Functions

-// HTML-SHAPE:

area

-// HTML-SHAPE:

public double area()

-// HTML-SHAPE:
brief
-// HTML-SHAPE:

Calculates the area of the shape.

-// HTML-SHAPE:

perimeter

-// HTML-SHAPE:

public double perimeter()

-// HTML-SHAPE:
brief
-// HTML-SHAPE:

Calculates the perimeter of the shape.

-// HTML-SHAPE:
return
-// HTML-SHAPE:

double The perimeter of the shape.

-// HTML-SHAPE:

~Shape

-// HTML-SHAPE:

public void ~Shape()

-// HTML-SHAPE:

Defined at line 13 of file {{.}}Shape.h

-// HTML-SHAPE:
brief
-// HTML-SHAPE:

Virtual destructor.

+// HTML-SHAPE:

class Shape

+// HTML-SHAPE-NEXT:

+// HTML-SHAPE-NEXT: Defined at line +// HTML-SHAPE-NEXT: 8 +// HTML-SHAPE-NEXT: of file +// HTML-SHAPE-NEXT: Shape.h +// HTML-SHAPE-NEXT:

+// HTML-SHAPE:
brief
+// HTML-SHAPE:

Abstract base class for shapes.

+// HTML-SHAPE:

Provides a common interface for different types of shapes.

+// HTML-SHAPE:

Functions

+// HTML-SHAPE:

area

+// HTML-SHAPE:

public double area()

+// HTML-SHAPE:
brief
+// HTML-SHAPE:

Calculates the area of the shape.

+// HTML-SHAPE:

perimeter

+// HTML-SHAPE:

public double perimeter()

+// HTML-SHAPE:
brief
+// HTML-SHAPE:

Calculates the perimeter of the shape.

+// HTML-SHAPE:
return
+// HTML-SHAPE:

double The perimeter of the shape.

+// HTML-SHAPE:

~Shape

+// HTML-SHAPE:

public void ~Shape()

+// HTML-SHAPE: Defined at line +// HTML-SHAPE-NEXT: 13 +// HTML-SHAPE-NEXT: of file +// HTML-SHAPE-NEXT: Shape.h +// HTML-SHAPE:
brief
+// HTML-SHAPE:

Virtual destructor.

-// HTML-CALC:

class Calculator

-// HTML-CALC:

Defined at line 8 of file {{.}}Calculator.h

-// HTML-CALC:
brief
-// HTML-CALC:

A simple calculator class.

-// HTML-CALC:

Provides basic arithmetic operations.

-// HTML-CALC:

Functions

-// HTML-CALC:

add

-// HTML-CALC:

public int add(int a, int b)

-// HTML-CALC:

Defined at line 3 of file {{.}}Calculator.cpp

-// HTML-CALC:
brief
-// HTML-CALC:

Adds two integers.

-// HTML-CALC:
return
-// HTML-CALC:

int The sum of a and b.

-// HTML-CALC:

subtract

-// HTML-CALC:

public int subtract(int a, int b)

-// HTML-CALC:

Defined at line 7 of file {{.}}Calculator.cpp

-// HTML-CALC:
brief
-// HTML-CALC:

Subtracts the second integer from the first.

-// HTML-CALC:
return
-// HTML-CALC:

int The result of a - b.

-// HTML-CALC:

multiply

-// HTML-CALC:

public int multiply(int a, int b)

-// HTML-CALC:

Defined at line 11 of file {{.}}Calculator.cpp

-// HTML-CALC:
brief
-// HTML-CALC:

Multiplies two integers.

-// HTML-CALC:
return
-// HTML-CALC:

int The product of a and b.

-// HTML-CALC:

divide

-// HTML-CALC:

public double divide(int a, int b)

-// HTML-CALC:

Defined at line 15 of file {{.*}}Calculator.cpp

-// HTML-CALC:
brief
-// HTML-CALC:

Divides the first integer by the second.

-// HTML-CALC:
return
-// HTML-CALC:

double The result of a / b.

-// HTML-CALC:
throw
-// HTML-CALC:

if b is zero.

+// HTML-CALC:

class Calculator

+// HTML-CALC-NEXT:

+// HTML-CALC-NEXT: Defined at line +// HTML-CALC-NEXT: 8 +// HTML-CALC-NEXT: of file +// HTML-CALC-NEXT: Calculator.h +// HTML-CALC-NEXT:

+// HTML-CALC:
brief
+// HTML-CALC:

A simple calculator class.

+// HTML-CALC:

Provides basic arithmetic operations.

+// HTML-CALC:

Functions

+// HTML-CALC:

add

+// HTML-CALC:

public int add(int a, int b)

+// HTML-CALC: Defined at line +// HTML-CALC-NEXT: 3 +// HTML-CALC-NEXT: of file +// HTML-CALC-NEXT: Calculator.cpp +// HTML-CALC:
brief
+// HTML-CALC:

Adds two integers.

+// HTML-CALC:
return
+// HTML-CALC:

int The sum of a and b.

+// HTML-CALC:

subtract

+// HTML-CALC:

public int subtract(int a, int b)

+// HTML-CALC: Defined at line +// HTML-CALC-NEXT: 7 +// HTML-CALC-NEXT: of file +// HTML-CALC-NEXT: Calculator.cpp +// HTML-CALC:
brief
+// HTML-CALC:

Subtracts the second integer from the first.

+// HTML-CALC:
return
+// HTML-CALC:

int The result of a - b.

+// HTML-CALC:

multiply

+// HTML-CALC:

public int multiply(int a, int b)

+// HTML-CALC: Defined at line +// HTML-CALC-NEXT: 11 +// HTML-CALC-NEXT: of file +// HTML-CALC-NEXT: Calculator.cpp +// HTML-CALC:
brief
+// HTML-CALC:

Multiplies two integers.

+// HTML-CALC:
return
+// HTML-CALC:

int The product of a and b.

+// HTML-CALC:

divide

+// HTML-CALC:

public double divide(int a, int b)

+// HTML-CALC: Defined at line +// HTML-CALC-NEXT: 15 +// HTML-CALC-NEXT: of file +// HTML-CALC-NEXT: Calculator.cpp +// HTML-CALC:
brief
+// HTML-CALC:

Divides the first integer by the second.

+// HTML-CALC:
return
+// HTML-CALC:

double The result of a / b.

+// HTML-CALC:
throw
+// HTML-CALC:

if b is zero.

-// HTML-RECTANGLE:

class Rectangle

-// HTML-RECTANGLE:

Defined at line 10 of file {{.}}Rectangle.h

-// HTML-RECTANGLE:

Represents a rectangle with a given width and height.</p -// HTML-RECTANGLE:

-// HTML-RECTANGLE: Inherits from -// HTML-RECTANGLE: Shape -// HTML-RECTANGLE:

-// HTML-RECTANGLE:

Members

-// HTML-RECTANGLE:

Width of the rectangle.

-// HTML-RECTANGLE:
private double width_
-// HTML-RECTANGLE:

Height of the rectangle.

-// HTML-RECTANGLE:
private double height_
-// HTML-RECTANGLE:

Functions

-// HTML-RECTANGLE:

Rectangle

-// HTML-RECTANGLE:

public void Rectangle(double width, double height)

-// HTML-RECTANGLE:

Defined at line 3 of file {{.}}Rectangle.cpp

-// HTML-RECTANGLE:
brief
-// HTML-RECTANGLE:

Constructs a new Rectangle object.

-// HTML-RECTANGLE:

area

-// HTML-RECTANGLE:

public double area()

-// HTML-RECTANGLE:

Defined at line 6 of file {{.}}Rectangle.cpp

-// HTML-RECTANGLE:
brief
-// HTML-RECTANGLE:

Calculates the area of the rectangle.

-// HTML-RECTANGLE:
return
-// HTML-RECTANGLE:

double The area of the rectangle.

-// HTML-RECTANGLE:

perimeter

-// HTML-RECTANGLE:

public double perimeter()

-// HTML-RECTANGLE:

Defined at line 10 of file {{.}}Rectangle.cpp

-// HTML-RECTANGLE:
brief
-// HTML-RECTANGLE:

Calculates the perimeter of the rectangle.

-// HTML-RECTANGLE:
return
-// HTML-RECTANGLE:

double The perimeter of the rectangle.

+// HTML-RECTANGLE:

class Rectangle

+// HTML-RECTANGLE-NEXT:

+// HTML-RECTANGLE-NEXT: Defined at line +// HTML-RECTANGLE-NEXT: 10 +// HTML-RECTANGLE-NEXT: of file +// HTML-RECTANGLE-NEXT: Rectangle.h +// HTML-RECTANGLE-NEXT:

+// HTML-RECTANGLE:

Represents a rectangle with a given width and height.

+// HTML-RECTANGLE:

+// HTML-RECTANGLE: Inherits from +// HTML-RECTANGLE: Shape +// HTML-RECTANGLE:

+// HTML-RECTANGLE:

Members

+// HTML-RECTANGLE:

Width of the rectangle.

+// HTML-RECTANGLE:
private double width_
+// HTML-RECTANGLE:

Height of the rectangle.

+// HTML-RECTANGLE:
private double height_
+// HTML-RECTANGLE:

Functions

+// HTML-RECTANGLE:

Rectangle

+// HTML-RECTANGLE:

public void Rectangle(double width, double height)

+// HTML-RECTANGLE: Defined at line +// HTML-RECTANGLE-NEXT: 3 +// HTML-RECTANGLE-NEXT: of file +// HTML-RECTANGLE-NEXT: Rectangle.cpp +// HTML-RECTANGLE:
brief
+// HTML-RECTANGLE:

Constructs a new Rectangle object.

+// HTML-RECTANGLE:

area

+// HTML-RECTANGLE:

public double area()

+// HTML-RECTANGLE: Defined at line +// HTML-RECTANGLE-NEXT: 6 +// HTML-RECTANGLE-NEXT: of file +// HTML-RECTANGLE-NEXT: Rectangle.cpp +// HTML-RECTANGLE:
brief
+// HTML-RECTANGLE:

Calculates the area of the rectangle.

+// HTML-RECTANGLE:
return
+// HTML-RECTANGLE:

double The area of the rectangle.

+// HTML-RECTANGLE:

perimeter

+// HTML-RECTANGLE:

public double perimeter()

+// HTML-RECTANGLE: Defined at line +// HTML-RECTANGLE-NEXT: 10 +// HTML-RECTANGLE-NEXT: of file +// HTML-RECTANGLE-NEXT: Rectangle.cpp +// HTML-RECTANGLE:
brief
+// HTML-RECTANGLE:

Calculates the perimeter of the rectangle.

+// HTML-RECTANGLE:
return
+// HTML-RECTANGLE:

double The perimeter of the rectangle.

-// HTML-CIRCLE:

class Circle

-// HTML-CIRCLE:

Defined at line 10 of file {{.}}Circle.h

-// HTML-CIRCLE:
brief
-// HTML-CIRCLE:

Circle class derived from Shape.

-// HTML-CIRCLE:

Represents a circle with a given radius.

-// HTML-CIRCLE:

-// HTML-CIRCLE: Inherits from -// HTML-CIRCLE: Shape -// HTML-CIRCLE:

-// HTML-CIRCLE:

Members

-// HTML-CIRCLE:

Radius of the circle.

-// HTML-CIRCLE:
private double radius_
-// HTML-CIRCLE:

Functions

-// HTML-CIRCLE:

Circle

-// HTML-CIRCLE:

public void Circle(double radius)

-// HTML-CIRCLE:

Defined at line 3 of file {{.}}Circle.cpp

-// HTML-CIRCLE:
brief
-// HTML-CIRCLE:

Constructs a new Circle object.

-// HTML-CIRCLE:

area

-// HTML-CIRCLE:

public double area()

-// HTML-CIRCLE:

Defined at line 5 of file {{.}}Circle.cpp

-// HTML-CIRCLE:
brief
-// HTML-CIRCLE:

Calculates the area of the circle.

-// HTML-CIRCLE:
return
-// HTML-CIRCLE:

double The area of the circle.

-// HTML-CIRCLE:

perimeter

-// HTML-CIRCLE:

public double perimeter()

-// HTML-CIRCLE:

Defined at line 9 of file {{.}}Circle.cpp

-// HTML-CIRCLE:
brief
-// HTML-CIRCLE:

Calculates the perimeter of the circle.

-// HTML-CIRCLE:
return
-// HTML-CIRCLE:

double The perimeter of the circle.

+// HTML-CIRCLE:

class Circle

+// HTML-CIRCLE-NEXT:

+// HTML-CIRCLE-NEXT: Defined at line +// HTML-CIRCLE-NEXT: 10 +// HTML-CIRCLE-NEXT: of file +// HTML-CIRCLE-NEXT: Circle.h +// HTML-CIRCLE-NEXT:

+// HTML-CIRCLE:
brief
+// HTML-CIRCLE:

Circle class derived from Shape.

+// HTML-CIRCLE:

Represents a circle with a given radius.

+// HTML-CIRCLE:

+// HTML-CIRCLE: Inherits from +// HTML-CIRCLE: Shape +// HTML-CIRCLE:

+// HTML-CIRCLE:

Members

+// HTML-CIRCLE:

Radius of the circle.

+// HTML-CIRCLE:
private double radius_
+// HTML-CIRCLE:

Functions

+// HTML-CIRCLE:

Circle

+// HTML-CIRCLE:

public void Circle(double radius)

+// HTML-CIRCLE: Defined at line +// HTML-CIRCLE-NEXT: 3 +// HTML-CIRCLE-NEXT: of file +// HTML-CIRCLE-NEXT: Circle.cpp +// HTML-CIRCLE:
brief
+// HTML-CIRCLE:

Constructs a new Circle object.

+// HTML-CIRCLE:

area

+// HTML-CIRCLE:

public double area()

+// HTML-CIRCLE: Defined at line +// HTML-CIRCLE-NEXT: 5 +// HTML-CIRCLE-NEXT: of file +// HTML-CIRCLE-NEXT: Circle.cpp +// HTML-CIRCLE:
brief
+// HTML-CIRCLE:

Calculates the area of the circle.

+// HTML-CIRCLE:
return
+// HTML-CIRCLE:

double The area of the circle.

+// HTML-CIRCLE:

perimeter

+// HTML-CIRCLE:

public double perimeter()

+// HTML-CIRCLE: Defined at line +// HTML-CIRCLE-NEXT: 9 +// HTML-CIRCLE-NEXT: of file +// HTML-CIRCLE-NEXT: Circle.cpp +// HTML-CIRCLE:
brief
+// HTML-CIRCLE:

Calculates the perimeter of the circle.

+// HTML-CIRCLE:
return
+// HTML-CIRCLE:

double The perimeter of the circle.

// MD-CALC: # class Calculator // MD-CALC: Defined at .{{[/]}}include{{[/]}}Calculator.h#8 diff --git a/clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp b/clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp index dfd31e65787145..97afa12cab6d32 100644 --- a/clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp +++ b/clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp @@ -319,7 +319,12 @@ TEST(HTMLGeneratorTest, emitFunctionHTML) { int P)