From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1QAEW7-0001Uh-W6 for garchives@archives.gentoo.org; Thu, 14 Apr 2011 04:51:00 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id BAA131C030; Thu, 14 Apr 2011 04:50:17 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 73DE51C030 for ; Thu, 14 Apr 2011 04:50:17 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 23F882AC015 for ; Thu, 14 Apr 2011 04:50:17 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 83DEC8006E for ; Thu, 14 Apr 2011 04:50:16 +0000 (UTC) From: "Petteri Räty" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Petteri Räty" Message-ID: Subject: [gentoo-commits] proj/libbash:master commit in: scripts/, src/core/, bashast/ X-VCS-Repository: proj/libbash X-VCS-Files: bashast/libbashWalker.g scripts/arithmetic_assignment.ebuild scripts/arithmetic_assignment.ebuild.result scripts/binary_arithmetic.ebuild scripts/binary_arithmetic.ebuild.result src/core/interpreter.h X-VCS-Directories: scripts/ src/core/ bashast/ X-VCS-Committer: betelgeuse X-VCS-Committer-Name: Petteri Räty X-VCS-Revision: e69a687ae1d3db7c61179b8492ee51e47dc0569a Date: Thu, 14 Apr 2011 04:50:16 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: 0ff67af17de5548eb341d2ae08d571ed commit: e69a687ae1d3db7c61179b8492ee51e47dc0569a Author: Mu Qiao gentoo org> AuthorDate: Tue Apr 12 11:11:32 2011 +0000 Commit: Petteri R=C3=A4ty gentoo org> CommitDate: Thu Apr 14 01:33:29 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/libbash.git;a= =3Dcommit;h=3De69a687a Implement array element in arithmetic expansion Array element reference and assignment in arithmetic expansion are supported now. --- bashast/libbashWalker.g | 72 ++++++++++++++++-----= ----- scripts/arithmetic_assignment.ebuild | 2 + scripts/arithmetic_assignment.ebuild.result | 3 + scripts/binary_arithmetic.ebuild | 28 ++++++++++- scripts/binary_arithmetic.ebuild.result | 26 +++++++++- src/core/interpreter.h | 22 ++++---- 6 files changed, 112 insertions(+), 41 deletions(-) diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g index 47634e8..05c1127 100644 --- a/bashast/libbashWalker.g +++ b/bashast/libbashWalker.g @@ -178,6 +178,22 @@ var_ref [bool double_quoted] returns[std::string lib= bash_value]: } |^(VAR_REF libbash_string=3Dvar_expansion) { $libbash_value =3D libbash= _string; }; =20 +// Only used in arithmetic expansion +primary returns[std::string libbash_value, unsigned index]: + (^(VAR_REF name)) =3D> ^(VAR_REF name) { + $libbash_value =3D $name.libbash_value; + $index =3D $name.index; + } + |name { + $libbash_value =3D $name.libbash_value; + $index =3D $name.index; + } + // array[@] and array[*] is meaningless to arithmetic expansion so true= /false are both ok. + |^(VAR_REF libbash_string=3Dvar_ref[false]) { + $libbash_value =3D libbash_string; + $index =3D 0; + }; + // shell arithmetic arithmetics returns[int value] : @@ -205,45 +221,45 @@ arithmetics returns[int value] |^(ARITHMETIC_CONDITION cnd=3Darithmetics l=3Darithmetics r=3Darithmeti= cs){ $value =3D walker->arithmetic_condition(cnd, l, r); } - |^(VAR_REF name) { - $value =3D walker->resolve($name.libbash_value); + |primary { + $value =3D walker->resolve($primary.libbash_value, $primary.index= ); } - |^(PRE_INCR ^(VAR_REF name)){ $value =3D walker->pre_incr($name.libbash= _value); } - |^(PRE_DECR ^(VAR_REF name)){ $value =3D walker->pre_decr($name.libbash= _value); } - |^(POST_INCR ^(VAR_REF name)){ $value =3D walker->post_incr($name.libba= sh_value); } - |^(POST_DECR ^(VAR_REF name)){ $value =3D walker->post_decr($name.libba= sh_value); } - |^(EQUALS name l=3Darithmetics) { - $value =3D walker->set_value($name.libbash_value, l); + |^(PRE_INCR primary){ $value =3D walker->pre_incr($primary.libbash_valu= e, $primary.index); } + |^(PRE_DECR primary){ $value =3D walker->pre_decr($primary.libbash_valu= e, $primary.index); } + |^(POST_INCR primary){ $value =3D walker->post_incr($primary.libbash_va= lue, $primary.index); } + |^(POST_DECR primary){ $value =3D walker->post_decr($primary.libbash_va= lue, $primary.index); } + |^(EQUALS primary l=3Darithmetics) { + $value =3D walker->set_value($primary.libbash_value, l, $primary.index= ); } - |^(MUL_ASSIGN name l=3Darithmetics) { - $value =3D walker->assign(&interpreter::multiply, $name.libbash_value,= l); + |^(MUL_ASSIGN primary l=3Darithmetics) { + $value =3D walker->assign(&interpreter::multiply, $primary.libbash_val= ue, l, $primary.index); } - |^(DIVIDE_ASSIGN name l=3Darithmetics) { - $value =3D walker->assign(&interpreter::divide, $name.libbash_value, l= ); + |^(DIVIDE_ASSIGN primary l=3Darithmetics) { + $value =3D walker->assign(&interpreter::divide, $primary.libbash_value= , l, $primary.index); } - |^(MOD_ASSIGN name l=3Darithmetics) { - $value =3D walker->assign(&interpreter::mod, $name.libbash_value, l); + |^(MOD_ASSIGN primary l=3Darithmetics) { + $value =3D walker->assign(&interpreter::mod, $primary.libbash_value, l= , $primary.index); } - |^(PLUS_ASSIGN name l=3Darithmetics) { - $value =3D walker->assign(&interpreter::plus, $name.libbash_value, l); + |^(PLUS_ASSIGN primary l=3Darithmetics) { + $value =3D walker->assign(&interpreter::plus, $primary.libbash_value, = l, $primary.index); } - |^(MINUS_ASSIGN name l=3Darithmetics) { - $value =3D walker->assign(&interpreter::minus, $name.libbash_value, l)= ; + |^(MINUS_ASSIGN primary l=3Darithmetics) { + $value =3D walker->assign(&interpreter::minus, $primary.libbash_value,= l, $primary.index); } - |^(LSHIFT_ASSIGN name l=3Darithmetics) { - $value =3D walker->assign(&interpreter::left_shift, $name.libbash_valu= e, l); + |^(LSHIFT_ASSIGN primary l=3Darithmetics) { + $value =3D walker->assign(&interpreter::left_shift, $primary.libbash_v= alue, l, $primary.index); } - |^(RSHIFT_ASSIGN name l=3Darithmetics) { - $value =3D walker->assign(&interpreter::right_shift, $name.libbash_val= ue, l); + |^(RSHIFT_ASSIGN primary l=3Darithmetics) { + $value =3D walker->assign(&interpreter::right_shift, $primary.libbash_= value, l, $primary.index); } - |^(AND_ASSIGN name l=3Darithmetics) { - $value =3D walker->assign(&interpreter::bitwiseand, $name.libbash_valu= e, l); + |^(AND_ASSIGN primary l=3Darithmetics) { + $value =3D walker->assign(&interpreter::bitwiseand, $primary.libbash_v= alue, l, $primary.index); } - |^(XOR_ASSIGN name l=3Darithmetics) { - $value =3D walker->assign(&interpreter::bitwisexor, $name.libbash_valu= e, l); + |^(XOR_ASSIGN primary l=3Darithmetics) { + $value =3D walker->assign(&interpreter::bitwisexor, $primary.libbash_v= alue, l, $primary.index); } - |^(OR_ASSIGN name l=3Darithmetics) { - $value =3D walker->assign(&interpreter::bitwiseor, $name.libbash_value= , l); + |^(OR_ASSIGN primary l=3Darithmetics) { + $value =3D walker->assign(&interpreter::bitwiseor, $primary.libbash_va= lue, l, $primary.index); } | NUMBER { $value =3D walker->parse_int($NUMBER);} | DIGIT { $value =3D walker->parse_int($DIGIT);} diff --git a/scripts/arithmetic_assignment.ebuild b/scripts/arithmetic_as= signment.ebuild index 20bcc44..27e2ee5 100644 --- a/scripts/arithmetic_assignment.ebuild +++ b/scripts/arithmetic_assignment.ebuild @@ -9,4 +9,6 @@ FOO007=3D"$((value>>=3D2))" FOO008=3D"$((value&=3D10))" FOO009=3D"$((value^=3D5))" FOO010=3D"$((value|=3D10))" +FOO011=3D("CREATED" 2) +FOO012=3D"$((${FOO011[0]}=3D10))" value=3D"$((100))" diff --git a/scripts/arithmetic_assignment.ebuild.result b/scripts/arithm= etic_assignment.ebuild.result index 64863b5..9f47242 100644 --- a/scripts/arithmetic_assignment.ebuild.result +++ b/scripts/arithmetic_assignment.ebuild.result @@ -1,3 +1,4 @@ +CREATED=3D10 FOO001=3D1000 FOO002=3D100 FOO003=3D1 @@ -8,4 +9,6 @@ FOO007=3D1 FOO008=3D0 FOO009=3D5 FOO010=3D15 +FOO011=3DCREATED 2 +FOO012=3D10 value=3D100 diff --git a/scripts/binary_arithmetic.ebuild b/scripts/binary_arithmetic= .ebuild index a674f5c..bdc3d94 100644 --- a/scripts/binary_arithmetic.ebuild +++ b/scripts/binary_arithmetic.ebuild @@ -1,3 +1,4 @@ +ARRAY=3D(1 2 3 4 5) FOO001=3D"$((0 || -2))" FOO002=3D"$((0 || 0))" FOO003=3D"$((-1 && 10))" @@ -36,4 +37,29 @@ FOO033=3D"$((++value+value++))" FOO034=3D"$((10*(2+5)<<3%2**5))" FOO035=3D"$((10*value<<3%2**5))" FOO036=3D"$(( (20&5|3||1*100-20&5*10)+~(2*5) ))" -value=3D"$((100))" +FOO037=3D"$((ARRAY[0]++))" +FOO038=3D"$((++ARRAY[0]))" +FOO039=3D"$((ARRAY[0]--))" +FOO040=3D"$((--ARRAY[0]))" +FOO041=3D"$((ARRAY[8]=3D9))" +FOO042=3D"$((ARRAY[8]*=3D10))" +FOO043=3D"$((ARRAY[8]/=3D10))" +FOO044=3D"$((ARRAY[8]%=3D2))" +FOO045=3D"$((ARRAY[8]+=3D8))" +FOO046=3D"$((ARRAY[8]-=3D0))" +FOO047=3D"$((ARRAY[8]<<=3D1))" +FOO048=3D"$((ARRAY[8]>>=3D1))" +FOO049=3D"$((ARRAY[8]&=3D5))" +FOO050=3D"$((ARRAY[8]|=3D10))" +FOO051=3D"$((ARRAY[8]^=3D3))" +PARTIAL[8]=3D5 +FOO052=3D"$((PARTIAL[8]*=3D1))" +# The following 3 just expand to non-exist variables +FOO053=3D"$((${#ARRAY[@]}))" +FOO054=3D"$((${ARRAY[5]:-10}))" +FOO055=3D"$((${ARRAY:0}))" +value=3D100 +FOO056=3D"value" +FOO057=3D"$((${FOO056}++))" +FOO058=3D"$((${FOO056}+=3D10))" +ARRAY=3D(1 2 3 4 5) diff --git a/scripts/binary_arithmetic.ebuild.result b/scripts/binary_ari= thmetic.ebuild.result index b258fd0..63cfa28 100644 --- a/scripts/binary_arithmetic.ebuild.result +++ b/scripts/binary_arithmetic.ebuild.result @@ -1,3 +1,4 @@ +ARRAY=3D1 2 3 4 5 FOO001=3D1 FOO002=3D0 FOO003=3D1 @@ -34,4 +35,27 @@ FOO033=3D206 FOO034=3D560 FOO035=3D8320 FOO036=3D-10 -value=3D100 +FOO037=3D1 +FOO038=3D3 +FOO039=3D3 +FOO040=3D1 +FOO041=3D9 +FOO042=3D90 +FOO043=3D9 +FOO044=3D1 +FOO045=3D9 +FOO046=3D9 +FOO047=3D18 +FOO048=3D9 +FOO049=3D1 +FOO050=3D11 +FOO051=3D8 +FOO052=3D5 +FOO053=3D0 +FOO054=3D0 +FOO055=3D0 +FOO056=3Dvalue +FOO057=3D100 +FOO058=3D111 +PARTIAL=3D5 +value=3D111 diff --git a/src/core/interpreter.h b/src/core/interpreter.h index 4d51d5b..5ac5027 100644 --- a/src/core/interpreter.h +++ b/src/core/interpreter.h @@ -321,9 +321,9 @@ public: /// \brief perform pre-increment /// \param the variable name /// \return the increased value - int pre_incr(const std::string& name) + int pre_incr(const std::string& name, const unsigned index) { - int value =3D resolve(name); + int value =3D resolve(name, index); set_value(name, ++value); return value; } @@ -331,9 +331,9 @@ public: /// \brief perform pre-decrement /// \param the variable name /// \return the decreased value - int pre_decr(const std::string& name) + int pre_decr(const std::string& name, const unsigned index) { - int value =3D resolve(name); + int value =3D resolve(name, index); set_value(name, --value); return value; } @@ -341,9 +341,9 @@ public: /// \brief perform post-increment /// \param the variable name /// \return the original value - int post_incr(const std::string& name) + int post_incr(const std::string& name, const unsigned index) { - int value =3D resolve(name); + int value =3D resolve(name, index); set_value(name, value + 1); return value; } @@ -351,9 +351,9 @@ public: /// \brief perform post-decrement /// \param the variable name /// \return the original value - int post_decr(const std::string& name) + int post_decr(const std::string& name, const unsigned index) { - int value =3D resolve(name); + int value =3D resolve(name, index); set_value(name, value - 1); return value; } @@ -363,10 +363,10 @@ public: /// \param the name of the variable /// \param the value to assign /// \return the new value of the variable - int assign(std::function f, const std::string& name, int= value) + int assign(std::function f, const std::string& name, int= value, const unsigned index) { - int new_value =3D f(resolve(name), value); - set_value(name, new_value); + int new_value =3D f(resolve(name, index), value); + set_value(name, new_value, index); return new_value; } =20