You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
2.3 KiB
85 lines
2.3 KiB
9 years ago
|
#ifndef OBJECT_H
|
||
|
#define OBJECT_H
|
||
|
#include <stdio.h>
|
||
|
#include <errno.h>
|
||
|
#include <string.h>
|
||
|
#include <inttypes.h>
|
||
9 years ago
|
#include "common.h"
|
||
9 years ago
|
|
||
|
// Class for storing identifiers
|
||
|
class OId: public ObjectBase
|
||
|
{
|
||
|
std::string name;
|
||
9 years ago
|
|
||
9 years ago
|
public:
|
||
9 years ago
|
OId(const std::string* t):name(*t) {}
|
||
9 years ago
|
~OId() {}
|
||
9 years ago
|
// Pure virtual overrides
|
||
9 years ago
|
ObjectBase* Copy() const override
|
||
|
{
|
||
|
COUT(WARNING)<<"OId::Copy: this call must never be happens."<<std::endl;
|
||
|
return new OId(&name);
|
||
|
}
|
||
9 years ago
|
bool Print() const override {return false;}
|
||
|
std::string Type() const override {return "IDENT";}
|
||
|
|
||
|
// Non-default overrides
|
||
|
std::string Dump() const override {return name;};
|
||
9 years ago
|
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;
|
||
|
}
|
||
9 years ago
|
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;}
|
||
9 years ago
|
};
|
||
|
|
||
|
// Class for storing functions
|
||
|
class OFunc: public ObjectBase
|
||
|
{
|
||
|
std::string name;
|
||
|
ObjectList* args;
|
||
|
public:
|
||
|
OFunc(const std::string* t, ObjectBase* p):name(*t)
|
||
|
{
|
||
|
if(IS_OTYPE(p,ObjectList)) args=dynamic_cast<ObjectList*>(p);
|
||
|
else args=new ObjectList(p);
|
||
|
}
|
||
|
OFunc(const char* t, ObjectBase* p):name(t)
|
||
|
{
|
||
|
if(IS_OTYPE(p,ObjectList)) args=dynamic_cast<ObjectList*>(p);
|
||
|
else args=new ObjectList(p);
|
||
|
}
|
||
|
~OFunc() {if(args!=0) delete args;}
|
||
9 years ago
|
// Pure virtual overrides
|
||
9 years ago
|
ObjectBase* Copy() const override
|
||
|
{
|
||
|
COUT(WARNING)<<"OFunc::Copy: this call must never be happens."<<std::endl;
|
||
|
return new OFunc(&name,args->Copy());
|
||
|
}
|
||
9 years ago
|
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();};
|
||
9 years ago
|
ObjectBase* Evaluate(bool* err) override;
|
||
9 years ago
|
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;}
|
||
9 years ago
|
};
|
||
|
|
||
|
#endif
|