User forums > Help

Find implementation / declaration fails with namespaces

<< < (2/3) > >>

ollydbg:

--- Quote from: Kalith on July 20, 2011, 10:37:59 am ---Indeed, Loaden's sample code works perfectly. That's the syntax I used in older files, but I've dropped it for the single line "using namespace".
I don't know how the CC parser works, but can't you do like a C++ compiler does ? When you read a "using namespace XX" directive, you temporarily bring to the current scope all the content of what has been previously parsed in this namespace/class.
Alternatively, you could check for each symbol found after a "using namespace XX" if is has any match both in the global scope and in namespace XX.
Depending on the size of the namespace and the file to parse, one or the other solution is better, but I guess the latter one would be the most efficient ("using namespace std", which is probably the most used one, sure contains a LOT of symbols...).

--- End quote ---
CC's parser do much less job than a compiler.

--- Quote ---you temporarily bring to the current scope all the content of what has been previously parsed in this namespace/class.
--- End quote ---
This sounds reasonable, but if the using directive is in a header file, also the header file was included in many cpp files, how can we deal with this? Currently, we just parse every file once, which means a header file will only be parsed once. This is much different with a C++ compiler. The compiler will do much dirty job, like preprocessing, which means a header file will be parsered several times in different translation unit. CC avoid doing that things to save time.


--- Quote ---Alternatively, you could check for each symbol found after a "using namespace XX" if is has any match both in the global scope and in namespace XX.
--- End quote ---
This is the same thing as before, which means we should do at least "semantic checking". which means we should maintain an "Exposed namespace set" dynamically. see the code below:


--- Code: ---#include "SomeHeader.h"
using namespace A;
void f()
{
    using namespace B;

    XXX;

    {
          using namespace C;
          YYY;
    }
}

ZZZ;


--- End code ---
When parsing the statement "YYY", we should the current exposed namespace set is
{A,B,C, namespace exposed in the "SomeHeader.h"}.

When parsing the statement "ZZZ", we only check the namespace
{A, namespace exposed in the "SomeHeader.h"}.

That's too complex for CC to remember all the exposed namespace scopes.

BTW: there are some code like:


--- Code: ---using B::b;
using A::a;
....
a;
b;

--- End code ---
which only introduce some variables or types of a namespace, which will make the semantic check more harder.

Finally, I think that's to complex for use.... C++'s grammar is toooo complex to write a simple parser. :D
This is why I some days ago suggest using some compiler directly, such as GCCsense or Clang.
search our forum for more details.
 :D



Kalith:
C++ is complex indeed... I understand that writing a real time parser is quite hard :shock:.
Dropping your current CC code for another library would be sad though. For all the hard work you've all put into it...
But it would surely release you of the burden.

Kalith:
I don't know if this is related, but I often get random crashes when typing, clinking on a function, or event exiting my compiled application.
There is a bug report attached, which seems to involve the CodeCompletion class.

Kalith:
The aforementioned crash still happens in the latest release from Jens' repository.
I'll fill in a bug report.
Any news on the original question though ?

ollydbg:
@kalith
Currently, the codecompletion was massively changed day by day in the trunk, so I would suggest you can try a more recent trunk version.(not sure which version in jens' repository).

from the crash, it seems the useful call stack is:

--- Code: ---<stack>
    <frame level="0" function="wxFatalSignalHandler" offset="00000026"/>
    <frame level="1"/>
    <frame level="2" function="wxChoice::GetCount() const" offset="00000053"/>
    <frame level="3" function="wxChoice::SetSelection(int)" offset="0000005c"/>
    <frame level="4" function="CodeCompletion::FindFunctionAndUpdate(int)" offset="00000155"/>
    <frame level="5" function="CodeCompletion::ParseFunctionsAndFillToolbar(bool)" offset="0000092d"/>
    <frame level="6" function="CodeCompletion::OnStartParsingFunctions(wxTimerEvent&amp;)" offset="0000002e"/>
    <frame level="7" function="wxAppConsole::HandleEvent(wxEvtHandler*, void (wxEvtHandler::*)(wxEvent&amp;), wxEvent&amp;) const" offset="0000003f"/>
    <frame level="8" function="wxEvtHandler::ProcessEventIfMatches(wxEventTableEntryBase const&amp;, wxEvtHandler*, wxEvent&amp;)" offset="00000079"/>
    <frame level="9" function="wxEventHashTable::HandleEvent(wxEvent&amp;, wxEvtHandler*)" offset="00000084"/>
    <frame level="10" function="wxEvtHandler::ProcessEvent(wxEvent&amp;)" offset="000000e7"/>
    <frame level="11" function="wxTimerBase::Notify()" offset="0000007d"/>
    <frame level="12"/>
    <frame level="13"/>
    <frame level="14" function="g_main_context_dispatch" offset="000001c8"/>
    <frame level="15"/>
    <frame level="16" function="g_main_loop_run" offset="0000017b"/>
    <frame level="17" function="gtk_main" offset="000000b9"/>
    <frame level="18" function="wxEventLoop::Run()" offset="00000048"/>
    <frame level="19" function="wxAppBase::MainLoop()" offset="0000004e"/>
    <frame level="20" function="wxAppBase::OnRun()" offset="00000021"/>
    <frame level="21"/>
  </stack>
--- End code ---
But even from this, I can't tell something useful to the bug.

the original question? which one, you want to enable the "scopeā€œ or the "context" info when parsing?

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version