Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => CodeCompletion redesign => Topic started by: ollydbg on April 05, 2013, 05:13:49 PM

Title: CC bug: show "lass" in find implementation
Post by: ollydbg on April 05, 2013, 05:13:49 PM
(http://i.imgur.com/tm6zVPh.png)
Look at the screen shot above, I see a "lass", I think it's a bug.
Title: Re: CC bug: show "lass" in find implementation
Post by: Jenna on April 05, 2013, 05:21:02 PM
Quote from: ollydbg on April 05, 2013, 05:13:49 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++  ;) ?
Title: Re: CC bug: show "lass" in find implementation
Post by: ollydbg on April 05, 2013, 05:24:39 PM
Quote from: jens on April 05, 2013, 05:21:02 PM
Quote from: ollydbg on April 05, 2013, 05:13:49 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.
Title: Re: CC bug: show "lass" in find implementation
Post by: Jenna on April 05, 2013, 06:20:40 PM
Quote from: ollydbg on April 05, 2013, 05:24:39 PM
Quote from: jens on April 05, 2013, 05:21:02 PM
Quote from: ollydbg on April 05, 2013, 05:13:49 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).
Title: Re: CC bug: show "lass" in find implementation
Post by: oBFusCATed 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. :)
Title: Re: CC bug: show "lass" in find implementation
Post by: Alpha on April 06, 2013, 07:30:10 PM
Maybe related:
(http://www.pasteall.org/pic/show.php?id=48732)
... Unequal? ;)
Title: Re: CC bug: show "lass" in find implementation
Post by: MortenMacFly on April 06, 2013, 09:02:21 PM
Quote from: Alpha on April 06, 2013, 07:30:10 PM
Maybe related:
[...]
... Unequal? ;)
Mmmmh... I recall I had fixed this in trunk some times back. It may got re-introduced.
Title: Re: CC bug: show "lass" in find implementation
Post by: ollydbg on May 13, 2013, 05:53:50 AM
Debug for a while, I found that the function:

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

   if (blockStart != -1)
   {
       ++blockStart; // skip {

But apparently, it was not "{", so the "c" of "class" was removed.
Title: Re: CC bug: show "lass" in find implementation
Post by: ollydbg on May 13, 2013, 07:05:00 AM

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.
Title: Re: CC bug: show "lass" in find implementation
Post by: MortenMacFly on May 13, 2013, 08:48:09 PM
Quote from: ollydbg on May 13, 2013, 07:05:00 AM
The patch above should fix this bug.
Nice catch!
Title: Re: CC bug: show "lass" in find implementation
Post by: ollydbg on May 14, 2013, 05:28:44 AM
Quote from: MortenMacFly on May 13, 2013, 08:48:09 PM
Quote from: ollydbg on May 13, 2013, 07:05:00 AM
The patch above should fix this bug.
Nice catch!
Commit in rev9094.