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

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5519
Re: New code completion remarks/issues
« Reply #75 on: September 29, 2009, 08:36:39 pm »
the intended purpose of the first combo box, is that you can filter on what you want to see in the right combo box.

For example you filter on a namespace,  class, a class in a namespace.

Basically, my idea was inspired about how it works in M$ Visual Studio.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: New code completion remarks/issues
« Reply #76 on: September 29, 2009, 11:23:36 pm »
I know the purpose of the combo,
but at the moment it is disabled and useless (wasting lots of gui-estate(place or something)).

By the way one combo with autocompletion/filtering (visual assist style) is better than two (visual c++ style).
Because it requires less actions to find what you want. But I think the combo in wx2.x can't do autocompletion easily :(

My question was, if you plan to make it work, though?
(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 killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5519
Re: New code completion remarks/issues
« Reply #77 on: September 29, 2009, 11:42:31 pm »
Back in the day I could not activate it yet, since the parser was not good enough.
Now it however still has some informative use : it shows the namespace::class, where the right hand side combobox only show the method names (+ arguments + return value) which it should.

But I think the left combobox could be reduced by half in width.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6035
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: New code completion remarks/issues
« Reply #78 on: September 30, 2009, 04:11:20 am »
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... ;-)


This bug can be fixed by this patch:

Code
Index: nativeparser.cpp
===================================================================
--- nativeparser.cpp (revision 5826)
+++ nativeparser.cpp (working copy)
@@ -1207,7 +1207,7 @@
         --startAt;
     return startAt;
 }
-static bool IsOperator(int startAt, const wxString& line)
+static bool IsOperatorEnd(int startAt, const wxString& line)
 {
     return (   (startAt > 0)
             && (startAt < line.Length())
@@ -1216,6 +1216,17 @@
                 || (   (line.GetChar(startAt) == ':')
                     && (line.GetChar(startAt - 1) == ':') ) ) );
 }
+
+static bool IsOperatorBegin(int startAt, const wxString& line)
+{
+    return (   (startAt > 0)
+            && (startAt + 1< line.Length())
+            && (   (   (line.GetChar(startAt ) == '-') )
+                    && (line.GetChar(startAt + 1) == '>')
+                || (   (line.GetChar(startAt) == ':')
+                    && (line.GetChar(startAt + 1) == ':') ) ) );
+}
+
 static bool IsOperatorDot(int startAt, const wxString& line)
 {
     return (   (startAt >= 0)
@@ -1274,7 +1285,7 @@
         }
         // Check for [Class]-> ('>' pressed)
         // Check for [Class]:: (':' pressed)
-        else if (IsOperator(startAt, line))
+        else if (IsOperatorEnd(startAt, line))
         {
             startAt -= 2;
             repeat = true; // yes -> repeat.
@@ -1394,7 +1405,10 @@
                 ++nest;
         }
     }
+    if (IsOperatorBegin(startAt, line))
+        ++startAt;
 
+
 #if DEBUG_CC_AI
     Manager::Get()->GetLogManager()->DebugLog(F(_T("Return at %d (%c): res=%s"), startAt, line.GetChar(startAt), res.c_str()));
 #endif
@@ -1446,7 +1460,7 @@
         }
         // Check for [Class]-> ('>' pressed)
         // Check for [Class]:: (':' pressed)
