clang 19.0.0git
CommentParser.h
Go to the documentation of this file.
1//===--- CommentParser.h - Doxygen comment parser ---------------*- 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 Doxygen comment parser.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_AST_COMMENTPARSER_H
14#define LLVM_CLANG_AST_COMMENTPARSER_H
15
16#include "clang/AST/Comment.h"
20#include "llvm/Support/Allocator.h"
21
22namespace clang {
23class SourceManager;
24
25namespace comments {
26class CommandTraits;
27
28/// Doxygen comment parser.
29class Parser {
30 Parser(const Parser &) = delete;
31 void operator=(const Parser &) = delete;
32
34
35 Lexer &L;
36
37 Sema &S;
38
39 /// Allocator for anything that goes into AST nodes.
40 llvm::BumpPtrAllocator &Allocator;
41
42 /// Source manager for the comment being parsed.
43 const SourceManager &SourceMgr;
44
45 DiagnosticsEngine &Diags;
46
47 DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) {
48 return Diags.Report(Loc, DiagID);
49 }
50
51 const CommandTraits &Traits;
52
53 /// Current lookahead token. We can safely assume that all tokens are from
54 /// a single source file.
55 Token Tok;
56
57 /// A stack of additional lookahead tokens.
58 SmallVector<Token, 8> MoreLATokens;
59
60 void consumeToken() {
61 if (MoreLATokens.empty())
62 L.lex(Tok);
63 else
64 Tok = MoreLATokens.pop_back_val();
65 }
66
67 void putBack(const Token &OldTok) {
68 MoreLATokens.push_back(Tok);
69 Tok = OldTok;
70 }
71
72 void putBack(ArrayRef<Token> Toks) {
73 if (Toks.empty())
74 return;
75
76 MoreLATokens.push_back(Tok);
77 MoreLATokens.append(Toks.rbegin(), std::prev(Toks.rend()));
78
79 Tok = Toks[0];
80 }
81
82 bool isTokBlockCommand() {
83 return (Tok.is(tok::backslash_command) || Tok.is(tok::at_command)) &&
85 }
86
87public:
88 Parser(Lexer &L, Sema &S, llvm::BumpPtrAllocator &Allocator,
89 const SourceManager &SourceMgr, DiagnosticsEngine &Diags,
90 const CommandTraits &Traits);
91
92 /// Parse arguments for \\param command.
93 void parseParamCommandArgs(ParamCommandComment *PC,
94 TextTokenRetokenizer &Retokenizer);
95
96 /// Parse arguments for \\tparam command.
97 void parseTParamCommandArgs(TParamCommandComment *TPC,
98 TextTokenRetokenizer &Retokenizer);
99
100 ArrayRef<Comment::Argument>
101 parseCommandArgs(TextTokenRetokenizer &Retokenizer, unsigned NumArgs);
102
103 BlockCommandComment *parseBlockCommand();
104 InlineCommandComment *parseInlineCommand();
105
106 HTMLStartTagComment *parseHTMLStartTag();
107 HTMLEndTagComment *parseHTMLEndTag();
108
109 BlockContentComment *parseParagraphOrBlockCommand();
110
111 VerbatimBlockComment *parseVerbatimBlock();
112 VerbatimLineComment *parseVerbatimLine();
113 BlockContentComment *parseBlockContent();
114 FullComment *parseFullComment();
115};
116
117} // end namespace comments
118} // end namespace clang
119
120#endif
121
Defines the Diagnostic-related interfaces.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:1271
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:192
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1547
Encodes a location in the source.
This class handles loading and caching of source files into memory.
Token - This structure provides full information about a lexed token.
Definition: Token.h:36
This class provides information about commands that can be used in comments.
const CommandInfo * getCommandInfo(StringRef Name) const
Doxygen comment parser.
Definition: CommentParser.h:29
VerbatimLineComment * parseVerbatimLine()
InlineCommandComment * parseInlineCommand()
ArrayRef< Comment::Argument > parseCommandArgs(TextTokenRetokenizer &Retokenizer, unsigned NumArgs)
void parseTParamCommandArgs(TParamCommandComment *TPC, TextTokenRetokenizer &Retokenizer)
Parse arguments for \tparam command.
BlockContentComment * parseParagraphOrBlockCommand()
HTMLEndTagComment * parseHTMLEndTag()
VerbatimBlockComment * parseVerbatimBlock()
BlockCommandComment * parseBlockCommand()
BlockContentComment * parseBlockContent()
HTMLStartTagComment * parseHTMLStartTag()
FullComment * parseFullComment()
friend class TextTokenRetokenizer
Definition: CommentParser.h:33
void parseParamCommandArgs(ParamCommandComment *PC, TextTokenRetokenizer &Retokenizer)
Parse arguments for \param command.
Re-lexes a sequence of tok::text tokens.
Comment token.
Definition: CommentLexer.h:55
unsigned getCommandID() const LLVM_READONLY
Definition: CommentLexer.h:120
bool is(tok::TokenKind K) const LLVM_READONLY
Definition: CommentLexer.h:92
The JSON file list parser is used to communicate input to InstallAPI.
unsigned IsBlockCommand
True if this command is a block command (of any kind).