Changeset: 1398c7821abd for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1398c7821abd
Modified Files:
        monetdb5/mal/Tests/tst010.malC
        monetdb5/mal/Tests/tst010.stable.err
        monetdb5/mal/Tests/tst019.stable.err
        monetdb5/mal/Tests/tst054.stable.err
        monetdb5/mal/Tests/tst804.stable.err
        monetdb5/mal/mal_exception.c
        monetdb5/mal/mal_function.c
        monetdb5/mal/mal_parser.c
        monetdb5/mal/mal_session.c
Branch: malerrors
Log Message:

Fix the error handling at mal interpreter level


diffs (truncated from 383 to 300 lines):

diff --git a/monetdb5/mal/Tests/tst010.malC b/monetdb5/mal/Tests/tst010.malC
--- a/monetdb5/mal/Tests/tst010.malC
+++ b/monetdb5/mal/Tests/tst010.malC
@@ -1,6 +1,6 @@
 # syntax analysis test for guarded blocks, redo's and leave's
 # forcefully end the block, because the parser counts barrier/exit pairs
-# function foo();
+function foo();
 barrier        L:= 1;
        #do it
        leave Z;        # not known in block
diff --git a/monetdb5/mal/Tests/tst010.stable.err 
b/monetdb5/mal/Tests/tst010.stable.err
--- a/monetdb5/mal/Tests/tst010.stable.err
+++ b/monetdb5/mal/Tests/tst010.stable.err
@@ -33,7 +33,7 @@ stderr of test 'tst010` in directory 'mo
 MAPI  = (monetdb) /var/tmp/mtest-7831/.s.monetdb.38226
 QUERY = # syntax analysis test for guarded blocks, redo's and leave's
         # forcefully end the block, because the parser counts barrier/exit 
pairs
-        # function foo();
+        function foo();
         barrier        L:= 1;
                #do it
                leave Z;        # not known in block
@@ -69,15 +69,15 @@ QUERY = # syntax analysis test for guard
                f:=1;
         end;
         end foo;
-ERROR = !SyntaxException:user.main[6]:label 'Z' not in guarded block
-        !SyntaxException:user.main[10]:label 'L' not in guarded block
-        !SyntaxException:user.main[12]:label 'X' not in guarded block
-        !SyntaxException:user.main[14]:label 'A' not in guarded block
-        !SyntaxException:user.main[17]:label 'L' not in guarded block
-        !SyntaxException:user.main[20]:label 'L' not in guarded block
-        !SyntaxException:user.main[30]:exit-label 'B' doesnot match 'A'
-        !SyntaxException:user.main[32]:exit-label 'F' without begin-label
-        !SyntaxException:user.main[42]:exit-label 'A' without begin-label
+ERROR = !MALException:user.foo[3]:label 'Z' not in guarded block
+        !MALException:user.foo[7]:label 'L' not in guarded block
+        !MALException:user.foo[9]:label 'X' not in guarded block
+        !MALException:user.foo[11]:label 'A' not in guarded block
+        !MALException:user.foo[14]:label 'L' not in guarded block
+        !MALException:user.foo[17]:label 'L' not in guarded block
+        !MALException:user.foo[27]:exit-label 'B' doesnot match 'A'
+        !MALException:user.foo[29]:exit-label 'F' without begin-label
+        !MALException:user.foo[39]:exit-label 'A' without begin-label
         !SyntaxException:parseError:end foo;
         !SyntaxException:parseError:   ^non matching end label
 
diff --git a/monetdb5/mal/Tests/tst019.stable.err 
b/monetdb5/mal/Tests/tst019.stable.err
--- a/monetdb5/mal/Tests/tst019.stable.err
+++ b/monetdb5/mal/Tests/tst019.stable.err
@@ -77,7 +77,7 @@ QUERY = function welcome(lim:int):void;
         (x,y):= user.welcome2(1);
 ERROR = !TypeException:user.welcome[3]:type mismatch void := str
         !TypeException:user.welcome0[3]:Multiple assignment mismatch
-        !SyntaxException:user.welcome3[2]:invalid return target!
+        !MALException:user.welcome3[2]:invalid return target!
         !TypeException:user.welcome4[2]:Multiple assignment mismatch
         !TypeException:user.main[5]:'user.welcome2' undefined in:     (x:any, 
y:str) := user.welcome2(1:int);
 
