diff options
author | Douglas Gregor <dgregor@apple.com> | 2008-11-05 04:29:56 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2008-11-05 04:29:56 +0000 |
commit | 7ad8390f7992ab7f19b1460c5f0b9d96f165c4e9 (patch) | |
tree | 93d1b7ba4d514152f8dc77e32c6cc1c80a746e0d /lib/Parse/ParseCXXInlineMethods.cpp | |
parent | e839b15d7d18c3f63ce0aea885d704ef663a05e9 (diff) |
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
Diffstat (limited to 'lib/Parse/ParseCXXInlineMethods.cpp')
-rw-r--r-- | lib/Parse/ParseCXXInlineMethods.cpp | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/lib/Parse/ParseCXXInlineMethods.cpp b/lib/Parse/ParseCXXInlineMethods.cpp index ca0003440f..7d977c1251 100644 --- a/lib/Parse/ParseCXXInlineMethods.cpp +++ b/lib/Parse/ParseCXXInlineMethods.cpp @@ -23,7 +23,8 @@ Parser::DeclTy * 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 @@ Parser::ParseCXXInlineMethodDef(AccessSpecifier AS, Declarator &D) { 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 @@ void Parser::ParseLexedMethodDefs() { // 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(); |