From 90efeaf21147505b1e8207822e606027f94183cc Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Thu, 28 Mar 2013 08:52:43 +0100 Subject: Forbid unsized fields in patterns of binary generators It makes no sense to be able to do `<<...,Rest/binary>> <= ...` in a comprehension. The related Dialyzer test is removed. --- lib/compiler/test/bs_bincomp_SUITE.erl | 38 ++-------------------------------- 1 file changed, 2 insertions(+), 36 deletions(-) (limited to 'lib/compiler/test/bs_bincomp_SUITE.erl') diff --git a/lib/compiler/test/bs_bincomp_SUITE.erl b/lib/compiler/test/bs_bincomp_SUITE.erl index 451a9b1e3b..6140320728 100644 --- a/lib/compiler/test/bs_bincomp_SUITE.erl +++ b/lib/compiler/test/bs_bincomp_SUITE.erl @@ -25,7 +25,7 @@ init_per_group/2,end_per_group/2, byte_aligned/1,bit_aligned/1,extended_byte_aligned/1, extended_bit_aligned/1,mixed/1,filters/1,trim_coverage/1, - nomatch/1,sizes/1,tail/1]). + nomatch/1,sizes/1]). -include_lib("test_server/include/test_server.hrl"). @@ -35,7 +35,7 @@ all() -> test_lib:recompile(?MODULE), [byte_aligned, bit_aligned, extended_byte_aligned, extended_bit_aligned, mixed, filters, trim_coverage, - nomatch, sizes, tail]. + nomatch, sizes]. groups() -> []. @@ -290,40 +290,6 @@ sizes(Config) when is_list(Config) -> ?line cs_end(), ok. -tail(Config) when is_list(Config) -> - ?line [] = tail_1(<<0:7>>), - ?line [0] = tail_1(<<0>>), - ?line [0] = tail_1(<<0:12>>), - ?line [0,0] = tail_1(<<0:20>>), - - ?line [] = tail_2(<<0:7>>), - ?line [42] = tail_2(<<0>>), - ?line [] = tail_2(<<0:12>>), - ?line [42,42] = tail_2(<<0,1>>), - - ?line <<>> = tail_3(<<0:7>>), - ?line <<42>> = tail_3(<<0>>), - ?line <<42>> = tail_3(<<0:12>>), - ?line <<42,42>> = tail_3(<<0:20>>), - - ?line [] = tail_4(<<0:15>>), - ?line [7] = tail_4(<<7,8>>), - ?line [9] = tail_4(<<9,17:12>>), - ok. - -tail_1(Bits) -> - [X || <> <= Bits]. - -tail_2(Bits) -> - [42 || <<_:8/integer, _/bytes>> <= Bits]. - -tail_3(Bits) -> - << <<42>> || <<_:8/integer, _/bits>> <= Bits >>. - -tail_4(Bits) -> - [X || <> <= Bits, bit_size(Tail) >= 8]. - - cs_init() -> erts_debug:set_internal_state(available_internal_state, true), ok. -- cgit v1.2.1 From 738c34d4bb8f1a3811acd00af8c6c12107f8315b Mon Sep 17 00:00:00 2001 From: Bruce Yinhe Date: Thu, 18 Jun 2015 11:31:02 +0200 Subject: Change license text to APLv2 --- lib/compiler/test/bs_bincomp_SUITE.erl | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'lib/compiler/test/bs_bincomp_SUITE.erl') diff --git a/lib/compiler/test/bs_bincomp_SUITE.erl b/lib/compiler/test/bs_bincomp_SUITE.erl index 4450405695..1bf4e9d4a7 100644 --- a/lib/compiler/test/bs_bincomp_SUITE.erl +++ b/lib/compiler/test/bs_bincomp_SUITE.erl @@ -3,16 +3,17 @@ %% %% Copyright Ericsson AB 2006-2013. 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. +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. %% %% %CopyrightEnd% %% -- cgit v1.2.1 From 03fcb7dabf8861e60ffab4121a909b347bccfec9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Mon, 15 Feb 2016 15:33:12 +0100 Subject: Eliminate use of test_server.hrl and test_server_line.hrl As a first step to removing the test_server application as as its own separate application, change the inclusion of test_server.hrl to an inclusion of ct.hrl and remove the inclusion of test_server_line.hrl. --- lib/compiler/test/bs_bincomp_SUITE.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/compiler/test/bs_bincomp_SUITE.erl') diff --git a/lib/compiler/test/bs_bincomp_SUITE.erl b/lib/compiler/test/bs_bincomp_SUITE.erl index 1bf4e9d4a7..d9865c3746 100644 --- a/lib/compiler/test/bs_bincomp_SUITE.erl +++ b/lib/compiler/test/bs_bincomp_SUITE.erl @@ -28,7 +28,7 @@ extended_bit_aligned/1,mixed/1,filters/1,trim_coverage/1, nomatch/1,sizes/1]). --include_lib("test_server/include/test_server.hrl"). +-include_lib("common_test/include/ct.hrl"). suite() -> [{ct_hooks,[ts_install_cth]}]. -- cgit v1.2.1 From fc3c64711400be9eae653350213630cb8cb257f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Thu, 25 Feb 2016 16:12:09 +0100 Subject: Remove ?line macros --- lib/compiler/test/bs_bincomp_SUITE.erl | 200 +++++++++++++++++---------------- 1 file changed, 102 insertions(+), 98 deletions(-) (limited to 'lib/compiler/test/bs_bincomp_SUITE.erl') diff --git a/lib/compiler/test/bs_bincomp_SUITE.erl b/lib/compiler/test/bs_bincomp_SUITE.erl index d9865c3746..93bce5c1f6 100644 --- a/lib/compiler/test/bs_bincomp_SUITE.erl +++ b/lib/compiler/test/bs_bincomp_SUITE.erl @@ -55,110 +55,114 @@ end_per_group(_GroupName, Config) -> byte_aligned(Config) when is_list(Config) -> cs_init(), - ?line <<"abcdefg">> = cs(<< <<(X+32)>> || <> <= <<"ABCDEFG">> >>), + <<"abcdefg">> = cs(<< <<(X+32)>> || <> <= <<"ABCDEFG">> >>), <<1:32/little,2:32/little,3:32/little,4:32/little>> = cs(<< <> || <> <= <<1:32,2:32,3:32,4:32>> >>), - ?line cs(<<1:32/little,2:32/little,3:32/little,4:32/little>> = - << <> || <> <= <<1:16,2:16,3:16,4:16>> >>), + cs(<<1:32/little,2:32/little,3:32/little,4:32/little>> = + << <> || <> <= <<1:16,2:16,3:16,4:16>> >>), cs_end(). bit_aligned(Config) when is_list(Config) -> cs_init(), - ?line <<$a:7,$b:7,$c:7,$d:7,$e:7,$f:7,$g:7>> = + <<$a:7,$b:7,$c:7,$d:7,$e:7,$f:7,$g:7>> = cs(<< <<(X+32):7>> || <> <= <<"ABCDEFG">> >>), - ?line <<"ABCDEFG">> = + <<"ABCDEFG">> = cs(<< <<(X-32)>> || <> <= <<$a:7,$b:7,$c:7,$d:7,$e:7,$f:7,$g:7>> >>), - ?line <<1:31/little,2:31/little,3:31/little,4:31/little>> = + <<1:31/little,2:31/little,3:31/little,4:31/little>> = cs(<< <> || <> <= <<1:31,2:31,3:31,4:31>> >>), - ?line <<1:31/little,2:31/little,3:31/little,4:31/little>> = + <<1:31/little,2:31/little,3:31/little,4:31/little>> = cs(<< <> || <> <= <<1:15,2:15,3:15,4:15>> >>), cs_end(). extended_byte_aligned(Config) when is_list(Config) -> cs_init(), - ?line <<"abcdefg">> = cs(<< <<(X+32)>> || X <- "ABCDEFG" >>), - ?line "abcdefg" = [(X+32) || <> <= <<"ABCDEFG">>], - ?line <<1:32/little,2:32/little,3:32/little,4:32/little>> = + <<"abcdefg">> = cs(<< <<(X+32)>> || X <- "ABCDEFG" >>), + "abcdefg" = [(X+32) || <> <= <<"ABCDEFG">>], + <<1:32/little,2:32/little,3:32/little,4:32/little>> = cs(<< <> || X <- [1,2,3,4] >>), - ?line [256,512,768,1024] = + [256,512,768,1024] = [X || <> <= <<1:16,2:16,3:16,4:16>>], cs_end(). extended_bit_aligned(Config) when is_list(Config) -> cs_init(), - ?line <<$a:7,$b:7,$c:7,$d:7,$e:7,$f:7,$g:7>> = + <<$a:7,$b:7,$c:7,$d:7,$e:7,$f:7,$g:7>> = cs(<< <<(X+32):7>> || X <- "ABCDEFG" >>), - ?line "ABCDEFG" = [(X-32) || <> <= <<$a:7,$b:7,$c:7,$d:7,$e:7,$f:7,$g:7>>], - ?line <<1:31/little,2:31/little,3:31/little,4:31/little>> = + "ABCDEFG" = [(X-32) || <> <= <<$a:7,$b:7,$c:7,$d:7,$e:7,$f:7,$g:7>>], + <<1:31/little,2:31/little,3:31/little,4:31/little>> = cs(<< <> || X <- [1,2,3,4] >>), - ?line [256,512,768,1024] = + [256,512,768,1024] = [X || <> <= <<1:15,2:15,3:15,4:15>>], cs_end(). mixed(Config) when is_list(Config) -> cs_init(), - ?line <<2,3,3,4,4,5,5,6>> = + <<2,3,3,4,4,5,5,6>> = cs(<< <<(X+Y)>> || <> <= <<1,2,3,4>>, <> <= <<1,2>> >>), - ?line <<2,3,3,4,4,5,5,6>> = + <<2,3,3,4,4,5,5,6>> = << <<(X+Y)>> || <> <= <<1,2,3,4>>, Y <- [1,2] >>, - ?line <<2,3,3,4,4,5,5,6>> = + <<2,3,3,4,4,5,5,6>> = cs(<< <<(X+Y)>> || X <- [1,2,3,4], Y <- [1,2] >>), One = id([1,2,3,4]), Two = id([1,2]), - ?line <<2,3,3,4,4,5,5,6>> = + <<2,3,3,4,4,5,5,6>> = cs(<< <<(X+Y)>> || X <- One, Y <- Two >>), - ?line [2,3,3,4,4,5,5,6] = + [2,3,3,4,4,5,5,6] = [(X+Y) || <> <= <<1,2,3,4>>, <> <= <<1,2>>], - ?line [2,3,3,4,4,5,5,6] = + [2,3,3,4,4,5,5,6] = [(X+Y) || <> <= <<1,2,3,4>>, Y <- [1,2]], - ?line <<2:3,3:3,3:3,4:3,4:3,5:3,5:3,6:3>> = + <<2:3,3:3,3:3,4:3,4:3,5:3,5:3,6:3>> = cs(<< <<(X+Y):3>> || <> <= <<1:3,2:3,3:3,4:3>>, <> <= <<1:3,2:3>> >>), - ?line <<2:3,3:3,3:3,4:3,4:3,5:3,5:3,6:3>> = + <<2:3,3:3,3:3,4:3,4:3,5:3,5:3,6:3>> = cs(<< <<(X+Y):3>> || <> <= <<1:3,2:3,3:3,4:3>>, Y <- [1,2] >>), - ?line <<2:3,3:3,3:3,4:3,4:3,5:3,5:3,6:3>> = + <<2:3,3:3,3:3,4:3,4:3,5:3,5:3,6:3>> = cs(<< <<(X+Y):3>> || X <- [1,2,3,4], Y <- [1,2] >>), - ?line <<2:3,3:3,3:3,4:3,4:3,5:3,5:3,6:3>> = + <<2:3,3:3,3:3,4:3,4:3,5:3,5:3,6:3>> = cs_default(<< <<(X+Y):3>> || {X,Y} <- [{1,1},{1,2},{2,1},{2,2}, {3,1},{3,2},{4,1},{4,2}] >>), - ?line [2,3,3,4,4,5,5,6] = + [2,3,3,4,4,5,5,6] = [(X+Y) || <> <= <<1:3,2:3,3:3,4:3>>, <> <= <<1:3,2:3>>], - ?line [2,3,3,4,4,5,5,6] = + [2,3,3,4,4,5,5,6] = [(X+Y) || <> <= <<1:3,2:3,3:3,4:3>>, {_,Y} <- [{a,1},{b,2}]], cs_end(). filters(Config) when is_list(Config) -> cs_init(), - ?line <<"BDF">> = - cs_default(<< <<(X-32)>> || <> <= <<$a:7,$b:7,$c:7,$d:7,$e:7,$f:7,$g:7>>, - X rem 2 == 0>>), - ?line <<"abc">> = cs_default(<< <<(X+32)>> || X <- "ABCDEFG", - is_less_than(X, $D)>>), - ?line <<"efg">> = cs_default(<< <<(X+32)>> || X <- "ABCDEFG", - not is_less_than(X, $E)>>), - ?line <<"b">> = cs_default(<< <<(X+32)>> || X <- "ABCDEFG", - is_less_than(X, $D), - X rem 2 == 0>>), - ?line <<"eg">> = cs_default(<< <<(X+32)>> || X <- "ABCDEFG", - not is_less_than(X, $E), - X rem 2 == 1>>), + <<"BDF">> = + cs_default(<< <<(X-32)>> || + <> <= <<$a:7,$b:7,$c:7,$d:7,$e:7,$f:7,$g:7>>, + X rem 2 == 0>>), + <<"abc">> = cs_default(<< <<(X+32)>> || + X <- "ABCDEFG", + is_less_than(X, $D)>>), + <<"efg">> = cs_default(<< <<(X+32)>> || + X <- "ABCDEFG", + not is_less_than(X, $E)>>), + <<"b">> = cs_default(<< <<(X+32)>> || + X <- "ABCDEFG", + is_less_than(X, $D), + X rem 2 == 0>>), + <<"eg">> = cs_default(<< <<(X+32)>> || + X <- "ABCDEFG", + not is_less_than(X, $E), + X rem 2 == 1>>), %% Filtering by a non-matching pattern. - ?line <<"abd">> = cs_default(<< <> || - <<0:1,X:7>> <= <<$a:8,$b:8,1:1,$c:7,$d:8, - 1:1,$e:7,0:4>> >>), + <<"abd">> = cs_default(<< <> || + <<0:1,X:7>> <= <<$a:8,$b:8,1:1,$c:7,$d:8, + 1:1,$e:7,0:4>> >>), - ?line <<42,42>> = cs_default(<< <<42:8>> || - 42 <- [1,2,3,42,43,42] >>), + <<42,42>> = cs_default(<< <<42:8>> || 42 <- [1,2,3,42,43,42] >>), cs_end(). is_less_than(X, C) when X < C -> true; is_less_than(_, _) -> false. trim_coverage(Config) when is_list(Config) -> - ?line <<0,0,0,2,0,0,5,48,0,11,219,174,0,0,0,0>> = coverage_materialiv(a, b, {1328,777134}), - ?line <<67,40,0,0,66,152,0,0,69,66,64,0>> = coverage_trimmer([42,19,777]), - ?line <<0,0,2,43,0,0,3,9,0,0,0,3,64,8,0,0,0,0,0,0, + <<0,0,0,2,0,0,5,48,0,11,219,174,0,0,0,0>> = coverage_materialiv(a, b, {1328,777134}), + <<67,40,0,0,66,152,0,0,69,66,64,0>> = coverage_trimmer([42,19,777]), + <<0,0,2,43,0,0,3,9,0,0,0,3,64,8,0,0,0,0,0,0, 64,68,0,0,0,0,0,0,192,171,198,0,0,0,0,0>> = coverage_lightfv(555, 777, {3.0,40.0,-3555.0}), ok. @@ -186,109 +190,109 @@ coverage_trimmer(Params) -> coverage_summer(A, B, C, D) -> A+B+C+D. nomatch(Config) when is_list(Config) -> - ?line <<>> = << <> || X = {_,_} = [_|_] <- [1,2,3] >>, + <<>> = << <> || X = {_,_} = [_|_] <- [1,2,3] >>, ok. sizes(Config) when is_list(Config) -> - ?line cs_init(), + cs_init(), Fun0 = fun(List) -> cs(<< <> || E <- List >>) end, - ?line <<>> = Fun0([]), - ?line <<1>> = Fun0([1]), - ?line <<1,2>> = Fun0([1,2]), - ?line <<1,2,3>> = Fun0([1,2,3]), + <<>> = Fun0([]), + <<1>> = Fun0([1]), + <<1,2>> = Fun0([1,2]), + <<1,2,3>> = Fun0([1,2,3]), Fun1 = fun(List) -> cs(<< <> || E <- List >>) end, - ?line <<>> = Fun1([]), - ?line <<1:16>> = Fun1([1]), - ?line <<1:16,2:16>> = Fun1([1,2]), - ?line <<1:16,2:16,3:16>> = Fun1([1,2,3]), + <<>> = Fun1([]), + <<1:16>> = Fun1([1]), + <<1:16,2:16>> = Fun1([1,2]), + <<1:16,2:16,3:16>> = Fun1([1,2,3]), Fun2 = fun(List) -> cs(<< <> || E <- List >>) end, - ?line <<>> = Fun2([]), - ?line <<1:4>> = Fun2([1]), - ?line <<1:4,13:4>> = Fun2([1,13]), - ?line <<1:4,13:4,7:4>> = Fun2([1,13,7]), - ?line <<0:1000/unit:8>> = Fun2(lists:duplicate(2000, 0)), + <<>> = Fun2([]), + <<1:4>> = Fun2([1]), + <<1:4,13:4>> = Fun2([1,13]), + <<1:4,13:4,7:4>> = Fun2([1,13,7]), + <<0:1000/unit:8>> = Fun2(lists:duplicate(2000, 0)), Fun3 = fun(List) -> cs(<< <> || E <- List >>) end, - ?line <<>> = Fun3([]), - ?line <<40,177,29:5>> = Fun3([1,2,1,3,0,7,5]), - ?line <<0:512/unit:3>> = Fun3(lists:duplicate(512, 0)), + <<>> = Fun3([]), + <<40,177,29:5>> = Fun3([1,2,1,3,0,7,5]), + <<0:512/unit:3>> = Fun3(lists:duplicate(512, 0)), Fun4 = fun(List, Size) -> cs(<< <> || E <- List >>) end, - ?line <<>> = Fun4([], 8), - ?line <<42:6>> = Fun4([42], 6), - ?line <<42:16>> = Fun4([42], 16), + <<>> = Fun4([], 8), + <<42:6>> = Fun4([42], 6), + <<42:16>> = Fun4([42], 16), Fun5 = fun(List, Sz1, Sz2, Sz3) -> cs(<< <> || E <- List >>) end, - ?line <<>> = Fun5([], 1, 1, 1), - ?line <<7:3,8:40,9:56>> = Fun5([7], 3, 5, 7), + <<>> = Fun5([], 1, 1, 1), + <<7:3,8:40,9:56>> = Fun5([7], 3, 5, 7), Fun6 = fun(List, Size) -> cs(<< <> || E <- List >>) end, - ?line <<>> = Fun6([], 42), - ?line <<42,43:20>> = Fun6([42], 20), + <<>> = Fun6([], 42), + <<42,43:20>> = Fun6([42], 20), %% Binary generators. Fun10 = fun(Bin) -> cs(<< <> || <> <= Bin >>) end, - ?line <<>> = Fun10(<<>>), - ?line <<1:16>> = Fun10(<<1>>), - ?line <<1:16,2:16>> = Fun10(<<1,2>>), + <<>> = Fun10(<<>>), + <<1:16>> = Fun10(<<1>>), + <<1:16,2:16>> = Fun10(<<1,2>>), Fun11 = fun(Bin) -> cs(<< <> || <> <= Bin >>) end, - ?line <<>> = Fun11(<<>>), - ?line <<1>> = Fun11(<<1:16>>), - ?line <<1,2>> = Fun11(<<1:16,2:16>>), - ?line <<1,2>> = Fun11(<<1:16,2:16,0:1>>), - ?line <<1,2>> = Fun11(<<1:16,2:16,0:7>>), - ?line <<1,2>> = Fun11(<<1:16,2:16,42:8>>), - ?line <<1,2>> = Fun11(<<1:16,2:16,42:9>>), - ?line <<1,2>> = Fun11(<<1:16,2:16,255:15>>), + <<>> = Fun11(<<>>), + <<1>> = Fun11(<<1:16>>), + <<1,2>> = Fun11(<<1:16,2:16>>), + <<1,2>> = Fun11(<<1:16,2:16,0:1>>), + <<1,2>> = Fun11(<<1:16,2:16,0:7>>), + <<1,2>> = Fun11(<<1:16,2:16,42:8>>), + <<1,2>> = Fun11(<<1:16,2:16,42:9>>), + <<1,2>> = Fun11(<<1:16,2:16,255:15>>), Fun12 = fun(Bin, Sz1, Sz2) -> cs(<< <> || <> <= Bin >>) end, - ?line <<>> = Fun12(<<>>, 1, 1), - ?line Binary = list_to_binary(lists:seq(0, 255)), - ?line Binary = Fun12(Binary, 1, 1), - ?line Binary = Fun12(Binary, 4, 4), - ?line Binary = Fun12(Binary, 8, 8), - ?line <<17:9,19:9>> = Fun12(<<17:6,19:6>>, 9, 6), + <<>> = Fun12(<<>>, 1, 1), + Binary = list_to_binary(lists:seq(0, 255)), + Binary = Fun12(Binary, 1, 1), + Binary = Fun12(Binary, 4, 4), + Binary = Fun12(Binary, 8, 8), + <<17:9,19:9>> = Fun12(<<17:6,19:6>>, 9, 6), Fun13 = fun(Sz) -> cs_default(<< <> || <> <= <<1:4,2:4,3:4,0:Sz>> >>) end, - ?line <<1,2,3>> = Fun13(0), - ?line <<1,2,3,0>> = Fun13(4), - ?line <<1,2,3,0>> = Fun13(5), - ?line <<1,2,3,0>> = Fun13(6), - ?line <<1,2,3,0>> = Fun13(7), - ?line <<1,2,3,0,0>> = Fun13(8), + <<1,2,3>> = Fun13(0), + <<1,2,3,0>> = Fun13(4), + <<1,2,3,0>> = Fun13(5), + <<1,2,3,0>> = Fun13(6), + <<1,2,3,0>> = Fun13(7), + <<1,2,3,0,0>> = Fun13(8), <<0:3>> = cs_default(<< <<0:S>> || S <- [0,1,2] >>), <<0:3>> = cs_default(<< <<0:S>> || <> <= <<0,1,2>> >>), - ?line {'EXIT',_} = (catch << <> || <> <= {1,2,3} >>), + {'EXIT',_} = (catch << <> || <> <= {1,2,3} >>), - ?line cs_end(), + cs_end(), ok. cs_init() -> -- cgit v1.2.1 From 205405f0bf1d2fa37d4c8170c11689a2937f5d9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Tue, 1 Mar 2016 06:23:36 +0100 Subject: Generalize bit string comprehensions The expression in a bit string comprehension is limited to a literal bit string expression. That is, the following code is legal: << <> || X <- List >> but not this code: << foo(X) || X <- List >> The limitation is annoying. For one thing, tools that transform the abstract format must be careful not to produce code such as: << begin %% Some instrumentation code. <> end || X <- List >> One reason for the limitation could be that we'll get reduce/reduce conflicts if we try to allow an arbitrary expression in a bit string comprehension: binary_comprehension -> '<<' expr '||' lc_exprs '>>' : {bc,?anno('$1'),'$2','$4'}. Unfortunately, there does not seem to be an easy way to work around that problem. The best we can do is to allow 'expr_max' expressions (as in the binary syntax): binary_comprehension -> '<<' expr_max '||' lc_exprs '>>' : {bc,?anno('$1'),'$2','$4'}. That will work, but functions calls must be enclosed in parentheses: << (foo(X)) || X <- List >> --- lib/compiler/test/bs_bincomp_SUITE.erl | 46 ++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) (limited to 'lib/compiler/test/bs_bincomp_SUITE.erl') diff --git a/lib/compiler/test/bs_bincomp_SUITE.erl b/lib/compiler/test/bs_bincomp_SUITE.erl index 93bce5c1f6..5e5f6e2169 100644 --- a/lib/compiler/test/bs_bincomp_SUITE.erl +++ b/lib/compiler/test/bs_bincomp_SUITE.erl @@ -26,7 +26,7 @@ init_per_group/2,end_per_group/2, byte_aligned/1,bit_aligned/1,extended_byte_aligned/1, extended_bit_aligned/1,mixed/1,filters/1,trim_coverage/1, - nomatch/1,sizes/1]). + nomatch/1,sizes/1,general_expressions/1]). -include_lib("common_test/include/ct.hrl"). @@ -36,7 +36,7 @@ all() -> test_lib:recompile(?MODULE), [byte_aligned, bit_aligned, extended_byte_aligned, extended_bit_aligned, mixed, filters, trim_coverage, - nomatch, sizes]. + nomatch, sizes, general_expressions]. groups() -> []. @@ -295,6 +295,48 @@ sizes(Config) when is_list(Config) -> cs_end(), ok. +-define(BAD(E), {'EXIT',{badarg,_}} = (catch << (E) || _ <- [1,2,3] >>)). +-define(BAD_V(E), {'EXIT',{badarg,_}} = (catch << (E) || I <- [1,2,3] >>)). + +general_expressions(_) -> + <<1,2,3>> = << begin <<1,2,3>> end || _ <- [1] >>, + <<"abc">> = << begin <<"abc">> end || _ <- [1] >>, + <<1,2,3>> = << begin + I = <<(I0+1)>>, + id(I) + end || <> <= <<0,1,2>> >>, + <<1,2,3>> = << I || I <- [<<1,2>>,<<3>>] >>, + <<1,2,3>> = << (id(<>)) || I <- [1,2,3] >>, + <<2,4>> = << case I rem 2 of + 0 -> <>; + 1 -> <<>> + end || I <- [1,2,3,4,5] >>, + <<2,3,4,5,6,7>> = << << (id(<>)) || J <- [2*I,2*I+1] >> || + I <- [1,2,3] >>, + <<1,2,2,3,4,4>> = << if + I rem 2 =:= 0 -> <>; + true -> <> + end || I <- [1,2,3,4] >>, + self() ! <<42>>, + <<42>> = << receive B -> B end || _ <- [1] >>, + <<10,5,3>> = << try + <<(10 div I)>> + catch _:_ -> + <<>> + end || I <- [0,1,2,3] >>, + + %% Failing expressions. + ?BAD(bad_atom), + ?BAD(42), + ?BAD(42.0), + ?BAD_V({ok,I}), + ?BAD_V([I]), + ?BAD_V(fun() -> I end), + + ok. + +-undef(BAD). + cs_init() -> erts_debug:set_internal_state(available_internal_state, true), ok. -- cgit v1.2.1 From 6664eed554974336909d3ffe03f20349cc4c38fd Mon Sep 17 00:00:00 2001 From: Henrik Nord Date: Tue, 15 Mar 2016 15:19:56 +0100 Subject: update copyright-year --- lib/compiler/test/bs_bincomp_SUITE.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/compiler/test/bs_bincomp_SUITE.erl') diff --git a/lib/compiler/test/bs_bincomp_SUITE.erl b/lib/compiler/test/bs_bincomp_SUITE.erl index 5e5f6e2169..4743821337 100644 --- a/lib/compiler/test/bs_bincomp_SUITE.erl +++ b/lib/compiler/test/bs_bincomp_SUITE.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2006-2013. All Rights Reserved. +%% Copyright Ericsson AB 2006-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. -- cgit v1.2.1