Skip to content

Commit

Permalink
Purged away the horrible clone
Browse files Browse the repository at this point in the history
  • Loading branch information
alexp-sssup committed Oct 27, 2009
1 parent 4020c1b commit 28ed2cb
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 131 deletions.
13 changes: 0 additions & 13 deletions abc.cpp
Expand Up @@ -855,19 +855,6 @@ void ABCContext::buildClassAndInjectBase(const string& s, IInterface* base,argum
}

assert(derived_class->getObjectType()==T_CLASS);
//Walk up the super prototype and clone to inject the base
/* ASObject* cur=derived_class;
while(cur->super->class_name!=base->class_name)
{
ASObject* new_super=cur->super->clone();
cur->super=new_super;
cur=cur->super;
assert(cur);
}
//TODO: handle refcounting
//Inject the base
cur->super=base;*/

//Now the class is valid, check that it's not a builtin one
Class_base* derived_class_tmp=static_cast<Class_base*>(derived_class);
Expand Down
4 changes: 2 additions & 2 deletions abc_opcodes.cpp
Expand Up @@ -345,7 +345,7 @@ ASObject* ABCVm::getProperty(ASObject* obj, multiname* name)
if(ret->getObjectType()==T_FUNCTION)
{
LOG(CALLS,"Attaching this to function " << name);
IFunction* f=ret->clone()->toFunction();
IFunction* f=ret->toFunction()->clone();
f->bind(owner);
ret=f;
}
Expand Down Expand Up @@ -1095,7 +1095,7 @@ void ABCVm::getLex(call_context* th, int n)
if(o->getObjectType()==T_FUNCTION)
{
LOG(CALLS,"Attaching this to function " << name);
IFunction* f=o->clone()->toFunction();
IFunction* f=o->toFunction()->clone();
f->bind(*it);
o=f;
}
Expand Down
14 changes: 7 additions & 7 deletions actions.cpp
Expand Up @@ -352,9 +352,9 @@ ActionTag* ACTIONRECORDHEADER::createTag(std::istream& in)
case 0x88:
t=new ActionConstantPool(in);
break;
case 0x8e:
t=new ActionDefineFunction2(in,this);
break;
// case 0x8e:
// t=new ActionDefineFunction2(in,this);
// break;
case 0x94:
t=new ActionWith(in);
break;
Expand All @@ -367,9 +367,9 @@ ActionTag* ACTIONRECORDHEADER::createTag(std::istream& in)
case 0x9a:
t=new ActionGetURL2(in);
break;
case 0x9b:
t=new ActionDefineFunction(in,this);
break;
// case 0x9b:
// t=new ActionDefineFunction(in,this);
// break;
case 0x9d:
t=new ActionIf(in);
break;
Expand Down Expand Up @@ -774,7 +774,7 @@ void ActionNewObject::Execute()
if(f==NULL)
LOG(ERROR,"Not possible error");
ASObject* obj=type->clone();
ASObject* obj=new ASObject;
f->call(obj,NULL);
rt->vm.stack.push(obj);
}
Expand Down
55 changes: 4 additions & 51 deletions asobjects.h
Expand Up @@ -83,10 +83,6 @@ friend class ABCVm;
int class_index;
Class_base(const tiny_string& name):super(NULL),constructor(NULL),class_name(name),class_index(-1){type=T_CLASS;}
~Class_base();
ASObject* clone()
{
abort();
}
virtual IInterface* getInstance(bool construct=false)=0;
tiny_string class_name;
ASObject* getVariableByMultiname(const multiname& name, ASObject*& owner)
Expand Down Expand Up @@ -121,6 +117,7 @@ class IFunction: public ASObject
typedef ASObject* (*as_function)(ASObject*, arguments*);
virtual ASObject* call(ASObject* obj, arguments* args)=0;
virtual ASObject* fast_call(ASObject* obj, ASObject** args,int num_args)=0;
virtual IFunction* clone()=0;
void bind(ASObject* c)
{
bound=true;
Expand All @@ -140,7 +137,7 @@ class Function : public IFunction
ASObject* call(ASObject* obj, arguments* args);
ASObject* fast_call(ASObject* obj, ASObject** args,int num_args);
IFunction* toFunction();
ASObject* clone()
Function* clone()
{
return new Function(*this);
}
Expand All @@ -159,11 +156,11 @@ friend void ASObject::handleConstruction(ABCContext* context,arguments* args);
ASObject* call(ASObject* obj, arguments* args);
ASObject* fast_call(ASObject* obj, ASObject** args,int num_args);
IFunction* toFunction();
ASObject* clone()
std::vector<ASObject*> func_scope;
SyntheticFunction* clone()
{
return new SyntheticFunction(*this);
}
std::vector<ASObject*> func_scope;

private:
method_info* mi;
Expand Down Expand Up @@ -192,10 +189,6 @@ class Undefined : public ASObject
Undefined();
tiny_string toString() const;
bool isEqual(const ASObject* r) const;
ASObject* clone()
{
return new Undefined;
}
virtual ~Undefined(){}
};

