Author Topic: New code completion remarks/issues  (Read 211970 times)

Offline mmkider

  • Almost regular
  • **
  • Posts: 150
Re: New code completion remarks/issues
« Reply #60 on: September 28, 2009, 08:39:13 am »
I Found a crash, See picture.
At last, I need keyin '\n' but I keyin '\'. it will crash.


I can't reproduce the crash when entering only one statements, can you give a simple testing code?

Code
static wxRegEx rePrint(_T("^(@_@)(.*)"));
void  Test_CodeCompletion()
{
static wxString buffer;
wxArrayString lines = GetArrayFromString(buffer, _T('\n'));
bool bMatch=false;
for (unsigned int i = 0; i < lines.GetCount(); ++i)
{
if (rePrint.Matches(lines[i]))
{

lines[i]=_T("");
bMatch=true;
}
}
if(bMatch)
{
buffer.clear();
for (unsigned int i = 0; i < lines.GetCount(); ++i)
{
if(lines[i]!=_T(""))
{
buffer+=lines[i]+_T("\n"); // this line will be crash.
}
}
}
        return; // come back later
}

Step 1: keyin "buffer"
Step 2: keyin "+"
Step 3: keyin "="
Step 4: keyin "lines"
Step 5: keyin "["
Step 6: keyin "]"
Step 7: keyin "i"
Step 8: keyin "+"
Step 9: keyin "_"
Step 10: keyin "T"
Step 11: keyin "()"
Step 12: keyin "\"\""
Step 13: keyin "\\"  => crash
« Last Edit: September 28, 2009, 08:44:19 am by mmkider »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: New code completion remarks/issues
« Reply #61 on: September 28, 2009, 08:49:50 am »
I follow you steps, but still can't reproduce this crash.

By the way, if you enter these statement:

