⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mal_resolve.c

📁 一个内存数据库的源代码这是服务器端还有客户端
💻 C
📖 第 1 页 / 共 2 页
字号:
#line 108 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"#include "mal_config.h"#include "mal_resolve.h"#include "mal_namespace.h"malType getPolyType(malType t, int *polytype);int updateTypeMap(int formal, int actual, int polytype[MAXTYPEVAR]);int typeKind(MalBlkPtr mb, InstrPtr p, int i);#define MAXMALARG 256str traceFcnName= "____";int tracefcn;int polyVector[MAXTYPEVAR];void polyInit(){	int i;	for(i=0;i<MAXTYPEVAR;i++) polyVector[i]= TYPE_any;}malType findFunctionType(Module scope, MalBlkPtr mb, InstrPtr p,int silent){	Module m;	Symbol s;	InstrPtr sig;	int i,k, unmatched = 0, s1;	int foundbutwrong=0;	int polytype[MAXTYPEVAR];	int *returntype;#line 150 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"	m= scope;	s= m->subscope[(int)(getSubScope(getFunctionId(p)))];	if( s == 0) return -1;	while(s != NULL){   /* single scope element check */	if( getFunctionId(p) != s->name  ){		s= s->skip; continue;	}#line 173 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"	sig = getSignature(s); 	unmatched = 0;#ifdef DEBUG_MAL_RESOLVE	if(tracefcn) {	stream_printf(GDKout,"-->resolving\n");	printInstruction(GDKout,mb,p,LIST_MAL_ALL);	stream_printf(GDKout,"++> test against signature\n");	printInstruction(GDKout,s->def,getSignature(s),LIST_MAL_ALL);	stream_printf(GDKout," %s \n", sig->polymorphic?"polymorphic":"");	}#endif#line 196 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"	if( sig->polymorphic ){	int limit = sig->polymorphic;	if( ! (sig->argc== p->argc ||		(sig->argc<p->argc && sig->varargs & (VARARGS | VARRETS) )) 	){		s= s->peer; continue;	}	if( sig->retc != p->retc) {		s= s->peer;		continue;	}/*  if(polyVector[0]==0) polyInit();	memcpy(polytype,polyVector, 2*sig->argc*sizeof(int)); */	for(k=0; k< limit; k++) polytype[k] = TYPE_any;#line 215 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"	for(i=p->retc; i<sig->argc; i++){		int actual = getArgType(mb,p,i);		int formal = getArgType(s->def,sig,i);#line 226 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"		if( formal == actual)			continue;		if( isPolyType(formal) && getVar(mb,getArg(p,i))->props){			/* printf("perform union type check\n");*/		}		if( updateTypeMap(formal, actual, polytype)){			unmatched= i; 		   break;		}		formal= getPolyType(formal,polytype);#line 241 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"		if( resolveType( formal,actual) == -1 ){			unmatched= i;			break;		}	}#line 253 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"	  if( sig->varargs ) {		if( sig->token != PATTERNsymbol )			unmatched = i;		else		for(k=i-1; i<p->argc; i++){			int actual = getArgType(mb,p,i);			int formal = getArgType(s->def,sig,k);			formal= getPolyType(formal,polytype);			if( formal == actual || formal == TYPE_any) 				continue;			if( resolveType( formal,actual) == -1 ){				unmatched= i;				break;			}		}	  }   } else {#line 274 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"		if( sig->argc != p->argc ||			sig->retc != p->retc) {			s= s->peer;			continue;		}		for(i=p->retc;i<p->argc;i++){			int actual = getArgType(mb,p,i);			int formal = getArgType(s->def,sig,i);			if(formal!=actual ){#ifdef DEBUG_MAL_RESOLVE			stream_printf(GDKout,"unmatched %d formal %s actual %s\n",				i, getTypeName(formal), getTypeName(actual));#endif				unmatched= i;				break;			}		}	}#line 299 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"#ifdef DEBUG_MAL_RESOLVE	if(tracefcn) {		 stream_printf(GDKout,"finished %s.%s unmatched=%d polymorphic=%d %d\n",			getModuleId(sig), getFunctionId(sig), unmatched, sig->polymorphic,p==sig);		if( sig->polymorphic){			int l;			for(l=0;l<2*p->argc;l++) 			if( polytype[l] != TYPE_any)			stream_printf(GDKout,"poly %d %s\n",l,getTypeName(polytype[l]));		}		stream_printf(GDKout,"-->resolving\n");		printInstruction(GDKout,mb,p,LIST_MAL_ALL);		stream_printf(GDKout,"++> test against signature\n");		printInstruction(GDKout,s->def,getSignature(s),LIST_MAL_ALL);		stream_printf(GDKout,"\nmismatch unmatched %d test %s poly %s\n",			unmatched, getTypeName(getArgType(mb,p,unmatched)),			getTypeName(getArgType(s->def,sig,unmatched)));	}#endif	if( unmatched) { s= s->peer; continue; }#line 329 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"	s1 = 0;	returntype= (int*) alloca(p->retc * sizeof(int));	if( sig->polymorphic)	for(i=0; i < p->retc; i++){		int actual = getArgType(mb,p,i);		int formal = getArgType(s->def,sig,i);		updateTypeMap(formal, actual, polytype);		s1= getPolyType(formal, polytype);		returntype[i]= resolveType(s1,actual);		if( returntype[i]== -1 ){			s1= -1;			break;		}	} else 	/* check for non-polymorphic return */	for(i=0; i < p->retc; i++){		int actual = getArgType(mb,p,i);		int formal = getArgType(s->def,sig,i);		if( actual== formal)			returntype[i]= actual;		else {			returntype[i]= resolveType(formal,actual);			if( returntype[i]== -1 ){				s1= -1;				break;			}		}	}	if(s1<0 ){		/* if(getSignature(s)->token !=PATTERNsymbol) foundbutwrong++;*/		s= s->peer; continue;	}#line 373 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"	p->typechk= TYPE_RESOLVED;	for(i=0;i<p->retc;i++) {		int ts= returntype[i];		if( !isFixed(mb,getArg(p,i)) && ts>=0) {			setVarType(mb, getArg(p,i),ts);			setFixed(mb, getArg(p,i));		}		#line 462 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"	if( findGDKtype(ts) == TYPE_bat){		setVarCleanup(mb,getArg(p,i)) = TRUE;		getInstrPtr(mb,0)->gc |= GARBAGECONTROL;		p->gc|= QUICKCLEANUP;	}	else if( !isPolyType(ts)  && ts< TYPE_any && 			ts>=0 && ATOMstorage(ts)== TYPE_str){		getInstrPtr(mb,0)->gc |= GARBAGECONTROL;		setVarCleanup(mb,getArg(p,i)) = TRUE;		p->gc|= QUICKCLEANUP;	} #line 380 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"	}#line 396 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"	s1= returntype[0];  /* for those interested */	foundbutwrong = 0;#line 406 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"	if( sig->polymorphic){ 		int cnt=0;		for(k=i=p->retc;i<p->argc;i++){			int actual = getArgType(mb,p,i);			if( isAnyExpression(actual)) cnt++;		}		if(cnt==0 && s->kind!= COMMANDsymbol && s->kind!=PATTERNsymbol ){			s = cloneFunction(scope, s, mb,p);			if( s->def->errors) return -3;		}	}#line 457 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"	#line 422 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"	if( p->token == ASSIGNsymbol){		switch(getSignature(s)->token){		case COMMANDsymbol: 			p->token = CMDcall; 			p->fcn = getSignature(s)->fcn;			if( p->fcn == 0) {				p->typechk= TYPE_UNKNOWN;				mb->errors++;				return -3;			}			break;		case PATTERNsymbol: 			p->token = PATcall; 			p->fcn = getSignature(s)->fcn;			break;		case FACTORYsymbol:			p->token = FACcall; 			p->fcn = getSignature(s)->fcn;			break;		case FUNCTIONsymbol: 			p->token = FCNcall; 			if( getSignature(s)->fcn)				p->fcn = getSignature(s)->fcn;			break;		default: {			showScriptException(mb, getPC(mb, p), MAL, 					"MALresolve: unexpected token type");			mb->errors++;			return -3;		}		} /* retarded indenting */		p->blk = s->def;	}#line 457 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"#line 474 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"#ifdef DEBUG_MAL_RESOLVE	if(tracefcn) {		printInstruction(GDKout,mb,p,LIST_MAL_ALL);		stream_printf(GDKout,"Finished matching\n");	}#endif	return s1;	} /* while */#line 487 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"	if( foundbutwrong && !silent){		showScriptException(mb, getPC(mb, p), TYPE,			"type conflict in assignment");	}	return -3;}#line 504 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"int resolveType(int dsttype, int srctype){  #ifdef DEBUG_MAL_RESOLVE	if( tracefcn){		stream_printf(GDKout,"resolveType dst %s (%d) %s(%d)\n",			getTypeName(dsttype), dsttype,			getTypeName(srctype),srctype);	}#endif	if( dsttype == srctype) return dsttype;	if( dsttype == TYPE_any) return srctype;	if( srctype == TYPE_any) return dsttype;#line 518 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"	if(isaBatType(srctype) && dsttype == TYPE_bat) return srctype;	if(isaBatType(dsttype) && srctype == TYPE_bat) return dsttype;	if( isaBatType(dsttype) && isaBatType(srctype) ){		int h1,t1,h2,t2,h3,t3;		h1= getHeadType(dsttype);		h2= getHeadType(srctype);		if( h1 == h2) h3= h1; else		if( h1 == TYPE_any) h3= h2; else		if( h2 == TYPE_any) h3= h1; 		else {#ifdef DEBUG_MAL_RESOLVE			if(tracefcn) stream_printf(GDKout,"Can not be resolved \n");#endif			return -1;		}		t1= getTailType(dsttype);		t2= getTailType(srctype);		if( t1 == t2) t3= t1; else		if( t1 == TYPE_any) t3= t2; else		if( t2 == TYPE_any) t3= t1;		else {#ifdef DEBUG_MAL_RESOLVE			if(tracefcn) stream_printf(GDKout,"Can not be resolved \n");#endif			return -1;		}#ifdef DEBUG_MAL_RESOLVE		if( tracefcn){			int i1=getHeadIndex(dsttype);			int i2= getTailIndex(dsttype);		stream_printf(GDKout,"resolved to bat[:%s,:%s] bat[:%s,:%s]->bat[%s:%d,%s:%d]\n",

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -