Author Topic: vector<int> is OK, but string or wstring no-work.  (Read 58453 times)

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9508
Re: vector<int> is OK, but string or wstring no-work.
« Reply #90 on: January 17, 2010, 02:46:44 pm »
Great! Why the "!" is missing........It seems we haven't change this function.
My fault. I was removing the artifacts from the past where there used to be a parser per project. So I changed all references to "per project parser" to the global none and obviously missed the !" there. Sorry. Will fix asap...
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: vector<int> is OK, but string or wstring no-work.
« Reply #91 on: January 17, 2010, 04:14:22 pm »
Code: [Select]
#include <iostream>
#include <map>
#include <string>

int main()
{
    typedef std::map<int, std::string> TestMap;
    TestMap testMap;
//    testMap. // not work!

    std::map<int, std::string> m;
    m.insert(1, "Hello World!"); // work fine.
    return 0;
}

@Loaden
you can not typedef something in the function body.The reason is not clear for me,maybe ollydbg or morten can release some answers. :D
Code: [Select]
#include <iostream>
#include <map>
#include <string>

typedef std::map<int, std::string> TestMap;

class A
{
public:
    void Test()
    {
        TestMap2 t2;
        t2.in // works here too.
    }
   
private:
    typedef std::map<int, std::string> TestMap2;
}

int main()
{
    TestMap testMap;
    testMap.i // ok, work now.
    return 0;
}


[attachment deleted by admin]

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: vector<int> is OK, but string or wstring no-work.
« Reply #92 on: January 17, 2010, 04:32:08 pm »
New bug:
Code: [Select]
#include <iostream>

int main()
{
    // std::cou // not work!
    std::endl // work here.
    return 0;
}

[attachment deleted by admin]

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: vector<int> is OK, but string or wstring no-work.
« Reply #93 on: January 17, 2010, 04:40:38 pm »
There's a small problem.


[attachment deleted by admin]

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9508
Re: vector<int> is OK, but string or wstring no-work.
« Reply #94 on: January 17, 2010, 07:22:00 pm »
There's a small problem.
That's not a problem, that's by design.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline blueshake

  • Regular
  • ***
  • Posts: 459
Re: vector<int> is OK, but string or wstring no-work.
« Reply #95 on: January 18, 2010, 03:06:52 am »
Quote
#include <iostream>

int main()
{
    // std::cou // not work!
    std::endl // work here.
    return 0;
}


where is the definition of std::cout???
Keep low and hear the sadness of little dog.
I fall in love with a girl,but I don't dare to tell her.What should I do?

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9508
Re: vector<int> is OK, but string or wstring no-work.
« Reply #96 on: January 18, 2010, 06:31:28 am »
where is the definition of std::cout???
Directly in iostream:
Code: [Select]
  extern istream cin; ///< Linked to standard input
  extern ostream cout; ///< Linked to standard output
  extern ostream cerr; ///< Linked to standard error (unbuffered)
  extern ostream clog; ///< Linked to standard error (buffered)
And yes: It's "gone". ?!
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5247
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: vector<int> is OK, but string or wstring no-work.
« Reply #97 on: January 18, 2010, 06:55:36 am »
In my opinion: In the parserThread DoParse function, when it meet the "extern" keyword, the parser just skip to the the ";".
« Last Edit: January 18, 2010, 07:08:38 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 blueshake

  • Regular
  • ***
  • Posts: 459
Re: vector<int> is OK, but string or wstring no-work.
« Reply #98 on: January 18, 2010, 08:07:41 am »
In my opinion: In the parserThread DoParse function, when it meet the "extern" keyword, the parser just skip to the the ";".

right.that is why I ask where is the real definition.if it is just so,we need to  do some handle about extern.
Keep low and hear the sadness of little dog.
I fall in love with a girl,but I don't dare to tell her.What should I do?

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9508
Re: vector<int> is OK, but string or wstring no-work.
« Reply #99 on: January 18, 2010, 08:10:58 am »
In my opinion: In the parserThread DoParse function, when it meet the "extern" keyword, the parser just skip to the the ";".
No, the code is question is as follows:
Code: [Select]
        else if (token==ParserConsts::kw_extern)
        {
            // check for "C"
            m_Str = m_Tokenizer.GetToken();
            if (m_Str==ParserConsts::kw_C)
            {
                m_Tokenizer.GetToken(); // "eat" {
                DoParse(); // time for recursion ;)
            }
            else
            {
                // do nothing, just skip keyword "extern", otherwise uncomment:
                //SkipToOneOfChars(ParserConsts::semicolon); // skip externs
            }
            m_Str.Clear();
        }
As you see: Really only "extern" is skipped, the rest is parsed as usual.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline blueshake

  • Regular
  • ***
  • Posts: 459
