Commit Graph

293 Commits

Author SHA1 Message Date
Douglas Gregor 6fc0413e59 Add a super-cool code completion for send-to-super. When we're typing
a message send to "super" from a method that appears to be meant to
override a superclass method (same kind, same selector, same argument
types), provide a "super" completion that fills in the selector along
with forwarding the method's arguments (as placeholders).

llvm-svn: 112263
2010-08-27 15:10:57 +00:00
Douglas Gregor 9ac1ad141b Tweak the @selector completion to collapse multiple informative and
typed-text blocks into one of each.

llvm-svn: 112194
2010-08-26 16:46:39 +00:00
Douglas Gregor 9be0ed4f3f When code-completing a potential call to a C++ non-static member
function, take into account the qualifiers on the object argument
(e.g., what will become "this"), filtering around uncallable member
functions and giving a slight priority boost to those with
exactly-matching qualifiers.

llvm-svn: 112193
2010-08-26 16:36:48 +00:00
Douglas Gregor 67c692cc3d Implement code completion for @selector expressions
llvm-svn: 112186
2010-08-26 15:07:07 +00:00
Douglas Gregor 78ccc2cb00 More ordering tweaks in this silly, silly test
llvm-svn: 112184
2010-08-26 14:20:32 +00:00
Douglas Gregor 49f67ce4b3 Move the sorting of code-completion results out of the main path and
into the clients, e.g., the printing code-completion consumer and
c-index-test. Clients may want to re-sort the results anyway.

Provide a libclang function that sorts the results.

3rd try. How embarrassing.

llvm-svn: 112180
2010-08-26 13:48:20 +00:00
Douglas Gregor 54d9c11a01 Tweak test to avoid checking for a specific ordering where none exists
llvm-svn: 112159
2010-08-26 03:52:21 +00:00
Ted Kremenek a594082210 Add libclang API hook "clang_getIBOutletCollectionType" to query the collection type for iboutletcollection attributes.
llvm-svn: 112139
2010-08-26 01:42:22 +00:00
Douglas Gregor 1099865124 Revert "Move the sorting of code-completion results out of the main path and
into the clients", because the C standard library sucks. Where's my
stable sort, huh?

llvm-svn: 112121
2010-08-26 00:30:24 +00:00
Ted Kremenek a0d7e434c0 Fix RUN line in test.
llvm-svn: 112097
2010-08-25 22:16:06 +00:00
Ted Kremenek 65b2cc061d When annotating tokens, don't fallback to annotating with a null cursor for cursors that come before a macro instantiation. Fixes <rdar://problem/7974151>.
llvm-svn: 112096
2010-08-25 22:16:02 +00:00
Douglas Gregor ebb7c84891 Move the sorting of code-completion results out of the main path and
into the clients, e.g., the printing code-completion consumer and
c-index-test. Clients may want to re-sort the results anyway.

llvm-svn: 112095
2010-08-25 22:15:42 +00:00
Douglas Gregor 0de55cecb2 When combining the code-completion results from Sema long with the
code-completion results cached by ASTUnit, sort the resulting result
set. This makes testing far, far easier, so this commit also includes
tests for the previous few fixes.

llvm-svn: 112070
2010-08-25 18:41:16 +00:00
Douglas Gregor 39a31a00ea Test for previous commit
llvm-svn: 112059
2010-08-25 17:11:34 +00:00
Douglas Gregor 115837041e Introduce a preprocessor code-completion hook for contexts where we
expect "natural" language and should not provide any completions,
e.g., comments, string literals, #error.

llvm-svn: 112054
2010-08-25 17:04:25 +00:00
Douglas Gregor 416b575edc When performing completions involving Objective-C method declarations
(e.g., for message sends or method declaration/definition
completions), adjust methods that come from a base class.

llvm-svn: 112013
2010-08-25 01:08:01 +00:00
Douglas Gregor 4d755e86b4 Give a slight preference to functions returning "void" when we're
performing code completion at the statement level (rather than in an
arbitrary expression).

llvm-svn: 112001
2010-08-24 23:58:17 +00:00
Douglas Gregor 45140a9040 In code-completion contexts where both types and other values are
present, prefer values to types, since it's more common to compute
with values than it is to declare new entities or perform type
casts. So, tweak the ranking of types vs. other declarations and
constants accordingly.

