News:

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

Main Menu

CodeBlocks cash when "Find declaration " on some symbol

Started by nanyu, February 06, 2011, 04:20:49 AM

Previous topic - Next topic

ollydbg

Quote from: MortenMacFly on February 23, 2011, 11:08:13 AM
Instead of all this copying (not sure how wxStringTokenizer is implemented though... :oops:)?
I'm not sure whether Tokenizer will depend on the wxString, so I just do a copy to avoid the risk :).

QuoteAnd what about the commented stuff? You change functionality here... was that on purpose (what about side-effects)?
Yes, I do change the functionality, but I'm not sure why we care about "local" characters of a token.

So, my patch is only a "candidate to avoid crash". :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.

MortenMacFly

Quote from: ollydbg on February 23, 2011, 12:51:38 PM
I'm not sure whether Tokenizer will depend on the wxString, so I just do a copy to avoid the risk :).
Checking the sources revealed a copy is made internally. So you don't need to do this. ;-)
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]

ollydbg

the code snippet:

       if (!token->m_IsLocal) // global symbols are linked once
       {
           //Manager::Get()->GetMessageManager()->DebugLog("Removing ancestor string from %s", token->m_Name.c_str(), token->m_Name.c_str());
           token->m_AncestorsString.Clear();
       }

was added in rev 1711 by rick22 with the log:

Quoterickg22  2006-1-11 15:19:20            
Revamped the CodeCompletion plugin, Stage 1. Reparsing after saving files is much faster now. Also, the code completion functionality is much faster due to the searchtree structure.
Known issues: The Class browser is NOT updated when using the cache. WARNING: Might cause crashes if you have the cache enabled. Please disable it.

I'm not sure why a token with m_IsLocal==true does NOT allowed to remove the m_AncestorsString. But currently rick is not maintain the CC's code, So I guess he nearly forget something. I'll PM him about this.

From my point of view, there is no reason we should keep the ancestorstring if we already use it to calculate the hierarchy. :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.

ollydbg

#18
see the source code:


void TokensTree::RecalcData()
{
#if CC_TOKEN_DEBUG_OUTPUT
   wxStopWatch sw;
#endif

   TRACE(_T("RecalcData() : Calculating full inheritance tree."));
   // first loop to convert ancestors string to token indices for each token
   for (size_t i = 0; i < size(); ++i)
   {
       Token* token = at(i);
       if (!token)
           continue;

       if (!(token->m_TokenKind & (tkClass | tkTypedef | tkEnum | tkNamespace)))
           continue;
       if (token->m_AncestorsString.IsEmpty())
           continue;
       // only local symbols might change inheritance
//        if (!token->m_IsLocal)
//            continue;




the last two line was comment out in rev 2855 by mandrav.

Note: currently, the function RecalcData() is not used in CC. we use a new method to dynamically call the hierarchy. which is:


class A :public B,C{};
class D :public B,C{};
class C :public X{};


Once the parser finish parsing, then, A's ancestorString is "B,C", D's ancestorString is "B,C", and C's ancestorString is "X".
Now, every thing is OK, we do not call RecalcData(). What's RecalcData() does can divided to two stages:

1, transform the ancestorString to ancestor Idx on evey tokens of the tree. so, A's ancestorIdx will have index to Token B, and index C
  D's ancestorIdx will have index to Token B, and index C ; D's ancestorIdx will have index to Token X. no further hierarchy is calculated.    meanwhile, all the ancestorString will be cleared.(as they were transform to Idxs)

2, calculate the full hierarchy, which means a recursive function call:
  A's ancestorIdx will have index to Token B, Token C and Token X.  (Token X added by calculate the hierarchy)
  D's ancestorIdx will have index to Token B, and Token C and Token X. (Token X added by calculate the hierarchy)
  C's ancestorIdx will have index to Token X. (the same as stage 1)

The currently way we use was "calculate the fully hierarchy on the Tokens we would like to use". which means if we want to query information of Token A, we only calculate the "stage 1 and stage 2" on the exact token A.


BTW:
This thread was suggested to move to CC's sub forum to record such info. :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.

ollydbg

patch v2.

Index: token.cpp
===================================================================
--- token.cpp (revision 7028)
+++ token.cpp (working copy)
@@ -1039,8 +1039,12 @@

     TRACE(_T("RecalcInheritanceChain() : Token %s, Ancestors %s"), token->m_Name.wx_str(),
           token->m_AncestorsString.wx_str());
-
     wxStringTokenizer tkz(token->m_AncestorsString, _T(","));
+
+    TRACE(_T("RecalcInheritanceChain() : Removing ancestor string from %s"), token->m_Name.wx_str());
+    token->m_AncestorsString.Clear();
+
+
     while (tkz.HasMoreTokens())
     {
         wxString ancestor = tkz.GetNextToken();
@@ -1111,11 +1115,6 @@

         token->m_DirectAncestors = token->m_Ancestors;

-        if (!token->m_IsLocal) // global symbols are linked once
-        {
-            TRACE(_T("RecalcInheritanceChain() : Removing ancestor string from %s"), token->m_Name.wx_str());
-            token->m_AncestorsString.Clear();
-        }
     }

#if CC_TOKEN_DEBUG_OUTPUT

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

@loaden:
I think the way you use in rev 6306 is still accepted if we can avoid the crash on calculating the class/namespace hierarchy. :D
http://forums.next.codeblocks.org/index.php/topic,14167.msg95899.html#msg95899
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.

nanyu

thanks for your work. Will this patch apply on next nightly build?

ollydbg

Quote from: ollydbg on February 27, 2011, 03:57:25 AM
I'm not sure why a token with m_IsLocal==true does NOT allowed to remove the m_AncestorsString. But currently rick is not maintain the CC's code, So I guess he nearly forget something. I'll PM him about this.
he replied that he can't not remember that. :(

Quote from: nanyu on February 27, 2011, 09:00:00 AM
thanks for your work. Will this patch apply on next nightly build?
depend on devs (mostly, Morten or Loaden). :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.

ollydbg

Quote from: nanyu on February 27, 2011, 09:00:00 AM
thanks for your work. Will this patch apply on next nightly build?
FYI:
Hi, nanyu, the revision 7157 has this fixed. :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.

nanyu

Quote from: ollydbg on May 24, 2011, 04:22:09 AM
Quote from: nanyu on February 27, 2011, 09:00:00 AM
thanks for your work. Will this patch apply on next nightly build?
FYI:
Hi, nanyu, the revision 7157 has this fixed. :D
thk for your work.