Gentoo Archives: gentoo-commits

From: "Petteri Räty" <betelgeuse@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/libbash:master commit in: bashast/, test/
Date: Wed, 30 Mar 2011 12:48:35
Message-Id: a7194ce05fd8c216847ec9a34b741eb07839c14d.betelgeuse@gentoo
1 commit: a7194ce05fd8c216847ec9a34b741eb07839c14d
2 Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
3 AuthorDate: Tue Mar 29 09:35:10 2011 +0000
4 Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
5 CommitDate: Tue Mar 29 10:18:48 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=a7194ce0
7
8 Implement arithmetic assignment
9
10 ---
11 bashast/bashwalker.g | 1 +
12 test/walker_test.cpp | 13 +++++++++++++
13 2 files changed, 14 insertions(+), 0 deletions(-)
14
15 diff --git a/bashast/bashwalker.g b/bashast/bashwalker.g
16 index d91e739..16d1216 100644
17 --- a/bashast/bashwalker.g
18 +++ b/bashast/bashwalker.g
19 @@ -79,6 +79,7 @@ arithmetics returns[int value]
20 |^(PRE_DECR libbash_name=name){ $value = walker->pre_decr(libbash_name); }
21 |^(POST_INCR libbash_name=name){ $value = walker->post_incr(libbash_name); }
22 |^(POST_DECR libbash_name=name){ $value = walker->post_decr(libbash_name); }
23 + |^(EQUALS libbash_name=name l=arithmetics) { walker->set_value(libbash_name, l); }
24 | NUMBER { $value = walker->parse_int($NUMBER);}
25 | DIGIT { $value = walker->parse_int($DIGIT);}
26 ;
27
28 diff --git a/test/walker_test.cpp b/test/walker_test.cpp
29 index c6ad4a9..0a74b10 100644
30 --- a/test/walker_test.cpp
31 +++ b/test/walker_test.cpp
32 @@ -65,6 +65,12 @@ public:
33 init_walker(script);
34 return treePsr->arithmetics(treePsr);
35 }
36 +
37 + int get_arithmetic_variable(const char* script, const string& name)
38 + {
39 + run_arithmetic(script);
40 + return walker->resolve<int>(name);
41 + }
42 };
43
44
45 @@ -155,3 +161,10 @@ TEST_BINARY_ARITHMETIC(complex_incr_decr2, "++value+value++", 202)
46 TEST_BINARY_ARITHMETIC(complex_cal, "10*(2+5)<<3%2**5", 560)
47 TEST_BINARY_ARITHMETIC(complex_cal2, "10*${value}<<3%2**5", 8000)
48 TEST_BINARY_ARITHMETIC(complex_cal3, "(20&5|3||1*100-20&5*10)+~(2*5)", -10)
49 +
50 +#define TEST_INT_VARIABLE_VALUE(name, script, var_name, exp_value)\
51 + TEST_F(walker_test, name) \
52 + { EXPECT_EQ(exp_value, get_arithmetic_variable(script, var_name)); }
53 +
54 +TEST_INT_VARIABLE_VALUE(assignment, "new_var=10", "new_var", 10)
55 +TEST_INT_VARIABLE_VALUE(assignment2, "value=10+5/2", "value", 12)