[cfe-commits] r75649 - in /cfe/trunk: include/clang/Parse/Action.h lib/AST/DeclCXX.cpp lib/Parse/ParseCXXInlineMethods.cpp lib/Sema/Sema.h lib/Sema/SemaDeclCXX.cpp

Fariborz Jahanian fjahanian at apple.com
Tue Jul 21 10:05:44 PDT 2009


On Jul 21, 2009, at 9:53 AM, Douglas Gregor wrote:

>
> On Jul 14, 2009, at 11:24 AM, Fariborz Jahanian wrote:
>
>> Author: fjahanian
>> Date: Tue Jul 14 13:24:21 2009
>> New Revision: 75649
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=75649&view=rev
>> Log:
>> Patch to build AST for ctor's initializer list according to
>> semantics of order of construction [class.init].
>
> Very nice.
>
>> Modified:
>>   cfe/trunk/include/clang/Parse/Action.h
>>   cfe/trunk/lib/AST/DeclCXX.cpp
>>   cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp
>>   cfe/trunk/lib/Sema/Sema.h
>>   cfe/trunk/lib/Sema/SemaDeclCXX.cpp
>>
>> Modified: cfe/trunk/include/clang/Parse/Action.h
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=75649&r1=75648&r2=75649&view=diff
>>
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =====================================================================
>> --- cfe/trunk/include/clang/Parse/Action.h (original)
>> +++ cfe/trunk/include/clang/Parse/Action.h Tue Jul 14 13:24:21 2009
>> @@ -1232,6 +1232,8 @@
>>                                    SourceLocation ColonLoc,
>>                                    MemInitTy **MemInits, unsigned  
>> NumMemInits){
>>  }
>> +
>> + virtual void ActOnDefaultInitializers(DeclPtrTy ConstructorDecl) {}
>>
>>  /// ActOnFinishCXXMemberSpecification - Invoked after all member  
>> declarators
>>  /// are parsed but *before* parsing of inline method definitions.
>>
>> Modified: cfe/trunk/lib/AST/DeclCXX.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=75649&r1=75648&r2=75649&view=diff
>>
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> =====================================================================
>> --- cfe/trunk/lib/AST/DeclCXX.cpp (original)
>> +++ cfe/trunk/lib/AST/DeclCXX.cpp Tue Jul 14 13:24:21 2009
>> @@ -482,12 +482,81 @@
>>                                    ASTContext &C,
>>                                    CXXBaseOrMemberInitializer  
>> **Initializers,
>>                                    unsigned NumInitializers) {
>> +  // We need to build the initializer AST according to order of  
>> construction
>> +  // and not what user specified in the Initializers list.
>> +  // FIXME. We probably don't need this. But it is cleaner.
>> +  CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(getDeclContext());
>> +  llvm::SmallVector<CXXBaseOrMemberInitializer*, 32> AllToInit;
>> +  // Push virtual bases before others.
>> +  for (CXXRecordDecl::base_class_iterator VBase =
>> +       ClassDecl->vbases_begin(),
>> +       E = ClassDecl->vbases_end(); VBase != E; ++VBase) {
>> +    const Type * T = VBase->getType()->getAsRecordType();
>> +    unsigned int i = 0;
>> +    for (i = 0; i < NumInitializers; i++) {
>> +      CXXBaseOrMemberInitializer *Member = Initializers[i];
>> +      if (Member->isBaseInitializer() &&
>> +          Member->getBaseClass() == T) {
>> +        AllToInit.push_back(Member);
>> +        break;
>> +      }
>> +    }
>
> This is quadratic in the number of initializers, which is rather  
> unfortunate. Can we do better than O(N^2)?

Yes, but in practice explosion is controlled by number of unique  
virtual bases. Do you think it matters? Then
I will look at using faster search methods.

>
>
>> +    if (i == NumInitializers) {
>> +      CXXBaseOrMemberInitializer *Member =
>> +        new CXXBaseOrMemberInitializer(VBase->getType(), 0,  
>> 0,SourceLocation());
>> +      AllToInit.push_back(Member);
>> +    }
>> +  }
>
> Eventually, we'll need to allocate CXXBaseOrMemberInitializers via  
> ASTContext. I know there are existing FIXMEs for this, though.
I will look into this after my current work.

- Thanks, Fariborz

>
>
>  - Doug




More information about the cfe-commits mailing list