GNOME Bugzilla – Bug 434515
Support conditional compilation
Last modified: 2009-04-03 07:41:28 UTC
Add support for basic conditional compilation constructs.
Maybe use attributes instead of preprocessor-like constructs.
It would be nice to have a support for macros. 1. #include <config.h> 2. Many headers define macros However, from the writer side it may look different (ie. I do not propose to include C preprocesor - I propose the evaluation to C preprocesor).
2008-01-17 Jürg Billeter <j@bitron.ch> * vala/parser.y, vala/valacodecontext.vala, compiler/valacompiler.vala: add [Conditional (condition = "CONDITION")] attribute for methods, fixes bug 434515 Fixed in r848.
Is this feature still supported? I tried to add a test in vala-tests, but that didn't seems to work as expected. It seems that the function ignore_node is no longer called anywhere. Jurg, could you comment? beta@pipo ~/git/gnome2/vala (master)$ ack-grep ignore_node vala/valacodecontext.h 78:gboolean vala_code_context_ignore_node (ValaCodeContext* self, ValaCodeNode* node); vala/valacodecontext.c 486:gboolean vala_code_context_ignore_node (ValaCodeContext* self, ValaCodeNode* node) { vala/vala.gidl 1069: <method name="ignore_node" symbol="vala_code_context_ignore_node"> build/vala/vala.gidl 1069: <method name="ignore_node" symbol="vala_code_context_ignore_node">
It's not working anymore for some time, however, I don't think we should just readd it as the implementation was questionable. As Vala projects usually distribute the generated C code, it doesn't make much sense to ignore nodes within valac. It would probably be a lot more useful to process everything in valac, however, make it possible to add #ifdef directives in the generated C code. This will probably require more changes in the compiler and I'm not sure about the syntax yet, any suggestions?
Generating generic C code with #ifdefs sounds like a complex task, I'm not expecting to get something like this into the compiler anytime soon. In the end it should not be necessary to distribute generated C code for most projects when we have a stable Vala compiler. In that case, supporting conditional compilation would be a lot easier. Maybe we should just implement that so that we can cover at least some use cases. For that purpose, the C# syntax makes sense to me. This would mean adding #if, #endif - without using a full preprocessor and without macro support.
commit 3f0e7474f8cb772cdd7e19f1e062d4706f8e598b Author: Jürg Billeter <j@bitron.ch> Date: Fri Apr 3 09:37:00 2009 +0200 Support conditional compilation Add -D SYMBOL commandline option to define conditional symbols. Support precondition directives #if, #elif, #else, and #endif. Fixes bug 434515.