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

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
Dusan Posted - May 31 2013 : 06:09:55 AM
Hello, I have found that when closing parenthesis is in conditional part, it is also considered in matching. Unfortunetly, I have only old version of VA, so I can not test if this is working on current one.

If I place carret on comment "place carret here", bracket and parenthesis marked as "mismatch" are considered mismatching.

static void bracket_matching_problem()
{ // mismatch
  int val = 0;

  // place carret here

  if ( val == 0 || 
#ifdef TEST_MACRO
    test_fnc1(val))
#else
    test_fnc2(val)) // mismatch
#endif
  {
    val = 1;
  }
}
3   L A T E S T    R E P L I E S    (Newest First)
accord Posted - Jun 03 2013 : 8:28:14 PM
Yes, you are absolutely right. This should work, since it's valid C++ code. The compiler have a lot more time, to figure out things, while VA should be fast even in very large projects. Preprocessor can really complicate things in C++ and slow parsing down.
Ifdefs are parsed like if both branches were valid which causes some side effects, unfortunately.
Dusan Posted - Jun 03 2013 : 02:16:42 AM
That code is just simple example, normally there is platform specific code, so I have no option to do it without macros.

I understand, how VA is designed, but if compiler accepts something as valid code, perhaps VA should handle it as well.

I can modify my code to get it working by moving last closing parenthesis outside of macro definitions.

Code in inactive parts of code is grayed out, so I think it should be not considered in bracket matching. I use this functionality to distinguish keying mistakes, so it took me a while to determine that I have not made any mistake, but it is caused by bracket matching...

However, now I know that this is expected, so I can write my code to satisfy VA's parser...

Perhaps we should also notice all other programmers of third party libraries to not use closing brackets in macro definitions, if we want correct bracket matching in VA... ;) Just kidding....
accord Posted - Jun 01 2013 : 09:13:01 AM
Visual Assist is designed to parse both the active and inactive source code, so for example, you can work on Release code while you set the solution configuration to Debug, etc. This approach usually works until you cut the code in pieces. Visual Assist don't and cannot distinguish between preprocessor branches, I'm afraid.

Personally, I would use something like the following, and it can be a workaround as well:

static void bracket_matching()
{
	int val = 0;

#ifdef TEST_MACRO
		if ( val == 0 || test_fnc1(val))
#else
		if ( val == 0 || test_fnc2(val))
#endif
	{
		val = 1;
	}
}

In fact, I usually prefer solutions without macros. So a bit more "C++ish" solution is the following:

template <bool test> void branch(int &val)
{
	if (val == 0 || (test ? test_fnc1(val) : test_fnc2(val)))
	{
		val = 1;
	}
}

const bool test_const = true;

void bracket()
{
	int val = 0;
	branch<test_const>(val);
}

But this is just a play with code and for testing purposes it would be overkill and not necessary. In an ideal world, VA should understand everything, but macro tricks are not always parsed correctly and this is one more reason for me to avoid them. (but not at all costs) Just my two cents.

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