Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => CodeCompletion redesign => Topic started by: killerbot on August 26, 2010, 12:07:14 pm

Title: std::endl : wrong completion
Post by: killerbot on August 26, 2010, 12:07:14 pm
For the first time (I think), CB::CC allowed me to complete std::endl. But it putted :
Code
std::endl()

The "()" shouldn't be there.
Title: Re: std::endl : wrong completion
Post by: blueshake on August 26, 2010, 03:31:14 pm
it is something related to auto assert "()",can you turn off this,and try again.if it work ,there maybe is something wrong with the parse for token "endl".
Title: Re: std::endl : wrong completion
Post by: killerbot on August 26, 2010, 10:02:13 pm
note that this does not happen during the completion of std::cout !
Title: Re: std::endl : wrong completion
Post by: ollydbg on August 27, 2010, 01:48:44 am
note that this does not happen during the completion of std::cout !
simple answer:
cout is regarded as a variable, and endl is regarded as a function( several token named "endl" exist under std namespace, but all of them were functions). see the image below:

(http://i683.photobucket.com/albums/vv194/ollydbg_cb/2010-08-27074414.png)

(http://i683.photobucket.com/albums/vv194/ollydbg_cb/2010-08-27074449.png)

This is due some parser problem... let me check it if I have time. :D

Title: Re: std::endl : wrong completion
Post by: Loaden on August 27, 2010, 05:57:10 am
Let's see iostream file (LINE: 536)
Quote
// [27.6.2.7] standard basic_ostream manipulators
  /**
   *  @brief  Write a newline and flush the stream.
   *
   *  This manipulator is often mistakenly used when a simple newline is
   *  desired, leading to poor buffering performance.  See
   *  http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#2 for more
   *  on this subject.
  */
  template<typename _CharT, typename _Traits>
    inline basic_ostream<_CharT, _Traits>&
    endl(basic_ostream<_CharT, _Traits>& __os)
    { return flush(__os.put(__os.widen('\n'))); }
This is a function!

But in:ostream.tcc (LINE: 361 or 384)
Quote
#if _GLIBCXX_EXTERN_TEMPLATE
  extern template class basic_ostream<char>;
 extern template ostream& endl(ostream&);
  extern template ostream& ends(ostream&);
Here is a variable.
Title: Re: std::endl : wrong completion
Post by: ollydbg on August 27, 2010, 06:55:04 am
But in:ostream.tcc (LINE: 361 or 384)
Quote
#if _GLIBCXX_EXTERN_TEMPLATE
  extern template class basic_ostream<char>;
 extern template ostream& endl(ostream&);
  extern template ostream& ends(ostream&);
Here is a variable.

our parser just recognize this "endl" as a function, because it has some grammar mode:
Code
AAAA BBBB();
Title: Re: std::endl : wrong completion
Post by: Loaden on August 27, 2010, 07:06:16 am
But in:ostream.tcc (LINE: 361 or 384)
Quote
#if _GLIBCXX_EXTERN_TEMPLATE
  extern template class basic_ostream<char>;
 extern template ostream& endl(ostream&);
  extern template ostream& ends(ostream&);
Here is a variable.

our parser just recognize this "endl" as a function, because it has some grammar mode:
Code
AAAA BBBB();

Looks can only judge of the special?
Quote
Index: src/plugins/codecompletion/codecompletion.cpp
===================================================================
--- src/plugins/codecompletion/codecompletion.cpp   (revision 6543)
+++ src/plugins/codecompletion/codecompletion.cpp   (working copy)
@@ -790,7 +790,8 @@
                 items.Add(tmp);
                 if (autoAddParentheses && token->m_TokenKind == tkFunction)
                 {
-                    m_SearchItem[token->m_Name] = token->m_Args.size() - 2;
+                    if (token->m_Name != _T("endl"))
+                        m_SearchItem[token->m_Name] = token->m_Args.size() - 2;
                 }
                 if (token->m_TokenKind == tkNamespace && token->m_Aliases.size())
                 {

[attachment deleted by admin]
Title: Re: std::endl : wrong completion
Post by: eranif on August 27, 2010, 07:55:16 am
std::endl *is* a function.

When people are typing std::endl they are actually passing the pointer of the function to the 'operator <<' of class basic_ostream

Code
__ostream_type&
      operator<<(__ostream_type& (*__pf)(__ostream_type&))

The same is true for all other similar methods, like std::hex, std::oct, std::dec etc
So if you are going to special handle the 'endl' case, make sure you handle the other methods as well (hex, dec, oct etc.)

Eran
Title: Re: std::endl : wrong completion
Post by: ollydbg on August 27, 2010, 07:58:05 am
std::endl *is* a function.

When people are typing std::endl they are actually passing the pointer of the function to the 'operator <<' of class basic_ostream

Code
__ostream_type&
      operator<<(__ostream_type& (*__pf)(__ostream_type&))

The same is true for all other similar methods, like std::hex, std::oct, std::dec etc
So if you are going to special handle the 'endl' case, make sure you handle the other methods as well (hex, dec, oct etc.)

Eran


Thanks eran for your help.
So, my personal question is: how does Codelite deal with this kind of problem??
thanks.
Title: Re: std::endl : wrong completion
Post by: eranif on August 27, 2010, 08:02:19 am
Quote
So, my personal question is: how does Codelite deal with this kind of problem??
I am not :D

The same as codeblocks:
when user types std::endl -> codelite adds the () and shows the function tip. I never find it a problem since in codelite if I delete the open brace, the closing brace is also deleted

Eran
Title: Re: std::endl : wrong completion
Post by: ollydbg on August 27, 2010, 08:09:46 am
Quote
So, my personal question is: how does Codelite deal with this kind of problem??
I am not :D

OK, Now we have two ways:
One is like codelite does
Quote
The same as codeblocks:
when user types std::endl -> codelite adds the () and shows the function tip. I never find it a problem since in codelite if I delete the open brace, the closing brace is also deleted
The other is special handling like: (endl, hex, dec, oct etc)

thanks. :D
Title: Re: std::endl : wrong completion
Post by: ollydbg on August 27, 2010, 08:11:26 am
maybe, a better way is :

checking the ”<<" can accept a function pointer, then we can avoid adding "()" in this case. But it is too complex  :D
Title: Re: std::endl : wrong completion
Post by: MortenMacFly on August 27, 2010, 08:12:57 am
Looks can only judge of the special?
No good. Imagine you have a local variable / method with this name than endl has a different meaning and appending the brackets might be desired. In addition: actually this codecompletion should not have any language specific elements at all... ;-)
Title: Re: std::endl : wrong completion
Post by: Loaden on August 27, 2010, 08:35:57 am
Looks can only judge of the special?
No good. Imagine you have a local variable / method with this name than endl has a different meaning and appending the brackets might be desired. In addition: actually this codecompletion should not have any language specific elements at all... ;-)
Well, we still remain the same.
Title: Re: std::endl : wrong completion
Post by: Loaden on August 27, 2010, 08:36:31 am
maybe, a better way is :

checking the ”<<" can accept a function pointer, then we can avoid adding "()" in this case. But it is too complex  :D
I think this is not possible!
Title: Re: std::endl : wrong completion
Post by: Loaden on August 27, 2010, 08:40:42 am
std::endl *is* a function.

When people are typing std::endl they are actually passing the pointer of the function to the 'operator <<' of class basic_ostream

Code
__ostream_type&
      operator<<(__ostream_type& (*__pf)(__ostream_type&))

The same is true for all other similar methods, like std::hex, std::oct, std::dec etc
So if you are going to special handle the 'endl' case, make sure you handle the other methods as well (hex, dec, oct etc.)

Eran

Thank eranif to help!
Another question, Why CodeLite can not use wxAuiToolBar on Linux?
Title: Re: std::endl : wrong completion
Post by: eranif on August 27, 2010, 05:01:49 pm
Quote
Thank eranif to help!
Another question, Why CodeLite can not use wxAuiToolBar on Linux?
It can. But I simply prefered not to use it but rather using wxToolbar (wxAuiToolBar is simply *ugly* under Linux, it looks like it was written for Windows and then ported to Linux/Mac)

If you really insist on enabling it, you can simply change it in the file cl_defs.h yo USE_AUI_TOOLBAR=1

Eran
Title: Re: std::endl : wrong completion
Post by: Loaden on August 27, 2010, 05:26:11 pm
Quote
Thank eranif to help!
Another question, Why CodeLite can not use wxAuiToolBar on Linux?
It can. But I simply prefered not to use it but rather using wxToolbar (wxAuiToolBar is simply *ugly* under Linux, it looks like it was written for Windows and then ported to Linux/Mac)

If you really insist on enabling it, you can simply change it in the file cl_defs.h yo USE_AUI_TOOLBAR=1

Eran
Well, thank you!