X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=idl%2Fparser.re;h=5a060232ab29a715cac7b9f4aecad08d59d2e476;hp=7b7b1c590163a689dc253d7d1d2a50fcf5577317;hb=9e0411db099e71409f0ee8a8f464aa34ac65c778;hpb=69008ba2a7733358974c8985caa2e5bcb1182fe1;ds=sidebyside diff --git a/idl/parser.re b/idl/parser.re index 7b7b1c5..5a06023 100644 --- a/idl/parser.re +++ b/idl/parser.re @@ -2,8 +2,13 @@ #include #include "parser.h" +#include "parser_proc.h" -PSI_Parser *PSI_ParserInit(PSI_Parser *P) +void *PSI_ParserProcAlloc(void*(unsigned long)); +void PSI_ParserProcFree(void*, void(*)(void*)); +void PSI_ParserProc(void *, token_t, PSI_Token *, PSI_Parser *); + +PSI_Parser *PSI_ParserInit(PSI_Parser *P, const char *filename) { FILE *fp; @@ -31,6 +36,8 @@ PSI_Parser *PSI_ParserInit(PSI_Parser *P) P->proc = PSI_ParserProcAlloc(malloc); PSI_ParserFill(P, 0); + + return P; } size_t PSI_ParserFill(PSI_Parser *P, size_t n) @@ -68,43 +75,25 @@ size_t PSI_ParserFill(PSI_Parser *P, size_t n) return P->lim - P->cur; } -int PSI_ParserParse(PSI_Parser *P) +void PSI_ParserParse(PSI_Parser *P, PSI_Token *T) { - PSI_Token *T = NULL; - - if (-1 == PSI_ParserScan(P)) { + if (T) { + PSI_ParserProc(P->proc, T->type, T, P); + } else { PSI_ParserProc(P->proc, 0, NULL, P); - return 0; - } - if (!(T = PSI_TokenAlloc(P, t))) { - return 0; } - - PSI_ParserProc(P->proc, P->num, T, P); - return 1; } void PSI_ParserDtor(PSI_Parser *P) { PSI_ParserProcFree(P->proc, free); + if (P->fp) { fclose(P->fp); } - if (P->fn) { - free(P->fn); - } - if (P->lib) { - free(P->lib); - } - if (P->defs) { - free_decl_typedefs(P->defs); - } - if (P->decls) { - free_decls(P->decls); - } - if (P->impls) { - free_impls(P->impls); - } + + PSI_DataDtor((PSI_Data *) P); + memset(P, 0, sizeof(*P)); } @@ -127,7 +116,8 @@ void PSI_ParserFree(PSI_Parser **P) #define RETURN(t) do { \ P->num = t; \ return t; \ -} +} while(1) + token_t PSI_ParserScan(PSI_Parser *P) { for (;;) { @@ -138,7 +128,7 @@ token_t PSI_ParserScan(PSI_Parser *P) re2c:define:YYCURSOR = P->cur; re2c:define:YYLIMIT = P->lim; re2c:define:YYMARKER = P->mrk; - re2c:define:YYFILL = "{ if (!fill(P,@@)) RETURN(-1); }"; + re2c:define:YYFILL = "{ if (!PSI_ParserFill(P,@@)) RETURN(-1); }"; re2c:yyfill:parameter = 0; B = [^a-zA-Z0-9_];