[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] /srv/bzr/gnash/trunk r12324: Updates to old function docu
From: |
Benjamin Wolsey |
Subject: |
[Gnash-commit] /srv/bzr/gnash/trunk r12324: Updates to old function documentation, various cleanups and rearranging |
Date: |
Thu, 22 Jul 2010 08:08:13 +0200 |
User-agent: |
Bazaar (2.0.3) |
------------------------------------------------------------
revno: 12324 [merge]
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Thu 2010-07-22 08:08:13 +0200
message:
Updates to old function documentation, various cleanups and rearranging
to make the code easy to refactor.
removed:
libcore/vm/with_stack_entry.h
modified:
libcore/TextField.cpp
libcore/as_environment.cpp
libcore/as_environment.h
libcore/vm/ASHandlers.cpp
libcore/vm/ActionExec.cpp
libcore/vm/ActionExec.h
libcore/vm/Makefile.am
=== modified file 'libcore/TextField.cpp'
--- a/libcore/TextField.cpp 2010-07-12 07:06:03 +0000
+++ b/libcore/TextField.cpp 2010-07-21 08:35:58 +0000
@@ -1970,7 +1970,7 @@
// name. We copy the string so we can assign to it if necessary.
std::string parsedName = variableName;
std::string path, var;
- if (as_environment::parse_path(variableName, path, var))
+ if (parsePath(variableName, path, var))
{
#ifdef DEBUG_DYNTEXT_VARIABLES
log_debug(_("Variable text Path: %s, Var: %s"), path, var);
=== modified file 'libcore/as_environment.cpp'
--- a/libcore/as_environment.cpp 2010-01-11 06:41:38 +0000
+++ b/libcore/as_environment.cpp 2010-07-21 10:30:55 +0000
@@ -132,7 +132,7 @@
std::string path;
std::string var;
- if (parse_path(varname, path, var))
+ if (parsePath(varname, path, var))
{
// TODO: let find_target return generic as_objects, or use 'with'
stack,
// see player2.swf or bug #18758 (strip.swf)
@@ -368,7 +368,7 @@
std::string var;
//log_debug(_("set_variable(%s, %s)"), varname, val);
- if (parse_path(varname, path, var)) {
+ if (parsePath(varname, path, var)) {
target = find_object(path, &scopeStack);
if (target)
{
@@ -472,59 +472,13 @@
}
}
-/* public static */
-bool
-as_environment::parse_path(const std::string& var_path_in, std::string& path,
- std::string& var)
-{
-#ifdef DEBUG_TARGET_FINDING
- log_debug("parse_path(%s)", var_path_in);
-#endif
-
- size_t lastDotOrColon = var_path_in.find_last_of(":.");
- if (lastDotOrColon == std::string::npos) return false;
-
- std::string thePath, theVar;
-
- thePath.assign(var_path_in, 0, lastDotOrColon);
- theVar.assign(var_path_in, lastDotOrColon+1, var_path_in.length());
-
-#ifdef DEBUG_TARGET_FINDING
- log_debug("path: %s, var: %s", thePath, theVar);
-#endif
-
- if (thePath.empty()) return false;
-
- // this check should be performed by callers (getvariable/setvariable
- // in particular)
- size_t pathlen = thePath.length();
- size_t i = pathlen - 1;
- size_t consecutiveColons = 0;
- while (i && thePath[i--] == ':')
- {
- if (++consecutiveColons > 1)
- {
-#ifdef DEBUG_TARGET_FINDING
- log_debug("path '%s' ends with too many colon chars, not "
- "considering a path", thePath);
-#endif
- return false;
- }
- }
-
- path = thePath;
- var = theVar;
-
- return true;
-}
-
bool
as_environment::parse_path(const std::string& var_path, as_object** target,
as_value& val)
{
std::string path;
std::string var;
- if (!parse_path(var_path, path, var)) return false;
+ if (!parsePath(var_path, path, var)) return false;
as_object* target_ptr = find_object(path);
if ( ! target_ptr ) return false;
@@ -540,8 +494,9 @@
{
for (const char* p = word; *p; p++) {
if (*p == '.' && p[1] == '.') {
- p++;
- } else if (*p == '.' || *p == '/' || *p == ':') {
+ ++p;
+ }
+ else if (*p == '.' || *p == '/' || *p == ':') {
return p;
}
}
@@ -566,103 +521,86 @@
as_environment::find_object(const std::string& path,
const ScopeStack* scopeStack) const
{
-#ifdef DEBUG_TARGET_FINDING
- log_debug(_("find_object(%s) called"), path);
-#endif
if (path.empty()) {
-#ifdef DEBUG_TARGET_FINDING
- log_debug(_("Returning m_target (empty path)"));
-#endif
- return getObject(m_target); // or should we return the *original* path
?
+ return getObject(m_target);
}
VM& vm = _vm;
string_table& st = vm.getStringTable();
- int swfVersion = vm.getSWFVersion();
-
- as_object* env = 0;
- env = getObject(m_target);
+ const int swfVersion = vm.getSWFVersion();
bool firstElementParsed = false;
bool dot_allowed = true;
+ // This points to the current object being used for lookup.
+ as_object* env;
const char* p = path.c_str();
- if (*p == '/')
- {
- // Absolute path. Start at the (AS) root (handle _lockroot)
+
+ // Check if it's an absolute path
+ if (*p == '/') {
+
MovieClip* root = 0;
if (m_target) root = m_target->getAsRoot();
else {
if (_original_target) {
- log_debug("current target is undefined on "
- "as_environment::find_object, we'll use original");
root = _original_target->getAsRoot();
}
- else {
- log_debug("both current and original target are undefined "
- "on as_environment::find_object, we'll return 0");
- return 0;
- }
- }
-
- if (!*(++p)) {
-#ifdef DEBUG_TARGET_FINDING
- log_debug(_("Path is '/', return the root (%p)"), (void*)root);
-#endif
- return getObject(root); // that's all folks..
- }
-
+ return 0;
+ }
+
+ // If the path is just "/" return the root.
+ if (!*(++p)) return getObject(root);
+
+ // Otherwise we start at the root for lookup.
env = getObject(root);
firstElementParsed = true;
dot_allowed = false;
-#ifdef DEBUG_TARGET_FINDING
- log_debug(_("Absolute path, start at the root (%p)"), (void*)env);
-#endif
-
}
-#ifdef DEBUG_TARGET_FINDING
else {
- log_debug(_("Relative path, start at (%s)"), m_target->getTarget());
+ env = getObject(m_target);
}
-#endif
assert (*p);
std::string subpart;
- while (1)
- {
+ while (1) {
+
+ // Skip past all colons (why?)
while (*p == ':') ++p;
- // No more components to scan
if (!*p) {
-#ifdef DEBUG_TARGET_FINDING
- log_debug(_("Path is %s, returning whatever we were up to"), path);
-#endif
+ // No more components to scan, so return the currently found
+ // object.
return env;
}
-
+ // Search for the next '/', ':' or '.'.
const char* next_slash = next_slash_or_dot(p);
subpart = p;
+
+ // Check whether p was pointing to one of those characters already.
if (next_slash == p) {
IF_VERBOSE_ASCODING_ERRORS(
log_aserror(_("invalid path '%s' (p=next_slash=%s)"),
path, next_slash);
);
- return NULL;
+ return 0;
}
- else if (next_slash) {
- if (*next_slash == '.')
- {
+
+ if (next_slash) {
+ if (*next_slash == '.') {
+
if (!dot_allowed) {
IF_VERBOSE_ASCODING_ERRORS(
- log_aserror(_("invalid path '%s' (dot not allowed "
- "after having seen a slash)"), path);
+ log_aserror(_("invalid path '%s' (dot not allowed "
+ "after having seen a slash)"), path);
);
- return NULL;
+ return 0;
}
+ // No dot allowed after a double-dot.
+ if (next_slash[1] == '.') dot_allowed = false;
}
else if (*next_slash == '/') {
dot_allowed = false;
@@ -675,14 +613,9 @@
assert(subpart[0] != ':');
// No more components to scan
- if (subpart.empty()) {
-#ifdef DEBUG_TARGET_FINDING
- log_debug(_("No more subparts, env is %p"), (void*)env);
-#endif
- break;
- }
+ if (subpart.empty()) break;
- string_table::key subpartKey = st.find(subpart);
+ const string_table::key subpartKey = st.find(subpart);
if (!firstElementParsed) {
as_object* element(0);
@@ -690,8 +623,7 @@
do {
// Try scope stack
if (scopeStack) {
- for (size_t i = scopeStack->size(); i > 0; --i)
- {
+ for (size_t i = scopeStack->size(); i > 0; --i) {
as_object* obj = (*scopeStack)[i-1];
element = getElement(obj, subpartKey);
@@ -709,12 +641,15 @@
// Looking for _global ?
as_object* global = _vm.getGlobal();
- if (swfVersion > 5 && subpartKey == NSV::PROP_uGLOBAL)
- {
+ const bool nocase = caseless(*global);
+
+ if (swfVersion > 5 &&
+ equal(st, subpartKey, NSV::PROP_uGLOBAL, nocase)) {
element = global;
break;
}
- // Try globals
+
+ // Look for globals.
element = getElement(global, subpartKey);
} while (0);
@@ -991,6 +926,31 @@
}
#endif // GNASH_USE_GC
+bool
+parsePath(const std::string& var_path_in, std::string& path, std::string& var)
+{
+
+ const size_t lastDotOrColon = var_path_in.find_last_of(":.");
+ if (lastDotOrColon == std::string::npos) return false;
+
+ const std::string p(var_path_in, 0, lastDotOrColon);
+ const std::string v(var_path_in, lastDotOrColon + 1, var_path_in.size());
+
+#ifdef DEBUG_TARGET_FINDING
+ log_debug("path: %s, var: %s", p, v);
+#endif
+
+ if (p.empty()) return false;
+
+ // The path may apparently not end with more than one colon.
+ if (p.size() > 1 && !p.compare(p.size() - 2, 2, "::")) return false;
+
+ path = p;
+ var = v;
+
+ return true;
+}
+
string_table&
getStringTable(const as_environment& env)
{
=== modified file 'libcore/as_environment.h'
--- a/libcore/as_environment.h 2010-03-13 20:19:03 +0000
+++ b/libcore/as_environment.h 2010-07-21 08:35:58 +0000
@@ -348,28 +348,6 @@
///
int get_version() const;
- /// 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 colon, no dot)
- /// in *var and returns true.
- ///
- /// If no colon or dot, returns false and leaves *path & *var alone.
- ///
- /// TODO: return an integer: 0 not a path, 1 a slash-based path, 2 a
- /// dot-based path
- ///
- static bool parse_path(const std::string& var_path, std::string& path,
- std::string& var);
-
/// \brief
/// Try to parse a string as a variable path
//
@@ -535,6 +513,28 @@
};
+/// 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 colon, no dot)
+/// in *var and returns true.
+///
+/// If no colon or dot, returns false and leaves *path & *var alone.
+///
+/// TODO: return an integer: 0 not a path, 1 a slash-based path, 2 a
+/// dot-based path
+///
+bool parsePath(const std::string& var_path, std::string& path,
+ std::string& var);
+
inline VM&
getVM(const as_environment& env)
{
=== modified file 'libcore/vm/ASHandlers.cpp'
--- a/libcore/vm/ASHandlers.cpp 2010-07-07 09:19:47 +0000
+++ b/libcore/vm/ASHandlers.cpp 2010-07-21 08:35:58 +0000
@@ -52,7 +52,6 @@
#include "as_environment.h"
#include "as_value.h"
#include "RunResources.h"
-#include "with_stack_entry.h"
#include "ObjectURI.h"
#include <string>
@@ -2217,7 +2216,7 @@
std::string frame_var;
DisplayObject* target = 0;
- if (env.parse_path(target_frame, target_path, frame_var)) {
+ if (parsePath(target_frame, target_path, frame_var)) {
target = env.find_target(target_path);
}
else {
@@ -2270,7 +2269,7 @@
std::string frame_var;
DisplayObject* target = NULL;
- if (env.parse_path(target_frame, target_path, frame_var)) {
+ if (parsePath(target_frame, target_path, frame_var)) {
target = env.find_target(target_path);
}
@@ -2352,7 +2351,7 @@
}
std::string path, var;
- if (!as_environment::parse_path(propertyname, path, var))
+ if (!parsePath(propertyname, path, var))
{
// It's not a path. For SWF 7 and above, don't delete. Otherwise
// assume it's a variable and try to delete.
@@ -2409,7 +2408,7 @@
// If it's not a path, delete it as a variable.
std::string path, var;
- if (!as_environment::parse_path(propertyname, path, var)) {
+ if (!parsePath(propertyname, path, var)) {
// See bug #18482, this works fine now (assuming the bug
// report is correct)
env.top(0) = thread.delVariable(propertyname);
@@ -3654,7 +3653,7 @@
// where does the 'with' block end?
const size_t block_end = thread.getNextPC() + block_length;
- if (!thread.pushWithEntry(with_stack_entry(with_obj, block_end)))
+ if (!thread.pushWith(With(with_obj, block_end)))
{
// skip the full block
thread.adjustNextPC(block_length);
=== modified file 'libcore/vm/ActionExec.cpp'
--- a/libcore/vm/ActionExec.cpp 2010-07-10 14:03:14 +0000
+++ b/libcore/vm/ActionExec.cpp 2010-07-21 08:35:58 +0000
@@ -36,7 +36,6 @@
#include "as_environment.h"
#include "debugger.h"
#include "SystemClock.h"
-#include "with_stack_entry.h"
#include <sstream>
#include <string>
@@ -647,7 +646,7 @@
}
bool
-ActionExec::pushWithEntry(const with_stack_entry& entry)
+ActionExec::pushWith(const With& entry)
{
// See comment in header about _withStackLimit
if (_withStack.size() >= _withStackLimit)
@@ -716,12 +715,10 @@
as_object*
ActionExec::getTarget()
{
- if (!_withStack.empty()) {
- return _withStack.back().object();
- }
- else {
+ if (_withStack.empty()) {
return getObject(env.get_target());
}
+ return _withStack.back().object();
}
void
=== modified file 'libcore/vm/ActionExec.h'
--- a/libcore/vm/ActionExec.h 2010-07-07 09:19:47 +0000
+++ b/libcore/vm/ActionExec.h 2010-07-21 08:35:58 +0000
@@ -19,14 +19,14 @@
#ifndef GNASH_ACTIONEXEC_H
#define GNASH_ACTIONEXEC_H
-#include "with_stack_entry.h"
-#include "as_environment.h" // for ScopeStack
-#include "SWF.h"
-#include "action_buffer.h"
-
#include <string>
#include <list>
#include <vector>
+#include <boost/noncopyable.hpp>
+
+#include "as_environment.h"
+#include "SWF.h"
+#include "action_buffer.h"
// Forward declarations
namespace gnash {
@@ -88,8 +88,33 @@
as_value _lastThrow;
};
+class With
+{
+public:
+
+ With(as_object* obj, size_t end)
+ :
+ _object(obj),
+ _block_end_pc(end)
+ {
+ }
+
+ size_t end_pc() const {
+ return _block_end_pc;
+ }
+
+ as_object* object() const {
+ return _object;
+ }
+
+private:
+ as_object* _object;
+ size_t _block_end_pc;
+};
+
/// Executor of an action_buffer
-class ActionExec {
+class ActionExec : boost::noncopyable
+{
private:
@@ -142,7 +167,7 @@
void cleanupAfterRun();
/// the 'with' stack associated with this execution thread
- std::vector<with_stack_entry> _withStack;
+ std::vector<With> _withStack;
typedef as_environment::ScopeStack ScopeStack;
@@ -260,47 +285,20 @@
/// Is this execution thread a function call ?
bool isFunction() const { return _func != 0; }
- /// Get a pointer of the function being executed (if any)
- const swf_function* getThisFunction() const { return _func; }
-
/// Get the current 'this' pointer, for use in function calls
as_object* getThisPointer();
/// Returns the scope stack associated with this execution thread
- //
- /// TODO: return by const ref instead
- ///
const ScopeStack& getScopeStack() const
{
return _scopeStack;
}
- /// Return the maximum allowed 'with' stack limit.
- //
- /// See http://sswf.sourceforge.net/SWFalexref.html#action_with
- /// for more info.
- ///
- /// Note that Gnash have NO limit on the number of 'with'
- /// stack entries, this information will only be used to
- /// generate useful warnings for coders (if ActionScript errors
- /// verbosity is enabled).
- ///
- size_t getWithStackLimit() const
- {
- return _withStackLimit;
- }
-
/// Push an entry to the with stack
//
- /// @return
- /// true if the entry was pushed, false otherwise.
- /// Note that false will *never* be returned as Gnash
- /// removed the 'with' stack limit. If the documented
- /// limit for stack (SWF# bound) is reached, and ActionScript
- /// errors verbosity is enabled, a warning will be raised,
- /// but the call will still succeed.
- ///
- bool pushWithEntry(const with_stack_entry& entry);
+ /// @return true if the entry was pushed, false otherwise. This
+ /// depends on the with stack limit.
+ bool pushWith(const With& entry);
/// Skip the specified number of action tags
//
@@ -379,13 +377,10 @@
/// A better, cleaner and less error-prone approach
/// would be providing a callFunction() method in
/// ActionExec. This will likely help debugger too
- ///
- ///
as_object* getTarget();
/// Execute.
- void operator() ();
-
+ void operator()();
// TODO: cut down these accessors.
bool atActionTag(SWF::ActionType t) { return code[pc] == t; }
=== modified file 'libcore/vm/Makefile.am'
--- a/libcore/vm/Makefile.am 2010-03-24 23:11:52 +0000
+++ b/libcore/vm/Makefile.am 2010-07-21 07:23:20 +0000
@@ -57,7 +57,6 @@
CodeStream.h \
ActionExec.h \
ExecutableCode.h \
- with_stack_entry.h \
$(NULL)
EXTENSIONS_API = \
=== removed file 'libcore/vm/with_stack_entry.h'
--- a/libcore/vm/with_stack_entry.h 2010-07-10 14:03:14 +0000
+++ b/libcore/vm/with_stack_entry.h 1970-01-01 00:00:00 +0000
@@ -1,73 +0,0 @@
-//
-// Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
-// Foundation, Inc
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-#ifndef GNASH_WITH_STACK_ENTRY_H
-#define GNASH_WITH_STACK_ENTRY_H
-
-#include <cstddef> // for size_t
-
-namespace gnash {
- class as_object;
-}
-
-namespace gnash {
-
-//
-// with_stack_entry
-//
-
-/// The "with" stack is for Pascal-like with-scoping.
-class with_stack_entry
-{
-public:
-
- with_stack_entry(as_object* obj, size_t end)
- :
- _object(obj),
- _block_end_pc(end)
- {
- }
-
- size_t end_pc() const
- {
- return _block_end_pc;
- }
-
- as_object* object() const
- {
- return _object;
- }
-
-private:
-
- as_object* _object;
-
- size_t _block_end_pc;
-
-};
-
-} // end namespace gnash
-
-
-#endif // GNASH_WITH_STACK_ENTRY_H
-
-
-// Local Variables:
-// mode: C++
-// indent-tabs-mode: t
-// End:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] /srv/bzr/gnash/trunk r12324: Updates to old function documentation, various cleanups and rearranging,
Benjamin Wolsey <=