|
|
|
#ifndef OBJECT_H
|
|
|
|
#define OBJECT_H
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include "common.h"
|
|
|
|
|
|
|
|
// Class for storing identifiers
|
|
|
|
class OId: public ObjectBase
|
|
|
|
{
|
|
|
|
std::string name;
|
|
|
|
|
|
|
|
public:
|
|
|
|
OId(const std::string* t):name(*t) {}
|
|
|
|
~OId() {}
|
|
|
|
// Pure virtual overrides
|
|
|
|
ObjectBase* Copy() const override
|
|
|
|
{
|
|
|
|
COUT(WARNING)<<"OId::Copy: this call must never be happens."<<std::endl;
|
|
|
|
return new OId(&name);
|
|
|
|
}
|
|
|
|
bool Print() const override {return false;}
|
|
|
|
std::string Type() const override {return "IDENT";}
|
|
|
|
|
|
|
|
// Non-default overrides
|
|
|
|
std::string Dump() const override {return name;};
|
|
|
|
ObjectBase* Evaluate(bool* err) override
|
|
|
|
{
|
|
|
|
COUT(ERROR)<<"Variable "<<name<<" still not defined."<<std::endl;
|
|
|
|
*err=true;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ObjectBase* ReplaceVar(const std::string& vname, ObjectBase* ob) override
|
|
|
|
{
|
|
|
|
if(vname==Name()) return ob->Copy();
|
|
|
|
else return 0;
|
|
|
|
}
|
|
|
|
void UsedIdents(UsedType& ids) const override {ids.insert(name);}
|
|
|
|
|
|
|
|
// Own functions
|
|
|
|
std::string Name() const {return name;}
|
|
|
|
// void SetName(const std::string& s) {name=s;}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Class for storing functions
|
|
|
|
class OFunc: public ObjectBase
|
|
|
|
{
|
|
|
|
std::string name;
|
|
|
|
ObjectList* args;
|
|
|
|
public:
|
|
|
|
OFunc(const std::string* t, ObjectBase* p):name(*t)
|
|
|
|
{
|
|
|
|
if(OBType<ObjectList>(p)) args=dynamic_cast<ObjectList*>(p);
|
|
|
|
else args=new ObjectList(p);
|
|
|
|
}
|
|
|
|
OFunc(const char* t, ObjectBase* p):name(t)
|
|
|
|
{
|
|
|
|
if(OBType<ObjectList>(p)) args=dynamic_cast<ObjectList*>(p);
|
|
|
|
else args=new ObjectList(p);
|
|
|
|
}
|
|
|
|
~OFunc() {if(args!=0) delete args;}
|
|
|
|
// Pure virtual overrides
|
|
|
|
ObjectBase* Copy() const override
|
|
|
|
{
|
|
|
|
COUT(WARNING)<<"OFunc::Copy: this call must never be happens."<<std::endl;
|
|
|
|
return new OFunc(&name,args->Copy());
|
|
|
|
}
|
|
|
|
bool Print() const override {return false;}
|
|
|
|
std::string Type() const override {return "FUNC";}
|
|
|
|
|
|
|
|
// Non-default overrides
|
|
|
|
std::string Dump() const override {return Name()+args->Dump();};
|
|
|
|
ObjectBase* Evaluate(bool* err) override;
|
|
|
|
ObjectBase* ReplaceVar(const std::string& vname, ObjectBase* ob) override {return args->ReplaceVar(vname,ob);}
|
|
|
|
void UsedFuncs(UsedType& funcs) const override {funcs.insert(name); args->UsedFuncs(funcs);}
|
|
|
|
void UsedIdents(UsedType& ids) const override {args->UsedIdents(ids);}
|
|
|
|
|
|
|
|
// Own functions
|
|
|
|
std::string Name() const {return name;}
|
|
|
|
// void SetName(std::string s) {name=s;}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|