[cfe-commits] [PATCH] Add callback object to Sema::CorrectTypo

Kaelyn Uhrain rikka at google.com
Wed Jan 11 09:54:29 PST 2012


Way too early in the morning... originally hit "Reply" instead of "Reply
All" and then when I resent the email to the mailing list I forgot to
attach the patch.  D'oh!

On Wed, Jan 11, 2012 at 9:53 AM, Kaelyn Uhrain <rikka at google.com> wrote:

> On Tue, Jan 10, 2012 at 8:23 PM, Douglas Gregor <dgregor at apple.com> wrote:
>
>>
>> On Jan 10, 2012, at 5:06 PM, Kaelyn Uhrain wrote:
>>
>> > This patch is a rough draft of my attempt to replace the
>> Sema::CorrectTypoContext enum with a callback object for performing finer
>> grained validation of potential typo corrections. This version just
>> includes a wrapper for Sema::CorrectTypo to translate a CorrectTypoContext
>> value into a corresponding callback object. The idea is to give CorrectTypo
>> a way to filter potential corrections with more accuracy by being able to
>> take into account e.g. what kinds of decls are allowed/expected, instead of
>> giving a very rough guide on what corrections are acceptable
>> (CorrectTypoContext values mainly affect which keywords should be added to
>> the set of possible corrections; the exceptions are that
>> CTC_ObjCMessageReceiver would give precedence to the "super" keyword over
>> other corrections with the same edit distance, and CTC_ObjCIvarLookup would
>> trigger ObjC ivar lookup before other forms of lookup when looking up
>> potential typo correction identifiers).
>> >
>> > I'll be surprised if the interface of the callback class doesn't expand
>> or improve as I fix up callers of CorrectTypo to use callback objects
>> directly. I also hope to entirely remove or at least come up with a cleaner
>> solution than the flags in the callback class that control which keywords
>> are added to the candidate pool. I'm sending this initial patch to start
>> gathering feedback on the approach while fixing up the CorrectTypo callers,
>> as those changes will most likely dwarf the changes that add the callback
>> infrastructure to CorrectTypo. As such, I'm fine with either submitting
>> this patch or holding off until the conversion is further along.
>>
>> I like this approach, and I'm fine with the callback interface evolving
>> as you switch callers over to using it. I do suggest migrating one caller
>> over to its own CorrectionCandidateCallback subclass so you're exercising
>> that code path, and then committing this patch and the change to that one
>> one caller at once.
>>
>> Then, you can switch each of the other call sites over, one-by-one,
>> improving the callback interface as necessary.
>>
>
> Sounds good. Thanks, Doug! Coincidentally enough, I had converted the two
> calls to CorrectTypo in SemaDeclCXX.cpp over to the new interface before
> going home yesterday. ;) I've attached that patch as a reference example
> for this thread.  In the first instance, it doesn't really change the logic
> that deals with the typo correction returned by CorrectTypo, while the
> second instance is able to move all of the checking of the correction's
> Decl type into the callback. In both instances, the new code should yield
> more accurate results by virtue of avoiding having a correction with the
> wrong Decl type be returned instead of a correction with the right Decl
> type because the former was slightly closer (or to have no correction
> returned because the two had the same edit distance). None of the current
> unit tests hit those situations, so I plan to come up with a few this
> morning to add to the patch before submitting it--they shouldn't be too
> hard to come up since the criteria are pretty clear and straightforward.
>
> Cheers,
> Kaelyn
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120111/1a996a93/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: typo-correction-callback-user.diff
Type: text/x-patch
Size: 6166 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120111/1a996a93/attachment.bin>


More information about the cfe-commits mailing list