|
|
|
@ -7,10 +7,10 @@ std::map<std::string,ObjectBase*> G_vars;
|
|
|
|
|
std::multimap<std::string,Func> G_funcs; |
|
|
|
|
|
|
|
|
|
// List of objects to save
|
|
|
|
|
std::list<ObjectList*> G_tosave; |
|
|
|
|
std::vector<ObjectList*> G_tosave; |
|
|
|
|
|
|
|
|
|
// List of objects to print
|
|
|
|
|
std::list<ObjectList*> G_toprint; |
|
|
|
|
std::vector<ObjectList*> G_toprint; |
|
|
|
|
|
|
|
|
|
void ClearGlobals() |
|
|
|
|
{ |
|
|
|
@ -27,3 +27,104 @@ void RegisterFunction(const std::string& name, Func func)
|
|
|
|
|
{ |
|
|
|
|
G_funcs.emplace(name,func); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int DepTree::CreateNodeFromVar(const std::string& var, std::set<std::string>& used) |
|
|
|
|
{ |
|
|
|
|
if(G_vars.count(var)==0) |
|
|
|
|
{ |
|
|
|
|
COUT(ERROR)<<"Definition of variable "<<var<<" not found."<<std::endl; |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::vector<std::string> ids; |
|
|
|
|
|
|
|
|
|
used.insert(var); |
|
|
|
|
G_vars[var]->UsedIdents(ids); |
|
|
|
|
type=DepTree::VAR; |
|
|
|
|
name=var; |
|
|
|
|
nchild=ids.size(); |
|
|
|
|
COUT(DEBUG)<<ids.size()<<std::endl; |
|
|
|
|
if(nchild!=0) |
|
|
|
|
{ |
|
|
|
|
childrens=new DepTree*[nchild]; |
|
|
|
|
for(unsigned int i=0;i<nchild;i++) {childrens[i]=new DepTree; childrens[i]->parent=this;} |
|
|
|
|
for(unsigned int i=0;i<nchild;i++) |
|
|
|
|
{ |
|
|
|
|
int ret; |
|
|
|
|
ret=childrens[i]->CreateNodeFromVar(ids[i],used); |
|
|
|
|
if(ret!=0) |
|
|
|
|
{ |
|
|
|
|
COUT(ERROR)<<" in definition of variable "<<var<<"."<<std::endl; |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int DepTree::CreateNodeFromSP(DepTree::NodeType list, std::vector<ObjectList*>::size_type ind, std::set<std::string>& used) |
|
|
|
|
{ |
|
|
|
|
if(list!=DepTree::SAVE && list!=DepTree::PRINT) |
|
|
|
|
{ |
|
|
|
|
COUT(ERROR)<<"Internal error, incorrect NodeType in DepTree::CreateNodeFromSP()."<<std::endl; |
|
|
|
|
return 2; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::vector<std::string> ids; |
|
|
|
|
|
|
|
|
|
type=list; |
|
|
|
|
index=ind; |
|
|
|
|
|
|
|
|
|
if(type==DepTree::SAVE) G_tosave[index]->UsedIdents(ids); |
|
|
|
|
else if(type==DepTree::PRINT) G_toprint[index]->UsedIdents(ids); |
|
|
|
|
nchild=ids.size(); |
|
|
|
|
if(nchild!=0) |
|
|
|
|
{ |
|
|
|
|
childrens=new DepTree*[nchild]; |
|
|
|
|
for(unsigned int i=0;i<nchild;i++) {childrens[i]=new DepTree; childrens[i]->parent=this;} |
|
|
|
|
for(unsigned int i=0;i<nchild;i++) |
|
|
|
|
{ |
|
|
|
|
int ret; |
|
|
|
|
ret=childrens[i]->CreateNodeFromVar(ids[i],used); |
|
|
|
|
if(ret!=0) |
|
|
|
|
{ |
|
|
|
|
COUT(ERROR)<<" in print/save directive "<<G_toprint[index]->Dump()<<"."<<std::endl; |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int DepTree::CreateGlobalTree(std::set<std::string>& used) |
|
|
|
|
{ |
|
|
|
|
if(parent!=0) |
|
|
|
|
{ |
|
|
|
|
COUT(ERROR)<<"Internal error, DepTree::CreateGlobalTree() call for non-root node."<<std::endl; |
|
|
|
|
return 2; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
unsigned int i,j; |
|
|
|
|
int ret; |
|
|
|
|
|
|
|
|
|
type=DepTree::ROOT; |
|
|
|
|
nchild=G_toprint.size()+G_tosave.size(); |
|
|
|
|
if(nchild!=0) childrens=new DepTree*[nchild]; |
|
|
|
|
for(i=0;i<nchild;i++) {childrens[i]=new DepTree; childrens[i]->parent=this;} |
|
|
|
|
i=0; |
|
|
|
|
for(j=0;j<G_tosave.size();j++) |
|
|
|
|
{ |
|
|
|
|
ret=childrens[i++]->CreateNodeFromSP(DepTree::SAVE,j,used); |
|
|
|
|
if(ret!=0) return ret; |
|
|
|
|
} |
|
|
|
|
for(j=0;j<G_toprint.size();j++) |
|
|
|
|
{ |
|
|
|
|
ret=childrens[i++]->CreateNodeFromSP(DepTree::PRINT,j,used); |
|
|
|
|
if(ret!=0) return ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|