diff options
| author | 2017-01-14 19:55:43 +0000 | |
|---|---|---|
| committer | 2017-01-14 19:55:43 +0000 | |
| commit | bd3306aecb3a15e8967143b8cdbbccf2b1b19b74 (patch) | |
| tree | 309a8132b44564b9e634c0da6815187ce8eab27c /gnu/llvm/tools/clang/lib/Parse/ParseObjc.cpp | |
| parent | killp -a should not kill the window if only one pane. (diff) | |
| download | wireguard-openbsd-bd3306aecb3a15e8967143b8cdbbccf2b1b19b74.tar.xz wireguard-openbsd-bd3306aecb3a15e8967143b8cdbbccf2b1b19b74.zip | |
Import LLVM 3.9.1 including clang and lld.
Diffstat (limited to 'gnu/llvm/tools/clang/lib/Parse/ParseObjc.cpp')
| -rw-r--r-- | gnu/llvm/tools/clang/lib/Parse/ParseObjc.cpp | 201 |
1 files changed, 132 insertions, 69 deletions
diff --git a/gnu/llvm/tools/clang/lib/Parse/ParseObjc.cpp b/gnu/llvm/tools/clang/lib/Parse/ParseObjc.cpp index e72a1f62f94..67abe5839bf 100644 --- a/gnu/llvm/tools/clang/lib/Parse/ParseObjc.cpp +++ b/gnu/llvm/tools/clang/lib/Parse/ParseObjc.cpp @@ -21,6 +21,7 @@ #include "clang/Sema/Scope.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" + using namespace clang; /// Skips attributes after an Objective-C @ directive. Emits a diagnostic. @@ -50,7 +51,7 @@ Parser::DeclGroupPtrTy Parser::ParseObjCAtDirectives() { if (Tok.is(tok::code_completion)) { Actions.CodeCompleteObjCAtDirective(getCurScope()); cutOffParsing(); - return DeclGroupPtrTy(); + return nullptr; } Decl *SingleDecl = nullptr; @@ -99,16 +100,20 @@ class Parser::ObjCTypeParamListScope { Sema &Actions; Scope *S; ObjCTypeParamList *Params; + public: ObjCTypeParamListScope(Sema &Actions, Scope *S) : Actions(Actions), S(S), Params(nullptr) {} + ~ObjCTypeParamListScope() { leave(); } + void enter(ObjCTypeParamList *P) { assert(!Params); Params = P; } + void leave() { if (Params) Actions.popObjCTypeParamList(S, Params); @@ -334,16 +339,11 @@ Decl *Parser::ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc, // Type arguments for the superclass or protocol conformances. if (Tok.is(tok::less)) { - parseObjCTypeArgsOrProtocolQualifiers(ParsedType(), - typeArgsLAngleLoc, - typeArgs, - typeArgsRAngleLoc, - LAngleLoc, - protocols, - protocolLocs, - EndProtoLoc, - /*consumeLastToken=*/true, - /*warnOnIncompleteProtocols=*/true); + parseObjCTypeArgsOrProtocolQualifiers( + nullptr, typeArgsLAngleLoc, typeArgs, typeArgsRAngleLoc, LAngleLoc, + protocols, protocolLocs, EndProtoLoc, + /*consumeLastToken=*/true, + /*warnOnIncompleteProtocols=*/true); } } @@ -459,14 +459,8 @@ ObjCTypeParamList *Parser::parseObjCTypeParamListOrProtocolRefs( unsigned index = 0; for (const auto &pair : protocolIdents) { DeclResult typeParam = Actions.actOnObjCTypeParam( - getCurScope(), - ObjCTypeParamVariance::Invariant, - SourceLocation(), - index++, - pair.first, - pair.second, - SourceLocation(), - ParsedType()); + getCurScope(), ObjCTypeParamVariance::Invariant, SourceLocation(), + index++, pair.first, pair.second, SourceLocation(), nullptr); if (typeParam.isUsable()) typeParams.push_back(typeParam.get()); } @@ -542,16 +536,9 @@ ObjCTypeParamList *Parser::parseObjCTypeParamListOrProtocolRefs( } // Create the type parameter. - DeclResult typeParam = Actions.actOnObjCTypeParam(getCurScope(), - variance, - varianceLoc, - typeParams.size(), - paramName, - paramLoc, - colonLoc, - boundType.isUsable() - ? boundType.get() - : ParsedType()); + DeclResult typeParam = Actions.actOnObjCTypeParam( + getCurScope(), variance, varianceLoc, typeParams.size(), paramName, + paramLoc, colonLoc, boundType.isUsable() ? boundType.get() : nullptr); if (typeParam.isUsable()) typeParams.push_back(typeParam.get()); } while (TryConsumeToken(tok::comma)); @@ -865,6 +852,7 @@ static void diagnoseRedundantPropertyNullability(Parser &P, /// nullable /// null_unspecified /// null_resettable +/// class /// void Parser::ParseObjCPropertyAttribute(ObjCDeclSpec &DS) { assert(Tok.getKind() == tok::l_paren); @@ -980,6 +968,8 @@ void Parser::ParseObjCPropertyAttribute(ObjCDeclSpec &DS) { // Also set the null_resettable bit. DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_null_resettable); + } else if (II->isStr("class")) { + DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_class); } else { Diag(AttrName, diag::err_objc_expected_property_attr) << II; SkipUntil(tok::r_paren, StopAtSemi); @@ -1287,7 +1277,6 @@ ParsedType Parser::ParseObjCTypeName(ObjCDeclSpec &DS, if (context == Declarator::ObjCResultContext) dsContext = DSC_objc_method_result; ParseSpecifierQualifierList(declSpec, AS_none, dsContext); - declSpec.SetRangeEnd(Tok.getLocation()); Declarator declarator(declSpec, context); ParseDeclarator(declarator); @@ -1361,8 +1350,8 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc, ParsingDeclRAIIObject PD(*this, ParsingDeclRAIIObject::NoParent); if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus, - /*ReturnType=*/ ParsedType()); + Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus, + /*ReturnType=*/nullptr); cutOffParsing(); return nullptr; } @@ -1432,7 +1421,7 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc, if (ExpectAndConsume(tok::colon)) break; - ArgInfo.Type = ParsedType(); + ArgInfo.Type = nullptr; if (Tok.is(tok::l_paren)) // Parse the argument type if present. ArgInfo.Type = ParseObjCTypeName(ArgInfo.DeclSpec, Declarator::ObjCParameterContext, @@ -1703,11 +1692,18 @@ void Parser::parseObjCTypeArgsOrProtocolQualifiers( return; } - // We syntactically matched a type argument, so commit to parsing - // type arguments. + // We parsed an identifier list but stumbled into non single identifiers, this + // means we might (a) check that what we already parsed is a legitimate type + // (not a protocol or unknown type) and (b) parse the remaining ones, which + // must all be type args. // Convert the identifiers into type arguments. bool invalid = false; + IdentifierInfo *foundProtocolId = nullptr, *foundValidTypeId = nullptr; + SourceLocation foundProtocolSrcLoc, foundValidTypeSrcLoc; + SmallVector<IdentifierInfo *, 2> unknownTypeArgs; + SmallVector<SourceLocation, 2> unknownTypeArgsLoc; + for (unsigned i = 0, n = identifiers.size(); i != n; ++i) { ParsedType typeArg = Actions.getTypeName(*identifiers[i], identifierLocs[i], getCurScope()); @@ -1721,17 +1717,32 @@ void Parser::parseObjCTypeArgsOrProtocolQualifiers( // Form a declarator to turn this into a type. Declarator D(DS, Declarator::TypeNameContext); TypeResult fullTypeArg = Actions.ActOnTypeName(getCurScope(), D); - if (fullTypeArg.isUsable()) + if (fullTypeArg.isUsable()) { typeArgs.push_back(fullTypeArg.get()); - else + if (!foundValidTypeId) { + foundValidTypeId = identifiers[i]; + foundValidTypeSrcLoc = identifierLocs[i]; + } + } else { invalid = true; + unknownTypeArgs.push_back(identifiers[i]); + unknownTypeArgsLoc.push_back(identifierLocs[i]); + } } else { invalid = true; + if (!Actions.LookupProtocol(identifiers[i], identifierLocs[i])) { + unknownTypeArgs.push_back(identifiers[i]); + unknownTypeArgsLoc.push_back(identifierLocs[i]); + } else if (!foundProtocolId) { + foundProtocolId = identifiers[i]; + foundProtocolSrcLoc = identifierLocs[i]; + } } } // Continue parsing type-names. do { + Token CurTypeTok = Tok; TypeResult typeArg = ParseTypeName(); // Consume the '...' for a pack expansion. @@ -1743,11 +1754,28 @@ void Parser::parseObjCTypeArgsOrProtocolQualifiers( if (typeArg.isUsable()) { typeArgs.push_back(typeArg.get()); + if (!foundValidTypeId) { + foundValidTypeId = CurTypeTok.getIdentifierInfo(); + foundValidTypeSrcLoc = CurTypeTok.getLocation(); + } } else { invalid = true; } } while (TryConsumeToken(tok::comma)); + // Diagnose the mix between type args and protocols. + if (foundProtocolId && foundValidTypeId) + Actions.DiagnoseTypeArgsAndProtocols(foundProtocolId, foundProtocolSrcLoc, + foundValidTypeId, + foundValidTypeSrcLoc); + + // Diagnose unknown arg types. + ParsedType T; + if (unknownTypeArgs.size()) + for (unsigned i = 0, e = unknownTypeArgsLoc.size(); i < e; ++i) + Actions.DiagnoseUnknownTypeName(unknownTypeArgs[i], unknownTypeArgsLoc[i], + getCurScope(), nullptr, T); + // Parse the closing '>'. SourceLocation rAngleLoc; (void)ParseGreaterThanInTemplateList(rAngleLoc, consumeLastToken, @@ -1976,7 +2004,6 @@ void Parser::ParseObjCClassInstanceVariables(Decl *interfaceDecl, } HelperActionsForIvarDeclarations(interfaceDecl, atLoc, T, AllIvarDecls, false); - return; } /// objc-protocol-declaration: @@ -2005,14 +2032,14 @@ Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc, if (Tok.is(tok::code_completion)) { Actions.CodeCompleteObjCProtocolDecl(getCurScope()); cutOffParsing(); - return DeclGroupPtrTy(); + return nullptr; } MaybeSkipAttributes(tok::objc_protocol); if (Tok.isNot(tok::identifier)) { Diag(Tok, diag::err_expected) << tok::identifier; // missing protocol name. - return DeclGroupPtrTy(); + return nullptr; } // Save the protocol name, then consume it. IdentifierInfo *protocolName = Tok.getIdentifierInfo(); @@ -2036,7 +2063,7 @@ Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc, if (Tok.isNot(tok::identifier)) { Diag(Tok, diag::err_expected) << tok::identifier; SkipUntil(tok::semi); - return DeclGroupPtrTy(); + return nullptr; } ProtocolRefs.push_back(IdentifierLocPair(Tok.getIdentifierInfo(), Tok.getLocation())); @@ -2047,7 +2074,7 @@ Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc, } // Consume the ';'. if (ExpectAndConsume(tok::semi, diag::err_expected_after, "@protocol")) - return DeclGroupPtrTy(); + return nullptr; return Actions.ActOnForwardProtocolDeclaration(AtLoc, ProtocolRefs, attrs.getList()); @@ -2062,7 +2089,7 @@ Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc, ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, false, true, LAngleLoc, EndProtoLoc, /*consumeLastToken=*/true)) - return DeclGroupPtrTy(); + return nullptr; Decl *ProtoType = Actions.ActOnStartProtocolInterface(AtLoc, protocolName, nameLoc, @@ -2096,7 +2123,7 @@ Parser::ParseObjCAtImplementationDeclaration(SourceLocation AtLoc) { if (Tok.is(tok::code_completion)) { Actions.CodeCompleteObjCImplementationDecl(getCurScope()); cutOffParsing(); - return DeclGroupPtrTy(); + return nullptr; } MaybeSkipAttributes(tok::objc_implementation); @@ -2104,7 +2131,7 @@ Parser::ParseObjCAtImplementationDeclaration(SourceLocation AtLoc) { if (Tok.isNot(tok::identifier)) { Diag(Tok, diag::err_expected) << tok::identifier; // missing class or category name. - return DeclGroupPtrTy(); + return nullptr; } // We have a class or category name - consume it. IdentifierInfo *nameId = Tok.getIdentifierInfo(); @@ -2137,7 +2164,7 @@ Parser::ParseObjCAtImplementationDeclaration(SourceLocation AtLoc) { if (Tok.is(tok::code_completion)) { Actions.CodeCompleteObjCImplementationCategory(getCurScope(), nameId, nameLoc); cutOffParsing(); - return DeclGroupPtrTy(); + return nullptr; } if (Tok.is(tok::identifier)) { @@ -2146,12 +2173,12 @@ Parser::ParseObjCAtImplementationDeclaration(SourceLocation AtLoc) { } else { Diag(Tok, diag::err_expected) << tok::identifier; // missing category name. - return DeclGroupPtrTy(); + return nullptr; } if (Tok.isNot(tok::r_paren)) { Diag(Tok, diag::err_expected) << tok::r_paren; SkipUntil(tok::r_paren); // don't stop at ';' - return DeclGroupPtrTy(); + return nullptr; } rparenLoc = ConsumeParen(); if (Tok.is(tok::less)) { // we have illegal '<' try to recover @@ -2178,7 +2205,7 @@ Parser::ParseObjCAtImplementationDeclaration(SourceLocation AtLoc) { if (Tok.isNot(tok::identifier)) { Diag(Tok, diag::err_expected) << tok::identifier; // missing super class name. - return DeclGroupPtrTy(); + return nullptr; } superClassId = Tok.getIdentifierInfo(); superClassLoc = ConsumeToken(); // Consume super class name @@ -2232,7 +2259,7 @@ Parser::ParseObjCAtEndDeclaration(SourceRange atEnd) { else // missing @implementation Diag(atEnd.getBegin(), diag::err_expected_objc_container); - return DeclGroupPtrTy(); + return nullptr; } Parser::ObjCImplParsingDataRAII::~ObjCImplParsingDataRAII() { @@ -2345,8 +2372,10 @@ Decl *Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) { propertyIvar = Tok.getIdentifierInfo(); propertyIvarLoc = ConsumeToken(); // consume ivar-name } - Actions.ActOnPropertyImplDecl(getCurScope(), atLoc, propertyLoc, true, - propertyId, propertyIvar, propertyIvarLoc); + Actions.ActOnPropertyImplDecl( + getCurScope(), atLoc, propertyLoc, true, + propertyId, propertyIvar, propertyIvarLoc, + ObjCPropertyQueryKind::OBJC_PR_query_unknown); if (Tok.isNot(tok::comma)) break; ConsumeToken(); // consume ',' @@ -2366,6 +2395,31 @@ Decl *Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) { assert(Tok.isObjCAtKeyword(tok::objc_dynamic) && "ParseObjCPropertyDynamic(): Expected '@dynamic'"); ConsumeToken(); // consume dynamic + + bool isClassProperty = false; + if (Tok.is(tok::l_paren)) { + ConsumeParen(); + const IdentifierInfo *II = Tok.getIdentifierInfo(); + + if (!II) { + Diag(Tok, diag::err_objc_expected_property_attr) << II; + SkipUntil(tok::r_paren, StopAtSemi); + } else { + SourceLocation AttrName = ConsumeToken(); // consume attribute name + if (II->isStr("class")) { + isClassProperty = true; + if (Tok.isNot(tok::r_paren)) { + Diag(Tok, diag::err_expected) << tok::r_paren; + SkipUntil(tok::r_paren, StopAtSemi); + } else + ConsumeParen(); + } else { + Diag(AttrName, diag::err_objc_expected_property_attr) << II; + SkipUntil(tok::r_paren, StopAtSemi); + } + } + } + while (true) { if (Tok.is(tok::code_completion)) { Actions.CodeCompleteObjCPropertyDefinition(getCurScope()); @@ -2381,8 +2435,11 @@ Decl *Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) { IdentifierInfo *propertyId = Tok.getIdentifierInfo(); SourceLocation propertyLoc = ConsumeToken(); // consume property name - Actions.ActOnPropertyImplDecl(getCurScope(), atLoc, propertyLoc, false, - propertyId, nullptr, SourceLocation()); + Actions.ActOnPropertyImplDecl( + getCurScope(), atLoc, propertyLoc, false, + propertyId, nullptr, SourceLocation(), + isClassProperty ? ObjCPropertyQueryKind::OBJC_PR_query_class : + ObjCPropertyQueryKind::OBJC_PR_query_unknown); if (Tok.isNot(tok::comma)) break; @@ -2599,6 +2656,12 @@ Parser::ParseObjCAutoreleasePoolStmt(SourceLocation atLoc) { /// StashAwayMethodOrFunctionBodyTokens - Consume the tokens and store them /// for later parsing. void Parser::StashAwayMethodOrFunctionBodyTokens(Decl *MDecl) { + if (SkipFunctionBodies && (!MDecl || Actions.canSkipFunctionBody(MDecl)) && + trySkippingFunctionBody()) { + Actions.ActOnSkippedFunctionBody(MDecl); + return; + } + LexedMethod* LM = new LexedMethod(this, MDecl); CurParsedObjCImpl->LateParsedObjCMethods.push_back(LM); CachedTokens &Toks = LM->Toks; @@ -2795,6 +2858,8 @@ ExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) { return ParsePostfixExpressionSuffix(ParseObjCProtocolExpression(AtLoc)); case tok::objc_selector: return ParsePostfixExpressionSuffix(ParseObjCSelectorExpression(AtLoc)); + case tok::objc_available: + return ParseAvailabilityCheckExpr(AtLoc); default: { const char *str = nullptr; if (GetLookAheadToken(1).is(tok::l_brace)) { @@ -2923,7 +2988,6 @@ bool Parser::isStartOfObjCClassMessageMissingOpenBracket() { InMessageExpression) return false; - ParsedType Type; if (Tok.is(tok::annot_typename)) @@ -2977,8 +3041,8 @@ ExprResult Parser::ParseObjCMessageExpression() { // get in Objective-C. if (Tok.is(tok::identifier) && Tok.getIdentifierInfo() == Ident_super && NextToken().isNot(tok::period) && getCurScope()->isInObjcMethodScope()) - return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(), - ParsedType(), nullptr); + return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(), nullptr, + nullptr); // Parse the receiver, which is either a type or an expression. bool IsExpr; @@ -2989,9 +3053,8 @@ ExprResult Parser::ParseObjCMessageExpression() { } if (IsExpr) - return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), - ParsedType(), - static_cast<Expr*>(TypeOrExpr)); + return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), nullptr, + static_cast<Expr *>(TypeOrExpr)); return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), ParsedType::getFromOpaquePtr(TypeOrExpr), @@ -3007,8 +3070,8 @@ ExprResult Parser::ParseObjCMessageExpression() { NextToken().is(tok::period), ReceiverType)) { case Sema::ObjCSuperMessage: - return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(), - ParsedType(), nullptr); + return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(), nullptr, + nullptr); case Sema::ObjCClassMessage: if (!ReceiverType) { @@ -3049,8 +3112,8 @@ ExprResult Parser::ParseObjCMessageExpression() { return Res; } - return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), - ParsedType(), Res.get()); + return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), nullptr, + Res.get()); } /// \brief Parse the remainder of an Objective-C message following the @@ -3553,7 +3616,7 @@ ExprResult Parser::ParseObjCSelectorExpression(SourceLocation AtLoc) { T.getOpenLocation(), T.getCloseLocation(), !HasOptionalParen); - } +} void Parser::ParseLexedObjCMethodDefs(LexedMethod &LM, bool parseMethod) { // MCDecl might be null due to error in method or c-function prototype, etc. @@ -3571,8 +3634,8 @@ void Parser::ParseLexedObjCMethodDefs(LexedMethod &LM, bool parseMethod) { // Append the current token at the end of the new token stream so that it // doesn't get lost. LM.Toks.push_back(Tok); - PP.EnterTokenStream(LM.Toks.data(), LM.Toks.size(), true, false); - + PP.EnterTokenStream(LM.Toks, true); + // Consume the previously pushed token. ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true); @@ -3595,6 +3658,8 @@ void Parser::ParseLexedObjCMethodDefs(LexedMethod &LM, bool parseMethod) { else { if (Tok.is(tok::colon)) ParseConstructorInitializer(MCDecl); + else + Actions.ActOnDefaultCtorInitializers(MCDecl); ParseFunctionStatementBody(MCDecl, BodyScope); } @@ -3609,6 +3674,4 @@ void Parser::ParseLexedObjCMethodDefs(LexedMethod &LM, bool parseMethod) { while (Tok.getLocation() != OrigLoc && Tok.isNot(tok::eof)) ConsumeAnyToken(); } - - return; } |
