Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: nanyu on April 28, 2013, 02:17:33 pm

Title: "Complete code" do not support "XXX const& "
Post by: nanyu 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
Title: Re: error on "Complete code" function
Post by: ollydbg 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. :)
Title: Re: error on "Complete code" function
Post by: ollydbg 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.
Title: Re: error on "Complete code" function
Post by: MortenMacFly 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.
Title: Re: error on "Complete code" function
Post by: ollydbg 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?
Title: Re: error on "Complete code" function
Post by: MortenMacFly 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 &...
Title: Re: error on "Complete code" function
Post by: ollydbg 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.
Title: Re: error on "Complete code" function
Post by: MortenMacFly 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. :-)
Title: Re: error on "Complete code" function
Post by: nanyu on April 10, 2014, 04:49:43 am
hi all....
This problem still exists......
do we have  a solution?
----
ubuntu codeblocks svn9744
Title: Re: "Complete code" do not support "XXX const& "
Post by: nanyu 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.
}
Title: Re: "Complete code" do not support "XXX const& "
Post by: ollydbg 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().
Title: Re: "Complete code" do not support "XXX const& "
Post by: nanyu on April 15, 2014, 11:58:40 am
Thank you!!