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 1QLZM2-0003YY-7M for garchives@archives.gentoo.org; Sun, 15 May 2011 11:19:23 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 7D2221C041; Sun, 15 May 2011 11:19:15 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 407961C041 for ; Sun, 15 May 2011 11:19:15 +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 D37EE1B4062 for ; Sun, 15 May 2011 11:19:14 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 0189480504 for ; Sun, 15 May 2011 11:19:14 +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/command_execution.bash scripts/command_execution.bash.result src/core/interpreter.cpp 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: d869ca70e03de7a07d041900592e8b3af2b2a562 Date: Sun, 15 May 2011 11:19:14 +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: b2978a4df1568eb14539f36d7990f7d9 commit: d869ca70e03de7a07d041900592e8b3af2b2a562 Author: Mu Qiao gentoo org> AuthorDate: Sun May 15 06:08:10 2011 +0000 Commit: Petteri R=C3=A4ty gentoo org> CommitDate: Sun May 15 10:40:51 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/libbash.git;a= =3Dcommit;h=3Dd869ca70 Walker: fix a bug in command stack handling All commands, built-ins and functions should have their own local scope(or command environment). Take "foo=3Dabc bar" for example, the variable foo need to be stored in local scope. We only cared about the local scope for functions, which caused the example crash. Now it's fixed by creating local scopes in the walker grammar. --- bashast/libbashWalker.g | 18 ++++++++++++------ scripts/command_execution.bash | 1 + scripts/command_execution.bash.result | 1 + src/core/interpreter.cpp | 6 +----- src/core/interpreter.h | 20 ++++++++++++++++++++ 5 files changed, 35 insertions(+), 11 deletions(-) diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g index 5b22e7a..bd87ee8 100644 --- a/bashast/libbashWalker.g +++ b/bashast/libbashWalker.g @@ -439,13 +439,19 @@ simple_command @declarations { std::vector libbash_args; } - :^(COMMAND string_expr (argument[libbash_args])* var_def[true]*) { - if(walker->has_function($string_expr.libbash_value)) + :^(COMMAND string_expr (argument[libbash_args])* execute_command[$strin= g_expr.libbash_value, libbash_args]); + +execute_command[const std::string& name, std::vector& libba= sh_args] +@declarations { + interpreter::local_scope current_scope(*walker); +} + :var_def[true]* { + if(walker->has_function(name)) { ANTLR3_MARKER command_index =3D INDEX(); try { - walker->set_status(walker->call($string_expr.libbash_value, + walker->set_status(walker->call(name, libbash_args, ctx, compound_command)); @@ -455,13 +461,13 @@ simple_command SEEK(command_index); } } - else if(cppbash_builtin::is_builtin($string_expr.libbash_value)) + else if(cppbash_builtin::is_builtin(name)) { - walker->set_status(walker->execute_builtin($string_expr.libbash_value= , libbash_args)); + walker->set_status(walker->execute_builtin(name, libbash_args)); } else { - std::cerr << $string_expr.libbash_value << " is not supported yet" <<= std::endl; + std::cerr << name << " is not supported yet" << std::endl; walker->set_status(1); } }; diff --git a/scripts/command_execution.bash b/scripts/command_execution.b= ash index 3664356..821d061 100644 --- a/scripts/command_execution.bash +++ b/scripts/command_execution.bash @@ -13,3 +13,4 @@ false && echo "wrong" false || echo "right" true || echo "wrong" echo "end" +FOO=3D"abc" echo "command environment" diff --git a/scripts/command_execution.bash.result b/scripts/command_exec= ution.bash.result index d9f3021..8bd7226 100644 --- a/scripts/command_execution.bash.result +++ b/scripts/command_execution.bash.result @@ -3,5 +3,6 @@ hello world right right end +command environment FOO001=3Dhello FOO002=3DHello World diff --git a/src/core/interpreter.cpp b/src/core/interpreter.cpp index 1102138..2214613 100644 --- a/src/core/interpreter.cpp +++ b/src/core/interpreter.cpp @@ -206,8 +206,7 @@ int interpreter::call(const std::string& name, return -1; func_index =3D iter->second; =20 - // Prepare function stack and arguments - local_members.push_back(scope()); + // Prepare arguments define_function_arguments(local_members.back(), arguments); =20 auto INPUT =3D ctx->pTreeParser->ctnstream; @@ -221,9 +220,6 @@ int interpreter::call(const std::string& name, // Reset to the previous index ISTREAM->seek(ISTREAM, curr); =20 - // Clear function stack - local_members.pop_back(); - return 0; } =20 diff --git a/src/core/interpreter.h b/src/core/interpreter.h index d71885a..c46afe1 100644 --- a/src/core/interpreter.h +++ b/src/core/interpreter.h @@ -87,6 +87,26 @@ class interpreter =20 public: =20 + /// + /// \class local_scope + /// \brief RAII concept for local scope management + /// + class local_scope + { + interpreter& walker; + + public: + local_scope(interpreter& w): walker(w) + { + walker.local_members.push_back(scope()); + } + + ~local_scope() + { + walker.local_members.pop_back(); + } + }; + interpreter(): out(&std::cout), err(&std::cerr), in(&std::cin) { define("IFS", " \t\n");