Expand All @@ -217,10 +210,6 @@ class ASString: public ASObject
tiny_string toString() const;
double toNumber() const;
bool isEqual(const ASObject* r) const;
ASObject* clone()
{
return new ASString(*this);
}
};

class ASStage: public ASObject
Expand All @@ -237,10 +226,6 @@ class Null : public ASObject
public:
Null(){type=T_NULL;}
tiny_string toString() const;
ASObject* clone()
{
return new Null;
}
bool isEqual(const ASObject* r) const;
};

Expand Down Expand Up @@ -274,10 +259,6 @@ friend class ABCVm;
ASFUNCTION(shift);
ASFUNCTION(unshift);
ASFUNCTION(_getLength);
/* ASObject* clone()
{
return new ASArray(*this);
}*/
ASObject* at(int index) const
{
if(index<data.size())
Expand Down Expand Up @@ -335,10 +316,6 @@ class arguments: public Array
// if(construct)
// _constructor(this,NULL);
}
/* ASObject* clone()
{
return new arguments(*this);
}*/
};

class Integer : public ASObject
Expand Down Expand Up @@ -368,10 +345,6 @@ friend ASObject* abstract_i(intptr_t i);
bool isLess(const ASObject* r) const;
bool isGreater(const ASObject* r) const;
bool isEqual(const ASObject* o) const;
ASObject* clone()
{
return new Integer(*this);
}
};

class Number : public ASObject
Expand All @@ -392,10 +365,6 @@ friend ASObject* abstract_d(number_t i);
return val;
}
operator double() const {return val;}
ASObject* clone()
{
return new Number(*this);
}
void copyFrom(const ASObject* o);
bool isLess(const ASObject* o) const;
bool isGreater(const ASObject* o) const;
Expand All @@ -409,10 +378,6 @@ class ASMovieClipLoader: public ASObject
ASFUNCTION(addListener);
ASFUNCTION(constructor);

ASObject* clone()
{
return new ASMovieClipLoader(*this);
}
};

class ASXML: public ASObject
Expand All @@ -425,10 +390,6 @@ class ASXML: public ASObject
ASXML();
ASFUNCTION(constructor);
ASFUNCTION(load);
ASObject* clone()
{
return new ASXML(*this);
}
};

class Date: public IInterface
Expand All @@ -453,10 +414,6 @@ class Date: public IInterface
ASFUNCTION(valueOf);
tiny_string toString() const;
int toInt() const;
/* ASObject* clone()
{
return new Date(*this);
}*/
};

//Internal objects used to store traits declared in scripts and object placed, but not yet valid
Expand Down Expand Up @@ -527,10 +484,6 @@ class RegExp: public IInterface
static void sinit(Class_base* c);
ASFUNCTION(_constructor);
ASFUNCTION(exec);
RegExp* clone()
{
return new RegExp(*this);
}
};

template<typename T>
Expand Down
12 changes: 0 additions & 12 deletions flashdisplay.h
Expand Up @@ -115,10 +115,6 @@ class Loader: public IThreadJob, public DisplayObjectContainer
return 0;
}
void Render();
Loader* clone()
{
return new Loader(*this);
}
};

