/usr/include/gnash/vm/ActionExec.h is in gnash-dev 0.8.11~git20160109-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | //
// Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
// 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_ACTIONEXEC_H
#define GNASH_ACTIONEXEC_H
#include <string>
#include <stack>
#include <vector>
#include <boost/noncopyable.hpp>
#include "as_environment.h"
#include "SWF.h"
#include "action_buffer.h"
// Forward declarations
namespace gnash {
class as_value;
class Function;
class ActionExec;
}
namespace gnash {
class TryBlock
{
public:
friend class ActionExec;
enum tryState
{
TRY_TRY, // In a try block.
TRY_CATCH, // In a catch block.
TRY_FINALLY, // In a finally block.
TRY_END // Finished with finally
};
TryBlock(size_t cur_off, size_t try_size, size_t catch_size,
size_t finally_size, std::string catchName)
:
_catchOffset(cur_off + try_size),
_finallyOffset(cur_off + try_size + catch_size),
_afterTriedOffset(cur_off + try_size + catch_size + finally_size),
_savedEndOffset(0),
_hasName(true),
_name(std::move(catchName)),
_registerIndex(0),
_tryState(TryBlock::TRY_TRY),
_lastThrow()
{}
TryBlock(size_t cur_off, size_t try_size, size_t catch_size,
size_t finally_size, std::uint8_t register_index)
:
_catchOffset(cur_off + try_size),
_finallyOffset(cur_off + try_size + catch_size),
_afterTriedOffset(cur_off + try_size + catch_size + finally_size),
_savedEndOffset(0),
_hasName(false),
_name(),
_registerIndex(register_index),
_tryState(TryBlock::TRY_TRY),
_lastThrow()
{}
private:
size_t _catchOffset;
size_t _finallyOffset;
size_t _afterTriedOffset;
size_t _savedEndOffset;
bool _hasName;
std::string _name;
unsigned int _registerIndex;
tryState _tryState;
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 : boost::noncopyable
{
typedef as_environment::ScopeStack ScopeStack;
public:
/// Create an execution thread
//
/// @param abuf the action code
/// @param newEnv the timeline context.
/// @param abortOnUnloaded If true (default) execution aborts as soon
/// as the target sprite is unloaded.
/// NOTE: original target is fetched from the environment.
ActionExec(const action_buffer& abuf, as_environment& newEnv,
bool abortOnUnloaded = true);
/// Create an execution thread for a function call.
//
/// @param func The function
/// @param newEnv The execution environment (variables scope, stack etc.)
/// @param nRetval Where to return a value. If NULL any return will
/// be discarded.
ActionExec(const Function& func, as_environment& newEnv,
as_value* nRetVal, as_object* this_ptr);
/// Use this to push a try block. It will be copied
void pushTryBlock(TryBlock t);
/// Set the return value.
void pushReturn(const as_value& t);
/// The actual action buffer
//
/// TODO: provide a getter and make private
const action_buffer& code;
/// TODO: provide a getter and make private ?
as_environment& env;
/// TODO: provide a setter and make private ?
as_value* retval;
/// Is this execution thread a function call ?
bool isFunction() const { return _func != nullptr; }
/// Get the current 'this' pointer, for use in function calls
as_object* getThisPointer();
/// Returns the scope stack associated with this execution thread
const ScopeStack& getScopeStack() const {
return _scopeStack;
}
/// Push an entry to the with stack
//
/// @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
//
/// The offset is relative to next_pc
void skip_actions(size_t offset);
/// Delete named variable, seeking for it in the with stack if any
//
/// @param name Name of the variable. Supports slash and dot syntax.
bool delVariable(const std::string& name);
/// Set a named variable, seeking for it in the with stack if any.
//
/// @param name Name of the variable. Supports slash and dot syntax.
void setVariable(const std::string& name, const as_value& val);
/// Set a function-local variable
//
/// If we're not in a function, set a normal variable.
//
/// @param name Name of the variable. Supports slash and dot syntax.
/// @param val The value to set the variable to.
void setLocalVariable(const std::string& name, const as_value& val);
/// Get a named variable, seeking for it in the with stack if any.
//
/// @param name Name of the variable. Supports slash and dot syntax.
/// @param target An output parameter, will be set to point to the object
/// containing any found variable. If you aren't interested,
/// pass null (default). If the variable does not belong
/// to an object, target will be set to null.
as_value getVariable(const std::string& name, as_object** target = nullptr);
/// Get current target.
//
/// This function returns top 'with' stack entry, if any.
/// Main use for this function is for calling methods and
/// properly setting the "this" pointer.
///
/// TODO:
/// 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()();
// TODO: cut down these accessors.
bool atActionTag(SWF::ActionType t) { return code[pc] == t; }
size_t getCurrentPC() const { return pc; }
void skipRemainingBuffer() { next_pc = stop_pc; }
void adjustNextPC(int offset);
size_t getNextPC() const { return next_pc; }
void setNextPC(size_t pc) { next_pc = pc; }
size_t getStopPC() const { return stop_pc; }
private:
/// \brief
/// Debugging function:
/// print opcodes from start (included) to end (not-included) PCs.
//
/// @param start
/// First opcode to dump
///
/// @param end
/// One-past last opcode to dump
///
/// @param os
/// Output stream to dump to
///
void dumpActions(size_t start, size_t end, std::ostream& os);
/// Processes the current try - catch - finally block
//
/// This function is called after each stage of a
/// try/catch/finally block. It ensures it is called
/// after each stage by setting stop_pc to the appropriate
/// number. If an exception is on the stack at any stage,
/// it takes the appropriate action (catch, set register
/// values, return, or leave it on the stack). Return
/// false means that the action processing loop should be
/// interrupted.
//
/// @return whether to continue executing the buffer
/// @param t the try block to process.
bool processExceptions(TryBlock& t);
/// Run after a complete run, or after an run interrupted by
/// a bail-out exception (ActionLimitException, for example)
//
/// The method restores original target of the as_environment,
/// checks for stack smashing (stack contains less entries
/// then it had at time of execution start) or leftovers
/// (stack contains more entries then it had at time of execution
/// start) and finally gives movie_root a chance to execute
/// actions queued in higher priority action queues.
///
/// The higher priority action queue flush is needed to allow
/// initialize/construct/initactions queued by effect of gotoFrame
/// calls in DOACTION block before frame actions queued by the same
/// cause (the latter would be pushed in the same level gotoFrame is
/// found)
void cleanupAfterRun();
/// the 'with' stack associated with this execution thread
std::vector<With> _withStack;
/// the scope stack associated with this execution thread
ScopeStack _scopeStack;
/// A pointer to the function being executed, or NULL
/// for non-function execution
///
/// TODO:
/// This should likely be put in a larger
/// structure including return address
/// and maintained in a stack (the call stack)
///
const Function* _func;
/// The 'this' pointer, if this is a function call
as_object* _this_ptr;
/// Stack size at start of execution
size_t _initialStackSize;
DisplayObject* _originalTarget;
int _origExecSWFVersion;
std::stack<TryBlock> _tryList;
bool _returning;
bool _abortOnUnload;
/// Program counter (offset of current action tag)
size_t pc;
/// Offset to next action tag
size_t next_pc;
/// End of current function execution
/// Used for try/throw/catch blocks.
size_t stop_pc;
};
} // namespace gnash
#endif // GNASH_ACTIONEXEC_H
// Local Variables:
// mode: C++
// indent-tabs-mode: t
// End:
|