[PATCH] D25519: [CodeCompletion] Refactor: Extract two Objective-C block formatting related functions from FormatFunctionParameter
This revision was automatically updated to reflect the committed changes. Closed by commit rL284467: [CodeCompletion][NFC] Extract a function that looks for block decl type locs. (authored by arphaman). Changed prior to commit: https://reviews.llvm.org/D25519?vs=74520&id=74972#toc Repository: rL LLVM https://reviews.llvm.org/D25519 Files: cfe/trunk/lib/Sema/SemaCodeComplete.cpp Index: cfe/trunk/lib/Sema/SemaCodeComplete.cpp === --- cfe/trunk/lib/Sema/SemaCodeComplete.cpp +++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp @@ -2162,6 +2162,53 @@ return Result; } +/// \brief Tries to find the most appropriate type location for an Objective-C +/// block placeholder. +/// +/// This function ignores things like typedefs and qualifiers in order to +/// present the most relevant and accurate block placeholders in code completion +/// results. +static void findTypeLocationForBlockDecl(const TypeSourceInfo *TSInfo, + FunctionTypeLoc &Block, + FunctionProtoTypeLoc &BlockProto, + bool SuppressBlock = false) { + if (!TSInfo) +return; + TypeLoc TL = TSInfo->getTypeLoc().getUnqualifiedLoc(); + while (true) { +// Look through typedefs. +if (!SuppressBlock) { + if (TypedefTypeLoc TypedefTL = TL.getAs()) { +if (TypeSourceInfo *InnerTSInfo = +TypedefTL.getTypedefNameDecl()->getTypeSourceInfo()) { + TL = InnerTSInfo->getTypeLoc().getUnqualifiedLoc(); + continue; +} + } + + // Look through qualified types + if (QualifiedTypeLoc QualifiedTL = TL.getAs()) { +TL = QualifiedTL.getUnqualifiedLoc(); +continue; + } + + if (AttributedTypeLoc AttrTL = TL.getAs()) { +TL = AttrTL.getModifiedLoc(); +continue; + } +} + +// Try to get the function prototype behind the block pointer type, +// then we're done. +if (BlockPointerTypeLoc BlockPtr = TL.getAs()) { + TL = BlockPtr.getPointeeLoc().IgnoreParens(); + Block = TL.getAs(); + BlockProto = TL.getAs(); +} +break; + } +} + static std::string FormatFunctionParameter(const PrintingPolicy &Policy, const ParmVarDecl *Param, bool SuppressName = false, @@ -2192,47 +2239,13 @@ } return Result; } - + // The argument for a block pointer parameter is a block literal with // the appropriate type. FunctionTypeLoc Block; FunctionProtoTypeLoc BlockProto; - TypeLoc TL; - if (TypeSourceInfo *TSInfo = Param->getTypeSourceInfo()) { -TL = TSInfo->getTypeLoc().getUnqualifiedLoc(); -while (true) { - // Look through typedefs. - if (!SuppressBlock) { -if (TypedefTypeLoc TypedefTL = TL.getAs()) { - if (TypeSourceInfo *InnerTSInfo = - TypedefTL.getTypedefNameDecl()->getTypeSourceInfo()) { -TL = InnerTSInfo->getTypeLoc().getUnqualifiedLoc(); -continue; - } -} - -// Look through qualified types -if (QualifiedTypeLoc QualifiedTL = TL.getAs()) { - TL = QualifiedTL.getUnqualifiedLoc(); - continue; -} - -if (AttributedTypeLoc AttrTL = TL.getAs()) { - TL = AttrTL.getModifiedLoc(); - continue; -} - } - - // Try to get the function prototype behind the block pointer type, - // then we're done. - if (BlockPointerTypeLoc BlockPtr = TL.getAs()) { -TL = BlockPtr.getPointeeLoc().IgnoreParens(); -Block = TL.getAs(); -BlockProto = TL.getAs(); - } - break; -} - } + findTypeLocationForBlockDecl(Param->getTypeSourceInfo(), Block, BlockProto, + SuppressBlock); if (!Block) { // We were unable to find a FunctionProtoTypeLoc with parameter names ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D25519: [CodeCompletion] Refactor: Extract two Objective-C block formatting related functions from FormatFunctionParameter
manmanren accepted this revision. manmanren added a comment. This revision is now accepted and ready to land. LGTM. Manman Repository: rL LLVM https://reviews.llvm.org/D25519 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D25519: [CodeCompletion] Refactor: Extract two Objective-C block formatting related functions from FormatFunctionParameter
arphaman updated this revision to Diff 74520. arphaman marked 2 inline comments as done. arphaman added a comment. The updated patch has comments for the two extracted functions. Repository: rL LLVM https://reviews.llvm.org/D25519 Files: lib/Sema/SemaCodeComplete.cpp Index: lib/Sema/SemaCodeComplete.cpp === --- lib/Sema/SemaCodeComplete.cpp +++ lib/Sema/SemaCodeComplete.cpp @@ -2162,6 +2162,59 @@ return Result; } +/// \brief Tries to find the most appropriate type location for an Objective-C +/// block placeholder. +/// +/// This function ignores things like typedefs and qualifiers in order to +/// present the most relevant and accurate block placeholders in code completion +/// results. +static void findTypeLocationForBlockDecl(const TypeSourceInfo *TSInfo, + FunctionTypeLoc &Block, + FunctionProtoTypeLoc &BlockProto, + bool SuppressBlock = false) { + if (!TSInfo) +return; + TypeLoc TL = TSInfo->getTypeLoc().getUnqualifiedLoc(); + while (true) { +// Look through typedefs. +if (!SuppressBlock) { + if (TypedefTypeLoc TypedefTL = TL.getAs()) { +if (TypeSourceInfo *InnerTSInfo = +TypedefTL.getTypedefNameDecl()->getTypeSourceInfo()) { + TL = InnerTSInfo->getTypeLoc().getUnqualifiedLoc(); + continue; +} + } + + // Look through qualified types + if (QualifiedTypeLoc QualifiedTL = TL.getAs()) { +TL = QualifiedTL.getUnqualifiedLoc(); +continue; + } + + if (AttributedTypeLoc AttrTL = TL.getAs()) { +TL = AttrTL.getModifiedLoc(); +continue; + } +} + +// Try to get the function prototype behind the block pointer type, +// then we're done. +if (BlockPointerTypeLoc BlockPtr = TL.getAs()) { + TL = BlockPtr.getPointeeLoc().IgnoreParens(); + Block = TL.getAs(); + BlockProto = TL.getAs(); +} +break; + } +} + +static std::string +formatBlockPlaceholder(const PrintingPolicy &Policy, const NamedDecl *BlockDecl, + FunctionTypeLoc &Block, FunctionProtoTypeLoc &BlockProto, + bool SuppressBlock = false, + Optional> ObjCSubsts = None); + static std::string FormatFunctionParameter(const PrintingPolicy &Policy, const ParmVarDecl *Param, bool SuppressName = false, @@ -2192,47 +2245,13 @@ } return Result; } - + // The argument for a block pointer parameter is a block literal with // the appropriate type. FunctionTypeLoc Block; FunctionProtoTypeLoc BlockProto; - TypeLoc TL; - if (TypeSourceInfo *TSInfo = Param->getTypeSourceInfo()) { -TL = TSInfo->getTypeLoc().getUnqualifiedLoc(); -while (true) { - // Look through typedefs. - if (!SuppressBlock) { -if (TypedefTypeLoc TypedefTL = TL.getAs()) { - if (TypeSourceInfo *InnerTSInfo = - TypedefTL.getTypedefNameDecl()->getTypeSourceInfo()) { -TL = InnerTSInfo->getTypeLoc().getUnqualifiedLoc(); -continue; - } -} - -// Look through qualified types -if (QualifiedTypeLoc QualifiedTL = TL.getAs()) { - TL = QualifiedTL.getUnqualifiedLoc(); - continue; -} - -if (AttributedTypeLoc AttrTL = TL.getAs()) { - TL = AttrTL.getModifiedLoc(); - continue; -} - } - - // Try to get the function prototype behind the block pointer type, - // then we're done. - if (BlockPointerTypeLoc BlockPtr = TL.getAs()) { -TL = BlockPtr.getPointeeLoc().IgnoreParens(); -Block = TL.getAs(); -BlockProto = TL.getAs(); - } - break; -} - } + findTypeLocationForBlockDecl(Param->getTypeSourceInfo(), Block, BlockProto, + SuppressBlock); if (!Block) { // We were unable to find a FunctionProtoTypeLoc with parameter names @@ -2258,12 +2277,30 @@ // We have the function prototype behind the block pointer type, as it was // written in the source. + return formatBlockPlaceholder(Policy, Param, Block, BlockProto, SuppressBlock, +ObjCSubsts); +} + +/// \brief Returns a placeholder string that corresponds to an Objective-C block +/// declaration. +/// +/// \param BlockDecl A declaration with an Objective-C block type. +/// +/// \param Block The most relevant type location for that block type. +/// +/// \param SuppressBlockName Determines wether or not the name of the block +/// declaration is included in the resulting string. +static std::string +formatBlockPlaceholder(const PrintingPolicy &Policy, const NamedDecl *BlockDecl, + FunctionTypeLoc &Block, Functi
[PATCH] D25519: [CodeCompletion] Refactor: Extract two Objective-C block formatting related functions from FormatFunctionParameter
manmanren added a comment. Cheers, Manman Comment at: lib/Sema/SemaCodeComplete.cpp:2165 +static void findTypeLocationForBlockDecl(const TypeSourceInfo *TSInfo, + FunctionTypeLoc &Block, Please add comments for the helper function. Comment at: lib/Sema/SemaCodeComplete.cpp:2279 +static std::string +formatBlockPlaceholder(const PrintingPolicy &Policy, const NamedDecl *BlockDecl, + FunctionTypeLoc &Block, FunctionProtoTypeLoc &BlockProto, Comments here as well. Repository: rL LLVM https://reviews.llvm.org/D25519 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D25519: [CodeCompletion] Refactor: Extract two Objective-C block formatting related functions from FormatFunctionParameter
arphaman created this revision. arphaman added a reviewer: manmanren. arphaman added a subscriber: cfe-commits. arphaman set the repository for this revision to rL LLVM. This patch extracts two new functions from the function `FormatFunctionParameter` that are related to Objective-C block formatting. It should be two separate commits (the first extracts `findTypeLocationForBlockDecl`, and the second extracts `formatBlockPlaceholder`), but I squashed them to make the review easier. This patch is required for my follow up patch that improves completion for block property setters. Repository: rL LLVM https://reviews.llvm.org/D25519 Files: lib/Sema/SemaCodeComplete.cpp Index: lib/Sema/SemaCodeComplete.cpp === --- lib/Sema/SemaCodeComplete.cpp +++ lib/Sema/SemaCodeComplete.cpp @@ -2162,6 +2162,53 @@ return Result; } +static void findTypeLocationForBlockDecl(const TypeSourceInfo *TSInfo, + FunctionTypeLoc &Block, + FunctionProtoTypeLoc &BlockProto, + bool SuppressBlock = false) { + if (!TSInfo) +return; + TypeLoc TL = TSInfo->getTypeLoc().getUnqualifiedLoc(); + while (true) { +// Look through typedefs. +if (!SuppressBlock) { + if (TypedefTypeLoc TypedefTL = TL.getAs()) { +if (TypeSourceInfo *InnerTSInfo = +TypedefTL.getTypedefNameDecl()->getTypeSourceInfo()) { + TL = InnerTSInfo->getTypeLoc().getUnqualifiedLoc(); + continue; +} + } + + // Look through qualified types + if (QualifiedTypeLoc QualifiedTL = TL.getAs()) { +TL = QualifiedTL.getUnqualifiedLoc(); +continue; + } + + if (AttributedTypeLoc AttrTL = TL.getAs()) { +TL = AttrTL.getModifiedLoc(); +continue; + } +} + +// Try to get the function prototype behind the block pointer type, +// then we're done. +if (BlockPointerTypeLoc BlockPtr = TL.getAs()) { + TL = BlockPtr.getPointeeLoc().IgnoreParens(); + Block = TL.getAs(); + BlockProto = TL.getAs(); +} +break; + } +} + +static std::string +formatBlockPlaceholder(const PrintingPolicy &Policy, const NamedDecl *BlockDecl, + FunctionTypeLoc &Block, FunctionProtoTypeLoc &BlockProto, + bool SuppressBlock = false, + Optional> ObjCSubsts = None); + static std::string FormatFunctionParameter(const PrintingPolicy &Policy, const ParmVarDecl *Param, bool SuppressName = false, @@ -2192,47 +2239,13 @@ } return Result; } - + // The argument for a block pointer parameter is a block literal with // the appropriate type. FunctionTypeLoc Block; FunctionProtoTypeLoc BlockProto; - TypeLoc TL; - if (TypeSourceInfo *TSInfo = Param->getTypeSourceInfo()) { -TL = TSInfo->getTypeLoc().getUnqualifiedLoc(); -while (true) { - // Look through typedefs. - if (!SuppressBlock) { -if (TypedefTypeLoc TypedefTL = TL.getAs()) { - if (TypeSourceInfo *InnerTSInfo = - TypedefTL.getTypedefNameDecl()->getTypeSourceInfo()) { -TL = InnerTSInfo->getTypeLoc().getUnqualifiedLoc(); -continue; - } -} - -// Look through qualified types -if (QualifiedTypeLoc QualifiedTL = TL.getAs()) { - TL = QualifiedTL.getUnqualifiedLoc(); - continue; -} - -if (AttributedTypeLoc AttrTL = TL.getAs()) { - TL = AttrTL.getModifiedLoc(); - continue; -} - } - - // Try to get the function prototype behind the block pointer type, - // then we're done. - if (BlockPointerTypeLoc BlockPtr = TL.getAs()) { -TL = BlockPtr.getPointeeLoc().IgnoreParens(); -Block = TL.getAs(); -BlockProto = TL.getAs(); - } - break; -} - } + findTypeLocationForBlockDecl(Param->getTypeSourceInfo(), Block, BlockProto, + SuppressBlock); if (!Block) { // We were unable to find a FunctionProtoTypeLoc with parameter names @@ -2258,12 +2271,21 @@ // We have the function prototype behind the block pointer type, as it was // written in the source. + return formatBlockPlaceholder(Policy, Param, Block, BlockProto, SuppressBlock, +ObjCSubsts); +} + +static std::string +formatBlockPlaceholder(const PrintingPolicy &Policy, const NamedDecl *BlockDecl, + FunctionTypeLoc &Block, FunctionProtoTypeLoc &BlockProto, + bool SuppressBlock, + Optional> ObjCSubsts) { std::string Result; QualType ResultType = Block.getTypePtr()->getReturnType(); if (ObjCSubsts) -ResultType = ResultType.