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

📄 mal_resolve.c

📁 一个内存数据库的源代码这是服务器端还有客户端
💻 C
📖 第 1 页 / 共 2 页
字号:
			getTypeName(h1),getTypeName(t1),			getTypeName(h2),getTypeName(t2),			getTypeName(h3),i1,getTypeName(t3),i2			);		}#endif		return newBatType(h3,t3);	}#ifdef DEBUG_MAL_RESOLVE	if(tracefcn) stream_printf(GDKout,"Can not be resolved \n");#endif	return -1;}#line 568 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"void typeMismatch(MalBlkPtr mb, InstrPtr p, int lhs, int rhs, int silent){	str n1;	str n2;	if (!silent) {		n1 = getTypeName(lhs);		n2 = getTypeName(rhs);		showScriptException(mb, getPC(mb, p), TYPE, 				"type mismatch %s := %s", n1, n2);		GDKfree(n1);		GDKfree(n2);		mb->errors++;	}	p->typechk= TYPE_UNKNOWN;}#line 595 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"void typeChecker(Module scope, MalBlkPtr mb, InstrPtr p,int silent){	int s1= -1, i,k;	Module m=0;	p->typechk= TYPE_UNKNOWN;	if( p->fcn && p->token>= FCNcall && p->token<= PATcall){		p->token= ASSIGNsymbol;		p->fcn = NULL;		p->blk = NULL;	}	if( isaSignature(p) ) {		for(k=0;k<p->argc;k++)			setFixed(mb,getArg(p,k));		for(k=p->retc;k<p->argc;k++){			#line 462 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"	if( findGDKtype(getArgType(mb,p,k)) == TYPE_bat){		setVarCleanup(mb,getArg(p,k)) = TRUE;		getInstrPtr(mb,0)->gc |= GARBAGECONTROL;		p->gc|= QUICKCLEANUP;	}	else if( !isPolyType(getArgType(mb,p,k))  && getArgType(mb,p,k)< TYPE_any && 			getArgType(mb,p,k)>=0 && ATOMstorage(getArgType(mb,p,k))== TYPE_str){		getInstrPtr(mb,0)->gc |= GARBAGECONTROL;		setVarCleanup(mb,getArg(p,k)) = TRUE;		p->gc|= QUICKCLEANUP;	} #line 610 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"		}		p->typechk= TYPE_RESOLVED;		for(k=0; k<p->retc;k++)			p->typechk = MIN(p->typechk,typeKind(mb,p,0));		return;	}	if( getFunctionId(p) && getModuleId(p)){#ifdef DEBUG_MAL_RESOLVE		tracefcn= idcmp(getFunctionId(p),traceFcnName)==0;#endif		m= findModule(scope,getModuleId(p));		s1= findFunctionType(m,mb,p,silent);		if( s1>= 0) return;#line 648 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"		if( ! isaSignature(p) && !getInstrPtr(mb,0)->polymorphic )  {			mb->errors++;			if( !silent) {				char errsig[BUFSIZ];				recognizedCall(mb,p,errsig);				showScriptException(mb,getPC(mb,p),TYPE,						"'%s%s%s' undefined in: %s", 						(getModuleId(p)?getModuleId(p):""),						(getModuleId(p)?".":""),						getFunctionId(p), errsig);			}			p->typechk= TYPE_UNKNOWN;		} else p->typechk= TYPE_RESOLVED;		return;	}#line 670 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"	if( getFunctionId(p) ) return;	if( p->retc > 1 && p->argc>p->retc && p->argc!= 2 * p->retc){		showScriptException( mb, getPC(mb,p), TYPE,			"Multiple assignment mismatch");		mb->errors++;	} else		p->typechk= TYPE_RESOLVED;	for(k=0,i= p->retc; k<p->retc && i<p->argc; i++,k++){		int rhs = getArgType(mb,p,i);		int lhs = getArgType(mb,p,k);		if( rhs != TYPE_void){			s1= resolveType(lhs,rhs);			if( s1== -1 ){				typeMismatch(mb,p,lhs,rhs,silent);				return;			}		} else #line 692 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"		if( lhs != TYPE_void && lhs != TYPE_any){			ValRecord cst;			cst.vtype= TYPE_void;			cst.val.oval= void_nil;						p->argv[i]= defConstant(mb, (isaBatType(lhs)?TYPE_bat:lhs), &cst);		} 		if( !isFixed(mb,getArg(p,k))) {			setVarType(mb,getArg(p,k),rhs);			setFixed(mb,getArg(p,k));		}		#line 462 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"	if( findGDKtype(s1) == TYPE_bat){		setVarCleanup(mb,getArg(p,0)) = TRUE;		getInstrPtr(mb,0)->gc |= GARBAGECONTROL;		p->gc|= QUICKCLEANUP;	}	else if( !isPolyType(s1)  && s1< TYPE_any && 			s1>=0 && ATOMstorage(s1)== TYPE_str){		getInstrPtr(mb,0)->gc |= GARBAGECONTROL;		setVarCleanup(mb,getArg(p,0)) = TRUE;		p->gc|= QUICKCLEANUP;	} #line 704 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"	}}#line 718 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"InstrPtr dynamicTypeChecker(Module scope, MalBlkPtr mb, MalStkPtr stk, InstrPtr p){	InstrPtr pci;	int i;	stream_printf(GDKout,"Start dynamic type check on:\n");	printInstruction(GDKout, mb, p,LIST_MAL_ALL);	pci = copyInstruction(p);	if( getFunctionId(pci) && (i=findVariable(mb,getFunctionId(pci))) != -1){		if( getVarType(mb,i) != TYPE_str)			setFunctionId(pci, 0);		else 			setFunctionId(pci,putName( stk->stk[i].val.sval,						strlen(stk->stk[i].val.sval)));	}	if( getModuleId(pci) && (i=findVariable(mb,getModuleId(pci))) != -1){		if( getVarType(mb,i) != TYPE_str)				setModuleId(pci, NULL);		else {				setModuleScope(pci, findModule(scope, stk->stk[i].val.sval));		}	}	typeChecker(scope, mb,pci,FALSE);#ifdef DEBUG_MAL_RESOLVE	stream_printf(GDKout,"type checked version:\n");	printInstruction(GDKout, mb, pci,LIST_MAL_ALL);#endif	return pci;}#line 757 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"int fcnBinder(Module scope, MalBlkPtr mb, InstrPtr p){	Module m=0;	Symbol s;	if( p->token != ASSIGNsymbol) return 0;	if( getModuleId(p)== NULL || getFunctionId(p)== NULL) return 0;	for(m= findModule(scope,getModuleId(p)); m; m= m->outer)	if( m->name == getModuleId(p) ) {		s= m->subscope[(int)(getSubScope(getFunctionId(p)))];		for(; s; s= s->peer)		if( getFunctionId(p)==s->name &&			p->argc == getSignature(s)->argc ){			/* found it */			#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 770 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"		}	}	return 0;}#line 791 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"void chkTypes(Module s, MalBlkPtr mb){	InstrPtr p=0;	int i, chk=0;	for(i=0;i<mb->stop;i++) {		p= getInstrPtr(mb,i);		if(p== NULL) continue;		if( p->typechk == TYPE_BIND) 			fcnBinder(s,mb,p);		else /*  not ready if( p->typechk != TYPE_RESOLVED)*/			typeChecker(s,mb,p,FALSE);		if( getFunctionId(p) ){			if(p->fcn != NULL && p->typechk== TYPE_RESOLVED) chk++;		} else		if( p->typechk== TYPE_RESOLVED) chk++;	}}#line 814 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"void chkInstruction(Module s, MalBlkPtr mb, InstrPtr p){	typeChecker(s,mb,p, FALSE);}void chkProgram(Module s, MalBlkPtr mb){/* it is not ready yet, too fragile		mb->typefixed = mb->stop == chk; ignored END *//*	if( mb->flowfixed == 0)*/	chkTypes(s,mb);	chkFlow(mb);	chkDeclarations(mb,FALSE);}#line 834 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"int typeKind(MalBlkPtr mb, InstrPtr p, int i){	malType t= getArgType(mb,p,i);	if(t == TYPE_any || isAnyExpression(t) ) {		return TYPE_DYNAMIC;	}	return TYPE_RESOLVED;}#line 846 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"malType getPolyType(malType t,int *polytype){	int hi,ti;	int head, tail;	ti = getTailIndex(t);	tail= ti == 0? getTailType(t): polytype[ti];	if( isaBatType(t)){		hi = getHeadIndex(t);		head= hi == 0 ? getHeadType(t): polytype[hi];		return newBatType(head,tail);	}	return tail;}#line 868 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_resolve.mx"int updateTypeMap(int formal, int actual, int polytype[MAXTYPEVAR]){	int h,t,ret=0;	if( formal== TYPE_bat && isaBatType(actual) ) return 0;#ifdef DEBUG_MAL_RESOLVE	stream_printf(GDKout,"updateTypeMap:");	stream_printf(GDKout,"formal %s ", getTypeName(formal));	stream_printf(GDKout,"actual %s\n", getTypeName(actual));#endif	if( (h=getTailIndex(formal))  ){		t= getTailType(actual);		if( t != polytype[h]){			if( polytype[h]== TYPE_bat && isaBatType(actual))				ret= 0;			else			if( polytype[h] == TYPE_any ) polytype[h]=  t;			else {				ret= -1;				goto updLabel;			}		}	}	if( isaBatType(formal)){		if(!isaBatType(actual) && actual!= TYPE_bat) return -1;		if( (h=getHeadIndex(formal)) ){			t= actual == TYPE_bat? actual: getHeadType(actual);			if( t!= polytype[h]){				if( polytype[h] == TYPE_any) polytype[h]= t;				else {					ret= -1;					goto updLabel;				}			}		}	} updLabel:#ifdef DEBUG_MAL_RESOLVE	stream_printf(GDKout,"updateTypeMap returns: %d\n",ret);#endif	return ret;}

⌨️ 快捷键说明

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