News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

New code completion remarks/issues

Started by killerbot, September 15, 2009, 12:24:28 PM

Previous topic - Next topic

oBFusCATed

Quote from: jens on January 02, 2010, 07:39:19 PM
Works fine here (debian 64-bit).
Both work (the completion and the calltip problems)?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Jenna

Quote from: oBFusCATed on January 02, 2010, 07:45:25 PM
Quote from: jens on January 02, 2010, 07:39:19 PM
Works fine here (debian 64-bit).
Both work (the completion and the calltip problems)?

No only the completion and the tooltip for method.

oBFusCATed

Another bug, this time 100% reproducible:



Steps:
1. Create console project
2. Remove the auto generated code
3. Paste the code below:


struct TestStruct
{
    int a;

    int Test()
    {
        int test_1, test_2;
        tes
    }
};


4. Hit ctrl + space at "tes" line
5. Type t_ and repeat step 4. ... works as expected.

Tested on gentoo amd64 + cb 6112 debugger branch
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

ollydbg

#258
Quote from: oBFusCATed on January 29, 2010, 11:28:41 PM
Another bug, this time 100% reproducible:

Ok, I just do more test, for example, if you paste these code to your main.cpp.
Test Code one:

struct TestStruct
{
   int test_3;

   int Test()
   {
       int test_1, test_2;
       te
   }
};

Then you get the auto-completion list is:(see the screen shot as attachment 1)
template
Test
test_3


These Code two:
struct TestStruct
{
   int test_3;

   int Test()
   {
       int test_1, test_2;
       test_
   }
};

Then you will get only "test_3" in auto-completion list.(see attachment2)

These code three:

struct TestStruct
{
   int aaaaa;

   int Test()
   {
       int test_1, test_2;
       test_
   }
};

Now, it can autocomplete both "test_1" and "test_3". see the screen shot of attachment 3.




[attachment deleted by admin]
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.

ollydbg

Let me explain why this bug happened.
It is related to the "initial search scope" in the CC's source code of AI() function.

// Start an Artificial Intelligence (!) sequence to gather all the matching tokens..
// The actual AI is in FindAIMatches() below...
size_t NativeParser::AI(TokenIdxSet& result,
                       cbEditor* editor,
                       const wxString& lineText,
                       bool noPartialMatch,
                       bool caseSensitive,
                       TokenIdxSet* search_scope,
                       int caretPos)
{
......
......



   if (result.size()<1) // found nothing in the search_scope, add global namespace
   {
       if (s_DebugSmartSense)
           Manager::Get()->GetLogManager()->DebugLog(F(_T("AI() result is zero. Adding global namespace.")));

       search_scope->insert(-1);
       FindAIMatches(components, result, -1, noPartialMatch, caseSensitive, true, 0xffff, search_scope);
   }

......



In the AI function, we firstly collect the "initial search scope", then do the recursive matching stage. I have already written some steps in the wiki, you can see here: 5 Automatic Code Completion, so, the "global namespace scope" is not added by default.( if I can remember, in a earlier revision, when we were collecting initial search scopes", global namespace is always added)

You can see the "if" condition.

For example, when we do the AI function in the code below:
struct TestStruct
{
   int test_3;

   int Test()
   {
       int test_1, test_2;
       te
   }
};


We firstly add the initial scope is "struct TestStruct", then do the AIMatch routing in this scope. Too bad that when the "local parser" parsing the local statement, both "test_1" and "test_2" will added to the "global scope namespace":
{
       int test_1, test_2;
       te
   }


So, when we do a AIMatch in the "strct TestStruct", we find we get the two matches: "Test()" and the member variable "test_3". At this time, we have already get the matching result size >1, so, due to the if condition, global namespace is not searched any more.

Solution:

We can have two solutions:
One: we can force to add the "global search scope" to the initial search, so that we can get the right matching result. the Pros is it is quite simple, the cons is that you will loose the performance and cause other issue.

For example:


int abcd;

int main()
{
   int abcd;
  ab
}


Here, both global variable and auto variable name will be prompted. In CB forum, some people just suggest the "auto variable" in the function body.

Two:
We don't need to add the global namespace in the initial search scope.
When the "local parser" parse the function body, the "auto variable" added as the children of the function body.

For example:
struct TestStruct
{
   int test_3;

   int Test()
   {
       int test_1, test_2;
       te
   }
};

This time, the initial search scope should be: "struct TestStruct" and the "Test()".
So, when we do an AIMatch under "TestStruct" scope, we get the "test_3" and "Test()" matches.
Also, when we do an AIMatch under "Test()", we get the "test_1" and "test_2" matches.
So, we get the expected prompted list.

I have tried to using this method, but I didn't get success, because, when a parserthread attached with a "local body" is initialed, the defualt m_Parent Token is always the "global namespace", so the "test_2" and "test_1" will always be added to the "global namespace".

If we can supply a way that we can "set" m_Parent pointer to "Test() Token", we can totally solved this problem.





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.

oBFusCATed

Quote from: ollydbg on January 31, 2010, 02:54:04 AM
We firstly add the initial scope is "struct TestStruct", then do the AIMatch routing in this scope. Too bad that when the "local parser" parsing the local statement, both "test_1" and "test_2" will added to the "global scope namespace":
{
       int test_1, test_2;
       te
   }


So, when we do a AIMatch in the "strct TestStruct", we find we get the two matches: "Test()" and the member variable "test_3". At this time, we have already get the matching result size >1, so, due to the if condition, global namespace is not searched any more.

So, this is a parser bug? Can it be fixed easily?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

blueshake

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?

damur

Hi!

I tried to use wxWidgets in Codeblocks, but Code Completion does not work correctly. And I think it's because of an #elif directive. Try this:
#define CONDITION

#if defined(SOMETHING)
    #include "something.h"
#elif defined(CONDITION)
    #include "class1.h"
#endif


int main()
{
    return 0;
}

class1.h is a file which is not part of your project (because else it would be parsed either way). So the file class1.h doesn't get parsed.
Interesting: replace "something.h" with "class1.h" and class1.h gets parsed, although SOMETHING is not defined.

Directives like this are used in most header files of wx base classes, for example "wx/button.h"

I'm using ubuntu9.10 and codeblocks SVN 6088. I tried also the 8.02 stable release, but it had the same bug.

blueshake

it is not a bug.it is just not implemented yet.Be patient! Ollydbg had done a little work.it will be solved soon.
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?

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.

oBFusCATed

(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

ollydbg

Quote from: oBFusCATed on March 02, 2010, 09:09:48 AM
OK, Might test it...
In fact, only one statement do the hack:

search_scope->insert(-1);//alwayser search the global scope.
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.