CommentParser.h revision 6f36366c85dc81d67d70efdeeea4cfc382053feb
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/Basic/Diagnostic.h"
18#include "clang/AST/CommentLexer.h"
19#include "clang/AST/Comment.h"
20#include "clang/AST/CommentSema.h"
21#include "llvm/Support/Allocator.h"
22
23namespace clang {
24class SourceManager;
25
26namespace comments {
27
28/// Doxygen comment parser.
29class Parser {
30  Parser(const Parser&);         // DO NOT IMPLEMENT
31  void operator=(const Parser&); // DO NOT IMPLEMENT
32
33  friend class TextTokenRetokenizer;
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  template<typename T>
46  ArrayRef<T> copyArray(ArrayRef<T> Source) {
47    size_t Size = Source.size();
48    if (Size != 0) {
49      T *Mem = Allocator.Allocate<T>(Size);
50      std::uninitialized_copy(Source.begin(), Source.end(), Mem);
51      return llvm::makeArrayRef(Mem, Size);
52    } else
53      return llvm::makeArrayRef(static_cast<T *>(NULL), 0);
54  }
55
56  DiagnosticsEngine &Diags;
57
58  DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) {
59    return Diags.Report(Loc, DiagID);
60  }
61
62  /// Current lookahead token.  We can safely assume that all tokens are from
63  /// a single source file.
64  Token Tok;
65
66  /// A stack of additional lookahead tokens.
67  SmallVector<Token, 8> MoreLATokens;
68
69  SourceLocation consumeToken() {
70    SourceLocation Loc = Tok.getLocation();
71    if (MoreLATokens.empty())
72      L.lex(Tok);
73    else {
74      Tok = MoreLATokens.back();
75      MoreLATokens.pop_back();
76    }
77    return Loc;
78  }
79
80  void putBack(const Token &OldTok) {
81    MoreLATokens.push_back(Tok);
82    Tok = OldTok;
83  }
84
85  void putBack(ArrayRef<Token> Toks) {
86    if (Toks.empty())
87      return;
88
89    MoreLATokens.push_back(Tok);
90    for (const Token *I = &Toks.back(),
91         *B = &Toks.front();
92         I != B; --I) {
93      MoreLATokens.push_back(*I);
94    }
95
96    Tok = Toks[0];
97  }
98
99public:
100  Parser(Lexer &L, Sema &S, llvm::BumpPtrAllocator &Allocator,
101         const SourceManager &SourceMgr, DiagnosticsEngine &Diags);
102
103  /// Parse arguments for \\param command.
104  ParamCommandComment *parseParamCommandArgs(
105                                    ParamCommandComment *PC,
106                                    TextTokenRetokenizer &Retokenizer);
107
108  BlockCommandComment *parseBlockCommandArgs(
109                                    BlockCommandComment *BC,
110                                    TextTokenRetokenizer &Retokenizer,
111                                    unsigned NumArgs);
112
113  BlockCommandComment *parseBlockCommand();
114  InlineCommandComment *parseInlineCommand();
115
116  HTMLStartTagComment *parseHTMLStartTag();
117  HTMLEndTagComment *parseHTMLEndTag();
118
119  BlockContentComment *parseParagraphOrBlockCommand();
120
121  VerbatimBlockComment *parseVerbatimBlock();
122  VerbatimLineComment *parseVerbatimLine();
123  BlockContentComment *parseBlockContent();
124  FullComment *parseFullComment();
125};
126
127} // end namespace comments
128} // end namespace clang
129
130#endif
131
132