Author Topic: Some strange behaviors  (Read 19475 times)

Offline GeO

  • Multiple posting newcomer
  • *
  • Posts: 51
Some strange behaviors
« on: August 07, 2009, 02:18:58 pm »
Currently i found some strange behaviors using the new CC Branch of Code::Blocks:
1) if i enter
Code
while ()
and then press "." it will be autocompleted as
Code
while ().while
2) if i enter "ret" and then press "CTRL-SPACE" (for autocompletion) it shows me: return ,SHORT ,short_f.....
(see attachment)

[attachment deleted by admin]

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5913
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Some strange behaviors
« Reply #1 on: August 07, 2009, 02:52:40 pm »
I can confirm the first issue.
But, if there's no space between "while" and "(", then it has no error tips.

For the second issue, in my Chinese system Windows XP, ctrl + space will do a input method switch, so, I cant reproduce it. Continuing enter "retu" will give the right tip "return".

Edit
After change the short cut to "ALT +/", I can't reproduce the second issue. It can give the correct tip list with the prefix I entered.




[attachment deleted by admin]
« Last Edit: August 07, 2009, 03:11:52 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: Some strange behaviors
« Reply #2 on: August 08, 2009, 02:20:50 pm »
This  not only happened in the new CC Branch of Code::Blocks,but also in normal version.
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 blueshake

  • Regular
  • ***
  • Posts: 459
Re: Some strange behaviors
« Reply #3 on: August 09, 2009, 10:37:06 am »
I found all the keywords had this problem. and the keywords will show twice .for example .
when you type cla and the codecompletion tip will show two class.
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 ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5913
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Some strange behaviors
« Reply #4 on: August 09, 2009, 12:04:02 pm »
I found all the keywords had this problem. and the keywords will show twice .for example .
when you type cla and the codecompletion tip will show two class.
Really? But I have only one "class" in the tip list.



[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.

Offline blueshake

  • Regular
  • ***
  • Posts: 459
Re: Some strange behaviors
« Reply #5 on: August 09, 2009, 02:51:28 pm »
That is right.I download the svn 5716 Nightly builds.and it still exist ,it is strange .
see the attachment .

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

  • Developer
  • Lives here!
  • *****
  • Posts: 5913
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Some strange behaviors
« Reply #6 on: August 09, 2009, 02:56:21 pm »
That's strange. My local copy was using "trunk + cc_branch + my own patch" , so...
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: Some strange behaviors
« Reply #7 on: August 26, 2009, 12:30:46 pm »
Quote
Currently i found some strange behaviors using the new CC Branch of Code::Blocks:
1) if i enter
Code:

while ()

and then press "." it will be autocompleted as
Code:

while ().while
this problem can be solved by this patch.
Code
Index: nativeparser.cpp
===================================================================
--- nativeparser.cpp (revision 5744)
+++ nativeparser.cpp (working copy)
@@ -1214,8 +1214,8 @@
                         case '(': --nest; break;
                     }
                 }
-                if ((x > 0) && (wxIsalnum(line.GetChar(x - 1)) || line.GetChar(x - 1) == '_'))
-                    --x;
+                //if ((x > 0) && (wxIsalnum(line.GetChar(x - 1)) || line.GetChar(x - 1) == '_'))
+                //    --x;
             }
         }
     }
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 ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5913
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Some strange behaviors
« Reply #8 on: August 26, 2009, 02:08:50 pm »
Can you explain a little about this modify on the function:

Code
unsigned int NativeParser::FindCCTokenStart(const wxString& line)
{
    ......
    return x;
}

Thanks!
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 ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5913
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Some strange behaviors
« Reply #9 on: August 26, 2009, 02:32:36 pm »
The function is list below:
Code
unsigned int NativeParser::FindCCTokenStart(const wxString& line)
{
    int x = line.Length() - 1;
    int nest = 0;

    bool repeat = true;
    while (repeat)
    {
        repeat = false;
        while ((x >= 0) && (wxIsalnum(line.GetChar(x)) || line.GetChar(x) == '_'))
            --x;

        if ( (x > 0) &&
             ( (line.GetChar(x) == '>' && line.GetChar(x - 1) == '-') ||
               (line.GetChar(x) == ':' && line.GetChar(x - 1) == ':') ) )
        {
            x -= 2;
            repeat = true;
        }
        else if ((x >= 0) && (line.GetChar(x) == '.'))
        {
            --x;
            repeat = true;
        }

        if (repeat)
        {
            // now we 're just before the "." or "->" or "::"
            // skip any whitespace
            while ((x >= 0) && (line.GetChar(x) == ' ' || line.GetChar(x) == '\t'))
                --x;

            // check for function/array/cast ()
            if ((x >= 0) && (line.GetChar(x) == ')' || line.GetChar(x) == ']'))
            {
                ++nest;
                while (--x >= 0 && nest != 0)
                {
                    #if wxCHECK_VERSION(2, 9, 0)
                    switch (line.GetChar(x).GetValue())
                    #else
                    switch (line.GetChar(x))
                    #endif
                    {
                        case ']':
                        case ')': ++nest; break;

                        case '[':
                        case '(': --nest; break;
                    }
                }
                if ((x > 0) && (wxIsalnum(line.GetChar(x - 1)) || line.GetChar(x - 1) == '_'))
                    --x;
            }
        }
    }
    ++x;

    if (x < 0)
        x = 0;

    while (line.GetChar(x) == ' ' || line.GetChar(x) == '\t')
        ++x;

    //Manager::Get()->GetLogManager()->DebugLog("Starting at %d \"%s\"", x, line.Mid(x).c_str());
    return x;
}

