[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ./ChangeLog server/Makefile.am server/act...
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ./ChangeLog server/Makefile.am server/act... |
Date: |
Fri, 19 May 2006 18:09:03 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Branch:
Changes by: Sandro Santilli <address@hidden> 06/05/19 18:09:03
Modified files:
. : ChangeLog
server : Makefile.am action.cpp action.h movie.h
Added files:
server : as_environment.cpp as_environment.h
Log message:
* server/Makefile.am, server/action.cpp, server/action.h,
server/as_environment.cpp, server/as_environment.h,
server/movie.h: put as_environment class in it's own
files.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/gnash/ChangeLog.diff?tr1=1.364&tr2=1.365&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/gnash/gnash/server/Makefile.am.diff?tr1=1.43&tr2=1.44&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/gnash/gnash/server/action.cpp.diff?tr1=1.76&tr2=1.77&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/gnash/gnash/server/action.h.diff?tr1=1.29&tr2=1.30&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/gnash/gnash/server/as_environment.cpp?rev=1.1
http://cvs.savannah.gnu.org/viewcvs/gnash/gnash/server/as_environment.h?rev=1.1
http://cvs.savannah.gnu.org/viewcvs/gnash/gnash/server/movie.h.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
Patches:
Index: gnash/ChangeLog
diff -u gnash/ChangeLog:1.364 gnash/ChangeLog:1.365
--- gnash/ChangeLog:1.364 Fri May 19 15:03:54 2006
+++ gnash/ChangeLog Fri May 19 18:09:03 2006
@@ -1,5 +1,9 @@
2006-05-19 Sandro Santilli <address@hidden>
+ * server/Makefile.am, server/action.cpp, server/action.h,
+ server/as_environment.cpp, server/as_environment.h,
+ server/movie.h: put as_environment class in it's own
+ files.
* testsuite/libbase/.cvsignore: new file
* testsuite/misc-ming.all/.cvsignore: new file
* server/swf/tag_loaders.{cpp,h}: doxygen comments for
Index: gnash/server/Makefile.am
diff -u gnash/server/Makefile.am:1.43 gnash/server/Makefile.am:1.44
--- gnash/server/Makefile.am:1.43 Thu May 18 11:53:02 2006
+++ gnash/server/Makefile.am Fri May 19 18:09:03 2006
@@ -123,6 +123,7 @@
libgnashserver_la_SOURCES = \
as_value.cpp \
+ as_environment.cpp \
character.cpp \
textformat.cpp \
timers.cpp \
@@ -167,6 +168,7 @@
action.h \
array.h \
as_value.h \
+ as_environment.h \
as_member.h \
as_prop_flags.h \
as_object.h \
Index: gnash/server/action.cpp
diff -u gnash/server/action.cpp:1.76 gnash/server/action.cpp:1.77
--- gnash/server/action.cpp:1.76 Tue May 16 16:47:37 2006
+++ gnash/server/action.cpp Fri May 19 18:09:03 2006
@@ -1330,399 +1330,6 @@
//
-// as_environment
-//
-
-// Return the value of the given var, if it's defined.
-as_value
-as_environment::get_variable(const tu_string& varname, const
std::vector<with_stack_entry>& with_stack) const
-{
- // Path lookup rigamarole.
- movie* target = m_target;
- tu_string path;
- tu_string var;
- if (parse_path(varname, &path, &var)) {
- target = find_target(path); // @@ Use with_stack here too??? Need
to test.
- if (target) {
- as_value val;
- target->get_member(var, &val);
- return val;
- } else {
- log_error("find_target(\"%s\") failed\n", path.c_str());
- return as_value();
- }
- } else {
- return this->get_variable_raw(varname, with_stack);
- }
-}
-
-
-as_value
-as_environment::get_variable_raw(
- const tu_string& varname,
- const std::vector<with_stack_entry>& with_stack) const
- // 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 (int i = with_stack.size() - 1; i >= 0; i--) {
- as_object* obj = with_stack[i].m_object.get_ptr();
- if (obj && obj->get_member(varname, &val)) {
- // Found the var in this context.
- return val;
- }
- }
-
- // Check locals.
- int local_index = find_local(varname);
- if (local_index >= 0) {
- // Get local var.
- return m_local_frames[local_index].m_value;
- }
-
- // Looking for "this"?
- if (varname == "this") {
- val.set_as_object(m_target);
- return val;
- }
-
- // Check movie members.
- if (m_target->get_member(varname, &val)) {
- return val;
- }
-
- // Check built-in constants.
- if (varname == "_root" || varname == "_level0") {
- return as_value(m_target->get_root_movie());
- }
- if (varname == "_global") {
- return as_value(s_global.get_ptr());
- }
- if (s_global->get_member(varname, &val)) {
- return val;
- }
-
- // Fallback.
- IF_VERBOSE_ACTION(dbglogfile << "get_variable_raw(\"" << varname.c_str()
- << "\" failed, returning UNDEFINED." << endl);
- return as_value();
-}
-
-// Given a path to variable, set its value.
-void
-as_environment::set_variable(
- const tu_string& varname,
- const as_value& val,
- const std::vector<with_stack_entry>& with_stack)
-{
- IF_VERBOSE_ACTION(dbglogfile << "-------------- "
- << varname.c_str() << " = " << val.to_string());
-
- // Path lookup rigamarole.
- movie* target = m_target;
- tu_string path;
- tu_string var;
- if (parse_path(varname, &path, &var)) {
- target = find_target(path);
- if (target) {
- target->set_member(var, val);
- }
- } else {
- this->set_variable_raw(varname, val, with_stack);
- }
-}
-
-// No path rigamarole.
-void
-as_environment::set_variable_raw(
- const tu_string& varname,
- const as_value& val,
- const std::vector<with_stack_entry>& with_stack)
-{
- // Check the with-stack.
- for (int i = with_stack.size() - 1; i >= 0; i--) {
- as_object* obj = with_stack[i].m_object.get_ptr();
- as_value dummy;
- if (obj && obj->get_member(varname, &dummy)) {
- // This object has the member; so set it here.
- obj->set_member(varname, val);
- return;
- }
- }
-
- // Check locals.
- int local_index = find_local(varname);
- if (local_index >= 0) {
- // Set local var.
- m_local_frames[local_index].m_value = val;
- return;
- }
-
- assert(m_target);
-
- m_target->set_member(varname, val);
-}
-
-// Set/initialize the value of the local variable.
-void
-as_environment::set_local(const tu_string& varname, const as_value& val)
-{
- // Is it in the current frame already?
- int index = find_local(varname);
- if (index < 0) {
- // 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;
- }
-}
-
-// Add a local var with the given name and value to our
-// current local frame. Use this when you know the var
-// doesn't exist yet, since it's faster than set_local();
-// e.g. when setting up args for a function.
-void
-as_environment::add_local(const tu_string& varname, const as_value& val)
-{
- assert(varname.length() > 0);
- m_local_frames.push_back(frame_slot(varname, val));
-}
-
-// Create the specified local var if it doesn't exist already.
-void
-as_environment::declare_local(const tu_string& varname)
-{
- // Is it in the current frame already?
- int index = find_local(varname);
- if (index < 0) {
- // 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()));
- } else {
- // In frame already; don't mess with it.
- }
-}
-
-bool
-as_environment::get_member(const tu_stringi& varname, as_value* val) const
-{
- return m_variables.get(varname, val);
-}
-
-
-void
-as_environment::set_member(const tu_stringi& varname, const as_value& val)
-{
- m_variables[varname] = val;
-}
-
-// Return a pointer to the specified local register.
-// Local registers are numbered starting with 1.
-//
-// Return value will never be NULL. If reg is out of bounds,
-// we log an error, but still return a valid pointer (to
-// global reg[0]). So the behavior is a bit undefined, but
-// not dangerous.
-as_value*
-as_environment::local_register_ptr(int reg)
-{
- // We index the registers from the end of the register
- // array, so we don't have to keep base/frame
- // pointers.
-
- if (reg <= 0 || reg > (int) m_local_register.size()) {
- log_error("Invalid local register %d, stack only has %zd entries\n",
- reg, m_local_register.size());
-
- // Fallback: use global 0.
- return &m_global_register[0];
- }
-
- return &m_local_register[m_local_register.size() - reg];
-}
-
-// 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 tu_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;
-}
-
-// See if the given variable name is actually a sprite path
-// followed by a variable name. These come in the format:
-//
-// /path/to/some/sprite/:varname
-//
-// (or same thing, without the last '/')
-//
-// or
-// path.to.some.var
-//
-// If that's the format, puts the path part (no colon or
-// trailing slash) in *path, and the varname part (no color)
-// in *var and returns true.
-//
-// If no colon, returns false and leaves *path & *var alone.
-bool
-as_environment::parse_path(const tu_string& var_path, tu_string* path,
tu_string* var) const
-{
- // Search for colon.
- int colon_index = 0;
- int var_path_length = var_path.length();
- for ( ; colon_index < var_path_length; colon_index++) {
- if (var_path[colon_index] == ':') {
- // Found it.
- break;
- }
- }
-
- if (colon_index >= var_path_length) {
- // No colon. Is there a '.'? Find the last
- // one, if any.
- for (colon_index = var_path_length - 1; colon_index >= 0;
colon_index--) {
- if (var_path[colon_index] == '.') {
- // Found it.
- break;
- }
- }
- if (colon_index < 0) {
- return false;
- }
- }
-
- // Make the subparts.
-
- // Var.
- *var = &var_path[colon_index + 1];
-
- // Path.
- if (colon_index > 0) {
- if (var_path[colon_index - 1] == '/') {
- // Trim off the extraneous trailing slash.
- colon_index--;
- }
- }
- // @@ could be better. This whole usage of tu_string is very flabby...
- *path = var_path;
- path->resize(colon_index);
-
- return true;
-}
-
-// Find the sprite/movie represented by the given value. The
-// value might be a reference to the object itself, or a
-// string giving a relative path name to the object.
-movie*
-as_environment::find_target(const as_value& val) const
-{
- if (val.get_type() == as_value::OBJECT) {
- if (val.to_object() != NULL) {
- return val.to_object()->to_movie();
- } else {
- return NULL;
- }
- } else if (val.get_type() == as_value::STRING) {
- return find_target(val.to_tu_string());
- } else {
- log_error("error: invalid path; neither string nor object");
- return NULL;
- }
-}
-
-// Search for next '.' or '/' character in this word. Return
-// a pointer to it, or to NULL if it wasn't found.
-static const char*
-next_slash_or_dot(const char* word)
-{
- for (const char* p = word; *p; p++) {
- if (*p == '.' && p[1] == '.') {
- p++;
- } else if (*p == '.' || *p == '/') {
- return p;
- }
- }
-
- return NULL;
-}
-
-// Find the sprite/movie referenced by the given path.
-movie*
-as_environment::find_target(const tu_string& path) const
-{
- if (path.length() <= 0) {
- return m_target;
- }
-
- assert(path.length() > 0);
-
- movie* env = m_target;
- assert(env);
-
- const char* p = path.c_str();
- tu_string subpart;
-
- if (*p == '/') {
- // Absolute path. Start at the root.
- env = env->get_relative_target("_level0");
- p++;
- }
-
- if (*p == '\0') {
- return env;
- }
-
- for (;;) {
- const char* next_slash = next_slash_or_dot(p);
- subpart = p;
- if (next_slash == p) {
- log_error("error: invalid path '%s'\n", path.c_str());
- break;
- } else if (next_slash) {
- // Cut off the slash and everything after it.
- subpart.resize(next_slash - p);
- }
-
- env = env->get_relative_target(subpart);
- //@@ _level0 --> root, .. --> parent, . --> this, other == character
-
- if (env == NULL || next_slash == NULL) {
- break;
- }
-
- p = next_slash + 1;
- }
- return env;
-}
-
-
-//
// event_id
//
Index: gnash/server/action.h
diff -u gnash/server/action.h:1.29 gnash/server/action.h:1.30
--- gnash/server/action.h:1.29 Mon May 8 11:43:58 2006
+++ gnash/server/action.h Fri May 19 18:09:03 2006
@@ -56,10 +56,11 @@
#include "smart_ptr.h"
//#include "Function.h"
#include "log.h"
+#include "as_environment.h" // for fn_call inlines
namespace gnash {
struct movie;
- struct as_environment;
+ //struct as_environment;
class as_object;
struct as_value;
struct function_as_object;
@@ -299,150 +300,6 @@
#endif // 0
-
- /// ActionScript "environment", essentially VM state?
- struct as_environment
- {
- /// Stack of as_values in this environment
- std::vector<as_value> m_stack;
-
- as_value m_global_register[4];
-
- /// function2 uses this
- std::vector<as_value> m_local_register;
-
- /// Movie target.
- movie* m_target;
-
- /// Variables available in this environment
- stringi_hash<as_value> m_variables;
-
- /// For local vars. Use empty names to separate frames.
- struct frame_slot
- {
- tu_string m_name;
- as_value m_value;
-
- frame_slot() {}
- frame_slot(const tu_string& name, const as_value& val)
: m_name(name), m_value(val) {}
- };
- std::vector<frame_slot> m_local_frames;
-
-
- as_environment()
- :
- m_target(0)
- {
- }
-
- movie* get_target() { return m_target; }
- void set_target(movie* target) { m_target = target; }
-
- // stack access/manipulation
- // @@ TODO do more checking on these
- template<class T>
- // stack access/manipulation
- void push(T val) { push_val(as_value(val)); }
- void push_val(const as_value& val) { m_stack.push_back(val);
}
-
-
- /// Pops an as_value off the stack top and return it.
- as_value pop() { as_value result = m_stack.back();
m_stack.pop_back(); return result; }
-
- /// Get stack value at the given distance from top.
- //
- /// top(0) is actual stack top
- ///
- as_value& top(int dist) { return m_stack[m_stack.size() -
1 - dist]; }
-
- /// Get stack value at the given distance from bottom.
- //
- /// bottom(0) is actual stack top
- ///
- as_value& bottom(int index) { return m_stack[index]; }
-
- /// Drop 'count' values off the top of the stack.
- void drop(int count) { m_stack.resize(m_stack.size() -
count); }
-
- /// Returns index of top stack element
- int get_top_index() const { return m_stack.size() - 1; }
-
- /// \brief
- /// Return the (possibly UNDEFINED) value of the named var.
- /// Variable name can contain path elements.
- ///
- as_value get_variable(const tu_string& varname,
- const std::vector<with_stack_entry>& with_stack) const;
-
- /// Same of the above, but no support for path.
- as_value get_variable_raw(const tu_string& varname,
- const std::vector<with_stack_entry>& with_stack) const;
-
- /// Given a path to variable, set its value.
- void set_variable(const tu_string& path, const as_value&
val, const std::vector<with_stack_entry>& with_stack);
-
- /// Same of the above, but no support for path
- void set_variable_raw(const tu_string& path, const as_value&
val, const std::vector<with_stack_entry>& with_stack);
-
- /// Set/initialize the value of the local variable.
- void set_local(const tu_string& varname, const as_value&
val);
- /// \brief
- /// Add a local var with the given name and value to our
- /// current local frame.
- ///
- /// Use this when you know the var
- /// doesn't exist yet, since it's faster than set_local();
- /// e.g. when setting up args for a function.
- void add_local(const tu_string& varname, const as_value&
val);
-
- /// Create the specified local var if it doesn't exist already.
- void declare_local(const tu_string& varname);
-
- /// Retrieve the named member (variable).
- //
- /// If no member is found under the given name
- /// 'val' is untouched and 'false' is returned.
- ///
- bool get_member(const tu_stringi& varname, as_value* val)
const;
- void set_member(const tu_stringi& varname, const as_value&
val);
-
- // Parameter/local stack frame management.
- int get_local_frame_top() const { return
m_local_frames.size(); }
- void set_local_frame_top(unsigned int t) {
- assert(t <= m_local_frames.size());
- m_local_frames.resize(t);
- }
- void add_frame_barrier() {
m_local_frames.push_back(frame_slot()); }
-
- // Local registers.
- void add_local_registers(int register_count)
- {
- m_local_register.resize(m_local_register.size() +
register_count);
- }
- void drop_local_registers(int register_count)
- {
- m_local_register.resize(m_local_register.size() -
register_count);
- }
- as_value* local_register_ptr(int reg);
-
- // Internal.
- int find_local(const tu_string& varname) const;
- bool parse_path(const tu_string& var_path, tu_string* path,
tu_string* var) const;
- movie* find_target(const tu_string& path) const;
- movie* find_target(const as_value& val) const;
-
- /// Dump content of the stack using the log_msg function
- void dump_stack()
- {
- for (int i=0, n=m_stack.size(); i<n; i++)
- {
- log_msg("Stack[%d]: %s\n",
- i, m_stack[i].to_string());
- }
- }
- };
-
-
/// Parameters/environment for C functions callable from ActionScript.
struct fn_call
{
Index: gnash/server/movie.h
diff -u gnash/server/movie.h:1.5 gnash/server/movie.h:1.6
--- gnash/server/movie.h:1.5 Mon May 8 21:12:24 2006
+++ gnash/server/movie.h Fri May 19 18:09:03 2006
@@ -51,6 +51,7 @@
#include "utility.h"
#include "smart_ptr.h"
#include "movie_interface.h" // for inheritance
+#include "action.h" // for event_id definitions
#include <cstdarg>
#include <cassert>