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: src/, src/core/, src/builtins/
Date: Sun, 03 Jul 2011 20:21:29
Message-Id: 6c8652270b3f350b8621f2923d23f3f265146d59.betelgeuse@gentoo
1 commit: 6c8652270b3f350b8621f2923d23f3f265146d59
2 Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
3 AuthorDate: Sun Jul 3 08:49:10 2011 +0000
4 Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
5 CommitDate: Sun Jul 3 08:49:10 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=6c865227
7
8 Doc: improve documentation
9
10 Now make doxygen-doc doesn't show so many warnings. The documentation
11 for following things is not fixed: unit tests, private members, some
12 built-in constructors.
13
14 ---
15 src/builtins/boolean_builtins.h | 2 +-
16 src/builtins/builtin_exceptions.h | 9 ++
17 src/common.h | 2 +
18 src/core/bash_ast.h | 55 +++++++++--
19 src/core/bash_condition.h | 8 ++
20 src/core/divide_by_zero_error.h | 2 +
21 src/core/function.h | 9 ++-
22 src/core/illegal_argument_exception.h | 2 +
23 src/core/interpreter.h | 166 ++++++++++++++++++--------------
24 src/core/interpreter_exception.h | 2 +
25 src/core/parse_exception.h | 2 +
26 src/core/readonly_exception.h | 2 +
27 src/core/runtime_exception.h | 2 +
28 src/core/symbols.hpp | 34 ++++---
29 src/core/unsupported_exception.h | 2 +
30 src/cppbash_builtin.h | 33 +++++--
31 16 files changed, 223 insertions(+), 109 deletions(-)
32
33 diff --git a/src/builtins/boolean_builtins.h b/src/builtins/boolean_builtins.h
34 index fb7aca9..0d3db1a 100644
35 --- a/src/builtins/boolean_builtins.h
36 +++ b/src/builtins/boolean_builtins.h
37 @@ -17,7 +17,7 @@
38 along with libbash. If not, see <http://www.gnu.org/licenses/>.
39 */
40 ///
41 -/// \file boolean_builtins.cpp
42 +/// \file boolean_builtins.h
43 /// \brief implementations for the true and false builtins
44 ///
45 #ifndef LIBBASH_BUILTINS_BOOLEAN_BUILTINS_H_
46
47 diff --git a/src/builtins/builtin_exceptions.h b/src/builtins/builtin_exceptions.h
48 index 7b45efc..e1a443a 100644
49 --- a/src/builtins/builtin_exceptions.h
50 +++ b/src/builtins/builtin_exceptions.h
51 @@ -49,8 +49,11 @@ protected:
52 virtual ~loop_control_exception() {}
53
54 public:
55 + /// \brief the construtor
56 + /// \param c the nested block counter
57 explicit loop_control_exception(int c): count(c) {}
58
59 + /// \brief rethrow the exception if the counter is greater than 1
60 void rethrow_unless_correct_frame()
61 {
62 if(count != 1)
63 @@ -64,12 +67,15 @@ public:
64 class continue_exception: public loop_control_exception
65 {
66 protected:
67 + /// \brief rethrow the exception itself
68 virtual void rethrow()
69 {
70 throw *this;
71 }
72
73 public:
74 + /// \brief the constructor of the exception
75 + /// \param c the nested block counter
76 explicit continue_exception(int c): loop_control_exception(c) {
77 if(c < 1)
78 throw libbash::illegal_argument_exception("continue: argument should be greater than or equal to 1");
79 @@ -79,12 +85,15 @@ public:
80 class break_exception: public loop_control_exception
81 {
82 protected:
83 + /// \brief rethrow the exception itself
84 virtual void rethrow()
85 {
86 throw *this;
87 }
88
89 public:
90 + /// \brief the constructor of the exception
91 + /// \param c the nested block counter
92 explicit break_exception(int c): loop_control_exception(c) {
93 if(c < 1)
94 throw libbash::illegal_argument_exception("break: argument should be greater than or equal to 1");
95
96 diff --git a/src/common.h b/src/common.h
97 index 537e8d8..7203f02 100644
98 --- a/src/common.h
99 +++ b/src/common.h
100 @@ -24,7 +24,9 @@
101 #ifndef LIBBASH_COMMON_H_
102 #define LIBBASH_COMMON_H_
103
104 +/// compiler hint for public symbols
105 #define LIBBASH_API __attribute__((visibility("default")))
106 +/// compiler hint for hidden symbols
107 #define LIBBASH_LOCAL __attribute__((visibility("hidden")))
108
109 #endif
110
111 diff --git a/src/core/bash_ast.h b/src/core/bash_ast.h
112 index 22635a1..fb42663 100644
113 --- a/src/core/bash_ast.h
114 +++ b/src/core/bash_ast.h
115 @@ -37,14 +37,19 @@
116 struct libbashLexer_Ctx_struct;
117 struct libbashParser_Ctx_struct;
118 struct libbashWalker_Ctx_struct;
119 -typedef libbashWalker_Ctx_struct* plibbashWalker;
120 class interpreter;
121
122 +/// \class bash_ast
123 +/// \brief customized unique_ptr for antlr objects.
124 template<typename T>
125 class antlr_pointer: public std::unique_ptr<T, std::function<void(T*)>>
126 {
127 + /// the constructor of base class
128 typedef std::unique_ptr<T, std::function<void(T*)>> parent;
129 public:
130 + /// \brief constructor of antlr_pointer
131 + /// \param p the pointer to the antlr objects, it should provide a method called 'free'
132 + /// to free the memory
133 antlr_pointer(T* p = 0) : parent(p, [](T* to_delete) { to_delete->free(to_delete); }) {};
134 };
135
136 @@ -61,54 +66,86 @@ class bash_ast: public boost::noncopyable
137 antlr_pointer<ANTLR3_COMMON_TREE_NODE_STREAM_struct> nodes;
138 std::function<pANTLR3_BASE_TREE(libbashParser_Ctx_struct*)> parse;
139
140 - typedef std::unique_ptr<libbashWalker_Ctx_struct, std::function<void(plibbashWalker)>> walker_pointer;
141 + typedef std::unique_ptr<libbashWalker_Ctx_struct, std::function<void(libbashWalker_Ctx_struct*)>> walker_pointer;
142
143 void init_parser(const std::string& script, const std::string& script_path);
144 walker_pointer create_walker(interpreter& walker);
145
146 public:
147 + /// \brief build AST from istream
148 + /// \param source input source
149 + /// \param p the parser rule for building the AST
150 bash_ast(const std::istream& source,
151 std::function<pANTLR3_BASE_TREE(libbashParser_Ctx_struct*)> p=parser_start);
152
153 + /// \brief build AST from string
154 + /// \param script_path input source
155 + /// \param p the parser rule for building the AST
156 bash_ast(const std::string& script_path,
157 std::function<pANTLR3_BASE_TREE(libbashParser_Ctx_struct*)> p=parser_start);
158
159 - static void walker_start(plibbashWalker tree_parser);
160 + /// \brief the functor for walker start rule
161 + /// \param tree_parser the pointer to the tree_parser
162 + static void walker_start(libbashWalker_Ctx_struct* tree_parser);
163
164 - static long walker_arithmetics(plibbashWalker tree_parser);
165 + /// \brief the functor for walker arithmetics rule
166 + /// \param tree_parser the pointer to the tree_parser
167 + static long walker_arithmetics(libbashWalker_Ctx_struct* tree_parser);
168
169 - static void call_function(plibbashWalker tree_parser,
170 + /// \brief call a function that is defined in the AST
171 + /// \param tree_parser the pointer to the tree_parser
172 + /// \param index the function index
173 + static void call_function(libbashWalker_Ctx_struct* tree_parser,
174 ANTLR3_MARKER index);
175
176 + /// \brief the functor for parser start rule
177 + /// \param parser the pointer to the parser
178 static pANTLR3_BASE_TREE parser_start(libbashParser_Ctx_struct* parser);
179
180 + /// \brief the functor for parser arithmetics rule
181 + /// \param parser the pointer to the parser
182 static pANTLR3_BASE_TREE parser_arithmetics(libbashParser_Ctx_struct* parser);
183
184 ///
185 /// \brief interpret the script with a given interpreter
186 - /// \param the interpreter object
187 + /// \param walker the interpreter object
188 + /// \param walk the walker rule to evaluate the AST
189 /// \return the interpreted result
190 template<typename Functor>
191 - typename std::result_of<Functor(plibbashWalker)>::type
192 + typename std::result_of<Functor(libbashWalker_Ctx_struct*)>::type
193 interpret_with(interpreter& walker, Functor walk)
194 {
195 walker_pointer p_tree_parser = create_walker(walker);
196 return walk(p_tree_parser.get());
197 }
198
199 + ///
200 + /// \brief use the start rule to interpret the script with a given interpreter
201 + /// \param walker the interpreter object
202 void interpret_with(interpreter& walker)
203 {
204 interpret_with(walker, walker_start);
205 }
206
207 + /// \brief get the dot graph for the AST
208 + /// \return the dot graph
209 std::string get_dot_graph();
210
211 + /// \brief get the string tree for the AST
212 + /// \return the string tree
213 std::string get_string_tree();
214
215 + /// \brief get parser tokens from a token stream
216 + /// \param token_stream the token stream
217 + /// \param token_mapper function that translates token numbers to token names
218 + /// \return the parser tokens
219 static std::string get_parser_tokens(antlr_pointer<ANTLR3_COMMON_TOKEN_STREAM_struct>& token_stream,
220 - std::function<std::string(ANTLR3_UINT32)>);
221 + std::function<std::string(ANTLR3_UINT32)> token_mapper);
222
223 - std::string get_walker_tokens(std::function<std::string(ANTLR3_UINT32)>);
224 + /// \brief get walker tokens from current AST
225 + /// \param token_mapper function that translates token numbers to token names
226 + /// \return the walker tokens
227 + std::string get_walker_tokens(std::function<std::string(ANTLR3_UINT32)> token_mapper);
228 };
229
230 #endif
231
232 diff --git a/src/core/bash_condition.h b/src/core/bash_condition.h
233 index e8e4096..1c4f26c 100644
234 --- a/src/core/bash_condition.h
235 +++ b/src/core/bash_condition.h
236 @@ -29,8 +29,16 @@ class interpreter;
237
238 namespace internal
239 {
240 + /// \brief implementation for built-in test unary operation
241 + /// \param the operator
242 + /// \param the operand
243 bool test_unary(char op, const std::string& target);
244
245 + /// \brief implementation for built-in test binary operation
246 + /// \param the operator
247 + /// \param the first operand
248 + /// \param the second operand
249 + /// \param a reference to the interpreter object
250 bool test_binary(const std::string& op,
251 const std::string& lhs,
252 const std::string& rhs,
253
254 diff --git a/src/core/divide_by_zero_error.h b/src/core/divide_by_zero_error.h
255 index 10603cc..59e0fcb 100644
256 --- a/src/core/divide_by_zero_error.h
257 +++ b/src/core/divide_by_zero_error.h
258 @@ -39,6 +39,8 @@ namespace libbash
259 class LIBBASH_API divide_by_zero_error: public libbash::interpreter_exception
260 {
261 public:
262 + /// \brief the constructor
263 + /// \param err_msg the error message
264 explicit divide_by_zero_error(const std::string& err_msg):
265 libbash::interpreter_exception(err_msg){}
266 };
267
268 diff --git a/src/core/function.h b/src/core/function.h
269 index fcd0e91..92ae97c 100644
270 --- a/src/core/function.h
271 +++ b/src/core/function.h
272 @@ -17,7 +17,7 @@
273 along with libbash. If not, see <http://www.gnu.org/licenses/>.
274 */
275 ///
276 -/// \file function.hpp
277 +/// \file function.h
278 /// \brief implementation for function
279 ///
280
281 @@ -31,13 +31,20 @@
282 class bash_ast;
283 class interpreter;
284
285 +/// \class function
286 +/// \brief bash function implementation
287 class function
288 {
289 bash_ast& ast;
290 ANTLR3_MARKER index;
291 public:
292 + /// \brief the constructor
293 + /// \param ast_ the reference to the AST
294 + /// \param i the function index
295 function(bash_ast& ast_, ANTLR3_MARKER i): ast(ast_), index(i){}
296
297 + /// \brief call the function
298 + /// \param walker the reference to the interpreter object
299 void call(interpreter& walker);
300 };
301
302
303 diff --git a/src/core/illegal_argument_exception.h b/src/core/illegal_argument_exception.h
304 index f67a9f6..847b6a8 100644
305 --- a/src/core/illegal_argument_exception.h
306 +++ b/src/core/illegal_argument_exception.h
307 @@ -39,6 +39,8 @@ namespace libbash
308 class LIBBASH_API illegal_argument_exception: public libbash::interpreter_exception
309 {
310 public:
311 + /// \brief the constructor
312 + /// \param err_msg the error message
313 explicit illegal_argument_exception(const std::string& err_msg):
314 libbash::interpreter_exception(err_msg){}
315 };
316
317 diff --git a/src/core/interpreter.h b/src/core/interpreter.h
318 index b0cfda5..c623e86 100644
319 --- a/src/core/interpreter.h
320 +++ b/src/core/interpreter.h
321 @@ -36,6 +36,7 @@
322 #include "core/symbols.hpp"
323 #include "cppbash_builtin.h"
324
325 +/// \brief symbol table implementation
326 typedef std::unordered_map<std::string, std::shared_ptr<variable>> scope;
327
328 ///
329 @@ -45,17 +46,14 @@ typedef std::unordered_map<std::string, std::shared_ptr<variable>> scope;
330 class interpreter: public boost::noncopyable
331 {
332
333 - /// \var private::members
334 /// \brief global symbol table for variables
335 scope members;
336
337 - /// \var private::function_definitions
338 /// \brief global symbol table for functions
339 std::unordered_map<std::string, function> functions;
340
341 std::stack<bash_ast*> ast_stack;
342
343 - /// \var private::local_members
344 /// \brief local scope for function arguments, execution environment and
345 /// local variables
346 std::vector<scope> local_members;
347 @@ -73,7 +71,6 @@ class interpreter: public boost::noncopyable
348 // as bash implementation.
349 std::map<char, bool> options;
350
351 - /// \var private::status
352 /// \brief the return status of the last command
353 int status;
354
355 @@ -107,6 +104,7 @@ class interpreter: public boost::noncopyable
356 unsigned length) const;
357 public:
358
359 + /// bash option iterator
360 typedef std::map<std::string, bool>::const_iterator option_iterator;
361
362 ///
363 @@ -118,17 +116,21 @@ public:
364 interpreter& walker;
365
366 public:
367 + /// \brief construtor
368 + /// \param w the reference to the interpreter object
369 local_scope(interpreter& w): walker(w)
370 {
371 walker.local_members.push_back(scope());
372 }
373
374 + /// \brief the destructor
375 ~local_scope()
376 {
377 walker.local_members.pop_back();
378 }
379 };
380
381 + /// \brief construtor
382 interpreter();
383
384 ///
385 @@ -174,11 +176,14 @@ public:
386 return members.end();
387 }
388
389 + /// \brief set current output stream
390 + /// \param stream the pointer to the output stream
391 void set_output_stream(std::ostream* stream)
392 {
393 _out = stream;
394 }
395
396 + /// \brief restore the current output stream to standard output stream
397 void restore_output_stream()
398 {
399 _out = &std::cout;
400 @@ -186,8 +191,8 @@ public:
401
402 /// \brief resolve string/long variable, local scope will be
403 /// checked first, then global scope
404 - /// \param variable name
405 - /// \param array index, use index=0 if it's not an array
406 + /// \param name variable name
407 + /// \param index array index, use index=0 if it's not an array
408 /// \return the value of the variable, call default constructor if
409 /// it's undefined
410 template <typename T>
411 @@ -201,8 +206,8 @@ public:
412 }
413
414 /// \brief resolve array variable
415 - /// \param variable name
416 - /// \param[out] vector that stores all array values
417 + /// \param name variable name
418 + /// \param[out] values vector that stores all array values
419 template <typename T>
420 bool resolve_array(const std::string& name, std::vector<T>& values) const
421 {
422 @@ -216,12 +221,13 @@ public:
423
424 /// \brief check whether the value of the variable is null, return true
425 /// if the variable is undefined
426 - /// \param variable name
427 + /// \param name variable name
428 + /// \param index array index, use index=0 if it's not an array
429 /// \return whether the value of the variable is null
430 bool is_unset_or_null(const std::string& name, const unsigned index) const;
431
432 /// \brief check whether the value of the variable is unset
433 - /// \param variable name
434 + /// \param name variable name
435 /// \return whether the value of the variable is unset
436 bool is_unset(const std::string& name) const
437 {
438 @@ -230,9 +236,9 @@ public:
439
440 /// \brief update the variable value, raise libbash::interpreter_exception if
441 /// it's readonly, will define the variable if it doesn't exist
442 - /// \param variable name
443 - /// \param new value
444 - /// \param array index, use index=0 if it's not an array
445 + /// \param name variable name
446 + /// \param new_value new value
447 + /// \param index array index, use index=0 if it's not an array
448 /// \return the new value of the variable
449 template <typename T>
450 const T& set_value(const std::string& name,
451 @@ -248,37 +254,36 @@ public:
452 }
453
454 /// \brief set the return status of the last command
455 - /// \param the value of the return status
456 + /// \param s the value of the return status
457 void set_status(int s)
458 {
459 status = s;
460 }
461
462 /// \brief get the return status of the last command
463 - /// \param the value of the return status
464 int get_status(void) const
465 {
466 return status;
467 }
468
469 /// \brief unset a variable
470 - /// \param the name of the variable
471 + /// \param name the name of the variable
472 void unset(const std::string& name);
473
474 /// \brief unset a function
475 - /// \param the name of the function
476 + /// \param name the name of the function
477 void unset_function(const std::string& name);
478
479 /// \brief unset a array member
480 - /// \param the name of the array
481 - /// \param the index of the member
482 + /// \param name the name of the array
483 + /// \param index the index of the member
484 void unset(const std::string& name, const unsigned index);
485
486 /// \brief define a new global variable
487 - /// \param the name of the variable
488 - /// \param the value of the variable
489 - /// \param whether it's readonly, default is false
490 - /// \param whether it's null, default is false
491 + /// \param name the name of the variable
492 + /// \param value the value of the variable
493 + /// \param readonly whether it's readonly, default is false
494 + /// \param index whether it's null, default is false
495 template <typename T>
496 void define(const std::string& name,
497 const T& value,
498 @@ -289,10 +294,10 @@ public:
499 }
500
501 /// \brief define a new local variable
502 - /// \param the name of the variable
503 - /// \param the value of the variable
504 - /// \param whether it's readonly, default is false
505 - /// \param whether it's null, default is false
506 + /// \param name the name of the variable
507 + /// \param value the value of the variable
508 + /// \param readonly whether it's readonly, default is false
509 + /// \param index whether it's null, default is false
510 template <typename T>
511 void define_local(const std::string& name,
512 const T& value,
513 @@ -303,8 +308,8 @@ public:
514 }
515
516 /// \brief define a new function
517 - /// \param the name of the function
518 - /// \param the body index of the function
519 + /// \param name the name of the function
520 + /// \param body_index the body index of the function
521 void define_function(const std::string& name,
522 ANTLR3_MARKER body_index)
523 {
524 @@ -312,7 +317,7 @@ public:
525 }
526
527 /// \brief push current AST, used for function definition
528 - /// \param current ast
529 + /// \param ast the pointer to the current ast
530 void push_current_ast(bash_ast* ast)
531 {
532 ast_stack.push(ast);
533 @@ -325,24 +330,29 @@ public:
534 }
535
536 /// \brief make function call
537 - /// \param function name
538 - /// \param function arguments
539 + /// \param name function name
540 + /// \param arguments function arguments
541 void call(const std::string& name,
542 const std::vector<std::string>& arguments);
543
544 /// \brief check if we have 'name' defined as a function
545 - /// \param function name
546 + /// \param name function name
547 /// \return whether 'name' is a function
548 bool has_function(const std::string& name) const
549 {
550 return functions.find(name) != functions.end();
551 }
552
553 + /// \brief get all defined function names
554 + /// \param[out] function_names the place to store the function names
555 void get_all_function_names(std::vector<std::string>& function_names) const;
556
557 /// \brief execute builtin
558 - /// \param builtin name
559 - /// \param builtin arguments
560 + /// \param name builtin name
561 + /// \param args builtin arguments
562 + /// \param output the output stream
563 + /// \param error the error stream
564 + /// \param input the input stream
565 /// \return the return value of the builtin
566 int execute_builtin(const std::string& name,
567 const std::vector<std::string>& args,
568 @@ -359,8 +369,9 @@ public:
569 }
570
571 /// \brief perform ${parameter:−word} expansion
572 - /// \param the name of the parameter
573 - /// \param the value of the word
574 + /// \param name the name of the parameter
575 + /// \param value the value of the word
576 + /// \param index the index of the paramter
577 /// \return the expansion result
578 const std::string do_default_expansion(const std::string& name,
579 const std::string& value,
580 @@ -371,8 +382,9 @@ public:
581 }
582
583 /// \brief perform ${parameter:=word} expansion
584 - /// \param the name of the parameter
585 - /// \param the value of the word
586 + /// \param name the name of the parameter
587 + /// \param value the value of the word
588 + /// \param index the index of the paramter
589 /// \return the expansion result
590 const std::string do_assign_expansion(const std::string& name,
591 const std::string& value,
592 @@ -383,8 +395,9 @@ public:
593 }
594
595 /// \brief perform ${parameter:+word} expansion
596 - /// \param the name of the parameter
597 - /// \param the value of the word
598 + /// \param name the name of the parameter
599 + /// \param value the value of the word
600 + /// \param index the index of the paramter
601 /// \return the expansion result
602 const std::string do_alternate_expansion(const std::string& name,
603 const std::string& value,
604 @@ -394,15 +407,19 @@ public:
605 }
606
607 /// \brief perform substring expansion
608 - /// \param the offset of the substring
609 + /// \param name the name of the parameter
610 + /// \param offset the offset of the substring
611 + /// \param index the index of the paramter
612 /// \return the expansion result
613 const std::string do_substring_expansion(const std::string& name,
614 long long offset,
615 const unsigned index) const;
616
617 /// \brief perform substring expansion
618 - /// \param the offset of the substring
619 - /// \param the length of the substring
620 + /// \param name the name of the parameter
621 + /// \param offset the offset of the substring
622 + /// \param length the length of the substring
623 + /// \param index the index of the paramter
624 /// \return the expansion result
625 const std::string do_substring_expansion(const std::string& name,
626 long long offset,
627 @@ -410,61 +427,64 @@ public:
628 const unsigned index) const;
629
630 /// \brief perform subarray expansion
631 - /// \param the offset of the subarray
632 + /// \param name the name of the parameter
633 + /// \param offset the offset of the subarray
634 /// \return the expansion result
635 const std::string do_subarray_expansion(const std::string& name,
636 long long offset) const;
637
638 /// \brief perform subarray expansion
639 - /// \param the offset of the subarray
640 - /// \param the length of the subarray
641 + /// \param name the name of the parameter
642 + /// \param offset the offset of the subarray
643 + /// \param length the length of the subarray
644 /// \return the expansion result
645 const std::string do_subarray_expansion(const std::string& name,
646 long long offset,
647 int length) const;
648
649 /// \brief perform replacement expansion
650 - /// \param the name of the varaible that needs to be expanded
651 - /// \param the function object used to perform expansion
652 - /// \param array index, use index=0 if it's not an array
653 + /// \param name the name of the varaible that needs to be expanded
654 + /// \param replacer the function object used to perform expansion
655 + /// \param index array index, use index=0 if it's not an array
656 /// \return the expanded value
657 std::string do_replace_expansion(const std::string& name,
658 std::function<void(std::string&)> replacer,
659 const unsigned index) const;
660
661 /// \brief get the length of a string variable
662 - /// \param the name of the variable
663 + /// \param name the name of the variable
664 + /// \param index the index of the variable
665 /// \return the length
666 std::string::size_type get_length(const std::string& name, const unsigned index=0) const;
667
668 /// \brief get the length of an array
669 - /// \param the name of the array
670 + /// \param name the name of the array
671 /// \return the length of the array
672 variable::size_type get_array_length(const std::string& name) const;
673
674 /// \brief get all array elements concatenated by space
675 - /// \param the name of the array
676 - /// \param[out] the concatenated string
677 - void get_all_elements(const std::string&, std::string&) const;
678 + /// \param name the name of the array
679 + /// \param[out] result the concatenated string
680 + void get_all_elements(const std::string& name, std::string& result) const;
681
682 /// \brief get all array elements concatenated by the first character of IFS
683 - /// \param the name of the array
684 - /// \param[out] the concatenated string
685 - void get_all_elements_IFS_joined(const std::string&, std::string&) const;
686 + /// \param name the name of the array
687 + /// \param[out] result the concatenated string
688 + void get_all_elements_IFS_joined(const std::string& name, std::string& result) const;
689
690 /// \brief implementation of word splitting
691 - /// \param the value of the word
692 - //. \param[out] the splitted result will be appended to output
693 + /// \param word the value of the word
694 + //. \param[out] output the splitted result will be appended to output
695 void split_word(const std::string& word, std::vector<std::string>& output) const;
696
697 /// \brief get the status of shell optional behavior
698 - /// \param the option name
699 + /// \param name the option name
700 /// \return zero unless the name is not a valid shell option
701 bool get_additional_option(const std::string& name) const;
702
703 /// \brief set the status of shell optional behavior
704 - /// \param the option name
705 - /// \param[in] true if option is enabled, false otherwise
706 + /// \param name the option name
707 + /// \param[in] value true if option is enabled, false otherwise
708 /// \return zero unless the name is not a valid shell option
709 void set_additional_option(const std::string& name, bool value);
710
711 @@ -484,34 +504,34 @@ public:
712 }
713
714 /// \brief evaluate arithmetic expression and return the result
715 - /// \param the arithmetic expression
716 + /// \param expression the arithmetic expression
717 /// \return the evaluated result
718 long eval_arithmetic(const std::string& expression);
719
720 /// \brief perform expansion like ${var//foo/bar}
721 - /// \param the value to be expanded
722 - /// \param the pattern used to match the value
723 - /// \param the replacement string
724 + /// \param value the value to be expanded
725 + /// \param pattern the pattern used to match the value
726 + /// \param replacement the replacement string
727 static void replace_all(std::string& value,
728 const boost::xpressive::sregex& pattern,
729 const std::string& replacement);
730
731 /// \brief perform expansion like ${var%foo}
732 - /// \param the value to be expanded
733 - /// \param the pattern used to match the value
734 + /// \param value the value to be expanded
735 + /// \param pattern the pattern used to match the value
736 static void lazy_remove_at_end(std::string& value,
737 const boost::xpressive::sregex& pattern);
738
739 /// \brief perform expansion like ${var/foo/bar}
740 - /// \param the value to be expanded
741 - /// \param the pattern used to match the value
742 - /// \param the replacement string
743 + /// \param value the value to be expanded
744 + /// \param pattern the pattern used to match the value
745 + /// \param replacement the replacement string
746 static void replace_first(std::string& value,
747 const boost::xpressive::sregex& pattern,
748 const std::string& replacement);
749
750 /// \brief remove trailing EOLs from the value
751 - /// \param[in, out] the target
752 + /// \param[in, out] value the target
753 static void trim_trailing_eols(std::string& value);
754 };
755 #endif
756
757 diff --git a/src/core/interpreter_exception.h b/src/core/interpreter_exception.h
758 index ea5a9ef..11f909f 100644
759 --- a/src/core/interpreter_exception.h
760 +++ b/src/core/interpreter_exception.h
761 @@ -38,6 +38,8 @@ namespace libbash
762 class LIBBASH_API interpreter_exception: public std::runtime_error
763 {
764 public:
765 + /// \brief the constructor
766 + /// \param err_msg the error message
767 explicit interpreter_exception(const std::string& err_msg):
768 runtime_error(err_msg){}
769 };
770
771 diff --git a/src/core/parse_exception.h b/src/core/parse_exception.h
772 index 20860b4..6f19bff 100644
773 --- a/src/core/parse_exception.h
774 +++ b/src/core/parse_exception.h
775 @@ -39,6 +39,8 @@ namespace libbash
776 class LIBBASH_API parse_exception: public libbash::interpreter_exception
777 {
778 public:
779 + /// \brief the constructor
780 + /// \param err_msg the error message
781 explicit parse_exception(const std::string& err_msg):
782 libbash::interpreter_exception(err_msg){}
783 };
784
785 diff --git a/src/core/readonly_exception.h b/src/core/readonly_exception.h
786 index 97964de..16d1106 100644
787 --- a/src/core/readonly_exception.h
788 +++ b/src/core/readonly_exception.h
789 @@ -39,6 +39,8 @@ namespace libbash
790 class LIBBASH_API readonly_exception: public libbash::interpreter_exception
791 {
792 public:
793 + /// \brief the constructor
794 + /// \param err_msg the error message
795 explicit readonly_exception(const std::string& err_msg):
796 libbash::interpreter_exception(err_msg){}
797 };
798
799 diff --git a/src/core/runtime_exception.h b/src/core/runtime_exception.h
800 index da6fffa..ed87655 100644
801 --- a/src/core/runtime_exception.h
802 +++ b/src/core/runtime_exception.h
803 @@ -39,6 +39,8 @@ namespace libbash
804 class LIBBASH_API runtime_exception: public libbash::interpreter_exception
805 {
806 public:
807 + /// \brief the constructor
808 + /// \param err_msg the error message
809 explicit runtime_exception(const std::string& err_msg):
810 libbash::interpreter_exception(err_msg){}
811 };
812
813 diff --git a/src/core/symbols.hpp b/src/core/symbols.hpp
814 index 8c6dec7..c535f8f 100644
815 --- a/src/core/symbols.hpp
816 +++ b/src/core/symbols.hpp
817 @@ -53,7 +53,7 @@ class converter<long>: public boost::static_visitor<long>
818 {
819 public:
820 /// \brief converter for long value
821 - /// \param the value to be converted
822 + /// \param value the value to be converted
823 /// \return the converted long
824 long operator() (const long value) const
825 {
826 @@ -61,7 +61,7 @@ public:
827 }
828
829 /// \brief converter for string value
830 - /// \param the value to be converted
831 + /// \param value the value to be converted
832 /// \return the converted long
833 long operator() (const std::string& value) const
834 {
835 @@ -88,7 +88,7 @@ class converter<std::string>:
836 {
837 public:
838 /// \brief converter for long value
839 - /// \param the value to be converted
840 + /// \param value the value to be converted
841 /// \return the converted string
842 std::string operator() (const long value) const
843 {
844 @@ -96,7 +96,7 @@ public:
845 }
846
847 /// \brief converter for string value
848 - /// \param the value to be converted
849 + /// \param value the value to be converted
850 /// \return the converted string
851 std::string operator() (const std::string& value) const
852 {
853 @@ -110,21 +110,19 @@ public:
854 ///
855 class variable
856 {
857 - /// \var private::name
858 /// \brief variable name
859 std::string name;
860
861 - /// \var private::value
862 /// \brief actual value of the variable. We put string in front of long
863 /// because we want "" as default string value; Otherwise we
864 /// will get "0".
865 std::map<unsigned, boost::variant<std::string, long>> value;
866
867 - /// \var private::readonly
868 /// \brief whether the variable is readonly
869 bool readonly;
870
871 public:
872 + /// size_type for array length
873 typedef std::map<unsigned, boost::variant<std::string, long>>::size_type size_type;
874
875 /// \brief retrieve variable name
876 @@ -134,6 +132,11 @@ public:
877 return name;
878 }
879
880 + /// \brief constructor
881 + /// \param name the name of the variable
882 + /// \param v the value of the variable
883 + /// \param ro whether the variable is readonly
884 + /// \param index the index of the variable, use 0 if it's not an array
885 template <typename T>
886 variable(const std::string& name,
887 const T& v,
888 @@ -146,6 +149,7 @@ public:
889
890 /// \brief retrieve actual value of the variable, if index is out of bound,
891 /// will return the default value of type T
892 + /// \param index the index of the variable, use 0 if it's not an array
893 /// \return the value of the variable
894 template<typename T>
895 T get_value(const unsigned index=0) const
896 @@ -160,7 +164,7 @@ public:
897 }
898
899 /// \brief retrieve all values of the array
900 - /// \param[out] vector that stores all array values
901 + /// \param[out] all_values vector that stores all array values
902 template<typename T>
903 void get_all_values(std::vector<T>& all_values) const
904 {
905 @@ -173,9 +177,8 @@ public:
906
907
908 /// \brief set the value of the variable, raise exception if it's readonly
909 - /// \param the new value to be set
910 - /// \param array index, use index=0 if it's not an array
911 - /// \param whether to set the variable to null value, default is false
912 + /// \param new_value the new value to be set
913 + /// \param index array index, use index=0 if it's not an array
914 template <typename T>
915 void set_value(const T& new_value,
916 const unsigned index=0)
917 @@ -187,7 +190,7 @@ public:
918 }
919
920 /// \brief unset the variable, only used for array variable
921 - /// \param the index to be unset
922 + /// \param index the index to be unset
923 void unset_value(const unsigned index)
924 {
925 if(readonly)
926 @@ -197,7 +200,7 @@ public:
927 }
928
929 /// \brief get the length of a variable
930 - /// \param the index of the variable, use 0 if it's not an array
931 + /// \param index the index of the variable, use 0 if it's not an array
932 /// \return the length of the variable
933 std::string::size_type get_length(const unsigned index=0) const
934 {
935 @@ -233,7 +236,10 @@ public:
936 }
937 };
938
939 -// specialization for arrays
940 +/// \brief the specialized constructor for arrays
941 +/// \param name the variable name
942 +/// \param value the variable value
943 +/// \param ro whether the variable readonly
944 template <>
945 inline variable::variable<>(const std::string& name,
946 const std::map<unsigned, std::string>& v,
947
948 diff --git a/src/core/unsupported_exception.h b/src/core/unsupported_exception.h
949 index 338b087..9920a5c 100644
950 --- a/src/core/unsupported_exception.h
951 +++ b/src/core/unsupported_exception.h
952 @@ -39,6 +39,8 @@ namespace libbash
953 class LIBBASH_API unsupported_exception: public libbash::interpreter_exception
954 {
955 public:
956 + /// \brief the constructor
957 + /// \param err_msg the error message
958 explicit unsupported_exception(const std::string& err_msg):
959 libbash::interpreter_exception(err_msg){}
960 };
961
962 diff --git a/src/cppbash_builtin.h b/src/cppbash_builtin.h
963 index c42ee1a..04ff387 100644
964 --- a/src/cppbash_builtin.h
965 +++ b/src/cppbash_builtin.h
966 @@ -34,6 +34,7 @@
967 #include <boost/scoped_ptr.hpp>
968 #include <boost/utility.hpp>
969
970 +/// shortcut for the arguments of the constructor
971 #define BUILTIN_ARGS std::ostream &out, std::ostream &err, std::istream &in, interpreter &walker
972
973 class interpreter;
974 @@ -46,9 +47,10 @@ class cppbash_builtin: public boost::noncopyable
975 public:
976 ///
977 /// \brief Default constructor, sets default streams
978 - /// \param outstream where to send standard output. Default: cout
979 - /// \param errstream where to send standard error. Default: cerr
980 - /// \param instream where to get standard input from. Default: stdin
981 + /// \param out where to send standard output. Default: cout
982 + /// \param err where to send standard error. Default: cerr
983 + /// \param in where to get standard input from. Default: stdin
984 + /// \param walker the interpreter object
985 ///
986 explicit cppbash_builtin(BUILTIN_ARGS);
987
988 @@ -75,6 +77,14 @@ class cppbash_builtin: public boost::noncopyable
989 ///
990 std::istream& input_buffer() {return *_inp_stream;}
991
992 + /// \brief execute the given builtin
993 + /// \param builtin the builtin name
994 + /// \param args the arguments
995 + /// \param out where to send standard output. Default: cout
996 + /// \param err where to send standard error. Default: cerr
997 + /// \param in where to get standard input from. Default: stdin
998 + /// \param walker the interpreter object
999 + /// \return the return status of the builtin
1000 static int exec(const std::string& builtin,
1001 const std::vector<std::string>& args,
1002 BUILTIN_ARGS)
1003 @@ -85,8 +95,8 @@ class cppbash_builtin: public boost::noncopyable
1004
1005 ///
1006 /// \brief check existence of the builtin
1007 - /// \param builtin name
1008 - /// \param whether it is a builtin
1009 + /// \param builtin builtin name
1010 + /// \return whether it is a builtin
1011 ///
1012 static bool is_builtin(const std::string& builtin)
1013 {
1014 @@ -111,21 +121,22 @@ class cppbash_builtin: public boost::noncopyable
1015 ///
1016 std::istream *_inp_stream;
1017
1018 + ///
1019 + /// \var _walker
1020 + /// \brief reference to the interpreter object
1021 interpreter& _walker;
1022
1023 - ///
1024 - /// \var builtins
1025 - /// \brief holds factories for creating instances of child classes
1026 - ///
1027 + /// holds factories for creating instances of child classes
1028 typedef std::map<std::string, boost::function< cppbash_builtin*(BUILTIN_ARGS) >> builtins_type;
1029 static builtins_type& builtins();
1030
1031 /// \brief transforms escapes in echo input
1032 - /// \param the target string
1033 - /// \param the place to write
1034 + /// \param string the target string
1035 + /// \param output the place to write
1036 void transform_escapes(const std::string &string, std::ostream& output) const;
1037 };
1038
1039 +/// shortcut for builtin constructor
1040 #define BUILTIN_CONSTRUCTOR(name) \
1041 name ## _builtin(BUILTIN_ARGS) : cppbash_builtin(out, err, in, walker) {}