Author Topic: code completion fails for struct in a vector  (Read 10487 times)

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5490
code completion fails for struct in a vector
« on: October 27, 2010, 09:41:37 am »
Consider the following code :
Code
#include <vector>

class Foo
{
public:
    void DoSomething();

private:
    struct Bar
    {
        int mMember1;
        int mMember2;

        Bar() : mMember1(), mMember2() {}
    };

    std::vector<Bar> mBars;
};


void Foo::DoSomething()
{
    Bar bar1;
    mBars.push_back(bar1);

    bar1.mMember1 = 0;

    mBars[0].mMember1 = 0;
}

int main()
{
    Foo foo1;
    foo1.DoSomething();
    return 0;
}

Focus on the DoSomething() method.

1) if you type "bar1." --> completion works : OK
2) if you type "mBars[0]."  --> NO completion kicks in : NOT OK

hope this example can help for the improvement ;-)

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: code completion fails for struct in a vector
« Reply #1 on: October 27, 2010, 09:56:09 am »
This feature need blueshake help.
 :lol:

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: code completion fails for struct in a vector
« Reply #2 on: October 27, 2010, 09:56:36 am »
Just for the record: it works with clang (new toy  :lol: ):
Code
jens@debian-inspiron:/tmp/test$ clang++ -w -fsyntax-only -Xclang -code-completion-at=main.cpp:28:14 main.cpp
COMPLETION: Bar : Bar::
COMPLETION: mMember1 : [#int#]mMember1
COMPLETION: mMember2 : [#int#]mMember2
COMPLETION: operator= : [#struct Foo::Bar &#]operator=(<#struct Foo::Bar const &#>)
COMPLETION: ~Bar : [#void#]~Bar()
jens@debian-inspiron:/tmp/test$

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: code completion fails for struct in a vector
« Reply #3 on: October 27, 2010, 10:53:25 am »
2) if you type "mBars[0]."  --> NO completion kicks in : NOT OK

Current CC will do something like:

splite the statement
Code
mBars[0].
to
two pieces

One is: mBars class
The next One is: empty string (everything)

Note:
Code
[0] 
is skipped. So, cc woks badly.

The way to solve the statement information is quite hard. codelite use the bison/yacc grammar to solve the statement grammar tree.
This is the way like gdb to parse user's statement like you enter some command (GDB use bison/yacc grammar either, you can see gdb's source of c-exp.y under gdb subfolder.
Code
p mBars[0].Value

Implement this kind of expression solving is not easy. :D
like jens said, I suggest using Clang (or in the feature) :D it was more powerful and if we use the clang and PCH feature, I think codecompletion will run fast. (see some comments from eranif Clang command line support for codecompletion)


edit
from this page,
http://clang.llvm.org/features.html

clang is a hand-write recursive descent parser.

Quote
A single unified parser for C, Objective C, C++, and Objective C++

Clang is the "C Language Family Front-end", which means we intend to support the most popular members of the C family. We are convinced that the right parsing technology for this class of languages is a hand-built recursive-descent parser. Because it is plain C++ code, recursive descent makes it very easy for new developers to understand the code, it easily supports ad-hoc rules and other strange hacks required by C/C++, and makes it straight-forward to implement excellent diagnostics and error recovery.

We believe that implementing C/C++/ObjC in a single unified parser makes the end result easier to maintain and evolve than maintaining a separate C and C++ parser which must be bugfixed and maintained independently of each other.
« Last Edit: October 27, 2010, 02:32:05 pm by ollydbg »
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.

Offline blueshake

  • Regular
  • ***
  • Posts: 459
Re: code completion fails for struct in a vector
« Reply #4 on: October 27, 2010, 01:19:10 pm »
autually operator [] has been supported for a long time,you guys can write some codes to test it.
the vector doesn't work because of the class[vector]  inheritance is not built. I should do this a long ago.
but recently I am quite losing my time.sorry.
Keep low and hear the sadness of little dog.
I fall in love with a girl,but I don't dare to tell her.What should I do?

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5490
Re: code completion fails for struct in a vector
« Reply #5 on: October 27, 2010, 04:07:37 pm »
autually operator [] has been supported for a long time,you guys can write some codes to test it.
the vector doesn't work because of the class[vector]  inheritance is not built. I should do this a long ago.
but recently I am quite losing my time.sorry.

you might be able to do it somewhere in the (near) future, cause I understand you might have an idea how it can be done, right ?

Offline blueshake

  • Regular
  • ***
  • Posts: 459
Re: code completion fails for struct in a vector
« Reply #6 on: October 28, 2010, 01:11:43 am »
yes,I have thought this issue for a while.just need to prove if it is right or not.Now I have several plastic struct design on hand. after I finish them .I will start to do it. :D
Keep low and hear the sadness of little dog.
I fall in love with a girl,but I don't dare to tell her.What should I do?