llvm-svn: 111998
2010-08-24 23:40:45 +00:00
Ted Kremenek cc7f215872 USRs for class extensions should "mangle" in the location of the extension. (<rdar://problem/8350262>)
llvm-svn: 111991
2010-08-24 23:13:41 +00:00
Douglas Gregor b46e9bc26f Remove i386 macro check from expected output of preprocessor
llvm-svn: 111984
2010-08-24 22:46:25 +00:00
Douglas Gregor ec00a26855 Implement code completion for preprocessor expressions and in macro
arguments.

llvm-svn: 111976
2010-08-24 22:20:20 +00:00
Daniel Dunbar b44eb0b900 tests: Use REQUIRES: instead of XFAIL: for crash recovery tests; running them on
Windows breaks things (because it pops up dialogs) since we don't have crash
recovery support there (yet).

llvm-svn: 111970
2010-08-24 21:39:55 +00:00
Douglas Gregor 127851084d Implement preprocessor code completion where a macro name is expected,
e.g., after #ifdef/#ifndef or #undef, or inside a defined <macroname>
expression in a preprocessor conditional.

llvm-svn: 111954
2010-08-24 20:21:13 +00:00
Douglas Gregor 3a7ad25eb6 Introduce basic code-completion support for preprocessor directives,
e.g., after a "#" we'll suggest #if, #ifdef, etc.

llvm-svn: 111943
2010-08-24 19:08:16 +00:00
Douglas Gregor e90dd00c3c When providing completions for a function or method argument that
corresponds to a block pointer, provide the skeleton of a block
literal.

llvm-svn: 111918
2010-08-24 16:15:59 +00:00
Douglas Gregor 99fa264a67 Provide code completion results for the context-sensitive Objective-C
keywords "in", "out", "inout", "byref", "bycopy", and "oneway".

llvm-svn: 111884
2010-08-24 01:06:58 +00:00
Douglas Gregor dbb71db4cc When calling a function or messaging a method marked "sentinel", add
the ", nil", ", NULL", or ", (void*)0" to the end of the code
completion, since it always has to be there anyway.

llvm-svn: 111867
2010-08-23 23:51:41 +00:00
Douglas Gregor f757a12dfc Introduce new libclang API functions that determine the availability
of a cursor or code-completion result, e.g., whether that result
refers to an unavailable, deleted, or deprecated declaration.

llvm-svn: 111858
2010-08-23 23:00:57 +00:00
Douglas Gregor ce0e856809 Include __FUNCTION__, __PRETTY_FUNCTION_, __func__ in code-completion
results for expression contexts within a function.

llvm-svn: 111851
2010-08-23 21:54:33 +00:00
Douglas Gregor 68762e7852 Introduce a code-completion hook for the Objective-C collection
argument in a for-each statement (e.g., "for (id x in <blah>)"), which
restricts the expression completions provided to Objective-C types (or
class types in C++).

llvm-svn: 111843
2010-08-23 21:17:50 +00:00
Douglas Gregor c49f5b2f11 Introduce a new code-completion point when we're parsing a
declarator. Here, we can only see a few things (e.g., cvr-qualifiers,
nested name specifiers) and we do not want to provide other non-macro
completions. Previously, we would end up in recovery mode and would
provide a large number of non-relevant completions.

llvm-svn: 111818
2010-08-23 18:23:48 +00:00
Douglas Gregor b97b666c47 When performing code-completion in the presence of a preamble, make
sure to (1) actually use the remapped files we were given rather
than old data, and (2) keep the remapped files alive until the
code-completion results are destroyed. Big thanks to Daniel for the
test case.

llvm-svn: 111597
2010-08-20 00:59:43 +00:00
Douglas Gregor 7b02b583b2 When we decide not to reuse a precompiled preamble, clear out the
previous precompiled preamble completely. Fixes <rdar://problem/8330950>.

llvm-svn: 111590
2010-08-20 00:02:33 +00:00
Daniel Dunbar 77af1c564e libclang: Execute clang_codeCompleteAt() inside a crash recovery context.
- Test case is disabled for now, because something isn't write with file
   remapping.

llvm-svn: 111581
2010-08-19 23:44:10 +00:00
Daniel Dunbar 438c7724f9 Fix a loop overrun in ComputePreamble when the last remapped file was erased,
and reenable crash recovery test.
 - Reparsing is still very crashy / weird, so I had to sprinkle random code into
   the remapped input to get it to do what I want (i.e., crash!).

llvm-svn: 111550
2010-08-19 19:40:40 +00:00
Daniel Dunbar e6a39d33e5 CrashRecovery: Disable the reparse test for now while I investigate, it goes
bonkers sometimes.

llvm-svn: 111523
2010-08-19 16:40:14 +00:00
Daniel Dunbar 79acdd9402 libclang: Put clang_reparseTranslationUnit inside a crash recovery context.
llvm-svn: 111451
2010-08-18 23:09:31 +00:00
Daniel Dunbar 583c3b775e libclang: Put clang_parseTranslationUnit inside a crash recovery context.
llvm-svn: 111387
2010-08-18 18:43:17 +00:00
Douglas Gregor 7116a8c19a When generating code completion patterns for method declarations, give
the resulting pattern the appropriate cursor kind of an instance or
class method declaration.

llvm-svn: 111237
2010-08-17 16:06:07 +00:00
Douglas Gregor b0ce9b79ba 1 != I. Fix the formulation of code-completion patterns for
Objective-C method declarations with > 2 parameters.

llvm-svn: 111233
2010-08-17 15:53:35 +00:00
Douglas Gregor 59cab5564f Implement support for cached code completions for
nested-name-specifiers. Also includes fixes to the generation of
nested-name-specifier result in the non-cached case; we were producing
lame results for namespaces and namespace aliases, which (1) didn't
always have nested-name-specifiers when we want them, and (2) did not
have the necessary "::" as part of the completion.

llvm-svn: 111203
2010-08-16 23:05:20 +00:00
Douglas Gregor 6199f2d146 Implement name hiding of cached global code-completion results.
llvm-svn: 111184
2010-08-16 21:18:39 +00:00
Douglas Gregor b61c07aca0 When caching code completions for global declarations, keep track of
the usage type of each declaration result, then compare those types to
the preferred type of the completion. This provides parity in the
priority calculation between the code-completion results produced
directly from Sema and those cached by ASTUnit. 

For the standard Cocoa.h (+ others) example, there's a penalty of 3-4
hundredeths of a second when caching the global results (for ~31,000
results), because we need an ASTContext-agnostic representation of
types for the comparison, and therefore we use... strings. Eventually,
we'd like to implement a more efficient ASTContext-agnostic encoding
of types.

llvm-svn: 111165
2010-08-16 18:08:11 +00:00
Douglas Gregor 6e24033bd2 When caching global completion results, keep track of the simplified
type class, so that we can adjust priorities appropriately when the
preferred type for the context and the actual type of the completion
are similar.

This gets us one step closer to parity of the cached completion
results with the non-cached completion results.

llvm-svn: 111139
2010-08-16 16:18:59 +00:00
Douglas Gregor 3998219789 Extend the code-completion caching infrastructure to include global
declarations (in addition to macros). Each kind of declaration maps to
a certain set of completion contexts, and the ASTUnit completion logic
introduces the completion strings for those declarations if the actual
code-completion occurs in one of the contexts where it matters. 

There are a few new code-completion-context kinds. Without these,
certain completions (e.g., after "using namespace") would need to
suppress all global completions, which would be unfortunate.

Note that we don't get the priorities right for global completions,
because we don't have enough type information. We'll need a way to
compare types in an ASTContext-agnostic way before this can be
implemented.

llvm-svn: 111093
2010-08-15 06:18:01 +00:00
Ted Kremenek aa01481d78 Always recurse into sub-cursors when annotating tokens, as this information is used for annotating macro arguments. This finishes up <rdar://problem/8044584>.
llvm-svn: 111066
2010-08-14 02:50:46 +00:00
Ted Kremenek f4ade0ae3f As a heuristic, annotate tokens (via clang_annotateTokens) that are the arguments of a macro instantiation using the closest cursor with the same spelling location. Because macro arguments can get token pasted in any arbitrary order, we use the annotation map to paper over the token -> cursor annotations during our post-processing stage. This fixes most of <rdar://problem/8044584>, but still doesn't work for assert().
llvm-svn: 111062
2010-08-14 01:14:06 +00:00
Douglas Gregor b14904c4a8 Implement caching of code-completion results for macro definitions
when the CXTranslationUnit_CacheCompletionResults option is given to
clang_parseTranslationUnit(). Essentially, we compute code-completion
results for macro definitions after we have parsed the file, then
store an ASTContext-agnostic version of those results (completion
string, cursor kind, priority, and active contexts) in the
ASTUnit. When performing code completion in that ASTUnit, we splice 
the macro definition results into the results provided by the actual
code-completion (which has had macros turned off) before libclang gets
those results. We use completion context information to only splice in
those results that make sense for that context.

With a completion involving all of the macros from Cocoa.h and a few other
system libraries (totally ~8500 macro definitions) living in a
precompiled header, we get about a 9% performance improvement from
code completion, since we no longer have to deserialize all of the
macro definitions from the precompiled header. 

Note that macro definitions are merely the canary; the cache is
designed to also support other top-level declarations, which should be
a bigger performance win. That optimization will be next.

Note also that there is no mechanism for determining when to throw
away the cache and recompute its contents.

llvm-svn: 111051
2010-08-13 22:48:40 +00:00
Douglas Gregor e938668003 Implement clang_saveTranslationUnit(), which saves a translation unit
into a PCH/AST file.

llvm-svn: 111006
2010-08-13 05:36:37 +00:00
Douglas Gregor 02690ba643 Don't emit end-of-file diagnostics like "unterminated conditional" or
"unterminated string" when we're performing code completion.

llvm-svn: 110933
2010-08-12 17:04:55 +00:00