[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

Douglas Gregor dgregor at apple.com
Tue Jul 21 10:15:12 PDT 2009


On Jul 21, 2009, at 10:05 AM, Fariborz Jahanian wrote:

>
> On Jul 21, 2009, at 9:53 AM, Douglas Gregor wrote:
>
>>
>> On Jul 14, 2009, at 11:24 AM, Fariborz Jahanian wrote:
>>> =
>>> =
>>> =
>>> =
>>> =
>>> =
>>> =
>>> =
>>> =
>>> =
>>> ====================================================================
>>> --- 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.

Well, there's similar O(N^2) code for direct, non-virtual base classes  
and for fields. It's pretty rare for there to be a large number of  
base classes (virtual or non-virtual direct), but it is relatively  
common to have quite a few fields. I think it's worth giving some  
thought to whether we can make this code more efficient... but if we  
can't think of something, just documenting it with a FIXME: O(N^2) is  
fine.

>>
>>
>>> +    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!

	- Doug



More information about the cfe-commits mailing list