[cfe-commits] r148708 - in /cfe/trunk: include/clang/AST/DeclCXX.h lib/AST/DeclCXX.cpp tools/libclang/IndexingContext.cpp

Argyrios Kyrtzidis kyrtzidis at apple.com
Mon Jan 23 17:41:41 PST 2012


On Jan 23, 2012, at 5:00 PM, Douglas Gregor wrote:

> 
> On Jan 23, 2012, at 8:58 AM, Argyrios Kyrtzidis <akyrtzi at gmail.com> wrote:
> 
>> Author: akirtzidis
>> Date: Mon Jan 23 10:58:45 2012
>> New Revision: 148708
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=148708&view=rev
>> Log:
>> 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
>> 
>> Modified:
>>   cfe/trunk/include/clang/AST/DeclCXX.h
>>   cfe/trunk/lib/AST/DeclCXX.cpp
>>   cfe/trunk/tools/libclang/IndexingContext.cpp
>> 
>> Modified: cfe/trunk/include/clang/AST/DeclCXX.h
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=148708&r1=148707&r2=148708&view=diff
>> ==============================================================================
>> --- cfe/trunk/include/clang/AST/DeclCXX.h (original)
>> +++ cfe/trunk/include/clang/AST/DeclCXX.h Mon Jan 23 10:58:45 2012
>> @@ -348,6 +348,9 @@
>>    /// \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 @@
>>  /// 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
>> 
>> Modified: cfe/trunk/lib/AST/DeclCXX.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=148708&r1=148707&r2=148708&view=diff
>> ==============================================================================
>> --- cfe/trunk/lib/AST/DeclCXX.cpp (original)
>> +++ cfe/trunk/lib/AST/DeclCXX.cpp Mon Jan 23 10:58:45 2012
>> @@ -43,7 +43,8 @@
>>    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::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 @@
>>      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;
>> +}
> 
> Don't you also want to check if it's a POD?

Very true, in r148765, thanks!

-Argyrios

> 
>  - Doug
> 
>> static CanQualType GetConversionType(ASTContext &Context, NamedDecl *Conv) {
>>  QualType T;
>>  if (isa<UsingShadowDecl>(Conv))
>> 
>> Modified: cfe/trunk/tools/libclang/IndexingContext.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/IndexingContext.cpp?rev=148708&r1=148707&r2=148708&view=diff
>> ==============================================================================
>> --- cfe/trunk/tools/libclang/IndexingContext.cpp (original)
>> +++ cfe/trunk/tools/libclang/IndexingContext.cpp Mon Jan 23 10:58:45 2012
>> @@ -814,12 +814,9 @@
>>      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;
>> 
>> 
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list