Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Technical Support
 Incorrect parsing of C++ namespaces

You must be registered to post a reply.
Click here to register.

Screensize:
UserName:
Password:
Format: BoldItalicizeUnderlineStrikethrough Align leftCenterAlign right Insert horizontal ruleUpload and insert imageInsert hyperlinkInsert email addressInsert codeInsert quoted textInsert listInsert Emoji
   
Message:

Forum code is on.
Html is off.

 
Check to subscribe to this topic.
   

T O P I C    R E V I E W
KirillMueller Posted - Jan 02 2008 : 1:44:23 PM
In my C++ code, in a file that I include from StdAfx.h, I have a declaration like this:

#ifdef _PC_LINT_

#define BEGIN_NAMESPACE namespace MyNamespace {
#define END_NAMESPACE }
#define USE_NAMESPACE using namespace MyNamespace

#else // #ifdef _PC_LINT_

#define BEGIN_NAMESPACE
#define END_NAMESPACE
#define USE_NAMESPACE /**/

#endif // #ifdef _PC_LINT_

// ...

BEGIN_NAMESPACE

// ...

class A {
// ...
};

class B {
// ...
};

END_NAMESPACE

USE_NAMESPACE


All classes are declared in a single .h, but the implementations are spread over different modules.

Apparently, this code isn't parsed correctly. When I position the caret over a member function, the left combobox in the source file window shows the namespace as part of the name. However, when positioning the caret over the definition of the method in the .cpp file, the namespace isn't included in the name.

Interestingly enough, using the declaration below fixes the problem:

#ifndef _PC_LINT_

#define BEGIN_NAMESPACE
#define END_NAMESPACE
#define USE_NAMESPACE /**/

#else // #ifndef _PC_LINT_

#define BEGIN_NAMESPACE namespace MyNamespace {
#define END_NAMESPACE }
#define USE_NAMESPACE using namespace MyNamespace

#endif // #ifndef _PC_LINT_


Can you reproduce this behavior for a small example?

How does VAX treat preprocessor macros that aren't defined anywhere? _PC_LINT_ is defined only when the code is lint-ed, no defining reference whatsoever in the sources.
7   L A T E S T    R E P L I E S    (Newest First)
feline Posted - Jan 04 2008 : 3:16:08 PM
I really do not see why this should have been causing problems, but I am glad you have found a solution.

Uniwares does something similar, so I wonder if your discovery will shed some light on the problems he is having. Thank you for the update!
KirillMueller Posted - Jan 04 2008 : 11:13:43 AM
It seems that the namespace thing sort of killed VAX's database. Now everything works like a charm.

Note that there's a syntax error in my example, which is not present in the code. The symbol USE_NAMESPACE cannot be used without a semicolon at the end. Could this make a difference?

I have altered the code now. I have


#ifndef _PC_LINT_

#define BEGIN_NAMESPACE(Namespace)
#define END_NAMESPACE(Namespace)
#define USE_NAMESPACE(Namespace)

#else // #ifndef _PC_LINT_

#define BEGIN_NAMESPACE(Namespace) namespace Namespace {
#define END_NAMESPACE(Namespace) }
#define USE_NAMESPACE(Namespace) using namespace Namespace

#endif // #ifndef _PC_LINT_


in a central header file, and I define


#define BEGIN_MY_NAMESPACE BEGIN_NAMESPACE(MyNamespace)


and so on in each project's header, and use these symbols. After rebuilding the database, everything is recognized properly.

I'll test that for a while now, and start a new thread if problems occur.
feline Posted - Jan 04 2008 : 10:39:30 AM
Odd. Are you still happy with just removing the namespace lines?

Something is going on here, but I am not quite sure what, and my initial tests did not reproduce the effect you are seeing with the namespace.
KirillMueller Posted - Jan 03 2008 : 2:34:39 PM
No, surprisingly enough, this didn't help. I've tried that already.
feline Posted - Jan 03 2008 : 2:31:43 PM
You might find that adding:

#define BEGIN_NAMESPACE
#define END_NAMESPACE
#define USE_NAMESPACE

to VA stdafx.h file as described here:

http://docs.wholetomato.com?W302

fixes the problems, and lets you keep your code unmodified.
KirillMueller Posted - Jan 03 2008 : 12:05:09 PM
Sorry, I forgot to post this. The workaround doesn't help anything. Only removing

#define BEGIN_NAMESPACE namespace MyNamespace {
#define END_NAMESPACE }
#define USE_NAMESPACE using namespace MyNamespace

altogether from the code fixes the problem. I can cope with that. Thanks for your comments.
feline Posted - Jan 03 2008 : 10:40:20 AM
I am not sure how your code is structured, so I have added the following code to a header file:

#ifdef _PC_LINT_

#define BEGIN_NAMESPACE namespace MyNamespace {
#define END_NAMESPACE }
#define USE_NAMESPACE using namespace MyNamespace

#else // #ifdef _PC_LINT_

#define BEGIN_NAMESPACE
#define END_NAMESPACE
#define USE_NAMESPACE /**/

#endif // #ifdef _PC_LINT_

BEGIN_NAMESPACE

class testNamespaceMacroOne {
	int getClassSize();
};

class testNamespaceMacroTwo {
	int getClassCount();
};

END_NAMESPACE

USE_NAMESPACE


and the following code to the matching cpp file, which includes the header file:

int testNamespaceMacroOne::getClassSize()
{
	return 0;
}

int testNamespaceMacroTwo::getClassCount()
{
	return 0;
}


For me VA shows the namespace name in the Definition field when I place the caret into the member function name "getClassSize" in both the header and cpp files.

The question of code parsing, it is not quite that simple. _PC_LINT_ might be defined some of the time and not defined some of the time. VA does not attempt to work out if this is defined or not. It normally uses the first definition of a macro that it finds.

This is done so that VA will offer you help with code that is not currently being compiled, e.g. UNIX specific code while editing under Windows.

If you want to force a specific interpretation of a macro try adding it to VA's stdafx.h file, as explained here:

http://docs.wholetomato.com?W302

This file is used to help VA's parser with difficult code, and can be used to work around odd effects. After modifying this file you need to rebuild the VA symbol database for the changes to take effect:

VA Options -> Performance -> General -> Rebuild symbol databases

© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000