Changeset: a8d44f599588 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a8d44f599588
Modified Files:
        monetdb5/mal/mal_function.c
Branch: default
Log Message:

Postpone name generation until you need it


diffs (194 lines):

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
@@ -94,17 +94,15 @@ chkFlow(MalBlkPtr mb)
 {   int i,j,k, v,lastInstruction;
        int  pc[DEPTH];
        int  var[DEPTH];
-       char buf[IDLENGTH * 2 +2];
        InstrPtr stmt[DEPTH];
        int btop=0;
        int endseen=0, retseen=0, yieldseen=0;
-       InstrPtr p;
+       InstrPtr p, sig;
        str msg = MAL_SUCCEED;
 
        if ( mb->errors != MAL_SUCCEED)
                return mb->errors ;
-       p = getInstrPtr(mb, 0);
-       snprintf(buf, IDLENGTH * 2 +2, "%s.%s", getModuleId(p), 
getFunctionId(p));
+       sig = getInstrPtr(mb, 0);
        lastInstruction = mb->stop-1;
        for(i= 0; i<mb->stop; i++){
                p= getInstrPtr(mb,i);
@@ -114,23 +112,23 @@ chkFlow(MalBlkPtr mb)
                case BARRIERsymbol:
                case CATCHsymbol:
                        if(btop== DEPTH)
-                           throw(MAL,buf,"Too many nested MAL blocks");
+                           throw(MAL,"%s.%s Too many nested MAL blocks", 
getModuleId(sig), getFunctionId(sig));
                        pc[btop]= i;
                        v= var[btop]= getDestVar(p);
                        stmt[btop]=p;
 
                        for(j=btop-1;j>=0;j--)
                        if( v==var[j])
-                           throw(MAL,buf, "recursive %s[%d] shields %s[%d]", 
getVarName(mb,v), pc[j], getFcnName(mb),pc[i]);
+                           throw(MAL,"%s.%s recursive %s[%d] shields %s[%d]", 
getModuleId(sig), getFunctionId(sig), getVarName(mb,v), pc[j], 
getFcnName(mb),pc[i]);
 
                        btop++;
                        break;
                case EXITsymbol:
                        v= getDestVar(p);
                        if( btop>0 && var[btop-1] != v)
-                           throw(MAL, buf, "exit-label '%s' doesnot match 
'%s'", getVarName(mb,v), getVarName(mb,var[btop-1]));
+                           throw(MAL, "%s.%s exit-label '%s' doesnot match 
'%s'", getModuleId(sig), getFunctionId(sig), getVarName(mb,v), 
getVarName(mb,var[btop-1]));
                        if(btop==0)
-                           throw(MAL,buf, "exit-label '%s' without 
begin-label", getVarName(mb,v));
+                           throw(MAL,"%s.%s exit-label '%s' without 
begin-label",  getModuleId(sig), getFunctionId(sig), getVarName(mb,v));
                        /* search the matching block */
                        for(j=btop-1;j>=0;j--)
                        if( var[j]==v) break;
@@ -156,13 +154,13 @@ chkFlow(MalBlkPtr mb)
                        if( var[j]==v) break;
                        if(j<0){
                                str nme=getVarName(mb,v);
-                           throw(MAL,buf, "label '%s' not in guarded block", 
nme);
+                           throw(MAL, "%s.%s label '%s' not in guarded block", 
getModuleId(sig), getFunctionId(sig), nme);
                        }
                        break;
                case YIELDsymbol:
                        { InstrPtr ps= getInstrPtr(mb,0);
                        if( ps->token != FACTORYsymbol){
-                           throw(MAL, buf, "yield misplaced!");
+                           throw(MAL, "%s.%s yield misplaced!",  
getModuleId(sig), getFunctionId(sig));
                        }
                        yieldseen= TRUE;
                         }
@@ -174,13 +172,13 @@ chkFlow(MalBlkPtr mb)
                                if (p->barrier == RETURNsymbol)
                                        yieldseen = FALSE;    /* always end 
with a return */
                                if (ps->retc != p->retc) {
-                                       throw(MAL, buf, "invalid return 
target!");
+                                       throw(MAL, "%s.%s invalid return 
target!",  getModuleId(sig), getFunctionId(sig));
                                } else
                                if (ps->typechk == TYPE_RESOLVED)
                                        for (e = 0; e < p->retc; e++) {
                                                if (resolveType(getArgType(mb, 
ps, e), getArgType(mb, p, e)) < 0) {
                                                        str tpname = 
getTypeName(getArgType(mb, p, e));
-                                                       msg = 
createException(MAL, buf, "%s type mismatch at type '%s'\n",
+                                                       msg = 
createException(MAL, "%s.%s %s type mismatch at type '%s'\n", getModuleId(p), 
getFunctionId(p),
                                                                        
(p->barrier == RETURNsymbol ? "RETURN" : "YIELD"), tpname);
                                                        GDKfree(tpname);
                                                        return msg;
@@ -202,7 +200,7 @@ chkFlow(MalBlkPtr mb)
                                        /* do nothing */
                                } else if( i) {
                                        str l = instruction2str(mb,0,p,TRUE);
-                                       msg = createException( MAL, buf, 
"signature misplaced\n!%s",l);
+                                       msg = createException( MAL, "%s.%s 
signature misplaced\n!%s", getModuleId(p), getFunctionId(p),l);
                                        GDKfree(l);
                                        return  msg;
                                }
@@ -211,20 +209,20 @@ chkFlow(MalBlkPtr mb)
        }
 
        if(lastInstruction < mb->stop-1 )
-               throw(MAL, buf, "instructions after END");
+               throw(MAL, "%s.%s instructions after END", getModuleId(sig), 
getFunctionId(sig));
 
        if( endseen && btop  > 0)
-                       throw(MAL, buf, "barrier '%s' without exit in %s[%d]", 
getVarName(mb,var[btop - 1]),getFcnName(mb),i);
+                       throw(MAL, "%s.%s barrier '%s' without exit in %s[%d]", 
getModuleId(sig), getFunctionId(sig), i, getVarName(mb,var[btop - 
1]),getFcnName(mb),i);
        p= getInstrPtr(mb,0);
        if( !isaSignature(p))
-               throw( MAL, buf, "signature missing");
+               throw( MAL, "%s.%s signature missing",  getModuleId(sig), 
getFunctionId(sig));
        if( retseen == 0){
                if( getArgType(mb,p,0)!= TYPE_void &&
                        (p->token==FUNCTIONsymbol || p->token==FACTORYsymbol))
-                               throw(MAL, buf,  "RETURN missing");
+                               throw(MAL, "%s.%s RETURN missing", 
getModuleId(sig), getFunctionId(sig));
        }
        if ( yieldseen && getArgType(mb,p,0)!= TYPE_void)
-                       throw( MAL, buf,"RETURN missing");
+                       throw( MAL, "%s.%s RETURN missing", getModuleId(sig), 
getFunctionId(sig));
        return MAL_SUCCEED;
 }
 
@@ -490,6 +488,8 @@ renameVariables(MalBlkPtr mb)
                s = getVarName(mb, i);
                if( s[1] == '_' && (*s == 'C' || *s == 'X'))
                        snprintf(s + 2, IDLENGTH-2, "%d", i);
+               else
+                       strcpy(mb->var[i].name, s);
        }
 }
 
@@ -697,10 +697,9 @@ void clrDeclarations(MalBlkPtr mb){
 str
 chkDeclarations(MalBlkPtr mb){
        int pc,i, k,l;
-       InstrPtr p;
+       InstrPtr p, sig;
        short blks[MAXDEPTH], top= 0, blkId=1;
        int dflow = -1;
-       char buf[IDLENGTH * 2 +2];
        str msg = MAL_SUCCEED;
 
        if( mb->errors)
@@ -712,10 +711,9 @@ chkDeclarations(MalBlkPtr mb){
                setVarScope(mb,i,0);
 
        /* all signature variables are declared at outer level */
-       p= getInstrPtr(mb,0);
-       for(k=0;k<p->argc; k++)
-               setVarScope(mb, getArg(p,k), blkId);
-       snprintf(buf, IDLENGTH * 2 +2, "%s.%s", getModuleId(p), 
getFunctionId(p));
+       sig= getInstrPtr(mb,0);
+       for(k=0; k<sig->argc; k++)
+               setVarScope(mb, getArg(sig, k), blkId);
 
        for(pc=1;pc<mb->stop; pc++){
                p= getInstrPtr(mb,pc);
@@ -725,7 +723,7 @@ chkDeclarations(MalBlkPtr mb){
                for(k=p->retc;k<p->argc; k++) {
                        l=getArg(p,k);
                        if ( l < 0)
-                                       throw(MAL, buf, "Non-declared variable: 
pc=%d, var= %d", pc, k);
+                                       throw(MAL, "%s.%s Non-declared 
variable: pc=%d, var= %d",  getModuleId(sig), getFunctionId(sig), pc, k);
                        setVarUsed(mb,l);
                        if( getVarScope(mb,l) == 0){
                                /*
@@ -741,7 +739,7 @@ chkDeclarations(MalBlkPtr mb){
                                        setVarScope(mb, l, blks[0]);
                                } else if( !( isVarConstant(mb, l) || 
isVarTypedef(mb,l)) &&
                                        !isVarInit(mb,l) ) {
-                                       throw(MAL, buf, "'%s' may not be used 
before being initialized", getVarName(mb,l));
+                                       throw(MAL, "%s.%s '%s' may not be used 
before being initialized",  getModuleId(sig), getFunctionId(sig), 
getVarName(mb,l));
                                }
                        } else if( !isVarInit(mb,l) ){
                            /* is the block still active ? */
@@ -749,7 +747,7 @@ chkDeclarations(MalBlkPtr mb){
                                if( blks[i] == getVarScope(mb,l) )
                                        break;
                            if( i> top || blks[i]!= getVarScope(mb,l) )
-                               throw( MAL, buf, "'%s' used outside scope", 
getVarName(mb,l));
+                               throw( MAL, "%s.%s '%s' used outside scope", 
getModuleId(sig), getFunctionId(sig), getVarName(mb,l));
                        }
                        if( blockCntrl(p) || blockStart(p) )
                                setVarInit(mb, l);
@@ -777,11 +775,11 @@ chkDeclarations(MalBlkPtr mb){
                if( p->barrier && msg == MAL_SUCCEED){
                        if ( blockStart(p)){
                                if( top == MAXDEPTH-2)
-                                       throw(MAL, buf, "too deeply nested  MAL 
program");
+                                       throw(MAL, "%s.%s too deeply nested  
MAL program",  getModuleId(sig), getFunctionId(sig));
                                blkId++;
                                if (getModuleId(p) && getFunctionId(p) && 
strcmp(getModuleId(p),"language")==0 && strcmp(getFunctionId(p),"dataflow")== 
0){
                                        if( dflow != -1)
-                                               throw(MAL, buf, "setLifeSpan 
nested dataflow blocks not allowed" );
+                                               throw(MAL, "%s.%s setLifeSpan 
nested dataflow blocks not allowed", getModuleId(sig), getFunctionId(sig));
                                        dflow= blkId;
                                }
                                blks[++top]= blkId;
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to