Commit Graph

77 Commits

Author SHA1 Message Date
Douglas Gregor bafff22b91 Disable this test again, which naturally fails on every platform except the one I'm building with
llvm-svn: 116642
2010-10-15 23:23:05 +00:00
Douglas Gregor 26c5578d84 When performing typo correction, keep track of whether the last lookup
we did was an acceptable lookup. If it is, then we can re-use that
lookup result. If it isn't, we have to perform the lookup again. This
is almost surely the cause behind the mysterious typo.m failures on
some builders; we were getting the wrong lookup results returned.

llvm-svn: 116586
2010-10-15 16:49:56 +00:00
Daniel Dunbar 2a40abae4d Disable type.m while failures are investigated.
llvm-svn: 116577
2010-10-15 15:28:09 +00:00
Daniel Dunbar 1837dbd4e3 Make test more consistent.
llvm-svn: 116576
2010-10-15 15:13:02 +00:00
Argyrios Kyrtzidis b5c7c51392 When we encounter a '==' in a context expecting a '=', assume the user made a typo:
t.c:1:7: error: invalid '==' at end of declaration; did you mean '='?
int x == 0;
      ^~
      =

Implements rdar://8488464.

llvm-svn: 116035
2010-10-08 02:39:23 +00:00
Francois Pichet 6d76e6cd92 Better diagnostic for superfluous scope specifier inside a class definition for member functions. + Fixit.
Example: 
class A {
   void A::foo(); //warning: extra qualification on member 'foo'
};

llvm-svn: 115347
2010-10-01 21:19:28 +00:00
Douglas Gregor 196cf88a01 Update test
llvm-svn: 114234
2010-09-17 23:01:08 +00:00
Douglas Gregor 29d907de03 When we run into an error parsing or type-checking the left-hand side
of a binary expression, continue on and parse the right-hand side of
the binary expression anyway, but don't call the semantic actions to
type-check. Previously, we would see the error and then, effectively,
skip tokens until the end of the statement. 

The result should be more useful recovery, both in the normal case
(we'll actually see errors beyond the first one in a statement), but
it also helps code completion do a much better job, because we do
"real" code completion on the right-hand side of an invalid binary
expression rather than completing with the recovery completion. For
example, given

  x = p->y

if there is no variable named "x", we can still complete after the p->
as a member expression. Along the recovery path, we would have
completed after the "->" as if we were in an expression context, which
is mostly useless.

llvm-svn: 114225
2010-09-17 22:25:06 +00:00
Douglas Gregor abf4a3e4c6 Implement automatic bracket insertion for Objective-C class message
sends. These are far trickier than instance messages, because we
typically have something like

  NSArray alloc]

where it appears to be a declaration of a variable named "alloc" up
until we see the ']' (or a ':'), and at that point we can't backtrace.
So, we use a combination of syntactic and semantic disambiguation to
treat this as a message send only when the type is an Objective-C type
and it has the syntax of a class message send (which would otherwise
be ill-formed).

llvm-svn: 114057
2010-09-16 01:51:54 +00:00
Douglas Gregor 3e972009fb Handle bracket insertion for Objective-C class messages in a very
narrow, almost useless case where we're inside a parenthesized
expression, e.g.,

  (NSArray alloc])

The solution to the general case still eludes me.

llvm-svn: 114039
2010-09-15 23:19:31 +00:00
Douglas Gregor 7617c7d295 Extend bracket insertion to message sends to "super", e.g.,
super method:arg]

will now recover nicely and insert the '[' before 'super'.

llvm-svn: 113971
2010-09-15 15:09:43 +00:00
Douglas Gregor d6d980044e Extend bracket insertion to handle nullary selectors, e.g.
a getFoo]

llvm-svn: 113969
2010-09-15 14:54:45 +00:00
Douglas Gregor e9bba4f1a4 Implement bracket insertion for Objective-C instance message sends as
part of parser recovery. For example, given:

  a method1:arg];

