clang 23.0.0git
CommentSema.h
Go to the documentation of this file.
1//===--- CommentSema.h - Doxygen comment semantic analysis ------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the semantic analysis class for Doxygen comments.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_AST_COMMENTSEMA_H
14#define LLVM_CLANG_AST_COMMENTSEMA_H
15
16#include "clang/AST/Comment.h"
19#include "llvm/ADT/ArrayRef.h"
20#include "llvm/ADT/StringMap.h"
21#include "llvm/ADT/StringRef.h"
22#include "llvm/Support/Allocator.h"
23
24namespace clang {
25class Decl;
26class SourceMgr;
27class Preprocessor;
28
29namespace comments {
30class CommandTraits;
31
32class Sema {
33 Sema(const Sema &) = delete;
34 void operator=(const Sema &) = delete;
35
36 /// Allocator for AST nodes.
37 llvm::BumpPtrAllocator &Allocator;
38
39 /// Source manager for the comment being parsed.
40 const SourceManager &SourceMgr;
41
42 DiagnosticsEngine &Diags;
43
44 CommandTraits &Traits;
45
46 const Preprocessor *PP;
47
48 /// Information about the declaration this comment is attached to.
49 DeclInfo *ThisDeclInfo;
50
51 /// Comment AST nodes that correspond to parameter names in
52 /// \c TemplateParameters.
53 ///
54 /// Contains a valid value if \c DeclInfo->IsFilled is true.
55 llvm::StringMap<TParamCommandComment *> TemplateParameterDocs;
56
57 /// AST node for the \command and its aliases.
58 const BlockCommandComment *BriefCommand;
59
60 /// AST node for the \\headerfile command.
61 const BlockCommandComment *HeaderfileCommand;
62
63 DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) {
64 return Diags.Report(Loc, DiagID);
65 }
66
67 /// A stack of HTML tags that are currently open (not matched with closing
68 /// tags).
70
71public:
72 Sema(llvm::BumpPtrAllocator &Allocator, const SourceManager &SourceMgr,
73 DiagnosticsEngine &Diags, CommandTraits &Traits,
74 const Preprocessor *PP);
75
76 void setDecl(const Decl *D);
77
78 /// Returns a copy of array, owned by Sema's allocator.
79 template<typename T>
81 if (!Source.empty())
82 return Source.copy(Allocator);
83 return {};
84 }
85
88
90 SourceLocation LocEnd,
91 unsigned CommandID,
92 CommandMarkerKind CommandMarker);
93
96
98 ParagraphComment *Paragraph);
99
101 SourceLocation LocEnd,
102 unsigned CommandID,
103 CommandMarkerKind CommandMarker);
104
106 SourceLocation ArgLocBegin,
107 SourceLocation ArgLocEnd,
108 StringRef Arg);
109
111 SourceLocation ArgLocBegin,
112 SourceLocation ArgLocEnd,
113 StringRef Arg);
114
116 ParagraphComment *Paragraph);
117
119 SourceLocation LocEnd,
120 unsigned CommandID,
121 CommandMarkerKind CommandMarker);
122
124 SourceLocation ArgLocBegin,
125 SourceLocation ArgLocEnd,
126 StringRef Arg);
127
129 ParagraphComment *Paragraph);
130
132 SourceLocation CommandLocEnd,
133 unsigned CommandID,
134 CommandMarkerKind CommandMarker,
136
138 SourceLocation LocEnd,
139 StringRef CommandName,
140 CommandMarkerKind CommandMarker);
141
143 SourceLocation LocEnd,
144 unsigned CommandID,
145 CommandMarkerKind CommandMarker);
146
148 SourceLocation LocEnd,
149 StringRef Text);
150
152 unsigned CommandID);
153
155 StringRef Text);
156
158 SourceLocation CloseNameLocBegin,
159 StringRef CloseName,
161
163 unsigned CommandID,
164 SourceLocation TextBegin,
165 StringRef Text);
166
168 StringRef TagName);
169
172 SourceLocation GreaterLoc,
173 bool IsSelfClosing);
174
176 SourceLocation LocEnd,
177 StringRef TagName);
178
180
181private:
182 void checkBlockCommandEmptyParagraph(BlockCommandComment *Command);
183
184 void checkReturnsCommand(const BlockCommandComment *Command);
185
186 /// Emit diagnostics about duplicate block commands that should be
187 /// used only once per comment, e.g., \and \\returns.
188 void checkBlockCommandDuplicate(const BlockCommandComment *Command);
189
190 void checkDeprecatedCommand(const BlockCommandComment *Comment);
191
192 void checkFunctionDeclVerbatimLine(const BlockCommandComment *Comment);
193
194 void checkContainerDeclVerbatimLine(const BlockCommandComment *Comment);
195
196 void checkContainerDecl(const BlockCommandComment *Comment);
197
198 /// Resolve parameter names to parameter indexes in function declaration.
199 /// Emit diagnostics about unknown parameters.
200 void resolveParamCommandIndexes(const FullComment *FC);
201
202 /// \returns \c true if the declaration that this comment is attached to
203 /// is a pointer to function/method/block type or has such a type.
204 bool involvesFunctionType();
205
206 bool isFunctionDecl();
207 bool isAnyFunctionDecl();
208
209 /// \returns \c true if declaration that this comment is attached to declares
210 /// a function pointer.
211 bool isFunctionPointerVarDecl();
213 bool isObjCMethodDecl();
214 bool isObjCPropertyDecl();
215 bool isTemplateOrSpecialization();
216 bool isExplicitFunctionTemplateInstantiation();
217 bool isRecordLikeDecl();
218 bool isClassOrStructDecl();
219 /// \return \c true if the declaration that this comment is attached to
220 /// declares either struct, class or tag typedef.
221 bool isClassOrStructOrTagTypedefDecl();
222 bool isUnionDecl();
223 bool isObjCInterfaceDecl();
224 bool isObjCProtocolDecl();
225 bool isClassTemplateDecl();
226 bool isFunctionTemplateDecl();
227
228 ArrayRef<const ParmVarDecl *> getParamVars();
229
230 /// Extract all important semantic information from
231 /// \c ThisDeclInfo->ThisDecl into \c ThisDeclInfo members.
232 void inspectThisDecl();
233
234 /// Returns index of a function parameter with a given name.
235 unsigned resolveParmVarReference(StringRef Name,
237
238 /// Returns index of a function parameter with the name closest to a given
239 /// typo.
240 unsigned correctTypoInParmVarReference(StringRef Typo,
242
243 bool resolveTParamReference(StringRef Name,
244 const TemplateParameterList *TemplateParameters,
245 SmallVectorImpl<unsigned> *Position);
246
247 StringRef correctTypoInTParamReference(
248 StringRef Typo,
249 const TemplateParameterList *TemplateParameters);
250
251 InlineCommandRenderKind getInlineCommandRenderKind(StringRef Name) const;
252};
253
254} // end namespace comments
255} // end namespace clang
256
257#endif
258
Defines the Diagnostic-related interfaces.
Defines the clang::SourceLocation class and associated facilities.
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
A little helper class used to produce diagnostics.
Concrete class used by the front-end to report problems and issues.
Definition Diagnostic.h:234
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Encodes a location in the source.
This class handles loading and caching of source files into memory.
Stores a list of template parameters for a TemplateDecl and its derived classes.
A command that has zero or more word-like arguments (number of word-like arguments depends on command...
Definition Comment.h:616
This class provides information about commands that can be used in comments.
Any part of the comment.
Definition Comment.h:66
A full comment attached to a declaration, contains block content.
Definition Comment.h:1097
An opening HTML tag with attributes.
Definition Comment.h:445
A command with word-like arguments that is considered inline content.
Definition Comment.h:341
Inline content (contained within a block).
Definition Comment.h:271
A single paragraph that contains inline content.
Definition Comment.h:567
Doxygen \param command.
Definition Comment.h:723
FullComment * actOnFullComment(ArrayRef< BlockContentComment * > Blocks)
void actOnParamCommandDirectionArg(ParamCommandComment *Command, SourceLocation ArgLocBegin, SourceLocation ArgLocEnd, StringRef Arg)
InlineCommandComment * actOnInlineCommand(SourceLocation CommandLocBegin, SourceLocation CommandLocEnd, unsigned CommandID, CommandMarkerKind CommandMarker, ArrayRef< Comment::Argument > Args)
TParamCommandComment * actOnTParamCommandStart(SourceLocation LocBegin, SourceLocation LocEnd, unsigned CommandID, CommandMarkerKind CommandMarker)
void actOnTParamCommandFinish(TParamCommandComment *Command, ParagraphComment *Paragraph)
void actOnBlockCommandFinish(BlockCommandComment *Command, ParagraphComment *Paragraph)
TextComment * actOnText(SourceLocation LocBegin, SourceLocation LocEnd, StringRef Text)
void actOnBlockCommandArgs(BlockCommandComment *Command, ArrayRef< BlockCommandComment::Argument > Args)
BlockCommandComment * actOnBlockCommandStart(SourceLocation LocBegin, SourceLocation LocEnd, unsigned CommandID, CommandMarkerKind CommandMarker)
void actOnParamCommandParamNameArg(ParamCommandComment *Command, SourceLocation ArgLocBegin, SourceLocation ArgLocEnd, StringRef Arg)
HTMLEndTagComment * actOnHTMLEndTag(SourceLocation LocBegin, SourceLocation LocEnd, StringRef TagName)
VerbatimLineComment * actOnVerbatimLine(SourceLocation LocBegin, unsigned CommandID, SourceLocation TextBegin, StringRef Text)
void actOnVerbatimBlockFinish(VerbatimBlockComment *Block, SourceLocation CloseNameLocBegin, StringRef CloseName, ArrayRef< VerbatimBlockLineComment * > Lines)
VerbatimBlockLineComment * actOnVerbatimBlockLine(SourceLocation Loc, StringRef Text)
void actOnParamCommandFinish(ParamCommandComment *Command, ParagraphComment *Paragraph)
ArrayRef< T > copyArray(ArrayRef< T > Source)
Returns a copy of array, owned by Sema's allocator.
Definition CommentSema.h:80
HTMLStartTagComment * actOnHTMLStartTagStart(SourceLocation LocBegin, StringRef TagName)
void actOnHTMLStartTagFinish(HTMLStartTagComment *Tag, ArrayRef< HTMLStartTagComment::Attribute > Attrs, SourceLocation GreaterLoc, bool IsSelfClosing)
ParamCommandComment * actOnParamCommandStart(SourceLocation LocBegin, SourceLocation LocEnd, unsigned CommandID, CommandMarkerKind CommandMarker)
VerbatimBlockComment * actOnVerbatimBlockStart(SourceLocation Loc, unsigned CommandID)
void actOnTParamCommandParamNameArg(TParamCommandComment *Command, SourceLocation ArgLocBegin, SourceLocation ArgLocEnd, StringRef Arg)
void setDecl(const Decl *D)
InlineContentComment * actOnUnknownCommand(SourceLocation LocBegin, SourceLocation LocEnd, StringRef CommandName, CommandMarkerKind CommandMarker)
ParagraphComment * actOnParagraphComment(ArrayRef< InlineContentComment * > Content)
Doxygen \tparam command, describes a template parameter.
Definition Comment.h:805
A verbatim block command (e.
Definition Comment.h:891
A line of text contained in a verbatim block.
Definition Comment.h:866
A verbatim line command.
Definition Comment.h:942
InlineCommandRenderKind
The most appropriate rendering mode for this command, chosen on command semantics in Doxygen.
Definition Comment.h:332
CommandMarkerKind
Describes the syntax that was used in a documentation command.
Definition Comment.h:39
The JSON file list parser is used to communicate input to InstallAPI.
bool isFunctionOrMethodVariadic(const Decl *D)
Definition Attr.h:112
Information about the declaration, useful to clients of FullComment.
Definition Comment.h:974