Author Topic: Can I color C/C++ function macros differently than constant macros?  (Read 5007 times)

CGAllred

  • New Community Member
  • Posts: 1
  • Hero Points: 0
I just started using SlickEdit, having come from Source Insight.  SI treats the following #defines differently for the purpose of symbol coloring:

#define FOO 0xf00

#define FlagOn(F,SF) ( \
    (((F) & (SF)))     \
)

For symbol coloring SI can treat the first as though it were a constant, and the second as though it were a function.  This means I can have them show up in different colors in the code.

Can I get SE's symbol coloring to make that distinction?

jb

  • Community Member
  • Posts: 37
  • Hero Points: 0
Re: Can I color C/C++ function macros differently than constant macros?
« Reply #1 on: June 04, 2009, 09:30:15 pm »
I just started using SlickEdit, having come from Source Insight.  SI treats the following #defines differently for the purpose of symbol coloring:

#define FOO 0xf00

#define FlagOn(F,SF) ( \
    (((F) & (SF)))     \
)

For symbol coloring SI can treat the first as though it were a constant, and the second as though it were a function.  This means I can have them show up in different colors in the code.
Basically I think it would be nice if object-like macros and function-like macros could be displayed differently.
However in my opinion it is a bad idea to display macro symbols like non-macro symbols because the goal should be to avoid macros whenever possible. So I find it important to recognize macros easily. For the very same reason there is also an old, common convention to use only uppercase characters for macro names.

Can I get SE's symbol coloring to make that distinction?
I don't think so because only one symbol type ("Preprocessor macro") is related to macros and the regular expression for the symbol name is applied only to the name itself, not to its context, that is, a regular expression such as \:v(?=\() that requires the macro name to be followed by '(' would never match.

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2571
  • Hero Points: 386
Re: Can I color C/C++ function macros differently than constant macros?
« Reply #2 on: June 04, 2009, 10:04:51 pm »
The basic color coding capabilities in SlickEdit allow you to assign a different color (usually just BOLD font attributes) to identifiers which are followed by a parenthesis, presumably Function calls.  This can be configured by modifying the "Function" color under the Color options dialog (not Symbol Coloring).

I am going to add a feature to Symbol Coloring so that "Function" colored identifiers, when colored by symbol coloring will inherit the font attributes from the "Function" color specified in the Color options.

This will make it possible for you to distinguish between constant-like macros and function-like macros, because the function ones will be bolded (presuming you use the default bold color for Functions).  You will not be able to assign a different color to the Function-like macros, but it should be good enough.

This change will be available in the 14.0.2 patch release.

jb

  • Community Member
  • Posts: 37
  • Hero Points: 0
Re: Can I color C/C++ function macros differently than constant macros?
« Reply #3 on: June 05, 2009, 05:18:02 am »
I am going to add a feature to Symbol Coloring so that "Function" colored identifiers, when colored by symbol coloring will inherit the font attributes from the "Function" color specified in the Color options.

This will make it possible for you to distinguish between constant-like macros and function-like macros, because the function ones will be bolded (presuming you use the default bold color for Functions).  You will not be able to assign a different color to the Function-like macros, but it should be good enough.
I agree that this solution is good enough.
By the way the term "object-like macros" is more accurate than "constant-like macros". Why? See http://gcc.gnu.org/onlinedocs/cpp/Object_002dlike-Macros.html#Object_002dlike-Macros
« Last Edit: June 05, 2009, 05:37:49 am by jb »

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2571
  • Hero Points: 386
Re: Can I color C/C++ function macros differently than constant macros?
« Reply #4 on: June 08, 2009, 05:47:55 pm »
That's fair enough.  I think I still prefer the term constant-like macro because it encourages people to use preprocessing in a more human-decipherable manner.  Maybe my thinking is old-school, so be it.

I have always hoped that that future of C/C++ would be to sever or at least restrict the dependency on the preprocessor, but, alas, that is another entire philosophical debate.

jb

  • Community Member
  • Posts: 37
  • Hero Points: 0
Re: Can I color C/C++ function macros differently than constant macros?
« Reply #5 on: June 09, 2009, 05:22:53 am »
I think the primary criterion for a technical term should be correctness, not preference.
Willynilly the current C++ standard allows to define object-like macros and I bet that the soon coming next C++ standard won't change that.
I find that macros should be used sparingly and that unfortunately many programmers use them without a good reason.
It seems that you dislike macros even more.
But anyway how are the chances that the SlickEdit tagger will support object-like macros perfectly?
How much would it increase the complexity of the SlickEdit tagger in terms of performance and size of the vtg file?
See also "Re: Tagging/Context problem with #define?" (about object-like macros and the 'Auto-list members' feature).
« Last Edit: June 09, 2009, 04:20:09 pm by jb »