we detect after parsing the expression "a" that we have the start of a
message send expression. We pretend we've seen a '[' prior to the a,
then parse the remainder as a message send. We'll then give a
diagnostic+fix-it such as:

fixit-objc-message.m:17:3: error: missing '[' at start of message
      send expression
  a method1:arg];
  ^
  [

The algorithm here is very simple, and always assumes that the open
bracket goes at the beginning of the message send. It also only works
for non-super instance message sends at this time.

llvm-svn: 113968
2010-09-15 14:51:05 +00:00
Gabor Greif 80c218386f add a fixit when 'main' does ot return 'int'; review welcome
llvm-svn: 113324
2010-09-08 00:31:13 +00:00
Douglas Gregor 45d6bdfa88 Improve recovery when there is a stray ']' or ')' before the ';' at
the end of a statement. Fixes <rdar://problem/6896493>.

llvm-svn: 113202
2010-09-07 15:23:11 +00:00
Douglas Gregor ce66d02877 Improve recovery when a comma is missing between enumerators in an
enumeration definition. Fixes <rdar://problem/7159693>.

llvm-svn: 113201
2010-09-07 14:51:08 +00:00
Douglas Gregor 3465e26102 Improve diagnostic and recovery when missing a comma between base or
member initializers in a C++ constructor. Fixes <rdar://problem/7796492>.

llvm-svn: 113199
2010-09-07 14:35:10 +00:00
Douglas Gregor a05f5aba9a When complaining about a duplicate declspec, provide a Fix-It that
removes the copy. Patch from Eelis van der Weegen, tweaked/updated by
me.

llvm-svn: 111807
2010-08-23 14:34:43 +00:00
Douglas Gregor 8ed0c0b99d Introduce -f{no-}spell-checking options to enable/disable
spell-checking. By default, spell-checking is enabled for Clang
(obviously) but disabled in CIndex for performance reasons.

llvm-svn: 107992
2010-07-09 17:35:33 +00:00
Douglas Gregor 6969fb73ca Fix broken testcase
llvm-svn: 107194
2010-06-29 19:17:14 +00:00
Douglas Gregor 9629e9ac3e Typo correction for namespace alias definitions
llvm-svn: 107191
2010-06-29 18:55:19 +00:00
Douglas Gregor cdf87024ed Allow a using directive to refer to the implicitly-defined namespace
"std", with a warning, to improve GCC compatibility. Fixes PR7517.

As a drive-by, add typo correction for using directives.

llvm-svn: 107172
2010-06-29 17:53:46 +00:00
Douglas Gregor 952cf9414f Tweak test for non-64-bit Darwin
llvm-svn: 105222
2010-05-31 14:58:57 +00:00
Douglas Gregor 990ccace5b When we see the a '[' in a postfix expression in Objective-C, perform
a simple, quick check to determine whether the expression starting
with '[' can only be an Objective-C message send. If so, don't parse
it as an array subscript expression. This improves recovery for, e.g.,

  [a method1]
  [a method2]

so that we now produce

  t.m:10:13: error: expected ';' after expression
  [a method]
            ^

instead of some mess about expecting ']'.

llvm-svn: 105221
2010-05-31 14:40:22 +00:00
Douglas Gregor 8b6be164d6 Fix typo test case
llvm-svn: 104027
2010-05-18 16:57:36 +00:00
Douglas Gregor 86ad085b40 Give a slight edge to the context-sensitive keyword 'super' over
non-function-local declarations with names similar to what the user
typed. For example, this allows us to correct 'supper' to 'super' in
an Objective-C message send, even though the C function 'isupper' has
the same edit distance.

llvm-svn: 104023
2010-05-18 16:30:22 +00:00
Douglas Gregor 5fd04d4832 Tweak typo-correction logic a bit regarding "super", so that we
consider "super" as a candidate whenever we're parsing an expression
within an Objective-C method in an interface that has a superclass. At
some point, we'd like to give "super" a little edge over non-local
names; that will come later.

llvm-svn: 104022
2010-05-18 16:14:23 +00:00
Ted Kremenek 990783e345 Clean up test case and remove XFAIL. This test can now distinguish between
cases where Clang can suggest and fix and suggest and not auto-fix (because of
current limitations).

llvm-svn: 103987
2010-05-17 23:03:33 +00:00
Nick Lewycky 784fad7a41 Teach clang -fixit to modify files in-place, or -fixit=suffix to create new
files with the additional suffix in the middle.

llvm-svn: 102230
2010-04-24 01:30:46 +00:00
Chris Lattner 0151b7edb7 fix the ?: fixit that ted added to recover properly.
llvm-svn: 101943
2010-04-20 21:33:39 +00:00
Douglas Gregor 0b59e80db5 When searching for code-completion and typo-correction candidates,
look from an Objective-C class or category to its implementation, to
pick up synthesized ivars. Fixes a problem reported by David
Chisnall.

llvm-svn: 101792
2010-04-19 18:02:19 +00:00
Nick Lewycky a1e20de908 Teach -fixit to modify all of its inputs instead of just the main file, unless
-fixit-at specified a particular fixit to fix, or the -o flag was used.

llvm-svn: 101359
2010-04-15 06:46:58 +00:00
Douglas Gregor 2fb18b746f Thread a Scope pointer into BuildRecoveryCallExpr to help typo
correction find names when a call failed. Fixes
<rdar://problem/7853795>.

llvm-svn: 101278
2010-04-14 20:27:54 +00:00
Douglas Gregor 280e1ee0ae Teach typo correction about various language keywords. We can't
generally recover from typos in keywords (since we would effectively
have to mangle the token stream). However, there are still benefits to
typo-correcting with keywords:
  - We don't make stupid suggestions when the user typed something
  that is similar to a keyword. 
  - We can suggest the keyword in a diagnostic (did you mean
  "static_cast"?), even if we can't recover and therefore don't have
  a fix-it.

llvm-svn: 101274
2010-04-14 20:04:41 +00:00
Douglas Gregor 8aa4ebf0bc Implement typo correction for Objective-C message sends when the
receiver is a mis-typed class name. Previously, we would give a non-specific
typo-correction diagnostic from the expression-parsing code, but there
was no fix-it because it was too late to recover. Now, we give a nice
diagnostic

honk.m:6:4: error: unknown receiver 'Hnk'; did you mean 'Honk'?
  [Hnk method];
   ^~~
   Honk
honk.m:1:1: note: 'Honk' declared here
@interface Honk
^

which includes a fix-it.

We still need to recover better from mis-typing "super".

llvm-svn: 101211
2010-04-14 02:46:37 +00:00
Ted Kremenek e601365de9 Add fixit hint for missing ':' in ternary expressions.
llvm-svn: 101073
2010-04-12 22:10:35 +00:00
Ted Kremenek 800b66be9d Remove fixit for string literal comparison. Telling the user to use 'strcmp' is bad, and
we don't have enough information to tell them how to use 'strncmp'.  Instead, change the
diagnostic to indicate they should use 'strncmp'.

llvm-svn: 100890
2010-04-09 20:26:53 +00:00
John McCall 3155f573f5 Turn access control on by default in -cc1.
Remove -faccess-control from -cc1; add -fno-access-control.
Make the driver pass -fno-access-control by default.
Update a bunch of tests to be correct under access control.

llvm-svn: 100880
2010-04-09 19:03:51 +00:00
Douglas Gregor b10646d4ce Improve diagnostics like "initializing <type> from an expression of
type..." with "initializing <type> with an expression of type...",
which reads better. Thanks to John for the improved wording.

llvm-svn: 100873
2010-04-09 17:53:29 +00:00
Douglas Gregor c68e140657 Improve diagnostics when we fail to convert from a source type to a
destination type for initialization, assignment, parameter-passing,
etc. The main issue fixed here is that we used rather confusing
wording for diagnostics such as

t.c:2:9: warning: initializing 'char const [2]' discards qualifiers,
      expected 'char *' [-pedantic]
  char *name = __func__;
        ^      ~~~~~~~~

We're not initializing a 'char const [2]', we're initializing a 'char
*' with an expression of type 'char const [2]'. Similar problems
existed for other diagnostics in this area, so I've normalized them all
with more precise descriptive text to say what we're
initializing/converting/assigning/etc. from and to. The warning for
the code above is now:

t.c:2:9: warning: initializing 'char *' from an expression of type
      'char const [2]' discards qualifiers [-pedantic]
  char *name = __func__;
        ^      ~~~~~~~~

Fixes <rdar://problem/7447179>.

llvm-svn: 100832
2010-04-09 00:35:39 +00:00
Douglas Gregor d6bc5e6bbc When a declaration of a function is missing an exception specification
that was present in a prior declaration, emit a warning rather than a
hard error (which we did before, and still do with mismatched
exception specifications). Moreover, provide a fix-it hint with the
throw() clause that should be added, e.g.,

t.C:10:7: warning: 'operator new' is missing exception specification
      'throw(std::bad_alloc)'
void *operator new(unsigned long sz)
      ^
                                     throw(std::bad_alloc)

As part of this, disable the warning when we're missing an exception
specification on operator new, operator new[], operator delete, or
operator delete[] when exceptions are turned off (-fno-exceptions).

Fixes PR5957.

llvm-svn: 99388
2010-03-24 07:14:45 +00:00
John McCall 85f9055955 When pretty-printing tag types, only print the tag if we're in C (and
therefore not creating ElaboratedTypes, which are still pretty-printed
with the written tag).

