public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Petteri Räty" <betelgeuse@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/libbash:master commit in: src/, src/core/
Date: Tue,  5 Apr 2011 06:37:42 +0000 (UTC)	[thread overview]
Message-ID: <521f35d17053082429276d4ecfd4e1962c01dee8.betelgeuse@gentoo> (raw)

commit:     521f35d17053082429276d4ecfd4e1962c01dee8
Author:     Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Mon Apr  4 19:12:02 2011 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Mon Apr  4 19:12:02 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=521f35d1

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 <typename T>
   T resolve(const std::string& name)
   {
-    std::shared_ptr<symbol> value = members.resolve(name);
+    std::shared_ptr<variable> value = members.resolve(name);
     if(!value)
       return T();
-    return std::static_pointer_cast<variable>(value)->get_value<T>();
+    return value->get_value<T>();
   }
 
   /// \brief check whether the value of the variable is null, return true
@@ -368,9 +368,9 @@ public:
   /// \return whether the value of the variable is null
   bool is_null(const std::string& name)
   {
-    std::shared_ptr<symbol> value = members.resolve(name);
+    std::shared_ptr<variable> value = members.resolve(name);
     if(value)
-      return std::static_pointer_cast<variable>(value)->is_null();
+      return value->is_null();
     else
       return true;
   }
@@ -391,11 +391,11 @@ public:
   template <typename T>
   const T& set_value(const std::string& name, const T& new_value)
   {
-    std::shared_ptr<symbol> value = members.resolve(name);
+    std::shared_ptr<variable> value = members.resolve(name);
     if(!value)
       define(name, new_value, false);
     else
-      std::static_pointer_cast<variable>(value)->set_value(new_value);
+      value->set_value(new_value);
     return new_value;
   }
 

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"
 
 ///
-/// \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<int, std::string> value;
 
   /// \var private::readonly
-  /// \brief whether the symbol is readonly
+  /// \brief whether the variable is readonly
   bool readonly;
 
   /// \var private::null_value
-  /// \brief whether the symbol is null 
+  /// \brief whether the variable is null
   bool null_value;
 
 public:
+  /// \brief retrieve variable name
+  /// \return const string value of variable name
+  const std::string& get_name() const
+  {
+    return name;
+  }
+
   template <typename T>
   variable(const std::string& name,
            T v,
            bool ro=false,
            bool is_null=false)
-    : symbol(name), value(v), readonly(ro), null_value(is_null){}
+    : name(name), value(v), readonly(ro), null_value(is_null){}
 
-  /// \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<typename T>
   T get_value() const
   {
@@ -162,7 +150,7 @@ public:
     return boost::apply_visitor(visitor, value);
   }
 
-  /// \brief set the value of the symbol, raise exception if it's readonly
+  /// \brief set the value of the variable, raise exception if it's readonly
   /// \param the new value to be set
   /// \param whether to set the variable to null value, default is false
   template <typename T>
@@ -189,7 +177,7 @@ public:
 class scope
 {
 public:
-  typedef std::unordered_map<std::string, std::shared_ptr<symbol>>
+  typedef std::unordered_map<std::string, std::shared_ptr<variable>>
     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;
 
   ///
-  /// \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();
   }
 
   ///
-  /// \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();
   }
 
   ///
-  /// \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:
 
   ///
   /// \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:
 
   ///
   /// \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();
   }
 
-  /// \brief define a new symbol
-  /// \param the new symbol
-  void define(std::shared_ptr<symbol> s)
+  /// \brief define a new variable
+  /// \param the new variable
+  void define(std::shared_ptr<variable> s)
   {
     members[s->get_name()] = s;
   }
 
-  /// \brief resolve a symbol
-  /// \param the symbol name
-  /// \return target symbol passed by reference
-  std::shared_ptr<symbol> resolve(const std::string& name)
+  /// \brief resolve a variable
+  /// \param the variable name
+  /// \return target variable passed by reference
+  std::shared_ptr<variable> resolve(const std::string& name)
   {
     auto iter = members.find(name);
-    return (iter == members.end()? std::shared_ptr<symbol>() : iter->second);
+    return (iter == members.end()? std::shared_ptr<variable>() : iter->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
 
     for(auto iter = walker->begin(); iter != walker->end(); ++iter)
     {
-      variables[iter->first]=std::static_pointer_cast<variable>(iter->second)->get_value<std::string>();
+      variables[iter->first]=iter->second->get_value<std::string>();
     }
   }
 }



             reply	other threads:[~2011-04-05  6:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-05  6:37 Petteri Räty [this message]
  -- strict thread matches above, loose matches on Subject: below --
2011-06-02 11:48 [gentoo-commits] proj/libbash:master commit in: src/, src/core/ Petteri Räty

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=521f35d17053082429276d4ecfd4e1962c01dee8.betelgeuse@gentoo \
    --to=betelgeuse@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox