diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AST/Comment.cpp | 64 | ||||
-rw-r--r-- | lib/AST/CommentSema.cpp | 89 |
2 files changed, 86 insertions, 67 deletions
diff --git a/lib/AST/Comment.cpp b/lib/AST/Comment.cpp index 82dbed47f8..15b80c6455 100644 --- a/lib/AST/Comment.cpp +++ b/lib/AST/Comment.cpp @@ -8,6 +8,9 @@ //===----------------------------------------------------------------------===// #include "clang/AST/Comment.h" +#include "clang/AST/Decl.h" +#include "clang/AST/DeclObjC.h" +#include "clang/AST/DeclTemplate.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" @@ -134,5 +137,66 @@ const char *ParamCommandComment::getDirectionAsString(PassDirection D) { llvm_unreachable("unknown PassDirection"); } +void DeclInfo::fill() { + assert(!IsFilled); + + // Set defaults. + IsFunctionDecl = false; + IsTemplateDecl = false; + IsTemplateSpecialization = false; + IsTemplatePartialSpecialization = false; + IsInstanceMethod = false; + IsClassMethod = false; + ParamVars = ArrayRef<const ParmVarDecl *>(); + TemplateParameters = NULL; + + if (!ThisDecl) { + // Defaults are OK. + } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(ThisDecl)) { + IsFunctionDecl = true; + ParamVars = ArrayRef<const ParmVarDecl *>(FD->param_begin(), + FD->getNumParams()); + unsigned NumLists = FD->getNumTemplateParameterLists(); + if (NumLists != 0) { + IsTemplateDecl = true; + IsTemplateSpecialization = true; + TemplateParameters = + FD->getTemplateParameterList(NumLists - 1); + } + + if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { + IsInstanceMethod = MD->isInstance(); + IsClassMethod = !IsInstanceMethod; + } + } else if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(ThisDecl)) { + IsFunctionDecl = true; + ParamVars = ArrayRef<const ParmVarDecl *>(MD->param_begin(), + MD->param_size()); + IsInstanceMethod = MD->isInstanceMethod(); + IsClassMethod = !IsInstanceMethod; + } else if (const FunctionTemplateDecl *FTD = + dyn_cast<FunctionTemplateDecl>(ThisDecl)) { + IsFunctionDecl = true; + IsTemplateDecl = true; + const FunctionDecl *FD = FTD->getTemplatedDecl(); + ParamVars = ArrayRef<const ParmVarDecl *>(FD->param_begin(), + FD->getNumParams()); + TemplateParameters = FTD->getTemplateParameters(); + } else if (const ClassTemplateDecl *CTD = + dyn_cast<ClassTemplateDecl>(ThisDecl)) { + IsTemplateDecl = true; + TemplateParameters = CTD->getTemplateParameters(); + } else if (const ClassTemplatePartialSpecializationDecl *CTPSD = + dyn_cast<ClassTemplatePartialSpecializationDecl>(ThisDecl)) { + IsTemplateDecl = true; + IsTemplatePartialSpecialization = true; + TemplateParameters = CTPSD->getTemplateParameters(); + } else if (isa<ClassTemplateSpecializationDecl>(ThisDecl)) { + IsTemplateDecl = true; + IsTemplateSpecialization = true; + } + IsFilled = true; +} + } // end namespace comments } // end namespace clang diff --git a/lib/AST/CommentSema.cpp b/lib/AST/CommentSema.cpp index 7b42c861d3..3566091655 100644 --- a/lib/AST/CommentSema.cpp +++ b/lib/AST/CommentSema.cpp @@ -10,7 +10,6 @@ #include "clang/AST/CommentSema.h" #include "clang/AST/CommentDiagnostic.h" #include "clang/AST/Decl.h" -#include "clang/AST/DeclObjC.h" #include "clang/AST/DeclTemplate.h" #include "clang/Basic/SourceManager.h" #include "llvm/ADT/StringSwitch.h" @@ -20,12 +19,16 @@ namespace comments { Sema::Sema(llvm::BumpPtrAllocator &Allocator, const SourceManager &SourceMgr, DiagnosticsEngine &Diags) : - Allocator(Allocator), SourceMgr(SourceMgr), Diags(Diags), ThisDecl(NULL), - IsThisDeclInspected(false) { + Allocator(Allocator), SourceMgr(SourceMgr), Diags(Diags), + ThisDeclInfo(NULL) { } void Sema::setDecl(const Decl *D) { - ThisDecl = D; + if (!D) + return; + + ThisDeclInfo = new (Allocator) DeclInfo; + ThisDeclInfo->ThisDecl = D; } ParagraphComment *Sema::actOnParagraphComment( @@ -234,6 +237,8 @@ TParamCommandComment *Sema::actOnTParamCommandParamNameArg( return Command; } + const TemplateParameterList *TemplateParameters = + ThisDeclInfo->TemplateParameters; SmallVector<unsigned, 2> Position; if (resolveTParamReference(Arg, TemplateParameters, &Position)) { Command->setPosition(copyArray(llvm::makeArrayRef(Position))); @@ -449,7 +454,7 @@ HTMLEndTagComment *Sema::actOnHTMLEndTag(SourceLocation LocBegin, FullComment *Sema::actOnFullComment( ArrayRef<BlockContentComment *> Blocks) { - return new (Allocator) FullComment(Blocks); + return new (Allocator) FullComment(Blocks, ThisDeclInfo); } void Sema::checkBlockCommandEmptyParagraph(BlockCommandComment *Command) { @@ -467,80 +472,30 @@ void Sema::checkBlockCommandEmptyParagraph(BlockCommandComment *Command) { } bool Sema::isFunctionDecl() { - if (!IsThisDeclInspected) + if (!ThisDeclInfo) + return false; + if (!ThisDeclInfo->IsFilled) inspectThisDecl(); - return IsFunctionDecl; + return ThisDeclInfo->IsFunctionDecl; } bool Sema::isTemplateDecl() { - if (!IsThisDeclInspected) + if (!ThisDeclInfo) + return false; + if (!ThisDeclInfo->IsFilled) inspectThisDecl(); - return IsTemplateDecl; + return ThisDeclInfo->IsTemplateDecl; } ArrayRef<const ParmVarDecl *> Sema::getParamVars() { - if (!IsThisDeclInspected) + if (!ThisDeclInfo->IsFilled) inspectThisDecl(); - return ParamVars; + return ThisDeclInfo->ParamVars; } void Sema::inspectThisDecl() { - assert(!IsThisDeclInspected); - if (!ThisDecl) { - IsFunctionDecl = false; - IsTemplateDecl = false; - ParamVars = ArrayRef<const ParmVarDecl *>(); - TemplateParameters = NULL; - } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(ThisDecl)) { - IsFunctionDecl = true; - IsTemplateDecl = false; - ParamVars = ArrayRef<const ParmVarDecl *>(FD->param_begin(), - FD->getNumParams()); - TemplateParameters = NULL; - unsigned NumLists = FD->getNumTemplateParameterLists(); - if (NumLists != 0) { - IsTemplateDecl = true; - TemplateParameters = FD->getTemplateParameterList(NumLists - 1); - } - } else if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(ThisDecl)) { - IsFunctionDecl = true; - IsTemplateDecl = false; - ParamVars = ArrayRef<const ParmVarDecl *>(MD->param_begin(), - MD->param_size()); - TemplateParameters = NULL; - } else if (const FunctionTemplateDecl *FTD = - dyn_cast<FunctionTemplateDecl>(ThisDecl)) { - IsFunctionDecl = true; - IsTemplateDecl = true; - const FunctionDecl *FD = FTD->getTemplatedDecl(); - ParamVars = ArrayRef<const ParmVarDecl *>(FD->param_begin(), - FD->getNumParams()); - TemplateParameters = FTD->getTemplateParameters(); - } else if (const ClassTemplateDecl *CTD = - dyn_cast<ClassTemplateDecl>(ThisDecl)) { - IsFunctionDecl = false; - IsTemplateDecl = true; - ParamVars = ArrayRef<const ParmVarDecl *>(); - TemplateParameters = CTD->getTemplateParameters(); - } else if (const ClassTemplatePartialSpecializationDecl *CTPSD = - dyn_cast<ClassTemplatePartialSpecializationDecl>(ThisDecl)) { - IsFunctionDecl = false; - IsTemplateDecl = true; - ParamVars = ArrayRef<const ParmVarDecl *>(); - TemplateParameters = CTPSD->getTemplateParameters(); - } else if (isa<ClassTemplateSpecializationDecl>(ThisDecl)) { - IsFunctionDecl = false; - IsTemplateDecl = true; - ParamVars = ArrayRef<const ParmVarDecl *>(); - TemplateParameters = NULL; - } else { - IsFunctionDecl = false; - IsTemplateDecl = false; - ParamVars = ArrayRef<const ParmVarDecl *>(); - TemplateParameters = NULL; - } - ParamVarDocs.resize(ParamVars.size(), NULL); - IsThisDeclInspected = true; + ThisDeclInfo->fill(); + ParamVarDocs.resize(ThisDeclInfo->ParamVars.size(), NULL); } unsigned Sema::resolveParmVarReference(StringRef Name, |