Browse Source

Check parsed config on unknown functions

test
Michael Uleysky 9 years ago
parent
commit
894a74eed9
  1. 42
      src/init.cpp
  2. 1
      src/init.h
  3. 4
      src/main.cpp

42
src/init.cpp

@ -54,6 +54,48 @@ int BuildDepTree(DepTree* deptree,std::set<std::string>& used)
return deptree->CreateGlobalTree(used); return deptree->CreateGlobalTree(used);
} }
int CheckFunctions()
{
std::set<std::string> funcs;
for(auto& i:G_tosave)
{
i->UsedFuncs(funcs);
for(auto& f:funcs) if(G_funcs.find(f)==G_funcs.end())
{
COUT(ERROR)<<"Unknown function "<<f<<" in directive save"<<i->Dump()<<std::endl;
return 1;
}
funcs.clear();
}
for(auto& i:G_toprint)
{
i->UsedFuncs(funcs);
for(auto& f:funcs) if(G_funcs.find(f)==G_funcs.end())
{
COUT(ERROR)<<"Unknown function "<<f<<" in directive print"<<i->Dump()<<std::endl;
return 1;
}
funcs.clear();
}
for(auto& i:G_vars)
{
i.second->UsedFuncs(funcs);
for(auto& f:funcs) if(G_funcs.find(f)==G_funcs.end())
{
COUT(ERROR)<<"Unknown function "<<f<<" in definition of variable "<<i.first<<std::endl;
return 1;
}
funcs.clear();
}
return 0;
}
void DumpConfig() void DumpConfig()
{ {
for(auto& i: G_vars) COUT(INFO)<<i.first<<"="+i.second->Dump()<<";"<<std::endl; for(auto& i: G_vars) COUT(INFO)<<i.first<<"="+i.second->Dump()<<";"<<std::endl;

1
src/init.h

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

4
src/main.cpp

@ -37,6 +37,10 @@ int main(int argc, char** argv)
RegisterArifmeticFunctions(); RegisterArifmeticFunctions();
COUT(INFO)<<"Checking functions ";
ret=CheckFunctions(); if(ret!=0) { ClearGlobals(); delete DPTree; return 1;}
COUT(INFO)<<"Ok"<<std::endl;
DumpConfig(); DumpConfig();
ClearGlobals(); ClearGlobals();

Loading…
Cancel
Save