diff options
Diffstat (limited to 'contrib/llvm/tools/clang/lib/Parse/ParseDeclCXX.cpp')
-rw-r--r-- | contrib/llvm/tools/clang/lib/Parse/ParseDeclCXX.cpp | 161 |
1 files changed, 82 insertions, 79 deletions
diff --git a/contrib/llvm/tools/clang/lib/Parse/ParseDeclCXX.cpp b/contrib/llvm/tools/clang/lib/Parse/ParseDeclCXX.cpp index 53e4a41..47778b8 100644 --- a/contrib/llvm/tools/clang/lib/Parse/ParseDeclCXX.cpp +++ b/contrib/llvm/tools/clang/lib/Parse/ParseDeclCXX.cpp @@ -685,7 +685,7 @@ Decl *Parser::ParseUsingDeclaration(unsigned Context, /// _Static_assert ( constant-expression , string-literal ) ; /// Decl *Parser::ParseStaticAssertDeclaration(SourceLocation &DeclEnd){ - assert((Tok.is(tok::kw_static_assert) || Tok.is(tok::kw__Static_assert)) && + assert(Tok.isOneOf(tok::kw_static_assert, tok::kw__Static_assert) && "Not a static_assert declaration"); if (Tok.is(tok::kw__Static_assert) && !getLangOpts().C11) @@ -753,7 +753,7 @@ Decl *Parser::ParseStaticAssertDeclaration(SourceLocation &DeclEnd){ /// 'decltype' ( 'auto' ) [C++1y] /// SourceLocation Parser::ParseDecltypeSpecifier(DeclSpec &DS) { - assert((Tok.is(tok::kw_decltype) || Tok.is(tok::annot_decltype)) + assert(Tok.isOneOf(tok::kw_decltype, tok::annot_decltype) && "Not a decltype specifier"); ExprResult Result; @@ -943,7 +943,7 @@ TypeResult Parser::ParseBaseTypeSpecifier(SourceLocation &BaseLoc, // Parse decltype-specifier // tok == kw_decltype is just error recovery, it can only happen when SS // isn't empty - if (Tok.is(tok::kw_decltype) || Tok.is(tok::annot_decltype)) { + if (Tok.isOneOf(tok::kw_decltype, tok::annot_decltype)) { if (SS.isNotEmpty()) Diag(SS.getBeginLoc(), diag::err_unexpected_scope_on_base_decltype) << FixItHint::CreateRemoval(SS.getRange()); @@ -1058,9 +1058,9 @@ TypeResult Parser::ParseBaseTypeSpecifier(SourceLocation &BaseLoc, } void Parser::ParseMicrosoftInheritanceClassAttributes(ParsedAttributes &attrs) { - while (Tok.is(tok::kw___single_inheritance) || - Tok.is(tok::kw___multiple_inheritance) || - Tok.is(tok::kw___virtual_inheritance)) { + while (Tok.isOneOf(tok::kw___single_inheritance, + tok::kw___multiple_inheritance, + tok::kw___virtual_inheritance)) { IdentifierInfo *AttrName = Tok.getIdentifierInfo(); SourceLocation AttrNameLoc = ConsumeToken(); attrs.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0, @@ -1232,9 +1232,9 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind, MaybeParseMicrosoftDeclSpecs(attrs); // Parse inheritance specifiers. - if (Tok.is(tok::kw___single_inheritance) || - Tok.is(tok::kw___multiple_inheritance) || - Tok.is(tok::kw___virtual_inheritance)) + if (Tok.isOneOf(tok::kw___single_inheritance, + tok::kw___multiple_inheritance, + tok::kw___virtual_inheritance)) ParseMicrosoftInheritanceClassAttributes(attrs); // If C++0x attributes exist here, parse them. @@ -1250,55 +1250,55 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind, Tok.isNot(tok::identifier) && !Tok.isAnnotation() && Tok.getIdentifierInfo() && - (Tok.is(tok::kw___is_abstract) || - Tok.is(tok::kw___is_arithmetic) || - Tok.is(tok::kw___is_array) || - Tok.is(tok::kw___is_base_of) || - Tok.is(tok::kw___is_class) || - Tok.is(tok::kw___is_complete_type) || - Tok.is(tok::kw___is_compound) || - Tok.is(tok::kw___is_const) || - Tok.is(tok::kw___is_constructible) || - Tok.is(tok::kw___is_convertible) || - Tok.is(tok::kw___is_convertible_to) || - Tok.is(tok::kw___is_destructible) || - Tok.is(tok::kw___is_empty) || - Tok.is(tok::kw___is_enum) || - Tok.is(tok::kw___is_floating_point) || - Tok.is(tok::kw___is_final) || - Tok.is(tok::kw___is_function) || - Tok.is(tok::kw___is_fundamental) || - Tok.is(tok::kw___is_integral) || - Tok.is(tok::kw___is_interface_class) || - Tok.is(tok::kw___is_literal) || - Tok.is(tok::kw___is_lvalue_expr) || - Tok.is(tok::kw___is_lvalue_reference) || - Tok.is(tok::kw___is_member_function_pointer) || - Tok.is(tok::kw___is_member_object_pointer) || - Tok.is(tok::kw___is_member_pointer) || - Tok.is(tok::kw___is_nothrow_assignable) || - Tok.is(tok::kw___is_nothrow_constructible) || - Tok.is(tok::kw___is_nothrow_destructible) || - Tok.is(tok::kw___is_object) || - Tok.is(tok::kw___is_pod) || - Tok.is(tok::kw___is_pointer) || - Tok.is(tok::kw___is_polymorphic) || - Tok.is(tok::kw___is_reference) || - Tok.is(tok::kw___is_rvalue_expr) || - Tok.is(tok::kw___is_rvalue_reference) || - Tok.is(tok::kw___is_same) || - Tok.is(tok::kw___is_scalar) || - Tok.is(tok::kw___is_sealed) || - Tok.is(tok::kw___is_signed) || - Tok.is(tok::kw___is_standard_layout) || - Tok.is(tok::kw___is_trivial) || - Tok.is(tok::kw___is_trivially_assignable) || - Tok.is(tok::kw___is_trivially_constructible) || - Tok.is(tok::kw___is_trivially_copyable) || - Tok.is(tok::kw___is_union) || - Tok.is(tok::kw___is_unsigned) || - Tok.is(tok::kw___is_void) || - Tok.is(tok::kw___is_volatile))) + Tok.isOneOf(tok::kw___is_abstract, + tok::kw___is_arithmetic, + tok::kw___is_array, + tok::kw___is_base_of, + tok::kw___is_class, + tok::kw___is_complete_type, + tok::kw___is_compound, + tok::kw___is_const, + tok::kw___is_constructible, + tok::kw___is_convertible, + tok::kw___is_convertible_to, + tok::kw___is_destructible, + tok::kw___is_empty, + tok::kw___is_enum, + tok::kw___is_floating_point, + tok::kw___is_final, + tok::kw___is_function, + tok::kw___is_fundamental, + tok::kw___is_integral, + tok::kw___is_interface_class, + tok::kw___is_literal, + tok::kw___is_lvalue_expr, + tok::kw___is_lvalue_reference, + tok::kw___is_member_function_pointer, + tok::kw___is_member_object_pointer, + tok::kw___is_member_pointer, + tok::kw___is_nothrow_assignable, + tok::kw___is_nothrow_constructible, + tok::kw___is_nothrow_destructible, + tok::kw___is_object, + tok::kw___is_pod, + tok::kw___is_pointer, + tok::kw___is_polymorphic, + tok::kw___is_reference, + tok::kw___is_rvalue_expr, + tok::kw___is_rvalue_reference, + tok::kw___is_same, + tok::kw___is_scalar, + tok::kw___is_sealed, + tok::kw___is_signed, + tok::kw___is_standard_layout, + tok::kw___is_trivial, + tok::kw___is_trivially_assignable, + tok::kw___is_trivially_constructible, + tok::kw___is_trivially_copyable, + tok::kw___is_union, + tok::kw___is_unsigned, + tok::kw___is_void, + tok::kw___is_volatile)) // GNU libstdc++ 4.2 and libc++ use certain intrinsic names as the // name of struct templates, but some are keywords in GCC >= 4.3 // and Clang. Therefore, when we see the token sequence "struct @@ -1476,7 +1476,7 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind, } } - if (Tok.is(tok::l_brace) || Tok.is(tok::colon)) + if (Tok.isOneOf(tok::l_brace, tok::colon)) TUK = Sema::TUK_Definition; else TUK = Sema::TUK_Reference; @@ -2220,8 +2220,7 @@ void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS, // Access declarations. bool MalformedTypeSpec = false; if (!TemplateInfo.Kind && - (Tok.is(tok::identifier) || Tok.is(tok::coloncolon) || - Tok.is(tok::kw___super))) { + Tok.isOneOf(tok::identifier, tok::coloncolon, tok::kw___super)) { if (TryAnnotateCXXScopeToken()) MalformedTypeSpec = true; @@ -2274,7 +2273,7 @@ void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS, // static_assert-declaration. A templated static_assert declaration is // diagnosed in Parser::ParseSingleDeclarationAfterTemplate. if (!TemplateInfo.Kind && - (Tok.is(tok::kw_static_assert) || Tok.is(tok::kw__Static_assert))) { + Tok.isOneOf(tok::kw_static_assert, tok::kw__Static_assert)) { SourceLocation DeclEnd; ParseStaticAssertDeclaration(DeclEnd); return; @@ -2411,7 +2410,7 @@ void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS, if (Tok.is(tok::l_brace) && !getLangOpts().CPlusPlus11) { DefinitionKind = FDK_Definition; } else if (DeclaratorInfo.isFunctionDeclarator()) { - if (Tok.is(tok::l_brace) || Tok.is(tok::colon) || Tok.is(tok::kw_try)) { + if (Tok.isOneOf(tok::l_brace, tok::colon, tok::kw_try)) { DefinitionKind = FDK_Definition; } else if (Tok.is(tok::equal)) { const Token &KW = NextToken(); @@ -2480,7 +2479,7 @@ void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS, while (1) { InClassInitStyle HasInClassInit = ICIS_NoInit; - if ((Tok.is(tok::equal) || Tok.is(tok::l_brace)) && !HasInitializer) { + if (Tok.isOneOf(tok::equal, tok::l_brace) && !HasInitializer) { if (BitfieldSize.get()) { Diag(Tok, diag::err_bitfield_member_init); SkipUntil(tok::comma, StopAtSemi | StopBeforeMatch); @@ -2657,7 +2656,7 @@ void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS, /// be a constant-expression. ExprResult Parser::ParseCXXMemberInitializer(Decl *D, bool IsFunction, SourceLocation &EqualLoc) { - assert((Tok.is(tok::equal) || Tok.is(tok::l_brace)) + assert(Tok.isOneOf(tok::equal, tok::l_brace) && "Data member initializer not starting with '=' or '{'"); EnterExpressionEvaluationContext Context(Actions, @@ -2671,8 +2670,7 @@ ExprResult Parser::ParseCXXMemberInitializer(Decl *D, bool IsFunction, // An initializer of '= delete p, foo' will never be parsed, because // a top-level comma always ends the initializer expression. const Token &Next = NextToken(); - if (IsFunction || Next.is(tok::semi) || Next.is(tok::comma) || - Next.is(tok::eof)) { + if (IsFunction || Next.isOneOf(tok::semi, tok::comma, tok::eof)) { if (IsFunction) Diag(ConsumeToken(), diag::err_default_delete_in_multiple_declaration) << 1 /* delete */; @@ -2724,12 +2722,13 @@ void Parser::SkipCXXMemberSpecification(SourceLocation RecordLoc, ParseScope ClassScope(this, Scope::ClassScope|Scope::DeclScope); ParsingClassDefinition ParsingDef(*this, TagDecl, /*NonNestedClass*/ true, TagType == DeclSpec::TST_interface); - Actions.ActOnTagStartSkippedDefinition(getCurScope(), TagDecl); + auto OldContext = + Actions.ActOnTagStartSkippedDefinition(getCurScope(), TagDecl); // Parse the bases but don't attach them to the class. ParseBaseClause(nullptr); - Actions.ActOnTagFinishSkippedDefinition(); + Actions.ActOnTagFinishSkippedDefinition(OldContext); if (!Tok.is(tok::l_brace)) { Diag(PP.getLocForEndOfToken(PrevTokLocation), @@ -2915,8 +2914,8 @@ void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc, while (Tok.isNot(tok::r_brace) && !isEofOrEom()) { // Each iteration of this loop reads one member-declaration. - if (getLangOpts().MicrosoftExt && (Tok.is(tok::kw___if_exists) || - Tok.is(tok::kw___if_not_exists))) { + if (getLangOpts().MicrosoftExt && Tok.isOneOf(tok::kw___if_exists, + tok::kw___if_not_exists)) { ParseMicrosoftIfExistsClassDeclaration((DeclSpec::TST)TagType, CurAS); continue; } @@ -3127,7 +3126,7 @@ void Parser::ParseConstructorInitializer(Decl *ConstructorDecl) { break; // If the next token looks like a base or member initializer, assume that // we're just missing a comma. - else if (Tok.is(tok::identifier) || Tok.is(tok::coloncolon)) { + else if (Tok.isOneOf(tok::identifier, tok::coloncolon)) { SourceLocation Loc = PP.getLocForEndOfToken(PrevTokLocation); Diag(Loc, diag::err_ctor_init_missing_comma) << FixItHint::CreateInsertion(Loc, ", "); @@ -3779,7 +3778,7 @@ SourceLocation Parser::SkipCXX11Attributes() { return EndLoc; } -/// ParseMicrosoftAttributes - Parse a Microsoft attribute [Attr] +/// Parse one or more Microsoft-style attributes [Attr] /// /// [MS] ms-attribute: /// '[' token-seq ']' @@ -3791,13 +3790,17 @@ void Parser::ParseMicrosoftAttributes(ParsedAttributes &attrs, SourceLocation *endLoc) { assert(Tok.is(tok::l_square) && "Not a Microsoft attribute list"); - while (Tok.is(tok::l_square)) { + do { // FIXME: If this is actually a C++11 attribute, parse it as one. - ConsumeBracket(); + BalancedDelimiterTracker T(*this, tok::l_square); + T.consumeOpen(); + if (Tok.is(tok::r_square)) + Diag(T.getOpenLocation(), diag::err_empty_attribute_block); SkipUntil(tok::r_square, StopAtSemi | StopBeforeMatch); - if (endLoc) *endLoc = Tok.getLocation(); - ExpectAndConsume(tok::r_square); - } + T.consumeClose(); + if (endLoc) + *endLoc = T.getCloseLocation(); + } while (Tok.is(tok::l_square)); } void Parser::ParseMicrosoftIfExistsClassDeclaration(DeclSpec::TST TagType, @@ -3829,7 +3832,7 @@ void Parser::ParseMicrosoftIfExistsClassDeclaration(DeclSpec::TST TagType, while (Tok.isNot(tok::r_brace) && !isEofOrEom()) { // __if_exists, __if_not_exists can nest. - if ((Tok.is(tok::kw___if_exists) || Tok.is(tok::kw___if_not_exists))) { + if (Tok.isOneOf(tok::kw___if_exists, tok::kw___if_not_exists)) { ParseMicrosoftIfExistsClassDeclaration((DeclSpec::TST)TagType, CurAS); continue; } |