This is an archive of the discontinued LLVM Phabricator instance.

[Sema] Generate completion fix-its for C code as well
ClosedPublic

Authored by yvvan on Sep 19 2018, 5:31 AM.

Details

Summary

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.

Diff Detail

Repository
rC Clang

Event Timeline

yvvan created this revision.Sep 19 2018, 5:31 AM
yvvan updated this revision to Diff 166110.Sep 19 2018, 5:59 AM

Test is added

It's the responsibility of the caller to provide a corrected expression, this keeps the completion function simpler. I suggest we stick to this contract.
We do something in getLangOpts().CPlusPlus case to create a corrected expression, let's just implement a similar fallback for C at the single callsite that we have (ParsePostfixExpressionSuffix).

I tried that first but did not I find a way just to copy an expression (we basically need the same expr for such case). Do you know how to properly generate a copy of expression or some other way to get the same expression?

I tried that first but did not I find a way just to copy an expression (we basically need the same expr for such case). Do you know how to properly generate a copy of expression or some other way to get the same expression?

It seems Sema::ActOnStartCXXMemberReference only changes expression when overloading for C++'s operator -> is required, otherwise it keeps the same expression. Since C does not have that, we can just leave the expression as is.
So setting CorrectedLHS = LHS for C should do the trick (no need to copy the expression IIUC, it's fine to use the same pointer for both CorrectedLHS and LHS).

You're right actually. The fix is much simpler than I expected :)

yvvan updated this revision to Diff 166407.Sep 21 2018, 12:21 AM

Provide CorrectedBase = Base for C code

ilya-biryukov accepted this revision.Sep 21 2018, 4:06 AM

Thanks! LGTM!

This revision is now accepted and ready to land.Sep 21 2018, 4:06 AM
This revision was automatically updated to reflect the committed changes.