Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-dev] Content assist + function pointers

Hi all,

I would have a suggestion for content assist/auto-complete.

Let's say I have this function pointer type:

  typedef void (*callback_type) (int a, double b, char c);

and function foo takes one of these as a parameter:

  void foo(callback_type func);

and bar implements that signature:

  void bar (int a, double b, char c) {
    ...
  }

and I want to pass bar to foo like this:

  foo (bar);

i can type up to this point:

  foo (b

and then use content assist (ctrl-space) to auto-complete bar (well, that's a
bad example since it's a short name, but imagine it's a reaaally long name). When
I select bar in the content assist drop down, CDT autocompletes as if I wanted to
call bar at this point:

  foo (bar (a, b, c)

but it's not the case, I just want to pass it as a pointer, so I'd like if it did:

  foo (bar

I then have to remove the parentheses and their content.  When working frequently
with callbacks/function pointers, it becomes a bit annoying.  Could CDT be smarter,
so that under certain conditions, it doesn't add the parentheses?

For example, if the type of the function selected in the menu (bar) matches precisely
the type expected at this point (which foo accepts), then there is a good chance that
we don't actually want to call the function, but pass it as a function pointer.  I
don't really know how CDT works internally, but I guess that this might be tricky.
For example, the AST might not include the necessary info at this point, since the
statement is not syntactically correct yet, so it might be hard to detect that the
user is typing foo's first parameter.

But anyway, I am throwing the idea out there, so people who know how it works can tell
whether it's realistic or not.

Thanks!

Simon





Back to the top