CommentParser.h revision 3f38bf2d441fac379c427f86153fbb0cb41256c6
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 Lexer &L; 31 32 Sema &S; 33 34 /// Allocator for anything that goes into AST nodes. 35 llvm::BumpPtrAllocator &Allocator; 36 37 /// Source manager for the comment being parsed. 38 const SourceManager &SourceMgr; 39 40 template<typename T> 41 ArrayRef<T> copyArray(ArrayRef<T> Source) { 42 size_t Size = Source.size(); 43 if (Size != 0) { 44 T *Mem = Allocator.Allocate<T>(Size); 45 std::uninitialized_copy(Source.begin(), Source.end(), Mem); 46 return llvm::makeArrayRef(Mem, Size); 47 } else 48 return llvm::makeArrayRef(static_cast<T *>(NULL), 0); 49 } 50 51 DiagnosticsEngine &Diags; 52 53 DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) { 54 return Diags.Report(Loc, DiagID); 55 } 56 57 /// Current lookahead token. We can safely assume that all tokens are from 58 /// a single source file. 59 Token Tok; 60 61 /// A stack of additional lookahead tokens. 62 SmallVector<Token, 8> MoreLATokens; 63 64 SourceLocation consumeToken() { 65 SourceLocation Loc = Tok.getLocation(); 66 if (MoreLATokens.empty()) 67 L.lex(Tok); 68 else { 69 Tok = MoreLATokens.back(); 70 MoreLATokens.pop_back(); 71 } 72 return Loc; 73 } 74 75 void putBack(const Token &OldTok) { 76 MoreLATokens.push_back(Tok); 77 Tok = OldTok; 78 } 79 80 void putBack(ArrayRef<Token> Toks) { 81 if (Toks.empty()) 82 return; 83 84 MoreLATokens.push_back(Tok); 85 for (const Token *I = &Toks.back(), 86 *B = &Toks.front() + 1; 87 I != B; --I) { 88 MoreLATokens.push_back(*I); 89 } 90 91 Tok = Toks[0]; 92 } 93 94public: 95 Parser(Lexer &L, Sema &S, llvm::BumpPtrAllocator &Allocator, 96 const SourceManager &SourceMgr, DiagnosticsEngine &Diags); 97 98 /// Parse arguments for \\param command. 99 ParamCommandComment *parseParamCommandArgs( 100 ParamCommandComment *PC, 101 TextTokenRetokenizer &Retokenizer); 102 103 BlockCommandComment *parseBlockCommandArgs( 104 BlockCommandComment *BC, 105 TextTokenRetokenizer &Retokenizer, 106 unsigned NumArgs); 107 108 BlockCommandComment *parseBlockCommand(); 109 InlineCommandComment *parseInlineCommand(); 110 111 HTMLStartTagComment *parseHTMLStartTag(); 112 HTMLEndTagComment *parseHTMLEndTag(); 113 114 BlockContentComment *parseParagraphOrBlockCommand(); 115 116 VerbatimBlockComment *parseVerbatimBlock(); 117 VerbatimLineComment *parseVerbatimLine(); 118 BlockContentComment *parseBlockContent(); 119 FullComment *parseFullComment(); 120}; 121 122} // end namespace comments 123} // end namespace clang 124 125#endif 126 127