CommentParser.h revision 30a2e16f6c27f888dd11eba6bbbae1e980078fcb
1//===--- CommentParser.h - Doxygen comment parser ---------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10//  This file defines the Doxygen comment parser.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_AST_COMMENT_PARSER_H
15#define LLVM_CLANG_AST_COMMENT_PARSER_H
16
17#include "clang/AST/Comment.h"
18#include "clang/AST/CommentLexer.h"
19#include "clang/AST/CommentSema.h"
20#include "clang/Basic/Diagnostic.h"
21#include "llvm/Support/Allocator.h"
22
23namespace clang {
24class SourceManager;
25
26namespace comments {
27class CommandTraits;
28
29/// Doxygen comment parser.
30class Parser {
31  Parser(const Parser &) LLVM_DELETED_FUNCTION;
32  void operator=(const Parser &) LLVM_DELETED_FUNCTION;
33
34  friend class TextTokenRetokenizer;
35
36  Lexer &L;
37
38  Sema &S;
39
40  /// Allocator for anything that goes into AST nodes.
41  llvm::BumpPtrAllocator &Allocator;
42
43  /// Source manager for the comment being parsed.
44  const SourceManager &SourceMgr;
45
46  DiagnosticsEngine &Diags;
47
48  DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) {
49    return Diags.Report(Loc, DiagID);
50  }
51
52  const CommandTraits &Traits;
53
54  /// Current lookahead token.  We can safely assume that all tokens are from
55  /// a single source file.
56  Token Tok;
57
58  /// A stack of additional lookahead tokens.
59  SmallVector<Token, 8> MoreLATokens;
60
61  void consumeToken() {
62    if (MoreLATokens.empty())
63      L.lex(Tok);
64    else {
65      Tok = MoreLATokens.back();
66      MoreLATokens.pop_back();
67    }
68  }
69
70  void putBack(const Token &OldTok) {
71    MoreLATokens.push_back(Tok);
72    Tok = OldTok;
73  }
74
75  void putBack(ArrayRef<Token> Toks) {
76    if (Toks.empty())
77      return;
78
79    MoreLATokens.push_back(Tok);
80    for (const Token *I = &Toks.back(),
81         *B = &Toks.front();
82         I != B; --I) {
83      MoreLATokens.push_back(*I);
84    }
85
86    Tok = Toks[0];
87  }
88
89public:
90  Parser(Lexer &L, Sema &S, llvm::BumpPtrAllocator &Allocator,
91         const SourceManager &SourceMgr, DiagnosticsEngine &Diags,
92         const CommandTraits &Traits);
93
94  /// Parse arguments for \\param command.
95  void parseParamCommandArgs(ParamCommandComment *PC,
96                             TextTokenRetokenizer &Retokenizer);
97
98  /// Parse arguments for \\tparam command.
99  void parseTParamCommandArgs(TParamCommandComment *TPC,
100                              TextTokenRetokenizer &Retokenizer);
101
102  void parseBlockCommandArgs(BlockCommandComment *BC,
103                             TextTokenRetokenizer &Retokenizer,
104                             unsigned NumArgs);
105
106  BlockCommandComment *parseBlockCommand();
107  InlineCommandComment *parseInlineCommand();
108
109  HTMLStartTagComment *parseHTMLStartTag();
110  HTMLEndTagComment *parseHTMLEndTag();
111
112  BlockContentComment *parseParagraphOrBlockCommand();
113
114  VerbatimBlockComment *parseVerbatimBlock();
115  VerbatimLineComment *parseVerbatimLine();
116  BlockContentComment *parseBlockContent();
117  FullComment *parseFullComment();
118};
119
120} // end namespace comments
121} // end namespace clang
122
123#endif
124
125