-        else if (IsOperator(startAt, line))
+        else if (IsOperatorEnd(startAt, line))
         {
             if (line.GetChar(startAt) == ':')
                 tokenType = pttNamespace;

Note: for checking IsOperator, we need to check whether "it is the beginning of the operator?" or "the end of the operator", because sometimes, we use a "left search" and sometimes we need a "right search".
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: 458
Re: New code completion remarks/issues
« Reply #79 on: October 02, 2009, 08:51:14 am »
May someboby notice that the cc suggestion list window style is different from the notepad++ whose window
stytle is something like pop menu.So if I want to change the cc suggestion list window style to make it similar with notepad++'s,what should I do?(change what codes, I read the codes,found nothing)
any comment? Thanks!
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: 6035
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: New code completion remarks/issues
« Reply #80 on: October 03, 2009, 09:03:28 am »
I find another issue in the current cc.

If you open the "plugins\debuggergdb\gdb_commands.h"

You will notice that in the CC's toolbar, only one function (wxStrHexTo) is listed. it seems the parser failed parsing this file.  :(

I haven't found the reason....
« Last Edit: October 03, 2009, 09:29:59 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: 6035
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: New code completion remarks/issues
« Reply #81 on: October 03, 2009, 10:18:08 am »
hi, all.

It seems the parser failed parsing this statement in the gdb_commands.h. (comment this statement can let the parser works ok :D)

Code
static wxRegEx rePendingBreakpoint(_T("Breakpoint ([0-9]+)[ \\t]\\(\\\"(.+):([0-9]+)\\)[ \\t]pending\\."));
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: 6035
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: New code completion remarks/issues
« Reply #82 on: October 03, 2009, 03:20:29 pm »
May someboby notice that the cc suggestion list window style is different from the notepad++ whose window
stytle is something like pop menu.So if I want to change the cc suggestion list window style to make it similar with notepad++'s,what should I do?(change what codes, I read the codes,found nothing)
any comment? Thanks!

I compare the suggestion list window style of notepad++ 5.4 and codeblocks trunk. They are nearly the same. :D

Can you supply a screenshot that their windows are different??
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: 6035
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: New code completion remarks/issues
« Reply #83 on: October 03, 2009, 03:53:23 pm »
hi, all.

It seems the parser failed parsing this statement in the gdb_commands.h. (comment this statement can let the parser works ok :D)

Code
static wxRegEx rePendingBreakpoint(_T("Breakpoint ([0-9]+)[ \\t]\\(\\\"(.+):([0-9]+)\\)[ \\t]pending\\."));

One catch: it seems the parser failed parsing statement below:

Code
char * aaa = "\\\"";


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: 6035
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: New code completion remarks/issues
« Reply #84 on: October 04, 2009, 01:37:05 am »
The problem is located in this function in Tokenizer.cpp
Code
bool Tokenizer::SkipToCharBreak()
{
  if (PreviousChar() != '\\')
      return true;
  else
  {
      // check for "\\"
      if (   ((m_TokenIndex - 2) >= 0)
          && ((m_TokenIndex - 2) <= m_BufferLen)
          && (m_Buffer.GetChar(m_TokenIndex - 2) == '\\') )
          return true;
  }
  return false;
}

The main task of this function is try to check the current char is in a "C escape character".

For example, in the statement below:

Code
char * aaa = "\\\"";

There are three quots in the statement above. the first quot and third quot is the start and the end of a C string definition. But the second quot is after a back slash \, is part of an escape character.

The parser starts the search from the first quot, and try to find the end of the C string. When it meets the second quot, This function try to check whether the second quot is the end of the C string.

But this function mistakenly regard the second quot as the end of the C string.

Also, this function checks several characters before the second quot, but that's not enough. In this statement
Code
"\\\""
, the first two back slash
Code
\\
is an escape character, and the third and forth
Code
\"
groups another escape character.

So, how about parsing this statement?
Code
"\\\\\""
or
"\\\\\\\""

I think we should left search from the second quot and count the back slash number until we meet the first non-back-slash char. and check the number is odd or even. :D

Any comments?
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: 6035
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: New code completion remarks/issues
« Reply #85 on: October 04, 2009, 02:32:12 am »
here is the patch to solve this problem. :D

Code
Index: tokenizer.cpp
===================================================================
--- tokenizer.cpp (revision 5834)
+++ tokenizer.cpp (working copy)
@@ -216,17 +216,22 @@
 
 bool Tokenizer::SkipToCharBreak()
 {
-  if (PreviousChar() != '\\')
-      return true;
-  else
-  {
-      // check for "\\"
-      if (   ((m_TokenIndex - 2) >= 0)
-          && ((m_TokenIndex - 2) <= m_BufferLen)
-          && (m_Buffer.GetChar(m_TokenIndex - 2) == '\\') )
-          return true;
-  }
-  return false;
+    if (PreviousChar() != '\\')
+        return true;
+    else
+    {
+        // check for "\\"
+        unsigned int numBackslash = 2;
+        while(   ((m_TokenIndex - numBackslash) >= 0)
+            && ((m_TokenIndex - numBackslash) <= m_BufferLen)
+            && (m_Buffer.GetChar(m_TokenIndex - numBackslash) == '\\') )
+            ++numBackslash;
+        if(numBackslash%2==1) // number of back slash(include current char ) is even
+            return true;     // eg: "\""
+        else
+            return false;    // eg: "\\""
+    }
+    return false;
 }


@ marton

I think the function name "SkipToCharBreak" is confusion, because it doesn't really do a skip.

So, I suggest using another name like :  IsRealCharBreak or IsCharBreak or IsEscapeChar

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 blueshake

  • Regular
  • ***
  • Posts: 458
Re: New code completion remarks/issues
« Reply #86 on: October 04, 2009, 05:58:58 am »
Because my slow Internet,it seems a lot of messages were not caughted. :D
In this threadhttp://forums.codeblocks.org/index.php/topic,10990.msg75079.html#msg75079,the patch I provide is some kind of mistake.So please change it back.I test the codes,it can work under tktypedef,there are so many codes connect with tktypedef,it is risky to do this (apply this patch.)Thanks.
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: 6035
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: New code completion remarks/issues
« Reply #87 on: October 04, 2009, 06:42:31 am »
Because my slow Internet,it seems a lot of messages were not caughted. :D
In this threadhttp://forums.codeblocks.org/index.php/topic,10990.msg75079.html#msg75079,the patch I provide is some kind of mistake.So please change it back.I test the codes,it can work under tktypedef,there are so many codes connect with tktypedef,it is risky to do this (apply this patch.)Thanks.

hi, blueshake. Here is the test code

Code
class sStruct
{
  SomeClass* some_class;
  int some_int;
  void* some_void;
};
typedef class sStruct tStruct;

int main()
{
    tStruct pp;
    pp.
    cout << "Hello world!" << endl;
    return 0;
}

And In my working copy of trunk, code completion works after "pp.".
Why do you want to reverse your patch?

You mean the patch below should be reversed?
Code
Index: parserthread.cpp
===================================================================
--- parserthread.cpp (revision 5730)
+++ parserthread.cpp (working copy)


@@ -1707,15 +1737,60 @@
 #if PARSER_DEBUG_OUTPUT
     Manager::Get()->GetLogManager()->DebugLog(F(_("Adding typedef: name='%s', ancestor='%s'"), components.front().c_str(), ancestor.c_str()));
 #endif
-    Token* tdef = DoAddToken(tkTypedef, components.front(), lineNr, 0, 0, args);

+    Token* tdef = DoAddToken(tkClass, components.front(), lineNr, 0, 0, args);


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: 458
Re: New code completion remarks/issues
« Reply #88 on: October 04, 2009, 06:55:22 am »
@ollydbg
The test codes work well under tktypedef now.But it did not work before.Maybe some bugs have been fixeed.The reason I want to change it back to tktypedef is that there are some codes are connected with tktypedef.For example:In the nativeparser.cpp
Code
    if (local_result.size() == 1)
    {
        int id = *local_result.begin();
        Token* token = tree->at(id);

        if (token->m_TokenKind == tkTypedef)
        {
            std::queue<ParserComponent> type_components;
            BreakUpComponents(parser, token->m_ActualType, type_components);

            while(!components.empty())
            {
                ParserComponent comp = components.front();
                components.pop();
                type_components.push(comp);
            }

    #ifdef DEBUG_CC_AI
            if (s_DebugSmartSense)
            #if wxCHECK_VERSION(2, 9, 0)
                Manager::Get()->GetLogManager()->DebugLog(F(_T("Replacing %s to %s"), token->m_Name.wx_str(), token->m_ActualType.wx_str()));
            #else
                Manager::Get()->GetLogManager()->DebugLog(F(_T("Replacing %s to %s"), token->m_Name.c_str(), token->m_ActualType.c_str()));
            #endif
    #endif
            return FindAIMatches(parser, type_components, result, parentTokenIdx, noPartialMatch, caseSensitive, use_inheritance, kindMask, search_scope);
        }

    }

I think it is too risky to  change tktypedef to tkclass. :D
« Last Edit: October 04, 2009, 07:00:12 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: 458
Re: New code completion remarks/issues
« Reply #89 on: October 04, 2009, 07:27:19 am »
Ok, tiny fixed with ReadClsNames in parserthread.
for broken codes below:
Quote
#include <iostream>

using namespace std;
typedef class qq
{
    int x;
    int y;

}xx
int main()
{
    cout << "Hello world!" << endl;
    return 0;
}

before : the parser will regard xx, int ,main as class.
now: only the main (refer to visual assist ,this is what it do).So I think it will be a better way to do this.
patch:
Code
Index: src/plugins/codecompletion/parser/parserthread.cpp
===================================================================
--- src/plugins/codecompletion/parser/parserthread.cpp (revision 5825)
+++ src/plugins/codecompletion/parser/parserthread.cpp (working copy)
@@ -1768,7 +1768,7 @@
     Manager::Get()->GetLogManager()->DebugLog(F(_("HandleTypedef() : Adding typedef: name='%s', ancestor='%s'"), components.front().c_str(), ancestor.c_str()));
 #endif
 //    Token* tdef = DoAddToken(tkTypedef, components.front(), lineNr, 0, 0, args);
-    Token* tdef = DoAddToken(tkClass, components.front(), lineNr, 0, 0, args);
+    Token* tdef = DoAddToken(tkTypedef, components.front(), lineNr, 0, 0, args);
     if (tdef)
     {
         if (!is_function_pointer)
@@ -1796,7 +1796,7 @@
                 m_Tokenizer.UngetToken();
                 break;
             }
-        else if (wxIsalpha(current.GetChar(0)))
+        else if (wxIsalpha(current.GetChar(0)) && (m_Tokenizer.PeekToken() == ParserConsts::semicolon || m_Tokenizer.PeekToken() == ParserConsts::comma))
         {
 #if PARSERTHREAD_DEBUG_OUTPUT
             Manager::Get()->GetLogManager()->DebugLog(F(_T("ReadClsNames() : Adding variable '%s' as '%s' to '%s'"), current.c_str(), m_Str.c_str(), (m_pLastParent?m_pLastParent->m_Name.c_str():_T("<no-parent>"))));
@@ -1811,7 +1811,10 @@
             }
 
         }
-        else // unexpected
+        else// unexpected
+        {
+            m_Tokenizer.UngetToken();
             break;
+        }
     }
 }
« Last Edit: October 04, 2009, 07:29:53 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?