Author Topic: CC bug: show "lass" in find implementation  (Read 16924 times)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
CC bug: show "lass" in find implementation
« on: April 05, 2013, 05:13:49 pm »

Look at the screen shot above, I see a "lass", I think it's a bug.
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: CC bug: show "lass" in find implementation
« Reply #1 on: April 05, 2013, 05:21:02 pm »
Look at the screen shot above, I see a "lass", I think it's a bug.

Maybe a new widley unknown token in C++  ;) ?

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: CC bug: show "lass" in find implementation
« Reply #2 on: April 05, 2013, 05:24:39 pm »
Look at the screen shot above, I see a "lass", I think it's a bug.

Maybe a new widley unknown token in C++  ;) ?

I guess it is a "class", but I don't know why the first char "c" is missing.
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: CC bug: show "lass" in find implementation
« Reply #3 on: April 05, 2013, 06:20:40 pm »
Look at the screen shot above, I see a "lass", I think it's a bug.

Maybe a new widley unknown token in C++  ;) ?

I guess it is a "class", but I don't know why the first char "c" is missing.
Adding a space before the class-keyword makes it works correctly, if I hover over UserVariableManager in uservarmanager.h: it shows the class and the two constructors.

By the way, "Find implementation" from inside manager.cpp (as on your screenshot) does not work for me at all (fedora 18 64-bit with C::B 8938 from my repo).

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: CC bug: show "lass" in find implementation
« Reply #4 on: April 05, 2013, 08:29:49 pm »
This is happening for a long time. I've even seen the second row repeated multiple times.
Hope you fix it Ollydbg, because it is annoying a bit. :)
(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!]

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: CC bug: show "lass" in find implementation
« Reply #5 on: April 06, 2013, 07:30:10 pm »
Maybe related:

