gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash ChangeLog server/as_environment.cpp serve...


From: Sandro Santilli
Subject: [Gnash-commit] gnash ChangeLog server/as_environment.cpp serve...
Date: Fri, 08 Dec 2006 23:11:25 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Sandro Santilli <strk>  06/12/08 23:11:25

Modified files:
        .              : ChangeLog 
        server         : as_environment.cpp as_environment.h 
        server/vm      : ActionExec.cpp ActionExec.h 

Log message:
                * server/as_environment.{cpp,h}: obsoleted crappy find_local 
function,
                  substituted with iterators-based equivalent; typedef'd
                  LocalFrames; added del_variable_raw method.
                * server/vm/ActionExec.{cpp,h}: added delVariable() method, 
invoking
                  as_environment::del_variable_raw with current 'with' stack.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.1897&r2=1.1898
http://cvs.savannah.gnu.org/viewcvs/gnash/server/as_environment.cpp?cvsroot=gnash&r1=1.35&r2=1.36
http://cvs.savannah.gnu.org/viewcvs/gnash/server/as_environment.h?cvsroot=gnash&r1=1.29&r2=1.30
http://cvs.savannah.gnu.org/viewcvs/gnash/server/vm/ActionExec.cpp?cvsroot=gnash&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/gnash/server/vm/ActionExec.h?cvsroot=gnash&r1=1.2&r2=1.3

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.1897
retrieving revision 1.1898
diff -u -b -r1.1897 -r1.1898
--- ChangeLog   8 Dec 2006 16:10:34 -0000       1.1897
+++ ChangeLog   8 Dec 2006 23:11:25 -0000       1.1898
@@ -1,5 +1,13 @@
 2006-12-08 Sandro Santilli <address@hidden>
 
+       * server/as_environment.{cpp,h}: obsoleted crappy find_local function,
+         substituted with iterators-based equivalent; typedef'd
+         LocalFrames; added del_variable_raw method.
+       * server/vm/ActionExec.{cpp,h}: added delVariable() method, invoking
+         as_environment::del_variable_raw with current 'with' stack.
+
+2006-12-08 Sandro Santilli <address@hidden>
+
        * server/as_object.{cpp,h}: added delProperty() member.
        * server/PropertyList.{cpp,h}: added delProperty() member.
        * testsuite/server/PropertyListTest.cpp: added test for delProperty().

Index: server/as_environment.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/as_environment.cpp,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -b -r1.35 -r1.36
--- server/as_environment.cpp   7 Dec 2006 15:26:04 -0000       1.35
+++ server/as_environment.cpp   8 Dec 2006 23:11:25 -0000       1.36
@@ -16,7 +16,7 @@
 
 //
 
