|
|
|
#include <inttypes.h>
|
|
|
|
#include "init.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "object.h"
|
|
|
|
#include "globals.h"
|
|
|
|
#include "arifmetic.h"
|
|
|
|
#include "parser/parser.h"
|
|
|
|
#include "parser/grammatical.h"
|
|
|
|
// definitions for bison-bridge
|
|
|
|
#define YYSTYPE CONFSTYPE
|
|
|
|
#define YYLTYPE CONFLTYPE
|
|
|
|
#include "parser/lexical.h"
|
|
|
|
#undef YYSTYPE
|
|
|
|
#undef YYLTYPE
|
|
|
|
|
|
|
|
int ParseConfigFile(const char* config)
|
|
|
|
{
|
|
|
|
yyscan_t scanner;
|
|
|
|
struct lexical_extra extra;
|
|
|
|
FILE* conffd;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
conffd=fopen(config,"r");
|
|
|
|
if(conffd==0)
|
|
|
|
{
|
|
|
|
COUT(ERROR)<<"Can't open file "<<config<<std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
extra.maxinclevel=10;
|
|
|
|
extra.retcode=0;
|
|
|
|
extra.state.inclevel=0;
|
|
|
|
extra.state.curline=1;
|
|
|
|
extra.state.curpos=extra.state.curoffset=0;
|
|
|
|
char* cwd=get_current_dir_name();
|
|
|
|
extra.state.curdir=cwd;
|
|
|
|
free(cwd);
|
|
|
|
extra.ParsePath(config);
|
|
|
|
|
|
|
|
conflex_init_extra(&extra,&scanner);
|
|
|
|
confset_in(conffd,scanner);
|
|
|
|
// {YYSTYPE qqq; while(conflex(&qqq,scanner)>0);}
|
|
|
|
ret=confparse(scanner);
|
|
|
|
conflex_destroy(scanner);
|
|
|
|
fclose(conffd);
|
|
|
|
return ret+extra.retcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int RegisterArifmeticFunctions()
|
|
|
|
{
|
|
|
|
RegisterFunction("ADD",Arifm_Add);
|
|
|
|
RegisterFunction("SUB",Arifm_Sub);
|
|
|
|
RegisterFunction("MUL",Arifm_Mul);
|
|
|
|
RegisterFunction("DIV",Arifm_Div);
|
|
|
|
RegisterFunction("POW",Arifm_Pow);
|
|
|
|
RegisterFunction("POS",Arifm_Pos);
|
|
|
|
RegisterFunction("NEG",Arifm_Neg);
|
|
|
|
|
|
|
|
RegisterFunction("GET",Get<ObjectList>);
|
|
|
|
RegisterFunction("GET",Get<ObjectPair>);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int BuildDepTree(DepTree* deptree, UsedType& used)
|
|
|
|
{
|
|
|
|
return deptree->CreateGlobalTree(used);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CheckFunctions()
|
|
|
|
{
|
|
|
|
UsedType 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()
|
|
|
|
{
|
|
|
|
for(auto& i: G_vars) COUT(INFO)<<i.first<<"="+i.second->Dump()<<";"<<std::endl;
|
|
|
|
for(auto& i: G_tosave) COUT(INFO)<<"save"<<i->Dump()<<";"<<std::endl;
|
|
|
|
for(auto& i: G_toprint) COUT(INFO)<<"print"<<i->Dump()<<";"<<std::endl;
|
|
|
|
}
|