User forums > Help
Find implementation / declaration fails with namespaces
Kalith:
Hi,
I've created a bug report for this issue in march, but it has received no comments since then.
The "Find implementation" and "Find declaration" methods (I guess it is the CodeCompletion plugin ?) fail in the following case :
--- Code: ---namespace Foo
{
class Bar
{
public :
Bar();
void SomeFunction();
};
}
using namespace Foo;
Bar::Bar()
{
}
void Bar::SomeFunction()
{
}
--- End code ---
Try with "SomeFunction".
I'm using SVN 7282 on Ubuntu.
ollydbg:
I can confirm this is a bug. (I test with latest trunk)
currently I'm too busy, so I guess I can't have much time to debug this.
ollydbg:
The bug is related to the change of
rev 6823 by loaden
--- Quote ---loaden 2010-11-4 8:19:39
* special handle function overloading for 'Goto declaration' and 'Goto implementation'
--- End quote ---
on the code:
--- Code: --- // special handle for function overloading
if (result.size() > 1)
{
const size_t curLine = editor->GetControl()->GetCurrentLine() + 1;
for (TokenIdxSet::iterator it = result.begin(); it != result.end(); ++it)
{
Token* tk = tokens->at(*it);
if (tk)
{
if (tk->m_Line == curLine || tk->m_ImplLine == curLine)
{
const int theOnlyOne = *it;
result.clear();
result.insert(theOnlyOne);
break;
}
}
}
}
--- End code ---
In you test code, the parser find two declaration of "SomeFunction".
Note: the parser do not handle scope information, so even you use "using namespace Foo"; the second "SomeFunction" will be added as another Token.
Which means, there are two Tokens:
--- Code: ---Foo::Bar::SomeFunction
Bar::SomeFunction
--- End code ---
But the code change in rev 6823 just delete the first Token in the result, and only add the later one.
So, we should refine the code snippet above.
Loaden:
--- Code: ---namespace Foo
{
class Bar
{
public :
Bar();
void SomeFunction();
};
}
namespace Foo
{
Bar::Bar()
{
}
void Bar::SomeFunction()
{
}
}
--- End code ---
Should works well.
So, the real question is how to solved "using namespace foo;" issue.
see: https://developer.berlios.de/bugs/?func=detailbug&group_id=5358&bug_id=17988
That's not easy.
I have not good idea about that.
Kalith:
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...).
Navigation
[0] Message Index
[#] Next page
Go to full version