diff --git a/monetdb5/mal/Tests/tst054.stable.err 
b/monetdb5/mal/Tests/tst054.stable.err
--- a/monetdb5/mal/Tests/tst054.stable.err
+++ b/monetdb5/mal/Tests/tst054.stable.err
@@ -78,6 +78,7 @@ QUERY = function z()( :int,:int,:int,:in
         z();
 ERROR = !SyntaxException:parseError:return 
(1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0);
         !SyntaxException:parseError:        ^<identifier> expected
+        !MALException:user.z[2]:invalid return target!
         !TypeException:user.main[1]:'user.z' undefined in:     user.z();
 
 # 11:11:08 >  
diff --git a/monetdb5/mal/Tests/tst804.stable.err 
b/monetdb5/mal/Tests/tst804.stable.err
--- a/monetdb5/mal/Tests/tst804.stable.err
+++ b/monetdb5/mal/Tests/tst804.stable.err
@@ -45,6 +45,7 @@ ERROR = !SyntaxException:parseError:func
         !SyntaxException:parseError:end message;
         !SyntaxException:parseError:   ^non matching end label
         !TypeException:user.foo[1]:'wrong.message' undefined in:     
wrong.message();
+        !TypeException:user.foo[2]:'wrongTo.message' undefined in:     
wrongTo.message();
 
 # 15:26:53 >  
 # 15:26:53 >  "Done."
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
@@ -212,6 +212,8 @@ createMalExceptionInternal(MalBlkPtr mb,
                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);
+       if( buf[i-1] != '\n')
+               buf[i++]= '\n';
        buf[i] = '\0';
 
        s = GDKstrdup(buf);
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
@@ -189,7 +189,7 @@ void chkFlow(MalBlkPtr mb)
                                                }
                                        }
                        }
-                       if (btop == 0)
+                       //if (btop == 0)
                                retseen = 1;
                        break;
            case RAISEsymbol:
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
@@ -802,12 +802,11 @@ helpInfo(Client cntxt, str *help)
                        *help = strCopy(cntxt, l);
                        if (*help)
                                advance(cntxt, l - 1);
-               } else {
+                       skipToEnd(cntxt);
+               } else 
                        parseError(cntxt, "<string> expected\n");
-               }
        } else if (currChar(cntxt) != ';')
                parseError(cntxt, "';' expected\n");
-       skipToEnd(cntxt);
 }
 
 static InstrPtr
@@ -1032,7 +1031,6 @@ parseInclude(Client cntxt)
 
        if (currChar(cntxt) != ';') {
                parseError(cntxt, "';' expected\n");
-               skipToEnd(cntxt);
                return 0;
        }
        skipToEnd(cntxt);
@@ -1086,7 +1084,6 @@ fcnHeader(Client cntxt, int kind)
                l = idLength(cntxt);
        if (l == 0) {
                parseError(cntxt, "<identifier> | <operator> expected\n");
-               skipToEnd(cntxt);
                return 0;
        }
 
@@ -1098,7 +1095,6 @@ fcnHeader(Client cntxt, int kind)
                modnme = fnme;
                if( strcmp(modnme,"user") && getModule(modnme) == NULL){
                        parseError(cntxt, "<module> name not defined\n");
-                       skipToEnd(cntxt);
                        return 0;
                }
                l = operatorLength(cntxt);
@@ -1106,7 +1102,6 @@ fcnHeader(Client cntxt, int kind)
                        l = idLength(cntxt);
                if (l == 0){
                        parseError(cntxt, "<identifier> | <operator> 
expected\n");
-                       skipToEnd(cntxt);
                        return 0;
                }
                fnme = putNameLen(((char *) CURRENT(cntxt)), l);
@@ -1117,12 +1112,10 @@ fcnHeader(Client cntxt, int kind)
        /* temporary suspend capturing statements in main block */
        if (cntxt->backup){
                parseError(cntxt, "mal_parser: unexpected recursion\n");
-               skipToEnd(cntxt);
                return 0;
        }
        if (currChar(cntxt) != '('){
                parseError(cntxt, "function header '(' expected\n");
-               skipToEnd(cntxt);
                return curBlk;
        }
        advance(cntxt, 1);
@@ -1156,7 +1149,6 @@ fcnHeader(Client cntxt, int kind)
                                curBlk = NULL;
                        }
                        parseError(cntxt, "',' expected\n");
-                       skipToEnd(cntxt);
                        return curBlk;
                } else
                        nextChar(cntxt);  /* skip ',' */
@@ -1164,7 +1156,7 @@ fcnHeader(Client cntxt, int kind)
                ch = currChar(cntxt);
        }
        if (currChar(cntxt) != ')') {
-               freeInstruction(curInstr);
+               pushInstruction(curBlk, curInstr);
                if (cntxt->backup) {
                        freeSymbol(cntxt->curprg);
                        cntxt->curprg = cntxt->backup;
@@ -1172,7 +1164,6 @@ fcnHeader(Client cntxt, int kind)
                        curBlk = NULL;
                }
                parseError(cntxt, "')' expected\n");
-               skipToEnd(cntxt);
                return curBlk;
        }
        advance(cntxt, 1); /* skip ')' */
