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: scripts/, src/core/, bashast/, bashast/gunit/
Date: Fri, 27 May 2011 23:03:45
Message-Id: 2d7c18099e5b1f4fd3188e0c102da1c4615198a5.betelgeuse@gentoo
1 commit: 2d7c18099e5b1f4fd3188e0c102da1c4615198a5
2 Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
3 AuthorDate: Wed May 25 14:08:23 2011 +0000
4 Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
5 CommitDate: Thu May 26 08:20:30 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=2d7c1809
7
8 Builtin: fix a bug in local built-in
9
10 Now we allow declaring a local variable without assigning any value.
11
12 ---
13 bashast/bashast.g | 6 +++++-
14 bashast/gunit/simp_command.gunit | 2 +-
15 scripts/function_def.bash | 6 ++++--
16 scripts/function_def.bash.result | 2 +-
17 src/core/interpreter.h | 8 ++++----
18 5 files changed, 15 insertions(+), 9 deletions(-)
19
20 diff --git a/bashast/bashast.g b/bashast/bashast.g
21 index b5b133e..bb12b91 100644
22 --- a/bashast/bashast.g
23 +++ b/bashast/bashast.g
24 @@ -134,8 +134,12 @@ simple_command
25 | variable_definitions -> ^(VARIABLE_DEFINITIONS variable_definitions)
26 | bash_command^ redirect*;
27 variable_definitions
28 - : (LOCAL BLANK!+)? var_def (BLANK!+ var_def)*
29 + : var_def (BLANK!+ var_def)*
30 + | LOCAL BLANK!+ local_item (BLANK!+ local_item)*
31 | EXPORT! (BLANK!+ export_item)+;
32 +local_item
33 + :var_def
34 + |name -> ^(EQUALS name);
35 export_item
36 :var_def
37 |name ->;
38
39 diff --git a/bashast/gunit/simp_command.gunit b/bashast/gunit/simp_command.gunit
40 index 0ec100f..235819c 100644
41 --- a/bashast/gunit/simp_command.gunit
42 +++ b/bashast/gunit/simp_command.gunit
43 @@ -29,4 +29,4 @@ simple_command:
44 "./foobär" -> (COMMAND (STRING . / foob ä r))
45 "cat ~/Documents/todo.txt" -> (COMMAND (STRING cat) (STRING ~ / Documents / todo . txt))
46 "dodir ${foo}/${bar}" -> (COMMAND (STRING dodir) (STRING (VAR_REF foo) / (VAR_REF bar)))
47 -"local a=123 b=(1 2 3)" -> (VARIABLE_DEFINITIONS local (= a (STRING 123)) (= b (ARRAY (STRING 1) (STRING 2) (STRING 3))))
48 +"local a=123 b=(1 2 3) c" -> (VARIABLE_DEFINITIONS local (= a (STRING 123)) (= b (ARRAY (STRING 1) (STRING 2) (STRING 3))) (EQUALS c))
49
50 diff --git a/scripts/function_def.bash b/scripts/function_def.bash
51 index 5be1e36..54030e7 100644
52 --- a/scripts/function_def.bash
53 +++ b/scripts/function_def.bash
54 @@ -44,14 +44,16 @@ func_with_return2
55 RETURN_STATUS2=$?
56
57 func_nested1() {
58 - echo $foo_nested ${bar_nested[0]}
59 + echo $foo_nested ${bar_nested[0]} $localbar
60 }
61 func_nested2() {
62 local foo_nested=hi bar_nested=(1 2
63 - 3)
64 + 3) localbar
65 + localbar=1
66 func_nested1
67 }
68 func_nested2
69 +echo $localbar
70
71 let() {
72 echo "overloaded let"
73
74 diff --git a/scripts/function_def.bash.result b/scripts/function_def.bash.result
75 index d3abad0..41e19ca 100644
76 --- a/scripts/function_def.bash.result
77 +++ b/scripts/function_def.bash.result
78 @@ -1,4 +1,4 @@
79 -hi 1
80 +hi 1 1
81 overloaded let
82 1 2 3
83 1 2 3
84
85 diff --git a/src/core/interpreter.h b/src/core/interpreter.h
86 index 3c85450..f35b8ff 100644
87 --- a/src/core/interpreter.h
88 +++ b/src/core/interpreter.h
89 @@ -475,11 +475,11 @@ public:
90 const T& new_value,
91 const unsigned index=0)
92 {
93 - auto i = members.find(name);
94 - if(i == members.end())
95 - define(name, new_value, false, index);
96 + auto var = resolve_variable(name);
97 + if(var)
98 + var->set_value(new_value, index);
99 else
100 - i->second->set_value(new_value, index);
101 + define(name, new_value, false, index);
102 return new_value;
103 }