clang  6.0.0svn
CommentParser.h
Go to the documentation of this file.
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_COMMENTPARSER_H
15 #define LLVM_CLANG_AST_COMMENTPARSER_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 
23 namespace clang {
24 class SourceManager;
25 
26 namespace comments {
27 class CommandTraits;
28 
29 /// Doxygen comment parser.
30 class Parser {
31  Parser(const Parser &) = delete;
32  void operator=(const Parser &) = delete;
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.pop_back_val();
66  }
67 
68  void putBack(const Token &OldTok) {
69  MoreLATokens.push_back(Tok);
70  Tok = OldTok;
71  }
72 
73  void putBack(ArrayRef<Token> Toks) {
74  if (Toks.empty())
75  return;
76 
77  MoreLATokens.push_back(Tok);
78  MoreLATokens.append(Toks.rbegin(), std::prev(Toks.rend()));
79 
80  Tok = Toks[0];
81  }
82 
83  bool isTokBlockCommand() {
84  return (Tok.is(tok::backslash_command) || Tok.is(tok::at_command)) &&
85  Traits.getCommandInfo(Tok.getCommandID())->IsBlockCommand;
86  }
87 
88 public:
89  Parser(Lexer &L, Sema &S, llvm::BumpPtrAllocator &Allocator,
90  const SourceManager &SourceMgr, DiagnosticsEngine &Diags,
91  const CommandTraits &Traits);
92 
93  /// Parse arguments for \\param command.
95  TextTokenRetokenizer &Retokenizer);
96 
97  /// Parse arguments for \\tparam command.
99  TextTokenRetokenizer &Retokenizer);
100 
102  TextTokenRetokenizer &Retokenizer,
103  unsigned NumArgs);
104 
107 
110 
112 
117 };
118 
119 } // end namespace comments
120 } // end namespace clang
121 
122 #endif
123 
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
VerbatimLineComment * parseVerbatimLine()
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1207
A command with word-like arguments that is considered inline content.
Definition: Comment.h:303
InlineCommandComment * parseInlineCommand()
A verbatim line command.
Definition: Comment.h:949
const FormatToken & Tok
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:147
void parseParamCommandArgs(ParamCommandComment *PC, TextTokenRetokenizer &Retokenizer)
Parse arguments for \param command.
Defines the Diagnostic-related interfaces.
A verbatim block command (e.
Definition: Comment.h:897
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:955
BlockContentComment * parseParagraphOrBlockCommand()
A command that has zero or more word-like arguments (number of word-like arguments depends on command...
Definition: Comment.h:602
void parseTParamCommandArgs(TParamCommandComment *TPC, TextTokenRetokenizer &Retokenizer)
Parse arguments for \tparam command.
An opening HTML tag with attributes.
Definition: Comment.h:419
bool is(tok::TokenKind K) const LLVM_READONLY
Definition: CommentLexer.h:93
This class provides information about commands that can be used in comments.
Re-lexes a sequence of tok::text tokens.
Encodes a location in the source.
Comment lexer.
Definition: CommentLexer.h:221
const CommandInfo * getCommandInfo(StringRef Name) const
Block content (contains inline content).
Definition: Comment.h:536
HTMLEndTagComment * parseHTMLEndTag()
FullComment * parseFullComment()
A closing HTML tag.
Definition: Comment.h:513
Doxygen \tparam command, describes a template parameter.
Definition: Comment.h:805
BlockCommandComment * parseBlockCommand()
Dataflow Directional Tag Classes.
BlockContentComment * parseBlockContent()
unsigned getCommandID() const LLVM_READONLY
Definition: CommentLexer.h:121
HTMLStartTagComment * parseHTMLStartTag()
VerbatimBlockComment * parseVerbatimBlock()
Comment token.
Definition: CommentLexer.h:56
Doxygen comment parser.
Definition: CommentParser.h:30
void parseBlockCommandArgs(BlockCommandComment *BC, TextTokenRetokenizer &Retokenizer, unsigned NumArgs)
Doxygen \param command.
Definition: Comment.h:717
This class handles loading and caching of source files into memory.
A full comment attached to a declaration, contains block content.
Definition: Comment.h:1097