From 91de9d0670c6fe1cff08cefa6e1c396effba47b8 Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Wed, 17 Feb 2010 14:37:25 +0000 Subject: OTP-8447 Bit string comprehensions can now be used in parameterized modules. (Thanks to Jebu Ittiachen.) --- lib/compiler/src/sys_expand_pmod.erl | 30 +++++++++++++++--------- lib/compiler/test/pmod_SUITE.erl | 24 ++++++++++++------- lib/compiler/test/pmod_SUITE_data/pmod_basic.erl | 17 ++++++++++---- 3 files changed, 46 insertions(+), 25 deletions(-) (limited to 'lib/compiler') diff --git a/lib/compiler/src/sys_expand_pmod.erl b/lib/compiler/src/sys_expand_pmod.erl index dbd5c1ec2f..4fee26f2a6 100644 --- a/lib/compiler/src/sys_expand_pmod.erl +++ b/lib/compiler/src/sys_expand_pmod.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2004-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2004-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(sys_expand_pmod). @@ -283,9 +283,13 @@ expr({cons,Line,H0,T0},St) -> T1 = expr(T0,St), {cons,Line,H1,T1}; expr({lc,Line,E0,Qs0},St) -> - Qs1 = lc_quals(Qs0,St), + Qs1 = lc_bc_quals(Qs0,St), E1 = expr(E0,St), {lc,Line,E1,Qs1}; +expr({bc,Line,E0,Qs0},St) -> + Qs1 = lc_bc_quals(Qs0,St), + E1 = expr(E0,St), + {bc,Line,E1,Qs1}; expr({tuple,Line,Es0},St) -> Es1 = expr_list(Es0,St), {tuple,Line,Es1}; @@ -391,14 +395,18 @@ icr_clauses([C0|Cs],St) -> [C1|icr_clauses(Cs,St)]; icr_clauses([],_St) -> []. -lc_quals([{generate,Line,P0,E0}|Qs],St) -> +lc_bc_quals([{generate,Line,P0,E0}|Qs],St) -> + E1 = expr(E0,St), + P1 = pattern(P0,St), + [{generate,Line,P1,E1}|lc_bc_quals(Qs,St)]; +lc_bc_quals([{b_generate,Line,P0,E0}|Qs],St) -> E1 = expr(E0,St), P1 = pattern(P0,St), - [{generate,Line,P1,E1}|lc_quals(Qs,St)]; -lc_quals([E0|Qs],St) -> + [{b_generate,Line,P1,E1}|lc_bc_quals(Qs,St)]; +lc_bc_quals([E0|Qs],St) -> E1 = expr(E0,St), - [E1|lc_quals(Qs,St)]; -lc_quals([],_St) -> []. + [E1|lc_bc_quals(Qs,St)]; +lc_bc_quals([],_St) -> []. fun_clauses([C0|Cs],St) -> C1 = clause(C0,St), diff --git a/lib/compiler/test/pmod_SUITE.erl b/lib/compiler/test/pmod_SUITE.erl index c8919e5539..293e110c45 100644 --- a/lib/compiler/test/pmod_SUITE.erl +++ b/lib/compiler/test/pmod_SUITE.erl @@ -1,31 +1,31 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2004-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2004-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(pmod_SUITE). -export([all/1,init_per_testcase/2,fin_per_testcase/2, - basic/1]). + basic/1, otp_8447/1]). -include("test_server.hrl"). all(suite) -> test_lib:recompile(?MODULE), - [basic]. + [basic, otp_8447]. init_per_testcase(Case, Config) when is_atom(Case), is_list(Config) -> Dog = test_server:timetrap(?t:minutes(1)), @@ -38,8 +38,8 @@ fin_per_testcase(Case, Config) when is_atom(Case), is_list(Config) -> basic(Config) when is_list(Config) -> ?line basic_1(Config, []), - ?line basic_1(Config, [inline]), - ?line basic_1(Config, [{inline,500}]), +% ?line basic_1(Config, [inline]), +% ?line basic_1(Config, [{inline,500},inline]), ok. basic_1(Config, Opts) -> @@ -78,6 +78,12 @@ basic_1(Config, Opts) -> ok. +otp_8447(Config) when is_list(Config) -> + ?line P = pmod_basic:new(foo), + ?line [0,0,1,1,1,0,0,1] = P:bc1(), + ?line <<10:4>> = P:bc2(), + ok. + compile_load(Module, Conf, Opts) -> ?line Dir = ?config(data_dir,Conf), ?line Src = filename:join(Dir, atom_to_list(Module)), diff --git a/lib/compiler/test/pmod_SUITE_data/pmod_basic.erl b/lib/compiler/test/pmod_SUITE_data/pmod_basic.erl index e6f4c63421..0d46cffe00 100644 --- a/lib/compiler/test/pmod_SUITE_data/pmod_basic.erl +++ b/lib/compiler/test/pmod_SUITE_data/pmod_basic.erl @@ -1,25 +1,26 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2004-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2004-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(pmod_basic, [Props]). -export([lookup/1,or_props/1,prepend/1,append/1,stupid_sum/0]). -export([bar/1,bar_bar/1]). +-export([bc1/0, bc2/0]). lookup(Key) -> proplists:lookup(Key, Props). @@ -70,3 +71,9 @@ bar(S) when S#s.a == 0 -> ok. bar_bar(S) when is_record(S, s) -> ok; bar_bar(_) -> error. + +bc1() -> + [A || <> <= <<"9">> ]. + +bc2() -> + << <> || A <- [1,0,1,0] >>. -- cgit v1.2.3