summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-01-23 16:58:45 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-01-23 16:58:45 +0000
commit5c4e065a9a6a5b24a676330e58e9d70da0ac78b5 (patch)
treee171fbcb517c49bc725ceeb4e950659e3bac4919
parent7e614d7dce06221e4484fb720b69457c162f048d (diff)
downloadbcm5719-llvm-5c4e065a9a6a5b24a676330e58e9d70da0ac78b5.tar.gz
bcm5719-llvm-5c4e065a9a6a5b24a676330e58e9d70da0ac78b5.zip
Introduce CXXRecordDecl::isCLike() that is true if the class is C-like,
without C++-specific features. Use it to set the language to C++ when indexing non-C-like structs. rdar://10732579 llvm-svn: 148708
-rw-r--r--clang/include/clang/AST/DeclCXX.h7
-rw-r--r--clang/lib/AST/DeclCXX.cpp18
-rw-r--r--clang/tools/libclang/IndexingContext.cpp7
3 files changed, 26 insertions, 6 deletions
diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h
index 6592e1beaae..e035e0b2fc0 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -348,6 +348,9 @@ class CXXRecordDecl : public RecordDecl {
/// \brief True if this class (or any subobject) has mutable fields.
bool HasMutableFields : 1;
+ /// \brief True if there no non-field members declared by the user.
+ bool HasOnlyFields : 1;
+
/// HasTrivialDefaultConstructor - True when, if this class has a default
/// constructor, this default constructor is trivial.
///
@@ -962,6 +965,10 @@ public:
/// user-defined destructor.
bool isPOD() const { return data().PlainOldData; }
+ /// \brief True if this class is C-like, without C++-specific features, e.g.
+ /// it contains only public fields, no bases, tag kind is not 'class', etc.
+ bool isCLike() const;
+
/// isEmpty - Whether this class is empty (C++0x [meta.unary.prop]), which
/// means it has a virtual function, virtual base, data member (other than
/// 0-width bit-field) or inherits from a non-empty class. Does NOT include
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index b09b6720955..7cf7bf1017e 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -43,7 +43,8 @@ CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl *D)
Aggregate(true), PlainOldData(true), Empty(true), Polymorphic(false),
Abstract(false), IsStandardLayout(true), HasNoNonEmptyBases(true),
HasPrivateFields(false), HasProtectedFields(false), HasPublicFields(false),
- HasMutableFields(false), HasTrivialDefaultConstructor(true),
+ HasMutableFields(false), HasOnlyFields(true),
+ HasTrivialDefaultConstructor(true),
HasConstexprNonCopyMoveConstructor(false),
DefaultedDefaultConstructorIsConstexpr(true),
DefaultedCopyConstructorIsConstexpr(true),
@@ -456,6 +457,9 @@ void CXXRecordDecl::markedVirtualFunctionPure() {
}
void CXXRecordDecl::addedMember(Decl *D) {
+ if (!isa<FieldDecl>(D) && !isa<IndirectFieldDecl>(D) && !D->isImplicit())
+ data().HasOnlyFields = false;
+
// Ignore friends and invalid declarations.
if (D->getFriendObjectKind() || D->isInvalidDecl())
return;
@@ -957,6 +961,18 @@ NotASpecialMember:;
data().Conversions.addDecl(Shadow, Shadow->getAccess());
}
+bool CXXRecordDecl::isCLike() const {
+ if (getTagKind() == TTK_Class || !TemplateOrInstantiation.isNull())
+ return false;
+ if (!hasDefinition())
+ return true;
+
+ return data().HasOnlyFields &&
+ !data().HasPrivateFields &&
+ !data().HasProtectedFields &&
+ !data().NumBases;
+}
+
static CanQualType GetConversionType(ASTContext &Context, NamedDecl *Conv) {
QualType T;
if (isa<UsingShadowDecl>(Conv))
diff --git a/clang/tools/libclang/IndexingContext.cpp b/clang/tools/libclang/IndexingContext.cpp
index 3d70144db54..a124cbdff52 100644
--- a/clang/tools/libclang/IndexingContext.cpp
+++ b/clang/tools/libclang/IndexingContext.cpp
@@ -814,12 +814,9 @@ void IndexingContext::getEntityInfo(const NamedDecl *D,
EntityInfo.kind = CXIdxEntity_Enum; break;
}
- if (const CXXRecordDecl *CXXRec = dyn_cast<CXXRecordDecl>(D)) {
- // FIXME: isPOD check is not sufficient, a POD can contain methods,
- // we want a isCStructLike check.
- if (CXXRec->hasDefinition() && !CXXRec->isPOD())
+ if (const CXXRecordDecl *CXXRec = dyn_cast<CXXRecordDecl>(D))
+ if (!CXXRec->isCLike())
EntityInfo.lang = CXIdxEntityLang_CXX;
- }
if (isa<ClassTemplatePartialSpecializationDecl>(D)) {
EntityInfo.templateKind = CXIdxEntity_TemplatePartialSpecialization;
OpenPOWER on IntegriCloud