aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/AST/CommentParser.cpp
AgeCommit message (Collapse)AuthorFilesLines
2 daysNFC: Clean up of IntrusiveRefCntPtr construction from raw pointers. (#151545)James Y Knight1-3/+2
Handles clang::DiagnosticsEngine and clang::DiagnosticIDs. For DiagnosticIDs, this mostly migrates from `new DiagnosticIDs` to convenience method `DiagnosticIDs::create()`. Part of cleanup https://github.com/llvm/llvm-project/issues/151026
2025-05-22Reapply "[clang] Remove intrusive reference count from `DiagnosticOptions` ↵Jan Svoboda1-6/+4
(#139584)" This reverts commit e2a885537f11f8d9ced1c80c2c90069ab5adeb1d. Build failures were fixed right away and reverting the original commit without the fixes breaks the build again.
2025-05-22Revert "[clang] Remove intrusive reference count from `DiagnosticOptions` ↵Kazu Hirata1-4/+6
(#139584)" This reverts commit 9e306ad4600c4d3392c194a8be88919ee758425c. Multiple builtbot failures have been reported: https://github.com/llvm/llvm-project/pull/139584
2025-05-22[clang] Remove intrusive reference count from `DiagnosticOptions` (#139584)Jan Svoboda1-6/+4
The `DiagnosticOptions` class is currently intrusively reference-counted, which makes reasoning about its lifetime very difficult in some cases. For example, `CompilerInvocation` owns the `DiagnosticOptions` instance (wrapped in `llvm::IntrusiveRefCntPtr`) and only exposes an accessor returning `DiagnosticOptions &`. One would think this gives `CompilerInvocation` exclusive ownership of the object, but that's not the case: ```c++ void shareOwnership(CompilerInvocation &CI) { llvm::IntrusiveRefCntPtr<DiagnosticOptions> CoOwner = &CI.getDiagnosticOptions(); // ... } ``` This is a perfectly valid pattern that is being actually used in the codebase. I would like to ensure the ownership of `DiagnosticOptions` by `CompilerInvocation` is guaranteed to be exclusive. This can be leveraged for a copy-on-write optimization later on. This PR changes usages of `DiagnosticOptions` across `clang`, `clang-tools-extra` and `lldb` to not be intrusively reference-counted.
2025-02-05[Clang][Comments] Allow HTML tags across multiple lines (#120843)nerix1-11/+12
HTML starting tags that span multiple lines were previously not allowed (or rather, only the starting line was lexed as HTML). Doxygen allows those tags. This PR allows the starting tags to span multiple lines. They can't span multiple (C-)Comments, though (it's likely a user-error). Multiple BCPL comments are fine as those are single lines (shown below). Example: ```c /// <a /// href="foo" /// >Aaa</a>b int Test; ``` Fixes #28321.
2024-06-20[Clang][Comments] Support for parsing headers in Doxygen \par commands (#91100)hdoc1-0/+137
### Background Doxygen's `\par` command ([link](https://www.doxygen.nl/manual/commands.html#cmdpar)) has an optional argument, which denotes the header of the paragraph started by a given `\par` command. In short, the paragraph command can be used with a heading, or without one. The code block below shows both forms and how the current version of LLVM/Clang parses this code: ``` $ cat test.cpp /// \par User defined paragraph: /// Contents of the paragraph. /// /// \par /// New paragraph under the same heading. /// /// \par /// A second paragraph. class A {}; $ clang++ -cc1 -ast-dump -fcolor-diagnostics -std=c++20 test.cpp `-CXXRecordDecl 0x1530f3a78 <test.cpp:11:1, col:10> col:7 class A definition |-FullComment 0x1530fea38 <line:2:4, line:9:23> | |-ParagraphComment 0x1530fe7e0 <line:2:4> | | `-TextComment 0x1530fe7b8 <col:4> Text=" " | |-BlockCommandComment 0x1530fe800 <col:5, line:3:30> Name="par" | | `-ParagraphComment 0x1530fe878 <line:2:9, line:3:30> | | |-TextComment 0x1530fe828 <line:2:9, col:32> Text=" User defined paragraph:" | | `-TextComment 0x1530fe848 <line:3:4, col:30> Text=" Contents of the paragraph." | |-ParagraphComment 0x1530fe8c0 <line:5:4> | | `-TextComment 0x1530fe898 <col:4> Text=" " | |-BlockCommandComment 0x1530fe8e0 <col:5, line:6:41> Name="par" | | `-ParagraphComment 0x1530fe930 <col:4, col:41> | | `-TextComment 0x1530fe908 <col:4, col:41> Text=" New paragraph under the same heading." | |-ParagraphComment 0x1530fe978 <line:8:4> | | `-TextComment 0x1530fe950 <col:4> Text=" " | `-BlockCommandComment 0x1530fe998 <col:5, line:9:23> Name="par" | `-ParagraphComment 0x1530fe9e8 <col:4, col:23> | `-TextComment 0x1530fe9c0 <col:4, col:23> Text=" A second paragraph." `-CXXRecordDecl 0x1530f3bb0 <line:11:1, col:7> col:7 implicit class A ``` As we can see above, the optional paragraph heading (`"User defined paragraph"`) is not an argument of the `\par` `BlockCommandComment`, but instead a child `TextComment`. For documentation generators like [hdoc](https://hdoc.io/), it would be ideal if we could parse Doxygen documentation comments with these semantics in mind. Currently that's not possible. ### Change This change parses `\par` command according to how Doxygen parses them, making an optional header available as a an argument if it is present. In addition: - AST unit tests are defined to test this functionality when an argument is present, isn't present, with additional spacing, etc. - TableGen is updated with an `IsParCommand` to support this functionality - `lit` tests are updated where needed
2024-06-10[Clang][Comments] Add argument parsing for @throw @throws @exception (#84726)hdoc1-1/+213
Doxygen allows for the `@throw`, `@throws`, and `@exception` commands to have an attached argument indicating the type being thrown. Currently, Clang's AST parsing doesn't support parsing out this argument from doc comments. The result is missing compatibility with Doxygen. This PR implements parsing of arguments for the `@throw`, `@throws`, and `@exception` commands. Each command can only have one argument, matching the semantics of Doxygen.
2023-11-06Add missing `llvm::to_underlying` in `AST/CommentParser.cpp` unit testVlad Serebrennikov1-2/+3
This fixed a test failure introduced in f2d8a0ac1dd1fe55b2c3b358c525fbc01b0121ed.
2023-11-06[clang][NFC] Refactor `ParamCommandComment::PassDirection`Vlad Serebrennikov1-37/+25
This patch converts `ParamCommandComment::PassDirection` to a scoped enum at namespace scope, making it eligible for forward declaring. This is useful for e.g. annotating bit-fields with `preferred_type`.
2022-09-08[clang] Use std::size instead of llvm::array_lengthofJoe Loser1-18/+18
LLVM contains a helpful function for getting the size of a C-style array: `llvm::array_lengthof`. This is useful prior to C++17, but not as helpful for C++17 or later: `std::size` already has support for C-style arrays. Change call sites to use `std::size` instead. Leave the few call sites that use a locally defined `array_lengthof` that are meant to test previous bugs with NTTPs in clang analyzer and SemaTemplate. Differential Revision: https://reviews.llvm.org/D133520
2022-01-26Revert "Rename llvm::array_lengthof into llvm::size to match std::size from ↵Benjamin Kramer1-18/+18
C++17" This reverts commit ef8206320769ad31422a803a0d6de6077fd231d2. - It conflicts with the existing llvm::size in STLExtras, which will now never be called. - Calling it without llvm:: breaks C++17 compat
2022-01-26Rename llvm::array_lengthof into llvm::size to match std::size from C++17serge-sans-paille1-18/+18
As a conquence move llvm::array_lengthof from STLExtras.h to STLForwardCompat.h (which is included by STLExtras.h so no build breakage expected).
2020-08-09[AST] Fixed string list in testDávid Bolvanský1-2/+2
2020-08-09[AST] Fixed string concatenation warningsDávid Bolvanský1-32/+32
2020-07-03[clang][NFC] Store a pointer to the ASTContext in ASTDumper and TextNodeDumperBruno Ricci1-1/+1
In general there is no way to get to the ASTContext from most AST nodes (Decls are one of the exception). This will be a problem when implementing the rest of APValue::dump since we need the ASTContext to dump some kinds of APValues. The ASTContext* in ASTDumper and TextNodeDumper is not always non-null. This is because we still want to be able to use the various dump() functions in a debugger. No functional changes intended. Reverted in fcf4d5e4499a391dff42ea1a096f146db44147b6 since a few dump() functions in lldb where missed.
2020-07-02Revert "[clang][NFC] Store a pointer to the ASTContext in ASTDumper and ↵Bruno Ricci1-1/+1
TextNodeDumper" This reverts commit aa7fd905e4e1bc510448431da9310e8cf5197523. I missed some dump() functions.
2020-07-02[clang][NFC] Store a pointer to the ASTContext in ASTDumper and TextNodeDumperBruno Ricci1-1/+1
In general there is no way to get to the ASTContext from most AST nodes (Decls are one of the exception). This will be a problem when implementing the rest of APValue::dump since we need the ASTContext to dump some kinds of APValues. The ASTContext* in ASTDumper and TextNodeDumper is not always non-null. This is because we still want to be able to use the various dump() functions in a debugger. No functional changes intended.
2019-09-02[unittests][AST] CommentParser: don't name variable 'DEBUG'Roman Lebedev1-2/+2
It's may be an already-defined macro name, resulting in compilation errors. llvm-svn: 370650
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-4/+3
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2016-07-18[NFC] Header cleanupMehdi Amini1-1/+0
Summary: Removed unused headers, replaced some headers with forward class declarations Patch by: Eugene <claprix@yandex.ru> Differential Revision: https://reviews.llvm.org/D20100 llvm-svn: 275882
2014-08-29unique_ptrify SourceManager::createFileIDDavid Blaikie1-1/+1
llvm-svn: 216715
2014-08-27Update for LLVM api change.Rafael Espindola1-2/+2
llvm-svn: 216585
2014-06-08[C++11] Use 'nullptr'. Unittests edition.Craig Topper1-2/+2
llvm-svn: 210423
2014-05-16Rename SourceManager::createFileIDForMemBuffer()Alp Toker1-1/+1
It makes more sense to just overload createFileID(). Gardening only. llvm-svn: 209002
2014-01-27Comment parsing: don't crash while parsing \deprecated in a standalone commentDmitri Gribenko1-0/+20
(comment without a decl). I think this can not happen during normal compilation with -Wdocumentation, only while using Clang APIs to parse comments outside of a source file. Based on a patch by Olivier Goffart. llvm-svn: 200230
2013-08-23Comment parsing: fix a bug where a line with whitespace between two paragraphsDmitri Gribenko1-5/+30
would cause us to concatenate these paragraphs into a single one. The no-op whitespace churn in test/Index test happened because these tests don't use the correct approach for testing and are more strict than required for they are testing. llvm-svn: 189126
2013-05-03[Doc parsing] Provide diagnostics for unknown documentation Fariborz Jahanian1-1/+1
commands. // rdar://12381408 llvm-svn: 181071
2013-02-22Comment parsing: add CommentOptions to allow specifying custom comment block ↵Dmitri Gribenko1-1/+2
commands Add an ability to specify custom documentation block comment commands via a new class CommentOptions. The intention is that this class will hold future customizations for comment parsing, including defining documentation comments with specific numbers of parameters, etc. CommentOptions instance is a member of LangOptions. CommentOptions is controlled by a new command-line parameter -fcomment-block-commands=Foo,Bar,Baz. llvm-svn: 175892
2012-12-04Really sort the #include lines in unittests/...Chandler Carruth1-1/+1
I forgot to re-sort after fixing main module headers. llvm-svn: 169244
2012-12-04Sort the #include lines for unittests/...Chandler Carruth1-7/+6
I've tried to place sensible headers at the top as main-module headers. llvm-svn: 169243
2012-10-23More unit-test fixesDouglas Gregor1-0/+1
llvm-svn: 166511
2012-10-23Fixup unit tests for DiagnosticOptions changeDouglas Gregor1-1/+1
llvm-svn: 166509
2012-10-18[doc parsing] use getParamName to access parameter Fariborz Jahanian1-2/+2
for current(rewritten) comment and getParamNameAsWritten to access param name coming with \param marker. llvm-svn: 166231
2012-10-15structured document comment: patch to provide comment for overriding functionFariborz Jahanian1-1/+1
template when comment is comming from overridden declaration. // rdar://12378793 llvm-svn: 165953
2012-10-10[Doc parsing] This patch searches overridden objc/c++Fariborz Jahanian1-1/+1
methods looking for documentation on a particular base class inherited by any method that overrides the base class. In case of redeclaration, as when objc method is defined in the implementation, it also looks up for documentation in class/class extension being redeclared. llvm-svn: 165643
2012-09-29Move the 'find macro by spelling' infrastructure to the Preprocessor class andDmitri Gribenko1-1/+1
use it to suggest appropriate macro for __attribute__((deprecated)) in -Wdocumentation-deprecated-sync. llvm-svn: 164892
2012-09-10Comment AST: TableGen'ize all command lists in CommentCommandTraits.cpp.Dmitri Gribenko1-50/+68
Now we have a list of all commands. This is a good thing in itself, but it also enables us to easily implement typo correction for command names. With this change we have objects that contain information about each command, so it makes sense to resolve command name just once during lexing (currently we store command names as strings and do a linear search every time some property value is needed). Thus comment token and AST nodes were changed to contain a command ID -- index into a tables of builtin and registered commands. Unknown commands are registered during parsing and thus are also uniformly assigned an ID. Using an ID instead of a StringRef is also a nice memory optimization since ID is a small integer that fits into a common bitfield in Comment class. This change implies that to get any information about a command (even a command name) we need a CommandTraits object to resolve the command ID to CommandInfo*. Currently a fresh temporary CommandTraits object is created whenever it is needed since it does not have any state. But with this change it has state -- new commands can be registered, so a CommandTraits object was added to ASTContext. Also, in libclang CXComment has to be expanded to include a CXTranslationUnit so that all functions working on comment AST nodes can get a CommandTraits object. This breaks binary compatibility of CXComment APIs. Now clang_FullComment_getAsXML(CXTranslationUnit TU, CXComment CXC) doesn't need TU parameter anymore, so it was removed. This is a source-incompatible change for this C API. llvm-svn: 163540
2012-08-31Remove the useless CommentOptions class.Dmitri Gribenko1-1/+1
llvm-svn: 162986
2012-08-09Comment parsing: extract TableGen'able pieces into new CommandTraits class.Dmitri Gribenko1-3/+5
llvm-svn: 161548
2012-08-06Comment parsing: fix crash on \tparam followed immediately by another blockDmitri Gribenko1-8/+56
command, for example: \tparam\brief. llvm-svn: 161361
2012-08-01Comment parser tests: test that we allow placing no whitespace between \paramDmitri Gribenko1-0/+3
and [direction]. llvm-svn: 161146
2012-07-31Comment parsing: add support for \tparam command on all levels.Dmitri Gribenko1-0/+60
The only caveat is renumbering CXCommentKind enum for aesthetic reasons -- this breaks libclang binary compatibility, but should not be a problem since API is so new. This also fixes PR13372 as a side-effect. llvm-svn: 161087
2012-07-30Comment parser: add one more testDmitri Gribenko1-4/+23
llvm-svn: 160965
2012-07-27Implement resolving of HTML character references (named: &amp;, decimal: &#42;,Dmitri Gribenko1-1/+1
hex: &#x1a;) during comment parsing. Now internal representation of plain text in comment AST does not contain character references, but the characters themselves. llvm-svn: 160891
2012-07-24Comment parsing: allow newlines between \param, direction specification (e.g.,Dmitri Gribenko1-44/+82
[in]), parameter name and description paragraph. llvm-svn: 160682
2012-07-24Comment parsing: retokenized text tokens are now pushed back in correct (notDmitri Gribenko1-0/+25
reverse) order llvm-svn: 160675
2012-07-23Comment parser unit tests: split a huge test caseDmitri Gribenko1-34/+51
llvm-svn: 160649
2012-07-23Comment parser unit tests: reduce code duplicationDmitri Gribenko1-122/+45
llvm-svn: 160647
2012-07-20Fix PR13411: Comment parsing: failed assertion on unterminated verbatim block.Dmitri Gribenko1-15/+58
The assertion was wrong in case we have a verbatim block without a closing command. Also add tests for closing command name in a verbatim block, since now it can be empty in such cases. llvm-svn: 160568
2012-07-18Comment parsing: don't parse whitespace before \endverbatim as a separate ↵Dmitri Gribenko1-18/+48
line of whitespace. llvm-svn: 160464