public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/libbash:master commit in: src/, src/core/
@ 2011-04-05  6:37 Petteri Räty
  0 siblings, 0 replies; 2+ messages in thread
From: Petteri Räty @ 2011-04-05  6:37 UTC (permalink / raw
  To: gentoo-commits

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>();
     }
   }
 }



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [gentoo-commits] proj/libbash:master commit in: src/, src/core/
@ 2011-06-02 11:48 Petteri Räty
  0 siblings, 0 replies; 2+ messages in thread
From: Petteri Räty @ 2011-06-02 11:48 UTC (permalink / raw
  To: gentoo-commits

commit:     ae8b855bd14a965db5d9d49ca64e8c0c334874f0
Author:     Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu Jun  2 11:41:27 2011 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu Jun  2 11:41:27 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=ae8b855b

Core: prevent copying classes

Now classes that are not designed to be copyable inherit from
boost::noncopyable.

---
 src/core/bash_ast.h    |    3 ++-
 src/core/interpreter.h |    3 ++-
 src/cppbash_builtin.h  |    6 ++----
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/core/bash_ast.h b/src/core/bash_ast.h
index 9e388cb..5469d95 100644
--- a/src/core/bash_ast.h
+++ b/src/core/bash_ast.h
@@ -33,6 +33,7 @@
 #include <vector>
 
 #include <antlr3.h>
+#include <boost/utility.hpp>
 
 #include "libbashWalker.h"
 
@@ -42,7 +43,7 @@ class interpreter;
 
 /// \class bash_ast
 /// \brief a wrapper class that helps interpret from istream and string
-class bash_ast
+class bash_ast: public boost::noncopyable
 {
   pANTLR3_INPUT_STREAM input;
   std::string script;

diff --git a/src/core/interpreter.h b/src/core/interpreter.h
index 3420ee4..46c3d6a 100644
--- a/src/core/interpreter.h
+++ b/src/core/interpreter.h
@@ -32,6 +32,7 @@
 #include <string>
 
 #include <antlr3basetree.h>
+#include <boost/utility.hpp>
 #include <boost/xpressive/xpressive.hpp>
 
 #include "core/symbols.hpp"
@@ -46,7 +47,7 @@ typedef struct libbashWalker_Ctx_struct * plibbashWalker;
 /// \class interpreter
 /// \brief implementation for bash interpreter
 ///
-class interpreter
+class interpreter: public boost::noncopyable
 {
 
   /// \var private::members

diff --git a/src/cppbash_builtin.h b/src/cppbash_builtin.h
index e7b68ea..11c1edb 100644
--- a/src/cppbash_builtin.h
+++ b/src/cppbash_builtin.h
@@ -33,6 +33,7 @@
 #include <boost/functional/factory.hpp>
 #include <boost/function.hpp>
 #include <boost/scoped_ptr.hpp>
+#include <boost/utility.hpp>
 
 #define BUILTIN_ARGS std::ostream &out, std::ostream &err, std::istream &in, interpreter &walker
 
@@ -41,7 +42,7 @@ class interpreter;
 /// \class cppbash_builtin
 /// \brief a virtual class to inherit builtin functions from
 ///
-class cppbash_builtin
+class cppbash_builtin: public boost::noncopyable
 {
   public:
     ///
@@ -51,9 +52,6 @@ class cppbash_builtin
     /// \param instream where to get standard input from.  Default: stdin
     ///
     explicit cppbash_builtin(BUILTIN_ARGS);
-    /// prevent copying
-    cppbash_builtin(const cppbash_builtin& ) = delete;
-    const cppbash_builtin& operator=( const cppbash_builtin& ) = delete;
 
     virtual ~cppbash_builtin() {};
     ///



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-06-02 11:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-02 11:48 [gentoo-commits] proj/libbash:master commit in: src/, src/core/ Petteri Räty
  -- strict thread matches above, loose matches on Subject: below --
2011-04-05  6:37 Petteri Räty

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox