[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] /srv/bzr/gnash/avm2 r9699: Introduce AVM2 to Gnash coding
From: |
Benjamin Wolsey |
Subject: |
[Gnash-commit] /srv/bzr/gnash/avm2 r9699: Introduce AVM2 to Gnash coding style. Start some attempt at proper |
Date: |
Wed, 25 Mar 2009 13:01:00 +0100 |
User-agent: |
Bazaar (1.5) |
------------------------------------------------------------
revno: 9699
committer: Benjamin Wolsey <address@hidden>
branch nick: avm2
timestamp: Wed 2009-03-25 13:01:00 +0100
message:
Introduce AVM2 to Gnash coding style. Start some attempt at proper
encapsulation and replace some of the debugging output hacks.
modified:
libbase/log.cpp
libbase/log.h
libcore/abc_function.cpp
libcore/abc_function.h
libcore/asClass.cpp
libcore/asClass.h
libcore/parser/abc_block.cpp
libcore/parser/abc_block.h
libcore/swf/DoABCTag.h
libcore/vm/Machine.cpp
libcore/vm/asName.h
------------------------------------------------------------
revno: 9698.1.1
committer: Benjamin Wolsey <address@hidden>
branch nick: avm2-work
timestamp: Tue 2009-03-24 12:07:39 +0100
message:
Add log_abc for ABC block parsing, replacing macro.
modified:
libbase/log.cpp
libbase/log.h
libcore/parser/abc_block.cpp
libcore/parser/abc_block.h
------------------------------------------------------------
revno: 9698.1.2
committer: Benjamin Wolsey <address@hidden>
branch nick: avm2-work
timestamp: Tue 2009-03-24 12:13:33 +0100
message:
Replace ERR with log_error. Drop c_str().
modified:
libcore/parser/abc_block.cpp
------------------------------------------------------------
revno: 9698.1.3
committer: Benjamin Wolsey <address@hidden>
branch nick: avm2-work
timestamp: Tue 2009-03-24 12:23:07 +0100
message:
Clean up more.
modified:
libcore/parser/abc_block.cpp
------------------------------------------------------------
revno: 9698.1.4
committer: Benjamin Wolsey <address@hidden>
branch nick: avm2-work
timestamp: Wed 2009-03-25 12:02:48 +0100
message:
Introduce a bit of encapasulation.
modified:
libcore/abc_function.cpp
libcore/asClass.cpp
libcore/asClass.h
libcore/parser/abc_block.cpp
libcore/parser/abc_block.h
libcore/swf/DoABCTag.h
libcore/vm/Machine.cpp
libcore/vm/asName.h
------------------------------------------------------------
revno: 9698.1.5
committer: Benjamin Wolsey <address@hidden>
branch nick: avm2-work
timestamp: Wed 2009-03-25 12:23:39 +0100
message:
Initialize _body correctly and only log_abc at debug level 2 or above.
modified:
libbase/log.cpp
libcore/abc_function.h
libcore/asClass.cpp
=== modified file 'libbase/log.cpp'
--- a/libbase/log.cpp 2009-02-25 22:33:03 +0000
+++ b/libbase/log.cpp 2009-03-25 11:23:39 +0000
@@ -129,6 +129,13 @@
}
void
+processLog_abc(const boost::format& fmt)
+{
+ if (dbglogfile.getVerbosity() < GNASH_DEBUG_LEVEL) return;
+ dbglogfile.log(N_("ABC"), fmt.str());
+}
+
+void
processLog_parse(const boost::format& fmt)
{
dbglogfile.log(fmt.str());
=== modified file 'libbase/log.h'
--- a/libbase/log.h 2009-02-25 22:33:03 +0000
+++ b/libbase/log.h 2009-03-24 11:07:39 +0000
@@ -225,7 +225,7 @@
/// This is a sequence of different log message types to be used in
/// the code. Append the name to log_ to call the function, e.g.
/// log_error, log_unimpl.
-#define LOG_TYPES (error) (debug) (unimpl) (aserror) (swferror) (amferror)
(security) (action) (parse) (trace)
+#define LOG_TYPES (error) (debug) (unimpl) (aserror) (swferror) (amferror)
(security) (action) (parse) (trace) (abc)
/// This actually creates the template functions using the TOKENIZE
/// functions above. The templates look like this:
@@ -289,6 +289,7 @@
DSOEXPORT void processLog_swferror(const boost::format& fmt);
DSOEXPORT void processLog_amferror(const boost::format& fmt);
DSOEXPORT void processLog_aserror(const boost::format& fmt);
+DSOEXPORT void processLog_abc(const boost::format& fmt);
/// A fault-tolerant boost::format object for logging
//
=== modified file 'libcore/abc_function.cpp'
--- a/libcore/abc_function.cpp 2009-02-25 18:37:36 +0000
+++ b/libcore/abc_function.cpp 2009-03-25 11:02:48 +0000
@@ -36,9 +36,11 @@
as_value
abc_function::operator()(const fn_call& fn)
{
- LOG_DEBUG_AVM("Calling an abc_function id=%u.",mMethodInfo->mMethodID);
+ LOG_DEBUG_AVM("Calling an abc_function id=%u.",
+ mMethodInfo->methodID());
as_value val = mMachine->executeFunction(mMethodInfo,fn);
- LOG_DEBUG_AVM("Done calling abc_function id=%u
value=%s",mMethodInfo->mMethodID,val.toDebugString());
+ LOG_DEBUG_AVM("Done calling abc_function id=%u value=%s",
+ mMethodInfo->methodID(),val.toDebugString());
return val;
}
=== modified file 'libcore/abc_function.h'
--- a/libcore/abc_function.h 2009-02-25 18:37:36 +0000
+++ b/libcore/abc_function.h 2009-03-25 11:23:39 +0000
@@ -15,8 +15,8 @@
// 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_ABC_FUNCTION_H__
-#define __GNASH_ABC_FUNCTION_H__
+#ifndef GNASH_ABC_FUNCTION_H
+#define GNASH_ABC_FUNCTION_H
#ifdef HAVE_CONFIG_H
#include "gnashconfig.h" // GNASH_USE_GC
=== modified file 'libcore/asClass.cpp'
--- a/libcore/asClass.cpp 2009-03-04 20:30:04 +0000
+++ b/libcore/asClass.cpp 2009-03-25 11:23:39 +0000
@@ -28,19 +28,19 @@
#include "abc_function.h"
namespace gnash {
-#define STV(x) VM::get().getStringTable().value(x).c_str()
-asMethod::asMethod():mBody()
+asMethod::asMethod()
+ :
+ _minArguments(0),
+ _maxArguments(0),
+ _body(0)
{
- //mArguments();
- mMinArguments = 0;
- mMaxArguments = 0;
}
void
asMethod::print_body()
{
- if(!mBody){
+ if(!_body){
log_parse("Method has no body.");
return;
}
@@ -50,11 +50,11 @@
// ss.setf(std::ios::hex, std::ios::basefield);
// ss.setf (std::ios::showbase);
boost::uint32_t i;
- for(i=0;i<mBodyLength;i++){
- opcode = mBody->read_as3op();
+ for(i=0;i<_bodyLength;i++){
+ opcode = _body->read_as3op();
ss << "0x" << std::uppercase << std::hex << (opcode |
0x0) << " ";
}
- mBody->seekTo(0);
+ _body->seekTo(0);
log_parse("%s",ss.str());
}
@@ -62,11 +62,11 @@
asMethod::setOwner(asClass *pOwner)
{
log_debug("asMethod::setOwner");
- if(!mPrototype){
- log_debug("ERROR mPrototype is null.");
+ if(!_prototype){
+ log_debug("ERROR _prototype is null.");
}
- log_debug("Prototype text value: %s",mPrototype->get_text_value());
- mPrototype->set_member(NSV::PROP_PROTOTYPE, pOwner->getPrototype());
+ log_debug("Prototype text value: %s",_prototype->get_text_value());
+ _prototype->set_member(NSV::PROP_PROTOTYPE, pOwner->getPrototype());
}
void
@@ -92,10 +92,10 @@
if(slotId == 0){
- mPrototype->init_member(name, val, flags, nsname);
+ _prototype->init_member(name, val, flags, nsname);
}
else{
- mPrototype->init_member(name, val, flags, nsname, slotId);
+ _prototype->init_member(name, val, flags, nsname, slotId);
}
return true;
}
@@ -117,10 +117,10 @@
flags |= as_prop_flags::staticProp;
if(slotId == 0){
- mPrototype->init_member(name, val, flags, nsname);
+ _prototype->init_member(name, val, flags, nsname);
}
else{
- mPrototype->init_member(name, val, flags, nsname, slotId);
+ _prototype->init_member(name, val, flags, nsname, slotId);
}
return true;
}
@@ -146,7 +146,7 @@
string_table::key nsname = ns ? ns->getURI() : string_table::key(0);
int flags = as_prop_flags::dontDelete;
- mPrototype->init_member(name, as_value(), flags, nsname, slotId);
+ _prototype->init_member(name, as_value(), flags, nsname, slotId);
return true;
}
@@ -163,7 +163,7 @@
void
asMethod::initPrototype(Machine* machine)
{
- mPrototype = new abc_function(this,machine);
+ _prototype = new abc_function(this,machine);
}
bool
@@ -187,10 +187,10 @@
// log_debug("Before init_member.");
//TODO: Set flags.
if(slotId == 0){
- mPrototype->init_member(name,as_value(), 0, nsname);
+ _prototype->init_member(name,as_value(), 0, nsname);
}
else{
- mPrototype->init_member(name, as_value(), 0, nsname, slotId);
+ _prototype->init_member(name, as_value(), 0, nsname, slotId);
}
return true;
}
@@ -200,8 +200,8 @@
{
// string_table::key nsname = ns ? ns->getURI() : string_table::key(0);
// as_value val(method->getPrototype());
-// as value val = new
as_value(abc_function(asMethod->getBody,mPrototype->getVM().getMachine()));
-// mPrototype->init_member(name, val, as_prop_flags::readOnly |
+// as value val = new
as_value(abc_function(asMethod->getBody,_prototype->getVM().getMachine()));
+// _prototype->init_member(name, val, as_prop_flags::readOnly |
// as_prop_flags::dontDelete | as_prop_flags::dontEnum, nsname);
// return true;
return false;
@@ -211,8 +211,8 @@
asClass::addMethod(string_table::key name, asNamespace* ns, asMethod* method,
bool isstatic)
{
- as_value val = as_value(new
abc_function(method,mPrototype->getVM().getMachine()));
- mPrototype->init_member(name, val);
+ as_value val = as_value(new
abc_function(method,_prototype->getVM().getMachine()));
+ _prototype->init_member(name, val);
// int flags = as_prop_flags::readOnly | as_prop_flags::dontDelete
// | as_prop_flags::dontEnum;
// if (isstatic)
@@ -227,7 +227,7 @@
{
string_table::key nsname = ns ? ns->getURI() : string_table::key(0);
- Property *getset = mPrototype->getOwnProperty(name, nsname);
+ Property *getset = _prototype->getOwnProperty(name, nsname);
if (getset)
getset->setGetter(method->getPrototype());
@@ -236,7 +236,7 @@
int flags = as_prop_flags::dontDelete | as_prop_flags::dontEnum;
if (isstatic)
flags |= as_prop_flags::staticProp;
- mPrototype->init_property(name, *method->getPrototype(),
+ _prototype->init_property(name, *method->getPrototype(),
*method->getPrototype(), flags, nsname);
}
return true;
@@ -248,7 +248,7 @@
{
string_table::key nsname = ns ? ns->getURI() : string_table::key(0);
- Property *getset = mPrototype->getOwnProperty(name, nsname);
+ Property *getset = _prototype->getOwnProperty(name, nsname);
if (getset)
getset->setSetter(method->getPrototype());
@@ -257,7 +257,7 @@
int flags = as_prop_flags::dontDelete | as_prop_flags::dontEnum;
if (isstatic)
flags |= as_prop_flags::staticProp;
- mPrototype->init_property(name, *method->getPrototype(),
+ _prototype->init_property(name, *method->getPrototype(),
*method->getPrototype(), flags, nsname);
}
return true;
@@ -268,14 +268,14 @@
{
string_table::key nsname = ns ? ns->getURI() : string_table::key(0);
- Property *getset = mPrototype->getOwnProperty(name, nsname);
+ Property *getset = _prototype->getOwnProperty(name, nsname);
if (getset)
getset->setGetter(method->getPrototype());
else
{
int flags = as_prop_flags::dontDelete | as_prop_flags::dontEnum;
- mPrototype->init_property(name, *method->getPrototype(),
+ _prototype->init_property(name, *method->getPrototype(),
*method->getPrototype(), flags, nsname);
}
return true;
@@ -286,14 +286,14 @@
{
string_table::key nsname = ns ? ns->getURI() : string_table::key(0);
- Property *getset = mPrototype->getOwnProperty(name, nsname);
+ Property *getset = _prototype->getOwnProperty(name, nsname);
if (getset)
getset->setSetter(method->getPrototype());
else
{
int flags = as_prop_flags::dontDelete | as_prop_flags::dontEnum;
- mPrototype->init_property(name, *method->getPrototype(),
+ _prototype->init_property(name, *method->getPrototype(),
*method->getPrototype(), flags, nsname);
}
return true;
=== modified file 'libcore/asClass.h'
--- a/libcore/asClass.h 2009-03-04 20:30:04 +0000
+++ b/libcore/asClass.h 2009-03-25 11:02:48 +0000
@@ -30,8 +30,6 @@
#include "abc_block.h"
-
-
namespace gnash {
class as_function;
@@ -49,7 +47,7 @@
class Machine;
class abc_function;
-namespace abc_parsing{
+namespace abc_parsing {
class abc_Trait;
}
@@ -57,22 +55,22 @@
class asException
{
public:
- void setStart(boost::uint32_t i) { mStart = i; }
+ void setStart(boost::uint32_t i) { _start = i; }
void setEnd(boost::uint32_t i) { mEnd = i; }
void setCatch(boost::uint32_t i) { mCatch = i; }
void catchAny() { mCatchAny = true; }
void setCatchType(asClass* p) { mCatchType = p; }
- void setNamespace(asNamespace* n) { mNamespace = n; }
- void setName(string_table::key name) { mName = name; }
+ void setNamespace(asNamespace* n) { _namespace = n; }
+ void setName(string_table::key name) { _name = name; }
private:
- boost::uint32_t mStart;
+ boost::uint32_t _start;
boost::uint32_t mEnd;
boost::uint32_t mCatch;
bool mCatchAny;
asClass *mCatchType;
- asNamespace *mNamespace;
- string_table::key mName;
+ asNamespace *_namespace;
+ string_table::key _name;
};
#if 0
/// An abstract binding for ActionScript.
@@ -85,15 +83,15 @@
void unsetConst() { mConst = false; }
bool isConst() { return mConst; }
- void setStatic() { mStatic = true; }
- void unsetStatic() { mStatic = false; }
- bool isStatic() { return mStatic; }
+ void setStatic() { _static = true; }
+ void unsetStatic() { _static = false; }
+ bool isStatic() { return _static; }
- boost::uint32_t getSlotId() { return mSlotId; }
- void setSlotId(boost::uint32_t s) { mSlotId = s; }
+ boost::uint32_t getSlotId() { return _slotId; }
+ void setSlotId(boost::uint32_t s) { _slotId = s; }
// Chad: Document
- string_table::key getName() { return mName; }
+ string_table::key getName() { return _name; }
void setLexOnly(bool) { /* TODO */ }
/// If true, the attribute has a setter, but no getter.
@@ -110,37 +108,37 @@
// As a member method.
asBinding(asNamespace *ns, asMethod *pMethod, bool isstatic = false) :
- mNamespace(ns), mType(T_METHOD), mSlotId(0), mConst(true),
- mStatic(isstatic), mMethod(pMethod)
+ _namespace(ns), mType(T_METHOD), _slotId(0), mConst(true),
+ _static(isstatic), _method(pMethod)
{/**/}
// As an assignable function.
asBinding(asNamespace *ns, asMethod *pMethod, boost::uint32_t sid, bool
isstatic) :
- mNamespace(ns), mType(T_METHOD), mSlotId(sid), mConst(false),
- mStatic(isstatic), mMethod(pMethod)
+ _namespace(ns), mType(T_METHOD), _slotId(sid), mConst(false),
+ _static(isstatic), _method(pMethod)
{/**/}
asBinding(asNamespace *ns, asBoundValue *pValue, boost::uint32_t sid,
bool isconstant,
- bool isstatic) : mNamespace(ns), mType(T_VALUE), mSlotId(sid),
mConst(isconstant),
- mStatic(isstatic), mValue(pValue)
+ bool isstatic) : _namespace(ns), mType(T_VALUE), _slotId(sid),
mConst(isconstant),
+ _static(isstatic), mValue(pValue)
{/**/}
asBinding(asNamespace *ns, asBoundValue *pValue, boost::uint32_t sid,
bool isstatic) :
- mNamespace(ns), mType(T_VALUE), mSlotId(sid), mConst(false),
mStatic(isstatic),
+ _namespace(ns), mType(T_VALUE), _slotId(sid), mConst(false),
_static(isstatic),
mValue(pValue)
{/**/}
asBinding(asNamespace *ns, asBoundAccessor *pAccess, bool isstatic) :
- mNamespace(ns), mType(T_ACCESS), mSlotId(0), mConst(true),
mStatic(isstatic),
- mAccess(pAccess)
+ _namespace(ns), mType(T_ACCESS), _slotId(0), mConst(true),
_static(isstatic),
+ _access(pAccess)
{/**/}
asBinding(asNamespace *ns, asClass *pClass, boost::uint32_t sid, bool
isstatic) :
- mNamespace(ns), mType(T_CLASS), mSlotId(sid), mConst(true),
mStatic(isstatic),
+ _namespace(ns), mType(T_CLASS), _slotId(sid), mConst(true),
_static(isstatic),
mClass(pClass)
{/**/}
- asBinding() : mNamespace(NULL), mType(T_CLASS), mSlotId(0),
mConst(false), mStatic(false),
+ asBinding() : _namespace(NULL), mType(T_CLASS), _slotId(0),
mConst(false), _static(false),
mClass(NULL)
{/**/}
@@ -150,26 +148,26 @@
void reset(asBoundAccessor *pAccess, bool isstatic)
{
mType = T_ACCESS;
- mAccess = pAccess;
+ _access = pAccess;
mConst = true;
- mStatic = isstatic;
+ _static = isstatic;
}
asBoundAccessor* getAccessor()
- { return mType == T_ACCESS ? mAccess : NULL; }
+ { return mType == T_ACCESS ? _access : NULL; }
asBoundValue* getValue()
{ return mType == T_VALUE ? mValue : NULL; }
asMethod* getMethod()
- { return mType == T_METHOD ? mMethod : NULL; }
+ { return mType == T_METHOD ? _method : NULL; }
asClass* getClass()
{ return mType == T_CLASS ? mClass : NULL; }
as_function* getASFunction();
- asNamespace *mNamespace;
+ asNamespace *_namespace;
typedef enum
{
@@ -181,18 +179,18 @@
} types;
types mType;
- boost::uint32_t mSlotId;
+ boost::uint32_t _slotId;
bool mConst;
- bool mStatic;
- string_table::key mName;
- as_object* mOwner;
+ bool _static;
+ string_table::key _name;
+ as_object* _owner;
union
{
asClass *mClass;
- asMethod *mMethod;
+ asMethod *_method;
asBoundValue *mValue;
- asBoundAccessor *mAccess;
+ asBoundAccessor *_access;
};
};
#endif // comment out of asBinding
@@ -204,9 +202,9 @@
void markReachableResources() const { /* TODO */ }
/// Our parent (for protected)
- void setParent(asNamespace* p) { mParent = p; }
+ void setParent(asNamespace* p) { _parent = p; }
- asNamespace* getParent() { return mParent; }
+ asNamespace* getParent() { return _parent; }
/// Set the uri
void setURI(string_table::key name) { mUri = name; }
@@ -214,23 +212,23 @@
/// What is the Uri of the namespace?
string_table::key getURI() const { return mUri; }
- string_table::key getAbcURI() const {return mAbcURI;}
- void setAbcURI(string_table::key n){ mAbcURI = n; }
+ string_table::key getAbcURI() const {return _abcURI;}
+ void setAbcURI(string_table::key n){ _abcURI = n; }
/// What is the XML prefix?
- string_table::key getPrefix() const { return mPrefix; }
+ string_table::key getPrefix() const { return _prefix; }
/// Create an empty namespace
asNamespace()
:
- mParent(0),
+ _parent(0),
mUri(0),
- mPrefix(0),
- mAbcURI(0),
+ _prefix(0),
+ _abcURI(0),
mClasses(),
mRecursePrevent(false),
- mPrivate(false),
- mProtected(false)
+ _private(false),
+ _protected(false)
{/**/}
/// Add a class to the namespace. The namespace stores this, but
@@ -262,27 +260,27 @@
return found;
}
- void setPrivate() { mPrivate = true; }
- void unsetPrivate() { mPrivate = false; }
- bool isPrivate() { return mPrivate; }
+ void setPrivate() { _private = true; }
+ void unsetPrivate() { _private = false; }
+ bool isPrivate() { return _private; }
- void setProtected() { mProtected = true; }
- void unsetProtected() { mProtected = false; }
- bool isProtected() { return mProtected; }
+ void setProtected() { _protected = true; }
+ void unsetProtected() { _protected = false; }
+ bool isProtected() { return _protected; }
private:
- asNamespace *mParent;
+ asNamespace *_parent;
string_table::key mUri;
- string_table::key mPrefix;
+ string_table::key _prefix;
- string_table::key mAbcURI;
+ string_table::key _abcURI;
typedef std::map<string_table::key, asClass*> container;
container mClasses;
mutable bool mRecursePrevent;
- bool mPrivate;
- bool mProtected;
+ bool _private;
+ bool _protected;
asClass *getClassInternal(string_table::key name) const
{
@@ -303,16 +301,16 @@
{
public:
bool setGetter(asMethod *p) { mGetter = p; return true; }
- bool setSetter(asMethod *p) { mSetter = p; return true; }
+ bool setSetter(asMethod *p) { _setter = p; return true; }
bool setValue(asBoundValue *p) { mValue = p; return true; }
asBoundValue* getValue() { return mValue; }
asMethod *getGetter() { return mGetter; }
- asMethod *getSetter() { return mSetter; }
+ asMethod *getSetter() { return _setter; }
private:
asMethod *mGetter;
- asMethod *mSetter;
+ asMethod *_setter;
asBoundValue *mValue;
};
@@ -338,66 +336,50 @@
/// Methods are unnamed until they are bound to an object.
class asMethod
{
-private:
- abc_function* mPrototype;
-
- typedef enum
- {
- FLAGS_FINAL = 0x01,
- FLAGS_PROTECTED = 0x02,
- FLAGS_PUBLIC = 0x04,
- FLAGS_PRIVATE = 0x08
- } flags;
- /// A list of type identifiers
- typedef std::list<asClass*> argumentList;
- typedef std::map<string_table::key, asBinding> binding_container;
-
- int mMinArguments;
- int mMaxArguments;
- boost::uint32_t mBodyLength;
- bool mIsNative;
- argumentList mArguments;
- std::list<as_value> mOptionalArguments;
- as_function *mImplementation;
- unsigned char mFlags;
- CodeStream *mBody;
- boost::uint32_t mMaxRegisters;
- bool addBinding(string_table::key name, asBinding b);
-
public:
+
+ typedef std::list<asClass*> ArgumentList;
+
+ asMethod();
+
+ boost::uint32_t methodID() const {
+ return _methodID;
+ }
+
+ void setMethodID(boost::uint32_t m) {
+ _methodID = m;
+ }
void initPrototype(Machine* machine);
- boost::uint32_t getMaxRegisters(){ return mMaxRegisters;}
-
- void setMaxRegisters(boost::uint32_t maxRegisters){ mMaxRegisters =
maxRegisters;}
-
- boost::uint32_t mMethodID;
-
- boost::uint32_t getBodyLength(){ return mBodyLength;}
-
- void setBodyLength(boost::uint32_t length){ mBodyLength = length;}
-
- abc_function* getPrototype() { return mPrototype; }
+ boost::uint32_t getMaxRegisters(){ return _maxRegisters;}
+
+ void setMaxRegisters(boost::uint32_t maxRegisters) {
+ _maxRegisters = maxRegisters;
+ }
+
+ boost::uint32_t getBodyLength(){ return _bodyLength;}
+
+ void setBodyLength(boost::uint32_t length){ _bodyLength = length;}
+
+ abc_function* getPrototype() { return _prototype; }
asBinding* getBinding(string_table::key name);
- asMethod();
-
- bool isNative() { return mIsNative; }
- bool hasBody() const { return mBody != NULL; }
+ bool isNative() { return _isNative; }
+ bool hasBody() const { return _body != NULL; }
as_object* construct(as_object* /*base_scope*/) { /* TODO */ return
NULL; }
bool hasActivation();
- CodeStream *getBody() { return mBody; }
- void setBody(CodeStream *b) { mBody = b; }
+ CodeStream *getBody() { return _body; }
+ void setBody(CodeStream *b) { _body = b; }
- bool addValue(string_table::key name, asNamespace *ns, boost::uint32_t
slotId,
+ bool addValue(string_table::key name, asNamespace *ns, boost::uint32_t
slotID,
asClass *type, as_value& val, bool isconst);
- bool addSlot(string_table::key name, asNamespace *ns, boost::uint32_t
slotId,
+ bool addSlot(string_table::key name, asNamespace *ns, boost::uint32_t
slotID,
asClass *type);
bool addMethod(string_table::key name, asNamespace *ns, asMethod
*method);
@@ -407,10 +389,10 @@
bool addSetter(string_table::key name, asNamespace *ns, asMethod
*method);
bool addMemberClass(string_table::key name, asNamespace *ns,
- boost::uint32_t slotId, asClass *type);
+ boost::uint32_t slotID, asClass *type);
bool addSlotFunction(string_table::key name, asNamespace *ns,
- boost::uint32_t slotId, asMethod *method);
+ boost::uint32_t slotID, asMethod *method);
/// \brief
/// Set the owner of this method.
@@ -431,80 +413,85 @@
/// \brief
/// Is the method final? If so, it may not be overridden.
- bool isFinal() const { return mFlags & FLAGS_FINAL; }
+ bool isFinal() const { return _flags & FLAGS_FINAL; }
/// \brief
/// Set the method as final.
- void setFinal() { mFlags = mFlags | FLAGS_FINAL; }
+ void setFinal() { _flags = _flags | FLAGS_FINAL; }
/// \brief
/// Unset the method as final. Not final anymore.
- void unsetFinal() { mFlags = mFlags & ~FLAGS_FINAL; }
+ void unsetFinal() { _flags = _flags & ~FLAGS_FINAL; }
/// \brief
/// Is the method private?
- bool isPrivate() const { return mFlags & FLAGS_PRIVATE; }
+ bool isPrivate() const { return _flags & FLAGS_PRIVATE; }
/// \brief
/// Make the method private.
- void setPrivate()
- { mFlags = (mFlags & ~(FLAGS_PUBLIC | FLAGS_PROTECTED)) |
FLAGS_PRIVATE; }
+ void setPrivate() {
+ _flags = (_flags & ~(FLAGS_PUBLIC | FLAGS_PROTECTED)) | FLAGS_PRIVATE;
+ }
/// \brief
/// Is the method protected?
- bool isProtected() const { return mFlags & FLAGS_PROTECTED; }
+ bool isProtected() const {
+ return _flags & FLAGS_PROTECTED;
+ }
/// \brief
/// Make the method protected.
- void setProtected()
- { mFlags = (mFlags & ~(FLAGS_PUBLIC | FLAGS_PRIVATE)) |
FLAGS_PROTECTED; }
+ void setProtected() {
+ _flags = (_flags & ~(FLAGS_PUBLIC | FLAGS_PRIVATE)) | FLAGS_PROTECTED;
}
/// \brief
/// Is the method public?
- bool isPublic() const { return mFlags & FLAGS_PUBLIC; }
+ bool isPublic() const { return _flags & FLAGS_PUBLIC; }
/// \brief
/// Make the method public.
- void setPublic()
- { mFlags = (mFlags & ~(FLAGS_PRIVATE | FLAGS_PROTECTED)) |
FLAGS_PUBLIC; }
+ void setPublic() {
+ _flags = (_flags & ~(FLAGS_PRIVATE | FLAGS_PROTECTED)) | FLAGS_PUBLIC;
+ }
/// \brief
/// How many arguments are required? -1 means unknown.
- int minArgumentCount() const { return mMinArguments; }
+ int minArgumentCount() const { return _minArguments; }
/// \brief
/// Set the required minimum arguments.
- void setMinArgumentCount(int i) { mMinArguments = i; }
+ void setMinArgumentCount(int i) { _minArguments = i; }
/// \brief
/// How many arguments are allowed? -1 means unknown.
- int maxArgumentCount() const { return mMaxArguments; }
+ int maxArgumentCount() const { return _maxArguments; }
/// Set the required maximum arguments.
- void setMaxArgumentCount(int i) { mMaxArguments = i; }
+ void setMaxArgumentCount(int i) { _maxArguments = i; }
/// \brief
/// Push an argument of type t into the method definition
- void pushArgument(asClass *t) { mArguments.push_back(t); }
+ void pushArgument(asClass *t) { _arguments.push_back(t); }
/// \brief
/// Push an optional argument's default value.
- void pushOptional(const as_value& v) { mOptionalArguments.push_back(v);
}
+ void pushOptional(const as_value& v) { _optionalArguments.push_back(v);
}
/// \brief
/// Are any of the arguments optional?
- bool optionalArguments() const
- { return minArgumentCount() != maxArgumentCount(); }
+ bool optionalArguments() const {
+ return minArgumentCount() != maxArgumentCount();
+ }
/// \brief
/// Get a reference to a list of argument types.
- argumentList& getArgumentList() { return mArguments; }
+ ArgumentList& getArgumentList() { return _arguments; }
/// \brief
/// Get an object capable of executing this function.
/// Note: This may be NULL, because we might have information about this
/// function but not actually have it yet.
- as_function* getImplementation() { return mImplementation; }
+ as_function* getImplementation() { return _implementation; }
/// \brief
/// Print the opcodes that define a method using log_parse.
@@ -513,6 +500,36 @@
void print_static_constructor(){
}
+
+private:
+
+ enum Flag
+ {
+ FLAGS_FINAL = 0x01,
+ FLAGS_PROTECTED = 0x02,
+ FLAGS_PUBLIC = 0x04,
+ FLAGS_PRIVATE = 0x08
+ };
+
+ /// A list of type identifiers
+ typedef std::map<string_table::key, asBinding> BindingContainer;
+
+ bool addBinding(string_table::key name, asBinding b);
+
+ boost::uint32_t _methodID;
+
+ abc_function* _prototype;
+ int _minArguments;
+ int _maxArguments;
+ boost::uint32_t _bodyLength;
+ bool _isNative;
+ ArgumentList _arguments;
+ std::list<as_value> _optionalArguments;
+ as_function* _implementation;
+ unsigned char _flags;
+ CodeStream* _body;
+ boost::uint32_t _maxRegisters;
+
};
/// A class to represent, abstractly, ActionScript prototypes.
@@ -524,15 +541,37 @@
class asClass
{
public:
- as_object* getPrototype() { return mPrototype; }
+
+ asClass()
+ :
+ _prototype(0),
+ _final(false),
+ _sealed(false),
+ _dynamic(false),
+ _interface(false),
+ _name(0),
+ _interfaces(),
+ _protectedNs(0),
+ _super(0),
+ _constructor(0),
+ _staticConstructor(0),
+ _bindings(),
+ _staticBindings(),
+ _declared(false),
+ _inherited(false),
+ _system(false)
+ {}
+
+ as_object* getPrototype() { return _prototype; }
void dump();
- bool addValue(string_table::key name, asNamespace *ns, boost::uint32_t
slotId,
- asClass *type, as_value& val, bool isconst, bool isstatic);
+ bool addValue(string_table::key name, asNamespace *ns,
+ boost::uint32_t slotID, asClass *type, as_value& val,
+ bool isconst, bool isstatic);
- bool addSlot(string_table::key name, asNamespace *ns, boost::uint32_t
slotId,
- asClass *type, bool isstatic);
+ bool addSlot(string_table::key name, asNamespace *ns,
+ boost::uint32_t slotID, asClass *type, bool isstatic);
bool addMethod(string_table::key name, asNamespace *ns, asMethod
*method,
bool isstatic);
@@ -544,119 +583,97 @@
bool isstatic);
bool addMemberClass(string_table::key name, asNamespace *ns,
- boost::uint32_t slotId, asClass *type, bool isstatic);
+ boost::uint32_t slotID, asClass *type, bool isstatic);
// TODO: Figure out how this differs from addMethod
bool addSlotFunction(string_table::key name, asNamespace *ns,
- boost::uint32_t slotId, asMethod *method, bool isstatic);
+ boost::uint32_t slotID, asMethod *method, bool isstatic);
/// Is the class final?
- bool isFinal() const { return mFinal; }
+ bool isFinal() const { return _final; }
/// Set the class as final.
- void setFinal() { mFinal = true; }
+ void setFinal() { _final = true; }
/// Set the class as not final.
- void unsetFinal() { mFinal = false; }
+ void unsetFinal() { _final = false; }
/// Is the class sealed?
- bool isSealed() const { return mSealed; }
+ bool isSealed() const { return _sealed; }
/// Set the class as sealed.
- void setSealed() { mSealed = true; }
+ void setSealed() { _sealed = true; }
// Set the class as not sealed.
- void unsetSealed() { mSealed = false; }
+ void unsetSealed() { _sealed = false; }
/// Is the class an interface type?
- bool isInterface() const { return mInterface; }
+ bool isInterface() const { return _interface; }
/// Set the class as an interface.
- void setInterface() { mInterface = true; }
+ void setInterface() { _interface = true; }
/// Set the class as not an interface.
- void unsetInterface() { mInterface = false; }
+ void unsetInterface() { _interface = false; }
/// Is the class dynamic?
- bool isDynamic() const { return mDynamic; }
+ bool isDynamic() const { return _dynamic; }
/// Set the class as dynamic.
- void setDynamic() { mDynamic = true; }
+ void setDynamic() { _dynamic = true; }
/// Set the class as not dynamic.
- void unsetDynamic() { mDynamic = false; }
+ void unsetDynamic() { _dynamic = false; }
/// Does the class have a protected namespace to be inherited?
- bool hasProtectedNs() const { return mProtectedNs != NULL; }
+ bool hasProtectedNs() const { return _protectedNs; }
/// Get the protected namespace.
- asNamespace *getProtectedNs() { return mProtectedNs; }
+ asNamespace *getProtectedNs() { return _protectedNs; }
/// Set the protected namespace.
- void setProtectedNs(asNamespace *n) { mProtectedNs = n; }
-
- string_table::key getName() const { return mName; }
-
- void initPrototype(){ mPrototype = new as_object();}
+ void setProtectedNs(asNamespace *n) { _protectedNs = n; }
+
+ string_table::key getName() const { return _name; }
+
+ void initPrototype(){ _prototype = new as_object();}
/// Set our Name
- void setName(string_table::key name) { mName = name; }
+ void setName(string_table::key name) { _name = name; }
/// What is the type of our parent class?
- asClass* getSuper() const { return mSuper; }
+ asClass* getSuper() const { return _super; }
/// We implement this interface.
- void pushInterface(asClass* p) { mInterfaces.push_back(p); }
+ void pushInterface(asClass* p) { _interfaces.push_back(p); }
/// This is our constructor.
- void setConstructor(asMethod *m) { mConstructor = m; }
- asMethod *getConstructor() { return mConstructor; }
+ void setConstructor(asMethod *m) { _constructor = m; }
+ asMethod *getConstructor() { return _constructor; }
- void setStaticConstructor(asMethod *m) { mStaticConstructor = m; }
- asMethod *getStaticConstructor(){return mStaticConstructor;}
- void setSuper(asClass *p) { mSuper = p; }
+ void setStaticConstructor(asMethod *m) { _staticConstructor = m; }
+ asMethod *getStaticConstructor(){return _staticConstructor;}
+ void setSuper(asClass *p) { _super = p; }
/// Try to build an asClass object from just a prototype.
- void buildFromPrototype(as_object *o, string_table::key name,
+ void buildFro_prototype(as_object *o, string_table::key name,
ClassHierarchy *);
- void setDeclared() { mDeclared = true; }
- bool isDeclared() { return mDeclared; }
- void setInherited() { mInherited = true; }
- bool isInherited() { return mInherited; }
-
- void setSystem() { mSystem = true; }
- void unsetSystem() { mSystem = false; }
- bool isSystem() { return mSystem; }
-
- asClass()
- :
- mPrototype(0),
- mFinal(false),
- mSealed(false),
- mDynamic(false),
- mInterface(false),
- mName(0),
- mInterfaces(),
- mProtectedNs(0),
- mSuper(0),
- mConstructor(0),
- mStaticConstructor(0),
- mBindings(),
- mStaticBindings(),
- mDeclared(false),
- mInherited(false),
- mSystem(false)/*,mTraits()*/
- {/**/}
-
+ void setDeclared() { _declared = true; }
+ bool isDeclared() { return _declared; }
+ void setInherited() { _inherited = true; }
+ bool isInherited() { return _inherited; }
+
+ void setSystem() { _system = true; }
+ void unsetSystem() { _system = false; }
+ bool isSystem() { return _system; }
asBinding *getBinding(string_table::key name)
{
- binding_container::iterator i;
- if (mBindings.empty())
- return NULL;
- i = mBindings.find(name);
- if (i == mBindings.end())
+ BindingContainer::iterator i;
+ if (_bindings.empty()) return NULL;
+ i = _bindings.find(name);
+ if (i == _bindings.end())
return NULL;
return &i->second;
}
@@ -664,45 +681,46 @@
asBinding* getGetBinding(as_value& v, asName& n);
asBinding* getSetBinding(as_value& v, asName& n);
- std::vector<abc_Trait> mTraits;
+ std::vector<abc_Trait> _traits;
private:
- as_object *mPrototype;
+
+ typedef std::map<string_table::key, asBinding> BindingContainer;
+
+ as_object *_prototype;
bool addBinding(string_table::key name, asBinding b)
- { mBindings[name] = b; return true; }
+ { _bindings[name] = b; return true; }
bool addStaticBinding(string_table::key name, asBinding b)
- { mStaticBindings[name] = b; return true; }
+ { _staticBindings[name] = b; return true; }
asBinding *getStaticBinding(string_table::key name)
{
- binding_container::iterator i;
- if (mStaticBindings.empty())
+ BindingContainer::iterator i;
+ if (_staticBindings.empty())
return NULL;
- i = mStaticBindings.find(name);
- if (i == mStaticBindings.end())
+ i = _staticBindings.find(name);
+ if (i == _staticBindings.end())
return NULL;
return &i->second;
}
- bool mFinal;
- bool mSealed;
- bool mDynamic;
- bool mInterface;
- string_table::key mName;
- std::list<asClass*> mInterfaces;
- asNamespace *mProtectedNs;
- asClass *mSuper;
- asMethod *mConstructor;
- asMethod *mStaticConstructor;
-
- typedef std::map<string_table::key, asBinding> binding_container;
-
- binding_container mBindings;
- binding_container mStaticBindings;
- bool mDeclared;
- bool mInherited;
- bool mSystem;
+ bool _final;
+ bool _sealed;
+ bool _dynamic;
+ bool _interface;
+ string_table::key _name;
+ std::list<asClass*> _interfaces;
+ asNamespace* _protectedNs;
+ asClass* _super;
+ asMethod* _constructor;
+ asMethod* _staticConstructor;
+
+ BindingContainer _bindings;
+ BindingContainer _staticBindings;
+ bool _declared;
+ bool _inherited;
+ bool _system;
};
} /* namespace gnash */
=== modified file 'libcore/parser/abc_block.cpp'
--- a/libcore/parser/abc_block.cpp 2009-03-04 20:30:04 +0000
+++ b/libcore/parser/abc_block.cpp 2009-03-25 11:02:48 +0000
@@ -6,7 +6,7 @@
// 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,
+// 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.
@@ -29,79 +29,77 @@
#include "CodeStream.h"
#include "action_buffer.h"
-//#define ERR(x) IF_VERBOSE_MALFORMED_SWF(log_swferror x;);
-#define ERR(x) printf x; fflush(stdout);
-
namespace gnash {
-
namespace abc_parsing {
bool
abc_Trait::finalize(abc_block *pBlock, asClass *pClass, bool do_static)
{
- LOG_DEBUG_ABC("In finalize class name=%s trait
kind=0x%X",pBlock->mStringPool[pClass->getName()],mKind | 0x0);
- switch (mKind)
+ log_abc("In finalize class name=%s trait kind=0x%X",
+ pBlock->_stringPool[pClass->getName()], _kind | 0x0);
+ switch (_kind)
{
case KIND_SLOT:
case KIND_CONST:
{
// Validate the type.
asClass *pType;
- if (mTypeIndex){
- LOG_DEBUG_ABC("Trait type is
%s",pBlock->mStringPool[pBlock->mMultinamePool[mTypeIndex].getABCName()]);
- pType =
pBlock->locateClass(pBlock->mMultinamePool[mTypeIndex]);
+ if (_typeIndex) {
+ log_abc("Trait type is %s",
+
pBlock->_stringPool[pBlock->_multinamePool[_typeIndex].getABCName()]);
+ pType =
pBlock->locateClass(pBlock->_multinamePool[_typeIndex]);
}
- else{
+ else {
pType = pBlock->mTheObject;
}
- if (!pType)
- {
- ERR((_("ABC: Finalizing trait yielded bad type for
slot.\n")));
+
+ if (!pType) {
+ log_error(_("ABC: Finalizing trait yielded bad type for
slot."));
return false;
}
// The name has been validated in read.
// TODO: Find a better way to initialize trait values.
- if (!mHasValue){
- mValue = as_value((as_object*)0); // NULL value, right ?
+ if (!_hasValue) {
+ _value = as_value((as_object*)0); // NULL value, right ?
}
- LOG_DEBUG_ABC("Adding property=%s with value=%s
slot=%u",pBlock->mStringPool[mName],mValue.toDebugString(),mSlotId);
- pClass->addValue(mGlobalName, mNamespace, mSlotId, pType,
- mValue, mKind == KIND_CONST, do_static);
+ log_abc("Adding property=%s with value=%s slot=%u",
pBlock->_stringPool[_name], _value.toDebugString(), _slotID);
+ pClass->addValue(_globalName, _namespace, _slotID, pType,
+ _value, _kind == KIND_CONST, do_static);
break;
}
case KIND_METHOD:
{
- pClass->addMethod(mGlobalName, mNamespace, mMethod, false);
+ pClass->addMethod(_globalName, _namespace, _method, false);
break;
}
case KIND_GETTER:
{
- LOG_DEBUG_ABC("Finalize getter not implemented.");
+ log_abc("Finalize getter not implemented.");
break;
- pClass->addGetter(mName, mNamespace, mMethod, do_static);
+ pClass->addGetter(_name, _namespace, _method, do_static);
break;
}
case KIND_SETTER:
{
- LOG_DEBUG_ABC("Finalize setter not implemented.");
+ log_abc("Finalize setter not implemented.");
break;
- pClass->addSetter(mName, mNamespace, mMethod, do_static);
+ pClass->addSetter(_name, _namespace, _method, do_static);
break;
}
case KIND_CLASS:
{
- LOG_DEBUG_ABC("Finalize class not implemented.");
+ log_abc("Finalize class not implemented.");
break;
- pClass->addMemberClass(mName, mNamespace, mSlotId,
- pBlock->mClasses[mClassInfoIndex], do_static);
+ pClass->addMemberClass(_name, _namespace, _slotID,
+ pBlock->_classes[_classInfoIndex], do_static);
break;
}
case KIND_FUNCTION:
{
- LOG_DEBUG_ABC("Finalize function not implemented.");
+ log_abc("Finalize function not implemented.");
break;
- pClass->addSlotFunction(mName, mNamespace, mSlotId, mMethod,
do_static);
+ pClass->addSlotFunction(_name, _namespace, _slotID, _method,
do_static);
break;
}
default:
@@ -115,67 +113,67 @@
bool
abc_Trait::finalize_mbody(abc_block *pBlock, asMethod *pMethod)
{
- LOG_DEBUG_ABC("Finalizing method");
- switch (mKind)
+ log_abc("Finalizing method");
+ switch (_kind)
{
case KIND_SLOT:
case KIND_CONST:
{
// Validate the type.
asClass *pType;
- if (mTypeIndex)
- pType =
pBlock->locateClass(pBlock->mMultinamePool[mTypeIndex]);
+ if (_typeIndex)
+ pType =
pBlock->locateClass(pBlock->_multinamePool[_typeIndex]);
else
pType = pBlock->mTheObject;
if (!pType)
{
- ERR((_("ABC: Finalizing trait yielded bad type for
slot.\n")));
+ log_error(_("ABC: Finalizing trait yielded bad type for
slot."));
return false;
}
// The name has been validated in read.
// TODO: Find a better way to initialize trait values.
- if (!mHasValue){
- mValue = as_value((as_object*)0); // NULL value, right ?
+ if (!_hasValue) {
+ _value = as_value((as_object*)0); // NULL value, right ?
}
- LOG_DEBUG_ABC("Adding property=%s with value=%s
slot=%u",pBlock->mStringPool[mName],mValue.toDebugString(),mSlotId);
- pMethod->addValue(mGlobalName, mNamespace, mSlotId, pType,
- mValue, mKind == KIND_CONST);
+ log_abc("Adding property=%s with value=%s slot=%u",
pBlock->_stringPool[_name], _value.toDebugString(), _slotID);
+ pMethod->addValue(_globalName, _namespace, _slotID, pType,
+ _value, _kind == KIND_CONST);
break;
}
case KIND_METHOD:
{
- LOG_DEBUG_ABC("Finalize method trait not implemented.
Returning");
+ log_abc("Finalize method trait not implemented. Returning");
break;
- pMethod->addMethod(mName, mNamespace, mMethod);
+ pMethod->addMethod(_name, _namespace, _method);
break;
}
case KIND_GETTER:
{
- LOG_DEBUG_ABC("Finalize getter trait not implemented.
Returning");
+ log_abc("Finalize getter trait not implemented. Returning");
break;
- pMethod->addGetter(mName, mNamespace, mMethod);
+ pMethod->addGetter(_name, _namespace, _method);
break;
}
case KIND_SETTER:
{
- LOG_DEBUG_ABC("Finalize setter trait not implemented.
Returning");
+ log_abc("Finalize setter trait not implemented. Returning");
break;
- pMethod->addSetter(mName, mNamespace, mMethod);
+ pMethod->addSetter(_name, _namespace, _method);
break;
}
case KIND_CLASS:
{
- LOG_DEBUG_ABC("Finalize class trait not implemented.
Returning");
+ log_abc("Finalize class trait not implemented. Returning");
break;
- pMethod->addMemberClass(mName, mNamespace, mSlotId,
- pBlock->mClasses[mClassInfoIndex]);
+ pMethod->addMemberClass(_name, _namespace, _slotID,
+ pBlock->_classes[_classInfoIndex]);
break;
}
case KIND_FUNCTION:
{
- LOG_DEBUG_ABC("Finalize function trait not implemented.
Returning");
+ log_abc("Finalize function trait not implemented. Returning");
break;
- pMethod->addSlotFunction(mName, mNamespace, mSlotId, mMethod);
+ pMethod->addSlotFunction(_name, _namespace, _slotID, _method);
break;
}
default:
@@ -191,42 +189,42 @@
abc_Trait::read(SWFStream* in, abc_block *pBlock)
{
boost::uint32_t name = in->read_V32();
- if (name >= pBlock->mMultinamePool.size())
- {
- ERR((_("ABC: Bad name for trait.\n")));
- return false;
- }
- if (!pBlock->mMultinamePool[name].isQName())
- {
- ERR((_("ABC: Trait name must be fully qualified.\n")));
- return false;
- }
- asName multiname = pBlock->mMultinamePool[name];
- mName = pBlock->mMultinamePool[name].getABCName();
- mGlobalName = pBlock->mMultinamePool[name].getGlobalName();
- mNamespace = pBlock->mMultinamePool[name].getNamespace();
+ if (name >= pBlock->_multinamePool.size())
+ {
+ log_error(_("ABC: Bad name for trait."));
+ return false;
+ }
+ if (!pBlock->_multinamePool[name].isQName())
+ {
+ log_error(_("ABC: Trait name must be fully qualified."));
+ return false;
+ }
+ asName multiname = pBlock->_multinamePool[name];
+ _name = pBlock->_multinamePool[name].getABCName();
+ _globalName = pBlock->_multinamePool[name].getGlobalName();
+ _namespace = pBlock->_multinamePool[name].getNamespace();
boost::uint8_t kind = in->read_u8();
- mKind = static_cast<kinds> (kind & 0x0F);
+ _kind = static_cast<Kind>(kind & 0x0F);
- LOG_DEBUG_ABC("Trai name=%s Trait kind is 0x%X",
pBlock->mStringPool[multiname.getABCName()],kind | 0x0);
- switch (mKind)
+ log_abc("Trai name=%s Trait kind is 0x%X",
pBlock->_stringPool[multiname.getABCName()], kind | 0x0);
+ switch (_kind)
{
case KIND_SLOT:
case KIND_CONST:
{
- mSlotId = in->read_V32();
- mTypeIndex = in->read_V32();
+ _slotID = in->read_V32();
+ _typeIndex = in->read_V32();
boost::uint32_t vindex = in->read_V32();
- LOG_DEBUG_ABC("Slot ID=%u Type=%s Pool
index=%u",mSlotId,pBlock->mStringPool[pBlock->mMultinamePool[mTypeIndex].getABCName()],vindex);
+ log_abc("Slot ID=%u Type=%s Pool index=%u", _slotID,
pBlock->_stringPool[pBlock->_multinamePool[_typeIndex].getABCName()], vindex);
if (vindex)
{
- if (!pBlock->pool_value(vindex, in->read_u8(), mValue))
+ if (!pBlock->pool_value(vindex, in->read_u8(), _value))
return false; // Message done by pool_value
- mHasValue = true;
+ _hasValue = true;
}
else
- mHasValue = false;
+ _hasValue = false;
break;
}
case KIND_METHOD:
@@ -236,43 +234,46 @@
// Ignore the 'disp_id'
in->skip_V32();
- boost::uint32_t moffset = in->read_V32();
- LOG_DEBUG_ABC("Method index=%u",moffset);
- if (moffset >= pBlock->mMethods.size())
+ boost::uint32_t offset = in->read_V32();
+ log_abc("Method index=%u", offset);
+ if (offset >= pBlock->_methods.size())
{
- ERR((_("Bad method id in trait.\n")));
+ log_error(_("Bad method id in trait."));
return false;
}
- mMethod = pBlock->mMethods[moffset];
+ _method = pBlock->_methods[offset];
break;
}
case KIND_CLASS:
{
- mSlotId = in->read_V32();
- mClassInfoIndex = in->read_V32();
- LOG_DEBUG_ABC("Slot id: %u Class index: %u Class Name:
%s",mSlotId,mClassInfoIndex,pBlock->mStringPool[pBlock->mClasses[mClassInfoIndex]->getName()]);
- if (mClassInfoIndex >= pBlock->mClasses.size())
- {
- ERR((_("Bad Class id in trait.\n")));
+ _slotID = in->read_V32();
+ _classInfoIndex = in->read_V32();
+ log_abc("Slot id: %u Class index: %u Class Name: %s", _slotID,
+ _classInfoIndex,
+ pBlock->_stringPool[pBlock->
+ _classes[_classInfoIndex]->getName()]);
+
+ if (_classInfoIndex >= pBlock->_classes.size()) {
+ log_error(_("Bad Class id in trait."));
return false;
}
break;
}
case KIND_FUNCTION:
{
- mSlotId = in->read_V32();
- boost::uint32_t moffset = in->read_V32();
- if (moffset >= pBlock->mMethods.size())
+ _slotID = in->read_V32();
+ boost::uint32_t offset = in->read_V32();
+ if (offset >= pBlock->_methods.size())
{
- ERR((_("Bad method id in trait.\n")));
+ log_error(_("Bad method id in trait."));
return false;
}
- mMethod = pBlock->mMethods[moffset];
+ _method = pBlock->_methods[offset];
break;
}
default:
{
- ERR((_("ABC: Unknown type of trait.\n")));
+ log_error(_("ABC: Unknown type of trait."));
// return false;
}
} // end of switch statement
@@ -289,54 +290,90 @@
return true;
}
-} // namespace abc_parsing
+} // abc_parsing
using namespace abc_parsing;
-void
-abc_block::check_multiname_name(boost::uint32_t name){
-
- if (name >= mStringPool.size()){
- throw ParserException("ABC: Out of bounds string for
Multiname.\n");
- }
-}
-
-void
-abc_block::check_multiname_namespace(boost::uint32_t ns){
- if (ns >= mNamespacePool.size()){
- throw ParserException("ABC: Out of bounds namespace for
Multiname.\n");
- }
-}
-
-void
-abc_block::check_multiname_namespaceset(boost::uint32_t nsset){
- if (!nsset){
- throw ParserException("ABC: 0 selection for namespace set is
invalid.\n");
- }
- if (nsset >= mNamespaceSetPool.size()){
- throw ParserException("ABC: Out of bounds namespace set for
Multiname.\n");
- }
-}
-
-void
-abc_block::setMultinameNames(asName *n,string_table::key ABCName){
+abc_block::abc_block()
+ :
+ _stringTable(&VM::get().getStringTable())
+{
+ mCH = VM::get().getClassHierarchy();
+ // TODO: Make this the real 'Object' prototype.
+ mCH->getGlobalNs()->stubPrototype(NSV::CLASS_OBJECT);
+ mTheObject = mCH->getGlobalNs()->getClass(NSV::CLASS_OBJECT);
+}
+
+void
+abc_block::prepare(Machine* mach)
+{
+ std::for_each(_classes.begin(), _classes.end(),
+ std::mem_fun(&asClass::initPrototype));
+
+ std::for_each(_scripts.begin(), _scripts.end(),
+ std::mem_fun(&asClass::initPrototype));
+
+ std::for_each(_methods.begin(), _methods.end(),
+ boost::bind(&asMethod::initPrototype, _1, mach));
+
+ std::for_each(_traits.begin(), _traits.end(),
+ boost::bind(&abc_Trait::finalize, _1, this));
+
+ _traits.clear();
+
+}
+
+void
+abc_block::check_multiname_name(boost::uint32_t name)
+{
+
+ if (name >= _stringPool.size()) {
+ throw ParserException("ABC: Out of bounds string for
Multiname.");
+ }
+}
+
+void
+abc_block::check_multiname_namespace(boost::uint32_t ns)
+{
+ if (ns >= _namespacePool.size()) {
+ throw ParserException("ABC: Out of bounds namespace for
Multiname.");
+ }
+}
+
+void
+abc_block::check_multiname_namespaceset(boost::uint32_t nsset)
+{
+ if (!nsset)
+ {
+ throw ParserException("ABC: 0 selection for namespace set is
invalid.");
+ }
+ if (nsset >= _namespaceSetPool.size())
+ {
+ throw ParserException("ABC: Out of bounds namespace set for
Multiname.");
+ }
+}
+
+void
+abc_block::setMultinameNames(asName *n, string_table::key ABCName)
+{
n->setABCName(ABCName);
- std::string name = mStringPool[ABCName];
- string_table::key global_key = mStringTable->find(name,true);
- LOG_DEBUG_ABC("Global key %u",global_key);
+ std::string name = _stringPool[ABCName];
+ string_table::key global_key = _stringTable->find(name, true);
+ log_abc("Global key %u", global_key);
n->setGlobalName(global_key);
- LOG_DEBUG_ABC("Multiname: %s ABCName set to %u global name set to
%u",name,n->getABCName(),n->getGlobalName());
+ log_abc("Multiname: %s ABCName set to %u global name set to %u", name,
n->getABCName(), n->getGlobalName());
}
void
-abc_block::setNamespaceURI(asNamespace *ns,string_table::key ABCName){
+abc_block::setNamespaceURI(asNamespace *ns, string_table::key ABCName)
+{
ns->setAbcURI(ABCName);
- std::string name = mStringPool[ABCName];
- string_table::key global_key = mStringTable->find(name,false);
+ std::string name = _stringPool[ABCName];
+ string_table::key global_key = _stringTable->find(name, false);
ns->setURI(global_key);
- LOG_DEBUG_ABC("Namespace: %s AbcURI=%u
URI=%u.",name,ABCName,global_key);
+ log_abc("Namespace: %s AbcURI=%u URI=%u.", name, ABCName, global_key);
}
asClass *
@@ -350,10 +387,10 @@
if (found)
return found;
}
- if (m.mNamespaceSet && !m.mNamespaceSet->empty())
+ if (m.namespaceSet() && !m.namespaceSet()->empty())
{
- std::vector<asNamespace*>::iterator i;
- for (i = m.mNamespaceSet->begin(); i != m.mNamespaceSet->end();
++i)
+ std::vector<asNamespace*>::const_iterator i;
+ for (i = m.namespaceSet()->begin(); i !=
m.namespaceSet()->end(); ++i)
{
found = (*i)->getClass(m.getABCName());
if (found)
@@ -388,8 +425,8 @@
{
// Minor version, major version.
mVersion = (mS->read_u16()) | (mS->read_u16() << 16);
- ERR((_("Abc Version: %d.%d\n"), (mVersion & 0xFFFF0000) >> 16,
- (mVersion & 0x0000FFFF)));
+ log_error(_("Abc Version: %d.%d"), (mVersion & 0xFFFF0000) >> 16,
+ (mVersion & 0x0000FFFF));
return true;
}
@@ -399,12 +436,12 @@
{
// count overestimates by 1.
boost::uint32_t count = mS->read_V32();
- mIntegerPool.resize(count);
+ _integerPool.resize(count);
if (count)
- mIntegerPool[0] = 0;
+ _integerPool[0] = 0;
for (unsigned int i = 1; i < count; ++i)
{
- mIntegerPool[i] = static_cast<boost::int32_t> (mS->read_V32());
+ _integerPool[i] = static_cast<boost::int32_t> (mS->read_V32());
}
return true;
}
@@ -415,12 +452,12 @@
{
// count overestimates by 1.
boost::uint32_t count = mS->read_V32();
- mUIntegerPool.resize(count);
+ _uIntegerPool.resize(count);
if (count)
- mUIntegerPool[0] = 0;
+ _uIntegerPool[0] = 0;
for (unsigned int i = 1; i < count; ++i)
{
- mUIntegerPool[i] = mS->read_V32();
+ _uIntegerPool[i] = mS->read_V32();
}
return true;
}
@@ -430,13 +467,13 @@
abc_block::read_double_constants()
{
boost::uint32_t count = mS->read_V32();
- mDoublePool.resize(count);
+ _doublePool.resize(count);
if (count)
- mDoublePool[0] = 0.0;
+ _doublePool[0] = 0.0;
for (unsigned int i = 1; i < count; ++i)
{
- mDoublePool[i] = mS->read_d64();
- LOG_DEBUG_ABC("Double %u=%lf",i,mDoublePool[i]);
+ _doublePool[i] = mS->read_d64();
+ log_abc("Double %u=%lf", i, _doublePool[i]);
}
return true;
}
@@ -445,69 +482,69 @@
bool
abc_block::read_string_constants()
{
- LOG_DEBUG_ABC("Begin reading string constants.");
+ log_abc("Begin reading string constants.");
boost::uint32_t count = mS->read_V32();
- LOG_DEBUG_ABC("There are %u string constants.",count);
- mStringPool.resize(count);
- mStringPoolTableIds.resize(count);
+ log_abc("There are %u string constants.", count);
+ _stringPool.resize(count);
+ _stringPoolTableIDs.resize(count);
if (count)
{
- mStringPool[0] = "";
- mStringPoolTableIds[0] = 0;
+ _stringPool[0] = "";
+ _stringPoolTableIDs[0] = 0;
}
for (unsigned int i = 1; i < count; ++i)
{
boost::uint32_t length = mS->read_V32();
- mS->read_string_with_length(length, mStringPool[i]);
- LOG_DEBUG_ABC("Adding string constant to string pool: index=%u
%s",i,mStringPool[i]);
- mStringPoolTableIds[i] = 0;
+ mS->read_string_with_length(length, _stringPool[i]);
+ log_abc("Adding string constant to string pool: index=%u %s",
i, _stringPool[i]);
+ _stringPoolTableIDs[i] = 0;
}
return true;
}
/// Read the pool of namespaces
-/// Any two namespaces with the same uri here are the same namespace,
+/// Any two namespaces with the same uri here are the same namespace,
/// excepting private namespaces.
bool
abc_block::read_namespaces()
{
- LOG_DEBUG_ABC("Begin reading namespaces.");
+ log_abc("Begin reading namespaces.");
boost::uint32_t count = mS->read_V32();
- LOG_DEBUG_ABC("There are %u namespaces.",count);
- mNamespacePool.resize(count);
+ log_abc("There are %u namespaces.", count);
+ _namespacePool.resize(count);
if (count)
{
- mNamespacePool[0] = mCH->getGlobalNs();
+ _namespacePool[0] = mCH->getGlobalNs();
}
for (unsigned int i = 1; i < count; ++i)
{
boost::uint8_t kind = mS->read_u8();
boost::uint32_t nameIndex = mS->read_V32();
- LOG_DEBUG_ABC("Namespace %u kind=0x%X index=%u name=%s",i,kind
| 0x0,nameIndex,mStringPool[nameIndex]);
+ log_abc("Namespace %u kind=0x%X index=%u name=%s", i, kind |
0x0, nameIndex, _stringPool[nameIndex]);
- if (nameIndex >= mStringPool.size())
+ if (nameIndex >= _stringPool.size())
{
- ERR((_("ABC: Out of bounds string given for
namespace.\n")));
+ log_error(_("ABC: Out of bounds string given for
namespace."));
return false;
}
if (kind == PRIVATE_NS)
{
- mNamespacePool[i] = mCH->anonNamespace(nameIndex);
- mNamespacePool[i]->setPrivate();
+ _namespacePool[i] = mCH->anonNamespace(nameIndex);
+ _namespacePool[i]->setPrivate();
}
else
{
asNamespace *n = mCH->findNamespace(nameIndex);
if (n == NULL)
n = mCH->addNamespace(nameIndex);
- mNamespacePool[i] = n;
+ _namespacePool[i] = n;
}
if (kind == PROTECTED_NS)
{
- mNamespacePool[i]->setProtected();
+ _namespacePool[i]->setProtected();
}
- setNamespaceURI(mNamespacePool[i],nameIndex);
+ setNamespaceURI(_namespacePool[i], nameIndex);
}
return true;
}
@@ -517,24 +554,24 @@
abc_block::read_namespace_sets()
{
boost::uint32_t count = mS->read_V32();
- mNamespaceSetPool.resize(count);
+ _namespaceSetPool.resize(count);
if (count)
{
- mNamespaceSetPool[0].resize(0);
+ _namespaceSetPool[0].resize(0);
}
for (unsigned int i = 1; i < count; ++i)
{
boost::uint32_t icount = mS->read_V32();
- mNamespaceSetPool[i].resize(icount);
+ _namespaceSetPool[i].resize(icount);
for (unsigned int j = 0; j < icount; ++j)
{
boost::uint32_t selection = mS->read_V32();
- if (!selection || selection >= mNamespacePool.size())
+ if (!selection || selection >= _namespacePool.size())
{
- ERR((_("ABC: Out of bounds namespace for
namespace set.\n")));
+ log_error(_("ABC: Out of bounds namespace for
namespace set."));
return false;
}
- mNamespaceSetPool[i][j] = mNamespacePool[selection];
+ _namespaceSetPool[i][j] = _namespacePool[selection];
}
}
return true;
@@ -545,22 +582,22 @@
abc_block::read_multinames()
{
boost::uint32_t count = mS->read_V32();
- LOG_DEBUG_ABC("There are %u multinames.",count);
- mMultinamePool.resize(count);
+ log_abc("There are %u multinames.", count);
+ _multinamePool.resize(count);
if (count)
{
-// mMultinamePool[0].setABCName(0);
- setMultinameNames(&mMultinamePool[0],0);
- mMultinamePool[0].setNamespace(mCH->getGlobalNs());
+// _multinamePool[0].setABCName(0);
+ setMultinameNames(&_multinamePool[0], 0);
+ _multinamePool[0].setNamespace(mCH->getGlobalNs());
}
for (unsigned int i = 1; i < count; ++i)
{
- boost::uint8_t kind = mS->read_u8();
+ asName::Kind kind = static_cast<asName::Kind>(mS->read_u8());
boost::uint32_t ns = 0;
boost::uint32_t name = 0;
boost::uint32_t nsset = 0;
- LOG_DEBUG_ABC("Multiname %u has kind=0x%X",i,kind | 0x0);
+ log_abc("Multiname %u has kind=0x%X", i, kind | 0x0);
// Read, but don't upper validate until after the switch.
switch (kind)
@@ -572,7 +609,7 @@
check_multiname_namespace(ns);
name = mS->read_V32();
check_multiname_name(name);
- LOG_DEBUG_ABC("\tnamespace_index=%u name_index=%u
name=%s",ns,name,mStringPool[name]);
+ log_abc("\tnamespace_index=%u name_index=%u name=%s", ns, name,
_stringPool[name]);
break;
}
case asName::KIND_RTQname:
@@ -607,18 +644,22 @@
default:
{
// Unknown type.
- ERR((_("Action Block: Unknown multiname type (%d).\n"), kind));
+ log_error(_("Action Block: Unknown multiname type (%d)."), kind);
return false;
} // End of cases.
} // End of switch.
- mMultinamePool[i].mFlags = kind;
- setMultinameNames(&mMultinamePool[i],name);
- LOG_DEBUG_ABC("Done setting multinames: abc=%u
global=%u",mMultinamePool[i].getABCName(),mMultinamePool[i].getGlobalName());
- mMultinamePool[i].setNamespace(mNamespacePool[ns]);
-
- if (nsset)
- mMultinamePool[i].mNamespaceSet =
&mNamespaceSetPool[nsset];
+ _multinamePool[i].setFlags(kind);
+ setMultinameNames(&_multinamePool[i], name);
+ log_abc("Done setting multinames: abc=%u global=%u",
+ _multinamePool[i].getABCName(),
+ _multinamePool[i].getGlobalName());
+
+ _multinamePool[i].setNamespace(_namespacePool[ns]);
+
+ if (nsset) {
+
_multinamePool[i].namespaceSet(&_namespaceSetPool[nsset]);
+ }
} // End of main loop.
return true;
}
@@ -629,54 +670,54 @@
if (!index)
return true;
- LOG_DEBUG_ABC("Pool value: index is %u type is 0x%X",index,type | 0x0);
+ log_abc("Pool value: index is %u type is 0x%X", index, type | 0x0);
switch (type)
{
case POOL_STRING:
{
- if (index >= mStringPool.size())
+ if (index >= _stringPool.size())
{
- ERR((_("Action Block: Bad index in optional
argument.\n")));
+ log_error(_("Action Block: Bad index in optional
argument."));
return false;
}
- v.set_string(mStringPool[index]);
+ v.set_string(_stringPool[index]);
break;
}
case POOL_INTEGER:
{
- if (index >= mIntegerPool.size())
+ if (index >= _integerPool.size())
{
- ERR((_("Action Block: Bad index in optional
argument.\n")));
+ log_error(_("Action Block: Bad index in optional
argument."));
return false;
}
- v.set_int(mIntegerPool[index]);
+ v.set_int(_integerPool[index]);
break;
}
case POOL_UINTEGER:
{
- if (index >= mUIntegerPool.size())
+ if (index >= _uIntegerPool.size())
{
- ERR((_("Action Block: Bad index in optional
argument.\n")));
+ log_error(_("Action Block: Bad index in optional
argument."));
return false;
}
- v.set_int(mUIntegerPool[index]);
+ v.set_int(_uIntegerPool[index]);
break;
}
case POOL_DOUBLE:
{
- if (index >= mDoublePool.size())
+ if (index >= _doublePool.size())
{
- ERR((_("Action Block: Bad index in optional
argument.\n")));
+ log_error(_("Action Block: Bad index in optional
argument."));
return false;
}
- v.set_double(static_cast<double>(mDoublePool[index]));
+ v.set_double(static_cast<double>(_doublePool[index]));
break;
}
case POOL_NAMESPACE: // Namespace
{
- if (index >= mNamespacePool.size())
+ if (index >= _namespacePool.size())
{
- ERR((_("ABC: Bad index in optional argument,
namespaces.\n")));
+ log_error(_("ABC: Bad index in optional argument,
namespaces."));
return false;
}
break;
@@ -698,7 +739,7 @@
}
default: // All others are bogus.
{
- ERR((_("ABC: Bad default value type (%X), but continuing.\n"),
type));
+ log_error(_("ABC: Bad default value type (%X), but
continuing."), type);
return true;
break;
}
@@ -710,35 +751,35 @@
bool
abc_block::read_method_infos()
{
- LOG_DEBUG_ABC("Begin read_method_infos.\n");
+ log_abc("Begin read_method_infos.");
boost::uint32_t count = mS->read_V32();
- LOG_DEBUG_ABC("Method count: %u", count);
+ log_abc("Method count: %u", count);
- mMethods.resize(count);
+ _methods.resize(count);
for (unsigned int i = 0; i < count; ++i)
{
- LOG_DEBUG_ABC(" Reading method %u",i);
+ log_abc(" Reading method %u", i);
asMethod *pMethod = mCH->newMethod();
- pMethod->mMethodID = i;
-// LOG_DEBUG_ABC("Min arg count: %d max:
%d",pMethod->minArgumentCount(),pMethod->maxArgumentCount());
- mMethods[i] = pMethod;
+ pMethod->setMethodID(i);
+// log_abc("Min arg count: %d max: %d",
pMethod->minArgumentCount(), pMethod->maxArgumentCount());
+ _methods[i] = pMethod;
boost::uint32_t param_count = mS->read_V32();
boost::uint32_t return_type = mS->read_V32();
- LOG_DEBUG_ABC(" Param count: %u return type(index):
%s(%u)",param_count,mStringPool[mMultinamePool[return_type].getABCName()],return_type);
+ log_abc(" Param count: %u return type(index): %s(%u)",
param_count, _stringPool[_multinamePool[return_type].getABCName()],
return_type);
pMethod->setMinArgumentCount(param_count);
pMethod->setMaxArgumentCount(param_count);
- if (return_type >= mMultinamePool.size())
+ if (return_type >= _multinamePool.size())
{
- ERR((_("ABC: Out of bounds return type for method
info.\n")));
+ log_error(_("ABC: Out of bounds return type for method
info."));
return false;
}
- asClass *rtClass = locateClass(mMultinamePool[return_type]);
+ asClass *rtClass = locateClass(_multinamePool[return_type]);
if (!rtClass)
{
- ERR((_("ABC: Unknown return type.\n")));
+ log_error(_("ABC: Unknown return type."));
return false;
}
@@ -746,55 +787,55 @@
for (unsigned int j = 0; j < param_count; ++j)
{
- LOG_DEBUG_ABC(" Reading parameter %u",j);
+ log_abc(" Reading parameter %u", j);
// The parameter type.
boost::uint32_t ptype = mS->read_V32();
- LOG_DEBUG_ABC(" Parameter type(index):
%s(%u)",mStringPool[mMultinamePool[ptype].getABCName()],ptype);
- if (ptype >= mMultinamePool.size())
+ log_abc(" Parameter type(index): %s(%u)",
_stringPool[_multinamePool[ptype].getABCName()], ptype);
+ if (ptype >= _multinamePool.size())
{
- ERR((_("ABC: Out of bounds parameter type in
method.\n")));
+ log_error(_("ABC: Out of bounds parameter type
in method."));
return false;
}
- asClass *param_type =
locateClass(mMultinamePool[ptype]);
-// LOG_DEBUG_ABC("Done creating asClass object.\n");
+ asClass *param_type =
locateClass(_multinamePool[ptype]);
+// log_abc("Done creating asClass object.");
if (!param_type)
{
- ERR((_("ABC: Unknown parameter type.\n")));
+ log_error((_("ABC: Unknown parameter type.")));
return false;
}
-// LOG_DEBUG_ABC("Trying to add argument to method.\n");
+// log_abc("Trying to add argument to method.");
pMethod->pushArgument(param_type);
-// LOG_DEBUG_ABC("Done adding argument to method object.");
+// log_abc("Done adding argument to method object.");
}
-// LOG_DEBUG_ABC("End loop j.\n");
+// log_abc("End loop j.");
// A skippable name index.
// mS->skip_V32();
boost::uint32_t method_name = mS->read_V32();
- LOG_DEBUG_ABC( "Method name=%s
%d",mStringPool[method_name],method_name);
+ log_abc( "Method name=%s %d", _stringPool[method_name],
method_name);
boost::uint8_t flags = mS->read_u8();
- LOG_DEBUG_ABC(" Flags: %X",flags | 0x0);
-// LOG_DEBUG_ABC("Check if flags and optional args.");
+ log_abc(" Flags: %X", flags | 0x0);
+// log_abc("Check if flags and optional args.");
// If there are default parameters, read them now.
// Runtime will do validation of whether or not these can
actually
// be assigned to the corresponding parameters.
if (flags & METHOD_OPTIONAL_ARGS)
{
-// LOG_DEBUG_ABC("We have flags and optional args.");
+// log_abc("We have flags and optional args.");
boost::uint32_t ocount = mS->read_V32();
- LOG_DEBUG_ABC(" Optional args: %u",ocount);
+ log_abc(" Optional args: %u", ocount);
pMethod->setMinArgumentCount(pMethod->maxArgumentCount() - ocount);
for (unsigned int j = 0; j < ocount; ++j)
{
- LOG_DEBUG_ABC(" Reading optional arg: %u",j);
+ log_abc(" Reading optional arg: %u", j);
boost::uint32_t index = mS->read_V32();
boost::uint8_t kindof = mS->read_u8();
- LOG_DEBUG_ABC(" Index: %u Kindof:
%u",index,kindof);
+ log_abc(" Index: %u Kindof: %u", index,
kindof);
as_value v;
if (!pool_value(index, kindof, v))
return false; // message done by
pool_value
pMethod->pushOptional(v);
}
- LOG_DEBUG_ABC("Done handling optional args.");
+ log_abc("Done handling optional args.");
}
// If there are names present for the parameters, skip them.
@@ -833,47 +874,47 @@
abc_block::read_instances()
{
boost::uint32_t count = mS->read_V32();
- LOG_DEBUG_ABC("There are %u instances.",count);
- mClasses.resize(count);
+ log_abc("There are %u instances.", count);
+ _classes.resize(count);
for (unsigned int i = 0; i < count; ++i)
{
asClass *pClass;
//Read multiname index.
boost::uint32_t index = mS->read_V32();
// 0 is allowed as a name, typically for the last entry.
- if (index >= mMultinamePool.size())
+ if (index >= _multinamePool.size())
{
- ERR((_("ABC: Out of bounds instance name.\n")));
+ log_error(_("ABC: Out of bounds instance name."));
return false;
}
// This must be a QName.
- if (!mMultinamePool[index].isQName())
- {
- ERR((_("ABC: QName required for instance.\n")));
- return false;
- }
- if (mMultinamePool[index].getNamespace() == NULL)
- {
- ERR((_("ABC: No namespace to use for storing
class.\n")));
- return false;
- }
- pClass = locateClass(mMultinamePool[index]);
+ if (!_multinamePool[index].isQName())
+ {
+ log_error(_("ABC: QName required for instance."));
+ return false;
+ }
+ if (_multinamePool[index].getNamespace() == NULL)
+ {
+ log_error(_("ABC: No namespace to use for storing
class."));
+ return false;
+ }
+ pClass = locateClass(_multinamePool[index]);
if (!pClass)
{
pClass = mCH->newClass();
- if (!mMultinamePool[index].getNamespace()->addClass(
- mMultinamePool[index].getABCName(), pClass))
+ if (!_multinamePool[index].getNamespace()->addClass(
+ _multinamePool[index].getABCName(), pClass))
{
- ERR((_("Duplicate class registration.\n")));
+ log_error(_("Duplicate class registration."));
return false;
}
}
pClass->setDeclared();
- mClasses[i] = pClass;
+ _classes[i] = pClass;
boost::uint32_t super_index = mS->read_V32();;
- if (super_index && super_index >= mMultinamePool.size())
+ if (super_index && super_index >= _multinamePool.size())
{
- ERR((_("ABC: Out of bounds super type.\n")));
+ log_error(_("ABC: Out of bounds super type."));
return false;
}
if (!super_index)
@@ -882,33 +923,33 @@
}
else
{
- asClass *pSuper =
locateClass(mMultinamePool[super_index]);
+ asClass *pSuper =
locateClass(_multinamePool[super_index]);
if (!pSuper)
{
- ERR((_("ABC: Super type not found (%s),
faking.\n"),
-
mStringTable->value(mMultinamePool[super_index].getABCName()).c_str()));
+ log_error(_("ABC: Super type not found (%s),
faking."),
+
_stringTable->value(_multinamePool[super_index].getABCName()));
// While testing, we will add a fake type,
rather than abort.
pSuper = mCH->newClass();
-
pSuper->setName(mMultinamePool[super_index].getABCName());
-
mCH->getGlobalNs()->addClass(mMultinamePool[super_index].getABCName(), pSuper);
+
pSuper->setName(_multinamePool[super_index].getABCName());
+
mCH->getGlobalNs()->addClass(_multinamePool[super_index].getABCName(), pSuper);
// return false;
}
if (pSuper->isFinal())
{
- ERR((_("ABC: Can't extend a class which is
final.\n")));
+ log_error(_("ABC: Can't extend a class which is
final."));
return false;
}
if (pSuper->isInterface())
{
- ERR((_("ABC: Can't extend an interface
type.\n")));
+ log_error(_("ABC: Can't extend an interface
type."));
return false;
}
if (pSuper == pClass)
{
- ERR((_("ABC: Class cannot be its own
supertype.\n")));
+ log_error(_("ABC: Class cannot be its own
supertype."));
return false;
}
pClass->setSuper(pSuper);
@@ -916,7 +957,7 @@
}
boost::uint8_t flags = mS->read_u8();
- LOG_DEBUG_ABC("Instance %u multiname index=%u name=%s super
index=%u
flags=%X",i,index,mStringPool[mMultinamePool[index].getABCName()],super_index,flags
| 0x0);
+ log_abc("Instance %u multiname index=%u name=%s super index=%u
flags=%X", i, index, _stringPool[_multinamePool[index].getABCName()],
super_index, flags | 0x0);
if (flags & INSTANCE_SEALED)
pClass->setSealed();
@@ -930,36 +971,36 @@
if (flags & INSTANCE_PROTECTED_NS) // Protected Namespace
{
boost::uint32_t ns_index = mS->read_V32();
- if (ns_index >= mNamespacePool.size())
+ if (ns_index >= _namespacePool.size())
{
- ERR((_("ABC: Out of bounds namespace for
protected.\n")));
+ log_error(_("ABC: Out of bounds namespace for
protected."));
return false;
}
// Set the protected namespace's parent, if it exists.
if (pClass->getSuper()->hasProtectedNs())
-
mNamespacePool[ns_index]->setParent(pClass->getSuper()->getProtectedNs());
- pClass->setProtectedNs(mNamespacePool[ns_index]);
+
_namespacePool[ns_index]->setParent(pClass->getSuper()->getProtectedNs());
+ pClass->setProtectedNs(_namespacePool[ns_index]);
}
// This is the list of interfaces which the instances has
agreed to
// implement. They must be interfaces, and they must exist.
boost::uint32_t intcount = mS->read_V32();
- LOG_DEBUG_ABC("This instance has %u interfaces.",intcount);
+ log_abc("This instance has %u interfaces.", intcount);
for (unsigned int j = 0; j < intcount; ++j)
{
boost::uint32_t i_index = mS->read_V32();
- LOG_DEBUG_ABC("Interface %u has multiname
index=%u",i,i_index);
+ log_abc("Interface %u has multiname index=%u", i,
i_index);
// 0 is allowed as an interface, typically for the last
one.
- if (i_index >= mMultinamePool.size())
+ if (i_index >= _multinamePool.size())
{
- ERR((_("ABC: Out of bounds name for
interface.\n")));
+ log_error(_("ABC: Out of bounds name for
interface."));
return false;
}
- asClass *pInterface =
locateClass(mMultinamePool[i_index]);
+ asClass *pInterface =
locateClass(_multinamePool[i_index]);
// These may be undefined still, so don't check
interface just yet.
if (0) //!pInterface || !pInterface->isInterface())
{
- ERR((_("ABC: Can't implement a non-interface
type.\n")));
+ log_error(_("ABC: Can't implement a
non-interface type."));
return false;
}
pClass->pushInterface(pInterface);
@@ -967,24 +1008,24 @@
// The next thing should be the constructor.
// TODO: What does this mean exactly? How does it differ from
the one in
// the class info block?
- boost::uint32_t moffset = mS->read_V32();
- LOG_DEBUG_ABC("Moffset: %u",moffset);
- if (moffset >= mMethods.size())
+ boost::uint32_t offset = mS->read_V32();
+ log_abc("Moffset: %u", offset);
+ if (offset >= _methods.size())
{
- ERR((_("ABC: Out of bounds method for
initializer.\n")));
+ log_error(_("ABC: Out of bounds method for
initializer."));
return false;
}
// Don't validate for previous owner.
- pClass->setConstructor(mMethods[moffset]);
+ pClass->setConstructor(_methods[offset]);
/* Calling the asMethod::setOwner always results in a
segmentation fault,
since it tries to modify asMethod.mPrototype, which is never
initialized. The parser seems to work ok without this call.*/
-// mMethods[moffset]->setOwner(pClass);
+// _methods[offset]->setOwner(pClass);
// Next come the 'traits' of the instance. (The members.)
boost::uint32_t tcount = mS->read_V32();
- LOG_DEBUG_ABC("Trait count: %u",tcount);
+ log_abc("Trait count: %u", tcount);
for (unsigned int j = 0; j < tcount; ++j)
{
abc_Trait &aTrait = newTrait();
@@ -1001,29 +1042,29 @@
abc_block::read_classes()
{
// Count was found in read_instances().
- LOG_DEBUG_ABC("Begin reading classes.");
- boost::uint32_t count = mClasses.size();
- LOG_DEBUG_ABC("There are %u classes.",count);
+ log_abc("Begin reading classes.");
+ boost::uint32_t count = _classes.size();
+ log_abc("There are %u classes.", count);
for (unsigned int i = 0; i < count; ++i)
{
- asClass *pClass = mClasses[i];
- boost::uint32_t moffset = mS->read_V32();
- LOG_DEBUG_ABC("Class %u static constructor index=%u",i,moffset);
- if (moffset >= mMethods.size())
+ asClass *pClass = _classes[i];
+ boost::uint32_t offset = mS->read_V32();
+ log_abc("Class %u static constructor index=%u", i, offset);
+ if (offset >= _methods.size())
{
- ERR((_("ABC: Out of bound static constructor for
class.\n")));
+ log_error(_("ABC: Out of bound static constructor for
class."));
return false;
}
// Don't validate for previous owner.
- pClass->setStaticConstructor(mMethods[moffset]);
+ pClass->setStaticConstructor(_methods[offset]);
/* Calling the asMethod::setOwner always results in a
segmentation fault,
since it tries to modify asMethod.mPrototype, which is never
initialized. The parser seems to work ok without this call.*/
-// mMethods[moffset]->setOwner(pClass);
+// _methods[offset]->setOwner(pClass);
boost::uint32_t tcount = mS->read_V32();
- LOG_DEBUG_ABC("This class has %u traits.",tcount);
+ log_abc("This class has %u traits.", tcount);
for (unsigned int j = 0; j < tcount; ++j)
{
abc_Trait &aTrait = newTrait();
@@ -1040,30 +1081,30 @@
bool
abc_block::read_scripts()
{
- LOG_DEBUG_ABC("Begin reading scripts.");
+ log_abc("Begin reading scripts.");
boost::uint32_t count = mS->read_V32();
- LOG_DEBUG_ABC("There are %u scripts.",count);
- mScripts.resize(count);
+ log_abc("There are %u scripts.", count);
+ _scripts.resize(count);
for (unsigned int i = 0; i < count; ++i)
{
asClass *pScript = mCH->newClass();
- mScripts[i] = pScript;
+ _scripts[i] = pScript;
- boost::uint32_t moffset = mS->read_V32();
- LOG_DEBUG_ABC("Reading script %u initializer method
index=%u",i,moffset);
- if (moffset >= mMethods.size())
+ boost::uint32_t offset = mS->read_V32();
+ log_abc("Reading script %u initializer method index=%u", i,
offset);
+ if (offset >= _methods.size())
{
- ERR((_("ABC: Out of bounds method for script.\n")));
+ log_error(_("ABC: Out of bounds method for script."));
return false;
}
- /*Calling the asMethod::setOwner always results in a
segmentation fault,
- since it tries to modify asMethod.mPrototype, which is never
- initialized. The parser seems to work ok without this call.*/
+ // Calling the asMethod::setOwner always results in a
segmentation
+ // fault, since it tries to modify asMethod.mPrototype, which is never
+ // initialized. The parser seems to work ok without this call.
// Don't validate for previous owner.
-// mMethods[moffset]->setOwner(pScript);
+// _methods[offset]->setOwner(pScript);
- pScript->setConstructor(mMethods[moffset]);
+ pScript->setConstructor(_methods[offset]);
pScript->setSuper(mTheObject);
boost::uint32_t tcount = mS->read_V32();
@@ -1072,10 +1113,14 @@
abc_Trait &aTrait = newTrait();
aTrait.set_target(pScript, false);
- if (!(aTrait.read(mS, this)))
+ if (!(aTrait.read(mS, this))) {
return false;
- LOG_DEBUG_ABC("Trait: %u name: %s(%u) kind: %u value:
%s
",j,mStringPool[aTrait.mName],aTrait.mName,aTrait.mKind,aTrait.mValue.to_string());
- pScript->mTraits.push_back(aTrait);
+ }
+ log_abc("Trait: %u name: %s(%u) kind: %u value: %s ",
j,
+ _stringPool[aTrait._name], aTrait._name, aTrait._kind,
+ aTrait._value.to_string());
+
+ pScript->_traits.push_back(aTrait);
}
} // end of scripts loop
return true;
@@ -1086,19 +1131,19 @@
abc_block::read_method_bodies()
{
boost::uint32_t count = mS->read_V32();
- LOG_DEBUG_ABC("There are %u method bodies.",count);
+ log_abc("There are %u method bodies.", count);
for (unsigned int i = 0; i < count; ++i)
{
- boost::uint32_t moffset = mS->read_V32();
- LOG_DEBUG_ABC("Method body %u method offset=%u",i,moffset);
- if (moffset >= mMethods.size())
+ boost::uint32_t offset = mS->read_V32();
+ log_abc("Method body %u method offset=%u", i, offset);
+ if (offset >= _methods.size())
{
- ERR((_("ABC: Out of bounds for method body.\n")));
+ log_error(_("ABC: Out of bounds for method body."));
return false;
}
- if (mMethods[moffset]->getBody())
+ if (_methods[offset]->getBody())
{
- ERR((_("ABC: Only one body per method.\n")));
+ log_error(_("ABC: Only one body per method."));
return false;
}
//TODO: Read values.
@@ -1106,20 +1151,20 @@
// Maximum stack size.
mS->skip_V32();
// Maximum register size.
- mMethods[moffset]->setMaxRegisters(mS->read_V32());
+ _methods[offset]->setMaxRegisters(mS->read_V32());
// Scope depth.
mS->skip_V32();
// Max scope depth.
mS->skip_V32();
// Code length
boost::uint32_t clength = mS->read_V32();
- mMethods[moffset]->setBodyLength(clength);
+ _methods[offset]->setBodyLength(clength);
// The code.
//TODO: Clean this up.
std::string body;
- mS->read_string_with_length(clength,body);
+ mS->read_string_with_length(clength, body);
- mMethods[moffset]->setBody(new CodeStream(body));
+ _methods[offset]->setBody(new CodeStream(body));
boost::uint32_t ecount = mS->read_V32();
for (unsigned int j = 0; j < ecount; ++j)
@@ -1135,9 +1180,9 @@
// What types should be caught.
boost::uint32_t catch_type = mS->read_V32();
- if (catch_type >= mMultinamePool.size())
+ if (catch_type >= _multinamePool.size())
{
- ERR((_("ABC: Out of bound type for
exception.\n")));
+ log_error(_("ABC: Out of bound type for
exception."));
// return false;
}
if (!catch_type)
@@ -1146,11 +1191,11 @@
}
else
{
- asClass *pType =
locateClass(mMultinamePool[catch_type]);
+ asClass *pType =
locateClass(_multinamePool[catch_type]);
if (!pType)
{
- ERR((_("ABC: Unknown type of object to
catch. (%s)\n"),
-
mStringTable->value(mMultinamePool[catch_type].getABCName()).c_str()));
+ log_error(_("ABC: Unknown type of
object to catch. (%s)"),
+
_stringTable->value(_multinamePool[catch_type].getABCName()));
// return false;
// Fake it, for now:
pExcept->catchAny();
@@ -1166,13 +1211,13 @@
if (mVersion != ((46 << 16) | 15))
{
boost::uint32_t cvn = mS->read_V32();
- if (cvn >= mMultinamePool.size())
+ if (cvn >= _multinamePool.size())
{
- ERR((_("ABC: Out of bound name for
caught exception.\n")));
+ log_error(_("ABC: Out of bound name for
caught exception."));
// return false;
}
-
pExcept->setName(mMultinamePool[cvn].getABCName());
-
pExcept->setNamespace(mMultinamePool[cvn].getNamespace());
+
pExcept->setName(_multinamePool[cvn].getABCName());
+
pExcept->setNamespace(_multinamePool[cvn].getNamespace());
}
} // end of exceptions
@@ -1180,10 +1225,14 @@
for (unsigned int j = 0; j < tcount; ++j)
{
abc_Trait &aTrait = newTrait();
- aTrait.set_target(mMethods[moffset]);
- if (!aTrait.read(mS, this)) // TODO: 'method body
activation traits'
+ aTrait.set_target(_methods[offset]);
+ if (!aTrait.read(mS, this)) {
+ // TODO: 'method body activation traits'
return false;
- LOG_DEBUG_ABC("Trait: %u name: %s kind: %u value: %s
",j,mStringPool[aTrait.mName],aTrait.mKind,aTrait.mValue.to_string());
+ }
+ log_abc("Trait: %u name: %s kind: %u value: %s ", j,
+ _stringPool[aTrait._name], aTrait._kind,
+ aTrait._value.to_string());
}
} // end of bodies loop
return true;
@@ -1199,33 +1248,33 @@
if (!read_version()) return false;
if (!read_integer_constants()) return false;
if (!read_unsigned_integer_constants()) return false;
- LOG_DEBUG_ABC("Done reading unsigned integer constants.\n");
+ log_abc("Done reading unsigned integer constants.");
if (!read_double_constants()) return false;
- LOG_DEBUG_ABC("Done reading double constants.\n");
+ log_abc("Done reading double constants.");
if (!read_string_constants()) return false;
- LOG_DEBUG_ABC("Done reading string constants.\n");
+ log_abc("Done reading string constants.");
if (!read_namespaces()) return false;
- LOG_DEBUG_ABC("Done reading namespaces.\n");
+ log_abc("Done reading namespaces.");
if (!read_namespace_sets()) return false;
- LOG_DEBUG_ABC("Done reading namespace sets.\n");
+ log_abc("Done reading namespace sets.");
if (!read_multinames()) return false;
- LOG_DEBUG_ABC("Done reading multinames.\n");
+ log_abc("Done reading multinames.");
if (!read_method_infos()) return false;
- LOG_DEBUG_ABC("Done reading method infos.\n");
+ log_abc("Done reading method infos.");
if (!skip_metadata()) return false;
- LOG_DEBUG_ABC("Done reading metadata.\n");
+ log_abc("Done reading metadata.");
if (!read_instances()) return false;
- LOG_DEBUG_ABC("Done reading instances.\n");
+ log_abc("Done reading instances.");
if (!read_classes()) return false;
- LOG_DEBUG_ABC("Done reading classes.\n");
+ log_abc("Done reading classes.");
if (!read_scripts()) return false;
- LOG_DEBUG_ABC("Done reading scripts.\n");
+ log_abc("Done reading scripts.");
if (!read_method_bodies()) return false;
- LOG_DEBUG_ABC("Done reading stuff.\n");
+ log_abc("Done reading stuff.");
- for(unsigned int i=0;i<mMethods.size();i++){
- LOG_DEBUG_ABC("Method %d body:",i);
- IF_VERBOSE_PARSE(mMethods[i]->print_body());
+ for(unsigned int i=0;i<_methods.size();i++) {
+ log_abc("Method %d body:", i);
+ IF_VERBOSE_PARSE(_methods[i]->print_body());
}
/* The loop below causes a segmentation fault, because it tries to modify
asMethod.mPrototype, which is never initialized. The parser seems
@@ -1242,31 +1291,28 @@
return true;
}
-asClass *abc_block::locateClass(const std::string& className){
+asClass*
+abc_block::locateClass(const std::string& className)
+{
- std::vector<asClass*>::iterator i = mClasses.begin();
- for( ; i!=mClasses.end(); ++i){
- if(mStringPool[(*i)->getName()].compare(className) == 0){
+ std::vector<asClass*>::iterator i = _classes.begin();
+ for( ; i!=_classes.end(); ++i) {
+ if (_stringPool[(*i)->getName()] == className) {
return *i;
}
}
return NULL;
}
-void abc_block::update_global_name(unsigned int multiname_index){
+void
+abc_block::update_global_name(unsigned int multiname_index)
+{
- asName* multiname = &mMultinamePool[multiname_index];
- string_table::key new_key =
mStringTable->find(mStringPool[multiname->getABCName()],false);
+ asName* multiname = &_multinamePool[multiname_index];
+ string_table::key new_key =
+ _stringTable->find(_stringPool[multiname->getABCName()], false);
multiname->setGlobalName(new_key);
}
-abc_block::abc_block() : mStringTable(&VM::get().getStringTable())
-{
- mCH = VM::get().getClassHierarchy();
- // TODO: Make this the real 'Object' prototype.
- mCH->getGlobalNs()->stubPrototype(NSV::CLASS_OBJECT);
- mTheObject = mCH->getGlobalNs()->getClass(NSV::CLASS_OBJECT);
-}
-
} /* namespace gnash */
=== modified file 'libcore/parser/abc_block.h'
--- a/libcore/parser/abc_block.h 2009-03-04 20:30:04 +0000
+++ b/libcore/parser/abc_block.h 2009-03-25 11:02:48 +0000
@@ -29,8 +29,6 @@
#include "asClass.h"
#include "asName.h"
-#define LOG_DEBUG_ABC(fmt,...) IF_VERBOSE_PARSE(log_parse("ABC Parser: " fmt,
## __VA_ARGS__));
-
namespace gnash {
class SWFStream; // for read signature
}
@@ -51,7 +49,8 @@
class abc_Trait
{
public:
- typedef enum
+
+ enum Kind
{
KIND_SLOT = 0,
KIND_CONST = 6,
@@ -60,59 +59,64 @@
KIND_SETTER = 3,
KIND_CLASS = 4,
KIND_FUNCTION = 5
- } kinds;
-
- bool mHasValue;
- kinds mKind;
- boost::uint32_t mSlotId;
- boost::uint32_t mTypeIndex;
- boost::uint32_t mClassInfoIndex;
- as_value mValue;
- string_table::key mName;
- string_table::key mGlobalName;
- asNamespace *mNamespace;
- asMethod *mMethod;
- bool mValueSet;
-
- asClass *mCTarget;
- asMethod *mMTarget;
- bool mStatic;
+ };
+
+ bool _hasValue;
+ Kind _kind;
+ boost::uint32_t _slotID;
+ boost::uint32_t _typeIndex;
+ boost::uint32_t _classInfoIndex;
+ as_value _value;
+ string_table::key _name;
+ string_table::key _globalName;
+ asNamespace* _namespace;
+ asMethod* _method;
+ bool _valueSet;
+
+ asClass* _classTarget;
+ asMethod* _methodTarget;
+ bool _static;
abc_Trait()
:
- mHasValue(false),
- mKind(KIND_SLOT),
- mSlotId(0),
- mTypeIndex(0),
- mClassInfoIndex(0),
- mValue(),
- mName(0),
- mGlobalName(),
- mNamespace(0),
- mMethod(0),
- mValueSet(false),
- mCTarget(0),
- mMTarget(0),
- mStatic(false)
- {/**/}
+ _hasValue(false),
+ _kind(KIND_SLOT),
+ _slotID(0),
+ _typeIndex(0),
+ _classInfoIndex(0),
+ _value(),
+ _name(0),
+ _globalName(),
+ _namespace(0),
+ _method(0),
+ _valueSet(false),
+ _classTarget(0),
+ _methodTarget(0),
+ _static(false)
+ {}
bool read(SWFStream* in, abc_block *pBlock);
- bool finalize(abc_block *pBlock, asClass *pClass, bool do_static);
-
- bool finalize_mbody(abc_block *pBlock, asMethod *pMethod);
-
- void set_target(asClass *pClass, bool do_static)
- { mCTarget = pClass; mStatic = do_static; }
-
- void set_target(asMethod *pMethod)
- { mCTarget = 0; mMTarget = pMethod; }
-
- bool finalize(abc_block *pBlock)
+ bool finalize(abc_block* pBlock, asClass* pClass, bool do_static);
+
+ bool finalize_mbody(abc_block* pBlock, asMethod* pMethod);
+
+ void set_target(asClass* pClass, bool do_static) {
+ _classTarget = pClass;
+ _static = do_static;
+ }
+
+ void set_target(asMethod *pMethod) {
+ _classTarget = 0;
+ _methodTarget = pMethod;
+ }
+
+ bool finalize(abc_block* pBlock)
{
- if (mCTarget)
- return finalize(pBlock, mCTarget, mStatic);
- return finalize_mbody(pBlock, mMTarget);
+ if (_classTarget) {
+ return finalize(pBlock, _classTarget, _static);
+ }
+ return finalize_mbody(pBlock, _methodTarget);
}
};
@@ -123,7 +127,102 @@
class abc_block
{
public:
- typedef enum
+
+ abc_block();
+
+ asClass* locateClass(asName &m);
+
+ asClass* locateClass(const std::string& className);
+
+ abc_parsing::abc_Trait &newTrait()
+ {
+ abc_parsing::abc_Trait *p = new abc_parsing::abc_Trait;
+ _traits.push_back(p);
+ return *p;
+ }
+
+ bool read(SWFStream& in);
+
+ bool pool_value(boost::uint32_t index, boost::uint8_t type, as_value
&v);
+
+ void update_global_name(unsigned int multiname_index);
+
+ const std::vector<asClass*>& scripts() const {
+ return _scripts;
+ }
+
+ boost::uint32_t uIntegerPoolAt(size_t i) const {
+ assert(i < _uIntegerPool.size());
+ return _uIntegerPool[i];
+ }
+
+ const std::string& stringPoolAt(size_t i) const {
+ assert(i < _stringPool.size());
+ return _stringPool[i];
+ }
+
+ boost::int32_t integerPoolAt(size_t i) const {
+ assert(i < _integerPool.size());
+ return _integerPool[i];
+ }
+
+ double doublePoolAt(size_t i) const {
+ assert(i < _doublePool.size());
+ return _doublePool[i];
+ }
+
+ asMethod* methodPoolAt(size_t i) const {
+ assert(i < _methods.size());
+ return _methods[i];
+ }
+
+ asName multinamePoolAt(size_t i) const {
+ assert(i < _multinamePool.size());
+ return _multinamePool[i];
+ }
+
+ asClass* classPoolAt(size_t i) const {
+ assert(i < _classes.size());
+ return _classes[i];
+ }
+
+ asNamespace* namespacePoolAt(size_t i) const {
+ assert(i < _namespacePool.size());
+ return _namespacePool[i];
+ }
+
+ void prepare(Machine* mach);
+
+private:
+
+ friend class abc_parsing::abc_Trait;
+
+ bool read_version();
+ bool read_integer_constants();
+ bool read_unsigned_integer_constants();
+ bool read_double_constants();
+ bool read_string_constants();
+ bool read_namespaces();
+ bool read_namespace_sets();
+ bool read_multinames();
+ bool read_method_infos();
+ bool skip_metadata();
+ bool read_instances();
+ bool read_classes();
+ bool read_scripts();
+ bool read_method_bodies();
+
+ void check_multiname_name(boost::uint32_t name);
+
+ void check_multiname_namespace(boost::uint32_t ns);
+
+ void check_multiname_namespaceset(boost::uint32_t nsset);
+
+ void setMultinameNames(asName *n,string_table::key ABCName);
+
+ void setNamespaceURI(asNamespace *ns,string_table::key ABCName);
+
+ enum Constants
{
PRIVATE_NS = 0x05,
PROTECTED_NS = 0x18,
@@ -148,22 +247,22 @@
POOL_FALSE = 0x0A,
POOL_TRUE = 0x0B,
POOL_NULL = 0x0C
- } constants;
-
- std::vector<boost::int32_t> mIntegerPool;
- std::vector<boost::uint32_t> mUIntegerPool;
- std::vector<double> mDoublePool;
- std::vector<std::string> mStringPool;
- std::vector<string_table::key> mStringPoolTableIds;
- std::vector<asNamespace*> mNamespacePool;
- std::vector<NamespaceSet> mNamespaceSetPool;
- std::vector<asMethod*> mMethods;
- std::vector<asName> mMultinamePool;
- std::vector<asClass*> mClasses;
- std::vector<asClass*> mScripts;
- std::vector<abc_parsing::abc_Trait*> mTraits;
-
- string_table* mStringTable;
+ };
+
+ std::vector<boost::int32_t> _integerPool;
+ std::vector<boost::uint32_t> _uIntegerPool;
+ std::vector<double> _doublePool;
+ std::vector<std::string> _stringPool;
+ std::vector<string_table::key> _stringPoolTableIDs;
+ std::vector<asNamespace*> _namespacePool;
+ std::vector<NamespaceSet> _namespaceSetPool;
+ std::vector<asMethod*> _methods;
+ std::vector<asName> _multinamePool;
+ std::vector<asClass*> _classes;
+ std::vector<asClass*> _scripts;
+ std::vector<abc_parsing::abc_Trait*> _traits;
+
+ string_table* _stringTable;
SWFStream* mS; // Not stored beyond one read.
asClass *mTheObject;
@@ -171,55 +270,10 @@
boost::uint32_t mVersion;
- asClass *locateClass(asName &m);
-
- asClass *locateClass(const std::string& className);
-
- abc_parsing::abc_Trait &newTrait()
- {
- abc_parsing::abc_Trait *p = new abc_parsing::abc_Trait;
- mTraits.push_back(p);
- return *p;
- }
-
-public:
- bool read_version();
- bool read_integer_constants();
- bool read_unsigned_integer_constants();
- bool read_double_constants();
- bool read_string_constants();
- bool read_namespaces();
- bool read_namespace_sets();
- bool read_multinames();
- bool read_method_infos();
- bool skip_metadata();
- bool read_instances();
- bool read_classes();
- bool read_scripts();
- bool read_method_bodies();
-
- bool read(SWFStream& in);
-
- bool pool_value(boost::uint32_t index, boost::uint8_t type, as_value
&v);
-
- void update_global_name(unsigned int multiname_index);
-
- abc_block();
-
-private:
- void check_multiname_name(boost::uint32_t name);
-
- void check_multiname_namespace(boost::uint32_t ns);
-
- void check_multiname_namespaceset(boost::uint32_t nsset);
-
- void setMultinameNames(asName *n,string_table::key ABCName);
-
- void setNamespaceURI(asNamespace *ns,string_table::key ABCName);
};
-} /* namespace gnash */
+}
#endif /* GNASH_ABC_BLOCK_H */
=== modified file 'libcore/swf/DoABCTag.h'
--- a/libcore/swf/DoABCTag.h 2009-02-20 12:24:00 +0000
+++ b/libcore/swf/DoABCTag.h 2009-03-25 11:02:48 +0000
@@ -45,13 +45,6 @@
{}
- /// Read a DoAction block from the stream
- //
-// void read(SWFStream* in)
-// {
-// m_buf.read(*in, in->get_tag_end_position());
-// }
-
virtual void execute(MovieClip* /*m*/, DisplayList& /* dlist */) const
{
VM& vm = VM::get();
@@ -59,28 +52,8 @@
Machine *mach = vm.getMachine();
as_object* global = vm.getGlobal();
- std::vector<asClass*>::iterator ci = mABC->mClasses.begin();
- for(; ci != mABC->mClasses.end(); ++ci){
- (*ci)->initPrototype();
- }
-
- std::vector<asClass*>::iterator si = mABC->mScripts.begin();
- for(; si != mABC->mScripts.end(); ++si){
- (*si)->initPrototype();
- }
-
- std::vector<asMethod*>::iterator mi = mABC->mMethods.begin();
- for(; mi != mABC->mMethods.end(); ++mi){
- (*mi)->initPrototype(mach);
- }
-
- std::vector<abc_Trait*>::iterator i = mABC->mTraits.begin();
-
- for ( ; i != mABC->mTraits.end(); ++i)
- {
- (*i)->finalize(mABC);
- }
- mABC->mTraits.clear();
+ mABC->prepare(mach);
+
log_debug("Begin execute abc_block.");
// log_debug("Getting entry script.");
// asClass* start_script = a.mScripts.back();
=== modified file 'libcore/vm/Machine.cpp'
--- a/libcore/vm/Machine.cpp 2009-03-24 10:56:52 +0000
+++ b/libcore/vm/Machine.cpp 2009-03-25 11:02:48 +0000
@@ -52,7 +52,7 @@
{
public:
ASTypeError() : ASException()
- {/**/}
+ {}
};
// Functions for getting pool constants.
@@ -60,22 +60,21 @@
pool_string(boost::uint32_t index, abc_block *pool)
{
if (!pool) throw ASException();
- return pool->mStringPool.at(index);
+ return pool->stringPoolAt(index);
}
static inline int
pool_int(boost::uint32_t index, abc_block *pool)
{
- if (!pool)
- throw ASException();
- return pool->mIntegerPool.at(index);
+ if (!pool) throw ASException();
+ return pool->integerPoolAt(index);
}
static inline unsigned int
pool_uint(boost::uint32_t index, abc_block *pool)
{
if (!pool) throw ASException();
- return pool->mUIntegerPool.at(index);
+ return pool->uIntegerPoolAt(index);
}
static inline double
@@ -83,28 +82,28 @@
{
if (!pool) throw ASException();
LOG_DEBUG_AVM("Getting double from pool at index %u",index);
- return pool->mDoublePool.at(index);
+ return pool->doublePoolAt(index);
}
static inline asNamespace*
pool_namespace(boost::uint32_t index, abc_block *pool)
{
if (!pool) throw ASException();
- return pool->mNamespacePool.at(index);
+ return pool->namespacePoolAt(index);
}
static inline asMethod*
pool_method(boost::uint32_t index, abc_block* pool)
{
if (!pool) throw ASException();
- return pool->mMethods.at(index);
+ return pool->methodPoolAt(index);
}
static inline asClass*
pool_class(boost::uint32_t index, abc_block* pool)
{
if (!pool) throw ASException();
- return pool->mClasses.at(index);
+ return pool->classPoolAt(index);
}
// Don't make this a reference or you'll taint the pool.
@@ -112,8 +111,14 @@
pool_name(boost::uint32_t index, abc_block* pool)
{
if (!pool) throw ASException();
- asName multiname = pool->mMultinamePool.at(index);
- LOG_DEBUG_AVM("Searching multiname pool for property id=%u abc name=%u
global name = %u abc string=%s flags=0x%X
name_space=%u",index,multiname.getABCName(),multiname.getGlobalName(),pool->mStringPool[multiname.getABCName()],multiname.mFlags
| 0x0,multiname.getNamespace()->getURI());
+ asName multiname = pool->multinamePoolAt(index);
+#if 0
+ LOG_DEBUG_AVM("Searching multiname pool for property id=%u abc name=%u "
+ "global name = %u abc string=%s flags=0x%X name_space=%u",
+ index, multiname.getABCName(), multiname.getGlobalName(),
+ pool->mStringPool[multiname.getABCName()],multiname.mFlags | 0x0,
+ multiname.getNamespace()->getURI());
+#endif
return multiname;
}
@@ -1188,16 +1193,18 @@
as_value property =
object->getMember(a.getGlobalName(),0);
if (!property.is_undefined() && !property.is_null()) {
- LOG_DEBUG_AVM("Calling method %s on object
%s",property.toDebugString(),object_val.toDebugString());
+ LOG_DEBUG_AVM("Calling method %s on object %s",
+ property.toDebugString(),object_val.toDebugString());
as_environment env = as_environment(_vm);
result = call_method(property,&env,object,args);
}
else{
IF_VERBOSE_ASCODING_ERRORS(
- log_aserror(_("Property '%s' of object '%s' is
'%s', cannot call as method"),
- mPoolObject->mStringPool[a.getABCName()],
- object_val, property);
+ log_aserror(_("Property '%s' of object '%s' is
'%s', "
+ "cannot call as method"),
+ mPoolObject->stringPoolAt(a.getABCName()),
+ object_val, property);
)
}
@@ -1426,7 +1433,8 @@
{
boost::uint32_t cid = mStream->read_V32();
asClass *c = pool_class(cid, mPoolObject);
- LOG_DEBUG_AVM("Creating new class id=%u
name=%s",c->getName(),mPoolObject->mStringPool[c->getName()]);
+ LOG_DEBUG_AVM("Creating new class id=%u name=%s", c->getName(),
+ mPoolObject->stringPoolAt(c->getName()));
as_object* base_class = pop_stack().to_object().get();
as_object* new_class = c->getPrototype();
@@ -1559,8 +1567,9 @@
string_table::key name = 0;
asName a = pool_name(mStream->read_V32(), mPoolObject);
- //TODO: If multiname is runtime we need to also pop namespace
and name values of the stack.
- if (a.mFlags == asName::KIND_MultinameL) {
+ // TODO: If multiname is runtime we need to also pop namespace
+ // and name values of the stack.
+ if (a.flags() == asName::KIND_MultinameL) {
as_value nameValue = pop_stack();
name = mST.find(nameValue.to_string());
}
@@ -1635,7 +1644,7 @@
string_table::key name = 0;
asName a = pool_name(mStream->read_V32(), mPoolObject);
//TODO: If multiname is runtime we need to also pop namespace
and name values of the stack.
- if (a.mFlags == asName::KIND_MultinameL) {
+ if (a.flags() == asName::KIND_MultinameL) {
as_value nameValue = pop_stack();
name = mST.find(nameValue.to_string());
}
@@ -2700,7 +2709,7 @@
{
mPoolObject = pool_block;
log_debug("Getting entry script.");
- asClass* start_script = pool_block->mScripts.back();
+ asClass* start_script = pool_block->scripts().back();
log_debug("Getting constructor.");
asMethod* constructor = start_script->getConstructor();
clearRegisters(constructor->getMaxRegisters());
@@ -2824,8 +2833,9 @@
LOG_DEBUG_AVM("Cannot find property in scope stack. Trying again using
as_environment.");
as_object *target = NULL;
as_environment env = as_environment(_vm);
- std::string name = mPoolObject->mStringPool[multiname.getABCName()];
- std::string ns =
mPoolObject->mStringPool[multiname.getNamespace()->getAbcURI()];
+ std::string name = mPoolObject->stringPoolAt(multiname.getABCName());
+ std::string ns = mPoolObject->stringPoolAt(
+ multiname.getNamespace()->getAbcURI());
std::string path = ns.size() == 0 ? name : ns + "." + name;
val = env.get_variable(path,*getScopeStack(),&target);
push_stack(as_value(target));
@@ -2845,8 +2855,8 @@
{
std::string ns =
- mPoolObject->mStringPool[multiname.getNamespace()->getAbcURI()];
- std::string name = mPoolObject->mStringPool[multiname.getABCName()];
+ mPoolObject->stringPoolAt(multiname.getNamespace()->getAbcURI());
+ std::string name = mPoolObject->stringPoolAt(multiname.getABCName());
return get_property_value(obj, name, ns);
}
=== modified file 'libcore/vm/asName.h'
--- a/libcore/vm/asName.h 2009-03-04 20:30:04 +0000
+++ b/libcore/vm/asName.h 2009-03-25 11:02:48 +0000
@@ -26,31 +26,8 @@
class asName
{
public:
- /// If true, the name needs a run-time string value to complete it.
- bool isRuntime() { return (mFlags & FLAG_RTNAME) != 0; }
-
- /// If true, the name needs a run-time namespace to complete it.
- bool isRtns() { return (mFlags & FLAG_RTNS) != 0; }
-
- bool isQName() { return (mFlags & FLAG_QNAME) != 0; }
- void setQName() { mFlags |= FLAG_QNAME; }
-
- void setNamespace(asNamespace *ns) { mNamespace = ns; }
- asNamespace* getNamespace() const { return mNamespace; }
-
- string_table::key getABCName() const { return mABCName; }
- void setABCName(string_table::key n) { mABCName = n;}
-
- string_table::key getGlobalName() const { return mGlobalName;}
- void setGlobalName(string_table::key n) {mGlobalName = n;}
- void setAttr() { mFlags |= FLAG_ATTR; }
-
- void fill(as_object*) {/*TODO*/}
-
- Property* findProperty();
-
- typedef enum
+ enum Kind
{
KIND_Qname = 0x07,
KIND_QnameA = 0x0D,
@@ -62,27 +39,77 @@
KIND_MultinameA = 0x0E,
KIND_MultinameL = 0x1B,
KIND_MultinameLA = 0x1C
- } kinds;
- typedef enum
+ };
+
+ asName()
+ :
+ _flags(0),
+ _namespaceSet(0),
+ _abcName(0),
+ _globalName(0),
+ _namespace(0)
+ {}
+
+ void setFlags(Kind kind) {
+ _flags = kind;
+ }
+
+ boost::uint8_t flags() const {
+ return _flags;
+ }
+
+ /// If true, the name needs a run-time string value to complete it.
+ bool isRuntime() { return _flags & FLAG_RTNAME; }
+
+ /// If true, the name needs a run-time namespace to complete it.
+ bool isRtns() { return _flags & FLAG_RTNS; }
+
+ bool isQName() { return _flags & FLAG_QNAME; }
+ void setQName() { _flags |= FLAG_QNAME; }
+
+ void setNamespace(asNamespace *ns) { _namespace = ns; }
+ asNamespace* getNamespace() const { return _namespace; }
+
+ string_table::key getABCName() const { return _abcName; }
+ void setABCName(string_table::key n) { _abcName = n;}
+
+ string_table::key getGlobalName() const { return _globalName;}
+ void setGlobalName(string_table::key n) { _globalName = n;}
+
+ void setAttr() { _flags |= FLAG_ATTR; }
+
+ void fill(as_object*) {}
+
+ Property* findProperty();
+
+ void namespaceSet(std::vector<asNamespace*>* v) {
+ _namespaceSet = v;
+ }
+
+ const std::vector<asNamespace*>* namespaceSet() const {
+ return _namespaceSet;
+ }
+
+private:
+
+ enum Flag
{
FLAG_ATTR = 0x01,
FLAG_QNAME = 0x02,
FLAG_RTNS = 0x04,
FLAG_RTNAME = 0x08,
FLAG_NSSET = 0x10
- } flags;
-
- boost::uint8_t mFlags;
- std::vector<asNamespace*> *mNamespaceSet;
-
- asName() : mFlags(0), mNamespaceSet(NULL), mABCName(0), mGlobalName(0),
- mNamespace(NULL)
- {/**/}
-private:
- string_table::key mABCName;
- string_table::key mGlobalName;
- asNamespace* mNamespace;
+ };
+
+ boost::uint8_t _flags;
+
+ std::vector<asNamespace*>* _namespaceSet;
+
+ string_table::key _abcName;
+ string_table::key _globalName;
+ asNamespace* _namespace;
+
};
-} // end of namespace gnash
-#endif /* GNASH_AS_NAME_H */
+} // namespace gnash
+#endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] /srv/bzr/gnash/avm2 r9699: Introduce AVM2 to Gnash coding style. Start some attempt at proper,
Benjamin Wolsey <=