Add support for C++ namespace-aware typo correction, e.g., correcting

  vector<int>

to

  std::vector<int>

Patch by Kaelyn Uhrain, with minor tweaks + PCH support from me. Fixes
PR5776/<rdar://problem/8652971>.

Thanks Kaelyn!


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@134007 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp
index 80d3a74..c02b634 100644
--- a/lib/Sema/SemaExprObjC.cpp
+++ b/lib/Sema/SemaExprObjC.cpp
@@ -663,14 +663,15 @@
   }
 
   // Attempt to correct for typos in property names.
-  LookupResult Res(*this, MemberName, MemberLoc, LookupOrdinaryName);
-  if (CorrectTypo(Res, 0, 0, IFace, false, CTC_NoKeywords, OPT) &&
-      Res.getAsSingle<ObjCPropertyDecl>()) {
-    DeclarationName TypoResult = Res.getLookupName();
+  TypoCorrection Corrected = CorrectTypo(
+      DeclarationNameInfo(MemberName, MemberLoc), LookupOrdinaryName, NULL,
+      NULL, IFace, false, CTC_NoKeywords, OPT);
+  if (ObjCPropertyDecl *Property =
+      Corrected.getCorrectionDeclAs<ObjCPropertyDecl>()) {
+    DeclarationName TypoResult = Corrected.getCorrection();
     Diag(MemberLoc, diag::err_property_not_found_suggest)
       << MemberName << QualType(OPT, 0) << TypoResult
       << FixItHint::CreateReplacement(MemberLoc, TypoResult.getAsString());
-    ObjCPropertyDecl *Property = Res.getAsSingle<ObjCPropertyDecl>();
     Diag(Property->getLocation(), diag::note_previous_decl)
       << Property->getDeclName();
     return HandleExprPropertyRefExpr(OPT, BaseExpr, OpLoc,
@@ -898,29 +899,30 @@
         Method->getClassInterface()->getSuperClass())
       CTC = CTC_ObjCMessageReceiver;
       
-  if (DeclarationName Corrected = CorrectTypo(Result, S, 0, 0, false, CTC)) {
-    if (Result.isSingleResult()) {
+  if (TypoCorrection Corrected = CorrectTypo(Result.getLookupNameInfo(),
+                                             Result.getLookupKind(), S, NULL,
+                                             NULL, false, CTC)) {
+    if (NamedDecl *ND = Corrected.getCorrectionDecl()) {
       // If we found a declaration, correct when it refers to an Objective-C
       // class.
-      NamedDecl *ND = Result.getFoundDecl();
       if (ObjCInterfaceDecl *Class = dyn_cast<ObjCInterfaceDecl>(ND)) {
         Diag(NameLoc, diag::err_unknown_receiver_suggest)
-          << Name << Result.getLookupName()
+          << Name << Corrected.getCorrection()
           << FixItHint::CreateReplacement(SourceRange(NameLoc),
                                           ND->getNameAsString());
         Diag(ND->getLocation(), diag::note_previous_decl)
-          << Corrected;
+          << Corrected.getCorrection();
 
         QualType T = Context.getObjCInterfaceType(Class);
         TypeSourceInfo *TSInfo = Context.getTrivialTypeSourceInfo(T, NameLoc);
         ReceiverType = CreateParsedType(T, TSInfo);
         return ObjCClassMessage;
       }
-    } else if (Result.empty() && Corrected.getAsIdentifierInfo() &&
-               Corrected.getAsIdentifierInfo()->isStr("super")) {
+    } else if (Corrected.isKeyword() &&
+               Corrected.getCorrectionAsIdentifierInfo()->isStr("super")) {
       // If we've found the keyword "super", this is a send to super.
       Diag(NameLoc, diag::err_unknown_receiver_suggest)
-        << Name << Corrected
+        << Name << Corrected.getCorrection()
         << FixItHint::CreateReplacement(SourceRange(NameLoc), "super");
       return ObjCSuperMessage;
     }