News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

vector<int> is OK, but string or wstring no-work.

Started by Loaden, January 06, 2010, 05:39:50 AM

Previous topic - Next topic

MortenMacFly

Quote from: jens on January 14, 2010, 02:27:28 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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

Jenna


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.

ollydbg

#78
I think a variable in Tokenizer class can be removed, because it is never used any more.

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.
    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.
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.

blueshake

QuoteI 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

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?

ollydbg

Quote from: blueshake on January 17, 2010, 02:40:20 AM
QuoteI 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

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.

blueshake

test codes:
#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.
QuoteParseLocalBlock() 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.
QuoteParseLocalBlock() 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?

Loaden

#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]

blueshake

#83
Quotestd::map<int, std::string> m;
   m.insert(1, "Hello World!"); // work fine.

not work for me.

I search the tokenstree and get nothing.
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?

Loaden

Quote from: blueshake on January 17, 2010, 01:07:28 PM
Quotestd::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]

ollydbg

test 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!
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:
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.

blueshake

Quote from: Loaden on January 17, 2010, 12:53:04 PM
#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?

ollydbg

Quite strange. See the function below:
// 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 ParseFunctionArguments(ed, caretPos); should be called. But see in the ParseFunctionArguments body, there is a log out put :


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.

blueshake

hi,guys.
I found the bug
in the ParseFunctionArguments
should be so
   if (!m_Parser.Done())
       return false;


not so.

   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?

ollydbg

#89
Quote from: blueshake on January 17, 2010, 02:33:43 PM
hi,guys.
I found the bug
in the ParseFunctionArguments
should be so
   if (!m_Parser.Done())
       return false;


not so.

   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
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.