Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: humjack on July 11, 2012, 09:43:29 pm

Title: Questions on "Gray out Inactive Preprocessor Code"
Post by: humjack 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
Title: Re: Questions on "Gray out Inactive Preprocessor Code"
Post by: ollydbg 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 (http://forums.codeblocks.org/index.php/topic,16249.0.html), if you code can be compiled by clang, then I think this plugin can help to implement the "Gray out Inactive Preprocessor Code".
Title: Re: Questions on "Gray out Inactive Preprocessor Code"
Post by: Jenna 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 (http://forums.codeblocks.org/index.php/topic,16249.0.html), 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).
Title: Re: Questions on "Gray out Inactive Preprocessor Code"
Post by: humjack 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
Title: Re: Questions on "Gray out Inactive Preprocessor Code"
Post by: Calmarius 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.
Title: Re: Questions on "Gray out Inactive Preprocessor Code"
Post by: Jenna 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 ..." ?
Title: Re: Questions on "Gray out Inactive Preprocessor Code"
Post by: Joerg 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.

Title: Re: Questions on "Gray out Inactive Preprocessor Code"
Post by: pmlonline 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.
Title: Re: Questions on "Gray out Inactive Preprocessor Code"
Post by: oBFusCATed 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.
Title: Re: Questions on "Gray out Inactive Preprocessor Code"
Post by: pmlonline 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?
Title: Re: Questions on "Gray out Inactive Preprocessor Code"
Post by: oBFusCATed 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).
Title: Re: Questions on "Gray out Inactive Preprocessor Code"
Post by: ollydbg 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 (http://forums.codeblocks.org/index.php/topic,20767.msg141604.html#msg141604), you can have a look.