diff options
Diffstat (limited to 'clang/lib/Parse/ParseDecl.cpp')
-rw-r--r-- | clang/lib/Parse/ParseDecl.cpp | 66 |
1 files changed, 29 insertions, 37 deletions
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 8bca7badea2..ad16d2c5bb3 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -2131,37 +2131,6 @@ Decl *Parser::ParseDeclarationAfterDeclarator( Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes( Declarator &D, const ParsedTemplateInfo &TemplateInfo, ForRangeInit *FRI) { - // RAII type used to track whether we're inside an initializer. - struct InitializerScopeRAII { - Parser &P; - Declarator &D; - Decl *ThisDecl; - - InitializerScopeRAII(Parser &P, Declarator &D, Decl *ThisDecl) - : P(P), D(D), ThisDecl(ThisDecl) { - if (ThisDecl && P.getLangOpts().CPlusPlus) { - Scope *S = nullptr; - if (D.getCXXScopeSpec().isSet()) { - P.EnterScope(0); - S = P.getCurScope(); - } - P.Actions.ActOnCXXEnterDeclInitializer(S, ThisDecl); - } - } - ~InitializerScopeRAII() { pop(); } - void pop() { - if (ThisDecl && P.getLangOpts().CPlusPlus) { - Scope *S = nullptr; - if (D.getCXXScopeSpec().isSet()) - S = P.getCurScope(); - P.Actions.ActOnCXXExitDeclInitializer(S, ThisDecl); - if (S) - P.ExitScope(); - } - ThisDecl = nullptr; - } - }; - // Inform the current actions module that we just parsed this declarator. Decl *ThisDecl = nullptr; switch (TemplateInfo.Kind) { @@ -2239,7 +2208,10 @@ Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes( else Diag(ConsumeToken(), diag::err_default_special_members); } else { - InitializerScopeRAII InitScope(*this, D, ThisDecl); + if (getLangOpts().CPlusPlus && D.getCXXScopeSpec().isSet()) { + EnterScope(0); + Actions.ActOnCXXEnterDeclInitializer(getCurScope(), ThisDecl); + } if (Tok.is(tok::code_completion)) { Actions.CodeCompleteInitializer(getCurScope(), ThisDecl); @@ -2262,7 +2234,10 @@ Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes( FRI->RangeExpr = Init; } - InitScope.pop(); + if (getLangOpts().CPlusPlus && D.getCXXScopeSpec().isSet()) { + Actions.ActOnCXXExitDeclInitializer(getCurScope(), ThisDecl); + ExitScope(); + } if (Init.isInvalid()) { SmallVector<tok::TokenKind, 2> StopTokens; @@ -2284,7 +2259,10 @@ Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes( ExprVector Exprs; CommaLocsTy CommaLocs; - InitializerScopeRAII InitScope(*this, D, ThisDecl); + if (getLangOpts().CPlusPlus && D.getCXXScopeSpec().isSet()) { + EnterScope(0); + Actions.ActOnCXXEnterDeclInitializer(getCurScope(), ThisDecl); + } llvm::function_ref<void()> ExprListCompleter; auto ThisVarDecl = dyn_cast_or_null<VarDecl>(ThisDecl); @@ -2305,6 +2283,11 @@ Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes( if (ParseExpressionList(Exprs, CommaLocs, ExprListCompleter)) { Actions.ActOnInitializerError(ThisDecl); SkipUntil(tok::r_paren, StopAtSemi); + + if (getLangOpts().CPlusPlus && D.getCXXScopeSpec().isSet()) { + Actions.ActOnCXXExitDeclInitializer(getCurScope(), ThisDecl); + ExitScope(); + } } else { // Match the ')'. T.consumeClose(); @@ -2312,7 +2295,10 @@ Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes( assert(!Exprs.empty() && Exprs.size()-1 == CommaLocs.size() && "Unexpected number of commas!"); - InitScope.pop(); + if (getLangOpts().CPlusPlus && D.getCXXScopeSpec().isSet()) { + Actions.ActOnCXXExitDeclInitializer(getCurScope(), ThisDecl); + ExitScope(); + } ExprResult Initializer = Actions.ActOnParenListExpr(T.getOpenLocation(), T.getCloseLocation(), @@ -2325,11 +2311,17 @@ Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes( // Parse C++0x braced-init-list. Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists); - InitializerScopeRAII InitScope(*this, D, ThisDecl); + if (D.getCXXScopeSpec().isSet()) { + EnterScope(0); + Actions.ActOnCXXEnterDeclInitializer(getCurScope(), ThisDecl); + } ExprResult Init(ParseBraceInitializer()); - InitScope.pop(); + if (D.getCXXScopeSpec().isSet()) { + Actions.ActOnCXXExitDeclInitializer(getCurScope(), ThisDecl); + ExitScope(); + } if (Init.isInvalid()) { Actions.ActOnInitializerError(ThisDecl); |