From ebbcfcf837f3aadc20f8b0c091fc2d6ca20c6d8f Mon Sep 17 00:00:00 2001 From: Kaelyn Takata Date: Mon, 27 Oct 2014 18:07:20 +0000 Subject: [PATCH] Add the initial TypoExpr AST node for delayed typo correction. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@220692 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/DataRecursiveASTVisitor.h | 1 + include/clang/AST/Expr.h | 18 ++++++++++++++++++ include/clang/AST/RecursiveASTVisitor.h | 1 + include/clang/Basic/StmtNodes.td | 1 + include/clang/Sema/SemaInternal.h | 3 +++ 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/Sema/SemaExceptionSpec.cpp | 1 + lib/Sema/TreeTransform.h | 6 ++++++ lib/Serialization/ASTReaderStmt.cpp | 4 ++++ lib/Serialization/ASTWriterStmt.cpp | 6 ++++++ lib/StaticAnalyzer/Core/ExprEngine.cpp | 1 + tools/libclang/CXCursor.cpp | 1 + 17 files changed, 57 insertions(+), 1 deletion(-) diff --git a/include/clang/AST/DataRecursiveASTVisitor.h b/include/clang/AST/DataRecursiveASTVisitor.h index 54c22fbda3..f528e1cabb 100644 --- a/include/clang/AST/DataRecursiveASTVisitor.h +++ b/include/clang/AST/DataRecursiveASTVisitor.h @@ -2240,6 +2240,7 @@ DEF_TRAVERSE_STMT(CapturedStmt, { TRY_TO(TraverseDecl(S->getCapturedDecl())); }) DEF_TRAVERSE_STMT(CXXOperatorCallExpr, {}) DEF_TRAVERSE_STMT(OpaqueValueExpr, {}) +DEF_TRAVERSE_STMT(TypoExpr, {}) DEF_TRAVERSE_STMT(CUDAKernelCallExpr, {}) // These operators (all of them) do not need any action except diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 2b2adc810a..b838204b5d 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -4846,6 +4846,24 @@ public: return child_range(SubExprs, SubExprs+NumSubExprs); } }; + +/// TypoExpr - Internal placeholder for expressions where typo correction +/// still needs to be performed and/or an error diagnostic emitted. +class TypoExpr : public Expr { +public: + TypoExpr(QualType T) + : Expr(TypoExprClass, T, VK_LValue, OK_Ordinary, + /*isTypeDependent*/ true, + /*isValueDependent*/ true, + /*isInstantiationDependent*/ true, + /*containsUnexpandedParameterPack*/ false) { + assert(T->isDependentType() && "TypoExpr given a non-dependent type"); + } + + child_range children() { return child_range(); } + SourceLocation getLocStart() const LLVM_READONLY { return SourceLocation(); } + SourceLocation getLocEnd() const LLVM_READONLY { return SourceLocation(); } +}; } // end namespace clang #endif diff --git a/include/clang/AST/RecursiveASTVisitor.h b/include/clang/AST/RecursiveASTVisitor.h index bda4916201..4688beae8b 100644 --- a/include/clang/AST/RecursiveASTVisitor.h +++ b/include/clang/AST/RecursiveASTVisitor.h @@ -2262,6 +2262,7 @@ DEF_TRAVERSE_STMT(CapturedStmt, { TRY_TO(TraverseDecl(S->getCapturedDecl())); }) DEF_TRAVERSE_STMT(CXXOperatorCallExpr, {}) DEF_TRAVERSE_STMT(OpaqueValueExpr, {}) +DEF_TRAVERSE_STMT(TypoExpr, {}) DEF_TRAVERSE_STMT(CUDAKernelCallExpr, {}) // These operators (all of them) do not need any action except diff --git a/include/clang/Basic/StmtNodes.td b/include/clang/Basic/StmtNodes.td index be025e344a..ea2f931c1a 100644 --- a/include/clang/Basic/StmtNodes.td +++ b/include/clang/Basic/StmtNodes.td @@ -163,6 +163,7 @@ def ShuffleVectorExpr : DStmt; def ConvertVectorExpr : DStmt; def BlockExpr : DStmt; def OpaqueValueExpr : DStmt; +def TypoExpr : DStmt; // Microsoft Extensions. def MSPropertyRefExpr : DStmt; diff --git a/include/clang/Sema/SemaInternal.h b/include/clang/Sema/SemaInternal.h index 59920d20dc..9f0d39a11d 100644 --- a/include/clang/Sema/SemaInternal.h +++ b/include/clang/Sema/SemaInternal.h @@ -149,6 +149,9 @@ public: /// in the consumer. TypoCorrection getNextCorrection(); + ASTContext &getContext() const { return SemaRef.Context; } + const LookupResult &getLookupResult() const { return Result; } + private: class NamespaceSpecifierSet { struct SpecifierInfo { diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 5020d5a9e2..ec679f0669 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -2886,6 +2886,7 @@ bool Expr::HasSideEffects(const ASTContext &Ctx) const { case PackExpansionExprClass: case SubstNonTypeTemplateParmPackExprClass: case FunctionParmPackExprClass: + case TypoExprClass: llvm_unreachable("shouldn't see dependent / unresolved nodes here"); case DeclRefExprClass: diff --git a/lib/AST/ExprClassification.cpp b/lib/AST/ExprClassification.cpp index d3d25308a3..4e2e3ea2ee 100644 --- a/lib/AST/ExprClassification.cpp +++ b/lib/AST/ExprClassification.cpp @@ -124,10 +124,11 @@ static Cl::Kinds ClassifyInternal(ASTContext &Ctx, const Expr *E) { case Expr::ObjCPropertyRefExprClass: // C++ [expr.typeid]p1: The result of a typeid expression is an lvalue of... case Expr::CXXTypeidExprClass: - // Unresolved lookups get classified as lvalues. + // Unresolved lookups and uncorrected typos get classified as lvalues. // FIXME: Is this wise? Should they get their own kind? case Expr::UnresolvedLookupExprClass: case Expr::UnresolvedMemberExprClass: + case Expr::TypoExprClass: case Expr::CXXDependentScopeMemberExprClass: case Expr::DependentScopeDeclRefExprClass: // ObjC instance variables are lvalues diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 78de2578be..d49d9b2c27 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -8625,6 +8625,7 @@ static ICEDiag CheckICE(const Expr* E, const ASTContext &Ctx) { case Expr::CXXDeleteExprClass: case Expr::CXXPseudoDestructorExprClass: case Expr::UnresolvedLookupExprClass: + case Expr::TypoExprClass: case Expr::DependentScopeDeclRefExprClass: case Expr::CXXConstructExprClass: case Expr::CXXStdInitializerListExprClass: diff --git a/lib/AST/ItaniumMangle.cpp b/lib/AST/ItaniumMangle.cpp index 76664673d5..e41c664c8f 100644 --- a/lib/AST/ItaniumMangle.cpp +++ b/lib/AST/ItaniumMangle.cpp @@ -2627,6 +2627,7 @@ recurse: case Expr::ParenListExprClass: case Expr::LambdaExprClass: case Expr::MSPropertyRefExprClass: + case Expr::TypoExprClass: // This should no longer exist in the AST by now. llvm_unreachable("unexpected statement kind"); // FIXME: invent manglings for all these. diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp index c84875c09f..b5441c830d 100644 --- a/lib/AST/StmtPrinter.cpp +++ b/lib/AST/StmtPrinter.cpp @@ -2166,6 +2166,11 @@ void StmtPrinter::VisitOpaqueValueExpr(OpaqueValueExpr *Node) { PrintExpr(Node->getSourceExpr()); } +void StmtPrinter::VisitTypoExpr(TypoExpr *Node) { + // TODO: Print something reasonable for a TypoExpr, if necessary. + assert(false && "Cannot print TypoExpr nodes"); +} + void StmtPrinter::VisitAsTypeExpr(AsTypeExpr *Node) { OS << "__builtin_astype("; PrintExpr(Node->getSrcExpr()); diff --git a/lib/AST/StmtProfile.cpp b/lib/AST/StmtProfile.cpp index 87e30bb3e3..15a8676986 100644 --- a/lib/AST/StmtProfile.cpp +++ b/lib/AST/StmtProfile.cpp @@ -1242,6 +1242,10 @@ void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) { VisitExpr(E); } +void StmtProfiler::VisitTypoExpr(const TypoExpr *E) { + VisitExpr(E); +} + void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) { VisitExpr(S); } diff --git a/lib/Sema/SemaExceptionSpec.cpp b/lib/Sema/SemaExceptionSpec.cpp index e4963b13d6..ac0616df74 100644 --- a/lib/Sema/SemaExceptionSpec.cpp +++ b/lib/Sema/SemaExceptionSpec.cpp @@ -1068,6 +1068,7 @@ CanThrowResult Sema::canThrow(const Expr *E) { case Expr::UnaryExprOrTypeTraitExprClass: case Expr::UnresolvedLookupExprClass: case Expr::UnresolvedMemberExprClass: + case Expr::TypoExprClass: // FIXME: Can any of the above throw? If so, when? return CT_Cannot; diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index 28890f59ce..c569d31f7e 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -7321,6 +7321,12 @@ TreeTransform::TransformOpaqueValueExpr(OpaqueValueExpr *E) { return E; } +template +ExprResult +TreeTransform::TransformTypoExpr(TypoExpr *E) { + return E; +} + template ExprResult TreeTransform::TransformPseudoObjectExpr(PseudoObjectExpr *E) { diff --git a/lib/Serialization/ASTReaderStmt.cpp b/lib/Serialization/ASTReaderStmt.cpp index d2b7568dfa..5b4e12cbb4 100644 --- a/lib/Serialization/ASTReaderStmt.cpp +++ b/lib/Serialization/ASTReaderStmt.cpp @@ -1588,6 +1588,10 @@ void ASTStmtReader::VisitOpaqueValueExpr(OpaqueValueExpr *E) { E->Loc = ReadSourceLocation(Record, Idx); } +void ASTStmtReader::VisitTypoExpr(TypoExpr *E) { + llvm_unreachable("Cannot read TypoExpr nodes"); +} + //===----------------------------------------------------------------------===// // Microsoft Expressions and Statements //===----------------------------------------------------------------------===// diff --git a/lib/Serialization/ASTWriterStmt.cpp b/lib/Serialization/ASTWriterStmt.cpp index 6891f56e2d..18aad2ffe8 100644 --- a/lib/Serialization/ASTWriterStmt.cpp +++ b/lib/Serialization/ASTWriterStmt.cpp @@ -1588,6 +1588,12 @@ void ASTStmtWriter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { Code = serialization::EXPR_OPAQUE_VALUE; } +void ASTStmtWriter::VisitTypoExpr(TypoExpr *E) { + VisitExpr(E); + // TODO: Figure out sane writer behavior for a TypoExpr, if necessary + assert(false && "Cannot write TypoExpr nodes"); +} + //===----------------------------------------------------------------------===// // CUDA Expressions and Statements. //===----------------------------------------------------------------------===// diff --git a/lib/StaticAnalyzer/Core/ExprEngine.cpp b/lib/StaticAnalyzer/Core/ExprEngine.cpp index c844147e35..7464b84c4a 100644 --- a/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ b/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -760,6 +760,7 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred, case Stmt::ExpressionTraitExprClass: case Stmt::UnresolvedLookupExprClass: case Stmt::UnresolvedMemberExprClass: + case Stmt::TypoExprClass: case Stmt::CXXNoexceptExprClass: case Stmt::PackExpansionExprClass: case Stmt::SubstNonTypeTemplateParmPackExprClass: diff --git a/tools/libclang/CXCursor.cpp b/tools/libclang/CXCursor.cpp index 6590b158e5..2c83236ca9 100644 --- a/tools/libclang/CXCursor.cpp +++ b/tools/libclang/CXCursor.cpp @@ -469,6 +469,7 @@ CXCursor cxcursor::MakeCXCursor(const Stmt *S, const Decl *Parent, case Stmt::SubstNonTypeTemplateParmPackExprClass: case Stmt::FunctionParmPackExprClass: case Stmt::UnresolvedLookupExprClass: + case Stmt::TypoExprClass: // A typo could actually be a DeclRef or a MemberRef K = CXCursor_DeclRefExpr; break; -- 2.40.0