Developer forums (C::B DEVELOPMENT STRICTLY!) > CodeCompletion redesign

bug: ~XXX is always recognized as a destructor

(1/2) > >>

ollydbg:
From discussion:
Re: The 24 May 2014 build (9778) is out.


Use the git blame, I found this bug happens in this commit.


--- Code: ---Revision: 158fe092f69424861b309078741e38e7bec2c0cc
Author: loaden <loaden@2a5c6006-c6dd-42ca-98ab-0921f2732cef>
Date: 2010-11-2 21:29:18
Message:
* special handle destructor function for 'Goto declaration' and 'Goto implementation'

git-svn-id: http://svn.code.sf.net/p/codeblocks/code/trunk@6813 2a5c6006-c6dd-42ca-98ab-0921f2732cef
----
Modified: src/plugins/codecompletion/codecompletion.cpp



--- End code ---

Diff file:

--- Code: --- src/plugins/codecompletion/codecompletion.cpp | 60 ++++++++++++++++++++++-----
 1 file changed, 49 insertions(+), 11 deletions(-)

diff --git a/src/plugins/codecompletion/codecompletion.cpp b/src/plugins/codecompletion/codecompletion.cpp
index ffef317..a5071f6 100644
--- a/src/plugins/codecompletion/codecompletion.cpp
+++ b/src/plugins/codecompletion/codecompletion.cpp
@@ -645,6 +645,27 @@ void CodeCompletion::BuildMenu(wxMenuBar* menuBar)
         Manager::Get()->GetLogManager()->DebugLog(_T("Could not find Project menu!"));
 }
 
+wxChar GetLastNonWhitespaceChar(cbStyledTextCtrl* control, int position)
+{
+    if (!control)
+        return 0;
+
+    while (--position > 0)
+    {
+        const int style = control->GetStyleAt(position);
+        if (control->IsComment(style))
+            continue;
+
+        const wxChar ch = control->GetCharAt(position);
+        if (ch <= _T(' '))
+            continue;
+
+        return ch;
+    }
+
+    return 0;
+}
+
 // invariant : on return true : NameUnderCursor is NOT empty
 bool EditorHasNameUnderCursor(wxString& NameUnderCursor, bool& IsInclude)
 {
@@ -667,21 +688,14 @@ bool EditorHasNameUnderCursor(wxString& NameUnderCursor, bool& IsInclude)
         }
         else
         {
-            int start = control->WordStartPosition(pos, true);
+            const int start = control->WordStartPosition(pos, true);
             const int end = control->WordEndPosition(pos, true);
             const wxString word = control->GetTextRange(start, end);
             if (!word.IsEmpty())
             {
                 NameUnderCursor.Clear();
-                while (--start > 0)
-                {
-                    const wxChar ch = control->GetCharAt(start);
-                    if (ch <= _T(' '))
-                        continue;
-                    else if (ch == _T('~'))
-                        NameUnderCursor << _T("~");
-                    break;
-                }
+                if (GetLastNonWhitespaceChar(control, start) == _T('~'))
+                    NameUnderCursor << _T('~');
                 NameUnderCursor << word;
                 ReturnValue = true;
                 IsInclude = false;
@@ -2573,7 +2587,12 @@ void CodeCompletion::OnGotoDeclaration(wxCommandEvent& event)
     const int pos = editor->GetControl()->GetCurrentPos();
     const int start = editor->GetControl()->WordStartPosition(pos, true);
     const int end = editor->GetControl()->WordEndPosition(pos, true);
-    const wxString target = editor->GetControl()->GetTextRange(start, end);
+    wxString target;
+    if (GetLastNonWhitespaceChar(editor->GetControl(), start) == _T('~'))
+        target << _T('~');
+    target << editor->GetControl()->GetTextRange(start, end);
+    if (target.IsEmpty())
+        return;
 
     // prepare a boolean filter for declaration/implementation
     bool isDecl = event.GetId() == idGotoDeclaration || event.GetId() == idMenuGotoDeclaration;
@@ -2583,6 +2602,25 @@ void CodeCompletion::OnGotoDeclaration(wxCommandEvent& event)
     TokenIdxSet result;
     m_NativeParser.MarkItemsByAI(result, true, false, true, end);
 
+    // special handle destructor function
+    if (target[0] == _T('~'))
+    {
+        TokenIdxSet tmp = result;
+        result.clear();
+
+        TokensTree* tokens = m_NativeParser.GetParser().GetTokens();
+        for (TokenIdxSet::iterator it = tmp.begin(); it != tmp.end(); ++it)
+        {
+            Token* tk = tokens->at(*it);
+            if (tk && tk->m_TokenKind == tkClass)
+            {
+                tk = tokens->at(tokens->TokenExists(target, tk->GetSelf(), tkDestructor));
+                if (tk)
+                    result.insert(tk->GetSelf());
+            }
+        }
+    }
+
     // one match
     Token* token = NULL;
     if (result.size() == 1)


--- End code ---

Issue:

--- Code: ---+    if (GetLastNonWhitespaceChar(editor->GetControl(), start) == _T('~'))
+        target << _T('~');

--- End code ---
Maybe, this is the bug.

damorin:
Hi,

sounds exactly like it.

Adding a check for C++ project (or file) should be enough to fix it.

ollydbg:

--- Quote from: damorin on June 11, 2014, 07:11:42 pm ---Hi,

sounds exactly like it.

Adding a check for C++ project (or file) should be enough to fix it.



--- End quote ---
Hi, ~ can either be logic operator or the destructor prefix, so, why do you think adding a check for C++ project can solve this?

damorin:

--- Quote from: ollydbg on June 12, 2014, 06:18:50 am ---
--- Quote from: damorin on June 11, 2014, 07:11:42 pm ---Hi,

sounds exactly like it.

Adding a check for C++ project (or file) should be enough to fix it.



--- End quote ---
Hi, ~ can either be logic operator or the destructor prefix, so, why do you think adding a check for C++ project can solve this?

--- End quote ---

Oops, that would only fix it in C but the problem would remain in C++. It's not that good then unless there is a check to see if it's a destructor or not.



Huki:

--- Quote from: ollydbg on June 11, 2014, 03:47:08 am ---From discussion:
Re: The 24 May 2014 build (9778) is out.

Use the git blame, I found this bug happens in this commit.

...


--- End quote ---

Hi,
Have to remind you that I posted a patch for this one several weeks ago. :) See here.

Navigation

[0] Message Index

[#] Next page

Go to full version