diff options
author | Alp Toker <alp@nuanti.com> | 2014-01-22 07:29:52 +0000 |
---|---|---|
committer | Alp Toker <alp@nuanti.com> | 2014-01-22 07:29:52 +0000 |
commit | 296a4e54995407cf7e3602b29d28ffd001d15e23 (patch) | |
tree | d39e4e5fb8f8dfa316fdb3e4da74073fb4f1fedb /lib/Parse/ParseCXXInlineMethods.cpp | |
parent | 8a4d3a8337a6c91f2ae6613f67caff9e04d45811 (diff) |
Introduce and use Decl::getAsFunction() to simplify templated function checks
Lift the getFunctionDecl() utility out of the parser into a general
Decl::getAsFunction() and use it to simplify other parts of the implementation.
Reduce isFunctionOrFunctionTemplate() to a simple type check that works the
same was as the other is* functions and move unwrapping of shadowed decls to
callers so it doesn't get run twice.
Shuffle around canSkipFunctionBody() to reduce virtual dispatch on ASTConsumer.
There's no need to query when we already know the body can't be skipped.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199794 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/ParseCXXInlineMethods.cpp')
-rw-r--r-- | lib/Parse/ParseCXXInlineMethods.cpp | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/lib/Parse/ParseCXXInlineMethods.cpp b/lib/Parse/ParseCXXInlineMethods.cpp index 2fc705bc0f..a4b60992a5 100644 --- a/lib/Parse/ParseCXXInlineMethods.cpp +++ b/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. @@ -109,9 +102,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()->getResultType()->getContainedAutoType()) && ((Actions.CurContext->isDependentContext() || (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate && TemplateInfo.Kind != ParsedTemplateInfo::ExplicitSpecialization)) && @@ -121,7 +114,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); } @@ -173,7 +166,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); } @@ -456,7 +449,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 |