Changeset: d12fc065d77e for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=d12fc065d77e Modified Files: monetdb5/mal/mal_parser.c monetdb5/mal/mal_private.h monetdb5/mal/mal_scenario.c monetdb5/mal/mal_session.c monetdb5/modules/mal/orderidx.c monetdb5/modules/mal/remote.c sql/backends/monet5/sql_execute.c sql/backends/monet5/sql_gencode.c sql/backends/monet5/sql_optimizer.c sql/backends/monet5/sql_scenario.c sql/scripts/25_debug.sql Branch: malparsing Log Message:
Avoid showing exceptions directly diffs (truncated from 352 to 300 lines): diff --git a/monetdb5/mal/mal_parser.c b/monetdb5/mal/mal_parser.c --- a/monetdb5/mal/mal_parser.c +++ b/monetdb5/mal/mal_parser.c @@ -1321,7 +1321,7 @@ parseCommandPattern(Client cntxt, int ki cntxt->backup = 0; return (MalBlkPtr) parseError(cntxt, "<module> not found\n"); } - chkProgram(cntxt->fdout, cntxt->nspace, curBlk); + chkProgram(cntxt->nspace, curBlk); if (cntxt->backup) { cntxt->curprg = cntxt->backup; cntxt->backup = 0; @@ -1450,7 +1450,7 @@ parseEnd(Client cntxt) insertSymbol(cntxt->nspace, cntxt->curprg); cntxt->blkmode = 0; curBlk->typefixed = 0; - chkProgram(cntxt->fdout, cntxt->nspace, cntxt->curprg->def); + chkProgram(cntxt->nspace, cntxt->curprg->def); if (cntxt->backup) { cntxt->curprg = cntxt->backup; cntxt->backup = 0; diff --git a/monetdb5/mal/mal_private.h b/monetdb5/mal/mal_private.h --- a/monetdb5/mal/mal_private.h +++ b/monetdb5/mal/mal_private.h @@ -64,7 +64,7 @@ #ifdef MAXSCOPE /* MAXSCOPE is defined in the same file as Module */ -__hidden Symbol cloneFunction(stream *out, Module scope, Symbol proc, MalBlkPtr mb, InstrPtr p) +__hidden Symbol cloneFunction(Module scope, Symbol proc, MalBlkPtr mb, InstrPtr p) __attribute__((__visibility__("hidden"))); #endif __hidden int getBarrierEnvelop(MalBlkPtr mb) diff --git a/monetdb5/mal/mal_scenario.c b/monetdb5/mal/mal_scenario.c --- a/monetdb5/mal/mal_scenario.c +++ b/monetdb5/mal/mal_scenario.c @@ -90,9 +90,6 @@ * defined for code modules in general. * */ -/* - * @- - */ #include "monetdb_config.h" #include "mal_scenario.h" #include "mal_linker.h" /* for getAddress() */ @@ -112,7 +109,8 @@ static struct SCENARIO scenarioRec[MAXSC 0, 0, /* implicit */ "MALinitClient", (MALfcn) &MALinitClient, "MALexitClient", (MALfcn) &MALexitClient, - "MALreader", (MALfcn) &MALreader, 0, + //"MALreader", (MALfcn) &MALreader, 0, + "MALreader", 0,0, "MALparser", (MALfcn) &MALparser, 0, "MALoptimizer", 0, 0, 0, 0, 0, @@ -533,25 +531,20 @@ runScenarioBody(Client c) c->mode = FINISHCLIENT; while ((c->mode > FINISHCLIENT || msg != MAL_SUCCEED) && !GDKexiting()) { if (msg != MAL_SUCCEED){ -/* we should actually show it [postponed] mnstr_printf(c->fdout,"!%s\n",msg); -*/ freeException(msg); msg = MAL_SUCCEED; } - if (!c->state[0] && - (msg = runPhase(c, MAL_SCENARIO_INITCLIENT)) != MAL_SUCCEED) + if (( !c->state[0] && + (msg = runPhase(c, MAL_SCENARIO_INITCLIENT)) != MAL_SUCCEED) || c->mode <= FINISHCLIENT) continue; - if (c->mode <= FINISHCLIENT || - (msg = runPhase(c, MAL_SCENARIO_READER)) != MAL_SUCCEED) + if ( (msg = runPhase(c, MAL_SCENARIO_READER)) != MAL_SUCCEED || c->mode <= FINISHCLIENT) continue; c->lastcmd= time(0); start= GDKusec(); - if (c->mode <= FINISHCLIENT || - (msg = runPhase(c, MAL_SCENARIO_PARSER)) != MAL_SUCCEED) + if ( (msg = runPhase(c, MAL_SCENARIO_PARSER)) != MAL_SUCCEED || c->mode <= FINISHCLIENT || c->blkmode) continue; - if (c->mode <= FINISHCLIENT || - (msg = runPhase(c, MAL_SCENARIO_OPTIMIZE)) != MAL_SUCCEED) + if ( (msg = runPhase(c, MAL_SCENARIO_OPTIMIZE)) != MAL_SUCCEED || c->mode <= FINISHCLIENT) continue; if (c->mode <= FINISHCLIENT || (msg = runPhase(c, MAL_SCENARIO_SCHEDULER)) != MAL_SUCCEED) diff --git a/monetdb5/mal/mal_session.c b/monetdb5/mal/mal_session.c --- a/monetdb5/mal/mal_session.c +++ b/monetdb5/mal/mal_session.c @@ -58,7 +58,7 @@ malBootstrap(void) return 0; } pushEndInstruction(c->curprg->def); - chkProgram(c->fdout, c->nspace, c->curprg->def); + chkProgram(c->nspace, c->curprg->def); if (c->curprg->def->errors) { showErrors(c); #ifdef HAVE_EMBEDDED @@ -545,6 +545,7 @@ MALreader(Client c) { #ifndef HAVE_EMBEDDED int r = 1; + return MAL_SUCCEED; if (c == mal_clients) { r = readConsole(c); if (r < 0 && c->fdin->eof == 0) @@ -560,23 +561,107 @@ MALreader(Client c) MT_lock_unset(&mal_contextLock); if (c->fdin) c->fdin->buf[c->fdin->pos] = 0; +/* else throw(MAL, "mal.reader", RUNTIME_IO_EOF); +*/ return MAL_SUCCEED; } +static str +MALreadline(Client c) +{ str s,l; + size_t sz; + int string = 0; + + if ( c->line == NULL){ + c->line = GDKzalloc(8192); + if( c->line == NULL) + throw(MAL,"mal.readline", MAL_MALLOC_FAIL); + c->linesize = 8192; + c->linefill = 0; + } + do{ + if( c->fdin->pos >= c->fdin->len){ + if( c->prompt){ + mnstr_write(c->fdout, c->prompt, strlen(c->prompt), 1); + mnstr_flush(c->fdout); + } + sz= bstream_next(c->fdin); + if( c->fdin->eof) + return MAL_SUCCEED; + if ( sz >= c->linesize){ + l = GDKrealloc(c->line, c->linesize + sz + 512); + if( l == NULL) + throw(MAL,"mal.readline", MAL_MALLOC_FAIL); + c->line = l; + c->linesize += sz + 512; + } + } + // read until you find a complete MAL unit + s = c->line + c->linefill; + for( l = c->fdin->buf + c->fdin->pos ; c->fdin->pos < c->fdin->len ; l++){ + if ( *l == '"' ){ + if ( string == 0) + string = 1; + else + if ( string && *(l-1) != '\\') + string = !string; + } + *s++ = *l; + c->linefill++; + c->fdin->pos++; + if( *l == '#' && string ==0){ + // eat away until end of line + for( l++ ; c->fdin->pos < c->fdin->len ; l++){ + *s++ = *l; + c->linefill++; + c->fdin->pos++; + if ( *l == '\n') + break; + } + *s = 0; + return MAL_SUCCEED; + } + if (*l == ';' && string ==0){ + // eat away until end of line + for( l++ ; c->fdin->pos < c->fdin->len ; l++){ + *s++ = *l; + c->linefill++; + c->fdin->pos++; + if ( *l == '\n') + break; + } + *s = 0; + return MAL_SUCCEED; + } + } + *s = 0; + } while ( c->fdin->eof == 0); + + return MAL_SUCCEED; +} +/* + * The parser should parse a complete MAL unit + * This is either signature, MAL function block, guarded block, or single statement + * Syntax checking is performed on line by line basis and sent to the output channel. + * Type checking is the last step in this process. + */ str MALparser(Client c) { InstrPtr p; MalBlkRecord oldstate; + str msg; c->curprg->def->errors = 0; oldstate = *c->curprg->def; - if( prepareMalBlk(c->curprg->def, CURRENT(c))){ - throw(MAL, "mal.parser", MAL_MALLOC_FAIL); + while( (msg = MALreadline(c)) == MAL_SUCCEED && c->linefill){ + fprintf(stderr, "%s",c->line); + c->linefill = 0; } + if (parseMAL(c, c->curprg, 0) || c->curprg->def->errors) { /* just complete it for visibility */ pushEndInstruction(c->curprg->def); @@ -612,7 +697,7 @@ MALparser(Client c) throw(SYNTAX, "mal.parser", SYNTAX_SIGNATURE); } pushEndInstruction(c->curprg->def); - chkProgram(c->fdout, c->nspace, c->curprg->def); + chkProgram(c->nspace, c->curprg->def); if (c->curprg->def->errors) { showErrors(c); if (c->listing) diff --git a/monetdb5/modules/mal/orderidx.c b/monetdb5/modules/mal/orderidx.c --- a/monetdb5/modules/mal/orderidx.c +++ b/monetdb5/modules/mal/orderidx.c @@ -152,7 +152,7 @@ OIDXcreateImplementation(Client cntxt, i q->barrier = EXITsymbol; q->argv[0] = loopvar; pushEndInstruction(smb); - chkProgram(cntxt->fdout, cntxt->nspace, smb); + chkProgram(cntxt->nspace, smb); //printFunction(THRdata[0], smb, 0 , 23); if (smb->errors) { msg = createException(MAL, "bat.orderidx", diff --git a/monetdb5/modules/mal/remote.c b/monetdb5/modules/mal/remote.c --- a/monetdb5/modules/mal/remote.c +++ b/monetdb5/modules/mal/remote.c @@ -820,7 +820,7 @@ str RMTregisterInternal(Client cntxt, st mapi_close_handle(mhdl); /* make sure the program is error free */ - chkProgram(cntxt->fdout, cntxt->nspace, sym->def); + chkProgram(cntxt->nspace, sym->def); if (sym->def->errors) { MT_lock_unset(&c->lock); throw(MAL, "remote.register", diff --git a/sql/backends/monet5/sql_execute.c b/sql/backends/monet5/sql_execute.c --- a/sql/backends/monet5/sql_execute.c +++ b/sql/backends/monet5/sql_execute.c @@ -73,6 +73,7 @@ SQLsetTrace(Client cntxt, MalBlkPtr mb) InstrPtr q, resultset; InstrPtr tbls, cols, types, clen, scale; int k; + str msg; startTrace("sql_traces"); clearTrace(); @@ -176,7 +177,10 @@ SQLsetTrace(Client cntxt, MalBlkPtr mb) pushInstruction(mb,resultset); pushEndInstruction(mb); - chkTypes(cntxt->fdout, cntxt->nspace, mb, TRUE); + msg = chkTypes(cntxt->nspace, mb, TRUE); + // FIXIT return as proper error + if(msg) + GDKfree(msg); } /* diff --git a/sql/backends/monet5/sql_gencode.c b/sql/backends/monet5/sql_gencode.c --- a/sql/backends/monet5/sql_gencode.c +++ b/sql/backends/monet5/sql_gencode.c @@ -217,7 +217,7 @@ static int if( curBlk->inlineProp == 0) SQLoptimizeQuery(c, c->curprg->def); else{ - chkProgram(c->fdout, c->nspace, c->curprg->def); + chkProgram(c->nspace, c->curprg->def); SQLoptimizeFunction(c,c->curprg->def); } if (backup) @@ -431,7 +431,7 @@ static int //curBlk->inlineProp = 1; SQLaddQueryToCache(c); - //chkProgram(c->fdout, c->nspace, c->curprg->def); + //chkProgram(c->nspace, c->curprg->def); SQLoptimizeFunction(c, c->curprg->def); if (backup) c->curprg = backup; @@ -910,7 +910,7 @@ backend_create_sql_func(backend *be, sql if( curBlk->inlineProp == 0) SQLoptimizeFunction(c, c->curprg->def); else{ - chkProgram(c->fdout, c->nspace, c->curprg->def); + chkProgram(c->nspace, c->curprg->def); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list