Code
buffer+=lines[i]+_T("\");

You will notice that the open brace and the close brace have the different colors. I guess this is caused by Scintilla gramma highlight.
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 mmkider

  • Almost regular
  • **
  • Posts: 150
Re: New code completion remarks/issues
« Reply #62 on: September 28, 2009, 08:56:07 am »
I follow you steps, but still can't reproduce this crash.

By the way, if you enter these statement:

Code
buffer+=lines[i]+_T("\");

You will notice that the open brace and the close brace have the different colors. I guess this is caused by Scintilla gramma highlight.
you need create project from  wx project template.
I try this function in the normal C++ project, it will run fine.
But I try this function in the wx project, it still give me  a crash after Popup "(x)".

« Last Edit: September 28, 2009, 08:59:51 am by mmkider »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: New code completion remarks/issues
« Reply #63 on: September 28, 2009, 09:09:14 am »
@mmkider
I just create a wx project by wizard, and still can't reproduce crash.
In my test, I have no completion list like "(x)".

Which version of codeblocks did you use? For me, I use latest svn + my own patch. :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.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: New code completion remarks/issues
« Reply #64 on: September 28, 2009, 09:16:15 am »
I can more or less confirm this crash on linux.
It does not crash, but it hangs and eats 100 % of one of my CPU's.

Latest svn-source.
I will look into it.

Offline mmkider

  • Almost regular
  • **
  • Posts: 150
Re: New code completion remarks/issues
« Reply #65 on: September 28, 2009, 09:19:10 am »
I can more or less confirm this crash on linux.
It does not crash, but it hangs and eats 100 % of one of my CPU's.

Latest svn-source.
I will look into it.
Cool.  :D

I get 100 % of one of my CPU's too, and my codeblocks can not respond to any key.


Offline blueshake

  • Regular
  • ***
  • Posts: 459
Re: New code completion remarks/issues
« Reply #66 on: September 28, 2009, 10:12:33 am »
Quote
This bug is fixed by this patch
does it work for codes like these?
Code
#include <iostream>

using namespace std;
struct qq
{
    int x;
    int y;
};
struct qq tt;
struct qq& xx = tt;
xx.
int main()
{
    cout << "Hello world!" << endl;
    return 0;
}



EDIT:
And the issue in this thread seems not solved yet.http://forums.codeblocks.org/index.php/topic,10966.msg74954.html#msg74954
« Last Edit: September 28, 2009, 10:27:25 am by 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?

Offline blueshake

  • Regular
  • ***
  • Posts: 459
Re: New code completion remarks/issues
« Reply #67 on: September 28, 2009, 10:18:25 am »
Quote
I get 100 % of one of my CPU's too, and my codeblocks can not respond to any key.
I have this issue too.The programe hang,but 50% of CPU used.

EDIT:
It seems that (x) tip cause this.
« Last Edit: September 28, 2009, 10:21:41 am by 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?

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: New code completion remarks/issues
« Reply #68 on: September 28, 2009, 10:32:24 am »
I can more or less confirm this crash on linux.
It does not crash, but it hangs and eats 100 % of one of my CPU's.

Latest svn-source.
I will look into it.
Cool.  :D

I get 100 % of one of my CPU's too, and my codeblocks can not respond to any key.



Should be fixed in svn r5825.

By the way:
we should have a look at all occurrences of MoveToNextChar(), because testing for EOF does not make sense after this function. At EOF it returns false and sets the token-index to bufferlen (this was the cause for the endless-loop in this case).


Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: New code completion remarks/issues
« Reply #69 on: September 28, 2009, 10:37:13 am »
Quote
I get 100 % of one of my CPU's too, and my codeblocks can not respond to any key.
I have this issue too.The programe hang,but 50% of CPU used.

EDIT:
It seems that (x) tip cause this.

That's partly correct, the issue does not occur, if I cancel the (x)-tip with escape, but it hangs in in SkipToOneOfChars() because we never reach EOF and so never break out of the while-loop.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: New code completion remarks/issues
« Reply #70 on: September 28, 2009, 10:39:05 am »
Quote
This bug is fixed by this patch
does it work for codes like these?
Code
#include <iostream>

using namespace std;
struct qq
{
    int x;
    int y;
};
struct qq tt;
struct qq& xx = tt;
xx.
int main()
{
    cout << "Hello world!" << endl;
    return 0;
}

Not yet, but the statement below are nearly the same. so, it can be easily fixed.

Code
struct qq * xx
struct qq & xx

Here is my modified path, it works ok for both struct reference and pointer .

Code
Index: parserthread.cpp
===================================================================
--- parserthread.cpp (revision 5824)
+++ parserthread.cpp (working copy)
@@ -1350,8 +1350,13 @@
                 HandleFunction(current);
                 break;
             }
-            else if (next.GetChar(0) != '*')
+            else if (next.GetChar(0) == '*' || next.GetChar(0) == '&' )
             {
+                m_Str<<current;
+                break;
+            }
+            else
+            {
                 // might be instantiation, see the following
                 /*
                 struct HiddenStruct {
@@ -1391,8 +1396,7 @@
                     }
                 }
             }
-            else
-                m_Tokenizer.GetToken();
+
         }
         else
             break;



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: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: New code completion remarks/issues
« Reply #71 on: September 29, 2009, 10:37:11 am »
EDIT:
And the issue in this thread seems not solved yet.http://forums.codeblocks.org/index.php/topic,10966.msg74954.html#msg74954

Yes, this issue still exist when enter

Code
while ().

This is because a left search start from the "." will skip the brace pair, and find "while" as the first token.

But it is strange, it seems the right search starting from "w" give the wrong token length. I will look into it.
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: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: New code completion remarks/issues
« Reply #72 on: September 29, 2009, 11:07:14 am »
This is the modified version of the "right search", it just solve this problem in my previous reply.

Code
wxString NativeParser::GetNextCCToken(const wxString& line, unsigned int& startAt, bool& is_function)
{
    wxString res;
    int nest = 0;
    if ((startAt < line.Length()) && (line.GetChar(startAt) == '('))
    {
        while (startAt < line.Length() &&
                (line.GetChar(startAt) == '*' ||
                line.GetChar(startAt) == '&' ||
                line.GetChar(startAt) == '('))
        {
            if (line.GetChar(startAt) == '(')
                ++nest;
            ++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) == '_'))
    {
        res << line.GetChar(startAt);
        ++startAt;
    }
    while ((nest > 0) && (startAt < line.Length()))
    {
        if (line.GetChar(startAt) == ')')
            --nest;
        ++startAt;
    }
    //Manager::Get()->GetLogManager()->DebugLog(F(_T("Done nest: at %d (%c): res=%s"), startAt, line.GetChar(startAt), res.c_str()));
    while (startAt < line.Length()-1&& (line.GetChar(startAt) == ' ' || line.GetChar(startAt) == '\t'))
        ++startAt;
    if ((startAt < line.Length()) && (line.GetChar(startAt) == '(' || line.GetChar(startAt) == '['))
    {
        is_function = line.GetChar(startAt) == '(';

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

                case '[':
                case '(': ++nest; ++startAt;break;
            }
            while (startAt < line.Length()-1&& (line.GetChar(startAt) == ' ' || line.GetChar(startAt) == '\t'))
                        ++startAt;
            if (startAt < line.Length()-1 && (line.GetChar(startAt) == '(' || line.GetChar(startAt) == '['))
                        ++nest;
        }
        //++startAt;

    }

    //Manager::Get()->GetLogManager()->DebugLog("Return at %d (%c): res=%s", startAt, line.GetChar(startAt), res.c_str());
    return res;
}


Note, I just add a while statement to skip the spaces between "while" and "()".

Code
    while (startAt < line.Length()-1&& (line.GetChar(startAt) == ' ' || line.GetChar(startAt) == '\t'))
        ++startAt;

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 MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: New code completion remarks/issues
« Reply #73 on: September 29, 2009, 05:51:50 pm »
This is the modified version of the "right search", it just solve this problem in my previous reply.
Committed that to trunk (including some other mods). Hence some cases still do not work, check this snippet:
Code
struct _s
{
  int   x;
  float y;
};
typedef struct _s t_s;

int main()
{
    struct _s  s;
    struct _s& rs = s;
    struct _s* ps = &s;
    t_s        ts;
    t_s&       rts = ts;
    t_s*       pts = &ts;

    s.    // works
    rs.   // works
    ps.   // works
    ps->  // does not work
    ts.   // works
    rts.  // works
    pts.  // works
    pts-> // does not work

    return 0;
}
For ps and pts CC suggests... erm... ps and pts.
Probably I am missing something... it's late... ;-)
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 oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: New code completion remarks/issues
« Reply #74 on: September 29, 2009, 07:38:16 pm »
By the way are there any plans to enable the first combo box in the CC toolbar?
If yes, what needs to be done?
(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!]