Author Topic: "Complete code" do not support "XXX const& "  (Read 13962 times)

Offline nanyu

  • Almost regular
  • **
  • Posts: 188
  • nanyu
"Complete code" do not support "XXX const& "
« on: April 28, 2013, 02:17:33 pm »
struct Msg
{
  ...
};

void foo1(Msg* pmsg)
{
   pmsg->    //<-- OK, c::b will show tooltip.
}

BUT

void foo2(Msg const * const pmsg)
{
    pmsg->    // c::b show nothing...
}

AND
void foo3(Msg const * pmsg)
{
    pmsg->    // c::b show nothing...
}


//////////
redhat linux KDE
c::b 12.11
« Last Edit: April 14, 2014, 05:21:38 am by nanyu »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: error on "Complete code" function
« Reply #1 on: May 02, 2013, 04:54:10 am »
I can confirm this, thanks.
I will dig into it. Hopefully it was not hard to fix this by removing all "const" keyword in handling function arguments. :)
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: error on "Complete code" function
« Reply #2 on: May 02, 2013, 06:59:29 am »
When parsing string (function arguments):
Code
Msg const * pmsg;
I see:
a variable Token named "pmsg" is added, but its basetype is "const" which is wrong.

Code
wxString ParserThread::GetTokenBaseType()
{
    TRACE(_T("GetTokenBaseType() : Searching within m_Str='%s'"), m_Str.wx_str());

    // Compensate for spaces between namespaces (e.g. NAMESPACE :: SomeType)
    // which is valid C++ construct.
    // Also, spaces that follow a semicolon are removed.
    int pos = 0;
    while (pos < (int)m_Str.Length())
    {
        if (   (m_Str.GetChar(pos) == ParserConsts::space_chr)
            && (   (   (pos > 0)
                    && (m_Str.GetChar(pos - 1) == ParserConsts::colon_chr) )
                || (   (pos < (int)m_Str.Length() - 1)
                    && (m_Str.GetChar(pos + 1) == ParserConsts::colon_chr) ) ) )
        {
            m_Str.Remove(pos, 1);
        }
        else
            ++pos;
    }

    TRACE(_T("GetTokenBaseType() : Compensated m_Str='%s'"), m_Str.wx_str());

    // TODO (Morten#5#): Handle stuff like the following gracefully:
    // int __cdecl __MINGW_NOTHROW vscanf (const char * __restrict__, __VALIST);

    // m_Str contains the full text before the token's declaration
    // an example m_Str value would be: const wxString&
    // what we do here is locate the actual return value (wxString in this example)
    // it will be needed by code completion code ;)
    pos = m_Str.Length() - 1;

    // we walk m_Str backwards until we find a non-space character which also is
    // not * or &
    //                        const wxString&
    // in this example, we would stop here ^
    while (   (pos >= 0)
           && (   wxIsspace(m_Str.GetChar(pos))
               || (m_Str.GetChar(pos) == ParserConsts::ptr_chr)
               || (m_Str.GetChar(pos) == ParserConsts::ref_chr)) )
    {
        --pos;
    }

    if (pos >= 0)
    {
        // we have the end of the word we're interested in
        int end = pos;

        // continue walking backwards until we find the start of the word
        //                               const wxString&
        // in this example, we would stop here ^
        while (   (pos >= 0)
               && (   wxIsalnum(m_Str.GetChar(pos))
                   || (m_Str.GetChar(pos) == ParserConsts::underscore_chr)
                   || (m_Str.GetChar(pos) == ParserConsts::colon_chr)) )
        {
            --pos;
        }

        TRACE(_T("GetTokenBaseType() : Found '%s'"), m_Str.Mid(pos + 1, end - pos).wx_str());
        return m_Str.Mid(pos + 1, end - pos);
    }

    TRACE(_T("GetTokenBaseType() : Returning '%s'"), m_Str.wx_str());
    return m_Str; // token ends at start of phrase
}
For the above function: the input string is "Msg const", but the output string (basetype) is "const", well, this is the reason of 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: error on "Complete code" function
« Reply #3 on: May 02, 2013, 07:29:51 am »
For the above function: the input string is "Msg const", but the output string (basetype) is "const", well, this is the reason of bug.
Feel free to fix this bug but in this special case: Could you please provide a patch in advance? I am working on that part myself, to improve the base type detection in case of macros. So a patch helps me to integrate your changes into my code base more easier.
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: error on "Complete code" function
« Reply #4 on: May 02, 2013, 04:02:30 pm »
I'm not quite sure, but I think this code snippet:
Code
            else if (token == ParserConsts::kw_const)
            {
                m_Str << token << _T(" ");
            }

Can be improved, one simple way was just skip the "const" keyword, or do the similar thing like:
Code
            case ParserConsts::ptr_chr:
                {
                    m_PointerOrRef << token;
                }
                break;
Maybe, we can add a member variable like "m_IsConst" of Parserthread class.
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: error on "Complete code" function
« Reply #5 on: May 02, 2013, 04:04:51 pm »
Any ideas?
Hmm... this might work, indeed. I would need to check the use of m_PointerOrRef though... I don't recall if it really should only be * or &...
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: error on "Complete code" function
« Reply #6 on: May 02, 2013, 04:09:45 pm »
Any ideas?
Hmm... this might work, indeed. I would need to check the use of m_PointerOrRef though... I don't recall if it really should only be * or &...
I just edit my previous post, and said:
Quote
Maybe, we can add a member variable like "m_IsConst" of Parserthread class.
I mean we can add another member variable to remember whether we have meet a "const" keyword.
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: error on "Complete code" function
« Reply #7 on: May 02, 2013, 05:53:43 pm »
I mean we can add another member variable to remember whether we have meet a "const" keyword.
Even better. :-)
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 nanyu

  • Almost regular
  • **
  • Posts: 188
  • nanyu
Re: error on "Complete code" function
« Reply #8 on: April 10, 2014, 04:49:43 am »
hi all....
This problem still exists......
do we have  a solution?
----
ubuntu codeblocks svn9744
« Last Edit: April 10, 2014, 04:52:06 am by nanyu »

Offline nanyu

  • Almost regular
  • **
  • Posts: 188
  • nanyu
Re: "Complete code" do not support "XXX const& "
« Reply #9 on: April 14, 2014, 05:26:00 am »
struct Msg
{
    int a;
    int b;
};

void foo_1(const Msg& msg)
{
    msg. //<- OK! cc work well
}

void foo_2(Msg const& msg)
{
    msg. //<- ?? cc don't work.
}

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: "Complete code" do not support "XXX const& "
« Reply #10 on: April 15, 2014, 07:18:10 am »
@nanyu, committed r9754 should fix your problem. Thanks for the report!
@Morten, I choose a simple fix by specially handling the "const" in ParserThread::GetTokenBaseType().
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 nanyu

  • Almost regular
  • **
  • Posts: 188
  • nanyu
Re: "Complete code" do not support "XXX const& "
« Reply #11 on: April 15, 2014, 11:58:40 am »
Thank you!!