Epp Bugfix and macros overloading

christopher faulet christopher.faulet@REDACTED
Fri Oct 9 16:31:44 CEST 2009


Hi all,

Here are two patches for the module epp in R13B02-1.

* The first one fixes a bug in the function scan_undef. The dict that
helps to find circular macros is not correctly updated. Here is an example:

=============================
-module(test).
-export([test/0]).

-define(FOO(X), ?BAR(X)).
-define(BAR(X), ?FOO(X)).
-undef(FOO).

test() ->
    ?BAR(1).
=============================

On the last line, the preprocessor should found that 'FOO' is undefined.
But, with the current version, it finds a cycle between FOO and BAR.

* The second patch includes the first one and adds support of multiple
definitions for macros in the module epp (i.e. with the same name but
with different arities). This feature wouldn't break any code (I hope so
:) and might be usefull.

Here is an simple example that uses it:

=============================
-module(test).

-export([test/0]).

-define(MY_MACRO(),    foo).
-define(MY_MACRO,      bar).
-define(MY_MACRO(X,Y), {X, Y}).


test() ->  %% return [bar, foo, foo, {foo, bar}]
    [
     ?MY_MACRO,          %% use the 2nd def, replaced by bar
     ?MY_MACRO(),        %% use the 1st def, replaced by foo
     ?MY_MACRO(foo),     %% use the 2nd def, replaced by bar(foo)
     ?MY_MACRO(foo, bar) %% use the 3rd def, replaced by {foo,bar}
    ].

bar(X) ->
    X.
=============================

In this patch, we follow these rules:

- the overloading of predefined macros (?MODULE, ?LINE, ...) is forbidden
- the directive '-undef' removes all definitions of a macro
- when a macro is called, the preprocessor tries to match the definition
with the right number of arguments. If it fails, it uses the constant
definition, if there is one, else returns an error.
- the circular definitions are checked following the previous rule.

It would be interesting to add this feature. What do you think about it?

Best regards,
-- 
Christopher Faulet <christopher.faulet@REDACTED>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bugfix-epp-R13B02-1.patch
Type: text/x-patch
Size: 940 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-patches/attachments/20091009/5bf3a2b8/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: overload-epp-R13B02-1.patch
Type: text/x-patch
Size: 10034 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-patches/attachments/20091009/5bf3a2b8/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 260 bytes
Desc: OpenPGP digital signature
URL: <http://erlang.org/pipermail/erlang-patches/attachments/20091009/5bf3a2b8/attachment-0002.bin>


More information about the erlang-patches mailing list