From cd60230d544f1be799a2d5d95632a4f5f3fd3b56 Mon Sep 17 00:00:00 2001 From: Michael Uleysky Date: Sun, 6 Sep 2015 00:04:29 +1000 Subject: [PATCH] Add various typedef's --- src/deptree.cpp | 11 +++++------ src/deptree.h | 16 +++++++++------- src/globals.cpp | 9 +++++---- src/globals.h | 11 +++++++---- src/init.cpp | 4 ++-- src/init.h | 2 +- src/main.cpp | 4 +++- src/object.h | 22 ++++++++++++---------- 8 files changed, 44 insertions(+), 35 deletions(-) diff --git a/src/deptree.cpp b/src/deptree.cpp index 56ca8f4..503a749 100644 --- a/src/deptree.cpp +++ b/src/deptree.cpp @@ -1,7 +1,6 @@ #include "deptree.h" -#include "globals.h" -int DepTree::CreateNodeFromVar(const std::string& var, std::set& used, std::set& callstack) +int DepTree::CreateNodeFromVar(const std::string& var, UsedType& used, CallStack& callstack) { COUT(DEBUG)<<"DepTree::CreateNodeFromVar "<& us return 1; } - std::set ids; + UsedType ids; used.insert(var); G_vars[var]->UsedIdents(ids); @@ -51,7 +50,7 @@ int DepTree::CreateNodeFromVar(const std::string& var, std::set& us } -int DepTree::CreateNodeFromSP(DepTree::NodeType list, std::vector::size_type ind, std::set& 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:: COUT(DEBUG)<<"DepTree::CreateNodeFromSP "<<((list==DepTree::SAVE)?G_tosave:G_toprint)[ind]->Dump()< ids; - std::set callstack; + CallStack callstack; type=list; index=ind; @@ -95,7 +94,7 @@ int DepTree::CreateNodeFromSP(DepTree::NodeType list, std::vector:: } -int DepTree::CreateGlobalTree(std::set& used) +int DepTree::CreateGlobalTree(UsedType& used) { if(parents.size()!=0) { diff --git a/src/deptree.h b/src/deptree.h index 99718f8..274b73b 100644 --- a/src/deptree.h +++ b/src/deptree.h @@ -3,20 +3,22 @@ #include #include #include -#include "object.h" +#include "globals.h" class DepTree { enum NodeType {NOTDEF,ROOT,SAVE,PRINT,VAR}; - std::set parents; - std::set childrens; + typedef std::set NodeVector; + typedef std::set CallStack; + NodeVector parents; + NodeVector childrens; NodeType type; - std::vector::size_type index; + G_toType::size_type index; std::string name; - int CreateNodeFromVar(const std::string& var, std::set& used, std::set& callstack); - int CreateNodeFromSP(NodeType list, std::vector::size_type ind, std::set& 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& used); + int CreateGlobalTree(UsedType& used); }; #endif diff --git a/src/globals.cpp b/src/globals.cpp index 226861a..d460156 100644 --- a/src/globals.cpp +++ b/src/globals.cpp @@ -1,16 +1,17 @@ #include "globals.h" + // Variables definitions -std::map G_vars; +G_varsType G_vars; // Functions addresses -std::multimap G_funcs; +G_funcsType G_funcs; // List of objects to save -std::vector G_tosave; +G_toType G_tosave; // List of objects to print -std::vector G_toprint; +G_toType G_toprint; void ClearGlobals() { diff --git a/src/globals.h b/src/globals.h index 6bd37cd..77d4c22 100644 --- a/src/globals.h +++ b/src/globals.h @@ -6,17 +6,20 @@ #include "object.h" // Variables definitions -extern EXPORT std::map G_vars; +typedef std::map G_varsType; +extern EXPORT G_varsType G_vars; // Functions addresses typedef ObjectBase* (*Func)(ObjectList*); -extern EXPORT std::multimap G_funcs; +typedef std::multimap G_funcsType; +extern EXPORT G_funcsType G_funcs; +typedef std::vector G_toType; // List of objects to save -extern EXPORT std::vector EXPORT G_tosave; +extern EXPORT G_toType G_tosave; // List of objects to print -extern EXPORT std::vector EXPORT G_toprint; +extern EXPORT G_toType G_toprint; void ClearGlobals(); diff --git a/src/init.cpp b/src/init.cpp index ddc8680..dea807e 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -52,7 +52,7 @@ int RegisterArifmeticFunctions() } -int BuildDepTree(DepTree* deptree,std::set& used) +int BuildDepTree(DepTree* deptree, UsedType& used) { return deptree->CreateGlobalTree(used); } @@ -60,7 +60,7 @@ int BuildDepTree(DepTree* deptree,std::set& used) int CheckFunctions() { - std::set funcs; + UsedType funcs; for(auto& i:G_tosave) { diff --git a/src/init.h b/src/init.h index ccd52a8..d2578ae 100644 --- a/src/init.h +++ b/src/init.h @@ -8,7 +8,7 @@ typedef void* yyscan_t; int ParseConfigFile(char* config); int RegisterArifmeticFunctions(); -int BuildDepTree(DepTree* deptree, std::set& used); +int BuildDepTree(DepTree* deptree, UsedType& used); int CheckFunctions(); void DumpConfig(); diff --git a/src/main.cpp b/src/main.cpp index bdd1f07..d7f0c60 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,7 +21,7 @@ int main(int argc, char** argv) } { - std::set 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)< 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& funcs) const {} - virtual void UsedIdents(std::set& 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 ObjectReal; typedef ObjectSimple ObjectString; template<> -inline const int8_t* ObjectSimple::Blob(size_t* size) const +inline const int8_t* ObjectString::Blob(size_t* size) const { *size=val.length(); return reinterpret_cast(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& funcs) const override {return val->UsedFuncs(funcs);} - void UsedIdents(std::set& 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& funcs) const override {for(auto& i: *vals) i->UsedFuncs(funcs);} - void UsedIdents(std::set& 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& 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."<Dump();}; - void UsedFuncs(std::set& funcs) const override {funcs.insert(name); args->UsedFuncs(funcs);} - void UsedIdents(std::set& 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."<