Commit Graph

241 Commits

Author SHA1 Message Date
Douglas Gregor bcbf46c7b7 Create a special allocator class for code completion, so that all of
the string copying goes through a single place that can have
associated state.

llvm-svn: 124698
2011-02-01 22:57:45 +00:00
Douglas Gregor 304f9b0803 Provide constant strings for certain common code completion strings,
eliminating the need to copy those strings.

llvm-svn: 124683
2011-02-01 21:15:40 +00:00
Douglas Gregor b278aafbfb Allocate CodeCompletionString and all of its components in a
BumpPtrAllocator, rather than manually new/delete'ing them. This
optimization also allows us to avoid allocating memory for and copying
constant strings (e.g., "return", "class").

This also required embedding the priority and availability of results
within the code completion string, to avoid extra memory allocation
within libclang.

llvm-svn: 124673
2011-02-01 19:23:04 +00:00
Alexis Hunt 1d7926502f Renamed CXXBaseOrMemberInitializer to CXXCtorInitializer. This is both shorter,
more accurate, and makes it make sense for it to hold a delegating constructor
call.

llvm-svn: 123084
2011-01-08 20:30:50 +00:00
Douglas Gregor 87e927520d Fix a major inconsistency in the representation of Objective-C
classes, categories, protocols, and class extensions, where the
methods and properties of these entities would be inserted into the
DeclContext in an ordering that doesn't necessarily reflect source
order. The culprits were Sema::ActOnMethodDeclaration(), which did not
perform the insertion of the just-created method declaration into
the DeclContext for these Objective-C entities, and
Sema::ActOnAtEnd(), which inserted all method declarations at the
*end* of the DeclContext. 

With this fix in hand, clean up the code-completion actions for
property setters/getters that worked around this brokenness in the AST.

Fixes <rdar://problem/8062781>, where this problem manifested as poor
token-annotation information, but this would have struck again in many
other places.

llvm-svn: 122347
2010-12-21 17:34:17 +00:00
Abramo Bagnara 6d8106386c Added missing IgnoreParens().
llvm-svn: 121795
2010-12-14 22:11:44 +00:00
Abramo Bagnara 924a8f3573 Added ParenType type node.
llvm-svn: 121488
2010-12-10 16:29:40 +00:00
Douglas Gregor b888acf413 Eliminate duplicate code completions for properties.
llvm-svn: 121424
2010-12-09 23:01:55 +00:00
Douglas Gregor a3b23b025b Don't walk the translation unit context to produce protocol names when
global code completions are disabled (e.g., because they are
cached). Also, make sure that forward-declared protocols are visited
when we look for all visible names within a declaration context.

Previously, we would end up with duplicate completions for protocols.

llvm-svn: 121416
2010-12-09 21:44:02 +00:00
Francois Pichet d583da04d0 More anonymous struct/union redesign. This one deals with anonymous field used in a constructor initializer list:
struct X {
  X() : au_i1(123) {}
  union {
    int au_i1;
    float au_f1;
  };
};

clang will now deal with au_i1 explicitly as an IndirectFieldDecl.

llvm-svn: 120900
2010-12-04 09:14:42 +00:00
Douglas Gregor b4a7c0385d Do not produce "purely informative" code completion results for
Objective-C message sends, which have only whitespace in their
TypedText chunk. Such results have no purpose.

llvm-svn: 119569
2010-11-17 21:36:08 +00:00
Douglas Gregor 928479e727 Revert the fix for PR8013.
That bug concerned the well-formedness of code such as (&ovl)(a, b,
c). GCC rejects the code, while EDG accepts it. On further study of the
standard, I see no support for EDG's position: in particular, C++
[over.over] does not list this as a context where we can take the
address of an overloaded function, C++ [over.call.func] does not
reference the address-of operator at any point, and C++ [expr.call]
claims that the function argument in a call is either a function
lvalue or a pointer-to-function; (&ovl) is neither.

llvm-svn: 118620
2010-11-09 20:03:54 +00:00
Douglas Gregor 8f225bb508 Handle overload resolution when calling an overloaded function set
with, e.g., (&f)(a, b, c). Fixes PR8013.

llvm-svn: 118508
2010-11-09 16:13:15 +00:00
Douglas Gregor 2927c0c817 Teach code completion not to include out-of-line declarations and
definitions in its results. The original declarations will be visible
wherever they are declared.

