<div dir="ltr">On Fri, Sep 27, 2013 at 12:40 PM, Kaelyn Uhrain <span dir="ltr"><<a href="mailto:rikka@google.com" target="_blank">rikka@google.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rikka<br>
Date: Fri Sep 27 14:40:12 2013<br>
New Revision: 191544<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=191544&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=191544&view=rev</a><br>
Log:<br>
Avoid the hard-coded limit on the number of typo corrections attempted.<br>
<br>
Move some tests from typo-correction.cpp to typo-correction-pt2.cpp<br>
because they were running afoul of the hard-coded limit of 20 typos<br>
corrected. Some of the tests after it were still working due to the<br>
limit not applying to cached corrections and in cases where a non-NULL<br>
MemberContext is passed in to Sema::CorrectTypo.  Most of the moved tests<br>
still passed after being moved, but the test involving "data_struct" had<br>
only been passing because the test had exceeded that limit so a fix for<br>
it is also included (most of the changes to ParseStmt.cpp are shared with<br>
and originated from another typo correction impovement that was split<br>
into a separate commit).<br>
<br>
Modified:<br>
    cfe/trunk/lib/Parse/ParseStmt.cpp<br>
    cfe/trunk/test/SemaCXX/typo-correction-pt2.cpp<br>
    cfe/trunk/test/SemaCXX/typo-correction.cpp<br>
<br>
Modified: cfe/trunk/lib/Parse/ParseStmt.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=191544&r1=191543&r2=191544&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=191544&r1=191543&r2=191544&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/lib/Parse/ParseStmt.cpp (original)<br>
+++ cfe/trunk/lib/Parse/ParseStmt.cpp Fri Sep 27 14:40:12 2013<br>
@@ -111,6 +111,33 @@ Parser::ParseStatementOrDeclaration(Stmt<br>
   return Actions.ProcessStmtAttributes(Res.get(), Attrs.getList(), Attrs.Range);<br>
 }<br>
