[cfe-commits] r74639 - in /cfe/trunk: include/clang/AST/DeclCXX.h lib/AST/DeclCXX.cpp

Douglas Gregor dgregor at apple.com
Wed Jul 1 14:12:49 PDT 2009


On Jul 1, 2009, at 2:05 PM, Fariborz Jahanian wrote:

> Author: fjahanian
> Date: Wed Jul  1 16:05:43 2009
> New Revision: 74639
>
> URL: http://llvm.org/viewvc/llvm-project?rev=74639&view=rev
> Log:
> Updated CXXConstructorDecl AST node for ctor-initilaizer list.
> No change in functionality.
>
> [snip]
> +  /// arg_iterator - Iterates through the member/base initializer  
> list.
> +  typedef CXXBaseOrMemberInitializer **arg_iterator;
> +
> +  /// arg_const_iterator - Iterates through the memberbase  
> initializer list.
> +  typedef CXXBaseOrMemberInitializer * const * arg_const_iterator;
> +
> +  /// begin() - Retrieve an iterator to the first initializer.
> +  arg_iterator       begin()       { return  
> BaseOrMemberInitializers; }
> +  /// begin() - Retrieve an iterator to the first initializer.
> +  arg_const_iterator begin() const { return  
> BaseOrMemberInitializers; }
> +
> +  /// end() - Retrieve an iterator past the last initializer.
> +  arg_iterator       end()       {
> +    return BaseOrMemberInitializers + NumBaseOrMemberInitializers;
> +  }
> +  /// end() - Retrieve an iterator past the last initializer.
> +  arg_const_iterator end() const {
> +    return BaseOrMemberInitializers + NumBaseOrMemberInitializers;
> +  }
> +
> +  /// getNumArgs - Determine the number of arguments used to
> +  /// initialize the member or base.
> +  unsigned getNumBaseOrMemberInitializers() const {
> +      return NumBaseOrMemberInitializers;
> +  }
> +
> +  void setBaseOrMemberInitializers(CXXBaseOrMemberInitializer  
> **Initializers,
> +                                   unsigned NumInitializers);
> +

arg_iterator/begin/end are the wrong names for this functionality. I  
suggest init_iterator/init_begin/init_end.


>   /// isDefaultConstructor - Whether this constructor is a default
>   /// constructor (C++ [class.ctor]p5), which can be used to
>   /// default-initialize a class of this type.
>
> Modified: cfe/trunk/lib/AST/DeclCXX.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=74639&r1=74638&r2=74639&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/lib/AST/DeclCXX.cpp (original)
> +++ cfe/trunk/lib/AST/DeclCXX.cpp Wed Jul  1 16:05:43 2009
> @@ -407,6 +407,19 @@
>                                    isImplicitlyDeclared);
> }
>
> +void
> +CXXConstructorDecl::setBaseOrMemberInitializers(
> +                                    CXXBaseOrMemberInitializer  
> **Initializers,
> +                                    unsigned NumInitializers) {
> +  if (NumInitializers > 0) {
> +    NumBaseOrMemberInitializers = NumInitializers;
> +    BaseOrMemberInitializers =
> +    new CXXBaseOrMemberInitializer*[NumInitializers];
> +    for (unsigned Idx = 0; Idx < NumInitializers; ++Idx)
> +      BaseOrMemberInitializers[Idx] = Initializers[Idx];
> +  }
> +}

This should allocate memory using an ASTContext rather than the normal  
heap.

Also, a Destroy method should be added to free this memory.

	- Doug



More information about the cfe-commits mailing list