Author Topic: tagging and preprocessor macros  (Read 4945 times)

boo

  • Community Member
  • Posts: 16
  • Hero Points: 0
tagging and preprocessor macros
« on: August 08, 2007, 11:47:11 pm »

Would you tell me if this tagging is allowed:

Code: [Select]
#define MACRO(var) int var

typedef struct {
  MACRO(x);
} mystruct_type;

mystruct_type m;

For some reason typing "m." the "x" does not pop-up. How can this be done?

Thanks!

Kohei

  • Senior Community Member
  • Posts: 192
  • Hero Points: 25
Re: tagging and preprocessor macros
« Reply #1 on: August 09, 2007, 03:07:15 am »
You need to set that macro in Tools > Options > Tagging Options > C Preprocessing.  Just click New to define a new preprocessing macro, type the name of the macro, and make sure its value is set correctly (it should give you a list of choices so you can just pick the right value for the macro).  Once done, retag your workspace so that the tagging engine can correctly expand your new macro.

One caveat is that this is a global setting, not per workspace or project.  So if you are on multiple workspaces that use same macro names for different things, then you need to reset the macro values when switching workspaces...

Hope this helps.

Kohei

boo

  • Community Member
  • Posts: 16
  • Hero Points: 0
Re: tagging and preprocessor macros
« Reply #2 on: August 09, 2007, 03:41:33 am »
You need to set that macro in Tools > Options > Tagging Options > C Preprocessing.  Just click New to define a new preprocessing macro, type the name of the macro, and make sure its value is set correctly (it should give you a list of choices so you can just pick the right value for the macro).  Once done, retag your workspace so that the tagging engine can correctly expand your new macro.

One caveat is that this is a global setting, not per workspace or project.  So if you are on multiple workspaces that use same macro names for different things, then you need to reset the macro values when switching workspaces...

Hope this helps.

Kohei

Hi Kohei,

Thanks for your reply. I'm looking for something a bit more sophisticated than that. When preprocessor macros are really interface definitions, macros that create typedefs and function definitions, things become more cumbersome.

Code: [Select]
#define DECLARE_INTERFACE(iface_name) \
  struct iface_name##_vtable_type* vtable;

typedef struct {
  DECLARE_INTERFACE(custom);
} custom_iface_type;

#define CUSTOM_INTERFACE_METHODS(iface_name) \
  void (*myfuncA) (iface_name##_iface_type* This, int param1); \
  void (*myfuncB) (iface_name##_iface_type* This, int param1);

typedef struct {
  CUSTOM_INTERFACE_METHODS(custom);
} custom_iface_vtable_type;

int main (void)
{
  custom_iface_type* custom_instance;

  // initialize custom_instance
 
  custom_instance->vtable->myfuncA(custom_instance, 123); // use the function
  custom_instance-> // nothing pops up
  custom_instance->vtable-> // nothing pops up

  return 0;
}

You see without the auto-tagging working it's very painful having to refer to the header files. This is no school project so rewriting things is not an option.

Kohei

  • Senior Community Member
  • Posts: 192
  • Hero Points: 25
Re: tagging and preprocessor macros
« Reply #3 on: August 09, 2007, 01:58:38 pm »
Quote
Thanks for your reply. I'm looking for something a bit more sophisticated than that. When preprocessor macros are really interface definitions, macros that create typedefs and function definitions, things become more cumbersome.

Yes, I hear you. :)  My codebase also has lots of elements that are just like your example, and yes it's cumbersome (and I hate it).

But unless I'm mistaken, there is no easier way to deal with preprocessing macros than what I already suggested.

You can also take a look at this thread http://community.slickedit.com/index.php?topic=1743.0 for our past discussions on this topic.

hs2

  • Senior Community Member
  • Posts: 2754
  • Hero Points: 291
Re: tagging and preprocessor macros
« Reply #4 on: August 09, 2007, 02:51:04 pm »
Confirmed. This kind of meta-programming-by-preprocessor stuff is used in a project a friend is working on ( converted him to SE ;) ).
He already contacted support concerning this issue.
HS2