Commit Graph

73 Commits

Author SHA1 Message Date
Douglas Gregor 2a920014d3 When code-completion after a "," is building an overload set, note
that there is one more argument (the one following the comma) and make
the candidate non-viable if the function cannot accept any argument in
that position.

llvm-svn: 82625
2009-09-23 14:56:09 +00:00
Douglas Gregor f0f51985a1 Print the results of code-completion for overloading by displaying the
signature of the function with the current parameter highlighted as a
placeholder.

llvm-svn: 82593
2009-09-23 00:34:09 +00:00
Douglas Gregor 05f477c177 Separate the code-completion results for call completion from the
results for other, textual completion. For call completion, we now
produce enough information to show the function call argument that we
are currently on.

llvm-svn: 82592
2009-09-23 00:16:58 +00:00
Douglas Gregor 2b3ee156fc When code-completion finds a declaration only because it is usable as
the start of a nested-name-specifier, add the "::" after the
nested-name-specifier to the code-completion string.

llvm-svn: 82587
2009-09-22 23:22:24 +00:00
Douglas Gregor 5bf52697b0 Tweak the code-completion results ranking and formation, so that
members found in base classes have the same ranking as members found
in derived classes. However, we will introduce an informative note for
members found in base classes, showing (as a nested-name-specifier)
the qualification to name the base class, to make it clear which
members are from bases.
 

llvm-svn: 82586
2009-09-22 23:15:58 +00:00
Douglas Gregor ba4490399b Teach code-completion to introduce a ", ..." placeholder for variadic functions
llvm-svn: 82577
2009-09-22 21:42:17 +00:00
Douglas Gregor ea9b03e6e2 Replace the -code-completion-dump option with
-code-completion-at=filename:line:column

which performs code completion at the specified location by truncating
the file at that position and enabling code completion. This approach
makes it possible to run multiple tests from a single test file, and
gives a more natural command-line interface.

llvm-svn: 82571
2009-09-22 21:11:38 +00:00
Douglas Gregor cabea40ea3 Implement code completion within a function call, triggered after the
opening parentheses and after each comma. We gather the set of visible
overloaded functions, perform "partial" overloading based on the set
of arguments that we have thus far, and return the still-viable
results sorted by the likelihood that they will be the best candidate.

Most of the changes in this patch are a refactoring of the overloading
routines for a function call, since we needed to separate out the
notion of building an overload set (common to code-completion and
normal semantic analysis) and then what to do with that overload
set. As part of this change, I've pushed explicit template arguments
into a few more subroutines.

There is still much more work to do in this area. Function templates
won't be handled well (unless we happen to deduce all of the template
arguments before we hit the completion point), nor will overloaded
function-call operators or calls to member functions.

llvm-svn: 82549
2009-09-22 15:41:20 +00:00
Douglas Gregor 9d64c5e3a5 Code completion for ordinary names when we're starting a declaration, expression, or statement
llvm-svn: 82481
2009-09-21 20:51:25 +00:00
Douglas Gregor 2af2f670d1 When providing a code-completion suggestion for a hidden name, include
a nested-name-specifier that describes how to refer to that name. For
example, given:

  struct Base { int member; };
  struct Derived : Base { int member; };

the code-completion result for a member access into "Derived" will
provide both "member" to refer to Derived::member (no qualification needed) and
"Base::member" to refer to Base::member (qualification included).