<br>
+namespace {<br>
+class StatementFilterCCC : public CorrectionCandidateCallback {<br>
+public:<br>
+  StatementFilterCCC(Token nextTok) : NextToken(nextTok) {<br></blockquote><div><br></div><div>Please name local variables starting with an uppercase letter in new code.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

+    WantTypeSpecifiers = nextTok.is(tok::l_paren) || nextTok.is(tok::less) ||<br>
+                         nextTok.is(tok::identifier) || nextTok.is(tok::star) ||<br>
+                         nextTok.is(tok::amp) || nextTok.is(tok::l_square);<br>
+    WantExpressionKeywords = nextTok.is(tok::l_paren) ||<br>
+                             nextTok.is(tok::identifier) ||<br>
+                             nextTok.is(tok::arrow) || nextTok.is(tok::period);<br>
+    WantRemainingKeywords = nextTok.is(tok::l_paren) || nextTok.is(tok::semi) ||<br>
+                            nextTok.is(tok::identifier) ||<br>
+                            nextTok.is(tok::l_brace);<br>
+    WantCXXNamedCasts = false;<br>
+  }<br>
+<br>
+  virtual bool ValidateCandidate(const TypoCorrection &candidate) {<br>
+    if (FieldDecl *FD = candidate.getCorrectionDeclAs<FieldDecl>())<br>
+      return isa<ObjCIvarDecl>(FD);<br></blockquote><div><br></div><div>Hmm, what happens if I write:</div><div><br></div><div>struct S {</div><div>  int my_member;</div><div>  void f() { my_menber = 1; }</div><div>
};</div><div><br></div><div>Will we still correct that?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+    return CorrectionCandidateCallback::ValidateCandidate(candidate);<br>
+  }<br>
+<br>
+private:<br>
+  Token NextToken;<br>
+};<br>
+}<br>
+<br>
 StmtResult<br>
 Parser::ParseStatementOrDeclarationAfterAttributes(StmtVector &Stmts,<br>
           bool OnlyStatement, SourceLocation *TrailingElseLoc,<br>
@@ -149,21 +176,8 @@ Retry:<br>
     if (Next.isNot(tok::coloncolon)) {<br>
       // Try to limit which sets of keywords should be included in typo<br>
       // correction based on what the next token is.<br>
-      // FIXME: Pass the next token into the CorrectionCandidateCallback and<br>
-      //        do this filtering in a more fine-grained manner.<br>
-      CorrectionCandidateCallback DefaultValidator;<br>
-      DefaultValidator.WantTypeSpecifiers =<br>
-          Next.is(tok::l_paren) || Next.is(tok::less) ||<br>
-          Next.is(tok::identifier) || Next.is(tok::star) ||<br>
-          Next.is(tok::amp) || Next.is(tok::l_square);<br>
-      DefaultValidator.WantExpressionKeywords =<br>
-          Next.is(tok::l_paren) || Next.is(tok::identifier) ||<br>
-          Next.is(tok::arrow) || Next.is(tok::period);<br>
-      DefaultValidator.WantRemainingKeywords =<br>
-          Next.is(tok::l_paren) || Next.is(tok::semi) ||<br>
-          Next.is(tok::identifier) || Next.is(tok::l_brace);<br>
-      DefaultValidator.WantCXXNamedCasts = false;<br>
-      if (TryAnnotateName(/*IsAddressOfOperand*/false, &DefaultValidator)<br>
+      StatementFilterCCC Validator(Next);<br>
+      if (TryAnnotateName(/*IsAddressOfOperand*/false, &Validator)<br>
             == ANK_Error) {<br>
         // Handle errors here by skipping up to the next semicolon or '}', and<br>
         // eat the semicolon if that's what stopped us.<br>
<br>
Modified: cfe/trunk/test/SemaCXX/typo-correction-pt2.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/typo-correction-pt2.cpp?rev=191544&r1=191543&r2=191544&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/typo-correction-pt2.cpp?rev=191544&r1=191543&r2=191544&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/test/SemaCXX/typo-correction-pt2.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/typo-correction-pt2.cpp Fri Sep 27 14:40:12 2013<br>
@@ -5,6 +5,37 @@<br>
 // attempt within a single file (which is to avoid having very broken files take<br>
 // minutes to finally be rejected by the parser).<br>
<br>
+namespace bogus_keyword_suggestion {<br>
+void test() {<br>
+   status = "OK";  // expected-error-re {{use of undeclared identifier 'status'$}}<br>
+   return status;  // expected-error-re {{use of undeclared identifier 'status'$}}<br>
+ }<br>
+}<br>
+<br>
+namespace PR13387 {<br>
+struct A {<br>
+  void CreateFoo(float, float);<br>
+  void CreateBar(float, float);<br>
+};<br>
+struct B : A {<br>
+  using A::CreateFoo;<br>
+  void CreateFoo(int, int);<br>
+};<br>
+void f(B &x) {<br>
+  x.Createfoo(0,0);  // expected-error {{no member named 'Createfoo' in 'PR13387::B'; did you mean 'CreateFoo'?}}<br>
+}<br>
+}<br>
+<br>
+struct DataStruct {void foo();};<br>
+struct T {<br>
+ DataStruct data_struct;<br>
+ void f();<br>
+};<br>
+// should be void T::f();<br>
+void f() {<br>
+ data_struct->foo();  // expected-error-re{{use of undeclared identifier 'data_struct'$}}<br>
+}<br>
+<br>
 namespace PR12287 {<br>
 class zif {<br>
   void nab(int);<br>
<br>
Modified: cfe/trunk/test/SemaCXX/typo-correction.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/typo-correction.cpp?rev=191544&r1=191543&r2=191544&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/typo-correction.cpp?rev=191544&r1=191543&r2=191544&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/test/SemaCXX/typo-correction.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/typo-correction.cpp Fri Sep 27 14:40:12 2013<br>
@@ -246,37 +246,6 @@ namespace outer {<br>
   }<br>
 }<br>
<br>
-namespace bogus_keyword_suggestion {<br>
-void test() {<br>
-   status = "OK"; // expected-error-re{{use of undeclared identifier 'status'$}}<br>
-   return status; // expected-error-re{{use of undeclared identifier 'status'$}}<br>
- }<br>
-}<br>
-<br>
-namespace PR13387 {<br>
-struct A {<br>
-  void CreateFoo(float, float);<br>
-  void CreateBar(float, float);<br>
-};<br>
-struct B : A {<br>
-  using A::CreateFoo;<br>
-  void CreateFoo(int, int);<br>
-};<br>
-void f(B &x) {<br>
-  x.Createfoo(0,0); // expected-error {{no member named 'Createfoo' in 'PR13387::B'; did you mean 'CreateFoo'?}}<br>
-}<br>
-}<br>
-<br>
-struct DataStruct {void foo();};<br>
-struct T {<br>
- DataStruct data_struct;<br>
- void f();<br>
-};<br>
-// should be void T::f();<br>
-void f() {<br>
- data_struct->foo(); // expected-error-re{{use of undeclared identifier 'data_struct'$}}<br>
-}<br>
-<br>
 namespace b6956809_test1 {<br>
   struct A {};<br>
   struct B {};<br>
@@ -319,9 +288,13 @@ namespace b6956809_test2 {<br>
   }<br>
 }<br>
<br>
+// This test should have one correction, followed by an error without a<br>
+// suggestion due to exceeding the maximum number of typos for which correction<br>
+// is attempted.<br>
 namespace CorrectTypo_has_reached_its_limit {<br>
-int flibberdy();  // no note here<br>
+int flibberdy();  // expected-note{{'flibberdy' declared here}}<br>
 int no_correction() {<br>
-  return gibberdy();  // expected-error-re{{use of undeclared identifier 'gibberdy'$}}<br>
+  return hibberdy() +  // expected-error{{use of undeclared identifier 'hibberdy'; did you mean 'flibberdy'?}}<br>
+         gibberdy();  // expected-error-re{{use of undeclared identifier 'gibberdy'$}}<br>
 };<br>
 }<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>