70 Commits

Author SHA1 Message Date
PeterChou1
e10f67a827
[clang-doc][NFC] refactor out file helpers (#134298)
Split from https://github.com/llvm/llvm-project/pull/133161

refactor the code to extract file helpers used in HTML generators for
use in other generators for clang-doc
2025-04-09 17:21:28 -04:00
Mohamed Emad
515d1ae679
[clang-doc] Add --repository-line-prefix argument (#131280)
This PR adds a new command-line option that allows users to specify the
prefix used for line-based anchors in repository URLs. Different
repository interfaces use different formats for line anchors (GitHub
uses `#L123`, googlesource uses `#123`, etc.). This option enables users
to customize the line prefix to match their repository platform without
requiring hard-coded values for each service.

Fixes #59814
2025-03-28 16:45:09 -07:00
Paul Kirth
d4dc5712c4
[clang-doc] Allow setting a base directory for hosted pages (#132482)
Currently, when we set URLs from JS, we set them only using the protocol
and host locations. This works fine when docs are served from the base
directory of the site, but if you want to nest it under another
directory, our JS fails to set the correct path, leading to broken
links.

This patch adds a --base option to specify the path prefix to use, which
is set in the generated index_json.js file. index.json can then fill in
the prefix appropriately when generating links in a browser. This flag
has no effect for non HTML output.

Given an index hosted at: www.docs.com/base_directory/index.html
we used to generate the following link:
    www.docs.com/file.html
Using --base base_directory we now generate:
    www.docs.com/base_directory/file.html

This allows such links to work when hosting pages without using a custom
index.js.
2025-03-28 12:49:43 -07:00
Paul Kirth
a87a64b2e4
[clang-doc] Avoid deref of invalid std::optional (#131939)
Since our existing guard is insufficient to prevent accessing the
std::optional when in an invalid state, guard the access with
`.value_or()`. This maintains the desired behavior, without running into
UB.

The new test should prevent regressions.

Fixes #131697
2025-03-20 14:04:58 -07:00
Paul Kirth
1a7e79b85d
[clang-doc] Make --repository change the HTML output (#122566)
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.
2025-02-06 11:26:17 -08:00
Abhina Sree
2b3ddec7df
[SystemZ][z/OS] Open text files in text mode (#125570)
This patch continues the work that was started here
https://reviews.llvm.org/D99426 to correctly open text files in text
mode.
2025-02-04 09:12:45 -05:00
PeterChou1
c29aba7159
[clang-doc] add support for block commands in clang-doc html output (#101108) 2024-08-20 03:58:47 -04:00
PeterChou1
5ef2456a43
[clang-doc] add support for enums comments in html generation (#101282)
Part of https://github.com/llvm/llvm-project/issues/101129

This patch adds support for attaching comments to enums for HTML in
clang-doc. It changes the enum generation to table tags where as
perviously we're using lists which is more in line with what other doc
generators are doing. It also gives clang-doc the ability to show user
specified enum values
2024-08-16 18:37:17 -04:00
PeterChou1
b4bc7b182c
[clang-doc] add support for comments for members in HTML output (#101255)
currently the HTML output does not support comments attached to class
members, this patch modifies the HTMLGenerator to add comments for the
output.
2024-08-12 15:08:30 -04:00
PeterChou1
91450f1b57
[clang-doc] switched from using relative to absolute paths (#93281)
fixes https://github.com/llvm/llvm-project/issues/92867

This patches changes the way clang-doc index navigation works,
previously it was based a relative path approach, this approach is error
prone and lead to wrong paths for the anchor tag. The new navigation way
is based on absolute paths and should work and be less confusing
codewise.
Because the differences with serving over a http server and viewing via
file system I also added export a RootPath variable to the index_json.js
file
2024-07-25 03:33:02 -04:00
PeterChou1
fb55db5482
[clang-doc] fix broken tests (#100260)
This patch fixes the broken test caused by clang-doc which was caused by
https://github.com/llvm/llvm-project/pull/100251

https://lab.llvm.org/buildbot/#/builders/144/builds/3080
2024-07-23 18:55:25 -04:00
PeterChou1
80d1c6acc0
Revert "[clang-doc] add ftime profiling" (#100251)
This broke the build due to failing some clang-tidy checks:
https://lab.llvm.org/buildbot/#/builders/145/builds/789
2024-07-23 18:31:11 -04:00
Paul Kirth
46a2abb91c
[clang-doc][nfc] Avoid constructing SmallString in ToString method (#96921)
This patch updates the return type of HTMLTag::toString from
SmallString<16> to StringRef, since this API only returns string
literals. As a result, there is no need to construct a full heap
allocated or owned string.

Additionally, this patch renames ToString to toString to match the LLVM
style guide.
2024-07-08 16:30:18 -07:00
PeterChou1
a9b1e80acb
[clang-doc] add async loading (#93276)
Fixes https://github.com/llvm/llvm-project/issues/93273

This patch changes the way clang-doc loads html indexes. Previously
clang-doc loaded the index via an index_json.js file which uses
JSON.parse to parse the file. This patches changes that to use an async
function called LoadIndex which enables asynchronous loading making the
initial page load not be blocked by loading a large JavaScript object.
2024-06-30 08:52:36 -07:00
Paul Kirth
ecfbb8504e
[clang-doc][NFC] Fix style guide violations in HTMLGenerator.cpp
This patch addresses several code style issues that conflict with the
project's style guide. Primarily the naming of functions, and `else`
after `return` statements. It only addresses issues found in
HTMLGenerator.cpp.

Reviewers: petrhosek

Reviewed By: petrhosek

Pull Request: https://github.com/llvm/llvm-project/pull/96924
2024-06-27 13:46:35 -07:00
PeterChou1
f14ad74478
Reapply [clang-doc] Add --asset option to clang-doc (#96358)
Reapply https://github.com/llvm/llvm-project/pull/94717
Adds a new option --asset which allows users to specified the asset
folder for the html output of clang-doc.

This patch adds a better test for --asset option + fixes bug where
clang-doc assumes that user supplied js file is assume to be index.js
2024-06-27 13:22:01 -07:00
Kazu Hirata
2b00d449d2 [clang-tools-extra] Use SmallString::operator std::string (NFC) 2024-01-26 23:46:24 -08:00
Kazu Hirata
21edd381e4 [clang-doc] Use SmallString::operator std::string (NFC) 2024-01-14 12:17:56 -08:00
Kazu Hirata
15aa965363 [clang-tools-extra] Use *{Set,Map}::contains (NFC) 2023-03-14 21:30:29 -07:00
Kazu Hirata
f71ffd3b73 [clang-tools-extra] Use std::optional instead of llvm::Optional (NFC)
This patch replaces (llvm::|)Optional< with std::optional<.  I'll post
a separate patch to clean up the "using" declarations, #include
"llvm/ADT/Optional.h", etc.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-07 20:19:42 -08:00
Kazu Hirata
71f557355d [clang-tools-extra] Add #include <optional> (NFC)
This patch adds #include <optional> to those files containing
llvm::Optional<...> or Optional<...>.

I'll post a separate patch to actually replace llvm::Optional with
std::optional.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-07 20:02:20 -08:00
Fangrui Song
53243f2a29 std::optional::value => operator*/operator->
value() has undesired exception checking semantics and calls
__throw_bad_optional_access in libc++. Moreover, the API is unavailable without
_LIBCPP_NO_EXCEPTIONS on older Mach-O platforms (see
_LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS).

This fixes check-clang-tools.
2022-12-17 03:12:04 +00:00
Kazu Hirata
059a23c0f0 [clang-tools-extra] Use std::nullopt instead of None (NFC)
This patch mechanically replaces None with std::nullopt where the
compiler would warn if None were deprecated.  The intent is to reduce
the amount of manual work required in migrating from Optional to
std::optional.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-03 11:54:50 -08:00
Brett Wilson
7b8c7e0212 [clang-doc] Move file layout to the generators.
Previously file naming and directory layout was handled on a per Info
object basis by ClangDocMain and the generators blindly wrote to the
files given. This means all generators must use the same file layout and
caused problems where multiple objects mapped to the same file. The
object collision problem happens most easily with template
specializations because the template parameters are not part of the
"name".

This patch moves the responsibility for output file organization to the
generators. Currently HTML and MD use the same structure as before. But
they now collect all objects that map to a given file and combine them,
avoiding the corruption problems.

Converts the YAML generator to naming files based on USR in one
directory. This is easier for downstream tools to manage and avoids the
naming problems with template specializations. Since this change
requires backward-incompatible output changes to referenced files anyway
(since each one is now an array), this is a good time to introduce this
change.

Differential Revision: https://reviews.llvm.org/D138073
2022-11-29 14:40:58 -08:00
Paul Kirth
48bb147112 Revert "[clang-doc] Move file layout to the generators."
This reverts commit f8a469fc572778d05b72f34a772082cf3abd3cda.

The test in single-file-public.cpp breaks on Mac, due to an unknown
regextype in the find command.
2022-11-22 19:14:54 +00:00
Brett Wilson
f8a469fc57 [clang-doc] Move file layout to the generators.
Previously file naming and directory layout was handled on a per Info
object basis by ClangDocMain and the generators blindly wrote to the
files given. This means all generators must use the same file layout and
caused problems where multiple objects mapped to the same file. The
object collision problem happens most easily with template
specializations because the template parameters are not part of the
"name".

This patch moves the responsibility for output file organization to the
generators. Currently HTML and MD use the same structure as before. But
they now collect all objects that map to a given file and combine them,
avoiding the corruption problems.

Converts the YAML generator to naming files based on USR in one
directory. This is easier for downstream tools to manage and avoids
the naming problems with template specializations. Since this change
requires backward-incompatible output changes to referenced files anyway
(since each one is now an array), this is a good time to introduce this
change.

Differential Revision: https://reviews.llvm.org/D138073
2022-11-22 10:27:29 -08:00
Brett Wilson
21fb70c6ab [clang-doc] Add typedef/using information.
Read typedef and "using" type alias declarations and serialize into the
internal structures. Emit this information in the YAML output. The HTML
and MD generators are unchanged.

Separate out the logic to create the parent namespace or record object
and insert the newly created child into it. This logic was previously
duplicated for every "info" type and is now shared.

To help this, a struct containing the child vectors was separated out so
children can be added generically and without having too many templates.

A small change was made to populateParentNamespaces() to allow using
types that aren't themselves DeclContexts (typedefs are the first
example of this).

Differential Revision: https://reviews.llvm.org/D134371
2022-10-14 14:59:29 -07:00
Haowei Wu
a759477222 Revert "[clang-doc] Add typedef/using information."
This reverts commit eed22583fd78d4d657fb70b99e62fbdc1f83b8f9, which
breaks clang build with -Werror.
2022-09-27 18:35:34 -07:00
Brett Wilson
eed22583fd [clang-doc] Add typedef/using information.
Read typedef and "using" type alias declarations and serialize into the internal structures. Emit this information in the YAML output. The HTML and MD generators are unchanged.

Separate out the logic to create the parent namespace or record object and insert the newly created child into it. This logic was previously duplicated for every "info" type and is now shared.

To help this, a struct containing the child vectors was separated out so children can be added generically and without having too many templates.

A small change was made to populateParentNamespaces() to allow using types that aren't themselves DeclContexts (typedefs are the first example of this).

Reviewed By: paulkirth, haowei

Differential Revision: https://reviews.llvm.org/D134371
2022-09-27 23:35:16 +00:00
Brett Wilson
0afc60858e [clang-doc] Clean up *Info constructors.
The *Info object (for the copy of the AST") constructors had many duplicated variants. Many of the variants seemed to be in an attempt to avoid default arguments. But default arguments are not prohibited and using them allows most of the variants to be removed which improves readability.

Remove the IsInGlobalNamespace flag on a Reference. This is set when the path is empty, and only read once in the HTML generator with the identical condition. The constructor cleanup exposed a problem where this was set to false when the constructor with no path was used, but true when the path was set to empty.

There should be no observable change with the exception that IsInGlobalNamespace is no longer emitted in YAML.

Reviewed By: paulkirth, haowei

Differential Revision: https://reviews.llvm.org/D134235
2022-09-27 23:31:41 +00:00
Brett Wilson
eaa7b324d5 [clang-doc] Add support for explicitly typed enums
Add support for explicitly typed enums:
  enum Foo : unsigned { ... };
to the internal representation and to the YAML output.

Add support for getting the value of an enum constant, as well as accessing the original expression that produced it. This changes the YAML output of enums from an array of strings for the enum members to an array of dictionaries. These dictionaries now report the name, value, and original expression.

The markdown and HTML outputs are unchanged, they still output the name from the new enhanced internal schema.

Reviewed By: paulkirth

Differential Revision: https://reviews.llvm.org/D134055
2022-09-19 21:54:41 +00:00
Kazu Hirata
5cff5142a8 Use value instead of getValue (NFC) 2022-07-15 20:03:13 -07:00
Kazu Hirata
3b7c3a654c Revert "Don't use Optional::hasValue (NFC)"
This reverts commit aa8feeefd3ac6c78ee8f67bf033976fc7d68bc6d.
2022-06-25 11:56:50 -07:00
Kazu Hirata
aa8feeefd3 Don't use Optional::hasValue (NFC) 2022-06-25 11:55:57 -07:00
Kazu Hirata
ed8fceaa09 Don't use Optional::getValue (NFC) 2022-06-20 23:35:53 -07:00
Simon Pilgrim
1c502c63cb [clang-doc] SerializeIndex - pass Index param by constant reference
Silence coverity warnings about unnecessary copies
2022-02-17 13:28:02 +00:00
David Blaikie
1def2579e1 PR51018: Remove explicit conversions from SmallString to StringRef to future-proof against C++23
C++23 will make these conversions ambiguous - so fix them to make the
codebase forward-compatible with C++23 (& a follow-up change I've made
will make this ambiguous/invalid even in <C++23 so we don't regress
this & it generally improves the code anyway)
2021-07-08 13:37:57 -07:00
Daniel Martín
6407aa9d2e
[clangd] Add access specifier information to hover contents
Summary:
For https://github.com/clangd/clangd/issues/382

This commit adds access specifier information to the hover
contents. For example, the hover information of a class field or
member function will now indicate if the field or member is private,
public, or protected. This can be particularly useful when a developer
is in the implementation file and wants to know if a particular member
definition is public or private.

Reviewers: kadircet

Reviewed By: kadircet

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D80472
2020-05-27 19:36:46 +02:00
Petr Hosek
7003f64c1e [clang-doc] Improving Markdown Output
This change has two components. The moves the generated file
for a namespace to the directory named after the namespace in
a file named 'index.<format>'. This greatly improves the browsing
experience since the index page is shown by default for a directory.

The second improves the markdown output by adding the links to the
referenced pages for children objects and the link back to the source
code.

Patch By: Clayton

Differential Revision: https://reviews.llvm.org/D72954
2020-03-06 17:37:08 -08:00
Petr Hosek
ea086d10ce Revert "[clang-doc] Improving Markdown Output"
This reverts commit 45499f3801d8a00919deaf38c801885d8e75b942, it's
still failing on Windows bots.
2020-03-04 16:00:22 -08:00
Petr Hosek
45499f3801 [clang-doc] Improving Markdown Output
This change has two components. The moves the generated file
for a namespace to the directory named after the namespace in
a file named 'index.<format>'. This greatly improves the browsing
experience since the index page is shown by default for a directory.

The second improves the markdown output by adding the links to the
referenced pages for children objects and the link back to the source
code.

Patch By: Clayton

Differential Revision: https://reviews.llvm.org/D72954
2020-03-04 14:42:07 -08:00
Petr Hosek
7b627bb6e0 Revert "[clang-doc] Improving Markdown Output"
This reverts commit dac21fdd5923730342a4bc9abc0858fb56ff8d52 as this
is failing on Windows.
2020-02-07 19:43:47 -08:00
Petr Hosek
dac21fdd59 [clang-doc] Improving Markdown Output
This change has two components. The moves the generated file
for a namespace to the directory named after the namespace in
a file named 'index.<format>'. This greatly improves the browsing
experience since the index page is shown by default for a directory.

The second improves the markdown output by adding the links to the
referenced pages for children objects and the link back to the source
code.

Patch By: Clayton

Differential Revision: https://reviews.llvm.org/D72954
2020-02-07 19:17:03 -08:00
Petr Hosek
80e63c17c0 Revert "[clang-doc] Improving Markdown Output"
This reverts commit 0fbaf3a7c2395d751cfa4ecd7f483f077b03d9bd as tests
are failing on some bots.
2020-02-03 12:27:09 -08:00
Petr Hosek
0fbaf3a7c2 [clang-doc] Improving Markdown Output
This change has two components. The moves the generated file
for a namespace to the directory named after the namespace in
a file named 'index.<format>'. This greatly improves the browsing
experience since the index page is shown by default for a directory.

The second improves the markdown output by adding the links to the
referenced pages for children objects and the link back to the source
code.

Patch By: Clayton

Differential Revision: https://reviews.llvm.org/D72954
2020-02-03 12:14:17 -08:00
Petr Hosek
c0f475f2e3 Revert "[clang-doc] Improving Markdown Output"
This reverts commit deae8ee6916711b9b20f73fc1a350c3a034d5b34 as it
broke the build on several bots.
2020-01-31 14:30:42 -08:00
Petr Hosek
deae8ee691 [clang-doc] Improving Markdown Output
This change has two components. The moves the generated file
for a namespace to the directory named after the namespace in
a file named 'index.<format>'. This greatly improves the browsing
experience since the index page is shown by default for a directory.

The second improves the markdown output by adding the links to the
referenced pages for children objects and the link back to the source
code.

Patch By: Clayton

Differential Revision: https://reviews.llvm.org/D72954
2020-01-31 14:21:21 -08:00
Mikael Holmén
2103e08b3f More fixes of implicit std::string conversions 2020-01-29 15:29:46 +01:00
Fangrui Song
ff354de294 [clang-doc] sys::fs::F_None -> OF_None. NFC
F_None, F_Text and F_Append are kept for compatibility.

llvm-svn: 371394
2019-09-09 12:42:10 +00:00
Fangrui Song
180380651c [clang-doc] Use llvm::createStringError and canonicalize error messages
"Bad block found.\n" -> "bad block found"

The lower cased form with no full stop or newline is more common in LLVM
tools.

Reviewed By: juliehockett

Differential Revision: https://reviews.llvm.org/D66783

llvm-svn: 370155
2019-08-28 02:56:03 +00:00