Changeset: 3ffa0b460401 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=3ffa0b460401
Modified Files:
monetdb5/mal/mal_resolve.mx
Branch: Aug2011
Log Message:
uncrustify
diffs (truncated from 731 to 300 lines):
diff --git a/monetdb5/mal/mal_resolve.mx b/monetdb5/mal/mal_resolve.mx
--- a/monetdb5/mal/mal_resolve.mx
+++ b/monetdb5/mal/mal_resolve.mx
@@ -130,11 +130,13 @@
}
#endif
-static malType findFunctionType(Module scope, MalBlkPtr mb, InstrPtr p,int
silent){
+static malType
+findFunctionType(Module scope, MalBlkPtr mb, InstrPtr p, int silent)
+{
Module m;
Symbol s;
InstrPtr sig;
- int i,k, unmatched = 0, s1;
+ int i, k, unmatched = 0, s1;
/* int foundbutwrong=0;*/
int polytype[MAXTYPEVAR];
int *returntype;
@@ -155,164 +157,164 @@
* it will be looked up multiple types to resolve the instruction.[todo]
* Simplify polytype using a map into the concrete argument table.
*/
- 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;
- }
- /*
- * @-
- * Perform a strong type-check on the actual arguments. If it turns
- * out to be a polymorphic MAL function, we have to clone it.
- * Provided the actual/formal parameters are compliant throughout
- * the function call.
- *
- * Also look out for variable argument lists. This means that we
- * have to keep two iterators, one for the caller (i) and one for
- * the callee (k). Since a variable argument only occurs as the last
one,
- * we simple avoid an increment when running out of formal arguments.
- *
- * A call of the form (X1,..., Xi) := f(Y1,....,Yn) can be matched
against
- * the function signature (B1,...,Bk):= f(A1,...,Am) where i==k , n<=m
- * and type(Ai)=type(Yi). Furthermore, the variables Xi obtain their
type
- * from Bi (or type(Bi)==type(Xi)).
- */
- sig = getSignature(s);
- unmatched = 0;
+ 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;
+ }
+ /*
+ * @-
+ * Perform a strong type-check on the actual arguments. If it
turns
+ * out to be a polymorphic MAL function, we have to clone it.
+ * Provided the actual/formal parameters are compliant
throughout
+ * the function call.
+ *
+ * Also look out for variable argument lists. This means that we
+ * have to keep two iterators, one for the caller (i) and one
for
+ * the callee (k). Since a variable argument only occurs as the
last one,
+ * we simple avoid an increment when running out of formal
arguments.
+ *
+ * A call of the form (X1,..., Xi) := f(Y1,....,Yn) can be
matched against
+ * the function signature (B1,...,Bk):= f(A1,...,Am) where i==k
, n<=m
+ * and type(Ai)=type(Yi). Furthermore, the variables Xi obtain
their type
+ * from Bi (or type(Bi)==type(Xi)).
+ */
+ sig = getSignature(s);
+ unmatched = 0;
#ifdef DEBUG_MAL_RESOLVE
- if(tracefcn) {
- mnstr_printf(GDKout,"-->resolving\n");
- printInstruction(GDKout,mb,0,p,LIST_MAL_ALL);
- mnstr_printf(GDKout,"++> test against signature\n");
- printInstruction(GDKout,s->def,0,getSignature(s),LIST_MAL_ALL);
- mnstr_printf(GDKout," %s \n", sig->polymorphic?"polymorphic":"");
- }
+ if (tracefcn) {
+ mnstr_printf(GDKout, "-->resolving\n");
+ printInstruction(GDKout, mb, 0, p, LIST_MAL_ALL);
+ mnstr_printf(GDKout, "++> test against signature\n");
+ printInstruction(GDKout, s->def, 0, getSignature(s),
LIST_MAL_ALL);
+ mnstr_printf(GDKout, " %s \n", sig->polymorphic ?
"polymorphic" : "");
+ }
#endif
- /*
- * @-
- * The simple case could be taken care of separately to speedup
processing
- * However, it turned out not to make a big difference.
- * The first time we encounter a polymorphic argument in the
- * signature.
- * Subsequently, the polymorphic arguments update this table
- * and check for any type mismatches that might occur.
- * There are at most 2 type variables involved per argument
- * due to the limited type nesting permitted.
- * Note, each function returns at least one value.
- */
- 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 && !(sig->varargs & VARRETS)) {
- 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;
- /*
- * @-
- * Most polymorphic functions don;t have a variable argument
- * list. So we save some instructions factoring this caise out.
- * Be careful, the variable number of return arguments should
- * be considered as well.
- */
- i= p->retc;
- /* first handle the variable argument list */
- for(k=sig->retc; i<p->argc; k++, i++){
- int actual = getArgType(mb,p,i);
- int formal = getArgType(s->def,sig,k);
- if (k == sig->argc-1 && sig->varargs & VARARGS)
- k--;
/*
* @-
- * Take care of variable argument lists.
- * They are allowed as the last in the signature only.
- * Furthermore, for patterns if the formal type is 'any' then
all remaining arguments
- * are acceptable and detailed type analysis becomes part of
the pattern
- * implementation.
- * In all other cases the type should apply to all remaining
arguments.
+ * The simple case could be taken care of separately to speedup
processing
+ * However, it turned out not to make a big difference.
+ * The first time we encounter a polymorphic argument in the
+ * signature.
+ * Subsequently, the polymorphic arguments update this table
+ * and check for any type mismatches that might occur.
+ * There are at most 2 type variables involved per argument
+ * due to the limited type nesting permitted.
+ * Note, each function returns at least one value.
*/
- if (formal == actual)
- continue;
- if( updateTypeMap(formal, actual, polytype)){
- unmatched= i;
- break;
- }
- formal= getPolyType(formal,polytype);
- /*
- * @-
- * Collect the polymorphic types and resolve them.
- * If it fails, we know this isn;t the function we are
- * looking for.
- */
- if( resolveType( formal,actual) == -1 ){
- unmatched= i;
- break;
- }
- }
- /*
- * @-
- * The last argument/result type could be a polymorphic variable list.
- * It should only be allowed for patterns, where it can deal with the
stack.
- * If the type is specified as :any then any mix of arguments is
allowed.
- * If the type is a new numbered type variable then the first element
- * in the list determines the required type of all.
- */
- if( sig->varargs ) {
- if( sig->token != PATTERNsymbol )
- unmatched = i;
- else {
- /* resolve the arguments */
- for(; i<p->argc; i++){
- /* the type of the last one has already been
set */
- int actual = getArgType(mb,p,i);
- int formal = getArgType(s->def,sig,k);
- if (k == sig->argc-1 && sig->varargs & VARARGS)
+ 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 && !(sig->varargs & VARRETS)) {
+ 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;
+ /*
+ * @-
+ * Most polymorphic functions don;t have a variable
argument
+ * list. So we save some instructions factoring this
caise out.
+ * Be careful, the variable number of return arguments
should
+ * be considered as well.
+ */
+ i = p->retc;
+ /* first handle the variable argument list */
+ for (k = sig->retc; i < p->argc; k++, i++) {
+ int actual = getArgType(mb, p, i);
+ int formal = getArgType(s->def, sig, k);
+ if (k == sig->argc - 1 && sig->varargs &
VARARGS)
k--;
+ /*
+ * @-
+ * Take care of variable argument lists.
+ * They are allowed as the last in the
signature only.
+ * Furthermore, for patterns if the formal type
is 'any' then all remaining arguments
+ * are acceptable and detailed type analysis
becomes part of the pattern
+ * implementation.
+ * In all other cases the type should apply to
all remaining arguments.
+ */
+ if (formal == actual)
+ continue;
+ if (updateTypeMap(formal, actual, polytype)) {
+ unmatched = i;
+ break;
+ }
+ formal = getPolyType(formal, polytype);
+ /*
+ * @-
+ * Collect the polymorphic types and resolve
them.
+ * If it fails, we know this isn;t the function
we are
+ * looking for.
+ */
+ if (resolveType(formal, actual) == -1) {
+ unmatched = i;
+ break;
+ }
+ }
+ /*
+ * @-
+ * The last argument/result type could be a polymorphic
variable list.
+ * It should only be allowed for patterns, where it can
deal with the stack.
+ * If the type is specified as :any then any mix of
arguments is allowed.
+ * If the type is a new numbered type variable then the
first element
+ * in the list determines the required type of all.
+ */
+ if (sig->varargs) {
+ if (sig->token != PATTERNsymbol)
+ unmatched = i;
+ else {
+ /* resolve the arguments */
+ for (; i < p->argc; i++) {
+ /* the type of the last one has
already been set */
+ int actual = getArgType(mb, p,
i);
+ int formal = getArgType(s->def,
sig, k);
+ if (k == sig->argc - 1 &&
sig->varargs & VARARGS)
+ k--;
- formal= getPolyType(formal,polytype);
- if( formal == actual || formal == TYPE_any)
- continue;
- if( resolveType( formal,actual) == -1 ){
- unmatched= i;
+ formal = getPolyType(formal,
polytype);
+ if (formal == actual || formal
== TYPE_any)
+ continue;
+ if (resolveType(formal, actual)
== -1) {
+ unmatched = i;
+ break;
+ }
+ }
+ }
+ }
+ } else {
+ /*
+ * @-
+ * We have to check the argument types to determine a
+ * possible match for the non-polymorphic case.
+ */
+ 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 (resolveType(formal, actual) == -1) {
+#ifdef DEBUG_MAL_RESOLVE
+ mnstr_printf(GDKout, "unmatched %d
formal %s actual %s\n",
+ i, getTypeName(formal),
getTypeName(actual));
+#endif
+ unmatched = i;
break;
}
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list