Commit Graph

505 Commits

Author SHA1 Message Date
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 16443fdd31 Teach clang_getCursorReferenced() that a
CXXConstructorExpr/CXXTemporaryObjectExpr references the constructor
it calls. Then, tweak clang_getCursor() to prefer such a call over a
type reference to the type being called.

llvm-svn: 118297
2010-11-05 21:11:19 +00:00
Douglas Gregor 15417cfa56 Improve source-location information for CXXConstructExpr nodes, by
ensuring that they cover all of their child nodes. There's still a
clang_getCursor()-related issue with CXXFunctionalCastExprs with
CXXConstructExprs as children (see FIXME in the test case); I'll look
at that separately.

llvm-svn: 118132
2010-11-03 00:35:38 +00:00
Ted Kremenek d40a439067 Hack to workaround deficiency in ObjC ASTs. Functions and variables may be declared
within an @implementation, but we have no way to record that information in the AST.
This may cause CursorVisitor to miss these Decls when doing a AST walk.

Fixes <rdar://problem/8595462>.

llvm-svn: 118109
2010-11-02 23:10:24 +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
Ted Kremenek 818e5c1839 Encapsulate within CXCursor the notion of whether a VarDecl* is the first Decl in a DeclGroup. We use this
to recover some context that is currently not modeled directly in the AST.  Currently VarDecl's cannot
properly determine their source range because they have no context on whether or not they appear in a DeclGroup.
For the meantime, this bandaid suffices in libclang since that is where the correct SourceRange is directly needed.

Fixes <rdar://problem/8595749>.

llvm-svn: 117973
2010-11-01 23:26:51 +00:00
Chandler Carruth 0171815ae1 Improve the tracking of source locations for parentheses in constructor calls.
This adds them where missing, and traces them through PCH. We fix at least one
bug in the extents found by the Index library, and make a lot of refactoring
tools which care about the exact formulation of a constructor call easier to
write. Also some minor cleanups to more consistently follow the friend pattern
instead of the setter pattern when rebuilding a serialized AST.

Patch originally by Samuel Benzaquen.

llvm-svn: 117254
2010-10-25 08:47:36 +00:00
Douglas Gregor 263803a6cd Teach clang_getCursorReferenced() and friends about BlockDeclRefExprs.
llvm-svn: 117167
2010-10-22 22:24:08 +00:00
John McCall 457a04e3ce Substantially revise how clang computes the visibility of a declaration to
more closely parallel the computation of linkage.  This gets us to a state
much closer to what gcc emits, modulo bugs, which will undoubtedly arise in
abundance.

llvm-svn: 117147
2010-10-22 21:05:15 +00:00
Douglas Gregor 12a6c9e441 Update clang_getCursor() test to check searches on include directives
llvm-svn: 117063
2010-10-21 20:55:34 +00:00
Douglas Gregor adfdccf1f3 Improve the implementation of libclang's token-annotation logic for
entities in the preprocessing record. Previously, we would only end up
getting the first token of a preprocessing record annotated
correctly. For example, given

  #include "foo.h"

we would only get the '#' annotated as an inclusion directive; the
'include' and '"foo.h"' tokens would be given the general 'processing
directive' annotation.

Now, we get proper annotations for entities in the preprocessing
record.

llvm-svn: 117001
2010-10-21 06:10:04 +00:00
Douglas Gregor 796d76a663 Extend the preprocessing record and libclang with support for
inclusion directives, keeping track of every #include, #import,
etc. in the translation unit. We keep track of the source location and
kind of the inclusion, how the file name was spelled, and the
underlying file to which the inclusion resolved.

llvm-svn: 116952
2010-10-20 22:00:55 +00:00
Douglas Gregor 0787b3224d Tweak code-completion result priorities, so that exact and similar
type matches have a bigger impact. The impetus for this change was
that, when initializing an enumeration value, we want enumerators of
that enumeration type to have a higher priority than, e.g., unrelated
local variables.

llvm-svn: 116774
2010-10-19 00:03:23 +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 643c330b91 Provide code completion for types after the '^' that starts a block
literal. 

