Procházet zdrojové kódy

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
Kaelyn Takata před 10 roky
rodič
revize
ebbcfcf837

+ 1 - 0
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(CXXOperatorCallExpr, {})
 DEF_TRAVERSE_STMT(OpaqueValueExpr, {})
 DEF_TRAVERSE_STMT(OpaqueValueExpr, {})
+DEF_TRAVERSE_STMT(TypoExpr, {})
 DEF_TRAVERSE_STMT(CUDAKernelCallExpr, {})
 DEF_TRAVERSE_STMT(CUDAKernelCallExpr, {})
 
 
 // These operators (all of them) do not need any action except
 // These operators (all of them) do not need any action except

+ 18 - 0
include/clang/AST/Expr.h

@@ -4846,6 +4846,24 @@ public:
     return child_range(SubExprs, SubExprs+NumSubExprs);
     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
 }  // end namespace clang
 
 
 #endif
 #endif

+ 1 - 0
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(CXXOperatorCallExpr, {})
 DEF_TRAVERSE_STMT(OpaqueValueExpr, {})
 DEF_TRAVERSE_STMT(OpaqueValueExpr, {})
+DEF_TRAVERSE_STMT(TypoExpr, {})
 DEF_TRAVERSE_STMT(CUDAKernelCallExpr, {})
 DEF_TRAVERSE_STMT(CUDAKernelCallExpr, {})
 
 
 // These operators (all of them) do not need any action except
 // These operators (all of them) do not need any action except

+ 1 - 0
include/clang/Basic/StmtNodes.td

@@ -163,6 +163,7 @@ def ShuffleVectorExpr : DStmt<Expr>;
 def ConvertVectorExpr : DStmt<Expr>;
 def ConvertVectorExpr : DStmt<Expr>;
 def BlockExpr : DStmt<Expr>;
 def BlockExpr : DStmt<Expr>;
 def OpaqueValueExpr : DStmt<Expr>;
 def OpaqueValueExpr : DStmt<Expr>;
+def TypoExpr : DStmt<Expr>;
 
 
 // Microsoft Extensions.
 // Microsoft Extensions.
 def MSPropertyRefExpr : DStmt<Expr>;
 def MSPropertyRefExpr : DStmt<Expr>;

+ 3 - 0
include/clang/Sema/SemaInternal.h

@@ -149,6 +149,9 @@ public:
   /// in the consumer.
   /// in the consumer.
   TypoCorrection getNextCorrection();
   TypoCorrection getNextCorrection();
 
 
