Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => CodeCompletion redesign => Topic started by: killerbot on October 27, 2010, 09:41:37 am

Title: code completion fails for struct in a vector
Post by: killerbot 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 ;-)
Title: Re: code completion fails for struct in a vector
Post by: Loaden on October 27, 2010, 09:56:09 am
This feature need blueshake help.
 :lol:
Title: Re: code completion fails for struct in a vector
Post by: Jenna 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$
Title: Re: code completion fails for struct in a vector
Post by: ollydbg 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 (http://forums.codeblocks.org/index.php/topic,13559.0.html))


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.
Title: Re: code completion fails for struct in a vector
Post by: blueshake 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.
Title: Re: code completion fails for struct in a vector
Post by: killerbot 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 ?
Title: Re: code completion fails for struct in a vector
Post by: blueshake 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