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

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: vector<int> is OK, but string or wstring no-work.
« Reply #75 on: January 14, 2010, 04:31:47 pm »
This does normally (never ?) happen inside the same event, so we have to remember whether a reparse is needed, either with a member-variable or a static local variable.
Dammed. Now I got the point. Ok... I'll take care...
Me should not work when being sick. :?
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 Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: vector<int> is OK, but string or wstring no-work.
« Reply #76 on: January 14, 2010, 04:41:29 pm »
Me should not work when being sick. :?

Nobody should.

I hope you feel better soon.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: vector<int> is OK, but string or wstring no-work.
« Reply #77 on: January 16, 2010, 01:09:38 pm »
This is what Visual c++'s code completion do in the feature:
http://blogs.msdn.com/vcblog/archive/2009/08/12/tag-parsing-c.aspx
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: vector<int> is OK, but string or wstring no-work.
« Reply #78 on: January 16, 2010, 03:43:11 pm »
I think a variable in Tokenizer class can be removed, because it is never used any more.

Code
bool             m_IsOperator;

BTW: comparing with the "operator" keyword is done in the ParserThread class instead of Tokenizer class.

Edit
Also, this function is never used in Tokenizer, we use another function.
Code
    inline const wxString& ThisOrReplacement(const wxString& str) const
    {
        ConfigManagerContainer::StringToStringMap::const_iterator it = s_Replacements.find(str);
        if (it != s_Replacements.end())
            return it->second;
        return str;
    };
So, it can be cleaned up.
« Last Edit: January 16, 2010, 03:59:17 pm 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 #79 on: January 17, 2010, 02:40:20 am »
Quote
I think a variable in Tokenizer class can be removed, because it is never used any more.

Code:

bool             m_IsOperator;


BTW: comparing with the "operator" keyword is done in the ParserThread class instead of Tokenizer class.

@ollydbg

it was used here in nativeparser.cpp