... Unequal? ;)

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: CC bug: show "lass" in find implementation
« Reply #6 on: April 06, 2013, 09:02:21 pm »
Maybe related:
[...]
... Unequal? ;)
Mmmmh... I recall I had fixed this in trunk some times back. It may got re-introduced.
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: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: CC bug: show "lass" in find implementation
« Reply #7 on: May 13, 2013, 05:53:50 am »
Debug for a while, I found that the function:
Code
bool NativeParser::ParseLocalBlock(ccSearchData* searchData, TokenIdxSet& search_scope, int caretPos)
{
    if (s_DebugSmartSense)
        CCLogger::Get()->DebugLog(_T("ParseLocalBlock() Parse local block"));
    TRACE(_T("NativeParser::ParseLocalBlock()"));

    int parentIdx = -1;
    int blockStart = FindCurrentFunctionStart(searchData, nullptr, nullptr, &parentIdx, caretPos);
    int initLine = 0;
    if (parentIdx != -1)
    {
        TokenTree* tree = m_Parser->GetTokenTree();

        CC_LOCKER_TRACK_TT_MTX_LOCK(s_TokenTreeMutex)

        const Token* parent = tree->at(parentIdx);
        if (parent && (parent->m_TokenKind & tkAnyFunction))
        {
            m_LastFuncTokenIdx = parent->m_Index;
            initLine = parent->m_ImplLineStart;
        }

        CC_LOCKER_TRACK_TT_MTX_UNLOCK(s_TokenTreeMutex)

        if (!parent)
            return false;
    }

    if (blockStart != -1)
    {
        ++blockStart; // skip {
        cbStyledTextCtrl* stc = searchData->control;
        const int pos         = (caretPos == -1 ? stc->GetCurrentPos() : caretPos);
        const int line        = stc->LineFromPosition(pos);
        const int blockEnd    = stc->GetLineEndPosition(line);
        if (blockEnd < 0 || blockEnd > stc->GetLength())
        {
            if (s_DebugSmartSense)
            {
                CCLogger::Get()->DebugLog(F(_T("ParseLocalBlock() ERROR blockEnd=%d and edLength=%d?!"),
                                            blockEnd, stc->GetLength()));
            }
            return false;
        }

        if (blockStart >= blockEnd)
            blockStart = blockEnd;

//        wxString buffer = searchData->control->GetTextRange(blockStart, blockEnd);
        wxString buffer;
        // condense out-of-scope braces {...}
        int scanPos = blockEnd;
        for (int curPos = pos; curPos > blockStart; --curPos)
        {
            if (stc->GetCharAt(curPos) != wxT('}'))
                continue;
            const int style = stc->GetStyleAt(curPos);
            if (   stc->IsString(style)
                || stc->IsCharacter(style)
                || stc->IsComment(style))
            {
                continue;
            }
            const int scopeStart = stc->BraceMatch(curPos);
            if (scopeStart < blockStart)
                break;
            buffer.Prepend(stc->GetTextRange(curPos, scanPos));
            int startLn = stc->LineFromPosition(scopeStart);
            int endLn   = stc->LineFromPosition(curPos);
            if (startLn < endLn) // maintain correct line numbers for parsed tokens
                buffer.Prepend( wxString(wxT('\n'), endLn - startLn) );
            scanPos = scopeStart + 1;
            curPos  = scopeStart;

            // condense out-of-scope for/if/while declarations
            int prevCharIdx = scopeStart - 1;
            for (; prevCharIdx > blockStart; --prevCharIdx)
            {
                if (stc->IsComment(stc->GetStyleAt(prevCharIdx)))
                    continue;
                if (!wxIsspace(stc->GetCharAt(prevCharIdx)))
                    break;
            }
            if (stc->GetCharAt(prevCharIdx) != wxT(')'))
                continue;
            const int paramStart = stc->BraceMatch(prevCharIdx);
            if (paramStart < blockStart)
                continue;
            for (prevCharIdx = paramStart - 1; prevCharIdx > blockStart; --prevCharIdx)
            {
                if (stc->IsComment(stc->GetStyleAt(prevCharIdx)))
                    continue;
                if (!wxIsspace(stc->GetCharAt(prevCharIdx)))
                    break;
            }
            const wxString text = stc->GetTextRange(stc->WordStartPosition(prevCharIdx, true),
                                                    stc->WordEndPosition(  prevCharIdx, true));
            if (text == wxT("for"))
                buffer.Prepend(wxT("(;;){"));
            else if (text == wxT("if") || text == wxT("while"))
                buffer.Prepend(wxT("(0){"));
            else
                continue;
            startLn = stc->LineFromPosition(prevCharIdx);
            endLn   = stc->LineFromPosition(scopeStart);
            if (startLn < endLn)
                buffer.Prepend( wxString(wxT('\n'), endLn - startLn) );
            curPos  = stc->WordStartPosition(prevCharIdx, true);
            scanPos = stc->WordEndPosition(  prevCharIdx, true);
        }
        buffer.Prepend(stc->GetTextRange(blockStart, scanPos));

        buffer.Trim();

The "buffer" is start with "lass". ???

EDIT
Oh, I see the code
Code
    if (blockStart != -1)
    {
        ++blockStart; // skip {
But apparently, it was not "{", so the "c" of "class" was removed.
« Last Edit: May 13, 2013, 05:59:32 am 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 ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: CC bug: show "lass" in find implementation
« Reply #8 on: May 13, 2013, 07:05:00 am »
Code
Index: E:/code/cb/cb_trunk_sf/src/plugins/codecompletion/nativeparser.cpp
===================================================================
--- E:/code/cb/cb_trunk_sf/src/plugins/codecompletion/nativeparser.cpp (revision 9090)
+++ E:/code/cb/cb_trunk_sf/src/plugins/codecompletion/nativeparser.cpp (working copy)
@@ -1857,8 +1857,9 @@
 
     if (blockStart != -1)
     {
-        ++blockStart; // skip {
         cbStyledTextCtrl* stc = searchData->control;
+        if (stc->GetCharAt(blockStart) == wxT('{'))
+            ++blockStart; // skip { if we are in a function body
         const int pos         = (caretPos == -1 ? stc->GetCurrentPos() : caretPos);
         const int line        = stc->LineFromPosition(pos);
         const int blockEnd    = stc->GetLineEndPosition(line);
The patch above should fix this bug.
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: CC bug: show "lass" in find implementation
« Reply #9 on: May 13, 2013, 08:48:09 pm »
The patch above should fix this bug.
Nice catch!
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: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: CC bug: show "lass" in find implementation
« Reply #10 on: May 14, 2013, 05:28:44 am »
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.