Changeset: b2550d6d9ce8 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=b2550d6d9ce8
Modified Files:
monetdb5/mal/mal_exception.c
monetdb5/mal/mal_function.c
monetdb5/mal/mal_import.c
monetdb5/mal/mal_instruction.c
monetdb5/mal/mal_parser.c
monetdb5/mal/mal_session.c
Branch: malparsing
Log Message:
Several small fixes
- mal_function, spurious 'else'
- mal_parser, keep the old error messages around and return to caller
- mal_parser, better layout of parse errors
- mal_exception, formatting the parse errors differently
- *, keep track of usermodule
diffs (279 lines):
diff --git a/monetdb5/mal/mal_exception.c b/monetdb5/mal/mal_exception.c
--- a/monetdb5/mal/mal_exception.c
+++ b/monetdb5/mal/mal_exception.c
@@ -203,6 +203,10 @@ createMalExceptionInternal(MalBlkPtr mb,
i += snprintf(buf + i, GDKMAXERRLEN - 1 - i, "!%s:%s.%s[%d]:",
exceptionNames[type], s, fcn, pc);
} else
+ if( type == SYNTAX)
+ i += snprintf(buf + i, GDKMAXERRLEN - 1 - i, "%s:",
+ exceptionNames[type]);
+ else
i += snprintf(buf + i, GDKMAXERRLEN - 1 - i, "%s:%s.%s[%d]:",
exceptionNames[type], s, fcn, pc);
i += vsnprintf(buf + i, GDKMAXERRLEN - 1 - i, format, ap);
diff --git a/monetdb5/mal/mal_function.c b/monetdb5/mal/mal_function.c
--- a/monetdb5/mal/mal_function.c
+++ b/monetdb5/mal/mal_function.c
@@ -102,6 +102,7 @@ chkFlow(MalBlkPtr mb)
case CATCHsymbol:
if(btop== DEPTH){
mb->errors = createException(MAL,"chkFlow", "Too
many nested MAL blocks");
+ return;
}
pc[btop]= i;
v= var[btop]= getDestVar(p);
@@ -113,7 +114,6 @@ chkFlow(MalBlkPtr mb)
"recursive %s[%d] shields %s[%d]",
getVarName(mb,v), pc[j],
getFcnName(mb),pc[i]);
-
return;
}
@@ -130,7 +130,6 @@ chkFlow(MalBlkPtr mb)
mb->errors = createMalException(mb,i,SYNTAX,
"exit-label '%s' without begin-label",
getVarName(mb,v));
-
continue;
}
/* search the matching block */
@@ -160,7 +159,7 @@ chkFlow(MalBlkPtr mb)
str nme=getVarName(mb,v);
mb->errors = createMalException(mb,i,SYNTAX,
"label '%s' not in guarded block", nme);
- } else
+ }
break;
case YIELDsymbol:
{ InstrPtr ps= getInstrPtr(mb,0);
@@ -193,8 +192,11 @@ chkFlow(MalBlkPtr mb)
}
}
}
+ if( btop == 0)
+ retseen =1;
break;
case RAISEsymbol:
+ endseen = 1;
break;
case ENDsymbol:
endseen =1;
@@ -211,6 +213,7 @@ chkFlow(MalBlkPtr mb)
}
}
}
+
if(msg == MAL_SUCCEED && lastInstruction < mb->stop-1 ){
mb->errors = createMalException( mb,lastInstruction,SYNTAX,
"instructions after END");
diff --git a/monetdb5/mal/mal_import.c b/monetdb5/mal/mal_import.c
--- a/monetdb5/mal/mal_import.c
+++ b/monetdb5/mal/mal_import.c
@@ -115,7 +115,7 @@ evalFile(Client cntxt, str fname, int li
if (fd == 0 || mnstr_errnr(fd) == MNSTR_OPEN_ERROR) {
if(fd) mnstr_destroy(fd);
GDKfree(base);
- throw(MAL,"mal.import", "#WARNING: could not open file:
%s\n", fname);
+ throw(MAL,"mal.import", "#WARNING: could not open file:
%s\n", files[i]);
}
if( included){
@@ -131,10 +131,11 @@ evalFile(Client cntxt, str fname, int li
fprintf(stderr,"load file %s using new
client\n",files[i]);
#endif
c = MCinitClient((oid)0,bstream_create(fd, 32 *
BLOCK),0);
- c->usermodule = userModule();
+ c->curmodule = c->usermodule = userModule();
GDKfree(c->prompt);
c->prompt= NULL;
c->promptlength = 0;
+ c->blkmode = 1; // collect all statements
msg = defaultScenario(c);
if( msg == MAL_SUCCEED){
(void) MSinitClientPrg(c, "user", "main"); /*
create new context */
@@ -199,7 +200,7 @@ compileString(Client cntxt, str s)
c = MCinitClient((oid)0,0,0);
c->fdin = bstream_create(buffer_rastream(b, "compileString"), b->len);
strncpy(c->fdin->buf,s,len);
- c->usermodule = userModule();
+ c->curmodule = c->usermodule = userModule();
GDKfree(c->prompt);
c->prompt= NULL;
c->promptlength = 0;
@@ -217,12 +218,8 @@ compileString(Client cntxt, str s)
chkProgram(c->usermodule, c->curprg->def);
}
c->fdout = 0;
- freeMalBlk(cntxt->curprg->def);
- cntxt->curprg->def = copyMalBlk(c->curprg->def);
- if( cntxt->curprg->def == NULL){
- MCcloseClient(c);
- throw(MAL,"compileString", MAL_MALLOC_FAIL);
- }
+ cntxt->curprg = c->curprg;
+ c->curprg = 0;
MCcloseClient(c);
return MAL_SUCCEED;
}
diff --git a/monetdb5/mal/mal_instruction.c b/monetdb5/mal/mal_instruction.c
--- a/monetdb5/mal/mal_instruction.c
+++ b/monetdb5/mal/mal_instruction.c
@@ -1352,15 +1352,19 @@ destinationType(MalBlkPtr mb, InstrPtr p
inline void
setPolymorphic(InstrPtr p, int tpe, int force)
{
- int c2;
+ int c1= 0, c2=0;
if (force == FALSE && tpe == TYPE_any)
return;
- if (getBatType(tpe) == TYPE_any){
+ if (isaBatType(tpe))
+ c1 =TYPE_oid;
+ if (getTypeIndex(tpe) > 0)
c2 = getTypeIndex(tpe);
- if( c2 > 0 && c2 > p->polymorphic)
- p->polymorphic = c2 + 1;
- }
+ else if (getBatType(tpe) == TYPE_any)
+ c2 = 1;
+ c1 = c1 > c2 ? c1: c2;
+ if( c1 > 0 && c1 >= p->polymorphic)
+ p->polymorphic = c1 + 1;
}
/* Instructions are simply appended to a MAL block. It should always succeed.
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
@@ -38,22 +38,35 @@ static void
parseError(Client cntxt, str msg)
{
MalBlkPtr mb = cntxt->curprg->def;
- char *old, *new;
+ char *old, *new, *exception;
+ char *s, *t;
+ exception = createMalException( mb, mb->stop, SYNTAX,
+ "^%d %s", (int)(cntxt->lineptr - cntxt->line), msg);
old = mb->errors;
+ new = GDKzalloc((old? strlen(old):0) + strlen(exception) +
strlen(cntxt->line) + strlen(msg) + 64);
+ if (new == NULL){
+ freeException(exception);
+ return ; // just stick to one error message
+ }
if( old){
- new = GDKzalloc(strlen(old) + cntxt->linefill + strlen(msg) +
64);
- if (new == NULL)
- return ; // just stick to one error message
strcpy(new, old);
- strcat(new, msg);
- mb->errors = createMalException( mb, mb->stop, SYNTAX,
- "^%d %s", (int)(cntxt->lineptr - cntxt->line), new);
+ strcat(new,"!");
GDKfree(old);
- GDKfree(new);
- } else
- mb->errors = createMalException( mb, mb->stop, SYNTAX,
- "^%d %s", (int)(cntxt->lineptr - cntxt->line), msg);
+ }
+ strcat(new,"SyntaxException:");
+ for( s = new + strlen(new), t = cntxt->line; *t; s++, t++)
+ if ( *t == '\n')
+ *s = ' ';
+ else
+ *s = *t;
+ if( cntxt->line[strlen(cntxt->line)-1] =='\n')
+ strcat(new, "!");
+ else
+ strcat(new, "\n!");
+ strcat(new, exception);
+ mb->errors = new;
+ freeException(exception);
}
static inline void
@@ -953,6 +966,7 @@ fcnHeader(Client cntxt, int kind)
curInstr = getInstrPtr(cntxt->curprg->def,0);
setModuleId(curInstr,modnme);
setFunctionId(curInstr,fnme);
+ curInstr->token = kind;
cntxt->curprg->kind = kind;
/* get calling parameters */
@@ -1459,7 +1473,7 @@ int
parseMAL(Client cntxt)
{ int cntrl = 0;
int inlineProp =0, unsafeProp = 0, sealedProp = 0;
- str msg;
+ str msg, oldmsg;
cntxt->lineptr = cntxt->line;
skipSpace(cntxt);
@@ -1493,9 +1507,10 @@ parseMAL(Client cntxt)
if (inlineProp)
parseError(cntxt,
"parseError:INLINE ignored");
chkProgram(cntxt->usermodule,
cntxt->curprg->def);
- if( cntxt->curprg->def->errors)
- parseError(cntxt,"Program
contains errors\n");
+ oldmsg = cntxt->curprg->def->errors;
+ cntxt->curprg->def->errors = 0;
msg = MSinitClientPrg(cntxt, "user",
"main");
+ cntxt->curprg->def->errors = oldmsg;
if( msg != MAL_SUCCEED)
parseError(cntxt,msg);
}
@@ -1579,9 +1594,10 @@ parseMAL(Client cntxt)
unsafeProp = 0;
sealedProp = 0;
chkProgram(cntxt->usermodule,
cntxt->curprg->def);
- if( cntxt->curprg->def->errors)
- parseError(cntxt,"Program
contains errors\n");
+ oldmsg = cntxt->curprg->def->errors;
+ cntxt->curprg->def->errors = 0;
msg = MSinitClientPrg(cntxt,
"user","main");
+ cntxt->curprg->def->errors = oldmsg;
if( msg != MAL_SUCCEED)
parseError(cntxt,msg);
}
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
@@ -636,14 +636,17 @@ MALreader(Client c)
mnstr_printf(c->fdout,"%c", *l);
if( string)
continue;
- if ( *l == ';' || *l == '#'){
- if ( *l == '#' ){
- c->linefill--;
- s--;
- }
+ if ( *l == ';' ){
+ *s = 0;
+ return MAL_SUCCEED;
+ }
+
+ if ( *l == '#' ){
+ c->linefill--;
+ s--;
*s = 0;
// eat everything away until end of line
- for( l++ ; c->fdin->pos < c->fdin->len ; l++){
+ for( l++ ; *l && c->fdin->pos < c->fdin->len ;
l++){
if ( c->listing)
mnstr_printf(c->fdout,"%c", *l);
c->fdin->pos++;
@@ -701,9 +704,10 @@ MALparser(Client cntxt)
// Handle compound MAL blocks before execution
// There are three cases: a MAL function block, a barrier block or
single statement
// nested blocks are recognized by the blkmode depth
+ /* empty blocks should be skipped as well */
if (cntxt->blkmode)
return MAL_SUCCEED;
- /* empty blocks should be skipped as well */
+
if (cntxt->curprg->def->stop == 1)
return MAL_SUCCEED;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list