clang API Documentation
00001 //===--- CommentSema.h - Doxygen comment semantic analysis ------*- 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 semantic analysis class for Doxygen comments. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_CLANG_AST_COMMENTSEMA_H 00015 #define LLVM_CLANG_AST_COMMENTSEMA_H 00016 00017 #include "clang/AST/Comment.h" 00018 #include "clang/Basic/Diagnostic.h" 00019 #include "clang/Basic/SourceLocation.h" 00020 #include "llvm/ADT/ArrayRef.h" 00021 #include "llvm/ADT/StringMap.h" 00022 #include "llvm/ADT/StringRef.h" 00023 #include "llvm/Support/Allocator.h" 00024 00025 namespace clang { 00026 class Decl; 00027 class SourceMgr; 00028 class Preprocessor; 00029 00030 namespace comments { 00031 class CommandTraits; 00032 00033 class Sema { 00034 Sema(const Sema &) LLVM_DELETED_FUNCTION; 00035 void operator=(const Sema &) LLVM_DELETED_FUNCTION; 00036 00037 /// Allocator for AST nodes. 00038 llvm::BumpPtrAllocator &Allocator; 00039 00040 /// Source manager for the comment being parsed. 00041 const SourceManager &SourceMgr; 00042 00043 DiagnosticsEngine &Diags; 00044 00045 CommandTraits &Traits; 00046 00047 const Preprocessor *PP; 00048 00049 /// Information about the declaration this comment is attached to. 00050 DeclInfo *ThisDeclInfo; 00051 00052 /// Comment AST nodes that correspond to parameter names in 00053 /// \c TemplateParameters. 00054 /// 00055 /// Contains a valid value if \c DeclInfo->IsFilled is true. 00056 llvm::StringMap<TParamCommandComment *> TemplateParameterDocs; 00057 00058 /// AST node for the \\brief command and its aliases. 00059 const BlockCommandComment *BriefCommand; 00060 00061 /// AST node for the \\headerfile command. 00062 const BlockCommandComment *HeaderfileCommand; 00063 00064 DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) { 00065 return Diags.Report(Loc, DiagID); 00066 } 00067 00068 /// A stack of HTML tags that are currently open (not matched with closing 00069 /// tags). 00070 SmallVector<HTMLStartTagComment *, 8> HTMLOpenTags; 00071 00072 public: 00073 Sema(llvm::BumpPtrAllocator &Allocator, const SourceManager &SourceMgr, 00074 DiagnosticsEngine &Diags, CommandTraits &Traits, 00075 const Preprocessor *PP); 00076 00077 void setDecl(const Decl *D); 00078 00079 /// Returns a copy of array, owned by Sema's allocator. 00080 template<typename T> 00081 ArrayRef<T> copyArray(ArrayRef<T> Source) { 00082 size_t Size = Source.size(); 00083 if (Size != 0) { 00084 T *Mem = Allocator.Allocate<T>(Size); 00085 std::uninitialized_copy(Source.begin(), Source.end(), Mem); 00086 return llvm::makeArrayRef(Mem, Size); 00087 } 00088 return None; 00089 } 00090 00091 ParagraphComment *actOnParagraphComment( 00092 ArrayRef<InlineContentComment *> Content); 00093 00094 BlockCommandComment *actOnBlockCommandStart(SourceLocation LocBegin, 00095 SourceLocation LocEnd, 00096 unsigned CommandID, 00097 CommandMarkerKind CommandMarker); 00098 00099 void actOnBlockCommandArgs(BlockCommandComment *Command, 00100 ArrayRef<BlockCommandComment::Argument> Args); 00101 00102 void actOnBlockCommandFinish(BlockCommandComment *Command, 00103 ParagraphComment *Paragraph); 00104 00105 ParamCommandComment *actOnParamCommandStart(SourceLocation LocBegin, 00106 SourceLocation LocEnd, 00107 unsigned CommandID, 00108 CommandMarkerKind CommandMarker); 00109 00110 void actOnParamCommandDirectionArg(ParamCommandComment *Command, 00111 SourceLocation ArgLocBegin, 00112 SourceLocation ArgLocEnd, 00113 StringRef Arg); 00114 00115 void actOnParamCommandParamNameArg(ParamCommandComment *Command, 00116 SourceLocation ArgLocBegin, 00117 SourceLocation ArgLocEnd, 00118 StringRef Arg); 00119 00120 void actOnParamCommandFinish(ParamCommandComment *Command, 00121 ParagraphComment *Paragraph); 00122 00123 TParamCommandComment *actOnTParamCommandStart(SourceLocation LocBegin, 00124 SourceLocation LocEnd, 00125 unsigned CommandID, 00126 CommandMarkerKind CommandMarker); 00127 00128 void actOnTParamCommandParamNameArg(TParamCommandComment *Command, 00129 SourceLocation ArgLocBegin, 00130 SourceLocation ArgLocEnd, 00131 StringRef Arg); 00132 00133 void actOnTParamCommandFinish(TParamCommandComment *Command, 00134 ParagraphComment *Paragraph); 00135 00136 InlineCommandComment *actOnInlineCommand(SourceLocation CommandLocBegin, 00137 SourceLocation CommandLocEnd, 00138 unsigned CommandID); 00139 00140 InlineCommandComment *actOnInlineCommand(SourceLocation CommandLocBegin, 00141 SourceLocation CommandLocEnd, 00142 unsigned CommandID, 00143 SourceLocation ArgLocBegin, 00144 SourceLocation ArgLocEnd, 00145 StringRef Arg); 00146 00147 InlineContentComment *actOnUnknownCommand(SourceLocation LocBegin, 00148 SourceLocation LocEnd, 00149 StringRef CommandName); 00150 00151 InlineContentComment *actOnUnknownCommand(SourceLocation LocBegin, 00152 SourceLocation LocEnd, 00153 unsigned CommandID); 00154 00155 TextComment *actOnText(SourceLocation LocBegin, 00156 SourceLocation LocEnd, 00157 StringRef Text); 00158 00159 VerbatimBlockComment *actOnVerbatimBlockStart(SourceLocation Loc, 00160 unsigned CommandID); 00161 00162 VerbatimBlockLineComment *actOnVerbatimBlockLine(SourceLocation Loc, 00163 StringRef Text); 00164 00165 void actOnVerbatimBlockFinish(VerbatimBlockComment *Block, 00166 SourceLocation CloseNameLocBegin, 00167 StringRef CloseName, 00168 ArrayRef<VerbatimBlockLineComment *> Lines); 00169 00170 VerbatimLineComment *actOnVerbatimLine(SourceLocation LocBegin, 00171 unsigned CommandID, 00172 SourceLocation TextBegin, 00173 StringRef Text); 00174 00175 HTMLStartTagComment *actOnHTMLStartTagStart(SourceLocation LocBegin, 00176 StringRef TagName); 00177 00178 void actOnHTMLStartTagFinish(HTMLStartTagComment *Tag, 00179 ArrayRef<HTMLStartTagComment::Attribute> Attrs, 00180 SourceLocation GreaterLoc, 00181 bool IsSelfClosing); 00182 00183 HTMLEndTagComment *actOnHTMLEndTag(SourceLocation LocBegin, 00184 SourceLocation LocEnd, 00185 StringRef TagName); 00186 00187 FullComment *actOnFullComment(ArrayRef<BlockContentComment *> Blocks); 00188 00189 void checkBlockCommandEmptyParagraph(BlockCommandComment *Command); 00190 00191 void checkReturnsCommand(const BlockCommandComment *Command); 00192 00193 /// Emit diagnostics about duplicate block commands that should be 00194 /// used only once per comment, e.g., \\brief and \\returns. 00195 void checkBlockCommandDuplicate(const BlockCommandComment *Command); 00196 00197 void checkDeprecatedCommand(const BlockCommandComment *Comment); 00198 00199 void checkFunctionDeclVerbatimLine(const BlockCommandComment *Comment); 00200 00201 void checkContainerDeclVerbatimLine(const BlockCommandComment *Comment); 00202 00203 void checkContainerDecl(const BlockCommandComment *Comment); 00204 00205 /// Resolve parameter names to parameter indexes in function declaration. 00206 /// Emit diagnostics about unknown parametrs. 00207 void resolveParamCommandIndexes(const FullComment *FC); 00208 00209 bool isFunctionDecl(); 00210 bool isAnyFunctionDecl(); 00211 00212 /// \returns \c true if declaration that this comment is attached to declares 00213 /// a function pointer. 00214 bool isFunctionPointerVarDecl(); 00215 bool isFunctionOrMethodVariadic(); 00216 bool isObjCMethodDecl(); 00217 bool isObjCPropertyDecl(); 00218 bool isTemplateOrSpecialization(); 00219 bool isRecordLikeDecl(); 00220 bool isClassOrStructDecl(); 00221 bool isUnionDecl(); 00222 bool isObjCInterfaceDecl(); 00223 bool isObjCProtocolDecl(); 00224 bool isClassTemplateDecl(); 00225 bool isFunctionTemplateDecl(); 00226 00227 ArrayRef<const ParmVarDecl *> getParamVars(); 00228 00229 /// Extract all important semantic information from 00230 /// \c ThisDeclInfo->ThisDecl into \c ThisDeclInfo members. 00231 void inspectThisDecl(); 00232 00233 /// Returns index of a function parameter with a given name. 00234 unsigned resolveParmVarReference(StringRef Name, 00235 ArrayRef<const ParmVarDecl *> ParamVars); 00236 00237 /// Returns index of a function parameter with the name closest to a given 00238 /// typo. 00239 unsigned correctTypoInParmVarReference(StringRef Typo, 00240 ArrayRef<const ParmVarDecl *> ParamVars); 00241 00242 bool resolveTParamReference(StringRef Name, 00243 const TemplateParameterList *TemplateParameters, 00244 SmallVectorImpl<unsigned> *Position); 00245 00246 StringRef correctTypoInTParamReference( 00247 StringRef Typo, 00248 const TemplateParameterList *TemplateParameters); 00249 00250 InlineCommandComment::RenderKind 00251 getInlineCommandRenderKind(StringRef Name) const; 00252 }; 00253 00254 } // end namespace comments 00255 } // end namespace clang 00256 00257 #endif 00258