Gnash  0.8.11dev
CallStack.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 // Free Software Foundation, Inc
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 
19 #ifndef GNASH_VM_CALL_STACK_H
20 #define GNASH_VM_CALL_STACK_H
21 
22 #include <vector>
23 
24 #include "as_value.h"
25 
26 // Forward declarations
27 namespace gnash {
28  class as_object;
29  struct ObjectURI;
30  class UserFunction;
31 }
32 
33 namespace gnash {
34 
36 //
39 //
43 class CallFrame
44 {
45 public:
46 
47  typedef std::vector<as_value> Registers;
48 
50  //
54  CallFrame(UserFunction* func);
55 
57  CallFrame(const CallFrame& other)
58  :
59  _locals(other._locals),
60  _func(other._func),
61  _registers(other._registers)
62  {}
63 
65  CallFrame& operator=(const CallFrame& other) {
66  _locals = other._locals;
67  _func = other._func;
68  _registers = other._registers;
69  return *this;
70  }
71 
74  return *_locals;
75  }
76 
78  UserFunction& function() {
79  return *_func;
80  }
81 
83  //
87  const as_value* getLocalRegister(size_t i) const {
88  if (i >= _registers.size()) return nullptr;
89  return &_registers[i];
90  }
91 
93  //
95  //
98  void setLocalRegister(size_t i, const as_value& val);
99 
101  //
104  bool hasRegisters() const {
105  return !_registers.empty();
106  }
107 
109  //
112  void markReachableResources() const;
113 
114 
115 private:
116 
117  friend std::ostream& operator<<(std::ostream&, const CallFrame&);
118 
120  as_object* _locals;
121 
122  UserFunction* _func;
123 
125  Registers _registers;
126 
127 };
128 
130 //
132 //
135 void declareLocal(CallFrame& c, const ObjectURI& name);
136 
138 //
140 //
144 void setLocal(CallFrame& c, const ObjectURI& name, const as_value& val);
145 
146 typedef std::vector<CallFrame> CallStack;
147 
148 std::ostream& operator<<(std::ostream& o, const CallFrame& fr);
149 
150 } // namespace gnash
151 
152 #endif // GNASH_VM_CALL_STACK_H
gnash::CallFrame::CallFrame
CallFrame(const CallFrame &other)
Copy constructor for containers.
Definition: CallStack.h:57
name
std::string name
Definition: LocalConnection_as.cpp:149
gnash::CallStack
std::vector< CallFrame > CallStack
Definition: CallStack.h:146
gnash::as_object
The base class for all ActionScript objects.
Definition: as_object.h:162
as_object.h
gnash::CallFrame::operator<<
friend std::ostream & operator<<(std::ostream &, const CallFrame &)
Definition: CallStack.cpp:96
gnash::log_action
void log_action(StringType msg, Args... args)
Definition: log.h:307
gnash::key::i
@ i
Definition: GnashKey.h:155
gnash::setLocal
void setLocal(CallFrame &c, const ObjectURI &name, const as_value &val)
Set a local variable in this CallFrame.
Definition: CallStack.cpp:80
CallStack.h
_
#define _(String)
Definition: log.h:44
gnash
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:41
as_value.h
gnash::getGlobal
Global_as & getGlobal(const as_environment &env)
Definition: as_environment.cpp:651
gnash::CallFrame::setLocalRegister
void setLocalRegister(size_t i, const as_value &val)
Set a specific register in this CallFrame.
Definition: CallStack.cpp:57
gnash::key::r
@ r
Definition: GnashKey.h:164
gnash::renderer::opengl::for_each
void for_each(C &container, R(T::*pmf)(const A &), const A &arg)
Definition: Renderer_ogl.cpp:690
gnash::CallFrame::CallFrame
CallFrame(UserFunction *func)
Construct a CallFrame for a specific UserFunction.
Definition: CallStack.cpp:30
gnash::UserFunction
A UserFunction is a callable function defined in ActionScript.
Definition: UserFunction.h:38
Property.h
gnash::Property
An abstract property.
Definition: Property.h:277
gnash::as_value
ActionScript value type.
Definition: as_value.h:95
gnash::CallFrame::operator=
CallFrame & operator=(const CallFrame &other)
Assignment operator for containers.
Definition: CallStack.h:65
gnash::CallFrame::hasRegisters
bool hasRegisters() const
Set the number of registers for this CallFrame.
Definition: CallStack.h:104
log.h
gnash::as_value::setReachable
void setReachable() const
Set any object value as reachable (for the GC)
Definition: as_value.cpp:691
IF_VERBOSE_ACTION
#define IF_VERBOSE_ACTION(x)
Definition: log.h:384
gnash::CallFrame::markReachableResources
void markReachableResources() const
Mark all reachable resources.
Definition: CallStack.cpp:44
gnash::key::f
@ f
Definition: GnashKey.h:152
gnash::as_object::set_member
virtual bool set_member(const ObjectURI &uri, const as_value &val, bool ifFound=false)
Set a member value.
Definition: as_object.cpp:583
gnash::key::c
@ c
Definition: GnashKey.h:149
gnash::hasOwnProperty
bool hasOwnProperty(as_object &o, const ObjectURI &uri)
Return true if this object has the named property.
Definition: as_object.h:854
gnash::declareLocal
void declareLocal(CallFrame &c, const ObjectURI &name)
Declare a local variable in this CallFrame.
Definition: CallStack.cpp:71
gnash::CallFrame
A CallFrame is an element of a CallStack.
Definition: CallStack.h:44
gnash::key::o
@ o
Definition: GnashKey.h:161
gnash::CallFrame::Registers
std::vector< as_value > Registers
Definition: CallStack.h:47
UserFunction.h
gnash::ObjectURI
A URI for describing as_objects.
Definition: ObjectURI.h:45
gnash::CallFrame::getLocalRegister
const as_value * getLocalRegister(size_t i) const
Get a specific register in this CallFrame.
Definition: CallStack.h:87
gnash::CallFrame::locals
as_object & locals()
Access the local variables for this function call.
Definition: CallStack.h:73
gnash::Property::setValue
bool setValue(as_object &this_ptr, const as_value &value) const
Set value of this property.
Definition: Property.cpp:133
gnash::operator<<
std::ostream & operator<<(std::ostream &o, const URL &u)
Definition: URL.cpp:447
gnash::GcResource::setReachable
void setReachable() const
Mark this resource as being reachable.
Definition: GC.h:92
gnash::as_object::getOwnProperty
Property * getOwnProperty(const ObjectURI &uri)
Get this object's own named property, if existing.
Definition: as_object.cpp:926