diff options
author | dim <dim@FreeBSD.org> | 2014-11-24 18:11:16 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2014-11-24 18:11:16 +0000 |
commit | 6148c19c738a92f344008aa3f88f4e008bada0ee (patch) | |
tree | d4426858455f04d0d8c25a2f9eb9ea5582ffe1b6 /contrib/llvm/tools/clang/lib/Parse/ParseCXXInlineMethods.cpp | |
parent | 2c8643c6396b0a3db33430cf9380e70bbb9efce0 (diff) | |
parent | 173a4f43a911175643bda81ee675e8d9269056ea (diff) | |
download | FreeBSD-src-6148c19c738a92f344008aa3f88f4e008bada0ee.zip FreeBSD-src-6148c19c738a92f344008aa3f88f4e008bada0ee.tar.gz |
Merge clang 3.5.0 release from ^/vendor/clang/dist, resolve conflicts,
and preserve our customizations, where necessary.
Diffstat (limited to 'contrib/llvm/tools/clang/lib/Parse/ParseCXXInlineMethods.cpp')
-rw-r--r-- | contrib/llvm/tools/clang/lib/Parse/ParseCXXInlineMethods.cpp | 142 |
1 files changed, 74 insertions, 68 deletions
diff --git a/contrib/llvm/tools/clang/lib/Parse/ParseCXXInlineMethods.cpp b/contrib/llvm/tools/clang/lib/Parse/ParseCXXInlineMethods.cpp index 7792305..30a9120 100644 --- a/contrib/llvm/tools/clang/lib/Parse/ParseCXXInlineMethods.cpp +++ b/contrib/llvm/tools/clang/lib/Parse/ParseCXXInlineMethods.cpp @@ -19,13 +19,6 @@ #include "clang/Sema/Scope.h" using namespace clang; -/// Get the FunctionDecl for a function or function template decl. -static FunctionDecl *getFunctionDecl(Decl *D) { - if (FunctionDecl *fn = dyn_cast<FunctionDecl>(D)) - return fn; - return cast<FunctionTemplateDecl>(D)->getTemplatedDecl(); -} - /// ParseCXXInlineMethodDef - We parsed and verified that the specified /// Declarator is a well formed C++ inline method definition. Now lex its body /// and store its tokens for parsing after the C++ class is complete. @@ -42,8 +35,9 @@ NamedDecl *Parser::ParseCXXInlineMethodDef(AccessSpecifier AS, "Current token not a '{', ':', '=', or 'try'!"); MultiTemplateParamsArg TemplateParams( - TemplateInfo.TemplateParams ? TemplateInfo.TemplateParams->data() : 0, - TemplateInfo.TemplateParams ? TemplateInfo.TemplateParams->size() : 0); + TemplateInfo.TemplateParams ? TemplateInfo.TemplateParams->data() + : nullptr, + TemplateInfo.TemplateParams ? TemplateInfo.TemplateParams->size() : 0); NamedDecl *FnD; D.setFunctionDefinitionKind(DefinitionKind); @@ -52,7 +46,7 @@ NamedDecl *Parser::ParseCXXInlineMethodDef(AccessSpecifier AS, TemplateParams); else { FnD = Actions.ActOnCXXMemberDeclarator(getCurScope(), AS, D, - TemplateParams, 0, + TemplateParams, nullptr, VS, ICIS_NoInit); if (FnD) { Actions.ProcessDeclAttributeList(getCurScope(), FnD, AccessAttrs); @@ -69,30 +63,24 @@ NamedDecl *Parser::ParseCXXInlineMethodDef(AccessSpecifier AS, D.complete(FnD); - if (Tok.is(tok::equal)) { - ConsumeToken(); - + if (TryConsumeToken(tok::equal)) { if (!FnD) { SkipUntil(tok::semi); - return 0; + return nullptr; } bool Delete = false; SourceLocation KWLoc; - if (Tok.is(tok::kw_delete)) { - Diag(Tok, getLangOpts().CPlusPlus11 ? - diag::warn_cxx98_compat_deleted_function : - diag::ext_deleted_function); - - KWLoc = ConsumeToken(); + if (TryConsumeToken(tok::kw_delete, KWLoc)) { + Diag(KWLoc, getLangOpts().CPlusPlus11 + ? diag::warn_cxx98_compat_deleted_function + : diag::ext_deleted_function); Actions.SetDeclDeleted(FnD, KWLoc); Delete = true; - } else if (Tok.is(tok::kw_default)) { - Diag(Tok, getLangOpts().CPlusPlus11 ? - diag::warn_cxx98_compat_defaulted_function : - diag::ext_defaulted_function); - - KWLoc = ConsumeToken(); + } else if (TryConsumeToken(tok::kw_default, KWLoc)) { + Diag(KWLoc, getLangOpts().CPlusPlus11 + ? diag::warn_cxx98_compat_defaulted_function + : diag::ext_defaulted_function); Actions.SetDeclDefaulted(FnD, KWLoc); } else { llvm_unreachable("function definition after = not 'delete' or 'default'"); @@ -102,9 +90,9 @@ NamedDecl *Parser::ParseCXXInlineMethodDef(AccessSpecifier AS, Diag(KWLoc, diag::err_default_delete_in_multiple_declaration) << Delete; SkipUntil(tok::semi); - } else { - ExpectAndConsume(tok::semi, diag::err_expected_semi_after, - Delete ? "delete" : "default", tok::semi); + } else if (ExpectAndConsume(tok::semi, diag::err_expected_after, + Delete ? "delete" : "default")) { + SkipUntil(tok::semi); } return FnD; @@ -115,9 +103,9 @@ NamedDecl *Parser::ParseCXXInlineMethodDef(AccessSpecifier AS, // the tokens and store them for parsing at the end of the translation unit. if (getLangOpts().DelayedTemplateParsing && DefinitionKind == FDK_Definition && - !D.getDeclSpec().isConstexprSpecified() && - !(FnD && getFunctionDecl(FnD) && - getFunctionDecl(FnD)->getResultType()->getContainedAutoType()) && + !D.getDeclSpec().isConstexprSpecified() && + !(FnD && FnD->getAsFunction() && + FnD->getAsFunction()->getReturnType()->getContainedAutoType()) && ((Actions.CurContext->isDependentContext() || (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate && TemplateInfo.Kind != ParsedTemplateInfo::ExplicitSpecialization)) && @@ -127,7 +115,7 @@ NamedDecl *Parser::ParseCXXInlineMethodDef(AccessSpecifier AS, LexTemplateFunctionForLateParsing(Toks); if (FnD) { - FunctionDecl *FD = getFunctionDecl(FnD); + FunctionDecl *FD = FnD->getAsFunction(); Actions.CheckForFunctionRedefinition(FD); Actions.MarkAsLateParsedTemplate(FD, FnD, Toks); } @@ -179,7 +167,7 @@ NamedDecl *Parser::ParseCXXInlineMethodDef(AccessSpecifier AS, // If you remove this, you can remove the code that clears the flag // after parsing the member. if (D.getDeclSpec().isFriendSpecified()) { - FunctionDecl *FD = getFunctionDecl(FnD); + FunctionDecl *FD = FnD->getAsFunction(); Actions.CheckForFunctionRedefinition(FD); FD->setLateTemplateParsed(true); } @@ -275,7 +263,8 @@ void Parser::LateParsedMemberInitializer::ParseLexedMemberInitializers() { /// delayed (such as default arguments) and parse them. void Parser::ParseLexedMethodDeclarations(ParsingClass &Class) { bool HasTemplateScope = !Class.TopLevelClass && Class.TemplateScope; - ParseScope ClassTemplateScope(this, Scope::TemplateParamScope, HasTemplateScope); + ParseScope ClassTemplateScope(this, Scope::TemplateParamScope, + HasTemplateScope); TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth); if (HasTemplateScope) { Actions.ActOnReenterTemplateScope(getCurScope(), Class.TagOrTemplate); @@ -288,14 +277,16 @@ void Parser::ParseLexedMethodDeclarations(ParsingClass &Class) { ParseScope ClassScope(this, Scope::ClassScope|Scope::DeclScope, HasClassScope); if (HasClassScope) - Actions.ActOnStartDelayedMemberDeclarations(getCurScope(), Class.TagOrTemplate); + Actions.ActOnStartDelayedMemberDeclarations(getCurScope(), + Class.TagOrTemplate); for (size_t i = 0; i < Class.LateParsedDeclarations.size(); ++i) { Class.LateParsedDeclarations[i]->ParseLexedMethodDeclarations(); } if (HasClassScope) - Actions.ActOnFinishDelayedMemberDeclarations(getCurScope(), Class.TagOrTemplate); + Actions.ActOnFinishDelayedMemberDeclarations(getCurScope(), + Class.TagOrTemplate); } void Parser::ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM) { @@ -315,7 +306,7 @@ void Parser::ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM) { Scope::FunctionDeclarationScope | Scope::DeclScope); for (unsigned I = 0, N = LM.DefaultArgs.size(); I != N; ++I) { // Introduce the parameter into scope. - Actions.ActOnDelayedCXXMethodParameter(getCurScope(), + Actions.ActOnDelayedCXXMethodParameter(getCurScope(), LM.DefaultArgs[I].Param); if (CachedTokens *Toks = LM.DefaultArgs[I].Toks) { @@ -346,11 +337,10 @@ void Parser::ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM) { } else DefArgResult = ParseAssignmentExpression(); if (DefArgResult.isInvalid()) - Actions.ActOnParamDefaultArgumentError(LM.DefaultArgs[I].Param); + Actions.ActOnParamDefaultArgumentError(LM.DefaultArgs[I].Param, + EqualLoc); else { - if (Tok.is(tok::cxx_defaultarg_end)) - ConsumeToken(); - else { + if (!TryConsumeToken(tok::cxx_defaultarg_end)) { // The last two tokens are the terminator and the saved value of // Tok; the last token in the default argument is the one before // those. @@ -360,7 +350,7 @@ void Parser::ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM) { (*Toks)[Toks->size() - 3].getLocation()); } Actions.ActOnParamDefaultArgument(LM.DefaultArgs[I].Param, EqualLoc, - DefArgResult.take()); + DefArgResult.get()); } assert(!PP.getSourceManager().isBeforeInTranslationUnit(origLoc, @@ -372,7 +362,7 @@ void Parser::ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM) { ConsumeAnyToken(); delete Toks; - LM.DefaultArgs[I].Toks = 0; + LM.DefaultArgs[I].Toks = nullptr; } } @@ -446,7 +436,7 @@ void Parser::ParseLexedMethodDef(LexedMethod &LM) { // Error recovery. if (!Tok.is(tok::l_brace)) { FnScope.Exit(); - Actions.ActOnFinishFunctionBody(LM.D, 0); + Actions.ActOnFinishFunctionBody(LM.D, nullptr); while (Tok.getLocation() != origLoc && Tok.isNot(tok::eof)) ConsumeAnyToken(); return; @@ -464,7 +454,8 @@ void Parser::ParseLexedMethodDef(LexedMethod &LM) { ParseFunctionStatementBody(LM.D, FnScope); // Clear the late-template-parsed bit if we set it before. - if (LM.D) getFunctionDecl(LM.D)->setLateTemplateParsed(false); + if (LM.D) + LM.D->getAsFunction()->setLateTemplateParsed(false); if (Tok.getLocation() != origLoc) { // Due to parsing error, we either went over the cached tokens or @@ -477,6 +468,9 @@ void Parser::ParseLexedMethodDef(LexedMethod &LM) { while (Tok.getLocation() != origLoc && Tok.isNot(tok::eof)) ConsumeAnyToken(); } + + if (CXXMethodDecl *MD = dyn_cast_or_null<CXXMethodDecl>(LM.D)) + Actions.ActOnFinishInlineMethodDef(MD); } /// ParseLexedMemberInitializers - We finished parsing the member specification @@ -536,10 +530,13 @@ void Parser::ParseLexedMemberInitializer(LateParsedMemberInitializer &MI) { SourceLocation EqualLoc; + Actions.ActOnStartCXXInClassMemberInitializer(); + ExprResult Init = ParseCXXMemberInitializer(MI.Field, /*IsFunction=*/false, EqualLoc); - Actions.ActOnCXXInClassMemberInitializer(MI.Field, EqualLoc, Init.release()); + Actions.ActOnFinishCXXInClassMemberInitializer(MI.Field, EqualLoc, + Init.get()); // The next token should be our artificial terminating EOF token. if (Tok.isNot(tok::eof)) { @@ -580,6 +577,9 @@ bool Parser::ConsumeAndStoreUntil(tok::TokenKind T1, tok::TokenKind T2, switch (Tok.getKind()) { case tok::eof: + case tok::annot_module_begin: + case tok::annot_module_end: + case tok::annot_module_include: // Ran out of tokens. return false; @@ -675,7 +675,7 @@ bool Parser::ConsumeAndStoreFunctionPrologue(CachedTokens &Toks) { /*StopAtSemi=*/true, /*ConsumeFinalToken=*/false); if (Tok.isNot(tok::l_brace)) - return Diag(Tok.getLocation(), diag::err_expected_lbrace); + return Diag(Tok.getLocation(), diag::err_expected) << tok::l_brace; Toks.push_back(Tok); ConsumeBrace(); @@ -708,8 +708,8 @@ bool Parser::ConsumeAndStoreFunctionPrologue(CachedTokens &Toks) { Toks.push_back(Tok); ConsumeParen(); if (!ConsumeAndStoreUntil(tok::r_paren, Toks, /*StopAtSemi=*/true)) { - Diag(Tok.getLocation(), diag::err_expected_rparen); - Diag(OpenLoc, diag::note_matching) << "("; + Diag(Tok.getLocation(), diag::err_expected) << tok::r_paren; + Diag(OpenLoc, diag::note_matching) << tok::l_paren; return true; } } @@ -756,13 +756,15 @@ bool Parser::ConsumeAndStoreFunctionPrologue(CachedTokens &Toks) { /*ConsumeFinalToken=*/false)) { // We're not just missing the initializer, we're also missing the // function body! - return Diag(Tok.getLocation(), diag::err_expected_lbrace); + return Diag(Tok.getLocation(), diag::err_expected) << tok::l_brace; } } else if (Tok.isNot(tok::l_paren) && Tok.isNot(tok::l_brace)) { // We found something weird in a mem-initializer-id. - return Diag(Tok.getLocation(), getLangOpts().CPlusPlus11 - ? diag::err_expected_lparen_or_lbrace - : diag::err_expected_lparen); + if (getLangOpts().CPlusPlus11) + return Diag(Tok.getLocation(), diag::err_expected_either) + << tok::l_paren << tok::l_brace; + else + return Diag(Tok.getLocation(), diag::err_expected) << tok::l_paren; } tok::TokenKind kind = Tok.getKind(); @@ -784,11 +786,10 @@ bool Parser::ConsumeAndStoreFunctionPrologue(CachedTokens &Toks) { // Grab the initializer (or the subexpression of the template argument). // FIXME: If we support lambdas here, we'll need to set StopAtSemi to false // if we might be inside the braces of a lambda-expression. - if (!ConsumeAndStoreUntil(IsLParen ? tok::r_paren : tok::r_brace, - Toks, /*StopAtSemi=*/true)) { - Diag(Tok, IsLParen ? diag::err_expected_rparen : - diag::err_expected_rbrace); - Diag(OpenLoc, diag::note_matching) << (IsLParen ? "(" : "{"); + tok::TokenKind CloseKind = IsLParen ? tok::r_paren : tok::r_brace; + if (!ConsumeAndStoreUntil(CloseKind, Toks, /*StopAtSemi=*/true)) { + Diag(Tok, diag::err_expected) << CloseKind; + Diag(OpenLoc, diag::note_matching) << kind; return true; } @@ -822,7 +823,8 @@ bool Parser::ConsumeAndStoreFunctionPrologue(CachedTokens &Toks) { ConsumeBrace(); return false; } else if (!MightBeTemplateArgument) { - return Diag(Tok.getLocation(), diag::err_expected_lbrace_or_comma); + return Diag(Tok.getLocation(), diag::err_expected_either) << tok::l_brace + << tok::comma; } } } @@ -836,8 +838,9 @@ bool Parser::ConsumeAndStoreConditional(CachedTokens &Toks) { ConsumeToken(); while (Tok.isNot(tok::colon)) { - if (!ConsumeAndStoreUntil(tok::question, tok::colon, Toks, /*StopAtSemi*/true, - /*ConsumeFinalToken*/false)) + if (!ConsumeAndStoreUntil(tok::question, tok::colon, Toks, + /*StopAtSemi=*/true, + /*ConsumeFinalToken=*/false)) return false; // If we found a nested conditional, consume it. @@ -925,15 +928,15 @@ bool Parser::ConsumeAndStoreInitializer(CachedTokens &Toks, ? tok::semi : tok::r_paren); Sema::TentativeAnalysisScope Scope(Actions); - TPResult Result = TPResult::Error(); + TPResult Result = TPResult::Error; ConsumeToken(); switch (CIK) { case CIK_DefaultInitializer: Result = TryParseInitDeclaratorList(); // If we parsed a complete, ambiguous init-declarator-list, this // is only syntactically-valid if it's followed by a semicolon. - if (Result == TPResult::Ambiguous() && Tok.isNot(tok::semi)) - Result = TPResult::False(); + if (Result == TPResult::Ambiguous && Tok.isNot(tok::semi)) + Result = TPResult::False; break; case CIK_DefaultArgument: @@ -942,13 +945,13 @@ bool Parser::ConsumeAndStoreInitializer(CachedTokens &Toks, &InvalidAsDeclaration, /*VersusTemplateArgument*/true); // If this is an expression or a declaration with a missing // 'typename', assume it's not a declaration. - if (Result == TPResult::Ambiguous() && InvalidAsDeclaration) - Result = TPResult::False(); + if (Result == TPResult::Ambiguous && InvalidAsDeclaration) + Result = TPResult::False; break; } // If what follows could be a declaration, it is a declaration. - if (Result != TPResult::False() && Result != TPResult::Error()) { + if (Result != TPResult::False && Result != TPResult::Error) { PA.Revert(); return true; } @@ -965,6 +968,9 @@ bool Parser::ConsumeAndStoreInitializer(CachedTokens &Toks, goto consume_token; case tok::eof: + case tok::annot_module_begin: + case tok::annot_module_end: + case tok::annot_module_include: // Ran out of tokens. return false; |