Mercurial > hg > CbC > CbC_llvm
diff clang/lib/Parse/ParseObjc.cpp @ 207:2e18cbf3894f
LLVM12
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 08 Jun 2021 06:07:14 +0900 |
parents | 0572611fdcc8 |
children | c4bab56944e8 |
line wrap: on
line diff
--- a/clang/lib/Parse/ParseObjc.cpp Mon May 25 11:55:54 2020 +0900 +++ b/clang/lib/Parse/ParseObjc.cpp Tue Jun 08 06:07:14 2021 +0900 @@ -50,8 +50,8 @@ SourceLocation AtLoc = ConsumeToken(); // the "@" if (Tok.is(tok::code_completion)) { + cutOffParsing(); Actions.CodeCompleteObjCAtDirective(getCurScope()); - cutOffParsing(); return nullptr; } @@ -219,8 +219,8 @@ // Code completion after '@interface'. if (Tok.is(tok::code_completion)) { + cutOffParsing(); Actions.CodeCompleteObjCInterfaceDecl(getCurScope()); - cutOffParsing(); return nullptr; } @@ -253,8 +253,8 @@ SourceLocation categoryLoc; IdentifierInfo *categoryId = nullptr; if (Tok.is(tok::code_completion)) { + cutOffParsing(); Actions.CodeCompleteObjCInterfaceCategory(getCurScope(), nameId, nameLoc); - cutOffParsing(); return nullptr; } @@ -308,8 +308,8 @@ // Code completion of superclass names. if (Tok.is(tok::code_completion)) { + cutOffParsing(); Actions.CodeCompleteObjCSuperclass(getCurScope(), nameId, nameLoc); - cutOffParsing(); return nullptr; } @@ -472,8 +472,8 @@ if (Tok.is(tok::code_completion)) { // FIXME: If these aren't protocol references, we'll need different // completions. + cutOffParsing(); Actions.CodeCompleteObjCProtocolReferences(protocolIdents); - cutOffParsing(); // FIXME: Better recovery here?. return nullptr; @@ -635,10 +635,11 @@ // Code completion within an Objective-C interface. if (Tok.is(tok::code_completion)) { + cutOffParsing(); Actions.CodeCompleteOrdinaryName(getCurScope(), CurParsedObjCImpl? Sema::PCC_ObjCImplementation : Sema::PCC_ObjCInterface); - return cutOffParsing(); + return; } // If we don't have an @ directive, parse it as a function definition. @@ -657,7 +658,7 @@ if (Tok.isOneOf(tok::kw_static_assert, tok::kw__Static_assert)) { SourceLocation DeclEnd; allTUVariables.push_back( - ParseDeclaration(DeclaratorContext::FileContext, DeclEnd, attrs)); + ParseDeclaration(DeclaratorContext::File, DeclEnd, attrs)); continue; } @@ -668,8 +669,9 @@ // Otherwise, we have an @ directive, eat the @. SourceLocation AtLoc = ConsumeToken(); // the "@" if (Tok.is(tok::code_completion)) { + cutOffParsing(); Actions.CodeCompleteObjCAtDirective(getCurScope()); - return cutOffParsing(); + return; } tok::ObjCKeywordKind DirectiveKind = Tok.getObjCKeywordID(); @@ -778,8 +780,9 @@ // We break out of the big loop in two cases: when we see @end or when we see // EOF. In the former case, eat the @end. In the later case, emit an error. if (Tok.is(tok::code_completion)) { + cutOffParsing(); Actions.CodeCompleteObjCAtDirective(getCurScope()); - return cutOffParsing(); + return; } else if (Tok.isObjCAtKeyword(tok::objc_end)) { ConsumeToken(); // the "end" identifier } else { @@ -847,8 +850,9 @@ while (1) { if (Tok.is(tok::code_completion)) { + cutOffParsing(); Actions.CodeCompleteObjCPropertyFlags(getCurScope(), DS); - return cutOffParsing(); + return; } const IdentifierInfo *II = Tok.getIdentifierInfo(); @@ -893,11 +897,12 @@ } if (Tok.is(tok::code_completion)) { + cutOffParsing(); if (IsSetter) Actions.CodeCompleteObjCPropertySetter(getCurScope()); else Actions.CodeCompleteObjCPropertyGetter(getCurScope()); - return cutOffParsing(); + return; } SourceLocation SelLoc; @@ -1141,14 +1146,15 @@ /// void Parser::ParseObjCTypeQualifierList(ObjCDeclSpec &DS, DeclaratorContext Context) { - assert(Context == DeclaratorContext::ObjCParameterContext || - Context == DeclaratorContext::ObjCResultContext); + assert(Context == DeclaratorContext::ObjCParameter || + Context == DeclaratorContext::ObjCResult); while (1) { if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteObjCPassingType(getCurScope(), DS, - Context == DeclaratorContext::ObjCParameterContext); - return cutOffParsing(); + cutOffParsing(); + Actions.CodeCompleteObjCPassingType( + getCurScope(), DS, Context == DeclaratorContext::ObjCParameter); + return; } if (Tok.isNot(tok::identifier)) @@ -1237,10 +1243,10 @@ ParsedType Parser::ParseObjCTypeName(ObjCDeclSpec &DS, DeclaratorContext context, ParsedAttributes *paramAttrs) { - assert(context == DeclaratorContext::ObjCParameterContext || - context == DeclaratorContext::ObjCResultContext); + assert(context == DeclaratorContext::ObjCParameter || + context == DeclaratorContext::ObjCResult); assert((paramAttrs != nullptr) == - (context == DeclaratorContext::ObjCParameterContext)); + (context == DeclaratorContext::ObjCParameter)); assert(Tok.is(tok::l_paren) && "expected ("); @@ -1259,7 +1265,7 @@ DeclSpec declSpec(AttrFactory); declSpec.setObjCQualifiers(&DS); DeclSpecContext dsContext = DeclSpecContext::DSC_normal; - if (context == DeclaratorContext::ObjCResultContext) + if (context == DeclaratorContext::ObjCResult) dsContext = DeclSpecContext::DSC_objc_method_result; ParseSpecifierQualifierList(declSpec, AS_none, dsContext); Declarator declarator(declSpec, context); @@ -1281,7 +1287,7 @@ // If we're parsing a parameter, steal all the decl attributes // and add them to the decl spec. - if (context == DeclaratorContext::ObjCParameterContext) + if (context == DeclaratorContext::ObjCParameter) takeDeclAttributes(*paramAttrs, declarator); } } @@ -1335,9 +1341,9 @@ ParsingDeclRAIIObject PD(*this, ParsingDeclRAIIObject::NoParent); if (Tok.is(tok::code_completion)) { + cutOffParsing(); Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus, /*ReturnType=*/nullptr); - cutOffParsing(); return nullptr; } @@ -1345,19 +1351,18 @@ ParsedType ReturnType; ObjCDeclSpec DSRet; if (Tok.is(tok::l_paren)) - ReturnType = ParseObjCTypeName(DSRet, DeclaratorContext::ObjCResultContext, - nullptr); + ReturnType = + ParseObjCTypeName(DSRet, DeclaratorContext::ObjCResult, nullptr); // If attributes exist before the method, parse them. ParsedAttributes methodAttrs(AttrFactory); - if (getLangOpts().ObjC) - MaybeParseGNUAttributes(methodAttrs); - MaybeParseCXX11Attributes(methodAttrs); + MaybeParseAttributes(PAKM_CXX11 | (getLangOpts().ObjC ? PAKM_GNU : 0), + methodAttrs); if (Tok.is(tok::code_completion)) { + cutOffParsing(); Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus, ReturnType); - cutOffParsing(); return nullptr; } @@ -1377,9 +1382,8 @@ SmallVector<DeclaratorChunk::ParamInfo, 8> CParamInfo; if (Tok.isNot(tok::colon)) { // If attributes exist after the method, parse them. - if (getLangOpts().ObjC) - MaybeParseGNUAttributes(methodAttrs); - MaybeParseCXX11Attributes(methodAttrs); + MaybeParseAttributes(PAKM_CXX11 | (getLangOpts().ObjC ? PAKM_GNU : 0), + methodAttrs); Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent); Decl *Result = Actions.ActOnMethodDeclaration( @@ -1407,25 +1411,23 @@ ArgInfo.Type = nullptr; if (Tok.is(tok::l_paren)) // Parse the argument type if present. - ArgInfo.Type = ParseObjCTypeName(ArgInfo.DeclSpec, - DeclaratorContext::ObjCParameterContext, - ¶mAttrs); + ArgInfo.Type = ParseObjCTypeName( + ArgInfo.DeclSpec, DeclaratorContext::ObjCParameter, ¶mAttrs); // If attributes exist before the argument name, parse them. // Regardless, collect all the attributes we've parsed so far. - if (getLangOpts().ObjC) - MaybeParseGNUAttributes(paramAttrs); - MaybeParseCXX11Attributes(paramAttrs); + MaybeParseAttributes(PAKM_CXX11 | (getLangOpts().ObjC ? PAKM_GNU : 0), + paramAttrs); ArgInfo.ArgAttrs = paramAttrs; // Code completion for the next piece of the selector. if (Tok.is(tok::code_completion)) { + cutOffParsing(); KeyIdents.push_back(SelIdent); Actions.CodeCompleteObjCMethodDeclSelector(getCurScope(), mType == tok::minus, /*AtParameterName=*/true, ReturnType, KeyIdents); - cutOffParsing(); return nullptr; } @@ -1445,11 +1447,11 @@ // Code completion for the next piece of the selector. if (Tok.is(tok::code_completion)) { + cutOffParsing(); Actions.CodeCompleteObjCMethodDeclSelector(getCurScope(), mType == tok::minus, /*AtParameterName=*/false, ReturnType, KeyIdents); - cutOffParsing(); return nullptr; } @@ -1485,7 +1487,7 @@ DeclSpec DS(AttrFactory); ParseDeclarationSpecifiers(DS); // Parse the declarator. - Declarator ParmDecl(DS, DeclaratorContext::PrototypeContext); + Declarator ParmDecl(DS, DeclaratorContext::Prototype); ParseDeclarator(ParmDecl); IdentifierInfo *ParmII = ParmDecl.getIdentifier(); Decl *Param = Actions.ActOnParamDeclarator(getCurScope(), ParmDecl); @@ -1497,9 +1499,8 @@ // FIXME: Add support for optional parameter list... // If attributes exist after the method, parse them. - if (getLangOpts().ObjC) - MaybeParseGNUAttributes(methodAttrs); - MaybeParseCXX11Attributes(methodAttrs); + MaybeParseAttributes(PAKM_CXX11 | (getLangOpts().ObjC ? PAKM_GNU : 0), + methodAttrs); if (KeyIdents.size() == 0) return nullptr; @@ -1532,8 +1533,8 @@ while (1) { if (Tok.is(tok::code_completion)) { + cutOffParsing(); Actions.CodeCompleteObjCProtocolReferences(ProtocolIdents); - cutOffParsing(); return true; } @@ -1631,12 +1632,12 @@ } QualType BaseT = Actions.GetTypeFromParser(baseType); + cutOffParsing(); if (!BaseT.isNull() && BaseT->acceptsObjCTypeParams()) { Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Type); } else { Actions.CodeCompleteObjCProtocolReferences(identifierLocPairs); } - cutOffParsing(); return; } @@ -1692,7 +1693,7 @@ typeArg, Actions.getASTContext().getPrintingPolicy()); // Form a declarator to turn this into a type. - Declarator D(DS, DeclaratorContext::TypeNameContext); + Declarator D(DS, DeclaratorContext::TypeName); TypeResult fullTypeArg = Actions.ActOnTypeName(getCurScope(), D); if (fullTypeArg.isUsable()) { typeArgs.push_back(fullTypeArg.get()); @@ -1925,8 +1926,9 @@ // Set the default visibility to private. if (TryConsumeToken(tok::at)) { // parse objc-visibility-spec if (Tok.is(tok::code_completion)) { + cutOffParsing(); Actions.CodeCompleteObjCAtVisibility(getCurScope()); - return cutOffParsing(); + return; } switch (Tok.getObjCKeywordID()) { @@ -1955,9 +1957,10 @@ } if (Tok.is(tok::code_completion)) { + cutOffParsing(); Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_ObjCInstanceVariableList); - return cutOffParsing(); + return; } // This needs to duplicate a small amount of code from @@ -2022,8 +2025,8 @@ ConsumeToken(); // the "protocol" identifier if (Tok.is(tok::code_completion)) { + cutOffParsing(); Actions.CodeCompleteObjCProtocolDecl(getCurScope()); - cutOffParsing(); return nullptr; } @@ -2106,8 +2109,8 @@ // Code completion after '@implementation'. if (Tok.is(tok::code_completion)) { + cutOffParsing(); Actions.CodeCompleteObjCImplementationDecl(getCurScope()); - cutOffParsing(); return nullptr; } @@ -2144,8 +2147,8 @@ IdentifierInfo *categoryId = nullptr; if (Tok.is(tok::code_completion)) { + cutOffParsing(); Actions.CodeCompleteObjCImplementationCategory(getCurScope(), nameId, nameLoc); - cutOffParsing(); return nullptr; } @@ -2314,8 +2317,8 @@ while (true) { if (Tok.is(tok::code_completion)) { + cutOffParsing(); Actions.CodeCompleteObjCPropertyDefinition(getCurScope()); - cutOffParsing(); return nullptr; } @@ -2332,8 +2335,8 @@ if (TryConsumeToken(tok::equal)) { // property '=' ivar-name if (Tok.is(tok::code_completion)) { + cutOffParsing(); Actions.CodeCompleteObjCPropertySynthesizeIvar(getCurScope(), propertyId); - cutOffParsing(); return nullptr; } @@ -2392,8 +2395,8 @@ while (true) { if (Tok.is(tok::code_completion)) { + cutOffParsing(); Actions.CodeCompleteObjCPropertyDefinition(getCurScope()); - cutOffParsing(); return nullptr; } @@ -2536,7 +2539,7 @@ if (Tok.isNot(tok::ellipsis)) { DeclSpec DS(AttrFactory); ParseDeclarationSpecifiers(DS); - Declarator ParmDecl(DS, DeclaratorContext::ObjCCatchContext); + Declarator ParmDecl(DS, DeclaratorContext::ObjCCatch); ParseDeclarator(ParmDecl); // Inform the actions module about the declarator, so it @@ -2729,8 +2732,8 @@ StmtResult Parser::ParseObjCAtStatement(SourceLocation AtLoc, ParsedStmtContext StmtCtx) { if (Tok.is(tok::code_completion)) { + cutOffParsing(); Actions.CodeCompleteObjCAtStatement(getCurScope()); - cutOffParsing(); return StmtError(); } @@ -2770,8 +2773,8 @@ ExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) { switch (Tok.getKind()) { case tok::code_completion: + cutOffParsing(); Actions.CodeCompleteObjCAtExpression(getCurScope()); - cutOffParsing(); return ExprError(); case tok::minus: @@ -2952,7 +2955,7 @@ // We have a class message. Turn the simple-type-specifier or // typename-specifier we parsed into a type and parse the // remainder of the class message. - Declarator DeclaratorInfo(DS, DeclaratorContext::TypeNameContext); + Declarator DeclaratorInfo(DS, DeclaratorContext::TypeName); TypeResult Type = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); if (Type.isInvalid()) return true; @@ -3017,8 +3020,8 @@ SourceLocation LBracLoc = ConsumeBracket(); // consume '[' if (Tok.is(tok::code_completion)) { + cutOffParsing(); Actions.CodeCompleteObjCMessageReceiver(getCurScope()); - cutOffParsing(); return ExprError(); } @@ -3154,6 +3157,7 @@ InMessageExpressionRAIIObject InMessage(*this, true); if (Tok.is(tok::code_completion)) { + cutOffParsing(); if (SuperLoc.isValid()) Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, None, false); @@ -3163,7 +3167,6 @@ else Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, None, false); - cutOffParsing(); return ExprError(); } @@ -3192,6 +3195,7 @@ /// Parse the expression after ':' if (Tok.is(tok::code_completion)) { + cutOffParsing(); if (SuperLoc.isValid()) Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, KeyIdents, @@ -3205,7 +3209,6 @@ KeyIdents, /*AtArgumentExpression=*/true); - cutOffParsing(); return ExprError(); } @@ -3230,6 +3233,7 @@ // Code completion after each argument. if (Tok.is(tok::code_completion)) { + cutOffParsing(); if (SuperLoc.isValid()) Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, KeyIdents, @@ -3242,7 +3246,6 @@ Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, KeyIdents, /*AtArgumentExpression=*/false); - cutOffParsing(); return ExprError(); } @@ -3582,8 +3585,8 @@ ConsumeParen(); if (Tok.is(tok::code_completion)) { + cutOffParsing(); Actions.CodeCompleteObjCSelector(getCurScope(), KeyIdents); - cutOffParsing(); return ExprError(); } @@ -3608,8 +3611,8 @@ break; if (Tok.is(tok::code_completion)) { + cutOffParsing(); Actions.CodeCompleteObjCSelector(getCurScope(), KeyIdents); - cutOffParsing(); return ExprError(); }