Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Feature Requests
 Extended enumeration highlighting

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
Millianz Posted - Oct 27 2011 : 3:31:40 PM
Hello,

I ran into a slight problem enums today. I'm not sure if Visual Assist can do anything about it, but if it is possible it would be great to fix this in the future:

Assume there is a header file with the following contents

REGISTER_MESSAGE(CORE_STARTUP)
REGISTER_MESSAGE(CORE_SHUTDOWN)


and is called "messagenames.h"

In another header, messages.h the following setup can be found:

#pragma once

#define REGISTER_MESSAGE(x) x,
typedef enum
{
  #include "messagenames.h"
  NUM_MESSAGES
} Messages;
#undef REGISTER_MESSAGE

#define REGISTER_MESSAGE(x) #x,
static char const gMessageNames[] = 
{
  #include "messagenames.h"
  "Invalid"
};
#undef REGISTER_MESSAGE



I now have an enum that is kept in sync automatically with the associated strings of the same name. But both, Visual Studio and Visual Assist fail to do proper syntax highglighting when I use the enum entries for more than 3 enumerations.

4   L A T E S T    R E P L I E S    (Newest First)
feline Posted - Oct 28 2011 : 6:26:54 PM
This makes a bit more sense. You can do some very clever, but also rather opaque things with the pre-processor.

If your main problem is the enum items CORE_STARTUP and CORE_SHUTDOWN not being recognised or coloured correctly, you could simply add:

#ifdef VA_HELPER_CODE
#define CORE_STARTUP
#define CORE_SHUTDOWN
#endif

or

#ifdef VA_HELPER_CODE
enum VA_HELPER_REGISTER_MESSAGE { CORE_STARTUP, CORE_SHUTDOWN };
#endif

I know this is a work around, but it is a quick and simple one.
mwb1100 Posted - Oct 28 2011 : 1:11:02 PM
quote:
Originally posted by feline

I am totally confused, and have no idea what this is supposed to be doing.


Just as an FYI: this is a not-too-common technique that is sometimes called "X-Macros": http://en.wikibooks.org/wiki/C_Programming/Preprocessor#X-Macros

Millianz Posted - Oct 28 2011 : 01:19:27 AM
Hi,

I tried what was suggested under the link you posted but that didn't seem to resolve the issue.
To clarify the above example:

messagenames.h only contains lines containing REGISTER_MESSAGE(messagename), no other code or include guards.

When the preprocessor parses "messages.h" it copy pastes the contents of messagenames.h into where it was included.

Since the macro REGISTER_MESSAGES is defined right above the use, it is defined once it's copy pasted into the enum / array initializer list. For the enum, the macro is defined to simply copy paste the contents of the macro into the enum followed by a comman. For the array, the macro stringizes the arguments of the macro and inserts those strings comma separated.

So after the preprocessor expands the example above the file "messages.h" would look something like this:


#define REGISTER_MESSAGE(x) x,
typedef enum
{
  CORE_STARTUP,
  CORE_SHUTDOWN,
  NUM_MESSAGES
} Messages;
#undef REGISTER_MESSAGE

#define REGISTER_MESSAGE(x) #x,
static char const gMessageNames[] = 
{
  "CORE_STARTUP",
  "CORE_SHUTDOWN",
  "Invalid"
};
#undef REGISTER_MESSAGE


The purpose of this trick: stringizing enums. Basically now it's possible to use the enum as both an int (for quick identification of a symbol, say index into a std::map using the enum value), while maintaining an array of corresponding strings.

gMessageNames[CORE_STARTUP] equals "CORE_STARTUP"

feline Posted - Oct 27 2011 : 5:37:26 PM
I am totally confused, and have no idea what this is supposed to be doing.

If I have followed correctly, the header file "messagenames.h" contains the uses of the macros, but the macros themselves include the header file that contains the uses of the macros, which sounds like an infinite look in the making to me, which presumably the #pragma once saves you from.

Can you explain the problem you are having with syntax highlighting?

You might want to try telling VA to parse macros more deeply, as explained here:

http://docs.wholetomato.com?W363

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