Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => CodeCompletion redesign => Topic started by: ollydbg on November 13, 2013, 06:29:42 am

Title: Commit rev 6058 question
Post by: ollydbg on November 13, 2013, 06:29:42 am
When discuss this patch:
CodeCompletion: fixes UnnamedStruct in the classBrowser (https://developer.berlios.de/patch/index.php?func=detailpatch&patch_id=3494&group_id=5358), 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 (http://cb.biplab.in/websvn/comp.php?repname=codeblocks&compare[)

Code
-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:
Code
int newitem = AddTokenToList(newToken,forceidx);

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

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

Title: Re: Commit rev 6058 question
Post by: ollydbg on November 13, 2013, 07:48:56 am
The lucky thing is:
Code
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.
Code
m_FilesMap[fileIdx].insert(newItem);
Title: Re: Commit rev 6058 question
Post by: ollydbg on November 13, 2013, 08:50:39 am
Ok, a patch to fix this issue (include the CodeCompletion: fixes UnnamedStruct in the classBrowser (https://developer.berlios.de/patch/index.php?func=detailpatch&patch_id=3494&group_id=5358))

EDIT: update to version 2 of the patch
Title: Re: Commit rev 6058 question
Post by: ollydbg on November 17, 2013, 03:53:33 pm
Version 3 of the patch.
See attachment.