News:

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

Main Menu

Commit rev 6058 question

Started by ollydbg, November 13, 2013, 06:29:42 AM

Previous topic - Next topic

ollydbg

When discuss this patch:
CodeCompletion: fixes UnnamedStruct in the classBrowser, see the commens there, the main issue is:

I see that in rev =/@6057&compare[]=/@6058]WebSVN - codeblocks - Path Comparison - / Rev 6057 and / Rev 6058


-int TokensTree::AddToken(Token* newToken,int forceidx)
+int TokensTree::AddToken(Token* newToken, int fileIndex)
{
    if (!newToken)
        return -1;

    const wxString & name = newToken->m_Name;

-    static TokenIdxSet tmp_tokens = TokenIdxSet();
-    // tmp_tokens.clear();
+    static TokenIdxSet tmpTokens = TokenIdxSet();

    // Insert the token's name and the token in the (inserted?) list
-    size_t idx2 = m_Tree.AddItem(name,tmp_tokens,false);
-    TokenIdxSet& curlist = m_Tree.GetItemAtPos(idx2);
+    size_t idx = m_Tree.AddItem(name, tmpTokens);
+    TokenIdxSet& curList = m_Tree.GetItemAtPos(idx);
+
+    int newItem = AddTokenToList(newToken, fileIndex);
+    curList.insert(newItem);

-    int newitem = AddTokenToList(newToken,forceidx);
-    curlist.insert(newitem);
-    m_FilesMap[newToken->m_FileIdx].insert(newitem);
+    size_t fileIdx = (fileIndex<0) ? newToken->m_FileIdx : (size_t)fileIndex;
+    m_FilesMap[fileIdx].insert(newItem);

    // Add Token (if applicable) to the namespaces indexes
    if (newToken->m_ParentIndex < 0)
    {
        newToken->m_ParentIndex = -1;
-        m_GlobalNameSpace.insert(newitem);
+        m_GlobalNameSpace.insert(newItem);
        if (newToken->m_TokenKind == tkNamespace)
-            m_TopNameSpaces.insert(newitem);
+            m_TopNameSpaces.insert(newItem);
    }

    // All done!
-    return newitem;
+    return newItem;
}


The function parameter is "token index" as I see, but it was changed to "file index"?????

EDIT:
old:
int newitem = AddTokenToList(newToken,forceidx);

new:
int newItem = AddTokenToList(newToken, fileIndex);

I see that AddTokenToList() function's second parameter is the token index not file index.

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

#1
The lucky thing is:
size_t fileIdx = (fileIndex<0) ? newToken->m_FileIdx : (size_t)fileIndex;
Here, fileIndex is always < 0 (Unless we construct the Token tree from the cache)
So, the later code always works OK, because fileIdx is always newToken->m_FileIdx.
m_FilesMap[fileIdx].insert(newItem);
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

#2
Ok, a patch to fix this issue (include the CodeCompletion: fixes UnnamedStruct in the classBrowser)

EDIT: update to version 2 of the patch
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

Version 3 of the patch.
See attachment.
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.