class Sprite: public DisplayObjectContainer
Expand Down Expand Up @@ -146,10 +142,6 @@ class Sprite: public DisplayObjectContainer
{
LOG(NOT_IMPLEMENTED,"Sprite Rendering");
}
Sprite* clone()
{
return new Sprite(*this);
}
};

class MovieClip: public Sprite
Expand Down Expand Up @@ -185,10 +177,6 @@ friend class ParseThread;

//IRenderObject interface
void Render();
MovieClip* clone()
{
return new MovieClip(*this);
}
};

#endif
4 changes: 0 additions & 4 deletions flashevents.h
Expand Up @@ -41,10 +41,6 @@ class Event: public IInterface
ASFUNCTION(_getType);
virtual EVENT_TYPE getEventType() {return EVENT;} //DEPRECATED
tiny_string type;
Event* clone()
{
return new Event(*this);
}
};

class FakeEvent: public Event
Expand Down
12 changes: 1 addition & 11 deletions swftypes.cpp
Expand Up @@ -51,11 +51,6 @@ double ConstantReference::toNumber() const
return ret;
}
ASObject* ConstantReference::clone()
{
return new ASString((const char*)rt->vm.getConstantByIndex(index));
}
int ConstantReference::toInt() const
{
LOG(ERROR,"Cannot convert ConstRef to Int");
Expand Down Expand Up @@ -1351,12 +1346,7 @@ void variables_map::setSlot(int n,ASObject* o)
}
}

/*ASObject* RegisterNumber::clone()
{
return rt->execContext->regs[index];
}
tiny_string RegisterNumber::toString() const
/*tiny_string RegisterNumber::toString() const
{
char buf[20];
snprintf(buf,20,"Register %i",index);
Expand Down
21 changes: 0 additions & 21 deletions swftypes.h
Expand Up @@ -403,12 +403,6 @@ friend class SystemState;
virtual double toNumber() const;
virtual IFunction* toFunction();

//TODO: check clone semantics, as actually nothing is cloned
virtual ASObject* clone()
{
return new ASObject(*this);
}

virtual bool isEqual(const ASObject* r) const;
virtual bool isLess(const ASObject* r) const;
virtual bool isGreater(const ASObject* r) const;
Expand Down Expand Up @@ -466,11 +460,6 @@ T* Manager::get()
tiny_string toString() const;
int toInt() const;
// double toNumber() const;
ASObject* clone();
ASObject* clone()
{
return new ConstantReference(*this);
}
};
class RegisterNumber : public ASObject
Expand All @@ -481,23 +470,13 @@ class RegisterNumber : public ASObject
RegisterNumber(int i):index(i){type=T_REGNUMBER;}
tiny_string toString() const;
//int toInt();
ASObject* clone();
ASObject* clone()
{
return new RegisterNumber(*this);
}
ASObject* instantiate();
};*/

class Package : public ASObject
{
public:
Package(){type=T_PACKAGE;}
ASObject* clone()
{
abort();
return NULL;
}
};

class FLOAT
Expand Down
10 changes: 0 additions & 10 deletions tags.h
Expand Up @@ -370,10 +370,6 @@ class DefineBinaryDataTag: public DictionaryTag, public ByteArray
DefineBinaryDataTag(RECORDHEADER h,std::istream& s);
~DefineBinaryDataTag(){delete[] bytes;}
virtual int getId(){return Tag;}
DefineBinaryDataTag* clone()
{
return new DefineBinaryDataTag(*this);
}
};

class FontTag: public DictionaryTag, public ASFont
Expand Down Expand Up @@ -482,12 +478,6 @@ class DefineSpriteTag: public DictionaryTag, public MovieClip
{
return new DefineSpriteTag(*this);
}

//ASObject interface
DefineSpriteTag* clone()
{
return new DefineSpriteTag(*this);
}
};

class ProtectTag: public ControlTag
Expand Down

0 comments on commit 28ed2cb

Please sign in to comment.