From d45c36308e563e1fac1cd124d606f403f9a39a29 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Wed, 1 Jul 2009 21:05:43 +0000 Subject: [PATCH] Updated CXXConstructorDecl AST node for ctor-initilaizer list. No change in functionality. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74639 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/DeclCXX.h | 50 ++++++++++++++++++++++++++++++++----- lib/AST/DeclCXX.cpp | 13 ++++++++++ 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/include/clang/AST/DeclCXX.h b/include/clang/AST/DeclCXX.h index 847dd0cfdf..d5ae20d356 100644 --- a/include/clang/AST/DeclCXX.h +++ b/include/clang/AST/DeclCXX.h @@ -696,16 +696,23 @@ class CXXConstructorDecl : public CXXMethodDecl { /// @c !Implicit && ImplicitlyDefined. bool ImplicitlyDefined : 1; - /// FIXME: Add support for base and member initializers. - + /// Support for base and member initializers. + /// BaseOrMemberInitializers - The arguments used to initialize the base + /// or member. + CXXBaseOrMemberInitializer **BaseOrMemberInitializers; + unsigned NumBaseOrMemberInitializers; + CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation L, DeclarationName N, QualType T, bool isExplicit, bool isInline, bool isImplicitlyDeclared) : CXXMethodDecl(CXXConstructor, RD, L, N, T, false, isInline), - Explicit(isExplicit), ImplicitlyDefined(false) { + Explicit(isExplicit), ImplicitlyDefined(false), + BaseOrMemberInitializers(0), NumBaseOrMemberInitializers(0) { setImplicit(isImplicitlyDeclared); } - + + ~CXXConstructorDecl() { delete [] BaseOrMemberInitializers; } + public: static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation L, DeclarationName N, @@ -721,7 +728,8 @@ public: /// already been defined. bool isImplicitlyDefined(ASTContext &C) const { assert(isThisDeclarationADefinition() && - "Can only get the implicit-definition flag once the constructor has been defined"); + "Can only get the implicit-definition flag once the " + "constructor has been defined"); return ImplicitlyDefined; } @@ -729,10 +737,40 @@ public: /// implicitly defined or not. void setImplicitlyDefined(bool ID) { assert(isThisDeclarationADefinition() && - "Can only set the implicit-definition flag once the constructor has been defined"); + "Can only set the implicit-definition flag once the constructor " + "has been defined"); ImplicitlyDefined = ID; } + /// 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); + /// isDefaultConstructor - Whether this constructor is a default /// constructor (C++ [class.ctor]p5), which can be used to /// default-initialize a class of this type. diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp index 1b4dcd86c9..f653943f1d 100644 --- a/lib/AST/DeclCXX.cpp +++ b/lib/AST/DeclCXX.cpp @@ -407,6 +407,19 @@ CXXDestructorDecl::Create(ASTContext &C, CXXRecordDecl *RD, 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]; + } +} + CXXConversionDecl * CXXConversionDecl::Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation L, DeclarationName N, -- 2.40.0