Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Technical Support
 Macro Parenthesis matching bug

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
mortal2k Posted - Dec 11 2007 : 05:21:55 AM
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.
3   L A T E S T    R E P L I E S    (Newest First)
mortal2k Posted - Dec 11 2007 : 12:28:35 PM
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)
mortal2k Posted - Dec 11 2007 : 12:02:19 PM
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.
feline Posted - Dec 11 2007 : 08:47:05 AM
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.

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