Author Topic: Code completion problems in 7966?  (Read 9512 times)

zabzonk

  • Guest
Code completion problems in 7966?
« on: May 20, 2012, 05:53:27 pm »
After having no code completion problems for ages, I'm experiencing some after installing the latest nightly. This is from my project CSVfix at http://code.google.com/p/csvfix/

int ExcludeCommand :: Execute( ALib::CommandLine & cmd ) {   
   ProcessFlags( cmd );
        ....


Here, code completion on the "cmd" parameter works just fine. But if I move down in the source about 30 lines to:

void ExcludeCommand :: ProcessFlags( const ALib::CommandLine & cmd ) {
   string es = cmd.GetValue( FLAG_IF, "" );
        ....


code completion on the "cmd" parameter no longer works (though completion on things like "this" does).  Note the parameters of both functions are of the same type, though the one that doesn't work is const, and the first (working) function calls the second (non-working) one.  I am experiencing similar problems with other classes.

This is quite old code, which compiles perfectly well, and I think did code-complete before (though I can't be 100% sure of that).

Any ideas?

Edit: I have tried making the second function non-const WRT the "cmd" parameter (in both the header and the implementation file), and if I do that code completion in that function starts working. If I revert to the const parameter, it stops working. Also, should have said Win7, 64-bit.

« Last Edit: May 20, 2012, 06:45:00 pm by Neil Butterworth »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5913
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion problems in 7966?
« Reply #1 on: May 21, 2012, 04:35:49 am »
Ok, I can confirm this, here is the test code:
Code
namespace ALib
{
    class CommandLine
    {
        int a;
        int b;
    };
};


void ExcludeCommand :: ProcessFlags( const ALib::CommandLine & cmd ) {

cmd;

}

void ExcludeCommand :: ProcessFlags1( ALib::CommandLine & cmd ) {

cmd;

}


When I hit the "." (dot) after "cmd", It only works in the second function body.


Enable the smart debug, I see:
Code
MarkItemsByAI_1()
ParseUsingNamespace() Parse file scope for "using namespace"
BreakUpComponents() Breaking up 'ALib'
BreakUpComponents() Found component: 'ALib' (SearchText)
BreakUpComponents() Adding component: 'ALib'.
ParseUsingNamespace() Found ALib
ParseFunctionArguments() Parse function arguments
FindCurrentFunctionStart() Looking for tokens in 'E:\code\cb\test_code\mortenr2012-01-15\main.cpp'
FindCurrentFunctionStart() Found 4 results
FindCurrentFunctionStart() Current function: 'void ExcludeCommand::ProcessFlags(const ALib::CommandLine& cmd)' (at line 11)
FindCurrentFunctionStart() Namespace='ExcludeCommand::', proc='ProcessFlags' (returning 166)
BreakUpComponents() Breaking up 'ExcludeCommand'
BreakUpComponents() Found component: 'ExcludeCommand' (SearchText)
BreakUpComponents() Adding component: 'ExcludeCommand'.
FindAIMatches() ----- FindAIMatches - enter -----
FindAIMatches() Search for ExcludeCommand, isLast = 1
GenerateResultSet() search 'ExcludeCommand', parent='Global namespace (id:0, type:(null)), isPrefix=0'
FindAIMatches() Looping 1 results
FindAIMatches() Match: 'ExcludeCommand' (ID='497') : type=''
FindAIMatches() ----- FindAIMatches - leave -----
GenerateResultSet() search 'ProcessFlags', parent='ExcludeCommand (id:497, type:class), isPrefix=0'
ParseFunctionArguments() + Function match: ProcessFlags
ParseFunctionArguments() Parsing arguments: "const ALib::CommandLine& cmd;"
ParseLocalBlock() Parse local block
FindCurrentFunctionStart() Looking for tokens in 'E:\code\cb\test_code\mortenr2012-01-15\main.cpp'
FindCurrentFunctionStart() Found 4 results
FindCurrentFunctionStart() Current function: 'void ExcludeCommand::ProcessFlags(const ALib::CommandLine& cmd)' (at line 11)
FindCurrentFunctionStart() Namespace='ExcludeCommand::', proc='ProcessFlags' (returning 166)
ParseLocalBlock() Block:


cmd.;
ParseLocalBlock() Local tokens:
 + constCommandLine & ExcludeCommand::ProcessFlags::cmd Parent = ProcessFlags
AI() =========================================================
AI() Doing AI for 'cmd.':
FindCurrentFunctionStart() Looking for tokens in 'E:\code\cb\test_code\mortenr2012-01-15\main.cpp'
FindCurrentFunctionStart() Found 4 results
FindCurrentFunctionStart() Current function: 'void ExcludeCommand::ProcessFlags(const ALib::CommandLine& cmd)' (at line 11)
FindCurrentFunctionStart() Namespace='ExcludeCommand::', proc='ProcessFlags' (returning 166)
BreakUpComponents() Breaking up 'ExcludeCommand'
BreakUpComponents() Found component: 'ExcludeCommand' (SearchText)
BreakUpComponents() Adding component: 'ExcludeCommand'.
FindAIMatches() ----- FindAIMatches - enter -----
FindAIMatches() Search for ExcludeCommand, isLast = 1
GenerateResultSet() search 'ExcludeCommand', parent='Global namespace (id:0, type:(null)), isPrefix=0'
FindAIMatches() Looping 1 results
FindAIMatches() Match: 'ExcludeCommand' (ID='497') : type=''
FindAIMatches() ----- FindAIMatches - leave -----
GenerateResultSet() search 'ProcessFlags', parent='ExcludeCommand (id:497, type:class), isPrefix=0'
AI() Adding search namespace: ExcludeCommand
BreakUpComponents() Breaking up 'cmd.'
BreakUpComponents() Found component: 'cmd' (Class)
BreakUpComponents() Adding component: 'cmd'.
BreakUpComponents() Found component: '' (SearchText)
BreakUpComponents() Adding component: ''.
ResolveExpression() search scope is 4 result.
search scope: -1
search scope: 492
search scope: 494
search scope: 497
ResolveExpression() Looping 1 result.
ResolvExpression() Match:'cmd(ID=498) : type='ALib::constCommandLine'
BreakUpComponents() Breaking up 'ALib::constCommandLine'
BreakUpComponents() Found component: 'ALib' (Namespace)
BreakUpComponents() Adding component: 'ALib'.
BreakUpComponents() Found component: 'constCommandLine' (SearchText)
BreakUpComponents() Adding component: 'constCommandLine'.
ResolveExpression() search scope is 0 result.
ResolveExpression() Looping 0 result.
AI() AI leave, returned 0 results
0 results

See, there is a wrong string "constCommandLine".

This bug also happens in the tip window when the mouse hover the "cmd".
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: 5913
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion problems in 7966?
« Reply #2 on: May 21, 2012, 05:18:48 am »
Ok, after debug for some time, I found that this problem happened at:

Code
                else if (peek==ParserConsts::dcolon)
                {
                    if (   m_Str.IsEmpty()
                        || m_Str.Trim(true).Trim(false).IsSameAs(ParserConsts::kw_const)
                        || m_Str.Trim(true).Trim(false).IsSameAs(ParserConsts::kw_volatile) ) // what else?!
                        m_EncounteredTypeNamespaces.push(token); // it's a type's namespace
                    else
                        m_EncounteredNamespaces.push(token);
                    m_Tokenizer.GetToken(); // eat ::
                }

When parsing the argument string:
Code
const ALib::CommandLine & cmd

The "stack" variable "m_Str" is originally "const ", and after that, it becomes "const", the last space is removed.

And later,  the CommandLine is added, and "m_Str" becomes "constCommandLine".

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: 5913
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion problems in 7966?
« Reply #3 on: May 21, 2012, 05:35:01 am »
This is the patch to fix this issue:
Code
Index: E:/code/cb/cb_trunk/src/plugins/codecompletion/parser/parserthread.cpp
===================================================================
--- E:/code/cb/cb_trunk/src/plugins/codecompletion/parser/parserthread.cpp (revision 7991)
+++ E:/code/cb/cb_trunk/src/plugins/codecompletion/parser/parserthread.cpp (working copy)
@@ -1058,7 +1058,12 @@
                     if (   m_Str.IsEmpty()
                         || m_Str.Trim(true).Trim(false).IsSameAs(ParserConsts::kw_const)
                         || m_Str.Trim(true).Trim(false).IsSameAs(ParserConsts::kw_volatile) ) // what else?!
+                    {
+                        if (!m_Str.IsEmpty())
+                            m_Str << _T(" ");
                         m_EncounteredTypeNamespaces.push(token); // it's a type's namespace
+                    }
+
                     else
                         m_EncounteredNamespaces.push(token);
                     m_Tokenizer.GetToken(); // eat ::

But I'm not satisfied with the logic on changing m_Str. Any ideas?
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: Code completion problems in 7966?
« Reply #4 on: May 21, 2012, 06:13:37 am »
But I'm not satisfied with the logic on changing m_Str. Any ideas?
I think the issue is that the space is removed. Where and why does that happen?
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: 5913
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion problems in 7966?
« Reply #5 on: May 21, 2012, 06:33:45 am »
But I'm not satisfied with the logic on changing m_Str. Any ideas?
I think the issue is that the space is removed.
Yes, the m_Str is like a "stack", when you push(add) something to it, you need a trailing space.
Quote
Where and why does that happen?
Code
m_Str.Trim(true).Trim(false).IsSameAs(ParserConsts::kw_const)
This code removed the trailing space, so my patch adds the space again.
« Last Edit: May 21, 2012, 08:30:08 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 MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Code completion problems in 7966?
« Reply #6 on: May 21, 2012, 06:52:01 am »
Yes, the m_Str is like a "stack", when you push(add) something to it, you need a tailing space.
[...]
Code
m_Str.Trim(true).Trim(false).IsSameAs(ParserConsts::kw_const)
This code removed the tailing space, so my patch adds the space again.
So, doing something like:
Code
wxString str_stripped(m_Str); if (str_stripped.Trim(true).Trim(false).IsSameAs(ParserConsts::kw_const)) ...
...wouldn't that be better?
...or even:
Code
wxString str_stripped(m_Str); str_stripped.Trim(true).Trim(false); if (str_stripped.IsSameAs(ParserConsts::kw_const)) ...

Edit: Edited the second code snippet so it is syntax-correct.
« Last Edit: May 21, 2012, 06:58:17 am by MortenMacFly »
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: 5913
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion problems in 7966?
« Reply #7 on: May 21, 2012, 07:03:27 am »
Ok, I'm going to commit the patch below (in a few hours):

Code
Index: E:/code/cb/cb_trunk/src/plugins/codecompletion/parser/parserthread.cpp
===================================================================
--- E:/code/cb/cb_trunk/src/plugins/codecompletion/parser/parserthread.cpp (revision 7991)
+++ E:/code/cb/cb_trunk/src/plugins/codecompletion/parser/parserthread.cpp (working copy)
@@ -1055,9 +1055,11 @@
                 }
                 else if (peek==ParserConsts::dcolon)
                 {
-                    if (   m_Str.IsEmpty()
-                        || m_Str.Trim(true).Trim(false).IsSameAs(ParserConsts::kw_const)
-                        || m_Str.Trim(true).Trim(false).IsSameAs(ParserConsts::kw_volatile) ) // what else?!
+                    wxString str_stripped(m_Str);
+                    str_stripped.Trim(true).Trim(false);
+                    if (   str_stripped.IsEmpty()
+                        || str_stripped.Trim(true).Trim(false).IsSameAs(ParserConsts::kw_const)
+                        || str_stripped.Trim(true).Trim(false).IsSameAs(ParserConsts::kw_volatile) ) // what else?!
                         m_EncounteredTypeNamespaces.push(token); // it's a type's namespace
                     else
                         m_EncounteredNamespaces.push(token);
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: 5913
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion problems in 7966?
« Reply #8 on: May 21, 2012, 08:15:18 am »
Commited:

Quote
Revision: 7992
Author: ollydbg
Date: 2012-5-21 14:14:18
Message:
* CC: Fix a bug when parsing some kind of buffer like "const ALib::CommandLine & cmd", the tailing space should be preserved in m_Str. See more details on http://forums.codeblocks.org/index.php/topic,16361.msg110868.html#msg110868
-------------------------------
M : /trunk/src/plugins/codecompletion/parser/parserthread.cpp


EDIT:
@Morten:
Thanks for the tiny fix in rev 7993.
« Last Edit: May 21, 2012, 09:49:10 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.