CommentParser.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- CommentParser.h - Doxygen comment parser ---------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file defines the Doxygen comment parser.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_CLANG_AST_COMMENTPARSER_H
  18. #define LLVM_CLANG_AST_COMMENTPARSER_H
  19. #include "clang/AST/Comment.h"
  20. #include "clang/AST/CommentLexer.h"
  21. #include "clang/AST/CommentSema.h"
  22. #include "clang/Basic/Diagnostic.h"
  23. #include "llvm/Support/Allocator.h"
  24. namespace clang {
  25. class SourceManager;
  26. namespace comments {
  27. class CommandTraits;
  28. /// Doxygen comment parser.
  29. class Parser {
  30. Parser(const Parser &) = delete;
  31. void operator=(const Parser &) = delete;
  32. friend class TextTokenRetokenizer;
  33. Lexer &L;
  34. Sema &S;
  35. /// Allocator for anything that goes into AST nodes.
  36. llvm::BumpPtrAllocator &Allocator;
  37. /// Source manager for the comment being parsed.
  38. const SourceManager &SourceMgr;
  39. DiagnosticsEngine &Diags;
  40. DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) {
  41. return Diags.Report(Loc, DiagID);
  42. }
  43. const CommandTraits &Traits;
  44. /// Current lookahead token. We can safely assume that all tokens are from
  45. /// a single source file.
  46. Token Tok;
  47. /// A stack of additional lookahead tokens.
  48. SmallVector<Token, 8> MoreLATokens;
  49. void consumeToken() {
  50. if (MoreLATokens.empty())
  51. L.lex(Tok);
  52. else
  53. Tok = MoreLATokens.pop_back_val();
  54. }
  55. void putBack(const Token &OldTok) {
  56. MoreLATokens.push_back(Tok);
  57. Tok = OldTok;
  58. }
  59. void putBack(ArrayRef<Token> Toks) {
  60. if (Toks.empty())
  61. return;
  62. MoreLATokens.push_back(Tok);
  63. MoreLATokens.append(Toks.rbegin(), std::prev(Toks.rend()));
  64. Tok = Toks[0];
  65. }
  66. bool isTokBlockCommand() {
  67. return (Tok.is(tok::backslash_command) || Tok.is(tok::at_command)) &&
  68. Traits.getCommandInfo(Tok.getCommandID())->IsBlockCommand;
  69. }
  70. public:
  71. Parser(Lexer &L, Sema &S, llvm::BumpPtrAllocator &Allocator,
  72. const SourceManager &SourceMgr, DiagnosticsEngine &Diags,
  73. const CommandTraits &Traits);
  74. /// Parse arguments for \\param command.
  75. void parseParamCommandArgs(ParamCommandComment *PC,
  76. TextTokenRetokenizer &Retokenizer);
  77. /// Parse arguments for \\tparam command.
  78. void parseTParamCommandArgs(TParamCommandComment *TPC,
  79. TextTokenRetokenizer &Retokenizer);
  80. ArrayRef<Comment::Argument>
  81. parseCommandArgs(TextTokenRetokenizer &Retokenizer, unsigned NumArgs);
  82. BlockCommandComment *parseBlockCommand();
  83. InlineCommandComment *parseInlineCommand();
  84. HTMLStartTagComment *parseHTMLStartTag();
  85. HTMLEndTagComment *parseHTMLEndTag();
  86. BlockContentComment *parseParagraphOrBlockCommand();
  87. VerbatimBlockComment *parseVerbatimBlock();
  88. VerbatimLineComment *parseVerbatimLine();
  89. BlockContentComment *parseBlockContent();
  90. FullComment *parseFullComment();
  91. };
  92. } // end namespace comments
  93. } // end namespace clang
  94. #endif
  95. #ifdef __GNUC__
  96. #pragma GCC diagnostic pop
  97. #endif