[PATCH] D52261: [Sema] Generate completion fix-its for C code as well
Ivan Donchevskii via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 19 05:31:33 PDT 2018
yvvan created this revision.
yvvan added reviewers: nik, ilya-biryukov.
Current completion fix-its approach does not provide OtherOpBase for C code. But we can easily proceed in this case taking the original Base type.
https://reviews.llvm.org/D52261
Files:
lib/Sema/SemaCodeComplete.cpp
Index: lib/Sema/SemaCodeComplete.cpp
===================================================================
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -4037,39 +4037,33 @@
QualType ConvertedBaseType = ConvertedBase.get()->getType();
enum CodeCompletionContext::Kind contextKind;
+ QualType TypeWithoutPointer = ConvertedBaseType;
if (IsArrow) {
- if (const PointerType *Ptr = ConvertedBaseType->getAs<PointerType>())
- ConvertedBaseType = Ptr->getPointeeType();
+ if (const PointerType *Ptr = TypeWithoutPointer->getAs<PointerType>())
+ TypeWithoutPointer = Ptr->getPointeeType();
}
if (IsArrow) {
contextKind = CodeCompletionContext::CCC_ArrowMemberAccess;
} else {
- if (ConvertedBaseType->isObjCObjectPointerType() ||
- ConvertedBaseType->isObjCObjectOrInterfaceType()) {
+ if (TypeWithoutPointer->isObjCObjectPointerType() ||
+ TypeWithoutPointer->isObjCObjectOrInterfaceType()) {
contextKind = CodeCompletionContext::CCC_ObjCPropertyAccess;
} else {
contextKind = CodeCompletionContext::CCC_DotMemberAccess;
}
}
- CodeCompletionContext CCContext(contextKind, ConvertedBaseType);
+ CodeCompletionContext CCContext(contextKind, TypeWithoutPointer);
ResultBuilder Results(*this, CodeCompleter->getAllocator(),
CodeCompleter->getCodeCompletionTUInfo(), CCContext,
&ResultBuilder::IsMember);
- auto DoCompletion = [&](Expr *Base, bool IsArrow, Optional<FixItHint> AccessOpFixIt) -> bool {
- if (!Base)
+ auto DoCompletion = [&](QualType BaseType, bool IsArrow,
+ Optional<FixItHint> AccessOpFixIt) -> bool {
+ if (BaseType.isNull())
return false;
-
- ExprResult ConvertedBase = PerformMemberExprBaseConversion(Base, IsArrow);
- if (ConvertedBase.isInvalid())
- return false;
- Base = ConvertedBase.get();
-
- QualType BaseType = Base->getType();
-
if (IsArrow) {
if (const PointerType *Ptr = BaseType->getAs<PointerType>())
BaseType = Ptr->getPointeeType();
@@ -4140,13 +4134,28 @@
Results.EnterNewScope();
- bool CompletionSucceded = DoCompletion(Base, IsArrow, None);
+ bool CompletionSucceded = DoCompletion(ConvertedBaseType, IsArrow, None);
if (CodeCompleter->includeFixIts()) {
- const CharSourceRange OpRange =
- CharSourceRange::getTokenRange(OpLoc, OpLoc);
- CompletionSucceded |= DoCompletion(
- OtherOpBase, !IsArrow,
- FixItHint::CreateReplacement(OpRange, IsArrow ? "." : "->"));
+ QualType ConvertedOtherBaseType;
+ if (!OtherOpBase) {
+ const Type *BaseTypePtr = ConvertedBaseType.getTypePtrOrNull();
+ // Proceed if the initial type is pointer but IsArrow is false or the
+ // other way around.
+ if (BaseTypePtr && IsArrow != BaseTypePtr->isPointerType())
+ ConvertedOtherBaseType = ConvertedBaseType;
+ } else {
+ ExprResult ConvertedOtherBase =
+ PerformMemberExprBaseConversion(OtherOpBase, !IsArrow);
+ if (!ConvertedOtherBase.isInvalid())
+ ConvertedOtherBaseType = ConvertedOtherBase.get()->getType();
+ }
+ if (!ConvertedOtherBaseType.isNull()) {
+ const CharSourceRange OpRange =
+ CharSourceRange::getTokenRange(OpLoc, OpLoc);
+ CompletionSucceded |= DoCompletion(
+ ConvertedOtherBaseType, !IsArrow,
+ FixItHint::CreateReplacement(OpRange, IsArrow ? "." : "->"));
+ }
}
Results.ExitScope();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52261.166103.patch
Type: text/x-patch
Size: 3528 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180919/8c2f8f8c/attachment-0001.bin>
More information about the cfe-commits
mailing list