diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp b/clang-tools-extra/clang-doc/HTMLGenerator.cpp index a6ebc007278db..18a0de826630c 100644 --- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp +++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp @@ -494,18 +494,31 @@ genReferencesBlock(const std::vector &References, static std::unique_ptr writeFileDefinition(const Location &L, std::optional RepositoryUrl = std::nullopt) { - if (!L.IsFileInRootDir || !RepositoryUrl) + if (!L.IsFileInRootDir && !RepositoryUrl) return std::make_unique( HTMLTag::TAG_P, "Defined at line " + std::to_string(L.LineNumber) + " of file " + L.Filename); SmallString<128> FileURL(*RepositoryUrl); - llvm::sys::path::append(FileURL, llvm::sys::path::Style::posix, L.Filename); + llvm::sys::path::append( + FileURL, llvm::sys::path::Style::posix, + // If we're on Windows, the file name will be in the wrong format, and + // append won't convert the full path being appended to the correct + // format, so we need to do that here. + llvm::sys::path::convert_to_slash( + L.Filename, + // The style here is the current style of the path, not the one we're + // targeting. If the string is already in the posix style, it will do + // nothing. + llvm::sys::path::Style::windows)); auto Node = std::make_unique(HTMLTag::TAG_P); Node->Children.emplace_back(std::make_unique("Defined at line ")); auto LocNumberNode = std::make_unique(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()); Node->Children.emplace_back(std::move(LocNumberNode)); 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 823384a4d97e8..3ddb2fd9ff563 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 b6b43bb82bb15..1f5ba8bdc0703 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.

-// 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 dfd31e6578714..97afa12cab6d3 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)

-

Defined at line 10 of file dir/test.cpp

+

+ Defined at line + 10 + of file + test.cpp +