Browse Source

Add various typedef's

test
Michael Uleysky 9 years ago
parent
commit
cd60230d54
  1. 11
      src/deptree.cpp
  2. 16
      src/deptree.h
  3. 9
      src/globals.cpp
  4. 11
      src/globals.h
  5. 4
      src/init.cpp
  6. 2
      src/init.h
  7. 4
      src/main.cpp
  8. 22
      src/object.h

11
src/deptree.cpp

@ -1,7 +1,6 @@
#include "deptree.h"
#include "globals.h"
int DepTree::CreateNodeFromVar(const std::string& var, std::set<std::string>& used, std::set<DepTree*>& callstack)
int DepTree::CreateNodeFromVar(const std::string& var, UsedType& used, CallStack& callstack)
{
COUT(DEBUG)<<"DepTree::CreateNodeFromVar "<<var<<std::endl;
if(G_vars.count(var)==0)
@ -10,7 +9,7 @@ int DepTree::CreateNodeFromVar(const std::string& var, std::set<std::string>& us
return 1;
}
std::set<std::string> ids;
UsedType ids;
used.insert(var);
G_vars[var]->UsedIdents(ids);
@ -51,7 +50,7 @@ int DepTree::CreateNodeFromVar(const std::string& var, std::set<std::string>& us
}
int DepTree::CreateNodeFromSP(DepTree::NodeType list, std::vector<ObjectList*>::size_type ind, std::set<std::string>& used)
int DepTree::CreateNodeFromSP(DepTree::NodeType list, G_toType::size_type ind, UsedType& used)
{
if(list!=DepTree::SAVE && list!=DepTree::PRINT)
{
@ -61,7 +60,7 @@ int DepTree::CreateNodeFromSP(DepTree::NodeType list, std::vector<ObjectList*>::
COUT(DEBUG)<<"DepTree::CreateNodeFromSP "<<((list==DepTree::SAVE)?G_tosave:G_toprint)[ind]->Dump()<<std::endl;
std::set<std::string> ids;
std::set<DepTree*> callstack;
CallStack callstack;
type=list;
index=ind;
@ -95,7 +94,7 @@ int DepTree::CreateNodeFromSP(DepTree::NodeType list, std::vector<ObjectList*>::
}
int DepTree::CreateGlobalTree(std::set<std::string>& used)
int DepTree::CreateGlobalTree(UsedType& used)
{
if(parents.size()!=0)
{

16
src/deptree.h

@ -3,20 +3,22 @@
#include <set>
#include <vector>
#include <string>
#include "object.h"
#include "globals.h"
class DepTree
{
enum NodeType {NOTDEF,ROOT,SAVE,PRINT,VAR};
std::set<DepTree*> parents;
std::set<DepTree*> childrens;
typedef std::set<DepTree*> NodeVector;
typedef std::set<DepTree*> CallStack;
NodeVector parents;
NodeVector childrens;
NodeType type;
std::vector<ObjectList*>::size_type index;
G_toType::size_type index;
std::string name;
int CreateNodeFromVar(const std::string& var, std::set<std::string>& used, std::set<DepTree*>& callstack);
int CreateNodeFromSP(NodeType list, std::vector<ObjectList*>::size_type ind, std::set<std::string>& used);
int CreateNodeFromVar(const std::string& var, UsedType& used, CallStack& callstack);
int CreateNodeFromSP(NodeType list, G_toType::size_type ind, UsedType& used);
DepTree* FindNodeByVarFromCurrent(const std::string& var) const;
DepTree* FindNodeByVar(const std::string& var) const;
public:
@ -32,7 +34,7 @@ public:
}
}
int CreateGlobalTree(std::set<std::string>& used);
int CreateGlobalTree(UsedType& used);
};
#endif

9
src/globals.cpp

@ -1,16 +1,17 @@
#include "globals.h"
// Variables definitions
std::map<std::string,ObjectBase*> G_vars;
G_varsType G_vars;
// Functions addresses
std::multimap<std::string,Func> G_funcs;
G_funcsType G_funcs;
// List of objects to save
std::vector<ObjectList*> G_tosave;
G_toType G_tosave;
// List of objects to print
std::vector<ObjectList*> G_toprint;
G_toType G_toprint;
void ClearGlobals()
{

11
src/globals.h

@ -6,17 +6,20 @@
#include "object.h"
// Variables definitions
extern EXPORT std::map<std::string,ObjectBase*> G_vars;
typedef std::map<std::string,ObjectBase*> G_varsType;
extern EXPORT G_varsType G_vars;
// Functions addresses
typedef ObjectBase* (*Func)(ObjectList*);
extern EXPORT std::multimap<std::string,Func> G_funcs;
typedef std::multimap<std::string,Func> G_funcsType;
extern EXPORT G_funcsType G_funcs;
typedef std::vector<ObjectList*> G_toType;
// List of objects to save
extern EXPORT std::vector<ObjectList*> EXPORT G_tosave;
extern EXPORT G_toType G_tosave;
// List of objects to print
extern EXPORT std::vector<ObjectList*> EXPORT G_toprint;
extern EXPORT G_toType G_toprint;
void ClearGlobals();

4
src/init.cpp

@ -52,7 +52,7 @@ int RegisterArifmeticFunctions()
}
int BuildDepTree(DepTree* deptree,std::set<std::string>& used)
int BuildDepTree(DepTree* deptree, UsedType& used)
{
return deptree->CreateGlobalTree(used);
}
@ -60,7 +60,7 @@ int BuildDepTree(DepTree* deptree,std::set<std::string>& used)
int CheckFunctions()
{
std::set<std::string> funcs;
UsedType funcs;
for(auto& i:G_tosave)
{

2
src/init.h

@ -8,7 +8,7 @@ typedef void* yyscan_t;
int ParseConfigFile(char* config);
int RegisterArifmeticFunctions();
int BuildDepTree(DepTree* deptree, std::set<std::string>& used);
int BuildDepTree(DepTree* deptree, UsedType& used);
int CheckFunctions();
void DumpConfig();

4
src/main.cpp

@ -21,7 +21,7 @@ int main(int argc, char** argv)
}
{
std::set<std::string> used, all;
UsedType used, all;
for(auto& i:G_vars) all.insert(i.first);
unsigned int tot=G_vars.size();
@ -43,6 +43,8 @@ int main(int argc, char** argv)
DumpConfig();
COUT(INFO)<<sizeof(DepTree)<<" "<<sizeof(ObjectList)<<std::endl;
ClearGlobals();
delete DPTree;
return 0;

22
src/object.h

@ -16,6 +16,8 @@
#define IS_OTYPE(quo,equ) (std::type_index(typeid(*quo))==std::type_index(typeid(equ)))
#define IS_OTYPEI(quo,equ) (std::type_index(typeid(quo))==std::type_index(typeid(equ)))
typedef std::set<std::string> UsedType;
// Base class for all objects
class EXPORT ObjectBase
{
@ -67,8 +69,8 @@ public:
return true;
}
virtual std::string Dump() const {return "%"+Type()+"%";}
virtual void UsedFuncs(std::set<std::string>& funcs) const {}
virtual void UsedIdents(std::set<std::string>& ids) const {}
virtual void UsedFuncs(UsedType& funcs) const {}
virtual void UsedIdents(UsedType& ids) const {}
virtual ObjectBase* Copy() const=0;
virtual ObjectBase* Evaluate(bool* err) {*err=false; return 0;}
virtual ObjectBase* ReplaceVar(const std::string& vname, ObjectBase* ob) {return 0;}
@ -120,7 +122,7 @@ typedef ObjectSimple<double> ObjectReal;
typedef ObjectSimple<std::string> ObjectString;
template<>
inline const int8_t* ObjectSimple<std::string>::Blob(size_t* size) const
inline const int8_t* ObjectString::Blob(size_t* size) const
{
*size=val.length();
return reinterpret_cast<const int8_t*>(val.c_str());
@ -153,8 +155,8 @@ public:
const ObjectBase* Value() const {return val.get();}
void SetPair(const std::string& n, ObjectBase* v) {if(!Exist()) {name=n; val.reset(v);}}
std::string Dump() const override { return Name()+"="+val->Dump(); }
void UsedFuncs(std::set<std::string>& funcs) const override {return val->UsedFuncs(funcs);}
void UsedIdents(std::set<std::string>& ids) const override {return val->UsedIdents(ids);}
void UsedFuncs(UsedType& funcs) const override {return val->UsedFuncs(funcs);}
void UsedIdents(UsedType& ids) const override {return val->UsedIdents(ids);}
ObjectBase* Copy() const override
{
auto ret=new ObjectPair;
@ -218,8 +220,8 @@ public:
if(vals->size()!=0) s.resize(s.length()-2);
return s+")";
}
void UsedFuncs(std::set<std::string>& funcs) const override {for(auto& i: *vals) i->UsedFuncs(funcs);}
void UsedIdents(std::set<std::string>& ids) const override {for(auto& i: *vals) i->UsedIdents(ids);}
void UsedFuncs(UsedType& funcs) const override {for(auto& i: *vals) i->UsedFuncs(funcs);}
void UsedIdents(UsedType& ids) const override {for(auto& i: *vals) i->UsedIdents(ids);}
ObjectBase* Copy() const override
{
auto ret=new ObjectList;
@ -287,7 +289,7 @@ public:
std::string Name() const {return name;}
void SetName(const std::string& s) {name=s;}
std::string Dump() const override {return name;};
void UsedIdents(std::set<std::string>& ids) const override {ids.insert(name);}
void UsedIdents(UsedType& ids) const override {ids.insert(name);}
ObjectBase* Copy() const override
{
COUT(WARNING)<<"OId::Copy: this call must never be happens."<<std::endl;
@ -328,8 +330,8 @@ public:
std::string Name() const {return name;}
void SetName(std::string s) {name=s;}
std::string Dump() const override {return Name()+args->Dump();};
void UsedFuncs(std::set<std::string>& funcs) const override {funcs.insert(name); args->UsedFuncs(funcs);}
void UsedIdents(std::set<std::string>& ids) const override {args->UsedIdents(ids);}
void UsedFuncs(UsedType& funcs) const override {funcs.insert(name); args->UsedFuncs(funcs);}
void UsedIdents(UsedType& ids) const override {args->UsedIdents(ids);}
ObjectBase* Copy() const override
{
COUT(WARNING)<<"OFunc::Copy: this call must never be happens."<<std::endl;

Loading…
Cancel
Save