Initial implementation of parsing, semantic analysis, and AST-building
for constructor initializations, e.g.,
class A { };
class B : public A {
int m;
public:
B() : A(), m(17) { };
};
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58749 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Parse/ParseCXXInlineMethods.cpp b/lib/Parse/ParseCXXInlineMethods.cpp
index ca00034..7d977c1 100644
--- a/lib/Parse/ParseCXXInlineMethods.cpp
+++ b/lib/Parse/ParseCXXInlineMethods.cpp
@@ -23,7 +23,8 @@
Parser::ParseCXXInlineMethodDef(AccessSpecifier AS, Declarator &D) {
assert(D.getTypeObject(0).Kind == DeclaratorChunk::Function &&
"This isn't a function declarator!");
- assert(Tok.is(tok::l_brace) && "Current token not a '{'!");
+ assert((Tok.is(tok::l_brace) || Tok.is(tok::colon)) &&
+ "Current token not a '{' or ':'!");
DeclTy *FnD = Actions.ActOnCXXMemberDeclarator(CurScope, AS, D, 0, 0, 0);
@@ -32,9 +33,16 @@
getCurTopClassStack().push(LexedMethod(FnD));
TokensTy &Toks = getCurTopClassStack().top().Toks;
- // Begin by storing the '{' token.
- Toks.push_back(Tok);
- ConsumeBrace();
+ // We may have a constructor initializer here.
+ if (Tok.is(tok::colon)) {
+ // Consume everything up to (and including) the left brace.
+ ConsumeAndStoreUntil(tok::l_brace, Toks);
+ } else {
+ // Begin by storing the '{' token.
+ Toks.push_back(Tok);
+ ConsumeBrace();
+ }
+ // Consume everything up to (and including) the matching right brace.
ConsumeAndStoreUntil(tok::r_brace, Toks);
return FnD;
@@ -55,13 +63,17 @@
// Consume the previously pushed token.
ConsumeAnyToken();
- assert(Tok.is(tok::l_brace) && "Inline method not starting with '{'");
+ assert((Tok.is(tok::l_brace) || Tok.is(tok::colon)) &&
+ "Inline method not starting with '{' or ':'");
// Parse the method body. Function body parsing code is similar enough
// to be re-used for method bodies as well.
EnterScope(Scope::FnScope|Scope::DeclScope);
Actions.ActOnStartOfFunctionDef(CurScope, LM.D);
+ if (Tok.is(tok::colon))
+ ParseConstructorInitializer(LM.D);
+
ParseFunctionStatementBody(LM.D, Tok.getLocation(), Tok.getLocation());
getCurTopClassStack().pop();