CommentSema.h revision 3d986980bd02594b1a5aa7b9f9f68d201621ced7
1//===--- CommentSema.h - Doxygen comment semantic analysis ------*- 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 semantic analysis class for Doxygen comments. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_CLANG_AST_COMMENT_SEMA_H 15#define LLVM_CLANG_AST_COMMENT_SEMA_H 16 17#include "clang/Basic/Diagnostic.h" 18#include "clang/Basic/SourceLocation.h" 19#include "clang/AST/Comment.h" 20#include "llvm/ADT/ArrayRef.h" 21#include "llvm/ADT/StringRef.h" 22#include "llvm/Support/Allocator.h" 23 24namespace clang { 25class Decl; 26class FunctionDecl; 27class ParmVarDecl; 28class SourceMgr; 29 30namespace comments { 31 32class Sema { 33 /// Allocator for AST nodes. 34 llvm::BumpPtrAllocator &Allocator; 35 36 /// Source manager for the comment being parsed. 37 const SourceManager &SourceMgr; 38 39 DiagnosticsEngine &Diags; 40 41 const Decl *ThisDecl; 42 43 DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) { 44 return Diags.Report(Loc, DiagID); 45 } 46 47 /// A stack of HTML tags that are currently open (not matched with closing 48 /// tags). 49 SmallVector<HTMLOpenTagComment *, 8> HTMLOpenTags; 50 51public: 52 Sema(llvm::BumpPtrAllocator &Allocator, const SourceManager &SourceMgr, 53 DiagnosticsEngine &Diags); 54 55 void setDecl(const Decl *D); 56 57 ParagraphComment *actOnParagraphComment( 58 ArrayRef<InlineContentComment *> Content); 59 60 BlockCommandComment *actOnBlockCommandStart(SourceLocation LocBegin, 61 SourceLocation LocEnd, 62 StringRef Name); 63 64 BlockCommandComment *actOnBlockCommandArgs( 65 BlockCommandComment *Command, 66 ArrayRef<BlockCommandComment::Argument> Args); 67 68 BlockCommandComment *actOnBlockCommandFinish(BlockCommandComment *Command, 69 ParagraphComment *Paragraph); 70 71 ParamCommandComment *actOnParamCommandStart(SourceLocation LocBegin, 72 SourceLocation LocEnd, 73 StringRef Name); 74 75 ParamCommandComment *actOnParamCommandDirectionArg( 76 ParamCommandComment *Command, 77 SourceLocation ArgLocBegin, 78 SourceLocation ArgLocEnd, 79 StringRef Arg); 80 81 ParamCommandComment *actOnParamCommandParamNameArg( 82 ParamCommandComment *Command, 83 SourceLocation ArgLocBegin, 84 SourceLocation ArgLocEnd, 85 StringRef Arg); 86 87 ParamCommandComment *actOnParamCommandFinish(ParamCommandComment *Command, 88 ParagraphComment *Paragraph); 89 90 InlineCommandComment *actOnInlineCommand(SourceLocation CommandLocBegin, 91 SourceLocation CommandLocEnd, 92 StringRef CommandName); 93 94 InlineCommandComment *actOnInlineCommand(SourceLocation CommandLocBegin, 95 SourceLocation CommandLocEnd, 96 StringRef CommandName, 97 SourceLocation ArgLocBegin, 98 SourceLocation ArgLocEnd, 99 StringRef Arg); 100 101 InlineContentComment *actOnUnknownCommand(SourceLocation LocBegin, 102 SourceLocation LocEnd, 103 StringRef Name); 104 105 TextComment *actOnText(SourceLocation LocBegin, 106 SourceLocation LocEnd, 107 StringRef Text); 108 109 VerbatimBlockComment *actOnVerbatimBlockStart(SourceLocation Loc, 110 StringRef Name); 111 112 VerbatimBlockLineComment *actOnVerbatimBlockLine(SourceLocation Loc, 113 StringRef Text); 114 115 VerbatimBlockComment *actOnVerbatimBlockFinish( 116 VerbatimBlockComment *Block, 117 SourceLocation CloseNameLocBegin, 118 StringRef CloseName, 119 ArrayRef<VerbatimBlockLineComment *> Lines); 120 121 VerbatimLineComment *actOnVerbatimLine(SourceLocation LocBegin, 122 StringRef Name, 123 SourceLocation TextBegin, 124 StringRef Text); 125 126 HTMLOpenTagComment *actOnHTMLOpenTagStart(SourceLocation LocBegin, 127 StringRef TagName); 128 129 HTMLOpenTagComment *actOnHTMLOpenTagFinish( 130 HTMLOpenTagComment *Tag, 131 ArrayRef<HTMLOpenTagComment::Attribute> Attrs, 132 SourceLocation GreaterLoc, 133 bool IsSelfClosing); 134 135 HTMLCloseTagComment *actOnHTMLCloseTag(SourceLocation LocBegin, 136 SourceLocation LocEnd, 137 StringRef TagName); 138 139 FullComment *actOnFullComment(ArrayRef<BlockContentComment *> Blocks); 140 141 void checkBlockCommandEmptyParagraph(BlockCommandComment *Command); 142 143 /// Returns index of a function parameter with a given name. 144 unsigned resolveParmVarReference(StringRef Name, 145 const ParmVarDecl * const *ParamVars, 146 unsigned NumParams); 147 148 /// Returns index of a function parameter with the name closest to a given 149 /// typo. 150 unsigned correctTypoInParmVarReference(StringRef Typo, 151 const ParmVarDecl * const *ParamVars, 152 unsigned NumParams); 153 154 bool isBlockCommand(StringRef Name); 155 bool isParamCommand(StringRef Name); 156 unsigned getBlockCommandNumArgs(StringRef Name); 157 158 bool isInlineCommand(StringRef Name); 159 160 bool isHTMLCloseTagOptional(StringRef Name); 161 bool isHTMLCloseTagForbidden(StringRef Name); 162}; 163 164} // end namespace comments 165} // end namespace clang 166 167#endif 168 169