Code
if (!token)
        {
            if (s_DebugSmartSense)
                Manager::Get()->GetLogManager()->DebugLog(_T("FindAIMatches() Token is NULL?!"));
            continue;
        }

        // ignore operators
        if (token->m_IsOperator)
            continue;

        // enums children (enumerators), are added by default
        if (token->m_TokenKind == tkEnum)
        {
            // insert enum type
            result.insert(id);
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 ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: vector<int> is OK, but string or wstring no-work.
« Reply #80 on: January 17, 2010, 02:58:47 am »
Quote
I think a variable in Tokenizer class can be removed, because it is never used any more.

Code:

bool             m_IsOperator;


BTW: comparing with the "operator" keyword is done in the ParserThread class instead of Tokenizer class.

@ollydbg

it was used here in nativeparser.cpp

Code
if (!token)
        {
            if (s_DebugSmartSense)
                Manager::Get()->GetLogManager()->DebugLog(_T("FindAIMatches() Token is NULL?!"));
            continue;
        }

        // ignore operators
        if (token->m_IsOperator)
            continue;

        // enums children (enumerators), are added by default
        if (token->m_TokenKind == tkEnum)
        {
            // insert enum type
            result.insert(id);
No, There is a member m_IsOperator in the Token class. so does in Tokenizer class.
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 #81 on: January 17, 2010, 11:50:31 am »
test codes:
Code
#include <iostream>

using namespace std;
int abc(int aa)
{

    int bb;
    aa----------------------not work here.
    return 0;
}
int main()
{
    cout << "Hello world!" << endl;
    return 0;
}

issue:

the cc can not do codecompletion for variable aa

reason:

I suspect  that the function arguments were not parsed.

see the output log.yoou can see that only one temp token bb was added.
Quote
ParseLocalBlock() Block:


    int bb;
    aa
ParseLocalBlock() Local tokens:
ParseLocalBlock() + int bb parent =
AI() AI enter, actual_search: "    aa"
AI() =========================================================


And see the output log of work version,two temp tokens(aa and bb) were added.
Quote
ParseLocalBlock() Block:


    int bb;
    aa
ParseLocalBlock() Local tokens:
ParseLocalBlock() + int aa parent =
ParseLocalBlock() + int bb parent =
AI() AI enter, actual: "    aa"
AI() =========================================================
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 #82 on: January 17, 2010, 12:53:04 pm »
Code
#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;
}


[attachment deleted by admin]

Offline blueshake

  • Regular
  • ***
  • Posts: 459
Re: vector<int> is OK, but string or wstring no-work.
« Reply #83 on: January 17, 2010, 01:07:28 pm »
Quote
   std::map<int, std::string> m;
    m.insert(1, "Hello World!"); // work fine.

not work for me.

I search the tokenstree and get nothing.
« Last Edit: January 17, 2010, 02:07:21 pm 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 Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: vector<int> is OK, but string or wstring no-work.
« Reply #84 on: January 17, 2010, 01:26:07 pm »
Quote
    std::map<int, std::string> m;
    m.insert(1, "Hello World!"); // work fine.

not work for me.

I search the tokenstree and get nothing.


[attachment deleted by admin]

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: vector<int> is OK, but string or wstring no-work.
« Reply #85 on: January 17, 2010, 01:41:46 pm »
test code:
Code
int abc(int aaaaa)
{

    int bb;
    aaa
    return 0;
}
int main()
{
    cout << "Hello world!" << endl;
    return 0;
}


In a old version of C::B, it works!
Code
MarkItemsByAI()
ParseUsingNamespace() Parse file scope for "using namespace"
ParseFunctionArguments() Parse function arguments
FindCurrentFunctionStart() Current function: int abc(int aaaaa) (at line 1)
GenerateResultSet() search 'abc', parent='Global namespace (id:0, type:(null)), isPrefix=0'
ParseFunctionArguments() + Function match: abc
ParseFunctionArguments() Parsing arguments: "int aaaaa;"
ParseLocalBlock() Parse local block
ParseLocalBlock() Block:


    int bb;
    aaa
ParseLocalBlock() Local tokens:
ParseLocalBlock() + int aaaaa parent =
ParseLocalBlock() + int bb parent =
AI() AI enter, actual: "    aaa"
AI() =========================================================

In the current C::B, failed. see the log:
Code
MarkItemsByAI()
ParseUsingNamespace() Parse file scope for "using namespace"
ParseLocalBlock() Parse local block
FindCurrentFunctionStart() Looking for tokens in 'C:\cb\testforum\main.cpp'
FindCurrentFunctionStart() Found 2 results
FindCurrentFunctionStart() (Next) Iteration...
FindCurrentFunctionStart() Iterating: tN='int main()', tF='C:\cb\testforum\main.cpp', tStart=9, tEnd=12
FindCurrentFunctionStart() Function out of bounds: tN='int main()', tF='C:\cb\testforum\main.cpp', tStart=9, tEnd=12, line=5 (size_t)line=5
FindCurrentFunctionStart() (Next) Iteration...
FindCurrentFunctionStart() Iterating: tN='int abc(int aaaaa)', tF='C:\cb\testforum\main.cpp', tStart=2, tEnd=7
FindCurrentFunctionStart() Current function: 'int abc(int aaaaa)' (at line 1)
FindCurrentFunctionStart() Namespace='', proc='abc' (returning 20)
ParseLocalBlock() Block:


    int bb;
    aa
ParseLocalBlock() Local tokens:
ParseLocalBlock() + int bb parent =
AI() AI enter, actual_search: "    aa"
AI() =========================================================

So, I will check why the function parameters were not added.....
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 #86 on: January 17, 2010, 02:14:25 pm »
Code
#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
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 ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: vector<int> is OK, but string or wstring no-work.
« Reply #87 on: January 17, 2010, 02:30:35 pm »
Quite strange. See the function below:
Code
// Here, we collect the "using namespace XXXX" directives
// Also, we locate the current caret in which function, then, add the function parameters to Token trie
// Also, the variables in the function body( local block ) was add to the Token trie
size_t NativeParser::MarkItemsByAI(TokenIdxSet& result, bool reallyUseAI, bool noPartialMatch, bool caseSensitive, int caretPos)
{

    if (s_DebugSmartSense)
        Manager::Get()->GetLogManager()->DebugLog(F(_T("MarkItemsByAI()")));

    result.clear();

    cbEditor* ed = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor();
    if (!ed)
        return 0;

    if (!m_Parser.Done())
        Manager::Get()->GetLogManager()->DebugLog(_T("C++ Parser is still parsing files..."));
    else
    {
        // remove old temporaries
        m_Parser.GetTokens()->FreeTemporaries();
        m_Parser.GetTempTokens()->Clear();

        // find "using namespace" directives in the file
        TokenIdxSet search_scope;
        ParseUsingNamespace(ed, search_scope, caretPos);

        // parse function's arguments
        ParseFunctionArguments(ed, caretPos);

        // parse current code block (from the start of function up to the cursor)
        ParseLocalBlock(ed, caretPos);

        if (!reallyUseAI)
        {
            // all tokens, no AI whatsoever
            TokensTree* tokens = m_Parser.GetTokens();
            for (size_t i = 0; i < tokens->size(); ++i)
                result.insert(i);
            return result.size();
        }
        // we have correctly collected all the tokens, so we will do the artificial intelligence search
        return AI(result, ed, wxEmptyString, noPartialMatch, caseSensitive, &search_scope, caretPos);
    }
    return 0;
}

So, the
Code
ParseFunctionArguments(ed, caretPos);
should be called. But see in the ParseFunctionArguments body, there is a log out put :

Code
bool NativeParser::ParseFunctionArguments(cbEditor* ed, int caretPos)
{
    if (!ed)
        return false;

    if (m_Parser.Done())
        return false;

    if (s_DebugSmartSense)
        Manager::Get()->GetLogManager()->DebugLog(_T("ParseFunctionArguments() Parse function arguments"));

    TokenIdxSet proc_result;
    if (FindCurrentFunctionToken(ed, proc_result, caretPos) != 0)
    {
        for (TokenIdxSet

But I can't see any text about "ParseFunctionArguments() Parse function arguments" in the debug log output.... Why?
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 #88 on: January 17, 2010, 02:33:43 pm »
hi,guys.
I found the bug
in the ParseFunctionArguments
should be so
Code
    if (!m_Parser.Done())
        return false;

not so.

Code
    if (m_Parser.Done())
        return false;
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 ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: vector<int> is OK, but string or wstring no-work.
« Reply #89 on: January 17, 2010, 02:36:07 pm »
hi,guys.
I found the bug
in the ParseFunctionArguments
should be so
Code
    if (!m_Parser.Done())
        return false;

not so.

Code
    if (m_Parser.Done())
        return false;

Great! Why the "!" is missing........It seems we haven't change this function.

Edit:

It is a typo in rev 6058. :D
« Last Edit: January 17, 2010, 02:47:32 pm 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.