Re: vector<int> is OK, but string or wstring no-work.
« Reply #100 on: January 18, 2010, 08:47:20 am »
Code: [Select]
           m_Str = m_Tokenizer.GetToken();
            if (m_Str==ParserConsts::kw_C)
            {
                m_Tokenizer.GetToken(); // "eat" {
                DoParse(); // time for recursion ;)
            }
            else
            {
                // do nothing, just skip keyword "extern", otherwise uncomment:
                //SkipToOneOfChars(ParserConsts::semicolon); // skip externs
            }
            m_Str.Clear();

it seems I get the reason.

e.g. extern int aa;

when we do this.
Code: [Select]
m_Str = m_Tokenizer.GetToken();
now the m_Str is int.


but here we clear the m_Str again.
Code: [Select]
m_Str.Clear();
so the m_Str is empty.I think this is why the cout can not be parsed correctly.

solution :

comment this statement may work.

Code: [Select]
//m_Str.Clear();
« Last Edit: January 18, 2010, 09:00:49 am by blueshake »
Keep low and hear the sadness of little dog.
I fall in love with a girl,but I don't dare to tell her.What should I do?

Offline blueshake

  • Regular
  • ***
  • Posts: 459
Re: vector<int> is OK, but string or wstring no-work.
« Reply #101 on: January 18, 2010, 09:00:15 am »
New bug:
Code: [Select]
#include <iostream>

int main()
{
    // std::cou // not work!
    std::endl // work here.
    return 0;
}


patch for it.

Code: [Select]
Index: src/plugins/codecompletion/parser/parserthread.cpp
===================================================================
--- src/plugins/codecompletion/parser/parserthread.cpp (revision 6089)
+++ src/plugins/codecompletion/parser/parserthread.cpp (working copy)
@@ -524,7 +524,7 @@
         else if (token==ParserConsts::kw_extern)
         {
             // check for "C"
-            m_Str = m_Tokenizer.GetToken();
+            m_Str = m_Tokenizer.PeekToken();
             if (m_Str==ParserConsts::kw_C)
             {
                 m_Tokenizer.GetToken(); // "eat" {

see the screen shot.



[attachment deleted by admin]
Keep low and hear the sadness of little dog.
I fall in love with a girl,but I don't dare to tell her.What should I do?

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9508
Re: vector<int> is OK, but string or wstring no-work.
« Reply #102 on: January 18, 2010, 09:04:11 am »
patch for it.
Code: [Select]
Index: src/plugins/codecompletion/parser/parserthread.cpp
             // check for "C"
-            m_Str = m_Tokenizer.GetToken();
+            m_Str = m_Tokenizer.PeekToken();
             if (m_Str==ParserConsts::kw_C)
             {
                 m_Tokenizer.GetToken(); // "eat" {
Be careful: In that case not the "{" is "eaten" in the case of extern C {...} statements, but the "C". So your patch will work for the extern cout thing, but will break extern C {...}.
This maybe corrected by issuing "m_Tokenizer.GetToken();" twice in the if clause, the fiorst time for "C", the second time for the "{".
« Last Edit: January 18, 2010, 09:05:53 am by MortenMacFly »
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline blueshake

  • Regular
  • ***
  • Posts: 459
Re: vector<int> is OK, but string or wstring no-work.
« Reply #103 on: January 18, 2010, 09:09:13 am »
hi,morten:
what about this way.
Code: [Select]
Index: src/plugins/codecompletion/parser/parserthread.cpp
===================================================================
--- src/plugins/codecompletion/parser/parserthread.cpp (revision 6089)
+++ src/plugins/codecompletion/parser/parserthread.cpp (working copy)
@@ -534,6 +534,7 @@
             {
                 // do nothing, just skip keyword "extern", otherwise uncomment:
                 //SkipToOneOfChars(ParserConsts::semicolon); // skip externs
+                m_Tokenizer.UngetToken();
             }
             m_Str.Clear();
         }
Keep low and hear the sadness of little dog.
I fall in love with a girl,but I don't dare to tell her.What should I do?

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: vector<int> is OK, but string or wstring no-work.
« Reply #104 on: January 18, 2010, 09:23:21 am »
hi,morten:
what about this way.
Code: [Select]
Index: src/plugins/codecompletion/parser/parserthread.cpp
===================================================================
--- src/plugins/codecompletion/parser/parserthread.cpp (revision 6089)
+++ src/plugins/codecompletion/parser/parserthread.cpp (working copy)
@@ -534,6 +534,7 @@
             {
                 // do nothing, just skip keyword "extern", otherwise uncomment:
                 //SkipToOneOfChars(ParserConsts::semicolon); // skip externs
+                m_Tokenizer.UngetToken();
             }
             m_Str.Clear();
         }
Work now! :P