@@ -1215,7 +1206,6 @@ fcnHeader(Client cntxt, int kind)
                                        curBlk = NULL;
                                }
                                parseError(cntxt, "',' expected\n");
-                               skipToEnd(cntxt);
                                return curBlk;
                        } else {
                                nextChar(cntxt); /* skip ',' */
@@ -1234,7 +1224,6 @@ fcnHeader(Client cntxt, int kind)
                                cntxt->backup = 0;
                                curBlk = NULL;
                        }
-                       skipToEnd(cntxt);
                        return curBlk;
                }
                for (i1 = retc; i1 < curInstr->argc; i1++)
@@ -1257,7 +1246,6 @@ fcnHeader(Client cntxt, int kind)
                                curBlk = NULL;
                        }
                        parseError(cntxt, "')' expected\n");
-                       skipToEnd(cntxt);
                        return curBlk;
                }
                nextChar(cntxt); /* skip ')' */
@@ -1291,7 +1279,7 @@ parseCommandPattern(Client cntxt, int ki
        curInstr = getInstrPtr(curBlk, 0);
 
        modnme = getModuleId(getInstrPtr(curBlk, 0));
-       if (modnme && getModule(modnme) == FALSE){
+       if (modnme && (getModule(modnme) == FALSE && strcmp(modnme,"user"))){
                parseError(cntxt, "<module> not defined\n");
                cntxt->blkmode = 0;
                return curBlk;
@@ -1431,28 +1419,48 @@ parseEnd(Client cntxt)
                }
                /* parse fcn */
                if ((l == (int) strlen(curPrg->name) &&
-                       strncmp(CURRENT(cntxt), curPrg->name, l) == 0) || l == 
0) {} else {
+                       strncmp(CURRENT(cntxt), curPrg->name, l) == 0) || l == 
0)
+                               advance(cntxt, l);
+               else 
                        parseError(cntxt, "non matching end label\n");
-               }
-               advance(cntxt, l);
                pushEndInstruction(cntxt->curprg->def);
                cntxt->blkmode = 0;
                if ( strcmp(getModuleId(sig),"user")== 0 )
                        insertSymbol(cntxt->usermodule, cntxt->curprg);
                else
                        insertSymbol(getModule(getModuleId(sig)), 
cntxt->curprg);
+
+               if (cntxt->curprg->def->errors) {
+                       errors = cntxt->curprg->def->errors;
+                       cntxt->curprg->def->errors=0;
+               }
                chkProgram(cntxt->usermodule, cntxt->curprg->def);
+               // check for newly identified errors
+               if (errors ==NULL){
+                       errors = cntxt->curprg->def->errors;
+                       cntxt->curprg->def->errors=0;
+               } else if( cntxt->curprg->def->errors){
+                       //collect all errors for reporting
+                       str new = GDKzalloc(strlen(errors) + 
strlen(cntxt->curprg->def->errors) +16);
+                       if( new){
+                               strcpy(new, errors);
+                               if( new[strlen(new)-1] != '\n')
+                                       strcat(new,"\n");
+                               strcat(new,"!");
+                               strcat(new,cntxt->curprg->def->errors);
+                               errors = new;
+                       }
+                       cntxt->curprg->def->errors=0;
+               }
                
-        if (cntxt->backup) 
-                       errors = GDKstrdup(cntxt->curprg->def->errors);
         if (cntxt->backup) {
             cntxt->curprg = cntxt->backup;
-                       cntxt->curprg->def->errors = errors;
             cntxt->backup = 0;
         }  else{
-                       (void) MSinitClientPrg(cntxt,"user","main");
-                       cntxt->curprg->def->errors = errors;
+                       (void) 
MSinitClientPrg(cntxt,cntxt->curmodule->name,"main");
                }
+               // pass collected errors to context
+               cntxt->curprg->def->errors = errors;
                return 1;
        }
        return 0;
@@ -1486,7 +1494,6 @@ parseArguments(Client cntxt, MalBlkPtr c
                default:
                        parseError(cntxt, "<factor> expected\n");
                        pushInstruction(curBlk, *curInstr);
-                       skipToEnd(cntxt);
                        return 1;
                }
                if (currChar(cntxt) == ',')
@@ -1532,8 +1539,7 @@ parseAssign(Client cntxt, int cntrl)
                        i = cstToken(cntxt, &cst);
                        if (l == 0 || i) {
                                parseError(cntxt, "<identifier> expected\n");
-                               skipToEnd(cntxt);
-                               freeInstruction(curInstr);
+                               pushInstruction(curBlk, curInstr);
                                return;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to