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 1Q6ztg-0004Me-Id for garchives@archives.gentoo.org; Tue, 05 Apr 2011 06:37:52 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 19C70E063D; Tue, 5 Apr 2011 06:37:44 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id C5F8BE063D for ; Tue, 5 Apr 2011 06:37:43 +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 2269B1B409C for ; Tue, 5 Apr 2011 06:37:43 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 3A1A880065 for ; Tue, 5 Apr 2011 06:37:42 +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: <521f35d17053082429276d4ecfd4e1962c01dee8.betelgeuse@gentoo> Subject: [gentoo-commits] proj/libbash:master commit in: src/, src/core/ X-VCS-Repository: proj/libbash X-VCS-Files: src/core/interpreter.h src/core/symbols.hpp src/libbash.cpp X-VCS-Directories: src/ src/core/ X-VCS-Committer: betelgeuse X-VCS-Committer-Name: Petteri Räty X-VCS-Revision: 521f35d17053082429276d4ecfd4e1962c01dee8 Date: Tue, 5 Apr 2011 06:37:42 +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: 6b3329d16a6c04d76bb5fa57c2f64377 commit: 521f35d17053082429276d4ecfd4e1962c01dee8 Author: Petteri R=C3=A4ty petteriraty eu> AuthorDate: Mon Apr 4 19:12:02 2011 +0000 Commit: Petteri R=C3=A4ty gentoo org> CommitDate: Mon Apr 4 19:12:02 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/libbash.git;a= =3Dcommit;h=3D521f35d1 Remove usage of static_pointer_cast Casting pointers like that is a sign of bast design. We only support variables at this point so there's no need for abstractions yet. Variables and functions can't live in the same symbol table any way as bash allows there to be both a function and a variable with the same name. --- src/core/interpreter.h | 12 +++--- src/core/symbols.hpp | 88 ++++++++++++++++++++----------------------= ----- src/libbash.cpp | 2 +- 3 files changed, 45 insertions(+), 57 deletions(-) diff --git a/src/core/interpreter.h b/src/core/interpreter.h index 5e097ea..340828a 100644 --- a/src/core/interpreter.h +++ b/src/core/interpreter.h @@ -356,10 +356,10 @@ public: template T resolve(const std::string& name) { - std::shared_ptr value =3D members.resolve(name); + std::shared_ptr value =3D members.resolve(name); if(!value) return T(); - return std::static_pointer_cast(value)->get_value(); + return value->get_value(); } =20 /// \brief check whether the value of the variable is null, return tru= e @@ -368,9 +368,9 @@ public: /// \return whether the value of the variable is null bool is_null(const std::string& name) { - std::shared_ptr value =3D members.resolve(name); + std::shared_ptr value =3D members.resolve(name); if(value) - return std::static_pointer_cast(value)->is_null(); + return value->is_null(); else return true; } @@ -391,11 +391,11 @@ public: template const T& set_value(const std::string& name, const T& new_value) { - std::shared_ptr value =3D members.resolve(name); + std::shared_ptr value =3D members.resolve(name); if(!value) define(name, new_value, false); else - std::static_pointer_cast(value)->set_value(new_value); + value->set_value(new_value); return new_value; } =20 diff --git a/src/core/symbols.hpp b/src/core/symbols.hpp index 8734548..825ba87 100644 --- a/src/core/symbols.hpp +++ b/src/core/symbols.hpp @@ -37,29 +37,6 @@ #include "core/interpreter_exception.h" =20 /// -/// \class symbol -/// \brief base class for symbols such as variables and functions -/// -class symbol -{ - /// \var private::name - /// \brief symbol name - std::string name; - -public: - /// \brief retrieve symbol name - /// \return const string value of symbol name - const std::string& get_name() const - { - return name; - } - -protected: - symbol(const std::string& n): name(n){} - ~symbol() {} -}; - -/// /// \class converter /// \brief template class of converter /// @@ -131,30 +108,41 @@ public: /// \class variable /// \brief implementation for all variable types /// -class variable: public symbol +class variable { + /// \var private::name + /// \brief variable name + std::string name; + /// \var private::value - /// \brief actual value of the symbol + /// \brief actual value of the variable boost::variant value; =20 /// \var private::readonly - /// \brief whether the symbol is readonly + /// \brief whether the variable is readonly bool readonly; =20 /// \var private::null_value - /// \brief whether the symbol is null=20 + /// \brief whether the variable is null bool null_value; =20 public: + /// \brief retrieve variable name + /// \return const string value of variable name + const std::string& get_name() const + { + return name; + } + template variable(const std::string& name, T v, bool ro=3Dfalse, bool is_null=3Dfalse) - : symbol(name), value(v), readonly(ro), null_value(is_null){} + : name(name), value(v), readonly(ro), null_value(is_null){} =20 - /// \brief retrieve actual value of the symbol - /// \return the value of the symbol + /// \brief retrieve actual value of the variable + /// \return the value of the variable template T get_value() const { @@ -162,7 +150,7 @@ public: return boost::apply_visitor(visitor, value); } =20 - /// \brief set the value of the symbol, raise exception if it's readon= ly + /// \brief set the value of the variable, raise exception if it's read= only /// \param the new value to be set /// \param whether to set the variable to null value, default is false template @@ -189,7 +177,7 @@ public: class scope { public: - typedef std::unordered_map> + typedef std::unordered_map> table_type; typedef table_type::iterator iterator; typedef table_type::const_iterator const_iterator; @@ -197,24 +185,24 @@ public: typedef table_type::value_type value_type; =20 /// - /// \brief return the number of symbols in current scope - /// \return the number of symbols + /// \brief return the number of variables in current scope + /// \return the number of variables size_type size() { return members.size(); } =20 /// - /// \brief return an iterator referring to the first symbol - /// \return iterator referring to the first symbol + /// \brief return an iterator referring to the first variable + /// \return iterator referring to the first variable iterator begin() { return members.begin(); } =20 /// - /// \brief return a const iterator referring to the first symbol - /// \return const iterator referring to the first symbol + /// \brief return a const iterator referring to the first variable + /// \return const iterator referring to the first variable const_iterator begin() const { return members.begin(); @@ -222,9 +210,9 @@ public: =20 /// /// \brief return an iterator referring to the next element after - /// the last symbol in current scope + /// the last variable in current scope /// \return iterator referring to he next element after the last - /// symbol in current scope + /// variable in current scope iterator end() { return members.end(); @@ -232,28 +220,28 @@ public: =20 /// /// \brief return a const iterator referring to the next element - /// after the last symbol in current scope + /// after the last variable in current scope /// \return const iterator referring to he next element after the - /// last symbol in current scope + /// last variable in current scope const_iterator end() const { return members.end(); } =20 - /// \brief define a new symbol - /// \param the new symbol - void define(std::shared_ptr s) + /// \brief define a new variable + /// \param the new variable + void define(std::shared_ptr s) { members[s->get_name()] =3D s; } =20 - /// \brief resolve a symbol - /// \param the symbol name - /// \return target symbol passed by reference - std::shared_ptr resolve(const std::string& name) + /// \brief resolve a variable + /// \param the variable name + /// \return target variable passed by reference + std::shared_ptr resolve(const std::string& name) { auto iter =3D members.find(name); - return (iter =3D=3D members.end()? std::shared_ptr() : iter-= >second); + return (iter =3D=3D members.end()? std::shared_ptr() : ite= r->second); } protected: /// \var protected::member diff --git a/src/libbash.cpp b/src/libbash.cpp index e821d81..19ca4b1 100644 --- a/src/libbash.cpp +++ b/src/libbash.cpp @@ -72,7 +72,7 @@ namespace libbash =20 for(auto iter =3D walker->begin(); iter !=3D walker->end(); ++iter) { - variables[iter->first]=3Dstd::static_pointer_cast(iter->= second)->get_value(); + variables[iter->first]=3Diter->second->get_value(); } } }