Author Topic: Code completion  (Read 7266 times)

Offline Wolf

  • Multiple posting newcomer
  • *
  • Posts: 30
Code completion
« on: September 21, 2008, 02:31:01 pm »
Hello,
I have been working all night on the code completion plugin, and I have noted a few design flaws, but there is an easy workaround for all those I found.
Anyways, I was able to get code completion to work for unions (yay! everyone has been waiting for that), and I'm not stopping there. I've got it working for variables declared using the struct/class/union keyword ("zz" in the example) and for variables declared with a class/structure/union declaration ("aa", "bb", and "cc" in the example). It knows when it is a typedef or not. I'm making it work for structures inside structures. However, I am faced with one small (big) problem. The difference between languages, C and C++.

Example:
Code
typedef struct {
struct s {
int value;
} aa;
} MyStruct;

struct MyOtherStruct {
int val;
} bb, cc;

struct MyOtherStruct zz;

In C, you can declare a variable of type s. But in C++, it has to be of type MyStruct::s. So I am wondering whether I should set s as global, as a child of MyStruct, or both?

Here's my patch: http://developer.berlios.de/patch/index.php?func=detailpatch&patch_id=2566&group_id=5358

EDIT: Okay, this is my latest version. Spent the whole night on this, time to get a few minutes of sleep.

-- Wolf --

PS: If you need someone to work on the code completion module, I would be glad to help.
« Last Edit: September 21, 2008, 02:54:32 pm by Wolf »

Offline Wolf

  • Multiple posting newcomer
  • *
  • Posts: 30
Re: Code completion
« Reply #1 on: September 22, 2008, 03:52:29 am »
Okay, looks like today my patch causes CB to crash. I'll check that out later. It has no security checks, so it is very possible...

EDIT: Found the code responsible for the crash. It is what I was thinking I forgot to handle.

Code
struct MyOtherStruct {
int val;
} bb, cc;

struct MyOtherStruct zz;

It doesn't handle yet declaring multiple variables after a structure declaration. Something very simple to handle... I'll do that soon.
« Last Edit: September 22, 2008, 03:54:23 am by Wolf »

Offline Wolf

  • Multiple posting newcomer
  • *
  • Posts: 30
Re: Code completion
« Reply #2 on: September 22, 2008, 07:03:10 pm »
I have fixed the problem, but not uploaded the patch yet patch uploaded, as I'm facing a new problem.

Code
struct HiddenStruct {
int myval;
struct {
int value;
} bb;
};

struct HiddenStruct yy;

struct MyOtherStruct {
int val;
} bb, cc;

It adds 'bb' as a variable of type 'Unnamed-Struct-xxx' with 'HiddenStruct' as a parent.
Then, it adds 'bb' as a variable of type 'MyOtherStruct' with no parent.
And in the symbols browser, 'bb' doesn't show up in the variables. And in 'HiddenStruct', it shows 'bb' as 'MyOtherStruct' instead of 'Unnamed-Struct-xxx'.

If anyone could check this out, it would be appreciated.
Also, I don't really know why, but even if 'cc' is added (so it says in the log), it doesn't appear in the symbols browser.
When I initially load the file (or call a re-parse), it does appear, but when I save the file and the tree is updated, it disappears.

-- Wolf --

Code
yy.bb. // shows val instead of value
« Last Edit: September 22, 2008, 11:47:31 pm by Wolf »

Offline JGM

  • Lives here!
  • ****
  • Posts: 518
  • Got to practice :)
Re: Code completion
« Reply #3 on: September 28, 2008, 07:21:17 pm »
Hey great job! You are really good to work with the currento cc code! Keep it going :D

Offline Wolf

  • Multiple posting newcomer
  • *
  • Posts: 30
Re: Code completion
« Reply #4 on: September 29, 2008, 10:08:05 pm »
Hey great job! You are really good to work with the currento cc code! Keep it going :D
Thanks. I wish I could keep it going, but I don't want to mess with the token tree. I don't think I'll be able to provide more patches in a while, so have fun with it.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5324
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion
« Reply #5 on: December 25, 2008, 02:51:53 pm »
hi, wolfs, It's great to improve this plugin. Thanks.
It still has many bugs. :D
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.