xref: /freebsd/contrib/llvm-project/clang/include/clang/AST/CommentParser.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
10b57cec5SDimitry Andric //===--- CommentParser.h - Doxygen comment parser ---------------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric //  This file defines the Doxygen comment parser.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #ifndef LLVM_CLANG_AST_COMMENTPARSER_H
140b57cec5SDimitry Andric #define LLVM_CLANG_AST_COMMENTPARSER_H
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric #include "clang/AST/Comment.h"
170b57cec5SDimitry Andric #include "clang/AST/CommentLexer.h"
180b57cec5SDimitry Andric #include "clang/AST/CommentSema.h"
190b57cec5SDimitry Andric #include "clang/Basic/Diagnostic.h"
200b57cec5SDimitry Andric #include "llvm/Support/Allocator.h"
210b57cec5SDimitry Andric 
220b57cec5SDimitry Andric namespace clang {
230b57cec5SDimitry Andric class SourceManager;
240b57cec5SDimitry Andric 
250b57cec5SDimitry Andric namespace comments {
260b57cec5SDimitry Andric class CommandTraits;
270b57cec5SDimitry Andric 
280b57cec5SDimitry Andric /// Doxygen comment parser.
290b57cec5SDimitry Andric class Parser {
300b57cec5SDimitry Andric   Parser(const Parser &) = delete;
310b57cec5SDimitry Andric   void operator=(const Parser &) = delete;
320b57cec5SDimitry Andric 
330b57cec5SDimitry Andric   friend class TextTokenRetokenizer;
340b57cec5SDimitry Andric 
350b57cec5SDimitry Andric   Lexer &L;
360b57cec5SDimitry Andric 
370b57cec5SDimitry Andric   Sema &S;
380b57cec5SDimitry Andric 
390b57cec5SDimitry Andric   /// Allocator for anything that goes into AST nodes.
400b57cec5SDimitry Andric   llvm::BumpPtrAllocator &Allocator;
410b57cec5SDimitry Andric 
420b57cec5SDimitry Andric   /// Source manager for the comment being parsed.
430b57cec5SDimitry Andric   const SourceManager &SourceMgr;
440b57cec5SDimitry Andric 
450b57cec5SDimitry Andric   DiagnosticsEngine &Diags;
460b57cec5SDimitry Andric 
Diag(SourceLocation Loc,unsigned DiagID)470b57cec5SDimitry Andric   DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) {
480b57cec5SDimitry Andric     return Diags.Report(Loc, DiagID);
490b57cec5SDimitry Andric   }
500b57cec5SDimitry Andric 
510b57cec5SDimitry Andric   const CommandTraits &Traits;
520b57cec5SDimitry Andric 
530b57cec5SDimitry Andric   /// Current lookahead token.  We can safely assume that all tokens are from
540b57cec5SDimitry Andric   /// a single source file.
550b57cec5SDimitry Andric   Token Tok;
560b57cec5SDimitry Andric 
570b57cec5SDimitry Andric   /// A stack of additional lookahead tokens.
580b57cec5SDimitry Andric   SmallVector<Token, 8> MoreLATokens;
590b57cec5SDimitry Andric 
consumeToken()600b57cec5SDimitry Andric   void consumeToken() {
610b57cec5SDimitry Andric     if (MoreLATokens.empty())
620b57cec5SDimitry Andric       L.lex(Tok);
630b57cec5SDimitry Andric     else
640b57cec5SDimitry Andric       Tok = MoreLATokens.pop_back_val();
650b57cec5SDimitry Andric   }
660b57cec5SDimitry Andric 
putBack(const Token & OldTok)670b57cec5SDimitry Andric   void putBack(const Token &OldTok) {
680b57cec5SDimitry Andric     MoreLATokens.push_back(Tok);
690b57cec5SDimitry Andric     Tok = OldTok;
700b57cec5SDimitry Andric   }
710b57cec5SDimitry Andric 
putBack(ArrayRef<Token> Toks)720b57cec5SDimitry Andric   void putBack(ArrayRef<Token> Toks) {
730b57cec5SDimitry Andric     if (Toks.empty())
740b57cec5SDimitry Andric       return;
750b57cec5SDimitry Andric 
760b57cec5SDimitry Andric     MoreLATokens.push_back(Tok);
770b57cec5SDimitry Andric     MoreLATokens.append(Toks.rbegin(), std::prev(Toks.rend()));
780b57cec5SDimitry Andric 
790b57cec5SDimitry Andric     Tok = Toks[0];
800b57cec5SDimitry Andric   }
810b57cec5SDimitry Andric 
isTokBlockCommand()820b57cec5SDimitry Andric   bool isTokBlockCommand() {
830b57cec5SDimitry Andric     return (Tok.is(tok::backslash_command) || Tok.is(tok::at_command)) &&
840b57cec5SDimitry Andric            Traits.getCommandInfo(Tok.getCommandID())->IsBlockCommand;
850b57cec5SDimitry Andric   }
860b57cec5SDimitry Andric 
870b57cec5SDimitry Andric public:
880b57cec5SDimitry Andric   Parser(Lexer &L, Sema &S, llvm::BumpPtrAllocator &Allocator,
890b57cec5SDimitry Andric          const SourceManager &SourceMgr, DiagnosticsEngine &Diags,
900b57cec5SDimitry Andric          const CommandTraits &Traits);
910b57cec5SDimitry Andric 
920b57cec5SDimitry Andric   /// Parse arguments for \\param command.
930b57cec5SDimitry Andric   void parseParamCommandArgs(ParamCommandComment *PC,
940b57cec5SDimitry Andric                              TextTokenRetokenizer &Retokenizer);
950b57cec5SDimitry Andric 
960b57cec5SDimitry Andric   /// Parse arguments for \\tparam command.
970b57cec5SDimitry Andric   void parseTParamCommandArgs(TParamCommandComment *TPC,
980b57cec5SDimitry Andric                               TextTokenRetokenizer &Retokenizer);
990b57cec5SDimitry Andric 
10081ad6265SDimitry Andric   ArrayRef<Comment::Argument>
10181ad6265SDimitry Andric   parseCommandArgs(TextTokenRetokenizer &Retokenizer, unsigned NumArgs);
1020b57cec5SDimitry Andric 
103*0fca6ea1SDimitry Andric   /// Parse arguments for \throws command supported args are in form of class
104*0fca6ea1SDimitry Andric   /// or template.
105*0fca6ea1SDimitry Andric   ArrayRef<Comment::Argument>
106*0fca6ea1SDimitry Andric   parseThrowCommandArgs(TextTokenRetokenizer &Retokenizer, unsigned NumArgs);
107*0fca6ea1SDimitry Andric 
108*0fca6ea1SDimitry Andric   ArrayRef<Comment::Argument>
109*0fca6ea1SDimitry Andric   parseParCommandArgs(TextTokenRetokenizer &Retokenizer, unsigned NumArgs);
110*0fca6ea1SDimitry Andric 
1110b57cec5SDimitry Andric   BlockCommandComment *parseBlockCommand();
1120b57cec5SDimitry Andric   InlineCommandComment *parseInlineCommand();
1130b57cec5SDimitry Andric 
1140b57cec5SDimitry Andric   HTMLStartTagComment *parseHTMLStartTag();
1150b57cec5SDimitry Andric   HTMLEndTagComment *parseHTMLEndTag();
1160b57cec5SDimitry Andric 
1170b57cec5SDimitry Andric   BlockContentComment *parseParagraphOrBlockCommand();
1180b57cec5SDimitry Andric 
1190b57cec5SDimitry Andric   VerbatimBlockComment *parseVerbatimBlock();
1200b57cec5SDimitry Andric   VerbatimLineComment *parseVerbatimLine();
1210b57cec5SDimitry Andric   BlockContentComment *parseBlockContent();
1220b57cec5SDimitry Andric   FullComment *parseFullComment();
1230b57cec5SDimitry Andric };
1240b57cec5SDimitry Andric 
1250b57cec5SDimitry Andric } // end namespace comments
1260b57cec5SDimitry Andric } // end namespace clang
1270b57cec5SDimitry Andric 
1280b57cec5SDimitry Andric #endif
129