1 |
commit: d732ef09039f155b824086d43c13b23ff7698ffc |
2 |
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org> |
3 |
AuthorDate: Fri Apr 1 05:23:49 2011 +0000 |
4 |
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat Apr 2 00:55:07 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=d732ef09 |
7 |
|
8 |
Add member functions to support variable traversal |
9 |
|
10 |
Add begin() and end() method to the scope and interpreter class to |
11 |
allow variable traversal. |
12 |
|
13 |
--- |
14 |
src/core/interpreter.h | 43 +++++++++++++++++++++++++++++++++++++++++++ |
15 |
src/core/symbols.hpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ |
16 |
2 files changed, 91 insertions(+), 0 deletions(-) |
17 |
|
18 |
diff --git a/src/core/interpreter.h b/src/core/interpreter.h |
19 |
index 1da370c..ef95caa 100644 |
20 |
--- a/src/core/interpreter.h |
21 |
+++ b/src/core/interpreter.h |
22 |
@@ -46,6 +46,49 @@ class interpreter{ |
23 |
scope members; |
24 |
public: |
25 |
|
26 |
+ /// |
27 |
+ /// \brief return the number of variables |
28 |
+ /// \return the number of variables |
29 |
+ scope::size_type size() |
30 |
+ { |
31 |
+ return members.size(); |
32 |
+ } |
33 |
+ |
34 |
+ /// |
35 |
+ /// \brief return an iterator referring to the first variable |
36 |
+ /// \return iterator referring to the first variable |
37 |
+ scope::iterator begin() |
38 |
+ { |
39 |
+ return members.begin(); |
40 |
+ } |
41 |
+ |
42 |
+ /// |
43 |
+ /// \brief return a const iterator referring to the first variable |
44 |
+ /// \return const iterator referring to the first variable |
45 |
+ scope::const_iterator begin() const |
46 |
+ { |
47 |
+ return members.begin(); |
48 |
+ } |
49 |
+ |
50 |
+ /// |
51 |
+ /// \brief return an iterator referring to the next element after the |
52 |
+ /// last variable |
53 |
+ /// \return iterator referring to he next element after the last variable |
54 |
+ scope::iterator end() |
55 |
+ { |
56 |
+ return members.end(); |
57 |
+ } |
58 |
+ |
59 |
+ /// |
60 |
+ /// \brief return a const iterator referring to the next element after |
61 |
+ /// the last variable |
62 |
+ /// \return const iterator referring to he next element after the last |
63 |
+ /// variable |
64 |
+ scope::const_iterator end() const |
65 |
+ { |
66 |
+ return members.end(); |
67 |
+ } |
68 |
+ |
69 |
/// \brief parse the text value of a tree to integer |
70 |
/// \param the target tree |
71 |
/// \return the parsed value |
72 |
|
73 |
diff --git a/src/core/symbols.hpp b/src/core/symbols.hpp |
74 |
index bde05fb..53b699e 100644 |
75 |
--- a/src/core/symbols.hpp |
76 |
+++ b/src/core/symbols.hpp |
77 |
@@ -175,6 +175,54 @@ class scope |
78 |
public: |
79 |
typedef std::unordered_map<std::string, std::shared_ptr<symbol>> |
80 |
table_type; |
81 |
+ typedef table_type::iterator iterator; |
82 |
+ typedef table_type::const_iterator const_iterator; |
83 |
+ typedef table_type::size_type size_type; |
84 |
+ typedef table_type::value_type value_type; |
85 |
+ |
86 |
+ /// |
87 |
+ /// \brief return the number of symbols in current scope |
88 |
+ /// \return the number of symbols |
89 |
+ size_type size() |
90 |
+ { |
91 |
+ return members.size(); |
92 |
+ } |
93 |
+ |
94 |
+ /// |
95 |
+ /// \brief return an iterator referring to the first symbol |
96 |
+ /// \return iterator referring to the first symbol |
97 |
+ iterator begin() |
98 |
+ { |
99 |
+ return members.begin(); |
100 |
+ } |
101 |
+ |
102 |
+ /// |
103 |
+ /// \brief return a const iterator referring to the first symbol |
104 |
+ /// \return const iterator referring to the first symbol |
105 |
+ const_iterator begin() const |
106 |
+ { |
107 |
+ return members.begin(); |
108 |
+ } |
109 |
+ |
110 |
+ /// |
111 |
+ /// \brief return an iterator referring to the next element after |
112 |
+ /// the last symbol in current scope |
113 |
+ /// \return iterator referring to he next element after the last |
114 |
+ /// symbol in current scope |
115 |
+ iterator end() |
116 |
+ { |
117 |
+ return members.end(); |
118 |
+ } |
119 |
+ |
120 |
+ /// |
121 |
+ /// \brief return a const iterator referring to the next element |
122 |
+ /// after the last symbol in current scope |
123 |
+ /// \return const iterator referring to he next element after the |
124 |
+ /// last symbol in current scope |
125 |
+ const_iterator end() const |
126 |
+ { |
127 |
+ return members.end(); |
128 |
+ } |
129 |
|
130 |
/// \brief define a new symbol |
131 |
/// \param the new symbol |