<div class="gmail_quote">On Tue, Jan 10, 2012 at 8:23 PM, Douglas Gregor <span dir="ltr"><<a href="mailto:dgregor@apple.com">dgregor@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im"><br>
On Jan 10, 2012, at 5:06 PM, Kaelyn Uhrain wrote:<br>
<br>
> 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).<br>

><br>
> 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.<br>

<br>
</div>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.<br>

<br>
Then, you can switch each of the other call sites over, one-by-one, improving the callback interface as necessary.<br></blockquote><div><br></div><div style="font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
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.</div>
<div style="font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br></div><div style="font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">Cheers,</div><div><span style="background-color:rgb(255,255,255);font-family:arial,sans-serif;font-size:13px">Kaelyn</span></div>
</div>