2012-07-06 08:28:32 +08:00
|
|
|
//===--- Comment.cpp - Comment AST node implementation --------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/AST/Comment.h"
|
2012-08-02 07:08:09 +08:00
|
|
|
#include "clang/AST/Decl.h"
|
|
|
|
#include "clang/AST/DeclObjC.h"
|
|
|
|
#include "clang/AST/DeclTemplate.h"
|
2012-07-06 08:28:32 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2012-07-19 00:30:42 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2012-07-06 08:28:32 +08:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace comments {
|
|
|
|
|
|
|
|
const char *Comment::getCommentKindName() const {
|
|
|
|
switch (getCommentKind()) {
|
|
|
|
case NoCommentKind: return "NoCommentKind";
|
|
|
|
#define ABSTRACT_COMMENT(COMMENT)
|
|
|
|
#define COMMENT(CLASS, PARENT) \
|
|
|
|
case CLASS##Kind: \
|
|
|
|
return #CLASS;
|
|
|
|
#include "clang/AST/CommentNodes.inc"
|
|
|
|
#undef COMMENT
|
|
|
|
#undef ABSTRACT_COMMENT
|
|
|
|
}
|
|
|
|
llvm_unreachable("Unknown comment kind!");
|
|
|
|
}
|
|
|
|
|
2012-07-19 00:30:42 +08:00
|
|
|
void Comment::dump() const {
|
|
|
|
// It is important that Comment::dump() is defined in a different TU than
|
|
|
|
// Comment::dump(raw_ostream, SourceManager). If both functions were defined
|
|
|
|
// in CommentDumper.cpp, that object file would be removed by linker because
|
|
|
|
// none of its functions are referenced by other object files, despite the
|
|
|
|
// LLVM_ATTRIBUTE_USED.
|
|
|
|
dump(llvm::errs(), NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Comment::dump(SourceManager &SM) const {
|
|
|
|
dump(llvm::errs(), &SM);
|
|
|
|
}
|
|
|
|
|
2012-07-06 08:28:32 +08:00
|
|
|
namespace {
|
|
|
|
struct good {};
|
|
|
|
struct bad {};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
good implements_child_begin_end(Comment::child_iterator (T::*)() const) {
|
|
|
|
return good();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bad implements_child_begin_end(
|
|
|
|
Comment::child_iterator (Comment::*)() const) {
|
|
|
|
return bad();
|
|
|
|
}
|
|
|
|
|
|
|
|
#define ASSERT_IMPLEMENTS_child_begin(function) \
|
|
|
|
(void) sizeof(good(implements_child_begin_end(function)))
|
|
|
|
|
|
|
|
static inline void CheckCommentASTNodes() {
|
|
|
|
#define ABSTRACT_COMMENT(COMMENT)
|
|
|
|
#define COMMENT(CLASS, PARENT) \
|
|
|
|
ASSERT_IMPLEMENTS_child_begin(&CLASS::child_begin); \
|
|
|
|
ASSERT_IMPLEMENTS_child_begin(&CLASS::child_end);
|
|
|
|
#include "clang/AST/CommentNodes.inc"
|
|
|
|
#undef COMMENT
|
|
|
|
#undef ABSTRACT_COMMENT
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef ASSERT_IMPLEMENTS_child_begin
|
|
|
|
|
|
|
|
} // end unnamed namespace
|
|
|
|
|
|
|
|
Comment::child_iterator Comment::child_begin() const {
|
|
|
|
switch (getCommentKind()) {
|
|
|
|
case NoCommentKind: llvm_unreachable("comment without a kind");
|
|
|
|
#define ABSTRACT_COMMENT(COMMENT)
|
|
|
|
#define COMMENT(CLASS, PARENT) \
|
|
|
|
case CLASS##Kind: \
|
|
|
|
return static_cast<const CLASS *>(this)->child_begin();
|
|
|
|
#include "clang/AST/CommentNodes.inc"
|
|
|
|
#undef COMMENT
|
|
|
|
#undef ABSTRACT_COMMENT
|
|
|
|
}
|
2012-07-07 05:13:09 +08:00
|
|
|
llvm_unreachable("Unknown comment kind!");
|
2012-07-06 08:28:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Comment::child_iterator Comment::child_end() const {
|
|
|
|
switch (getCommentKind()) {
|
|
|
|
case NoCommentKind: llvm_unreachable("comment without a kind");
|
|
|
|
#define ABSTRACT_COMMENT(COMMENT)
|
|
|
|
#define COMMENT(CLASS, PARENT) \
|
|
|
|
case CLASS##Kind: \
|
|
|
|
return static_cast<const CLASS *>(this)->child_end();
|
|
|
|
#include "clang/AST/CommentNodes.inc"
|
|
|
|
#undef COMMENT
|
|
|
|
#undef ABSTRACT_COMMENT
|
|
|
|
}
|
2012-07-07 05:13:09 +08:00
|
|
|
llvm_unreachable("Unknown comment kind!");
|
2012-07-06 08:28:32 +08:00
|
|
|
}
|
|
|
|
|
2012-07-19 04:54:32 +08:00
|
|
|
bool TextComment::isWhitespaceNoCache() const {
|
2012-07-12 05:38:39 +08:00
|
|
|
for (StringRef::const_iterator I = Text.begin(), E = Text.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
const char C = *I;
|
|
|
|
if (C != ' ' && C != '\n' && C != '\r' &&
|
|
|
|
C != '\t' && C != '\f' && C != '\v')
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-19 04:54:32 +08:00
|
|
|
bool ParagraphComment::isWhitespaceNoCache() const {
|
2012-07-12 05:38:39 +08:00
|
|
|
for (child_iterator I = child_begin(), E = child_end(); I != E; ++I) {
|
|
|
|
if (const TextComment *TC = dyn_cast<TextComment>(*I)) {
|
|
|
|
if (!TC->isWhitespace())
|
|
|
|
return false;
|
2012-07-19 08:01:56 +08:00
|
|
|
} else
|
|
|
|
return false;
|
2012-07-12 05:38:39 +08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *ParamCommandComment::getDirectionAsString(PassDirection D) {
|
|
|
|
switch (D) {
|
|
|
|
case ParamCommandComment::In:
|
|
|
|
return "[in]";
|
|
|
|
case ParamCommandComment::Out:
|
|
|
|
return "[out]";
|
|
|
|
case ParamCommandComment::InOut:
|
|
|
|
return "[in,out]";
|
|
|
|
}
|
|
|
|
llvm_unreachable("unknown PassDirection");
|
|
|
|
}
|
2012-07-06 08:28:32 +08:00
|
|
|
|
2012-08-02 07:08:09 +08:00
|
|
|
void DeclInfo::fill() {
|
|
|
|
assert(!IsFilled);
|
|
|
|
|
|
|
|
// Set defaults.
|
2012-08-04 05:15:32 +08:00
|
|
|
Kind = OtherKind;
|
2012-08-07 05:31:15 +08:00
|
|
|
TemplateKind = NotTemplate;
|
2012-08-07 00:29:26 +08:00
|
|
|
IsObjCMethod = false;
|
2012-08-02 07:08:09 +08:00
|
|
|
IsInstanceMethod = false;
|
|
|
|
IsClassMethod = false;
|
|
|
|
ParamVars = ArrayRef<const ParmVarDecl *>();
|
|
|
|
TemplateParameters = NULL;
|
|
|
|
|
|
|
|
if (!ThisDecl) {
|
2012-08-03 08:01:01 +08:00
|
|
|
// If there is no declaration, the defaults is our only guess.
|
|
|
|
IsFilled = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Decl::Kind K = ThisDecl->getKind();
|
|
|
|
switch (K) {
|
|
|
|
default:
|
|
|
|
// Defaults are should be good for declarations we don't handle explicitly.
|
|
|
|
break;
|
|
|
|
case Decl::Function:
|
|
|
|
case Decl::CXXMethod:
|
|
|
|
case Decl::CXXConstructor:
|
|
|
|
case Decl::CXXDestructor:
|
|
|
|
case Decl::CXXConversion: {
|
|
|
|
const FunctionDecl *FD = cast<FunctionDecl>(ThisDecl);
|
2012-08-03 05:45:39 +08:00
|
|
|
Kind = FunctionKind;
|
2012-08-02 07:08:09 +08:00
|
|
|
ParamVars = ArrayRef<const ParmVarDecl *>(FD->param_begin(),
|
|
|
|
FD->getNumParams());
|
2012-08-04 05:15:32 +08:00
|
|
|
ResultType = FD->getResultType();
|
2012-08-02 07:08:09 +08:00
|
|
|
unsigned NumLists = FD->getNumTemplateParameterLists();
|
|
|
|
if (NumLists != 0) {
|
2012-08-07 05:31:15 +08:00
|
|
|
TemplateKind = TemplateSpecialization;
|
2012-08-02 07:08:09 +08:00
|
|
|
TemplateParameters =
|
|
|
|
FD->getTemplateParameterList(NumLists - 1);
|
|
|
|
}
|
|
|
|
|
2012-08-04 05:15:32 +08:00
|
|
|
if (K == Decl::CXXMethod || K == Decl::CXXConstructor ||
|
|
|
|
K == Decl::CXXDestructor || K == Decl::CXXConversion) {
|
2012-08-03 08:01:01 +08:00
|
|
|
const CXXMethodDecl *MD = cast<CXXMethodDecl>(ThisDecl);
|
2012-08-02 07:08:09 +08:00
|
|
|
IsInstanceMethod = MD->isInstance();
|
|
|
|
IsClassMethod = !IsInstanceMethod;
|
|
|
|
}
|
2012-08-03 08:01:01 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Decl::ObjCMethod: {
|
|
|
|
const ObjCMethodDecl *MD = cast<ObjCMethodDecl>(ThisDecl);
|
2012-08-03 05:45:39 +08:00
|
|
|
Kind = FunctionKind;
|
2012-08-02 07:08:09 +08:00
|
|
|
ParamVars = ArrayRef<const ParmVarDecl *>(MD->param_begin(),
|
|
|
|
MD->param_size());
|
2012-08-04 05:15:32 +08:00
|
|
|
ResultType = MD->getResultType();
|
2012-08-07 00:29:26 +08:00
|
|
|
IsObjCMethod = true;
|
2012-08-02 07:08:09 +08:00
|
|
|
IsInstanceMethod = MD->isInstanceMethod();
|
|
|
|
IsClassMethod = !IsInstanceMethod;
|
2012-08-03 08:01:01 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Decl::FunctionTemplate: {
|
|
|
|
const FunctionTemplateDecl *FTD = cast<FunctionTemplateDecl>(ThisDecl);
|
2012-08-03 05:45:39 +08:00
|
|
|
Kind = FunctionKind;
|
2012-08-07 05:31:15 +08:00
|
|
|
TemplateKind = Template;
|
2012-08-02 07:08:09 +08:00
|
|
|
const FunctionDecl *FD = FTD->getTemplatedDecl();
|
|
|
|
ParamVars = ArrayRef<const ParmVarDecl *>(FD->param_begin(),
|
|
|
|
FD->getNumParams());
|
2012-08-04 05:15:32 +08:00
|
|
|
ResultType = FD->getResultType();
|
2012-08-02 07:08:09 +08:00
|
|
|
TemplateParameters = FTD->getTemplateParameters();
|
2012-08-03 08:01:01 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Decl::ClassTemplate: {
|
|
|
|
const ClassTemplateDecl *CTD = cast<ClassTemplateDecl>(ThisDecl);
|
2012-08-03 05:45:39 +08:00
|
|
|
Kind = ClassKind;
|
2012-08-07 05:31:15 +08:00
|
|
|
TemplateKind = Template;
|
2012-08-02 07:08:09 +08:00
|
|
|
TemplateParameters = CTD->getTemplateParameters();
|
2012-08-03 08:01:01 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Decl::ClassTemplatePartialSpecialization: {
|
|
|
|
const ClassTemplatePartialSpecializationDecl *CTPSD =
|
|
|
|
cast<ClassTemplatePartialSpecializationDecl>(ThisDecl);
|
2012-08-03 05:45:39 +08:00
|
|
|
Kind = ClassKind;
|
2012-08-07 05:31:15 +08:00
|
|
|
TemplateKind = TemplatePartialSpecialization;
|
2012-08-02 07:08:09 +08:00
|
|
|
TemplateParameters = CTPSD->getTemplateParameters();
|
2012-08-03 08:01:01 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Decl::ClassTemplateSpecialization:
|
2012-08-03 05:45:39 +08:00
|
|
|
Kind = ClassKind;
|
2012-08-07 05:31:15 +08:00
|
|
|
TemplateKind = TemplateSpecialization;
|
2012-08-03 08:01:01 +08:00
|
|
|
break;
|
|
|
|
case Decl::Record:
|
2012-08-04 05:15:32 +08:00
|
|
|
case Decl::CXXRecord:
|
2012-08-03 05:45:39 +08:00
|
|
|
Kind = ClassKind;
|
2012-08-03 08:01:01 +08:00
|
|
|
break;
|
|
|
|
case Decl::Var:
|
|
|
|
case Decl::Field:
|
2012-08-08 02:12:22 +08:00
|
|
|
case Decl::EnumConstant:
|
2012-08-03 08:01:01 +08:00
|
|
|
case Decl::ObjCIvar:
|
|
|
|
case Decl::ObjCAtDefsField:
|
2012-08-03 05:45:39 +08:00
|
|
|
Kind = VariableKind;
|
2012-08-03 08:01:01 +08:00
|
|
|
break;
|
|
|
|
case Decl::Namespace:
|
2012-08-03 05:45:39 +08:00
|
|
|
Kind = NamespaceKind;
|
2012-08-03 08:01:01 +08:00
|
|
|
break;
|
|
|
|
case Decl::Typedef:
|
|
|
|
case Decl::TypeAlias:
|
2012-08-03 05:45:39 +08:00
|
|
|
Kind = TypedefKind;
|
2012-08-03 08:01:01 +08:00
|
|
|
break;
|
|
|
|
case Decl::TypeAliasTemplate: {
|
|
|
|
const TypeAliasTemplateDecl *TAT = cast<TypeAliasTemplateDecl>(ThisDecl);
|
2012-08-03 05:45:39 +08:00
|
|
|
Kind = TypedefKind;
|
2012-08-07 05:31:15 +08:00
|
|
|
TemplateKind = Template;
|
2012-08-03 05:36:57 +08:00
|
|
|
TemplateParameters = TAT->getTemplateParameters();
|
2012-08-03 08:01:01 +08:00
|
|
|
break;
|
2012-08-02 07:08:09 +08:00
|
|
|
}
|
2012-08-03 08:01:01 +08:00
|
|
|
}
|
|
|
|
|
2012-08-02 07:08:09 +08:00
|
|
|
IsFilled = true;
|
|
|
|
}
|
|
|
|
|
2012-07-06 08:28:32 +08:00
|
|
|
} // end namespace comments
|
|
|
|
} // end namespace clang
|
2012-08-03 05:45:39 +08:00
|
|
|
|