Author Topic: Questions on "Gray out Inactive Preprocessor Code"  (Read 17214 times)

Offline humjack

  • Single posting newcomer
  • *
  • Posts: 4
Questions on "Gray out Inactive Preprocessor Code"
« on: July 11, 2012, 09:43:29 pm »
[Skip to # list below for questions]

First and foremost, I have been using C::B as my work editor of choice for over a year now, and have recommended it to others as well. I work in embedded development, and my project includes hundreds of files and a whole mess of preprocessor definitions to support our various product versions. All I have to do is #define one of these values in an included header file, and the code completion preprocessor parser handles this beautifully project-wide.

What I find lacking is the option I am teased with called "Gray out Inactive Preprocessor Code" in the general editor settings. I've seen a few mentions of this when searching the forums, but no real response or concern following them. I'll get to it:

1) Inactive preprocessor code is straight-up black, not gray. This makes it much less obvious for those of us who use black as a default text color, thus sort of defeating the purpose of the feature.

2) The feature does not work across multiple files within a project. I have tested this with the simplest single .cpp + .hpp file project. Defining the macro in the header file will still result in code being grayed out in the .cpp file. It has to be defined specifically in the same file I am looking at.


In my opinion these issues make the feature useless in any real project scenario, and makes me wonder why it is included in a default installation of C::B... It's unfortunate because I would really benefit from it if it was a little more robust. Perhaps it could be tied into the preprocessor parsing capability of code completion. As you can guess, I have no C::B development experience so I have no idea what kind of an undertaking this would be.

Mostly I am just curious if this is on anyone's radar, as it has been this way for quite some time now. I am currently using a nightly build from a couple weeks ago.


`Zach

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5128
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Questions on "Gray out Inactive Preprocessor Code"
« Reply #1 on: July 12, 2012, 02:28:59 am »
my project includes hundreds of files and a whole mess of preprocessor definitions to support our various product versions. All I have to do is #define one of these values in an included header file, and the code completion preprocessor parser handles this beautifully project-wide.
The parser in our code-completion plugin does not work 100% precise compared to a normal c++/c compiler. It does not expand the #include directive as a normal C preprocessor. This means it can not know which macro is defined or not in a cpp file. So, the information from code-completion plugin can not be used for "Gray out Inactive Preprocessor Code".

To make it work, I think you can look at some developing plugins like: Semantic highlight, if you code can be compiled by clang, then I think this plugin can help to implement the "Gray out Inactive Preprocessor Code".
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Questions on "Gray out Inactive Preprocessor Code"
« Reply #2 on: July 12, 2012, 06:32:30 am »
my project includes hundreds of files and a whole mess of preprocessor definitions to support our various product versions. All I have to do is #define one of these values in an included header file, and the code completion preprocessor parser handles this beautifully project-wide.
The parser in our code-completion plugin does not work 100% precise compared to a normal c++/c compiler. It does not expand the #include directive as a normal C preprocessor. This means it can not know which macro is defined or not in a cpp file. So, the information from code-completion plugin can not be used for "Gray out Inactive Preprocessor Code".

To make it work, I think you can look at some developing plugins like: Semantic highlight, if you code can be compiled by clang, then I think this plugin can help to implement the "Gray out Inactive Preprocessor Code".
The option in question is a scintilla option (if I remmeber correctly), based on the scintilla lexers and not a codecompletion option, so it does not know anything about other files content or global defines (e.g. from the build options).

Offline humjack

  • Single posting newcomer
  • *
  • Posts: 4
Re: Questions on "Gray out Inactive Preprocessor Code"
« Reply #3 on: July 12, 2012, 08:58:22 pm »
I'll keep an eye out for Semantic highlight (looks to still be a work in progress at the moment). I'll make sure to update this thread if I can manage to get things working the way I'd like.

Thanks for the input regarding code-competion - I was unaware of its shortcomings, it has always seemed to parse the macros properly on my projects.

`Zach

Offline Calmarius

  • Multiple posting newcomer
  • *
  • Posts: 32
Re: Questions on "Gray out Inactive Preprocessor Code"
« Reply #4 on: July 04, 2013, 02:56:37 pm »
Just upgraded CB to 12.11 at work. And this gray out preprocessor thing caught me off guard...

The project uses makefiles for compiling, and almost every preprocessor thing is defined in these makefiles.

Now every positive #ifdef and #if defined blocks are grayed out. I see no option to turn inactive thing off.

The only workaround so far is defining the inactive colors to be the same as the normal color.

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Questions on "Gray out Inactive Preprocessor Code"
« Reply #5 on: July 04, 2013, 03:19:01 pm »
Just upgraded CB to 12.11 at work. And this gray out preprocessor thing caught me off guard...

The project uses makefiles for compiling, and almost every preprocessor thing is defined in these makefiles.

Now every positive #ifdef and #if defined blocks are grayed out. I see no option to turn inactive thing off.

The only workaround so far is defining the inactive colors to be the same as the normal color.
Did you try to uncheck "Settings -> Editor -> General settings -> C/C++ Editor settings -> Colouring and highlighting options -> Interpret #if ..." ?

Offline Joerg

  • Multiple posting newcomer
  • *
  • Posts: 100
Re: Questions on "Gray out Inactive Preprocessor Code"
« Reply #6 on: July 30, 2013, 10:57:56 am »
just to throw in my two cents:

I like the feature in general, but it is not working as it pretends.
The option 'collect defines from project file' gives the impression that #defines in other files would be parsed and evaluated.
But in my C file everything is greyed out, though #defines are placed in an include file, included directly by this file.
The project structure is really quite simple.

It's never too late to fail!

Offline pmlonline

  • Single posting newcomer
  • *
  • Posts: 7
Re: Questions on "Gray out Inactive Preprocessor Code"
« Reply #7 on: November 30, 2018, 10:33:19 pm »
I just tested this on Windows 10 and Lubuntu and it's not looking into include files. Does anyone know where the code is located? I'll take a quick look to see if it's an easy fix.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11279
    • Travis build status
Re: Questions on "Gray out Inactive Preprocessor Code"
« Reply #8 on: December 01, 2018, 08:05:52 am »
lex_cpp.cpp probably. It is not an easy fix...
You have to implement the include searching logic of a compiler and also somehow pass the compile parameters to the editor.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline pmlonline

  • Single posting newcomer
  • *
  • Posts: 7
Re: Questions on "Gray out Inactive Preprocessor Code"
« Reply #9 on: December 01, 2018, 03:30:04 pm »
It looks like it scans through the file without scanning through the include files. If there's already existing code that scans through include files then maybe we could use that code. Doesthe Goto declaration and Goto implementation scan through include files?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11279
    • Travis build status
Re: Questions on "Gray out Inactive Preprocessor Code"
« Reply #10 on: December 01, 2018, 04:30:51 pm »
Yes, they do, but they are in a totally different part of the code (keep in mind that lex_cpp.cpp is part of scintilla which is external component).
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5128
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Questions on "Gray out Inactive Preprocessor Code"
« Reply #11 on: December 02, 2018, 08:37:33 am »
It looks like it scans through the file without scanning through the include files. If there's already existing code that scans through include files then maybe we could use that code. Doesthe Goto declaration and Goto implementation scan through include files?
In 2015, I have a patch to supply the macro definition from CodeCompletion plugin to the Scintilla, see this patch: Re: Conditional Code :: Blocks. highlighting in the editor, you can have a look.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.