Most of these testcase changes were done by script, so don't feel too
sorry for my fingers.

llvm-svn: 98149
2010-03-10 11:27:22 +00:00
Douglas Gregor 0c8a172911 Fix a crash with ill-formed code within a method in an ill-formed
category implementation, which showed up during (attempted) typo
correction. Fixes <rdar://problem/7605289>.

llvm-svn: 95334
2010-02-04 23:42:48 +00:00
Douglas Gregor f1d70adfd1 Make this fix-it test case actually fail when there is a problem; add
a test for access declarations and remove a (broken) test for removal
of default arguments.

llvm-svn: 95032
2010-02-01 23:46:27 +00:00
Fariborz Jahanian 98609b3a07 Patch to implement required warnings for unimplemented
properties imported frfom protocol. Fixes radar 7544809.

llvm-svn: 93965
2010-01-20 01:51:55 +00:00
Douglas Gregor 712dcfe921 Fix the search for visible declarations within a Scope to ensure that
we look into a Scope that corresponds to a compound statement whose
scope was combined with the scope of the function that owns it. This
improves typo correction in many common cases.

llvm-svn: 92879
2010-01-07 00:31:29 +00:00
Douglas Gregor 43a0857631 When we typo-correct a base class initializer, point to the base class
specifier that we corrected to.

llvm-svn: 92878
2010-01-07 00:26:25 +00:00
Douglas Gregor 6da83624e4 Whenever we emit a typo-correction diagnostic, also emit a note
pointing to the declaration that we found that has that name (if it is
unique).

llvm-svn: 92877
2010-01-07 00:17:44 +00:00
Douglas Gregor 35b0bac8c5 Implement typo correction for a variety of Objective-C-specific
constructs:

  - Instance variable lookup ("foo->ivar" and, in instance methods, "ivar")
  - Property name lookup ("foo.prop")
  - Superclasses
  - Various places where a class name is required
  - Protocol names (e.g., id<proto>)

This seems to cover many of the common places where typos could occur.

llvm-svn: 92449
2010-01-03 18:01:57 +00:00
Douglas Gregor 4f2486353a Make sure that the search for visible declarations looks into the semantic parents of out-of-line function contexts
llvm-svn: 92397
2010-01-01 17:44:25 +00:00