llvm-svn: 118484
2010-11-09 03:59:40 +00:00
Douglas Gregor dc520b0f08 If an instance method messages is sending to an expression of type Class,
and we statically can compute a bound on the actual type (e.g.,
because it's a send to the the magic "class" instance method), code
complete as if we were performing a class message send to that class.

llvm-svn: 118443
2010-11-08 21:12:30 +00:00
Douglas Gregor 05fcf84d14 Teach code completion to provide property results when the property
can be used to automatically synthesize an ivar.

llvm-svn: 118052
2010-11-02 20:36:02 +00:00
Douglas Gregor c769d6e007 Fix the translation of the PCC_ForInit code-completion context for
C++/C99/Objective-C, so that we properly include types. This fix
affects global caching of code-completion results; without caching,
the behavior was already correct.

llvm-svn: 116757
2010-10-18 22:01:46 +00:00
Douglas Gregor 8e3e8743fb Introduce code completion results for Objective-C methods, both when
declaring methods and when sending messages to them, by bringing all
of the selector into TypedCheck chunks in the completion result. This
way, we can improve the sorting of these results to account for the
full selector name rather than just the first chunk.

llvm-svn: 116746
2010-10-18 21:05:04 +00:00
Douglas Gregor 1b035bbe3a When providing code completions of Objective-C method declarations
(after - or +), always traverse superclasses and all categories. The
programmer may want to complete a method from *anywhere*.

llvm-svn: 116723
2010-10-18 18:21:28 +00:00
Douglas Gregor 392a84bdf6 Eliminate the use of ObjCSuperExpr in code completion.
llvm-svn: 116436
2010-10-13 21:24:53 +00:00
Douglas Gregor 36e3b5c79e Switch c-index-test from clang_codeComplete() over to
clang_codeCompleteAt(). This uncovered a few issues with the latter:

  - ASTUnit wasn't saving/restoring diagnostic state appropriately between
    reparses and code completions.
  - "Overload" completions weren't being passed through to the client

llvm-svn: 116241
2010-10-11 21:37:58 +00:00
Douglas Gregor 8ed5b77008 Fix the mapping of vertical-space cursor kinds to produce a newline,
rather than a space.

llvm-svn: 116097
2010-10-08 20:39:29 +00:00
Douglas Gregor af25cfaae0 When providing a block literal as a code completion for a
function/method argument, include the parameter name and always
include parentheses (even for zero-parameter blocks). Otherwise, the
block literal placeholder '^' can look very weird.

llvm-svn: 115444
2010-10-02 23:49:58 +00:00
Douglas Gregor 0ac41389a4 Synchronize globally-cached code completion results with the results
provided when the optimization is disabled. In particular, split
the completion context CCC_Other into two contexts: CCC_Other, which
means that it's an undisclosed context for which any other results are
unwelcome, and CCC_Recovery, which is used in recovery cases.

Since we're now using the completion context within the completion
results builder, make sure that it's always set to something.

Fixes <rdar://problem/8470644>.

llvm-svn: 114704
2010-09-23 23:01:17 +00:00
Douglas Gregor 0212fd7169 Add code completion for C++ constructors wherever we see the class (or
class template) and are in a context where we can have a value.

llvm-svn: 114441
2010-09-21 16:06:22 +00:00
Douglas Gregor 7466127a4b When providing code completions for an argument in an Objective-C
message send, e.g.,

  [[NSString alloc] initWithCString:<CC>

look up all of the possible methods and determine the preferred type
for the argument expression based on the type of the corresponding
parameter.

llvm-svn: 114379
2010-09-21 00:03:25 +00:00
Douglas Gregor f86e4da7ae Refactor code completion for expressions that occur as arguments in
Objective-C message sends. There is no functionality change here; this
is prep work for using the parameter types to help guide the
expression results when code-completing the argument.

llvm-svn: 114375
2010-09-20 23:34:21 +00:00
Douglas Gregor 5fb901deee Code completion has no reason to prefer values over types, especially
at the statement level or in Objective-C message receivers. Therefore,
just give types and declarations the same basic priority, and adjust
from there.

llvm-svn: 114374
2010-09-20 23:11:55 +00:00
Douglas Gregor 50832e0215 Slight refactoring in code-completion results generation, placing the
various priority adjustments for preferences (based on selectors,
types) in a single function to make extension easier.

llvm-svn: 114370
2010-09-20 22:39:41 +00:00
Douglas Gregor db5c09a8cd Get rid of the lame attempt to prioritize "void" functions at
statement context; it really isn't helpful in practice (remember
printf!) and we'll be doing other adjustments for statements very soon.

llvm-svn: 114358
2010-09-20 21:25:19 +00:00
Douglas Gregor 9dcf58a546 Tweak priorities for some types and macros:
- In Objective-C, we prefer BOOL to bool for historic reasons;
  slightly penalize "bool".
  - Treat Nil macro as a NULL pointer constant.
  - Treat YES, NO, true, and false macros as constants.
  - Treat the bool macro as a type.

llvm-svn: 114356
2010-09-20 21:11:48 +00:00
Douglas Gregor eda7e545e6 Continue parsing more postfix expressions, even after semantic
errors. Improves code completion in yet another case.

llvm-svn: 114255
2010-09-18 01:28:11 +00:00
Douglas Gregor 1154e27b4f Don't add two code-completion results for the same selector; it
doesn't add any value. Instead, we'll just take the first method with
that selector that we find and create a completion for it.

llvm-svn: 114082
2010-09-16 16:06:31 +00:00
Douglas Gregor f37c9498bf When collecting Objective-C methods for message send completions, be
sure to visit the protocols of protocols.

llvm-svn: 114079
2010-09-16 15:34:59 +00:00
Douglas Gregor bfcea8b5b1 Implement code completion for Objective-C class message sends that are
missing the opening bracket '[', e.g.,

  NSArray <CC>

at function scope. Previously, we would only give trivial completions
(const, volatile, etc.), because we're in a "declaration name"
scope. Now, we also provide completions for class methods of NSArray,
e.g.,

  alloc

Note that we already had support for this after the first argument,
e.g.,

  NSArray method:x <CC>

would get code completion for class methods of NSArray whose selector
starts with "method:". This was already present because we recover
as if NSArray method:x were a class message send missing the opening
bracket (which was committed in r114057).

llvm-svn: 114078
2010-09-16 15:14:18 +00:00
Douglas Gregor ed0b69dc81 Improve code completion for Objective-C message sends when the opening
'[' is missing. Prior commits improving recovery also improved code
completion beyond the first selector, e.g., at or after the "to" in

  calculator add:x to:y

but not after "calculator". We now provide the same completions for

  calculator <CC>

that we would for

  [calculator <CC>

if "calculator" is an expression whose type is something that can
receive Objective-C messages.

This code completion works for instance and super message sends, but not
class message sends.

llvm-svn: 113976
2010-09-15 16:23:04 +00:00
Douglas Gregor 5e35d59188 Introduce a new code-completion context for a parenthesized
expression, e.g., after the '(' that could also be a type cast. Here,
we provide types as code-completion results in C/Objective-C (C++
already had them), although we wouldn't in a normal expression context.

llvm-svn: 113904
2010-09-14 23:59:36 +00:00
Douglas Gregor f3af311382 Teach libclang to walk the base and member initializers of a
constructor, in source order. Also introduces a new reference kind for
class members, which is used here (for member initializers) and will
also be used for designated initializers and offsetof.

llvm-svn: 113545
2010-09-09 21:42:20 +00:00
Douglas Gregor 67da50e18d When providing a completion for a function/method parameter of block
pointer type, actually provide a usable block literal expression.

llvm-svn: 113431
2010-09-08 22:47:51 +00:00
Chris Lattner 9795b39113 zap dead code.
llvm-svn: 113074
2010-09-04 18:12:20 +00:00
Douglas Gregor 09c0eb1510 Synchronize code-completion cursor kinds with indexing cursor
kinds. How shameful that this code was duplicated!

llvm-svn: 113033
2010-09-03 23:30:36 +00:00
Ted Kremenek 0ef508d301 Split ObjCInterfaceDecl::ReferencedProtocols into two lists: ReferencedProtocols and AllReferencedProtocols. ReferencedProtocols
(and thus protocol_begin(), protocol_end()) now only contains the list of protocols that were directly referenced in
an @interface declaration.  'all_referenced_protocol_[begin,end]()' now returns the set of protocols that were referenced
in both the @interface and class extensions.  The latter is needed for semantic analysis/codegen, while the former is
needed to maintain the lexical information of the original source.

Fixes <rdar://problem/8380046>.

llvm-svn: 112691
2010-09-01 01:21:15 +00:00
Douglas Gregor 400f59763b When provide code completions for a variadic Objective-C method
declaration send or a variadic function call, collapse the ", ..."
into the parameter before it, so that we don't get a second
placeholder.

llvm-svn: 112579
2010-08-31 05:13:43 +00:00
Sebastian Redl 50c682585f Rename DeclContext::getLookupContext to getRedeclContext and change its semantics slightly. No functionality change in the absence of inline namespaces. Also, change a few places where inline namespaces actually make a difference to be prepared for them.
llvm-svn: 112563
2010-08-31 00:36:30 +00:00
Douglas Gregor 981a0c4613 When providing a code completion for an Objective-C message send, drop
the parameter names from the completions, e.g., provide

  withString:(NSString *)

instead of

  withString:(NSString *)string

since the parameter name is, by convention, redundant with the
selector piece that precedes it and the completions can get
unnecessarily long.

llvm-svn: 112456
2010-08-29 19:47:46 +00:00
Douglas Gregor 99129efdd3 Improve code completion for initializer lists in constructors. Instead
of prioritizing just by initialization order, we bump the priority of
just the *next* initializer in the list, and leave everything else at
the normal priority. That way, if one intentionally skips the
initialization of a base or member (to get default initialization),
we'll still get ordered completion for the rest.

llvm-svn: 112454
2010-08-29 19:27:27 +00:00
Douglas Gregor eaeeca9afe Basic code completion support for the base and member initializers in
a constructor.

llvm-svn: 112330
2010-08-28 00:00:50 +00:00
Douglas Gregor ac322ec9b9 Implement the "call super" code completion for C++. If the virtual
member function you're typing in overrides another virtual function,
this fills in a (qualified!) call to that virtual function to make
such delegation easy.

llvm-svn: 112294
2010-08-27 21:18:54 +00:00
Douglas Gregor 28c7843ec4 Suggest "const" and "volatile" code completions after a function
declarator, the very definition of "low-hanging fruit".

llvm-svn: 112274
2010-08-27 17:35:51 +00:00
Douglas Gregor c2cb2e23bc When code-completing inside an Objective-C method, give a slight
priority boost to methods with the same selector. 

llvm-svn: 112268
2010-08-27 15:29:55 +00:00