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
void setLocal(CallFrame &c, const ObjectURI &name, const as_value &val)
Set a local variable in this CallFrame.
Definition: CallStack.cpp:80
ActionScript value type.
Definition: as_value.h:94
A CallFrame is an element of a CallStack.
Definition: CallStack.h:43
as_object & locals()
Access the local variables for this function call.
Definition: CallStack.h:73
std::vector< as_value > Registers
Definition: CallStack.h:47
CallFrame & operator=(const CallFrame &other)
Assignment operator for containers.
Definition: CallStack.h:65
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
Definition: GnashKey.h:149
CallFrame(UserFunction *func)
Construct a CallFrame for a specific UserFunction.
Definition: CallStack.cpp:30
The base class for all ActionScript objects.
Definition: as_object.h:161
Definition: GnashKey.h:161
const as_value * getLocalRegister(size_t i) const
Get a specific register in this CallFrame.
Definition: CallStack.h:87
A URI for describing as_objects.
Definition: ObjectURI.h:44
A UserFunction is a callable function defined in ActionScript.
Definition: UserFunction.h:37
void declareLocal(CallFrame &c, const ObjectURI &name)
Declare a local variable in this CallFrame.
Definition: CallStack.cpp:71
CallFrame(const CallFrame &other)
Copy constructor for containers.
Definition: CallStack.h:57
bool hasRegisters() const
Set the number of registers for this CallFrame.
Definition: CallStack.h:104
void setLocalRegister(size_t i, const as_value &val)
Set a specific register in this CallFrame.
Definition: CallStack.cpp:57
std::vector< CallFrame > CallStack
Definition: CallStack.h:146
void markReachableResources() const
Mark all reachable resources.
Definition: CallStack.cpp:44
Definition: GnashKey.h:155
friend std::ostream & operator<<(std::ostream &, const CallFrame &)
Definition: CallStack.cpp:96
std::string name
Definition: LocalConnection_as.cpp:149