[Compbench-devel] CompBenchmarks++/libcompbenchmarks/CEL CEL-Atom.cpp, 1.2, 1.3 CEL-Atom.h, 1.2, 1.
Brought to you by:
xfred
From: Frederic T. <xf...@us...> - 2007-03-07 18:00:31
|
Update of /cvsroot/compbench/CompBenchmarks++/libcompbenchmarks/CEL In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv27293 Modified Files: CEL-Atom.cpp CEL-Atom.h CEL-Var.cpp CEL-Var.h Log Message: Variables are (implicitly) localy defined in blocks, function, and containers. Index: CEL-Atom.h =================================================================== RCS file: /cvsroot/compbench/CompBenchmarks++/libcompbenchmarks/CEL/CEL-Atom.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CEL-Atom.h 6 Mar 2007 19:32:00 -0000 1.2 --- CEL-Atom.h 7 Mar 2007 18:00:21 -0000 1.3 *************** *** 13,20 **** --- 13,31 ---- namespace CBM { + + typedef struct { + std::string name; + std::string value; + } celVar_t; /** \brief ? */ class CelAtom { + private: + std::vector<celVar_t*> celVars; + + void varDone(void); + protected: + CelAtom *parent; std::vector<CelAtom *> childs; CelAtom(); *************** *** 25,32 **** --- 36,50 ---- virtual std::string xmlValue(void); virtual std::string xmlProperties(void); + virtual CelAtom *varOwner(void); public: virtual std::string xmlEntityName(void) = 0; virtual std::vector<CelAtom *>& Childs(void); + virtual void setParent(CelAtom *_parent); + + virtual void VarSet(std::string _name, std::string _value); + virtual celVar_t *VarGet(std::string _name); + virtual std::string VarUndef(std::string _name); + virtual void add(CelAtom *_atom); virtual std::string Evaluate(void) = 0; Index: CEL-Atom.cpp =================================================================== RCS file: /cvsroot/compbench/CompBenchmarks++/libcompbenchmarks/CEL/CEL-Atom.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CEL-Atom.cpp 6 Mar 2007 19:32:00 -0000 1.2 --- CEL-Atom.cpp 7 Mar 2007 18:00:21 -0000 1.3 *************** *** 12,15 **** --- 12,30 ---- CelAtom::CelAtom() { + parent=0; + } + + void CelAtom::varDone(void) + { + int i; + int n = celVars.size(); + std::vector<celVar_t*> ncelVars; + celVar_t *V; + + for(i=0; i<n; i++) { + V=celVars[i]; + delete(V); + } + celVars=ncelVars; } *************** *** 28,31 **** --- 43,63 ---- } + CelAtom *CelAtom::varOwner(void) + { + CelAtom *ptr = this; + std::string e; + while (ptr->parent) { + e=ptr->xmlEntityName(); + if ((e=="cel-function-def") || + (e=="cel-block") || + (e=="cel")) { + return(ptr); + } + ptr=ptr->parent; + } + + return(ptr); + } + std::string CelAtom::xmlValue(void) { *************** *** 38,44 **** --- 70,131 ---- } + void CelAtom::setParent(CelAtom *_parent) + { + parent=_parent; + } + + void CelAtom::VarSet(std::string _name, + std::string _value) + { + celVar_t *cv; + + cv=VarGet(_name); + if (!cv) { + cv=new celVar_t; + celVars.push_back(cv); + } + cv->name=_name; + cv->value=_value; + } + + celVar_t *CelAtom::VarGet(std::string _name) + { + int i; + int n = celVars.size(); + celVar_t *V; + + for(i=0; i<n; i++) { + V=celVars[i]; + if (V->name==_name) + return(V); + } + return(0); + } + + std::string CelAtom::VarUndef(std::string _name) + { + celVar_t *cv = VarGet(_name); + celVar_t *V; + std::vector<celVar_t*> ncelVars; + int i; + int n = celVars.size(); + + if (!cv) + return("0"); + + for(i=0; i<n; i++) { + V=celVars[i]; + if (V!=cv) + ncelVars.push_back(V); + } + celVars=ncelVars; + delete(cv); + return("1"); + } + void CelAtom::add(CBM::CelAtom *_atom) { childs.push_back(_atom); + _atom->setParent(this); } *************** *** 97,100 **** --- 184,188 ---- CelAtom::~CelAtom() { + varDone(); } Index: CEL-Var.cpp =================================================================== RCS file: /cvsroot/compbench/CompBenchmarks++/libcompbenchmarks/CEL/CEL-Var.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CEL-Var.cpp 5 Mar 2007 20:32:40 -0000 1.1 --- CEL-Var.cpp 7 Mar 2007 18:00:21 -0000 1.2 *************** *** 11,71 **** using namespace CBM; - typedef struct { - std::string name; - std::string value; - } celVar_t; - - std::vector<celVar_t*> celVars; - - void CBM::CELVarDone(void) - { - int i; - int n = celVars.size(); - std::vector<celVar_t*> ncelVars; - celVar_t *V; - - for(i=0; i<n; i++) { - V=celVars[i]; - delete(V); - } - celVars=ncelVars; - - } - - celVar_t *celVarGet(std::string _name) - { - int i; - int n = celVars.size(); - celVar_t *V; - - for(i=0; i<n; i++) { - V=celVars[i]; - if (V->name==_name) - return(V); - } - return(0); - } - - std::string celVarRemove(std::string _name) - { - celVar_t *cv = celVarGet(_name); - celVar_t *V; - std::vector<celVar_t*> ncelVars; - int i; - int n = celVars.size(); - - if (!cv) - return("0"); - - for(i=0; i<n; i++) { - V=celVars[i]; - if (V!=cv) - ncelVars.push_back(V); - } - celVars=ncelVars; - delete(cv); - return("1"); - } - CelVar::CelVar() : CelAtom() --- 11,14 ---- *************** *** 95,99 **** std::string name; std::string value; - celVar_t *cv; if (n!=2) --- 38,41 ---- *************** *** 106,117 **** value=V->Evaluate(); ! cv=celVarGet(name); ! if (!cv) { ! cv=new celVar_t; ! celVars.push_back(cv); ! } ! cv->name=name; ! cv->value=value; ! return("1"); } --- 48,53 ---- value=V->Evaluate(); ! varOwner()->VarSet(name, ! value); return("1"); } *************** *** 142,146 **** N=childs[0]; ! cv=celVarGet(N->Evaluate()); if (cv) return(cv->value); --- 78,82 ---- N=childs[0]; ! cv=varOwner()->VarGet(N->Evaluate()); if (cv) return(cv->value); *************** *** 172,176 **** N=childs[0]; ! return(celVarRemove(N->Evaluate())); } --- 108,112 ---- N=childs[0]; ! return(varOwner()->VarUndef(N->Evaluate())); } Index: CEL-Var.h =================================================================== RCS file: /cvsroot/compbench/CompBenchmarks++/libcompbenchmarks/CEL/CEL-Var.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CEL-Var.h 5 Mar 2007 20:32:40 -0000 1.1 --- CEL-Var.h 7 Mar 2007 18:00:21 -0000 1.2 *************** *** 13,18 **** namespace CBM { - void CELVarDone(void); - /** \brief ? */ --- 13,16 ---- |