-/* $Id: as_environment.cpp,v 1.35 2006/12/07 15:26:04 strk Exp $ */
+/* $Id: as_environment.cpp,v 1.36 2006/12/08 23:11:25 strk Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -88,10 +88,10 @@
     }
 
     // Check locals.
-    int        local_index = find_local(varname);
-    if (local_index >= 0) {
+    LocalFrames::const_iterator it = findLocal(varname);
+    if (it != endLocal()) {
        // Get local var.
-       return m_local_frames[local_index].m_value;
+       return it->m_value;
     }
     
     // Looking for "this"?
@@ -128,6 +128,44 @@
     return as_value();
 }
 
+bool
+as_environment::del_variable_raw(
+    const std::string& varname,
+    const std::vector<with_stack_entry>& with_stack) 
+    // varname must be a plain variable name; no path parsing.
+{
+    assert(strchr(varname.c_str(), ':') == NULL);
+    assert(strchr(varname.c_str(), '/') == NULL);
+    assert(strchr(varname.c_str(), '.') == NULL);
+
+    as_value   val;
+
+    // Check the with-stack.
+    for (size_t i = with_stack.size(); i > 0; --i) {
+       as_object* obj = with_stack[i-1].m_object.get();
+       if (obj && obj->delProperty(varname)) {
+           // TODO: this is surely wrong, we don't want to keep seeking
+           // if a property is found probably, even if it's flags forbid 
deletion
+           // var is deletable in this context
+           return true;
+       }
+    }
+
+    // Check locals.
+    LocalFrames::iterator it = findLocal(varname);
+    if (it != endLocal())
+    {
+       // delete local var.
+       // This sucks, we need m_local_frames to be a list
+       // or map, NOT A VECTOR !
+       m_local_frames.erase(it);
+       return true;
+    }
+
+    // Try target
+    return m_target->delProperty(varname);
+}
+
 // varname must be a plain variable name; no path parsing.
 as_value
 as_environment::get_variable_raw(const std::string& varname) const
@@ -159,7 +197,7 @@
            target->set_member(var.c_str(), val);
        }
     } else {
-       this->set_variable_raw(varname, val, with_stack);
+       set_variable_raw(varname, val, with_stack);
     }
 }
 
@@ -192,10 +230,10 @@
        }
     
     // Check locals.
-    int        local_index = find_local(varname);
-    if (local_index >= 0) {
+    LocalFrames::iterator it = findLocal(varname);
+    if (it != endLocal()) {
        // Set local var.
-       m_local_frames[local_index].m_value = val;
+       it->m_value = val;
        return;
     }
     
@@ -218,15 +256,14 @@
 as_environment::set_local(const std::string& varname, const as_value& val)
 {
     // Is it in the current frame already?
-    int        index = find_local(varname);
-    if (index < 0) {
+    LocalFrames::iterator it = findLocal(varname), itEnd=endLocal();
+    if (it == itEnd) {
        // Not in frame; create a new local var.
-       
        assert(varname.length() > 0);   // null varnames are invalid!
        m_local_frames.push_back(frame_slot(varname, val));
     } else {
        // In frame already; modify existing var.
-       m_local_frames[index].m_value = val;
+       it->m_value = val;
     }
 }
        
@@ -246,8 +283,8 @@
 as_environment::declare_local(const std::string& varname)
 {
     // Is it in the current frame already?
-    int        index = find_local(varname);
-    if (index < 0) {
+    LocalFrames::const_iterator it = findLocal(varname), itEnd=endLocal();
+    if (it == itEnd) {
        // Not in frame; create a new local var.
        assert(varname.length() > 0);   // null varnames are invalid!
        m_local_frames.push_back(frame_slot(varname, as_value()));
@@ -293,33 +330,6 @@
        m_local_register.resize(m_local_register.size() + register_count);
 }
 
-
-// Search the active frame for the named var; return its index
-// in the m_local_frames stack if found.
-// 
-// Otherwise return -1.
-int
-as_environment::find_local(const std::string& varname) const
-{
-    // Linear search sucks, but is probably fine for
-    // typical use of local vars in script.  There could
-    // be pathological breakdowns if a function has tons
-    // of locals though.  The ActionScript bytecode does
-    // not help us much by using strings to index locals.
-    
-    for (int i = m_local_frames.size() - 1; i >= 0; i--) {
-       const frame_slot&       slot = m_local_frames[i];
-       if (slot.m_name.length() == 0) {
-           // End of local frame; stop looking.
-           return -1;
-       } else if (slot.m_name == varname) {
-           // Found it.
-           return i;
-       }
-    }
-    return -1;
-}
-
 /* public static */
 bool
 as_environment::parse_path(const std::string& var_path,
@@ -513,6 +523,21 @@
        if ( defined ) out << "Global registers (" << defined << "): " << 
registers << std::endl;
 }
 
+/*private*/
+as_environment::LocalFrames::iterator
+as_environment::findLocal(const std::string& varname)
+{
+       LocalFrames::iterator itEnd=endLocal();
+       for (LocalFrames::iterator it=beginLocal();
+                       it != itEnd;
+                       ++it)
+       {
+               frame_slot& slot = *it;
+               if ( slot.m_name == varname ) return it;
+       }
+       return itEnd;
+}
+
 }
 
 

Index: server/as_environment.h
===================================================================
RCS file: /sources/gnash/gnash/server/as_environment.h,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -b -r1.29 -r1.30
--- server/as_environment.h     7 Dec 2006 14:16:46 -0000       1.29
+++ server/as_environment.h     8 Dec 2006 23:11:25 -0000       1.30
@@ -18,7 +18,7 @@
 //
 //
 
