Conditional Compilation -- #if !macro -- haxeSupport plug-in for intelliJ is acting oddly

84 views
Skip to first unread message

Arnim Schachtschabel

unread,
Aug 29, 2017, 12:50:30 PM8/29/17
to Haxe


Hello Community,

I am sorry, I have to bother you with a very banal topic.

I have just installed the update of intelliJ and also the haxeSupport plug-in.

I have prepared the project structure properly ( ProjectStructure/ProjectSetting/Modules/Haxe/Project Macros ) by adding 'js' and 'macro'.

So the regular cases are recognized correctly by intellJ.

And they look like this.

#if macro
public function great()
{}
#end

The trouble start, when I want to tell the machine to compile a code in case it is NOT macro (or NOT js).

#if !macro
public function great()
{}
#end
 

The code still is commented out, which would be correct if it would be a not matched target.

But    #if  !macro    is needed in the same compilation like   #if macro   .   And of cause, I would like to read the code of either cases like the regular code.

I have also tried to put another '!macro' to the Project Structure. Without success...

Is there a setting, that I have overseen?
Should I post an issue at the according git pages of the repository?


Can anybody help me out?

Kind regards
Arnim

Greybeard

unread,
Aug 30, 2017, 1:42:46 AM8/30/17
to Haxe
Hi Arnim,

You can post an issue on the repository if you like.  I'll answer it either way (Greybeard == Eric Bishton), so this user group is also fine.

Putting '!macro' in the project definitions won't work.  The NOT prefix ('!') is never recognized as a name; it is always an operator when parsing the code, so it can never match a definition in the definitions list.

Definitions in Haxe are defined as "true" by default.  If you want to define them to something else (a string or any constant value), you can add ' =true|false|<float>|<int>|"string value" ' to the definition.  So, just placing 'macro' in the definitions is the same as 'macro=true'.

The 'macro' definition behaves the same as any other definition.  That is, code inside an "#if macro ... #end" block is mutually exclusive with "#if !macro ... #end".  They are not both defined at the same time.  That said, the *compiler* does two passes over the code, within a single compile run - setting the value differently during the macro pass.  That is likely why you think of the definition of 'macro' differently than, say, a platform definition.

Currently, there is no way to pretend that any definition can be both set and unset -- or have multiple values.  There is also no way to turn on or off the processing of definitions at the moment.

Now, as to solutions:  

It may be possible to note that certain definitions are multiply defined.  It certainly is possible to run the definition calculation multiple times -- but then, how to display that?  Only highlight if all passes have a true result??

Another possibility is to ignore all conditionals and try to highlight the code as if the conditional statement wasn't there -- kind of like the pre-0.10.0 (plugin version) days.  That had its own problems though -- not the least that the parser got confused easily if you didn't write your code just right (e.g. it had to be valid with all conditional sections present).  It also causes issues with find, goto definition, refactoring, coloring, error detection, and on and on.  This is why I spent a good deal of time restoring that functionality.

There are definitely improvements that can be made.  I'd like to set up 'definition sets' that can be easily swapped between (sort of like the project file allows with '--next').  And I think it would be interesting to 'auto-swap' between definition sets just by placing your cursor into a block that you would like to see highlighted. (There are some other technical issues to be overcome for that to be feasible.)  And I'm sure that other folks have their own ideas.  I encourage everybody to add their desired features to the github repo (https://github.com/HaxeFoundation/intellij-haxe/issues.  

I'm sorry that the plugin doesn't have a way to do exactly what you want right now.  Document the way you think it should work (in an issue) and we'll see what can be done about it.  (BTW, there is already an issue about colorizing all sections as if the conditional compilation directives were not there -- feel free to add to it.)

-Eric

Arnim Schachtschabel

unread,
Aug 30, 2017, 3:54:52 AM8/30/17
to Haxe
Hello Eric,

thank you for your sophisticated and detailed answer.

That makes it a lot clearer.

When I was thinking about the topic again, I realized that the case of using   !macro   is a very special and seldom case. It just occured as I have added some fields to a class during compilation and to prevent an error to be thrown at compile time.

So the issue is not as painfull as I initially thought. But I will write a reminder to inspire your work for future developement.

So thanks again.

Kind regard
Arnim


Reply all
Reply to author
Forward
0 new messages