llvm-svn: 116754
2010-10-18 21:34:55 +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
Andrew Trick 6c8ce5c8b5 Reverting r116493: removes a test that failed on clang selfhost and msvc
llvm-svn: 116522
2010-10-14 21:41:16 +00:00
David Chisnall a9d40ee0ab Test case for r116439
llvm-svn: 116493
2010-10-14 18:15:20 +00:00
Douglas Gregor 7bb8af613c When we load an ASTUnit from command-line arguments, hold on to the
diagnostics produced by the driver itself. Previously, we were
allowing these to either be dropped or to slip through to stderr.

Fixes <rdar://problem/7595339>.

llvm-svn: 116285
2010-10-12 00:50:20 +00:00
Douglas Gregor 21d0e5a06c This test should now work on windows, since we're no longer using temporary files badly
llvm-svn: 116261
2010-10-11 23:18:55 +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 7845f1e80e Eliminate clang_setUseExternalASTGeneration() from libclang. Between
improvements to the compiler and the introduction of crash recovery,
it no longer makes sense to allow this mode. Moreover, this eliminates
one use of the "clang" executable from within libclang; we'd like them
all to go away.

llvm-svn: 116207
2010-10-11 16:52:23 +00:00
Douglas Gregor aca68323f3 Remove a rogue typo
llvm-svn: 115618
2010-10-05 14:58:05 +00:00
Douglas Gregor 93269380e7 Register the __builtin_va_list_type node when we parse it, rather than
waiting until we think we need it: we didn't catch all of the places
where we actually needed it, and we probably wouldn't ever. Fixes a
C++ PCH crasher.

llvm-svn: 115617
2010-10-05 14:55:45 +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 97c7571ef3 Introduce a new libclang function, clang_getCursorDisplayName(), which
produces a simple "display" name that captures the
arguments/parameters for a function, function template, class
template, or class template specialization.

llvm-svn: 115428
2010-10-02 22:49:11 +00:00
Douglas Gregor 4e3918c06b Teach clang_getCursorType() about base specifiers and other references
to types. 

Also, teach clang_getTypeDeclaration() about template specializations,
injected-class-names, and elaborated types.

Fixes <rdar://problem/8506460>.

llvm-svn: 115425
2010-10-02 21:57:58 +00:00
Douglas Gregor 3478c75b71 Provide proper source location and range information for C++ base
specifier cursors in libclang. FIXME -=2, fixes the rest of
<rdar://problem/8274883>.

llvm-svn: 115419
2010-10-02 19:51:13 +00:00
Douglas Gregor e6712983d2 Teach clang_getCursorReferenced() about Objective-C property reference
and protocol expressions. Fixes <rdar://problem/7833565>.

llvm-svn: 115346
2010-10-01 21:11:22 +00:00
Douglas Gregor 99a26afd49 Extend libclang with an API that determines, given a C++ virtual
member function or an Objective-C method, which other member
functions/methods it overrides.

llvm-svn: 115338
2010-10-01 20:25:15 +00:00
Ted Kremenek 9fcf3e0a20 Add test case for <rdar://problem/8452791> (fixed in r114392).
llvm-svn: 114989
2010-09-28 21:11:07 +00:00
Douglas Gregor 2fb99df2c3 When setting the globally-visible declarations for a particular
identifier, we may have a Sema object but no translation unit scope
(because parsing is finished). In this case, we still need to update
the IdResolver, which might still be used when writing a PCH
containing another PCH (without chaining). This bug manifested as a
failure with precompiled preambles.

Also, add a little environment-variable-sensitive logging for
libclang.

llvm-svn: 114774
2010-09-24 23:29:12 +00:00
Ted Kremenek 45c42ec2f1 Remove this test for now until I figure out how to get it to work with c-index-test in a portable way.
llvm-svn: 114721
2010-09-24 02:43:32 +00:00
Ted Kremenek 2c2d146488 Pass -fobjc-nonfragile-abi2 in test.
llvm-svn: 114720
2010-09-24 02:00:46 +00:00
Ted Kremenek f93eb1b09e Since this test depends on default ivar synthesis, specify the target triple. This hopefully unbreaks the buildbot
on some archs.

llvm-svn: 114716
2010-09-24 01:51:38 +00:00
Ted Kremenek 25cfb3b511 Update comment in test with reference to bug report.
llvm-svn: 114715
2010-09-24 01:24:15 +00:00
Ted Kremenek 74a9f98522 Default synthesized ivars don't really have a location in the source. Using the location of the @implementation
is just confusing for clients that want to use SourceLocations for syntactic references.

