Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Technical Support
 Macro Parenthesis matching bug
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mortal2k
New Member

3 Posts

Posted - Dec 11 2007 :  05:21:55 AM  Show Profile  Reply with Quote
I am using a commercial game engine that uses a macro extensively. The problem is that this macro will invalidate all symbols after it is used, as if braces were unmatched. Visual Assist will show errors in all the code that follows the macro and I cannot use Alt-G anymore.

I have tested this in Visual Assist X 10.3 and 10.4 releases with VS2005. If I right-click->Go to Definition with VS2005, it will go to the definition. Alt-G will do nothing while it works before I use the Macro.

To reproduce the bug, do the following.

#define some_return_bool return (bool

#define SomeMacro(className,returnType) \        some_return_bool ) NULL; \        static returnType c##className(className *object)

struct SomeObject
{
	void someFunction()
};

SomeMacro(SomeObject, bool)
{
	//definition field is blank when I click someFunction()
	object->someFunction();
}


The problem is the parenthesis matching between macros and everything will work fine if
some_return_bool ) NULL; \\

was changed to
return (bool) NULL; \\


For many reasons, I cannot fix this in the code.

Thank you.

feline
Whole Tomato Software

United Kingdom
18939 Posts

Posted - Dec 11 2007 :  08:47:05 AM  Show Profile  Reply with Quote
I am not quite sure what the problem here is. It is possible VA is confused by the ## operator in the second macro. However I don't understand your example. Where does the variable "object" come from?

It should be possible to work around the problem. The trick is to show VA a macro it understands, and have it use that macro instead of the confusing one.

Either place this simpler macro further up this file, so VA's parser see's it before it sees the real macro:

#if 0
// macro for VA
#define SomeMacro(...) ...
#endif

#define some_return_bool return (bool

#define SomeMacro(className,returnType) \        some_return_bool ) NULL; \        static returnType c##className(className *object)


or place the simpler macro into VA's stdafx.h file as explained in this FAQ entry:

http://docs.wholetomato.com?W302

Since I don't really understand your example I cannot suggest a suitable replacement macro.

zen is the art of being at one with the two'ness
Go to Top of Page

mortal2k
New Member

3 Posts

Posted - Dec 11 2007 :  12:02:19 PM  Show Profile  Reply with Quote
You can paste the code in VS2005 in a new .cpp file and see that Visual Assist X will get confused in parenthesis matching when the return_bool macro is used. VA does not get confused with the ## operator.

The macro that I provided you does not make any sense in this context and I will try to explain it and make it simpler. This is also the code that you can use to test the bug:


#define return_bool return (bool

//declares a function that returns bool by casting NULL to bool
//also defines the beginning of a static function that takes
//as argument a pointer to a SomeObject object and the argument name is object
//the problem is only in the some_return_bool) part were
//the macro should expand to return (bool) but it gets confused
#define SomeMacro() \	bool function_bool() {return_bool)1;} \	static bool staticFunction(SomeObject *object)

struct SomeObject
{
	void someFunction()
};

SomeMacro()
{
        //click someFunction to test
        //will not work when macro defined with return_bool
        //and will work if defined with return(bool instead
	object->someFunction();
}


and all of this will expand to:

struct SomeObject
{
	void someFunction()
};

bool function_bool() 
{
	return(bool)1;
};

static bool staticFunction(SomeObject *object)
{
	object->someFunction();
}


If you paste this code in VS2005, it will show the behavior.
Paste the code and then click over someFunction, symbols will not work.

If you then replace return_bool by return (bool, the definition of someFunction will show in the definition field next to the context field. The problem is exactly the expansion of return_bool.

The actual macro in the engine is used to generate static functions that return specific types. Here I used bool in the example, but the functions can get generated with bool, void, int, const char *.

The actual code looks like the following:

#define conmethod_return_const              return (const
#define conmethod_return_S32                return (S32
#define conmethod_return_F32                return (F32
#define conmethod_nullify(val)
#define conmethod_return_void               conmethod_nullify(void
#define conmethod_return_bool               return (bool
#  define ConsoleMethod(className,name,returnType,minArgs,maxArgs,usage1)                             \      static inline returnType c##className##name(className *, S32, const char **argv);               \      static returnType c##className##name##caster(SimObject *object, S32 argc, const char **argv) {  \         AssertFatal( dynamic_cast<className*>( object ), "Object passed to " #name " is not a " #className "!" ); \         return (returnType) c##className##name(static_cast<className*>(object),argc,argv);              \      };                                                                                              \      static ConsoleConstructor className##name##obj(#className,#name,c##className##name##caster,usage1,minArgs,maxArgs); \      static inline returnType c##className##name(className *object, S32 argc, const char **argv)

and it is used about 1000 times like this:

ConsoleMethod( MyObject, rebuild, bool, 2, 2, "()")
{
	object->rebuild();
}


I will look into stdafx.h.

Thank you.
Go to Top of Page

mortal2k
New Member

3 Posts

Posted - Dec 11 2007 :  12:28:35 PM  Show Profile  Reply with Quote
Thank you, the stdAfx method worked worked! To fix my last example code, all I had to do was to put the following in stdafx.h were it did not define the function using return_bool.

#define SomeMacro() \	static bool staticFunction(SomeObject *object)


and in my real code, I have put the following in stdAfx:
#  define ConsoleMethod(className,name,returnType,minArgs,maxArgs,usage1)                             \      static inline returnType c##className##name(className *object, S32 argc, const char **argv)
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000