-/* $Id: as_environment.h,v 1.29 2006/12/07 14:16:46 strk Exp $ */
+/* $Id: as_environment.h,v 1.30 2006/12/08 23:11:25 strk Exp $ */
 
 #ifndef GNASH_AS_ENVIRONMENT_H
 #define GNASH_AS_ENVIRONMENT_H
@@ -67,10 +67,6 @@
                }
        };
 
-       /// local variables
-       std::vector<frame_slot> m_local_frames;
-
-
        as_environment()
                :
                m_target(0)
@@ -142,6 +138,16 @@
        as_value get_variable_raw(const std::string& varname) const;
 
        /// \brief
+       /// Delete a variable, w/out support for the path, seeking
+       /// in the given 'with' stack.
+       //
+       /// TODO: varname should be likely case-insensitive up to SWF6
+       ///       and case-SENSITIVE from SWF7 on
+       ///
+       bool del_variable_raw(const std::string& varname,
+                       const std::vector<with_stack_entry>& with_stack);
+
+       /// \brief
        /// Return the (possibly UNDEFINED) value of the named var.
        /// Variable name can contain path elements.
        /// Uses the with_stack ActionContext
@@ -286,6 +292,16 @@
        /// The variables container (case-insensitive)
        typedef std::map<std::string, as_value, StringNoCaseLessThen> Variables;
 
+       /// The locals container (TODO: use a std::map here !)
+       typedef std::vector<frame_slot> LocalFrames;
+
+       /// Local variables.
+       //
+       /// TODO: make private. currently an hack in timers.cpp prevents this.
+       ///
+       LocalFrames m_local_frames;
+
+
 private:
 
        /// Variables available in this environment
@@ -299,8 +315,6 @@
        /// Movie target. 
        character* m_target;
 
-       int find_local(const std::string& varname) const;
-
        /// Given a variable name, set its value (no support for path)
        void set_variable_raw(const std::string& path, const as_value& val,
                const std::vector<with_stack_entry>& with_stack);
@@ -310,6 +324,31 @@
                const std::vector<with_stack_entry>& with_stack) const;
 
 
+       /// Return an iterator to the local variable with given name,
+       /// or an iterator to it's end() iterator if none found
+       LocalFrames::iterator findLocal(const std::string& varname);
+
+       LocalFrames::const_iterator findLocal(const std::string& varname) const
+       {
+               return const_cast<as_environment*>(this)->findLocal(varname);
+       }
+
+       LocalFrames::iterator endLocal() {
+               return m_local_frames.end();
+       }
+
+       LocalFrames::const_iterator endLocal() const {
+               return m_local_frames.end();
+       }
+
+       LocalFrames::iterator beginLocal() {
+               return m_local_frames.begin();
+       }
+
+       LocalFrames::const_iterator beginLocal() const {
+               return m_local_frames.begin();
+       }
+
 };
 
 

Index: server/vm/ActionExec.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/vm/ActionExec.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- server/vm/ActionExec.cpp    7 Dec 2006 13:55:56 -0000       1.3
+++ server/vm/ActionExec.cpp    8 Dec 2006 23:11:25 -0000       1.4
@@ -16,7 +16,7 @@
 
 //
 
-/* $Id: ActionExec.cpp,v 1.3 2006/12/07 13:55:56 strk Exp $ */
+/* $Id: ActionExec.cpp,v 1.4 2006/12/08 23:11:25 strk Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -247,6 +247,12 @@
        }
 }
 
+bool
+ActionExec::delVariable(const std::string& name)
+{
+       return env.del_variable_raw(name, with_stack);
+}
+
 } // end of namespace gnash
 
 

Index: server/vm/ActionExec.h
===================================================================
RCS file: /sources/gnash/gnash/server/vm/ActionExec.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- server/vm/ActionExec.h      6 Dec 2006 10:58:34 -0000       1.2
+++ server/vm/ActionExec.h      8 Dec 2006 23:11:25 -0000       1.3
@@ -148,6 +148,12 @@
        ///
        void skip_actions(size_t offset);
 
+       /// \brief
+       /// Delete named variable, seeking for
+       /// it in the with stack if any
+       //
+       bool delVariable(const std::string& name);
+
        /// Execute.
        void operator() ();
 };




reply via email to

[Prev in Thread] Current Thread [Next in Thread]