Changeset: 5f905953d912 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=5f905953d912
Modified Files:
monetdb5/mal/mal_resolve.c
Branch: Apr2012
Log Message:
Indent. Plus some minor fixes to some comments.
diffs (truncated from 971 to 300 lines):
diff --git a/monetdb5/mal/mal_resolve.c b/monetdb5/mal/mal_resolve.c
--- a/monetdb5/mal/mal_resolve.c
+++ b/monetdb5/mal/mal_resolve.c
@@ -93,13 +93,16 @@ int typeKind(MalBlkPtr mb, InstrPtr p, i
#define MAXMALARG 256
-str traceFcnName= "____";
+str traceFcnName = "____";
int tracefcn;
int polyVector[MAXTYPEVAR];
#if 0
-void polyInit(void){
+void
+polyInit(void)
+{
int i;
- for(i=0;i<MAXTYPEVAR;i++) polyVector[i]= TYPE_any;
+ for (i = 0; i < MAXTYPEVAR; i++)
+ polyVector[i] = TYPE_any;
}
#endif
@@ -179,9 +182,9 @@ findFunctionType(stream *out, Module sco
Symbol s;
InstrPtr sig;
int i, k, unmatched = 0, s1;
- /* int foundbutwrong=0;*/
+ /* int foundbutwrong=0; */
int polytype[MAXTYPEVAR];
- int *returntype= NULL;
+ int *returntype = NULL;
/*
* Within a module find the subscope to locate the element in its list
* of symbols. A skiplist is used to speed up the search for the
@@ -199,31 +202,36 @@ findFunctionType(stream *out, Module sco
* Simplify polytype using a map into the concrete argument table.
*/
m = scope;
- s = m->subscope[(int)(getSubScope(getFunctionId(p)))];
- if (s == 0) return -1;
+ s = m->subscope[(int) (getSubScope(getFunctionId(p)))];
+ if (s == 0)
+ return -1;
- returntype= (int*) GDKzalloc(p->retc * sizeof(int));
- if ( returntype == 0) return -1;
+ returntype = (int *) GDKzalloc(p->retc * sizeof(int));
+ if (returntype == 0)
+ return -1;
- while (s != NULL) { /* single scope element check */
+ while (s != NULL) { /* single scope element check */
if (getFunctionId(p) != s->name) {
- s = s->skip; continue;
+ 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.
+ * 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.
+ * 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)).
+ * 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;
@@ -238,22 +246,24 @@ findFunctionType(stream *out, Module sco
}
#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
+ * 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.
+ * 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;
+ s = s->peer;
+ continue;
}
if (sig->retc != p->retc && !(sig->varargs & VARRETS)) {
s = s->peer;
@@ -262,7 +272,8 @@ findFunctionType(stream *out, Module sco
/* if(polyVector[0]==0) polyInit();
memcpy(polytype,polyVector, 2*sig->argc*sizeof(int)); */
- for (k = 0; k < limit; k++) polytype[k] = TYPE_any;
+ 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.
@@ -279,10 +290,12 @@ findFunctionType(stream *out, Module sco
/*
* 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.
+ * 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;
@@ -302,11 +315,13 @@ findFunctionType(stream *out, Module sco
}
}
/*
- * 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.
+ * 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)
@@ -335,8 +350,7 @@ findFunctionType(stream *out, Module sco
* 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) {
+ if (sig->argc != p->argc || sig->retc != p->retc) {
s = s->peer;
continue;
}
@@ -346,51 +360,56 @@ findFunctionType(stream *out, Module sco
if (resolveType(formal, actual) == -1) {
#ifdef DEBUG_MAL_RESOLVE
mnstr_printf(out, "unmatched %d formal
%s actual %s\n",
- i, getTypeName(formal),
getTypeName(actual));
+ i,
getTypeName(formal), getTypeName(actual));
#endif
unmatched = i;
break;
}
}
}
-/*
- * It is possible that you may have to coerce the value to another type.
- * We assume that coercions are explicit at the MAL
- * level. (e.g. var2:= var0:int). This avoids repeated type analysis
- * just before you execute a function.
- * An optimizer may at a later stage automatically insert such coercion
requests.
- */
+ /*
+ * It is possible that you may have to coerce the value to
+ * another type. We assume that coercions are explicit at the
+ * MAL level. (e.g. var2:= var0:int). This avoids repeated
+ * type analysis just before you execute a function.
+ * An optimizer may at a later stage automatically insert such
+ * coercion requests.
+ */
#ifdef DEBUG_MAL_RESOLVE
if (tracefcn) {
mnstr_printf(out, "finished %s.%s unmatched=%d
polymorphic=%d %d\n",
- getModuleId(sig), getFunctionId(sig),
unmatched, sig->polymorphic, p == sig);
+ 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)
- mnstr_printf(out, "poly %d
%s\n", l, getTypeName(polytype[l]));
+ mnstr_printf(out, "poly %d
%s\n",
+ l,
getTypeName(polytype[l]));
}
mnstr_printf(out, "-->resolving\n");
printInstruction(out, mb, 0, p, LIST_MAL_ALL);
mnstr_printf(out, "++> test against signature\n");
printInstruction(out, s->def, 0, getSignature(s),
LIST_MAL_ALL);
mnstr_printf(out, "\nmismatch unmatched %d test %s poly
%s\n",
- unmatched, getTypeName(getArgType(mb, p,
unmatched)),
- getTypeName(getArgType(s->def, sig,
unmatched)));
+ unmatched,
getTypeName(getArgType(mb, p, unmatched)),
+ getTypeName(getArgType(s->def,
sig, unmatched)));
}
#endif
if (unmatched) {
- s = s->peer; continue;
+ s = s->peer;
+ continue;
}
/*
- * At this stage we know all arguments are type compatible with
the
- * signature.
- * We should assure that also the target variables have the
proper types
- * or can inherit them from the signature. The result type
vector should be
- * build separately first, because we may encounter an error
later on.
+ * At this stage we know all arguments are type compatible
+ * with the signature.
+ * We should assure that also the target variables have the
+ * proper types or can inherit them from the signature. The
+ * result type vector should be build separately first,
+ * because we may encounter an error later on.
*
- * If any of the arguments refer to a constraint type, any_x,
then
- * the resulting type can not be determined.
+ * If any of the arguments refer to a constraint type, any_x,
+ * then the resulting type can not be determined.
*/
s1 = 0;
if (sig->polymorphic)
@@ -398,7 +417,8 @@ findFunctionType(stream *out, Module sco
int actual = getArgType(mb, p, i);
int formal = getArgType(s->def, sig, k);
- if (k == sig->retc - 1 && sig->varargs &
VARRETS) k--;
+ if (k == sig->retc - 1 && sig->varargs &
VARRETS)
+ k--;
s1 = getPolyType(formal, polytype);
@@ -414,7 +434,8 @@ findFunctionType(stream *out, Module sco
int actual = getArgType(mb, p, i);
int formal = getArgType(s->def, sig, i);
- if (k == sig->retc - 1 && sig->varargs &
VARRETS) k--;
+ if (k == sig->retc - 1 && sig->varargs &
VARRETS)
+ k--;
if (actual == formal)
returntype[i] = actual;
@@ -427,8 +448,9 @@ findFunctionType(stream *out, Module sco
}
}
if (s1 < 0) {
- /* if(getSignature(s)->token !=PATTERNsymbol)
foundbutwrong++;*/
- s = s->peer; continue;
+ /* if(getSignature(s)->token !=PATTERNsymbol)
foundbutwrong++; */
+ s = s->peer;
+ continue;
}
/*
* If the return types are correct, copy them in place.
@@ -462,31 +484,34 @@ findFunctionType(stream *out, Module sco
if (findGDKtype(getArgType(mb, p, i)) == TYPE_str ||
getArgType(mb, p, i) == TYPE_bat ||
isaBatType(getArgType(mb, p, i)) ||
- (!isPolyType(getArgType(mb, p, i)) &&
getArgType(mb, p, i) < TYPE_any &&
- getArgType(mb, p, i) >= 0 &&
ATOMstorage(getArgType(mb, p, i)) == TYPE_str)) {
+ (!isPolyType(getArgType(mb, p, i)) &&
+ getArgType(mb, p, i) < TYPE_any &&
+ getArgType(mb, p, i) >= 0 &&
+ ATOMstorage(getArgType(mb, p, i)) ==
TYPE_str)) {
getInstrPtr(mb, 0)->gc |= GARBAGECONTROL;
p->gc |= GARBAGECONTROL;
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list