+  ASTContext &getContext() const { return SemaRef.Context; }
+  const LookupResult &getLookupResult() const { return Result; }
+
 private:
 private:
   class NamespaceSpecifierSet {
   class NamespaceSpecifierSet {
     struct SpecifierInfo {
     struct SpecifierInfo {

+ 1 - 0
lib/AST/Expr.cpp

@@ -2886,6 +2886,7 @@ bool Expr::HasSideEffects(const ASTContext &Ctx) const {
   case PackExpansionExprClass:
   case PackExpansionExprClass:
   case SubstNonTypeTemplateParmPackExprClass:
   case SubstNonTypeTemplateParmPackExprClass:
   case FunctionParmPackExprClass:
   case FunctionParmPackExprClass:
+  case TypoExprClass:
     llvm_unreachable("shouldn't see dependent / unresolved nodes here");
     llvm_unreachable("shouldn't see dependent / unresolved nodes here");
 
 
   case DeclRefExprClass:
   case DeclRefExprClass:

+ 2 - 1
lib/AST/ExprClassification.cpp

@@ -124,10 +124,11 @@ static Cl::Kinds ClassifyInternal(ASTContext &Ctx, const Expr *E) {
   case Expr::ObjCPropertyRefExprClass:
   case Expr::ObjCPropertyRefExprClass:
     // C++ [expr.typeid]p1: The result of a typeid expression is an lvalue of...
     // C++ [expr.typeid]p1: The result of a typeid expression is an lvalue of...
   case Expr::CXXTypeidExprClass:
   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?
     // FIXME: Is this wise? Should they get their own kind?
   case Expr::UnresolvedLookupExprClass:
   case Expr::UnresolvedLookupExprClass:
   case Expr::UnresolvedMemberExprClass:
   case Expr::UnresolvedMemberExprClass:
+  case Expr::TypoExprClass:
   case Expr::CXXDependentScopeMemberExprClass:
   case Expr::CXXDependentScopeMemberExprClass:
   case Expr::DependentScopeDeclRefExprClass:
   case Expr::DependentScopeDeclRefExprClass:
     // ObjC instance variables are lvalues
     // ObjC instance variables are lvalues

+ 1 - 0
lib/AST/ExprConstant.cpp

@@ -8625,6 +8625,7 @@ static ICEDiag CheckICE(const Expr* E, const ASTContext &Ctx) {
   case Expr::CXXDeleteExprClass:
   case Expr::CXXDeleteExprClass:
   case Expr::CXXPseudoDestructorExprClass:
   case Expr::CXXPseudoDestructorExprClass:
   case Expr::UnresolvedLookupExprClass:
   case Expr::UnresolvedLookupExprClass:
+  case Expr::TypoExprClass:
   case Expr::DependentScopeDeclRefExprClass:
   case Expr::DependentScopeDeclRefExprClass:
   case Expr::CXXConstructExprClass:
   case Expr::CXXConstructExprClass:
   case Expr::CXXStdInitializerListExprClass:
   case Expr::CXXStdInitializerListExprClass:

+ 1 - 0
lib/AST/ItaniumMangle.cpp

@@ -2627,6 +2627,7 @@ recurse:
   case Expr::ParenListExprClass:
   case Expr::ParenListExprClass:
   case Expr::LambdaExprClass:
   case Expr::LambdaExprClass:
   case Expr::MSPropertyRefExprClass:
   case Expr::MSPropertyRefExprClass:
+  case Expr::TypoExprClass:  // This should no longer exist in the AST by now.
     llvm_unreachable("unexpected statement kind");
     llvm_unreachable("unexpected statement kind");
 
 
   // FIXME: invent manglings for all these.
   // FIXME: invent manglings for all these.

+ 5 - 0
lib/AST/StmtPrinter.cpp

@@ -2166,6 +2166,11 @@ void StmtPrinter::VisitOpaqueValueExpr(OpaqueValueExpr *Node) {
   PrintExpr(Node->getSourceExpr());
   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) {
 void StmtPrinter::VisitAsTypeExpr(AsTypeExpr *Node) {
   OS << "__builtin_astype(";
   OS << "__builtin_astype(";
   PrintExpr(Node->getSrcExpr());
   PrintExpr(Node->getSrcExpr());

+ 4 - 0
lib/AST/StmtProfile.cpp

@@ -1242,6 +1242,10 @@ void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
   VisitExpr(E);  
   VisitExpr(E);  
 }
 }
 
 
+void StmtProfiler::VisitTypoExpr(const TypoExpr *E) {
+  VisitExpr(E);
+}
+
 void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
 void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
   VisitExpr(S);
   VisitExpr(S);
 }
 }

+ 1 - 0
lib/Sema/SemaExceptionSpec.cpp

@@ -1068,6 +1068,7 @@ CanThrowResult Sema::canThrow(const Expr *E) {
   case Expr::UnaryExprOrTypeTraitExprClass:
   case Expr::UnaryExprOrTypeTraitExprClass:
   case Expr::UnresolvedLookupExprClass:
   case Expr::UnresolvedLookupExprClass:
   case Expr::UnresolvedMemberExprClass:
   case Expr::UnresolvedMemberExprClass:
+  case Expr::TypoExprClass:
     // FIXME: Can any of the above throw?  If so, when?
     // FIXME: Can any of the above throw?  If so, when?
     return CT_Cannot;
     return CT_Cannot;
 
 

+ 6 - 0
lib/Sema/TreeTransform.h

@@ -7321,6 +7321,12 @@ TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
   return E;
   return E;
 }
 }
 
 
+template<typename Derived>
+ExprResult
+TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
+  return E;
+}
+
 template<typename Derived>
 template<typename Derived>
 ExprResult
 ExprResult
 TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
 TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {

+ 4 - 0
lib/Serialization/ASTReaderStmt.cpp

@@ -1588,6 +1588,10 @@ void ASTStmtReader::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
   E->Loc = ReadSourceLocation(Record, Idx);
   E->Loc = ReadSourceLocation(Record, Idx);
 }
 }
 
 
+void ASTStmtReader::VisitTypoExpr(TypoExpr *E) {
+  llvm_unreachable("Cannot read TypoExpr nodes");
+}
+
 //===----------------------------------------------------------------------===//
 //===----------------------------------------------------------------------===//
 // Microsoft Expressions and Statements
 // Microsoft Expressions and Statements
 //===----------------------------------------------------------------------===//
 //===----------------------------------------------------------------------===//

+ 6 - 0
lib/Serialization/ASTWriterStmt.cpp

@@ -1588,6 +1588,12 @@ void ASTStmtWriter::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
   Code = serialization::EXPR_OPAQUE_VALUE;
   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.
 // CUDA Expressions and Statements.
 //===----------------------------------------------------------------------===//
 //===----------------------------------------------------------------------===//

+ 1 - 0
lib/StaticAnalyzer/Core/ExprEngine.cpp

@@ -760,6 +760,7 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred,
     case Stmt::ExpressionTraitExprClass:
     case Stmt::ExpressionTraitExprClass:
     case Stmt::UnresolvedLookupExprClass:
     case Stmt::UnresolvedLookupExprClass:
     case Stmt::UnresolvedMemberExprClass:
     case Stmt::UnresolvedMemberExprClass:
+    case Stmt::TypoExprClass:
     case Stmt::CXXNoexceptExprClass:
     case Stmt::CXXNoexceptExprClass:
     case Stmt::PackExpansionExprClass:
     case Stmt::PackExpansionExprClass:
     case Stmt::SubstNonTypeTemplateParmPackExprClass:
     case Stmt::SubstNonTypeTemplateParmPackExprClass:

+ 1 - 0
tools/libclang/CXCursor.cpp

@@ -469,6 +469,7 @@ CXCursor cxcursor::MakeCXCursor(const Stmt *S, const Decl *Parent,
   case Stmt::SubstNonTypeTemplateParmPackExprClass:
   case Stmt::SubstNonTypeTemplateParmPackExprClass:
   case Stmt::FunctionParmPackExprClass:
   case Stmt::FunctionParmPackExprClass:
   case Stmt::UnresolvedLookupExprClass:
   case Stmt::UnresolvedLookupExprClass:
+  case Stmt::TypoExprClass: // A typo could actually be a DeclRef or a MemberRef
     K = CXCursor_DeclRefExpr;
     K = CXCursor_DeclRefExpr;
     break;
     break;