clang API Documentation

CommentParser.h
Go to the documentation of this file.
00001 //===--- CommentParser.h - Doxygen comment parser ---------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 //  This file defines the Doxygen comment parser.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_CLANG_AST_COMMENTPARSER_H
00015 #define LLVM_CLANG_AST_COMMENTPARSER_H
00016 
00017 #include "clang/AST/Comment.h"
00018 #include "clang/AST/CommentLexer.h"
00019 #include "clang/AST/CommentSema.h"
00020 #include "clang/Basic/Diagnostic.h"
00021 #include "llvm/Support/Allocator.h"
00022 
00023 namespace clang {
00024 class SourceManager;
00025 
00026 namespace comments {
00027 class CommandTraits;
00028 
00029 /// Doxygen comment parser.
00030 class Parser {
00031   Parser(const Parser &) LLVM_DELETED_FUNCTION;
00032   void operator=(const Parser &) LLVM_DELETED_FUNCTION;
00033 
00034   friend class TextTokenRetokenizer;
00035 
00036   Lexer &L;
00037 
00038   Sema &S;
00039 
00040   /// Allocator for anything that goes into AST nodes.
00041   llvm::BumpPtrAllocator &Allocator;
00042 
00043   /// Source manager for the comment being parsed.
00044   const SourceManager &SourceMgr;
00045 
00046   DiagnosticsEngine &Diags;
00047 
00048   DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) {
00049     return Diags.Report(Loc, DiagID);
00050   }
00051 
00052   const CommandTraits &Traits;
00053 
00054   /// Current lookahead token.  We can safely assume that all tokens are from
00055   /// a single source file.
00056   Token Tok;
00057 
00058   /// A stack of additional lookahead tokens.
00059   SmallVector<Token, 8> MoreLATokens;
00060 
00061   void consumeToken() {
00062     if (MoreLATokens.empty())
00063       L.lex(Tok);
00064     else
00065       Tok = MoreLATokens.pop_back_val();
00066   }
00067 
00068   void putBack(const Token &OldTok) {
00069     MoreLATokens.push_back(Tok);
00070     Tok = OldTok;
00071   }
00072 
00073   void putBack(ArrayRef<Token> Toks) {
00074     if (Toks.empty())
00075       return;
00076 
00077     MoreLATokens.push_back(Tok);
00078     for (const Token *I = &Toks.back(),
00079          *B = &Toks.front();
00080          I != B; --I) {
00081       MoreLATokens.push_back(*I);
00082     }
00083 
00084     Tok = Toks[0];
00085   }
00086 
00087   bool isTokBlockCommand() {
00088     return (Tok.is(tok::backslash_command) || Tok.is(tok::at_command)) &&
00089            Traits.getCommandInfo(Tok.getCommandID())->IsBlockCommand;
00090   }
00091 
00092 public:
00093   Parser(Lexer &L, Sema &S, llvm::BumpPtrAllocator &Allocator,
00094          const SourceManager &SourceMgr, DiagnosticsEngine &Diags,
00095          const CommandTraits &Traits);
00096 
00097   /// Parse arguments for \\param command.
00098   void parseParamCommandArgs(ParamCommandComment *PC,
00099                              TextTokenRetokenizer &Retokenizer);
00100 
00101   /// Parse arguments for \\tparam command.
00102   void parseTParamCommandArgs(TParamCommandComment *TPC,
00103                               TextTokenRetokenizer &Retokenizer);
00104 
00105   void parseBlockCommandArgs(BlockCommandComment *BC,
00106                              TextTokenRetokenizer &Retokenizer,
00107                              unsigned NumArgs);
00108 
00109   BlockCommandComment *parseBlockCommand();
00110   InlineCommandComment *parseInlineCommand();
00111 
00112   HTMLStartTagComment *parseHTMLStartTag();
00113   HTMLEndTagComment *parseHTMLEndTag();
00114 
00115   BlockContentComment *parseParagraphOrBlockCommand();
00116 
00117   VerbatimBlockComment *parseVerbatimBlock();
00118   VerbatimLineComment *parseVerbatimLine();
00119   BlockContentComment *parseBlockContent();
00120   FullComment *parseFullComment();
00121 };
00122 
00123 } // end namespace comments
00124 } // end namespace clang
00125 
00126 #endif
00127