Fixes: <rdar://problem/8470540>
llvm-svn: 114714
2010-09-24 01:23:01 +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
Ted Kremenek 24fb1d03d3 Add test case for c-index-test showing that @property declarations added in class extensions don't get reported
in the @interface.

llvm-svn: 114694
2010-09-23 21:25:13 +00:00
Ted Kremenek cba5849c0b For properties declared in a @protocol and redeclared in a class extension, use the class extension
as the lexical DeclContext for the @property declaration that gets auto-created for the @interface.

Fixes: <rdar://problem/8467189>
llvm-svn: 114693
2010-09-23 21:18:05 +00:00
Ted Kremenek 2f07563f47 Correctly register the class extension as the lexical DeclContext for ObjC methods declared with @property in class extensions.
This matches the behavior for setters.

Also pass the class extension to ProcessPropertyDecl as the lexical DeclContext, even when not redeclaring the @property.

This fixes the remaining issues in <rdar://problem/7410145>.

llvm-svn: 114477
2010-09-21 20:52:59 +00:00
Ted Kremenek e3a7d1ba40 For ObjCPropertyDecls in class extensions, use the class extension as the lexical DeclContext for newly created
ObjCMethodDecls.  Further, use the location of the new property declaration as the location of new ObjCMethodDecls
(if they didn't previously exist).

This fixes more of the issues reported in <rdar://problem/7410145>.

llvm-svn: 114456
2010-09-21 18:28:43 +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 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 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 8af2ff89f7 Introduce a simple, substitution-based compression scheme for USRs, so
that redundant types don't result in super-long USRs. Fixes
<rdar://problem/8447875>.

llvm-svn: 114347
2010-09-20 20:37:39 +00:00
Douglas Gregor 521db40c15 Give the Objective-C _cmd an "unlikely" code completion priority; it's
very rarely used.

llvm-svn: 114286
2010-09-18 15:16:27 +00:00
Douglas Gregor 112b51e72d Add another text for code completion after recovery
llvm-svn: 114257
2010-09-18 02:10:40 +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 ec06c124f1 Improve recovery when the middle expression of a ternary operator is ill-formed
llvm-svn: 114231
2010-09-17 22:41:34 +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 f9088c93be When traversing an InitListExpr, there may not be a syntactic form;
check for NULL and visit the InitListExpr we have if there is no
syntactic form.

llvm-svn: 114203
2010-09-17 20:26:51 +00:00
Douglas Gregor e9e641cce1 Swap the priorities of constants and types, so that we prefer types.
llvm-svn: 114086
2010-09-16 16:21:35 +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 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 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 16a2bdd6b0 Introduce a new kind of cursor into libclang, which covers a reference
to an "overloaded" set of declarations. This cursor kind works for
unresolved references to functions/templates (e.g., a call within a
template), using declarations, and Objective-C class and protocol
forward declarations.

llvm-svn: 113805
2010-09-13 22:52:57 +00:00
Douglas Gregor 250ab1dc0e The two libclang crash-recovery tests that involve precompiled
preambles end up leaving the precompiled preambles around. This is by
design, since we do minimal cleanup during crash recovery. However,
it's unfortunate for testing, so introduce a hook that allows these
two tests to put the precompiled preamble somewhere where we can
delete them after testing.

llvm-svn: 113698
2010-09-11 18:05:19 +00:00
Douglas Gregor a93ab66331 Add libclang support for label statements, gotos, and taking the
address of a label (GNU extension).

llvm-svn: 113564
2010-09-10 00:22:18 +00:00
Douglas Gregor d198047ef3 Add libclang visitation for C99 designated initializers.
llvm-svn: 113560
2010-09-09 23:28:23 +00:00
Douglas Gregor 0d4d88cf38 Add libclang visitation for __builtin_offsetof's components (fields
and array references).

llvm-svn: 113556
2010-09-09 23:10:46 +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 57df3b4b12 Use temporary files for this test, to see if we can flush out an inexplicable error on Windows
llvm-svn: 113493
2010-09-09 16:16:39 +00:00
Douglas Gregor 54e5b13a27 Add proper type-source information to UnaryTypeTraitExpr, including
libclang visitation.

