diff options
author | Craig Topper <craig.topper@gmail.com> | 2014-05-21 06:02:52 +0000 |
---|---|---|
committer | Craig Topper <craig.topper@gmail.com> | 2014-05-21 06:02:52 +0000 |
commit | d685fc0eccf468b6d16204965b92f7ed65ee62b2 (patch) | |
tree | 0a9e285241c808467d238087ee13c3104974520e /lib/Parse/ParseObjc.cpp | |
parent | d1008e5c93536222903523b70245ec66876bbad5 (diff) | |
download | clang-d685fc0eccf468b6d16204965b92f7ed65ee62b2.tar.gz clang-d685fc0eccf468b6d16204965b92f7ed65ee62b2.tar.bz2 clang-d685fc0eccf468b6d16204965b92f7ed65ee62b2.tar.xz |
[C++11] Use 'nullptr'. Parser edition.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209275 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/ParseObjc.cpp')
-rw-r--r-- | lib/Parse/ParseObjc.cpp | 136 |
1 files changed, 69 insertions, 67 deletions
diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp index 776dbd6eed..2878aa094d 100644 --- a/lib/Parse/ParseObjc.cpp +++ b/lib/Parse/ParseObjc.cpp @@ -51,8 +51,8 @@ Parser::DeclGroupPtrTy Parser::ParseObjCAtDirectives() { cutOffParsing(); return DeclGroupPtrTy(); } - - Decl *SingleDecl = 0; + + Decl *SingleDecl = nullptr; switch (Tok.getObjCKeywordID()) { case tok::objc_class: return ParseObjCAtClassDeclaration(AtLoc); @@ -83,11 +83,11 @@ Parser::DeclGroupPtrTy Parser::ParseObjCAtDirectives() { return ParseModuleImport(AtLoc); Diag(AtLoc, diag::err_atimport); SkipUntil(tok::semi); - return Actions.ConvertDeclToDeclGroup(0); + return Actions.ConvertDeclToDeclGroup(nullptr); default: Diag(AtLoc, diag::err_unexpected_at); SkipUntil(tok::semi); - SingleDecl = 0; + SingleDecl = nullptr; break; } return Actions.ConvertDeclToDeclGroup(SingleDecl); @@ -109,7 +109,7 @@ Parser::ParseObjCAtClassDeclaration(SourceLocation atLoc) { if (Tok.isNot(tok::identifier)) { Diag(Tok, diag::err_expected) << tok::identifier; SkipUntil(tok::semi); - return Actions.ConvertDeclToDeclGroup(0); + return Actions.ConvertDeclToDeclGroup(nullptr); } ClassNames.push_back(Tok.getIdentifierInfo()); ClassLocs.push_back(Tok.getLocation()); @@ -121,7 +121,7 @@ Parser::ParseObjCAtClassDeclaration(SourceLocation atLoc) { // Consume the ';'. if (ExpectAndConsume(tok::semi, diag::err_expected_after, "@class")) - return Actions.ConvertDeclToDeclGroup(0); + return Actions.ConvertDeclToDeclGroup(nullptr); return Actions.ActOnForwardClassDeclaration(atLoc, ClassNames.data(), ClassLocs.data(), @@ -187,7 +187,7 @@ Decl *Parser::ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc, if (Tok.is(tok::code_completion)) { Actions.CodeCompleteObjCInterfaceDecl(getCurScope()); cutOffParsing(); - return 0; + return nullptr; } MaybeSkipAttributes(tok::objc_interface); @@ -195,7 +195,7 @@ Decl *Parser::ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc, if (Tok.isNot(tok::identifier)) { Diag(Tok, diag::err_expected) << tok::identifier; // missing class or category name. - return 0; + return nullptr; } // We have a class or category name - consume it. @@ -208,11 +208,11 @@ Decl *Parser::ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc, T.consumeOpen(); SourceLocation categoryLoc; - IdentifierInfo *categoryId = 0; + IdentifierInfo *categoryId = nullptr; if (Tok.is(tok::code_completion)) { Actions.CodeCompleteObjCInterfaceCategory(getCurScope(), nameId, nameLoc); cutOffParsing(); - return 0; + return nullptr; } // For ObjC2, the category name is optional (not an error). @@ -223,13 +223,13 @@ Decl *Parser::ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc, else if (!getLangOpts().ObjC2) { Diag(Tok, diag::err_expected) << tok::identifier; // missing category name. - return 0; + return nullptr; } T.consumeClose(); if (T.getCloseLocation().isInvalid()) - return 0; - + return nullptr; + if (!attrs.empty()) { // categories don't support attributes. Diag(nameLoc, diag::err_objc_no_attributes_on_category); attrs.clear(); @@ -242,7 +242,7 @@ Decl *Parser::ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc, if (Tok.is(tok::less) && ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true, LAngleLoc, EndProtoLoc)) - return 0; + return nullptr; Decl *CategoryType = Actions.ActOnStartCategoryInterface(AtLoc, @@ -260,7 +260,7 @@ Decl *Parser::ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc, return CategoryType; } // Parse a class interface. - IdentifierInfo *superClassId = 0; + IdentifierInfo *superClassId = nullptr; SourceLocation superClassLoc; if (Tok.is(tok::colon)) { // a super class is specified. @@ -270,13 +270,13 @@ Decl *Parser::ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc, if (Tok.is(tok::code_completion)) { Actions.CodeCompleteObjCSuperclass(getCurScope(), nameId, nameLoc); cutOffParsing(); - return 0; + return nullptr; } if (Tok.isNot(tok::identifier)) { Diag(Tok, diag::err_expected) << tok::identifier; // missing super class name. - return 0; + return nullptr; } superClassId = Tok.getIdentifierInfo(); superClassLoc = ConsumeToken(); @@ -288,7 +288,7 @@ Decl *Parser::ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc, if (Tok.is(tok::less) && ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true, LAngleLoc, EndProtoLoc)) - return 0; + return nullptr; if (Tok.isNot(tok::less)) Actions.ActOnTypedefedProtocols(ProtocolRefs, superClassId, superClassLoc); @@ -330,7 +330,7 @@ public: } void invoke(ParsingFieldDeclarator &FD) override { - if (FD.D.getIdentifier() == 0) { + if (FD.D.getIdentifier() == nullptr) { P.Diag(AtLoc, diag::err_objc_property_requires_field_name) << FD.D.getSourceRange(); return; @@ -577,7 +577,7 @@ void Parser::ParseObjCPropertyAttribute(ObjCDeclSpec &DS) { const IdentifierInfo *II = Tok.getIdentifierInfo(); // If this is not an identifier at all, bail out early. - if (II == 0) { + if (!II) { T.consumeClose(); return; } @@ -698,7 +698,7 @@ IdentifierInfo *Parser::ParseObjCSelectorPiece(SourceLocation &SelectorLoc) { switch (Tok.getKind()) { default: - return 0; + return nullptr; case tok::ampamp: case tok::ampequal: case tok::amp: @@ -717,7 +717,7 @@ IdentifierInfo *Parser::ParseObjCSelectorPiece(SourceLocation &SelectorLoc) { SelectorLoc = ConsumeToken(); return II; } - return 0; + return nullptr; } case tok::identifier: @@ -845,7 +845,7 @@ void Parser::ParseObjCTypeQualifierList(ObjCDeclSpec &DS, } DS.setObjCDeclQualifier(Qual); ConsumeToken(); - II = 0; + II = nullptr; break; } @@ -866,7 +866,7 @@ static void takeDeclAttributes(ParsedAttributes &attrs, // Clear out the next pointer. We're really completely // destroying the internal invariants of the declarator here, // but it doesn't matter because we're done with it. - cur->setNext(0); + cur->setNext(nullptr); attrs.add(cur); } } @@ -897,7 +897,8 @@ ParsedType Parser::ParseObjCTypeName(ObjCDeclSpec &DS, ParsedAttributes *paramAttrs) { assert(context == Declarator::ObjCParameterContext || context == Declarator::ObjCResultContext); - assert((paramAttrs != 0) == (context == Declarator::ObjCParameterContext)); + assert((paramAttrs != nullptr) == + (context == Declarator::ObjCParameterContext)); assert(Tok.is(tok::l_paren) && "expected ("); @@ -994,14 +995,15 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc, Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus, /*ReturnType=*/ ParsedType()); cutOffParsing(); - return 0; + return nullptr; } // Parse the return type if present. ParsedType ReturnType; ObjCDeclSpec DSRet; if (Tok.is(tok::l_paren)) - ReturnType = ParseObjCTypeName(DSRet, Declarator::ObjCResultContext, 0); + ReturnType = ParseObjCTypeName(DSRet, Declarator::ObjCResultContext, + nullptr); // If attributes exist before the method, parse them. ParsedAttributes methodAttrs(AttrFactory); @@ -1012,7 +1014,7 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc, Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus, ReturnType); cutOffParsing(); - return 0; + return nullptr; } // Now parse the selector. @@ -1025,7 +1027,7 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc, << SourceRange(mLoc, Tok.getLocation()); // Skip until we get a ; or @. SkipUntil(tok::at, StopAtSemi | StopBeforeMatch); - return 0; + return nullptr; } SmallVector<DeclaratorChunk::ParamInfo, 8> CParamInfo; @@ -1038,7 +1040,7 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc, Decl *Result = Actions.ActOnMethodDeclaration(getCurScope(), mLoc, Tok.getLocation(), mType, DSRet, ReturnType, - selLoc, Sel, 0, + selLoc, Sel, nullptr, CParamInfo.data(), CParamInfo.size(), methodAttrs.getList(), MethodImplKind, false, MethodDefinition); @@ -1069,7 +1071,7 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc, // If attributes exist before the argument name, parse them. // Regardless, collect all the attributes we've parsed so far. - ArgInfo.ArgAttrs = 0; + ArgInfo.ArgAttrs = nullptr; if (getLangOpts().ObjC2) { MaybeParseGNUAttributes(paramAttrs); ArgInfo.ArgAttrs = paramAttrs.getList(); @@ -1083,7 +1085,7 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc, /*AtParameterName=*/true, ReturnType, KeyIdents); cutOffParsing(); - return 0; + return nullptr; } if (Tok.isNot(tok::identifier)) { @@ -1110,7 +1112,7 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc, /*AtParameterName=*/false, ReturnType, KeyIdents); cutOffParsing(); - return 0; + return nullptr; } // Check for another keyword selector. @@ -1152,7 +1154,7 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc, CParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII, ParmDecl.getIdentifierLoc(), Param, - 0)); + nullptr)); } // FIXME: Add support for optional parameter list... @@ -1161,8 +1163,8 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc, MaybeParseGNUAttributes(methodAttrs); if (KeyIdents.size() == 0) - return 0; - + return nullptr; + Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(), &KeyIdents[0]); Decl *Result @@ -1255,7 +1257,7 @@ void Parser::HelperActionsForIvarDeclarations(Decl *interfaceDecl, SourceLocatio // for code rewriting tools that need to be aware of the empty list. Actions.ActOnFields(getCurScope(), atLoc, interfaceDecl, AllIvarDecls, - T.getOpenLocation(), T.getCloseLocation(), 0); + T.getOpenLocation(), T.getCloseLocation(), nullptr); } /// objc-class-instance-variables: @@ -1510,13 +1512,13 @@ Parser::ParseObjCAtImplementationDeclaration(SourceLocation AtLoc) { // We have a class or category name - consume it. IdentifierInfo *nameId = Tok.getIdentifierInfo(); SourceLocation nameLoc = ConsumeToken(); // consume class or category name - Decl *ObjCImpDecl = 0; + Decl *ObjCImpDecl = nullptr; if (Tok.is(tok::l_paren)) { // we have a category implementation. ConsumeParen(); SourceLocation categoryLoc, rparenLoc; - IdentifierInfo *categoryId = 0; + IdentifierInfo *categoryId = nullptr; if (Tok.is(tok::code_completion)) { Actions.CodeCompleteObjCImplementationCategory(getCurScope(), nameId, nameLoc); @@ -1551,7 +1553,7 @@ Parser::ParseObjCAtImplementationDeclaration(SourceLocation AtLoc) { } else { // We have a class implementation SourceLocation superClassLoc; - IdentifierInfo *superClassId = 0; + IdentifierInfo *superClassId = nullptr; if (TryConsumeToken(tok::colon)) { // We have a super class if (Tok.isNot(tok::identifier)) { @@ -1619,7 +1621,7 @@ Parser::ObjCImplParsingDataRAII::~ObjCImplParsingDataRAII() { << Sema::OCK_Implementation; } } - P.CurParsedObjCImpl = 0; + P.CurParsedObjCImpl = nullptr; assert(LateParsedObjCMethods.empty()); } @@ -1656,13 +1658,13 @@ Decl *Parser::ParseObjCAtAliasDeclaration(SourceLocation atLoc) { ConsumeToken(); // consume compatibility_alias if (Tok.isNot(tok::identifier)) { Diag(Tok, diag::err_expected) << tok::identifier; - return 0; + return nullptr; } IdentifierInfo *aliasId = Tok.getIdentifierInfo(); SourceLocation aliasLoc = ConsumeToken(); // consume alias-name if (Tok.isNot(tok::identifier)) { Diag(Tok, diag::err_expected) << tok::identifier; - return 0; + return nullptr; } IdentifierInfo *classId = Tok.getIdentifierInfo(); SourceLocation classLoc = ConsumeToken(); // consume class-name; @@ -1691,16 +1693,16 @@ Decl *Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) { if (Tok.is(tok::code_completion)) { Actions.CodeCompleteObjCPropertyDefinition(getCurScope()); cutOffParsing(); - return 0; + return nullptr; } if (Tok.isNot(tok::identifier)) { Diag(Tok, diag::err_synthesized_property_name); SkipUntil(tok::semi); - return 0; + return nullptr; } - - IdentifierInfo *propertyIvar = 0; + + IdentifierInfo *propertyIvar = nullptr; IdentifierInfo *propertyId = Tok.getIdentifierInfo(); SourceLocation propertyLoc = ConsumeToken(); // consume property name SourceLocation propertyIvarLoc; @@ -1709,7 +1711,7 @@ Decl *Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) { if (Tok.is(tok::code_completion)) { Actions.CodeCompleteObjCPropertySynthesizeIvar(getCurScope(), propertyId); cutOffParsing(); - return 0; + return nullptr; } if (Tok.isNot(tok::identifier)) { @@ -1726,7 +1728,7 @@ Decl *Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) { ConsumeToken(); // consume ',' } ExpectAndConsume(tok::semi, diag::err_expected_after, "@synthesize"); - return 0; + return nullptr; } /// property-dynamic: @@ -1744,26 +1746,26 @@ Decl *Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) { if (Tok.is(tok::code_completion)) { Actions.CodeCompleteObjCPropertyDefinition(getCurScope()); cutOffParsing(); - return 0; + return nullptr; } if (Tok.isNot(tok::identifier)) { Diag(Tok, diag::err_expected) << tok::identifier; SkipUntil(tok::semi); - return 0; + return nullptr; } IdentifierInfo *propertyId = Tok.getIdentifierInfo(); SourceLocation propertyLoc = ConsumeToken(); // consume property name Actions.ActOnPropertyImplDecl(getCurScope(), atLoc, propertyLoc, false, - propertyId, 0, SourceLocation()); + propertyId, nullptr, SourceLocation()); if (Tok.isNot(tok::comma)) break; ConsumeToken(); // consume ',' } ExpectAndConsume(tok::semi, diag::err_expected_after, "@dynamic"); - return 0; + return nullptr; } /// objc-throw-statement: @@ -1874,7 +1876,7 @@ StmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { SourceLocation AtCatchFinallyLoc = ConsumeToken(); if (Tok.isObjCAtKeyword(tok::objc_catch)) { - Decl *FirstPart = 0; + Decl *FirstPart = nullptr; ConsumeToken(); // consume catch if (Tok.is(tok::l_paren)) { ConsumeParen(); @@ -2033,13 +2035,13 @@ Decl *Parser::ParseObjCMethodDefinition() { // If we didn't find the '{', bail out. if (Tok.isNot(tok::l_brace)) - return 0; + return nullptr; } if (!MDecl) { ConsumeBrace(); SkipUntil(tok::r_brace); - return 0; + return nullptr; } // Allow the rest of sema to find private method decl implementations. @@ -2097,7 +2099,7 @@ ExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) { SourceLocation OpLoc = ConsumeToken(); if (!Tok.is(tok::numeric_constant)) { - const char *Symbol = 0; + const char *Symbol = nullptr; switch (Kind) { case tok::minus: Symbol = "-"; break; case tok::plus: Symbol = "+"; break; @@ -2152,7 +2154,7 @@ ExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) { return ParsePostfixExpressionSuffix(ParseObjCBoxedExpr(AtLoc)); default: - if (Tok.getIdentifierInfo() == 0) + if (Tok.getIdentifierInfo() == nullptr) return ExprError(Diag(AtLoc, diag::err_unexpected_at)); switch (Tok.getIdentifierInfo()->getObjCKeywordID()) { @@ -2163,13 +2165,13 @@ ExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) { case tok::objc_selector: return ParsePostfixExpressionSuffix(ParseObjCSelectorExpression(AtLoc)); default: { - const char *str = 0; + const char *str = nullptr; if (GetLookAheadToken(1).is(tok::l_brace)) { char ch = Tok.getIdentifierInfo()->getNameStart()[0]; str = ch == 't' ? "try" : (ch == 'f' ? "finally" - : (ch == 'a' ? "autoreleasepool" : 0)); + : (ch == 'a' ? "autoreleasepool" : nullptr)); } if (str) { SourceLocation kwLoc = Tok.getLocation(); @@ -2342,11 +2344,11 @@ ExprResult Parser::ParseObjCMessageExpression() { if (Tok.is(tok::identifier) && Tok.getIdentifierInfo() == Ident_super && NextToken().isNot(tok::period) && getCurScope()->isInObjcMethodScope()) return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(), - ParsedType(), 0); + ParsedType(), nullptr); // Parse the receiver, which is either a type or an expression. bool IsExpr; - void *TypeOrExpr = NULL; + void *TypeOrExpr = nullptr; if (ParseObjCXXMessageReceiver(IsExpr, TypeOrExpr)) { SkipUntil(tok::r_square, StopAtSemi); return ExprError(); @@ -2359,7 +2361,7 @@ ExprResult Parser::ParseObjCMessageExpression() { return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), ParsedType::getFromOpaquePtr(TypeOrExpr), - 0); + nullptr); } if (Tok.is(tok::identifier)) { @@ -2372,7 +2374,7 @@ ExprResult Parser::ParseObjCMessageExpression() { ReceiverType)) { case Sema::ObjCSuperMessage: return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(), - ParsedType(), 0); + ParsedType(), nullptr); case Sema::ObjCClassMessage: if (!ReceiverType) { @@ -2383,8 +2385,8 @@ ExprResult Parser::ParseObjCMessageExpression() { ConsumeToken(); // the type name return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), - ReceiverType, 0); - + ReceiverType, nullptr); + case Sema::ObjCInstanceMessage: // Fall through to parse an expression. break; @@ -2867,7 +2869,7 @@ ExprResult Parser::ParseObjCSelectorExpression(SourceLocation AtLoc) { while (1) { if (TryConsumeToken(tok::coloncolon)) { // Handle :: in C++. ++nColons; - KeyIdents.push_back(0); + KeyIdents.push_back(nullptr); } else if (ExpectAndConsume(tok::colon)) // Otherwise expect ':'. return ExprError(); ++nColons; |