diff options
author | Björn Gustavsson <[email protected]> | 2015-09-29 09:24:32 +0200 |
---|---|---|
committer | Tomas Abrahamsson <[email protected]> | 2018-05-09 08:38:32 +0200 |
commit | 109b1dc2e346efc37f8c5cfecbf0fa2a476b14fa (patch) | |
tree | 14ccd4985eb44013c27250a9ae05dd76b80e9265 /bootstrap/lib/stdlib/ebin/erl_parse.beam | |
parent | 55e852080d459b9b2be18cf41de60c3338f266af (diff) | |
download | otp-109b1dc2e346efc37f8c5cfecbf0fa2a476b14fa.tar.gz otp-109b1dc2e346efc37f8c5cfecbf0fa2a476b14fa.tar.bz2 otp-109b1dc2e346efc37f8c5cfecbf0fa2a476b14fa.zip |
epp: Implement the -if and -elif preprocessor directives
Libraries or applications that support more than one major
release of OTP may need to use conditional compilation of
Erlang source code. Here are few examples where it would be
necessary or desirable:
* To support a new data type or language feature only available
in the latest major release (real-world examples: maps and the
stacktrace syntax).
* To avoid warnings for deprecated functions.
* To avoid dialyzer warnings.
Previously, to do conditional compilation, one would have to
use a parse transform or some external tool such as 'autoconf'.
To simplify conditional compilation, introduce the -if and -elif
preprocessor directives, to allow code like this to be written:
-if(?OTP_RELEASE =:= 21).
%% Code that will only work in OTP 21.
-else.
%% Fallback code.
-endif.
What kind of expressions should be allowed after an -if?
We certainly don't want to allow anything with a side effect,
such as a '!' or a 'receive'. We also don't want it to be
possible to call erlang:system_info/1, as that could make the
code depedent on features of the run-time system that could
change very easily (such as the number of schedulers).
Requiring the expression to be a guard expression makes most
sense. It is to explain in the documentation and easy for users
to understand. For simplicity of implementation, only a single
guard expression will be supported; that is, the ',' and ';' syntax
for guards is not supported.
To allow some useful conditions to be written, there is a special
built-in function:
defined(Symbol) tests whether the preprocessor symbol is defined,
just like -ifdef. The reason for having this defined/1 is that
the defined test can be combined with other tests, for example:
'defined(SOME_NAME) andalso ?OTP_RELEASE > 21'.
Diffstat (limited to 'bootstrap/lib/stdlib/ebin/erl_parse.beam')
0 files changed, 0 insertions, 0 deletions