llvm-svn: 113492
2010-09-09 16:14:44 +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
Douglas Gregor 2b88c115f9 Provide proper type-source location information for
CXXTemporaryObjectExpr, CXXScalarValueInitExpr, and
CXXUnresolvedConstructExpr, getting rid of a bunch of FIXMEs in the
process.

llvm-svn: 113319
2010-09-08 00:15:04 +00:00
Douglas Gregor 0744ef6371 Improve source-location information for CXXNewExpr, by hanging on to
the TypeSourceInfo for the allocated type. Fixes PR7501.

llvm-svn: 113291
2010-09-07 21:49:58 +00:00
Chris Lattner 24b89469ac 'const std::type_info*' instead of 'std::type_info const*'
llvm-svn: 113092
2010-09-05 00:17:29 +00:00
Chris Lattner 53fa04909c make clang print types as "const int *" instead of "int const*",
which is should have done from the beginning.  As usual, the most
fun with this sort of change is updating all the testcases.

llvm-svn: 113090
2010-09-05 00:04:01 +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
Douglas Gregor 901a0fabfc Implement libclang visitation for UnresolvedMemberExpr. This is the
last of the C++-specific expressions where we have decent source
information in the AST already. In particular, various
object-construction expressions (CXXNewExpr, CXXTemporaryObjectExpr)
still have poor source-location information that needs to be addressed.

llvm-svn: 112981
2010-09-03 18:01:25 +00:00
Douglas Gregor 4583827e13 libclang visitation for CXXDependentScopeMemberExpr
llvm-svn: 112978
2010-09-03 17:35:34 +00:00
Douglas Gregor 4ae34afaf9 libclang visitation for DependentScopeDeclRefExpr
llvm-svn: 112975
2010-09-03 17:24:10 +00:00
Daniel Dunbar bf257a652d Avoid unnecessary redirect, so that stderr shows up in output.
llvm-svn: 112965
2010-09-03 15:45:00 +00:00
Douglas Gregor f24eaee2b3 Teach libclang to visit OverloadExprs, so that we can reuse this
code. Also, teach it about explicitly-specified template arguments.

llvm-svn: 112884
2010-09-02 22:29:21 +00:00
Douglas Gregor 3ca46b4275 Add libclang visitation for UnresolvedLookupExprs
llvm-svn: 112879
2010-09-02 22:19:24 +00:00
Douglas Gregor 4edb2ff89f Add libclang visitation for C++ pseudo-destructor expressions.
llvm-svn: 112873
2010-09-02 22:09:03 +00:00
Douglas Gregor 46af501065 Add libclang visitation for C++ typeid expressions.
llvm-svn: 112862
2010-09-02 21:20:16 +00:00
Douglas Gregor 32e4c861c8 In libclang, visit the nested-name-specifier and explicitly-specified template arguments of a MemberExpr.
llvm-svn: 112860
2010-09-02 21:07:44 +00:00
Douglas Gregor aac7c8106a Visit the nested-name-specifier and explicitly-specified template
arguments of a DeclRefExpr.

llvm-svn: 112854
2010-09-02 20:35:02 +00:00
Douglas Gregor 3335f48448 Implement basic visitation for nested name specifiers via libclang
cursors. Sadly, this visitation is a hack, because we don't have
proper source-location information for nested-name-specifiers in the
AST. It does improve on the status quo, however.

llvm-svn: 112837
2010-09-02 17:35:32 +00:00
Douglas Gregor d3f48bd3be Introduce a new libclang function,
clang_getSpecializedCursorTemplate(), which determines the template
(or member thereof) that the given cursor specializes or from which it
was instantiated. This routine can be used to establish a link between
templates and their instantiations/specializations.

llvm-svn: 112780
2010-09-02 00:07:54 +00:00
Douglas Gregor be99693127 Fix the source-range information for an EnumConstantDecl; previously,
it did not include the initializer expression.

llvm-svn: 112739
2010-09-01 20:41:53 +00:00
Douglas Gregor 982152433b Test visiting the template parameters of template template parameters,
support for which came in with the last commit.

llvm-svn: 112735
2010-09-01 20:21:58 +00:00
Douglas Gregor 06c7d2df9b Teach libclang to visit the default arguments of template parameters.
llvm-svn: 112734
2010-09-01 20:16:53 +00:00
Douglas Gregor a9aa29cf0b Implement libclang support for using declarations. Clang actually uses
three different kinds of AST nodes to represent using declarations:
UsingDecl, UnresolvedUsingValueDecl, and
UnresolvedUsingTypenameDecl. These three are collapsed into a single
cursor kind for using declarations, since libclang clients don't need
the distinction.

