summaryrefslogtreecommitdiff
path: root/lib/AST/RawCommentList.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [clang] Refactor doc comments to Decls attributionJan Korous2019-08-131-22/+42
| | | | | | | | | | | | - Create ASTContext::attachCommentsToJustParsedDecls so we don't have to load external comments in Sema when trying to attach existing comments to just parsed Decls. - Keep comments ordered and cache their decomposed location - faster SourceLoc-based searching. - Optimize work with redeclarations. - Keep one comment per redeclaration chain (represented by canonical Decl) instead of comment per redeclaration. - For redeclaration chains with no comment attached keep just the last declaration in chain that had no comment instead of every comment-less redeclaration. Differential Revision: https://reviews.llvm.org/D65301 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@368732 91177308-0d34-0410-b5e6-96231b3b80d8
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@351636 91177308-0d34-0410-b5e6-96231b3b80d8
* Misc typos fixes in ./lib folderRaphael Isemann2018-12-101-1/+1
| | | | | | | | | | | | | | Summary: Found via `codespell -q 3 -I ../clang-whitelist.txt -L uint,importd,crasher,gonna,cant,ue,ons,orign,ned` Reviewers: teemperor Reviewed By: teemperor Subscribers: teemperor, jholewinski, jvesely, nhaehnle, whisperity, jfb, cfe-commits Differential Revision: https://reviews.llvm.org/D55475 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@348755 91177308-0d34-0410-b5e6-96231b3b80d8
* Port getLocEnd -> getEndLocStephen Kelly2018-08-091-2/+2
| | | | | | | | | | Reviewers: teemperor! Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D50351 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@339386 91177308-0d34-0410-b5e6-96231b3b80d8
* Port getLocStart -> getBeginLocStephen Kelly2018-08-091-6/+6
| | | | | | | | | | Reviewers: teemperor! Subscribers: jholewinski, whisperity, jfb, cfe-commits Differential Revision: https://reviews.llvm.org/D50350 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@339385 91177308-0d34-0410-b5e6-96231b3b80d8
* [AST] Added a helper to extract a user-friendly text of a comment.Ilya Biryukov2018-05-161-0/+91
| | | | | | | | | | | | | | | | | | | | | | Summary: The helper is used in clangd for documentation shown in code completion and storing the docs in the symbols. See D45999. This patch reuses the code of the Doxygen comment lexer, disabling the bits that do command and html tag parsing. The new helper works on all comments, including non-doxygen comments. However, it does not understand or transform any doxygen directives, i.e. cannot extract brief text, etc. Reviewers: sammccall, hokein, ioeric Reviewed By: ioeric Subscribers: mgorny, cfe-commits Differential Revision: https://reviews.llvm.org/D46000 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@332458 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove \brief commands from doxygen comments.Adrian Prantl2018-05-091-1/+1
| | | | | | | | | | | | | | | | | | | This is similar to the LLVM change https://reviews.llvm.org/D46290. We've been running doxygen with the autobrief option for a couple of years now. This makes the \brief markers into our comments redundant. Since they are a visual distraction and we don't want to encourage more \brief markers in new code either, this patch removes them all. Patch produced by for i in $(git grep -l '\@brief'); do perl -pi -e 's/\@brief //g' $i & done for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done Differential Revision: https://reviews.llvm.org/D46320 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@331834 91177308-0d34-0410-b5e6-96231b3b80d8
* [NFC] Move CommentOpts checks to the call sites that depend on it. ↵David L. Jones2018-03-021-8/+9
| | | | | | | | | | | | | | | | | | | | | | | (Re-applying r326501.) When parsing comments, for example, for -Wdocumentation, slightly different behaviour occurs when -fparse-all-comments is specified. However, these differences are subtle: 1. All comments are saved during parsing, regardless of whether they are doc comments or not. 2. "Maybe-doc" comments, like <, !, etc, are saved as such, instead of marking them as ordinary comments. The maybe-doc type of comment is never saved otherwise. (Warning on these is the impetus of -Wdocumentation.) 3. All comments are treated as doc comments in ASTContext, even if they are ordinary. This change moves the logic for checking CommentOptions.ParseAllComments closer to where it has an effect. The overall logic is unchanged, but checks of the ParseAllComments flag are now done where the effect will be clearer. Subscribers: cfe-commits git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@326512 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert r326501 due to buildbot breakage.David L. Jones2018-03-011-9/+8
| | | | | | | | | | | | | | | | | | | | | | | Original change: [NFC] Move CommentOpts checks to the call sites that depend on it. When parsing comments, for example, for -Wdocumentation, slightly different behaviour occurs when -fparse-all-comments is specified. However, these differences are subtle: 1. All comments are saved during parsing, regardless of whether they are doc comments or not. 2. "Maybe-doc" comments, like //<, //!, etc, are saved as such, instead of marking them as ordinary comments. The maybe-doc type of comment is never saved otherwise. (Warning on these is the impetus of -Wdocumentation.) 3. All comments are treated as doc comments in ASTContext, even if they are ordinary. This change moves the logic for checking CommentOptions.ParseAllComments closer to where it has an effect. The overall logic is unchanged, but checks of the ParseAllComments flag are now done where the effect will be clearer. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@326508 91177308-0d34-0410-b5e6-96231b3b80d8
* [NFC] Move CommentOpts checks to the call sites that depend on it.David L. Jones2018-03-011-8/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | When parsing comments, for example, for -Wdocumentation, slightly different behaviour occurs when -fparse-all-comments is specified. However, these differences are subtle: 1. All comments are saved during parsing, regardless of whether they are doc comments or not. 2. "Maybe-doc" comments, like //<, //!, etc, are saved as such, instead of marking them as ordinary comments. The maybe-doc type of comment is never saved otherwise. (Warning on these is the impetus of -Wdocumentation.) 3. All comments are treated as doc comments in ASTContext, even if they are ordinary. This change moves the logic for checking CommentOptions.ParseAllComments closer to where it has an effect. The overall logic is unchanged, but checks of the ParseAllComments flag are now done where the effect will be clearer. Reviewers: rsmith Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D43663 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@326501 91177308-0d34-0410-b5e6-96231b3b80d8
* AST: Improve a couple of comments and cast unused values to voidJustin Bogner2016-10-161-5/+4
| | | | | | | | Make these comments a bit more explicit that they're initializing the RawText member, and explicitly cast the unused result of getRawText to void for clarity. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@284341 91177308-0d34-0410-b5e6-96231b3b80d8
* Allow any comment to be a trailing comment when -fparse-all-comments is on.James Dennett2015-07-151-7/+79
| | | | | | | | | | | | | | | | | | | | | | | | | This helps with freeform documentation styles, where otherwise code like enum class E { E1, // D1 E2 // D2 }; would result in D1 being associated with E2. To properly associate E1 with D1 and E2 with D2, this patch allows all raw comments C such that C.isParseAllComments() to participate in trailing comment checks inside getRawCommentForDeclNoCache. This takes care of linking the intended documentation with the intended decls. There remains an issue with code like: foo(); // DN int x; To prevent DN from being associated with x, this patch adds a new test on preceding-line comments C (where C.isParseAllComments() and also C's kind is RCK_OrdinaryBCPL or RCK_OrdinaryC) that checks whether C is the first non-whitespace thing on C's starting line. Patch from Luke Zarko <zarko@google.com>, D11069 reviewed by rsmith. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@242317 91177308-0d34-0410-b5e6-96231b3b80d8
* Comment parsing: when comment ranges are deserialized from multiple modules,Dmitri Gribenko2014-03-271-0/+12
| | | | | | | | | | correctly order comments in SourceManager::isBeforeInTranslationUnit() order Unfortunately, this is not as simple as it was implemented previously, and actually requires doing a merge sort. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204936 91177308-0d34-0410-b5e6-96231b3b80d8
* [C++11] Replace llvm::tie with std::tie.Benjamin Kramer2014-03-021-3/+2
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@202639 91177308-0d34-0410-b5e6-96231b3b80d8
* Refactor comment merging.Benjamin Kramer2013-09-281-61/+45
| | | | | | | | | | | - We scan for whitespace between comments anyways, remember any newlines seen along the way. - Use this newline number to decide whether two comments are adjacent. - Since the newline check is now free remove the caching and unused code. - Remove unnecessary boolean state from the comment list. - No behavioral change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191614 91177308-0d34-0410-b5e6-96231b3b80d8
* [Doc parsing] Provide diagnostics for unknown documentation Fariborz Jahanian2013-05-031-2/+4
| | | | | | | commands. // rdar://12381408 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181071 91177308-0d34-0410-b5e6-96231b3b80d8
* Comment parsing: -fparse-all-comments: recognize empty line commentsDmitri Gribenko2013-04-261-3/+5
| | | | | | | | | | In -fparse-all-comments mode empty '//' comments were recognized as RCK_Invalid, and were not merged with next and previous lines. Patch by Amin Shali. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@180625 91177308-0d34-0410-b5e6-96231b3b80d8
* Add an option to parse all comments as documentation commentsDmitri Gribenko2013-04-101-3/+4
| | | | | | | Patch by Amin Shali. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179180 91177308-0d34-0410-b5e6-96231b3b80d8
* Sort all of Clang's files under 'lib', and fix up the broken headersChandler Carruth2012-12-041-3/+3
| | | | | | | | | | | | | uncovered. This required manually correcting all of the incorrect main-module headers I could find, and running the new llvm/utils/sort_includes.py script over the files. I also manually added quite a few missing headers that were uncovered by shuffling the order or moving headers up to be main-module-headers. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169237 91177308-0d34-0410-b5e6-96231b3b80d8
* Move the 'find macro by spelling' infrastructure to the Preprocessor class andDmitri Gribenko2012-09-291-1/+3
| | | | | | | | use it to suggest appropriate macro for __attribute__((deprecated)) in -Wdocumentation-deprecated-sync. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164892 91177308-0d34-0410-b5e6-96231b3b80d8
* Comment AST: TableGen'ize all command lists in CommentCommandTraits.cpp.Dmitri Gribenko2012-09-101-7/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163540 91177308-0d34-0410-b5e6-96231b3b80d8
* RawCommentList: don't copy the whole new RawComment to LastComment each time.Dmitri Gribenko2012-09-091-16/+14
| | | | | | | We just need a single SourceLocation for previous comment end. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163482 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove the useless CommentOptions class.Dmitri Gribenko2012-08-311-3/+2
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162986 91177308-0d34-0410-b5e6-96231b3b80d8
* Merging consecutive comments: be more conservative.Dmitri Gribenko2012-08-281-8/+13
| | | | | | | Should fix part 2 of PR13374. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162723 91177308-0d34-0410-b5e6-96231b3b80d8
* Attaching comments to redeclarations: fix wrong assumptionsDmitri Gribenko2012-08-141-16/+5
| | | | | | | | | | | | | | | | | | | The reason for the recent fallout for "attaching comments to any redeclaration" change are two false assumptions: (1) a RawComment is attached to a single decl (not true for 'typedef struct X *Y' where we want the comment to be attached to both X and Y); (2) the whole redeclaration chain has only a single comment (obviously false, the user can put a separate comment for each redeclaration). To fix (1) I revert the part of the recent change where a 'Decl*' member was introduced to RawComment. Now ASTContext has a separate DenseMap for mapping 'Decl*' to 'FullComment*'. To fix (2) I just removed the test with this assumption. We might not parse every comment in redecl chain if we already parsed at least one. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161878 91177308-0d34-0410-b5e6-96231b3b80d8
* Attaching comments to declarations: find comment attached to any redeclarationDmitri Gribenko2012-08-111-1/+33
| | | | | | | | | Not only look for the comment near the declaration itself, but also walk the redeclaration chain: the previous declaration might have had a documentation comment. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161722 91177308-0d34-0410-b5e6-96231b3b80d8
* Comment parsing: extract TableGen'able pieces into new CommandTraits class.Dmitri Gribenko2012-08-091-2/+4
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161548 91177308-0d34-0410-b5e6-96231b3b80d8
* Implement resolving of HTML character references (named: &amp;, decimal: &#42;,Dmitri Gribenko2012-07-271-1/+7
| | | | | | | | | | hex: &#x1a;) during comment parsing. Now internal representation of plain text in comment AST does not contain character references, but the characters themselves. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160891 91177308-0d34-0410-b5e6-96231b3b80d8
* Enable comment parsing and semantic analysis to emit diagnostics. A fewDmitri Gribenko2012-07-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | diagnostics implemented -- see testcases. I created a new TableGen file for comment diagnostics, DiagnosticCommentKinds.td, because comment diagnostics don't logically fit into AST diagnostics file. But I don't feel strongly about it. This also implements support for self-closing HTML tags in comment lexer and parser (for example, <br />). In order to issue precise diagnostics CommentSema needs to know the declaration the comment is attached to. There is no easy way to find a decl by comment, so we match comments and decls in lockstep: after parsing one declgroup we check if we have any new, not yet attached comments. If we do -- then we do the usual comment-finding process. It is interesting that this automatically handles trailing comments. We pick up not only comments that precede the declaration, but also comments that *follow* the declaration -- thanks to the lookahead in the lexer: after parsing the declgroup we've consumed the semicolon and looked ahead through comments. Added -Wdocumentation-html flag for semantic HTML errors to allow the user to disable only HTML warnings (but not HTML parse errors, which we emit as warnings in -Wdocumentation). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160078 91177308-0d34-0410-b5e6-96231b3b80d8
* Don't store pointers into a std::vector (RawCommentList::Comments). AlthoughDmitri Gribenko2012-07-061-8/+7
| | | | | | | | | currently we take address of std::vector's contents only after we finished adding all comments (so no reallocation can happen), this will change in future. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159845 91177308-0d34-0410-b5e6-96231b3b80d8
* Renamed RawComment kinds to avoid name clash.Abramo Bagnara2012-07-041-11/+11
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159706 91177308-0d34-0410-b5e6-96231b3b80d8
* Add a new libclang completion API to get brief documentation comment that isDmitri Gribenko2012-07-021-3/+3
| | | | | | | | | | | | | | | | | | attached to a declaration in the completion string. Since extracting comments isn't free, a new code completion option is introduced. A new code completion option that enables including brief comments into CodeCompletionString should be a, err, code completion option. But because ASTUnit caches global declarations during parsing before even completion consumer is created, the option is duplicated as a translation unit option (in both libclang and ASTUnit, like the option to cache code completion results). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159539 91177308-0d34-0410-b5e6-96231b3b80d8
* Initialize RawComment::BriefTextValid in other constructor, too.Dmitri Gribenko2012-06-271-1/+2
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159253 91177308-0d34-0410-b5e6-96231b3b80d8
* Implement a lexer for structured comments.Dmitri Gribenko2012-06-261-0/+21
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159223 91177308-0d34-0410-b5e6-96231b3b80d8
* Handle include directive with comments. It turns out that in this case ↵Dmitri Gribenko2012-06-211-7/+9
| | | | | | comments are not coming in source order. Instead of trying to std::sort() comments (which can be costly), just remove comments that are not in order. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158940 91177308-0d34-0410-b5e6-96231b3b80d8
* VC9 does not like heterogenous compare function objects.Dmitri Gribenko2012-06-211-1/+1
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158936 91177308-0d34-0410-b5e6-96231b3b80d8
* RawCommentList::addComment: fix the assertion so it actually checks that new ↵Dmitri Gribenko2012-06-211-1/+3
| | | | | | comment is after the last one (change Comments[0] to Comments.back()), and handle the case of two consecutive comments, e.g. /** *//* */. There is already a testcase for that (but it didn't trigger the assert because the assert itself was wrong). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158882 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove unused ASTContext& arg in RawCommentList::addComment, as pointed out ↵Dmitri Gribenko2012-06-201-2/+1
| | | | | | by Chandler in commit message for r158807. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158845 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix a big layering violation introduced by r158771.Chandler Carruth2012-06-201-0/+207
That commit added a new library just to hold the RawCommentList. I've started a discussion on the commit thread about whether that is really meritted -- it certainly doesn't seem necessary at this stage. However, the immediate problem is that the AST library has a hard dependency on the Comment library, but the dependencies were set up completely backward. In addition to the layering violation, this had an unfortunate effect if scattering the Comments library dependency throughout the build system, but inconsistently so -- several parts of the CMake dependencies were missing and only showed up due to transitive deps or the fact that the target wasn't being built by tho bots. It turns out that the Comments library can't (currently) be a well formed layer *below* the AST library either, as it has an API that accepts an ASTContext. That parameter is currently unused, so maybe that was a mistake? Anyways, it really seems like this is logically part of the AST -- that's the whole point of the ASTContext providing access to it as far as I can tell -- so I've merged it into the AST library to solve the immediate layering violation problems and remove some of the churn from our library dependencies. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158807 91177308-0d34-0410-b5e6-96231b3b80d8