summaryrefslogtreecommitdiffstats
path: root/clang/include/clang
diff options
context:
space:
mode:
Diffstat (limited to 'clang/include/clang')
-rw-r--r--clang/include/clang/AST/DeclCXX.h99
-rw-r--r--clang/include/clang/Basic/DiagnosticKinds.def10
-rw-r--r--clang/include/clang/Parse/Action.h24
-rw-r--r--clang/include/clang/Parse/Parser.h14
4 files changed, 142 insertions, 5 deletions
diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h
index 7a0bce8f83f..3d0c805a3a7 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -395,6 +395,105 @@ protected:
friend Decl* Decl::Create(llvm::Deserializer& D, ASTContext& C);
};
+/// CXXBaseOrMemberInitializer - Represents a C++ base or member
+/// initializer, which is part of a constructor initializer that
+/// initializes one non-static member variable or one base class. For
+/// example, in the following, both 'A(a)' and 'f(3.14159)' are member
+/// initializers:
+///
+/// @code
+/// class A { };
+/// class B : public A {
+/// float f;
+/// public:
+/// B(A& a) : A(a), f(3.14159) { }
+/// };
+class CXXBaseOrMemberInitializer {
+ /// BaseOrMember - This points to the entity being initialized,
+ /// which is either a base class (a Type) or a non-static data
+ /// member (a CXXFieldDecl). When the low bit is 1, it's a base
+ /// class; when the low bit is 0, it's a member.
+ uintptr_t BaseOrMember;
+
+ /// Args - The arguments used to initialize the base or member.
+ Expr **Args;
+ unsigned NumArgs;
+
+public:
+ /// CXXBaseOrMemberInitializer - Creates a new base-class initializer.
+ explicit
+ CXXBaseOrMemberInitializer(QualType BaseType, Expr **Args, unsigned NumArgs);
+
+ /// CXXBaseOrMemberInitializer - Creates a new member initializer.
+ explicit
+ CXXBaseOrMemberInitializer(CXXFieldDecl *Member, Expr **Args, unsigned NumArgs);
+
+ /// ~CXXBaseOrMemberInitializer - Destroy the base or member initializer.
+ ~CXXBaseOrMemberInitializer();
+
+ /// arg_iterator - Iterates through the member initialization
+ /// arguments.
+ typedef Expr **arg_iterator;
+
+ /// arg_const_iterator - Iterates through the member initialization
+ /// arguments.
+ typedef Expr * const * arg_const_iterator;
+
+ /// isBaseInitializer - Returns true when this initializer is
+ /// initializing a base class.
+ bool isBaseInitializer() const { return (BaseOrMember & 0x1) != 0; }
+
+ /// isMemberInitializer - Returns true when this initializer is
+ /// initializing a non-static data member.
+ bool isMemberInitializer() const { return (BaseOrMember & 0x1) == 0; }
+
+ /// getBaseClass - If this is a base class initializer, returns the
+ /// type used to specify the initializer. The resulting type will be
+ /// a class type or a typedef of a class type. If this is not a base
+ /// class initializer, returns NULL.
+ Type *getBaseClass() {
+ if (isBaseInitializer())
+ return reinterpret_cast<Type*>(BaseOrMember & ~0x01);
+ else
+ return 0;
+ }
+
+ /// getBaseClass - If this is a base class initializer, returns the
+ /// type used to specify the initializer. The resulting type will be
+ /// a class type or a typedef of a class type. If this is not a base
+ /// class initializer, returns NULL.
+ const Type *getBaseClass() const {
+ if (isBaseInitializer())
+ return reinterpret_cast<const Type*>(BaseOrMember & ~0x01);
+ else
+ return 0;
+ }
+
+ /// getMember - If this is a member initializer, returns the
+ /// declaration of the non-static data member being
+ /// initialized. Otherwise, returns NULL.
+ CXXFieldDecl *getMember() {
+ if (isMemberInitializer())
+ return reinterpret_cast<CXXFieldDecl *>(BaseOrMember);
+ else
+ return 0;
+ }
+
+ /// begin() - Retrieve an iterator to the first initializer argument.
+ arg_iterator begin() { return Args; }
+ /// begin() - Retrieve an iterator to the first initializer argument.
+ arg_const_iterator begin() const { return Args; }
+
+ /// end() - Retrieve an iterator past the last initializer argument.
+ arg_iterator end() { return Args + NumArgs; }
+ /// end() - Retrieve an iterator past the last initializer argument.
+ arg_const_iterator end() const { return Args + NumArgs; }
+
+ /// getNumArgs - Determine the number of arguments used to
+ /// initialize the member or base.
+ unsigned getNumArgs() const { return NumArgs; }
+};
+
/// CXXConstructorDecl - Represents a C++ constructor within a
/// class. For example:
///
diff --git a/clang/include/clang/Basic/DiagnosticKinds.def b/clang/include/clang/Basic/DiagnosticKinds.def
index 8517222c1db..30238f6d6f9 100644
--- a/clang/include/clang/Basic/DiagnosticKinds.def
+++ b/clang/include/clang/Basic/DiagnosticKinds.def
@@ -562,6 +562,8 @@ DIAG(warn_statement_disambiguation, WARNING,
"statement was disambiguated as %0")
DIAG(warn_parens_disambiguated_as_function_decl, WARNING,
"parentheses were disambiguated as a function declarator")
+DIAG(err_expected_member_or_base_name, ERROR,
+ "expected class member or base class name")
// Language specific pragmas
@@ -1240,6 +1242,14 @@ DIAG(err_expected_class_name, ERROR,
DIAG(err_anon_type_definition, ERROR,
"declaration of anonymous %0 must be a definition")
+// C++ member initializers.
+DIAG(err_mem_init_not_member_or_class, ERROR,
+ "member initializer '%0' does not name a non-static data member or base class")
+DIAG(err_base_init_does_not_name_class, ERROR,
+ "constructor initializer '%0' does not name a class")
+DIAG(err_base_init_direct_and_virtual, ERROR,
+ "base class initializer '%0' names both a direct base class and an inherited virtual base class")
+
// Derived classes.
DIAG(err_dup_virtual, ERROR,
"duplicate 'virtual' in base specifier")
diff --git a/clang/include/clang/Parse/Action.h b/clang/include/clang/Parse/Action.h
index aa8710b97b0..345f1860901 100644
--- a/clang/include/clang/Parse/Action.h
+++ b/clang/include/clang/Parse/Action.h
@@ -58,6 +58,7 @@ public:
typedef void TypeTy;
typedef void AttrTy;
typedef void BaseTy;
+ typedef void MemInitTy;
/// ActionResult - This structure is used while parsing/acting on expressions,
/// stmts, etc. It encapsulates both the object returned by the action, plus
@@ -85,6 +86,7 @@ public:
typedef ActionResult<1> StmtResult;
typedef ActionResult<2> TypeResult;
typedef ActionResult<3> BaseResult;
+ typedef ActionResult<4> MemInitResult;
/// Deletion callbacks - Since the parser doesn't know the concrete types of
/// the AST nodes being generated, it must do callbacks to delete objects when
@@ -687,6 +689,28 @@ public:
return 0;
}
+ virtual MemInitResult ActOnMemInitializer(DeclTy *ConstructorDecl,
+ Scope *S,
+ IdentifierInfo *MemberOrBase,
+ SourceLocation IdLoc,
+ SourceLocation LParenLoc,
+ ExprTy **Args, unsigned NumArgs,
+ SourceLocation *CommaLocs,
+ SourceLocation RParenLoc) {
+ return true;
+ }
+
+ /// ActOnMemInitializers - This is invoked when all of the member
+ /// initializers of a constructor have been parsed. ConstructorDecl
+ /// is the function declaration (which will be a C++ constructor in
+ /// a well-formed program), ColonLoc is the location of the ':' that
+ /// starts the constructor initializer, and MemInit/NumMemInits
+ /// contains the individual member (and base) initializers.
+ virtual void ActOnMemInitializers(DeclTy *ConstructorDecl,
+ SourceLocation ColonLoc,
+ MemInitTy **MemInits, unsigned NumMemInits) {
+ }
+
/// ActOnFinishCXXMemberSpecification - Invoked after all member declarators
/// are parsed but *before* parsing of inline method definitions.
virtual void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h
index bffe66023e0..897c09d0bc4 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -74,7 +74,8 @@ public:
typedef Action::DeclTy DeclTy;
typedef Action::TypeTy TypeTy;
typedef Action::BaseTy BaseTy;
-
+ typedef Action::MemInitTy MemInitTy;
+
// Parsing methods.
/// ParseTranslationUnit - All in one method that initializes parses, and
@@ -314,10 +315,11 @@ private:
bool SkipUntil(const tok::TokenKind *Toks, unsigned NumToks,
bool StopAtSemi = true, bool DontConsume = false);
- typedef Action::ExprResult ExprResult;
- typedef Action::StmtResult StmtResult;
- typedef Action::BaseResult BaseResult;
-
+ typedef Action::ExprResult ExprResult;
+ typedef Action::StmtResult StmtResult;
+ typedef Action::BaseResult BaseResult;
+ typedef Action::MemInitResult MemInitResult;
+
//===--------------------------------------------------------------------===//
// Lexing and parsing of C++ inline methods.
@@ -717,6 +719,8 @@ private:
void ParseCXXMemberSpecification(SourceLocation StartLoc, unsigned TagType,
DeclTy *TagDecl);
DeclTy *ParseCXXClassMemberDeclaration(AccessSpecifier AS);
+ void ParseConstructorInitializer(DeclTy *ConstructorDecl);
+ MemInitResult ParseMemInitializer(DeclTy *ConstructorDecl);
//===--------------------------------------------------------------------===//
// C++ 10: Derived classes [class.derived]
OpenPOWER on IntegriCloud