llvm-svn: 82476
2009-09-21 20:12:40 +00:00
Douglas Gregor f251067530 Enhance "case" code completion in C++ to suggest qualified names for
enumerators when either the user intentionally wrote a qualified name
(in which case we just use that nested-name-specifier to match
the user's code) or when this is the first "case" statement and we
need a qualified name to refer to an enumerator in a different scope.

llvm-svn: 82474
2009-09-21 19:57:38 +00:00
Douglas Gregor d328d57c39 Code completion for "case" statements within a switch on an expression
of enumeration type, providing the various unused enumerators as options.

llvm-svn: 82467
2009-09-21 18:10:23 +00:00
Douglas Gregor b5c738b434 In C++ code completion, only suggest the "template" keyword after ".",
"->", or "::" if we will be looking into a dependent context. It's not
wrong to use the "template" keyword, but it's to needed, either.

llvm-svn: 82307
2009-09-18 23:55:56 +00:00
Douglas Gregor ce23bae4f8 Make the construction of the code-completion string for a function
template smarter, by taking into account which function template
parameters are deducible from the call arguments. For example,

  template<typename RandomAccessIterator>
  void sort(RandomAccessIterator first, RandomAccessIterator last);

will have a code-completion string like

  sort({RandomAccessIterator first}, {RandomAccessIterator last})

since the template argument for its template parameter is
deducible. On the other hand,

  template<class X, class Y>
  X* dyn_cast(Y *Val);

will have a code-completion string like

  dyn_cast<{class X}>({Y *Val})

since the template type parameter X is not deducible from the function
call.

llvm-svn: 82306
2009-09-18 23:21:38 +00:00
Douglas Gregor 3f6ca38927 Introduce code completion patterns for templates, which provide the
angle brackets < > along with placeholder template arguments.

llvm-svn: 82304
2009-09-18 22:47:56 +00:00
Douglas Gregor fedc328ae9 Introduce code completion strings, which describe how to *use* the
results of code completion, e.g., by providing function call syntax
with placeholders for each of the parameters.

llvm-svn: 82293
2009-09-18 22:15:54 +00:00
Douglas Gregor c811ede9b7 C++ code completion after the "operator" keyword. Provide overloaded
operators, type specifiers, type names, and nested-name-specifiers.

llvm-svn: 82264
2009-09-18 20:05:18 +00:00
Douglas Gregor 7e90c6db18 Introduce four new code-completion hooks for C++:
- after "using", show anything that can be a nested-name-specifier.
  - after "using namespace", show any visible namespaces or namespace aliases
  - after "namespace", show any namespace definitions in the current scope
  - after "namespace identifier = ", show any visible namespaces or
    namespace aliases

llvm-svn: 82251
2009-09-18 19:03:04 +00:00
Douglas Gregor 56c2dbcfe7 Handle using declarations and overload sets in code completion.
llvm-svn: 82233
2009-09-18 17:54:00 +00:00
Douglas Gregor 945e8d9762 For code completion in C++ member access expressions and tag names,
look into the current scope for anything that could start a
nested-names-specifier. These results are ranked worse than any of the
results actually found in the lexical scope.

Perform a little more pruning of the result set, eliminating
constructors, __va_list_tag, and any duplication of declarations in
the result set. For the latter, implemented
NamespaceDecl::getCanonicalDecl.

llvm-svn: 82231
2009-09-18 17:42:29 +00:00
Douglas Gregor 2da11086f3 When gathering results for code completion, only include hidden
results when there is some way to refer to them in the language, such
as with a qualified name in C++.

llvm-svn: 82223
2009-09-18 15:51:54 +00:00
Douglas Gregor f45b0cf389 Implement code completion for tags, e.g., code completion after "enum"
will provide the names of various enumerations currently
visible. Introduced filtering of code-completion results when we build
the result set, so that we can identify just the kinds of declarations
we want.

This implementation is incomplete for C++, since we don't consider
that the token after the tag keyword could start a
nested-name-specifier. 

llvm-svn: 82222
2009-09-18 15:37:17 +00:00
Douglas Gregor 2436e7116b Initial implementation of a code-completion interface in Clang. In
essence, code completion is triggered by a magic "code completion"
token produced by the lexer [*], which the parser recognizes at
certain points in the grammar. The parser then calls into the Action
object with the appropriate CodeCompletionXXX action.

Sema implements the CodeCompletionXXX callbacks by performing minimal
translation, then forwarding them to a CodeCompletionConsumer
subclass, which uses the results of semantic analysis to provide
code-completion results. At present, only a single, "printing" code
completion consumer is available, for regression testing and
debugging. However, the design is meant to permit other
code-completion consumers.

This initial commit contains two code-completion actions: one for
member access, e.g., "x." or "p->", and one for
nested-name-specifiers, e.g., "std::". More code-completion actions
will follow, along with improved gathering of code-completion results
for the various contexts.

[*] In the current -code-completion-dump testing/debugging mode, the
file is truncated at the completion point and EOF is translated into
"code completion".

llvm-svn: 82166
2009-09-17 21:32:03 +00:00