<div dir="ltr">+dblaikie</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Jul 31, 2014 at 1:20 PM, Kaelyn Takata <span dir="ltr"><<a href="mailto:rikka@google.com" target="_blank">rikka@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
This patch set adds a new node to the AST called a TypoExpr. It is used as a<br>
placeholder to delay typo correction until a full expression is being finalized<br>
(via Sema::ActOnFinishFullExpr), at which point a TreeTransform is run to<br>
replace each TypoExpr by performing typo correction. This allows, for example,<br>
to delay typo correction on a call to a class method until after the arguments<br>
have been parsed, instead of trying to do the typo correction while looking up<br>
the member before the parser has even reached the opening parenthesis. The<br>
patches have been broken up such that clang builds and the tests pass after<br>
each patch in the sequence has been applied. The first patch is included in<br>
here despite being a simple, mechanical moving around of code (instead of<br>
committing it directly) because it is unnecessary/useless outside of the rest<br>
of the patch set.<br>
<br>
v2:<br>
* Unmunge a couple of patches that accidentally got merged together<br>
(primarily #5 had incorrectly gotten squashed into #4).<br>
* Pass unique_ptrs by value instead of by reference.<br>
v3:<br>
* Have the TypoCorrectionConsumer remember all TypoCorrections it has<br>
returned instead of just the last one, and add the ability to restart/replay<br>
returning those TypoCorrections.<br>
* Rework TransformTypos to try all combinations of typo corrections when<br>
multiple TypoExpr nodes are present within the same Expr.<br>
* Add a helper method to TypoExpr to free the unique_ptr members once the<br>
TypoExpr has been processed e.g by TransformTypos.<br>
* A few other small changes in response to review feedback of patches 2 and 5.<br>
v4:<br>
* Rebase against ToT and resolve all merge conflicts and related changes.<br>
* Remove layering violation in the AST library by having Sema keep track of<br>
the Sema-specific state associated with each TypoExpr.<br>
* Make the typo count tracking in an ExpressionEvaluationContext to be more<br>
accurate by taking advantage of the TypoExpr state being tracked by Sema.<br>
* Keep track of the callees that were OverloadExprs which are subsequently<br>
resolved by TreeTransform<T>::RebuildCallExpr, and use that information when<br>
emitting typo correction diagnostics to select the right decl for the<br>
diagnostic note.<br>
* Remove the overload resolution code for members that are the callee in a<br>
CallExpr from the MemberExprTypoRecovery callback now that it is no longer<br>
needed to emit notes on the correct decl of an overloaded method.<br>
* Make the TypoCorrections passed to the various callbacks be const references<br>
and have the TypoCorrectionConsumer return the current and new<br>
TypoCorrection by const reference so that they remain immutable and replays<br>
of the typo correction stream are always identical, now that modifying the<br>
TypoCorrection in the recovery callback is no longer necessary to emit<br>
correct diagnostic notes.<br>
* Remove the expression stack tracking in the TypoExpr tree transform now that<br>
the parent Expr no longer needs to be passed to the recovery callback.<br>
* Submit the previous patch 7, "Add another keyword-selection flag to<br>
CorrectionCandidateCallback", separately with its own test (r214109).<br>
* A few other small changes in response to review feedback of patches 6 and 9.<br>
<br>
Note that dealing with TypoExprs that weren't handled by a call to<br>
ActOnFinishFullExpr is still missing. It will be coming in a subsequent patch<br>
since I don't have a good reproduction for having LookupMemberExpr create a<br>
TypoExpr that isn't subsequently dealt with by ActOnFinishFullExpr, while such<br>
cases are common when having DiagnoseEmptyLookup call CorrectTypoDelayed on<br>
behalf of ActOnFinishFullExpr.<br>
<br>
(I skipped re-mailing patch 1, "Move TypoCorrectionConsumer into a header",<br>
since it hasn't changed since the first versions of this patchset.)<br>
<br>
Kaelyn Takata (8):<br>
Move TypoCorrectionConsumer into a header.<br>
Add the initial TypoExpr AST node for delayed typo correction.<br>
Pass around CorrectionCandidateCallbacks as unique_ptrs so<br>
TypoCorrectionConsumer can keep the callback around as long as<br>
needed.<br>
Have TypoCorrectionConsumer remember the TypoCorrections it returned.<br>
Start adding the infrastructure for handling TypoExprs.<br>
Add simple way for a CorrectionCandidateCallback to reject exact<br>
matches of the typo.<br>
Add a callback for recovering using a typo correction.<br>
Wire up LookupMemberExpr to use the new TypoExpr.<br>
<br>
include/clang/AST/DataRecursiveASTVisitor.h | 1 +<br>
include/clang/AST/Expr.h | 18 +<br>
include/clang/AST/RecursiveASTVisitor.h | 1 +<br>
include/clang/Basic/StmtNodes.td | 1 +<br>
include/clang/Parse/Parser.h | 5 +-<br>
include/clang/Sema/Sema.h | 75 +++-<br>
include/clang/Sema/SemaInternal.h | 181 ++++++++-<br>
include/clang/Sema/TypoCorrection.h | 38 +-<br>
lib/AST/Expr.cpp | 1 +<br>
lib/AST/ExprClassification.cpp | 3 +-<br>
lib/AST/ExprConstant.cpp | 1 +<br>
lib/AST/ItaniumMangle.cpp | 1 +<br>
lib/AST/StmtPrinter.cpp | 5 +<br>
lib/AST/StmtProfile.cpp | 4 +<br>
lib/Parse/ParseExpr.cpp | 8 +-<br>
lib/Parse/ParseStmt.cpp | 6 +-<br>
lib/Parse/ParseTentative.cpp | 8 +-<br>
lib/Parse/Parser.cpp | 8 +-<br>
lib/Sema/SemaCXXScopeSpec.cpp | 9 +-<br>
lib/Sema/SemaDecl.cpp | 57 ++-<br>
lib/Sema/SemaDeclCXX.cpp | 27 +-<br>
lib/Sema/SemaDeclObjC.cpp | 21 +-<br>
lib/Sema/SemaExceptionSpec.cpp | 1 +<br>
lib/Sema/SemaExpr.cpp | 44 ++-<br>
lib/Sema/SemaExprCXX.cpp | 149 +++++++<br>
lib/Sema/SemaExprMember.cpp | 131 ++++++-<br>
lib/Sema/SemaExprObjC.cpp | 18 +-<br>
lib/Sema/SemaInit.cpp | 4 +-<br>
lib/Sema/SemaLambda.cpp | 4 +-<br>
lib/Sema/SemaLookup.cpp | 587 +++++++++++++---------------<br>
lib/Sema/SemaOpenMP.cpp | 7 +-<br>
lib/Sema/SemaOverload.cpp | 23 +-<br>
lib/Sema/SemaTemplate.cpp | 17 +-<br>
lib/Sema/SemaTemplateVariadic.cpp | 8 +-<br>
lib/Sema/TreeTransform.h | 6 +<br>
lib/Serialization/ASTReaderStmt.cpp | 4 +<br>
lib/Serialization/ASTWriterStmt.cpp | 6 +<br>
lib/StaticAnalyzer/Core/ExprEngine.cpp | 1 +<br>
test/SemaCXX/arrow-operator.cpp | 5 +-<br>
test/SemaCXX/typo-correction-delayed.cpp | 32 ++<br>
test/SemaCXX/typo-correction-pt2.cpp | 2 +-<br>
test/SemaCXX/typo-correction.cpp | 10 +-<br>
tools/libclang/CXCursor.cpp | 1 +<br>
43 files changed, 1057 insertions(+), 482 deletions(-)<br>
create mode 100644 test/SemaCXX/typo-correction-delayed.cpp<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
2.0.0.526.g5318336<br>
<br>
</font></span></blockquote></div><br></div>