I think we need to "skip any whitespace" after we find the "[" in the following line

Code
while     ().

That is what I think is right :D:

Code
                while (--x >= 0 && nest != 0)
                {
                    #if wxCHECK_VERSION(2, 9, 0)
                    switch (line.GetChar(x).GetValue())
                    #else
                    switch (line.GetChar(x))
                    #endif
                    {
                        case ']':
                        case ')': ++nest; break;

                        case '[':
                        case '(': --nest; break;
                    }
                }
                //***************ADD code here:
                // skip any whitespace
                while ((x >= 0) && (line.GetChar(x) == ' ' || line.GetChar(x) == '\t'))
                     --x;
                //**************
                ......


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: Some strange behaviors
« Reply #10 on: August 26, 2009, 02:39:14 pm »
so should we  add the codes
Code
                while ((x >= 0) && (line.GetChar(x) == ' ' || line.GetChar(x) == '\t'))
                     --x;
to the function or others?
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 MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Some strange behaviors
« Reply #11 on: August 26, 2009, 03:29:29 pm »
Both of you got me irritated by now... So I am simply looking forward to a new patch... ;-)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5913
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Some strange behaviors
« Reply #12 on: August 26, 2009, 03:43:03 pm »
Step into the CC plugin when I enter the "." after

Code
while   ()

I find that the "BreakUpComponents" function will give the components as "while".

See the screenshot


So, the code-completion related code will firstly search the global token trees, and the Keywords list, finally, it find one match "while".

So, the wrong call tip displayed.

I think the expect result that BreakUpcomponents return should be *empty* instead of a "while".
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: Some strange behaviors
« Reply #13 on: August 27, 2009, 05:44:42 am »
i think the problem can be solved by this patch too.
which one is better, still need to further discussed.
Code
Index: nativeparser.cpp
===================================================================
--- nativeparser.cpp (revision 5744)
+++ nativeparser.cpp (working copy)
@@ -1248,21 +1247,20 @@
             ++startAt;
         }
     }
-
-//    Manager::Get()->GetLogManager()->DebugLog(_T("at %d (%c): res=%s"), startAt, line.GetChar(startAt), res.c_str());
-    while ((startAt < line.Length()) && (wxIsalnum(line.GetChar(startAt)) || line.GetChar(startAt) == '_'))
+    //Manager::Get()->GetLogManager()->DebugLog(F(_T("at %d (%c): res=%s"), startAt, line.GetChar(startAt), res.c_str()));
+    while ((startAt < line.Length()) && (wxIsalnum(line.GetChar(startAt)) || line.GetChar(startAt) == '_' || line.GetChar(startAt) == ' ' || line.GetChar(startAt) == '\t'))
     {
         res << line.GetChar(startAt);
         ++startAt;
     }
-
+    res.Trim();
     while ((nest > 0) && (startAt < line.Length()))
     {
         if (line.GetChar(startAt) == ')')
             --nest;
         ++startAt;
     }
-    //Manager::Get()->GetLogManager()->DebugLog("Done nest: at %d (%c): res=%s", startAt, line.GetChar(startAt), res.c_str());
+    //Manager::Get()->GetLogManager()->DebugLog(F(_T("Done nest: at %d (%c): res=%s"), startAt, line.GetChar(startAt), res.c_str()));
 
     if ((startAt < line.Length()) && (line.GetChar(startAt) == '(' || line.GetChar(startAt) == '['))
     {
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 MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Some strange behaviors
« Reply #14 on: August 27, 2009, 08:17:51 am »
Code
Index: nativeparser.cpp
===================================================================
--- nativeparser.cpp (revision 5744)
+++ nativeparser.cpp (working copy)
@@ -1248,21 +1247,20 @@
             ++startAt;
         }
     }
-
-//    Manager::Get()->GetLogManager()->DebugLog(_T("at %d (%c): res=%s"), startAt, line.GetChar(startAt), res.c_str());
-    while ((startAt < line.Length()) && (wxIsalnum(line.GetChar(startAt)) || line.GetChar(startAt) == '_'))
+    //Manager::Get()->GetLogManager()->DebugLog(F(_T("at %d (%c): res=%s"), startAt, line.GetChar(startAt), res.c_str()));
+    while ((startAt < line.Length()) && (wxIsalnum(line.GetChar(startAt)) || line.GetChar(startAt) == '_' || line.GetChar(startAt) == ' ' || line.GetChar(startAt) == '\t'))
     {
         res << line.GetChar(startAt);
         ++startAt;
     }
-
+    res.Trim();
     while ((nest > 0) && (startAt < line.Length()))
     {
         if (line.GetChar(startAt) == ')')
             --nest;
         ++startAt;
     }
-    //Manager::Get()->GetLogManager()->DebugLog("Done nest: at %d (%c): res=%s", startAt, line.GetChar(startAt), res.c_str());
+    //Manager::Get()->GetLogManager()->DebugLog(F(_T("Done nest: at %d (%c): res=%s"), startAt, line.GetChar(startAt), res.c_str()));
 
     if ((startAt < line.Length()) && (line.GetChar(startAt) == '(' || line.GetChar(startAt) == '['))
     {
...so is this the only thing to apply and the other two modifications are obsolete?
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