[PATCH v3 0/9] Initial implementation of delayed typo correction.
Kaelyn Takata
rikka at google.com
Mon Jul 14 16:55:32 PDT 2014
This patch set adds a new node to the AST called a TypoExpr. It is used as a
placeholder to delay typo correction until a full expression is being finalized
(via Sema::ActOnFinishFullExpr), at which point a TreeTransform is run to
replace each TypoExpr by performing typo correction. This allows, for example,
to delay typo correction on a call to a class method until after the arguments
have been parsed, instead of trying to do the typo correction while looking up
the member before the parser has even reached the opening parenthesis. The
patches have been broken up such that clang builds and the tests pass after
each patch in the sequence has been applied. The first patch is included in
here despite being a simple, mechanical moving around of code (instead of
committing it directly) because it is unnecessary/useless outside of the rest
of the patch set.
v2:
* Unmunge a couple of patches that accidentally got merged together
(primarily #5 had incorrectly gotten squashed into #4).
* Pass unique_ptrs by value instead of by reference.
v3:
* Have the TypoCorrectionConsumer remember all TypoCorrections it has
returned instead of just the last one, and add the ability to restart/replay
returning those TypoCorrections.
* Rework TransformTypos to try all combinations of typo corrections when
multiple TypoExpr nodes are present within the same Expr.
* Add a helper method to TypoExpr to free the unique_ptr members once the
TypoExpr has been processed e.g by TransformTypos.
* A few other small changes in response to review feedback of patches 2 and 5.
Note that dealing with TypoExprs that weren't handled by a call to
ActOnFinishFullExpr is still missing. It will be coming in a subsequent patch
since I don't have a good reproduction for having LookupMemberExpr create a
TypoExpr that isn't subsequently dealt with by ActOnFinishFullExpr, while such
cases are common when having DiagnoseEmptyLookup call CorrectTypoDelayed on
behalf of ActOnFinishFullExpr.
Kaelyn Takata (9):
Move TypoCorrectionConsumer into a header.
Add the initial TypoExpr AST node for delayed typo correction.
Pass around CorrectionCandidateCallbacks as unique_ptrs so
TypoCorrectionConsumer can keep the callback around as long as
needed.
Have TypoCorrectionConsumer remember the TypoCorrections it returned.
Start adding the infrastructure for handling TypoExprs.
Add simple way for a CorrectionCandidateCallback to reject exact
matches of the typo.
Add another keyword-selection flag to CorrectionCandidateCallback.
Add a callback for recovering using a typo correction.
Wire up LookupMemberExpr to use the new TypoExpr.
include/clang/AST/DataRecursiveASTVisitor.h | 1 +
include/clang/AST/Expr.h | 23 ++
include/clang/AST/RecursiveASTVisitor.h | 1 +
include/clang/Basic/StmtNodes.td | 1 +
include/clang/Parse/Parser.h | 5 +-
include/clang/Sema/Sema.h | 53 ++-
include/clang/Sema/SemaInternal.h | 181 ++++++++-
include/clang/Sema/TypoCorrection.h | 47 ++-
lib/AST/Expr.cpp | 1 +
lib/AST/ExprClassification.cpp | 3 +-
lib/AST/ExprConstant.cpp | 1 +
lib/AST/ItaniumMangle.cpp | 1 +
lib/AST/StmtPrinter.cpp | 5 +
lib/AST/StmtProfile.cpp | 4 +
lib/Parse/ParseExpr.cpp | 8 +-
lib/Parse/ParseStmt.cpp | 6 +-
lib/Parse/ParseTentative.cpp | 8 +-
lib/Parse/Parser.cpp | 8 +-
lib/Sema/SemaCXXScopeSpec.cpp | 9 +-
lib/Sema/SemaDecl.cpp | 57 ++-
lib/Sema/SemaDeclCXX.cpp | 27 +-
lib/Sema/SemaDeclObjC.cpp | 21 +-
lib/Sema/SemaExceptionSpec.cpp | 1 +
lib/Sema/SemaExpr.cpp | 44 ++-
lib/Sema/SemaExprCXX.cpp | 117 ++++++
lib/Sema/SemaExprMember.cpp | 164 +++++++-
lib/Sema/SemaExprObjC.cpp | 18 +-
lib/Sema/SemaInit.cpp | 4 +-
lib/Sema/SemaLambda.cpp | 4 +-
lib/Sema/SemaLookup.cpp | 594 ++++++++++++++--------------
lib/Sema/SemaOpenMP.cpp | 7 +-
lib/Sema/SemaOverload.cpp | 23 +-
lib/Sema/SemaTemplate.cpp | 17 +-
lib/Sema/SemaTemplateVariadic.cpp | 8 +-
lib/Sema/TreeTransform.h | 6 +
lib/Serialization/ASTReaderStmt.cpp | 4 +
lib/Serialization/ASTWriterStmt.cpp | 6 +
lib/StaticAnalyzer/Core/ExprEngine.cpp | 1 +
test/SemaCXX/arrow-operator.cpp | 5 +-
test/SemaCXX/typo-correction-delayed.cpp | 32 ++
test/SemaCXX/typo-correction-pt2.cpp | 2 +-
test/SemaCXX/typo-correction.cpp | 10 +-
tools/libclang/CXCursor.cpp | 1 +
43 files changed, 1054 insertions(+), 485 deletions(-)
create mode 100644 test/SemaCXX/typo-correction-delayed.cpp
--
2.0.0.526.g5318336
More information about the cfe-commits
mailing list