Several related changes here:
  - Cursor visitation of the three AST nodes for using declarations
  - Proper source-range computation for these AST nodes
  - Using declarations have no USRs, since they don't actually declare
    any entities.

llvm-svn: 112730
2010-09-01 19:52:22 +00:00
Douglas Gregor 9dc243c3eb Improve libclang indexing support for class template specializations
in a few related ways:

  - Don't recurse into instantiations of templates.
  - Recurse into explicit specializations.
  - Visit the template arguments of an explicit specialization or
    explicit instantiation.
  - Include template specialization arguments in the USRs for class
    template specializations.

llvm-svn: 112720
2010-09-01 17:32:36 +00:00
Douglas Gregor 920cadf9ae Add test for nothing... i.e., the contents of a USR for using directives
llvm-svn: 112716
2010-09-01 16:37:17 +00:00
Douglas Gregor 01a430134f Implement libclang support for using directives (cursor + visitation +
suppressing USRs). Also, fix up the source location information for
using directives so that the declaration location refers to the
namespace name.

llvm-svn: 112693
2010-09-01 03:07:18 +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 f9e43cef54 Improve location information in the representation of namespace
aliases. Previously, the location of the alias was at the "namespace"
keyword. Now, it's on the identifier being declared (as is the custom
for Clang), and we keep a separate source location for the "namespace"
keyword.

Also, added a getSourceRange() member function to NamespaceAliasDecl
to correctly compute the source range.

Finally, removed a bunch of setters from NamespaceAliasDecl and gave
ASTReaderDecl friendship so that it could set the corresponding fields
directly.

llvm-svn: 112681
2010-09-01 00:08:19 +00:00
Douglas Gregor a89314e396 Add libclang support for namespace aliases (visitation + USRs) along
with a new cursor kind for a reference to a namespace. 

There's still some oddities in the source location information for
NamespaceAliasDecl that I'll address with a separate commit, so the
source locations displayed in the load-namespaces.cpp test will
change.

llvm-svn: 112676
2010-08-31 23:48:11 +00:00
Douglas Gregor a23e8f7a0f Extend libclang with a new cursor kind that indicates a reference to a
template. Such cursors occur, for example, in template specialization
types such as vector<int>. Note that we do not handle the
super-interesting case where the template name is unresolved, e.g.,
within a template.

llvm-svn: 112636
2010-08-31 20:37:03 +00:00
Douglas Gregor f96abb293a Add libclang support for class template partial specializations,
including a cursor kind, visitation, and USRs.

llvm-svn: 112629
2010-08-31 19:31:58 +00:00
Douglas Gregor 1fbaeb196b Add a libclang cursor kind, visitation support and USR support for C++
class templates. 

llvm-svn: 112627
2010-08-31 19:02:00 +00:00
Douglas Gregor 713602bb09 Implement basic support for indexing function templates in
libclang. This includes:
  - Cursor kind for function templates, with visitation logic
  - Cursor kinds for template parameters, with visitation logic
  - Visitation logic for template specialization types, qualified type
  locations
  - USR generation for function templates, template specialization
  types, template parameter types.

Also happens to fix PR7804, which I tripped across while testing.

llvm-svn: 112604
2010-08-31 17:01:39 +00:00
Douglas Gregor 12bca22e91 libclang indexing support for C++ constructors, destructors, and
conversion functions. This introduces new cursor kinds for these three
C++ entities, and reworks visitation of function declarations so that
we get type-source information for the names.

llvm-svn: 112600
2010-08-31 14:41:23 +00:00
Douglas Gregor db2be6a592 Add a simple test for indexing namespaces
llvm-svn: 112598
2010-08-31 13:31:19 +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
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 fdce48b0ca Add missing test case for constructor-initializer code completions
llvm-svn: 112453
2010-08-29 19:20:21 +00:00
Ted Kremenek ae9e221513 Implement CXCursor support for walking C++ base specifiers. This includes adding the API hooks clang_isVirtualBase() and clang_getCXXAccessSpecifier() to query properties of the base specifier.
Implements <rdar://problem/8274883>.

llvm-svn: 112296
2010-08-27 21:34:58 +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
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