From f58822d3b88a6af2d2f27f5e5cbf1ecab02552f2 Mon Sep 17 00:00:00 2001 From: Alp Toker Date: Thu, 9 Jan 2014 00:13:52 +0000 Subject: [PATCH] Implement isCXX11FinalKeyword() in terms of isCXX11VirtSpecifier() It's not worth keeping two copies of the identifier init and comparison code just to save a pointer coparison. This should reduce further once we get proper contextual keywords in the token stream, so having the identifier checks in one place is a step towards that. Cleanup only. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@198814 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Parse/ParseDeclCXX.cpp | 53 ++++++++++++++------------------------ 1 file changed, 19 insertions(+), 34 deletions(-) diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index 1fbc0adeb9..e64da87728 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -1817,29 +1817,27 @@ void Parser::HandleMemberFunctionDeclDelays(Declarator& DeclaratorInfo, /// override /// final VirtSpecifiers::Specifier Parser::isCXX11VirtSpecifier(const Token &Tok) const { - if (!getLangOpts().CPlusPlus) + if (!getLangOpts().CPlusPlus || Tok.isNot(tok::identifier)) return VirtSpecifiers::VS_None; - if (Tok.is(tok::identifier)) { - IdentifierInfo *II = Tok.getIdentifierInfo(); + IdentifierInfo *II = Tok.getIdentifierInfo(); - // Initialize the contextual keywords. - if (!Ident_final) { - Ident_final = &PP.getIdentifierTable().get("final"); - if (getLangOpts().MicrosoftExt) - Ident_sealed = &PP.getIdentifierTable().get("sealed"); - Ident_override = &PP.getIdentifierTable().get("override"); - } + // Initialize the contextual keywords. + if (!Ident_final) { + Ident_final = &PP.getIdentifierTable().get("final"); + if (getLangOpts().MicrosoftExt) + Ident_sealed = &PP.getIdentifierTable().get("sealed"); + Ident_override = &PP.getIdentifierTable().get("override"); + } - if (II == Ident_override) - return VirtSpecifiers::VS_Override; + if (II == Ident_override) + return VirtSpecifiers::VS_Override; - if (II == Ident_sealed) - return VirtSpecifiers::VS_Sealed; + if (II == Ident_sealed) + return VirtSpecifiers::VS_Sealed; - if (II == Ident_final) - return VirtSpecifiers::VS_Final; - } + if (II == Ident_final) + return VirtSpecifiers::VS_Final; return VirtSpecifiers::VS_None; } @@ -1882,24 +1880,11 @@ void Parser::ParseOptionalCXX11VirtSpecifierSeq(VirtSpecifiers &VS, } /// isCXX11FinalKeyword - Determine whether the next token is a C++11 -/// contextual 'final' keyword. +/// 'final' or Microsoft 'sealed' contextual keyword. bool Parser::isCXX11FinalKeyword() const { - if (!getLangOpts().CPlusPlus) - return false; - - if (!Tok.is(tok::identifier)) - return false; - - // Initialize the contextual keywords. - if (!Ident_final) { - Ident_final = &PP.getIdentifierTable().get("final"); - if (getLangOpts().MicrosoftExt) - Ident_sealed = &PP.getIdentifierTable().get("sealed"); - Ident_override = &PP.getIdentifierTable().get("override"); - } - - return Tok.getIdentifierInfo() == Ident_final || - Tok.getIdentifierInfo() == Ident_sealed; + VirtSpecifiers::Specifier Specifier = isCXX11VirtSpecifier(); + return Specifier == VirtSpecifiers::VS_Final || + Specifier == VirtSpecifiers::VS_Sealed; } /// ParseCXXClassMemberDeclaration - Parse a C++ class member declaration. -- 2.40.0