CommentParser.h revision 8d3ba23f2d9e6c87794d059412a0808c9cbacb25
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/CommentLexer.h"
18#include "clang/AST/Comment.h"
19#include "clang/AST/CommentSema.h"
20#include "llvm/Support/Allocator.h"
21
22namespace clang {
23namespace comments {
24
25/// Doxygen comment parser.
26class Parser {
27  Lexer &L;
28
29  Sema &S;
30
31  llvm::BumpPtrAllocator &Allocator;
32
33  template<typename T>
34  ArrayRef<T> copyArray(ArrayRef<T> Source) {
35    size_t Size = Source.size();
36    if (Size != 0) {
37      T *Mem = new (Allocator) T[Size];
38      std::copy(Source.begin(), Source.end(), Mem);
39      return llvm::makeArrayRef(Mem, Size);
40    } else
41      return llvm::makeArrayRef(static_cast<T *>(NULL), 0);
42  }
43
44  /// Current lookahead token.  We can safely assume that all tokens are from
45  /// a single source file.
46  Token Tok;
47
48  /// A stack of additional lookahead tokens.
49  SmallVector<Token, 8> MoreLATokens;
50
51  SourceLocation consumeToken() {
52    SourceLocation Loc = Tok.getLocation();
53    if (MoreLATokens.empty())
54      L.lex(Tok);
55    else {
56      Tok = MoreLATokens.back();
57      MoreLATokens.pop_back();
58    }
59    return Loc;
60  }
61
62  void putBack(const Token &OldTok) {
63    MoreLATokens.push_back(Tok);
64    Tok = OldTok;
65  }
66
67  void putBack(ArrayRef<Token> Toks) {
68    if (Toks.empty())
69      return;
70
71    MoreLATokens.push_back(Tok);
72    for (const Token *I = &Toks.back(),
73         *B = &Toks.front() + 1;
74         I != B; --I) {
75      MoreLATokens.push_back(*I);
76    }
77
78    Tok = Toks[0];
79  }
80
81public:
82  Parser(Lexer &L, Sema &S, llvm::BumpPtrAllocator &Allocator);
83
84  /// Parse arguments for \\param command.
85  ParamCommandComment *parseParamCommandArgs(
86                                    ParamCommandComment *PC,
87                                    TextTokenRetokenizer &Retokenizer);
88
89  BlockCommandComment *parseBlockCommandArgs(
90                                    BlockCommandComment *BC,
91                                    TextTokenRetokenizer &Retokenizer,
92                                    unsigned NumArgs);
93
94  BlockCommandComment *parseBlockCommand();
95  InlineCommandComment *parseInlineCommand();
96
97  HTMLOpenTagComment *parseHTMLOpenTag();
98  HTMLCloseTagComment *parseHTMLCloseTag();
99
100  BlockContentComment *parseParagraphOrBlockCommand();
101
102  VerbatimBlockComment *parseVerbatimBlock();
103  VerbatimLineComment *parseVerbatimLine();
104  BlockContentComment *parseBlockContent();
105  FullComment *parseFullComment();
106};
107
108} // end namespace comments
109} // end namespace clang
110
111#endif
112
113