Author Topic: namespaces and code completion  (Read 10987 times)

Offline Alcareru

  • Single posting newcomer
  • *
  • Posts: 5
namespaces and code completion
« on: May 17, 2009, 02:33:10 pm »
So I decided to give codeblocks a try. Now how I'd expect the code completion to work is that when I type something like this

#include <string>
std::strin
//It should suggest a completion to string, but it doesn't.

So I guess I'm asking have possibly misconfigured something?

Everything works as expected if I do something like this:

namespace foospace {
    void fooMethod(){}
    class FooClass {}
    int foospaceVariable = 2;
}

int GLOBAL_FOO_VARIABLE = 0;

int main(int argc, char* argv[])
{
// Now I do get code completion when I type
    foospace::fooMethod();
    foospace::FooClass;
    foospace::foospaceVariable;
    GLOBAL_FOO_VARIABLE;
}


P.S. I migth add that the include statement actually does work and the string class can be found and that I'm using ubuntu 8.10.
« Last Edit: May 17, 2009, 02:42:39 pm by Alcareru »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5236
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: namespaces and code completion
« Reply #1 on: May 17, 2009, 03:02:55 pm »
I have tested for you.

Here is the screen shot, I looked up in the database, found that string was in global scope.

And here is the header file.

Code: [Select]
_GLIBCXX_BEGIN_NAMESPACE(std)

  template<typename _Alloc>
    class allocator;

  template<class _CharT>
    struct char_traits;

  template<typename _CharT, typename _Traits = char_traits<_CharT>,
           typename _Alloc = allocator<_CharT> >
    class basic_string;

  template<> struct char_traits<char>;

  typedef basic_string<char>    string;

#ifdef _GLIBCXX_USE_WCHAR_T
  template<> struct char_traits<wchar_t>;

  typedef basic_string<wchar_t> wstring;
#endif

#if (defined(__GXX_EXPERIMENTAL_CXX0X__) \
     && defined(_GLIBCXX_USE_C99_STDINT_TR1))

  template<> struct char_traits<char16_t>;
  template<> struct char_traits<char32_t>;

  typedef basic_string<char16_t> u16string;
  typedef basic_string<char32_t> u32string;

#endif

_GLIBCXX_END_NAMESPACE



It seems that the code completion parse the Macro:

_GLIBCXX_BEGIN_NAMESPACE and

_GLIBCXX_END_NAMESPACE  very badly.

 :D




[attachment deleted by admin]
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: 5236
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: namespaces and code completion
« Reply #2 on: May 17, 2009, 04:17:07 pm »
By the way, only the  macro _GLIBCXX_STD can be correctly replaced by "std".

see here:

http://wiki.codeblocks.org/index.php?title=Code_Completion_Design#Return_a_correct_token

My question is:

How to replace the _GLIBCXX_BEGIN_NAMESPACE(std).

I know in Ctags, there are some options to do this.

Here is the message I cited from it's document from:

http://ctags.sourceforge.net/ctags.html

Quote
−I identifier−list
   

Specifies a list of identifiers which are to be specially handled while parsing C and C++ source files. This option is specifically provided to handle special cases arising through the use of preprocessor macros. When the identifiers listed are simple identifiers, these identifiers will be ignored during parsing of the source files. If an identifier is suffixed with a + character, ctags will also ignore any parenthesis-enclosed argument list which may immediately follow the identifier in the source files. If two identifiers are separated with the = character, the first identifiers is replaced by the second identifiers for parsing purposes. The list of identifiers may be supplied directly on the command line or read in from a separate file. If the first character of identifier−list is @, . or a pathname separator (/ or \), or the first two characters specify a drive letter (e.g. "C:"), the parameter identifier−list will be interpreted as a filename from which to read a list of identifiers, one per input line. Otherwise, identifier−list is a list of identifiers (or identifier pairs) to be specially handled, each delimited by a either a comma or by white space (in which case the list should be quoted to keep the entire list as one command line argument). Multiple −I options may be supplied. To clear the list of ignore identifiers, supply a single dash ("−") for identifier−list.

This feature is useful when preprocessor macros are used in such a way that they cause syntactic confusion due to their presence. Indeed, this is the best way of working around a number of problems caused by the presence of syntax-busting macros in source files (see CAVEATS, below). Some examples will illustrate this point.
   

int foo ARGDECL4(void *, ptr, long int, nbytes)
   

In the above example, the macro "ARGDECL4" would be mistakenly interpreted to be the name of the function instead of the correct name of "foo". Specifying −I ARGDECL4 results in the correct behavior.
   

/* creates an RCS version string in module */
   

MODULE_VERSION("$Revision: 590 $")
   

In the above example the macro invocation looks too much like a function definition because it is not followed by a semicolon (indeed, it could even be followed by a global variable definition that would look much like a K&R style function parameter declaration). In fact, this seeming function definition could possibly even cause the rest of the file to be skipped over while trying to complete the definition. Specifying −I MODULE_VERSION+ would avoid such a problem.
   

CLASS Example {
// your content here
};
   

The example above uses "CLASS" as a preprocessor macro which expands to something different for each platform. For instance CLASS may be defined as "class __declspec(dllexport)" on Win32 platforms and simply "class" on UNIX. Normally, the absence of the C++ keyword "class" would cause the source file to be incorrectly parsed. Correct behavior can be restored by specifying −I CLASS=class.


So, If code completion can do like ctags does, these problem can easily be solved.
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 Alcareru

  • Single posting newcomer
  • *
  • Posts: 5
Re: namespaces and code completion
« Reply #3 on: May 17, 2009, 04:44:45 pm »
So what your saying is that there's no code completion for STL stuff?

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5236
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: namespaces and code completion
« Reply #4 on: May 17, 2009, 04:50:08 pm »
So what your saying is that there's no code completion for STL stuff?

No, I suggest you can just use "string" as it is in global scopes.

see something like this:

Quote
#include <string>
using namespace std;
strin
// it should be work!

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 Alcareru

  • Single posting newcomer
  • *
  • Posts: 5
Re: namespaces and code completion
« Reply #5 on: May 17, 2009, 07:26:16 pm »
So what your saying is that there's no code completion for STL stuff?

No, I suggest you can just use "string" as it is in global scopes.

see something like this:

Quote
#include <string>
using namespace std;
strin
// it should be work!


It doesn't. I modified the previous example a bit:
#include <string>
#include <iostream>

using namespace std;

namespace foospace {
    void fooMethod(){}
    class FooClass {};
    int foospaceVariable = 2;
}

int GLOBAL_FOO_VARIABLE = -1;

int main(int argc, char* argv[])
{
    foospace::fooMethod();
    foospace::FooClass fooClassInstance = foospace::FooClass();
    if (!(foospace::foospaceVariable == 2))
        throw 1;
    if (!(GLOBAL_FOO_VARIABLE == -1))
        throw 2;

    std::string fooString("fooStringText");

    string fooStringInstance = "foostring";//<- no code completion
    cout<<fooStringInstance<<endl;// <- no code completion for cout nor endl

/* Remove this line to uncomment the next if-clause
    if (foospaceVariable == 2) // <- code completion, though variable is not even visible
        throw 3;/**/
    return 0;
}

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5236
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: namespaces and code completion
« Reply #6 on: May 18, 2009, 03:23:40 am »
Works fine in my XP and nightliy build.
See the screen shot below.

[attachment deleted by admin]
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 Alcareru

  • Single posting newcomer
  • *
  • Posts: 5
Re: namespaces and code completion
« Reply #7 on: May 18, 2009, 05:20:21 am »
Ok. I'll check the nightly build. Thanks.