Changeset: ff56155018b6 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ff56155018b6
Modified Files:
gdk/gdk_value.mx
Branch: default
Log Message:
Use VARconvert implementation for VALconvert.
VALconvert used an implementation which was very similar in function
to VARconvert. There is no need to keep two such similar pieces of
code.
Also reformatted some comments.
diffs (truncated from 478 to 300 lines):
diff --git a/gdk/gdk_value.mx b/gdk/gdk_value.mx
--- a/gdk/gdk_value.mx
+++ b/gdk/gdk_value.mx
@@ -29,16 +29,15 @@ All Rights Reserved.
* When manipulating values, MonetDB puts them into value records.
* The built-in types have a direct entry in the union. Others should
* be represented as a pointer of memory in pval or as a string, which
- * is basically the same. In such cases the len field indicates
- * the size of this piece of memory.
+ * is basically the same. In such cases the len field indicates the
+ * size of this piece of memory.
*
* MonetDB extenders will use value records for passing parameters to
- * their new operators. MonetDB algebraic commands receive an
- * (argc, argv) combination, where
- * argc is an integer indicating the size of the the argv array of value
- * records. On call, the first record, argv[0], is always empty. The
- * routine must place its return value - if any - there. The other
- * values are the parameters.
+ * their new operators. MonetDB algebraic commands receive an (argc,
+ * argv) combination, where argc is an integer indicating the size of
+ * the the argv array of value records. On call, the first record,
+ * argv[0], is always empty. The routine must place its return value -
+ * if any - there. The other values are the parameters.
*
* Actually, the gdk value type defined here should become a built-in
* type in the kernel. Next step will be to define the corresponding
@@ -183,7 +182,6 @@ VALinit(ValPtr d, int tpe, ptr s)
}
/*
- * @-
* VALprint shows the contents of a value record, but without
* expanding the BAT contents.
*/
@@ -206,421 +204,42 @@ VALformat(char **buf, ValPtr res)
}
/*
- * @-
- * The routine VALconvert transforms a value for interpretation
- * in a certain type. It uses some standard cast conventions to do this.
- * The result, a pointer to a value, is returned. If there are
- * illegal values, or type combinations involved, it gives
- * up with an ILLEGALVALUE.
+ * The routine VALconvert transforms a value for interpretation in a
+ * certain type. It uses some standard cast conventions to do this.
+ * The result, a pointer to a value, is returned. If there are illegal
+ * values, or type combinations involved, it gives up with an
+ * ILLEGALVALUE.
*/
-@= valcheck
- ((@3) @1 < (@3) GDK_@2_min || (@3) @1 > (@3) GDK_@2_max) ? @2_nil :
(@2) @1
-@= valcheck_r
- /* when converting from oid, there's no need to compare to GDK_@2_min,
- * since source value is unsigned (i.e. >= 0) and all GDK_*_min values
- * are <= 0 (in fact, compilers may warn about the test) */
- ((@3) @1 > (@3) GDK_@2_max) ? @2_nil : (@2) @1
-@= valcheck_l
- /* when converting to oid, there's no need to compare to GDK_@2_max
- * for those types, where we know that GDK_@2_max <= GDK_oid_max
- * (in fact, compilers may warn about the test) */
- ((@3) @1 < (@3) GDK_@2_min) ? @2_nil : (@2) @1
-@= valfconvert
- /* dbl always fits; flt almost always fits */
- switch (src_tpe) {
- case TYPE_bit:
- case TYPE_bte:
- @1 = (@2) src->val.btval;
- break;
- case TYPE_sht:
- @1 = (@2) src->val.shval;
- break;
- case TYPE_int:
- @1 = (@2) src->val.ival;
- break;
- case TYPE_oid:
- @1 = (@2) src->val.oval;
- break;
- case TYPE_wrd:
- @1 = (@2) src->val.wval;
- break;
- case TYPE_lng:
- @1 = (@2) src->val.lval;
- break;
- case TYPE_flt:
- @1 = (@2) src->val.fval;
- break;
- case TYPE_dbl:
- /* only need to do range check on dbl for dbl->flt conversion */
- if (src->val.dval < (dbl) GDK_@2_min || src->val.dval > (dbl)
GDK_@2_max)
- @1 = @2_nil;
- else
- @1 = (@2) src->val.dval;
- break;
- case TYPE_bat:
- @1 = (@2) src->val.bval;
- break;
- }
-@
-@c
-/* convert value in src and store in dst
- does not destroy src, but src and dst are allowed to point to the
- same location if the caller knows that that won't do any harm */
-static ptr
-VALconvert1(int typ, ValPtr src, ValPtr dst)
+ptr
+VALconvert(int typ, ValPtr t)
{
- int orig_src_tpe = src->vtype, src_tpe = src->vtype, dst_tpe = typ;
- ptr p; /* what's going to be returned (may change for
BATs */
+ int src_tpe = t->vtype;
+ ValRecord dst;
+ dst.vtype = typ;
/* use base types for user types */
if (src_tpe > TYPE_str)
src_tpe = ATOMstorage(src_tpe);
- if (dst_tpe > TYPE_str)
- dst_tpe = ATOMstorage(dst_tpe);
-
- if (src != dst)
- *dst = *src; /* copy already in case there is no conversion
*/
-
- /* we saved the original value of src->vtype, so we can
- overwrite that (in case src==dst */
- dst->vtype = typ;
- p = VALptr(dst);
-
- if (src_tpe != dst_tpe && orig_src_tpe != typ && dst_tpe != TYPE_void) {
- if (src_tpe >= TYPE_str || dst_tpe >= TYPE_str) {
- if (ATOMcmp(src_tpe, ATOMnilptr(src_tpe), VALptr(src))
== 0) {
- VALset(dst, dst_tpe, ATOMnil(dst_tpe));
- } else {
- return ILLEGALVALUE;
- }
- } else if ((orig_src_tpe == TYPE_bat && src->val.bval == 0) ||
- ATOMcmp(src_tpe, ATOMnilptr(src_tpe), VALptr(src))
== 0) {
- /* dst_tpe is a built-in type, so VALptr(dst)
- (p) points to valid memory */
- memcpy(p, ATOMnilptr(dst_tpe), ATOMsize(dst_tpe));
- } else {
- switch (dst_tpe) {
- case TYPE_bat:
- {
- bat bid = (bat) 0;
-
- switch (src_tpe) {
- case TYPE_bit:
- case TYPE_bte:
- if (ABS(src->val.btval) <= BBPsize)
- bid = (bat) src->val.btval;
- break;
- case TYPE_sht:
- if (ABS(src->val.shval) <= BBPsize)
- bid = (bat) src->val.shval;
- break;
- case TYPE_int:
- if (ABS(src->val.ival) <= BBPsize)
- bid = (bat) src->val.ival;
- break;
- case TYPE_oid:
- if (ABS(src->val.oval) <= BBPsize)
- bid = (bat) src->val.oval;
- break;
- case TYPE_wrd:
- if (ABS(src->val.wval) <= BBPsize)
- bid = (bat) src->val.wval;
- break;
- case TYPE_lng:
- if (ABS(src->val.lval) <= BBPsize)
- bid = (bat) src->val.lval;
- break;
- case TYPE_flt:
- if (ABS(src->val.fval) <= BBPsize)
- bid = (bat) src->val.fval;
- break;
- case TYPE_dbl:
- if (ABS(src->val.dval) <= BBPsize)
- bid = (bat) src->val.dval;
- break;
- }
- if (bid == 0 || !BBPvalid(bid)) {
- return ILLEGALVALUE;
- }
- dst->val.bval = bid;
- p = &dst->val.bval;
- break;
- }
- case TYPE_bit:
- /* bits are funny: true iff value != 0 */
- switch (src_tpe) {
- case TYPE_bit:
- case TYPE_bte:
- dst->val.btval = (src->val.btval != 0);
- break;
- case TYPE_sht:
- dst->val.btval = (src->val.shval != 0);
- break;
- case TYPE_int:
- dst->val.btval = (src->val.ival != 0);
- break;
- case TYPE_bat:
- dst->val.btval = (src->val.bval != 0);
- break;
- case TYPE_oid:
- dst->val.btval = (src->val.oval != 0);
- break;
- case TYPE_wrd:
- dst->val.btval = (src->val.wval != 0);
- break;
- case TYPE_lng:
- dst->val.btval = (src->val.lval != 0);
- break;
- case TYPE_flt:
- dst->val.btval = (src->val.fval != 0);
- break;
- case TYPE_dbl:
- dst->val.btval = (src->val.dval != 0);
- break;
- }
- break;
- case TYPE_bte:
- switch (src_tpe) {
- case TYPE_bit:
- case TYPE_bte:
- dst->val.btval = (bte) src->val.btval;
- break;
- case TYPE_sht:
- dst->val.btval =
@:valcheck(src->val.shval,bte,lng)@;
- break;
- case TYPE_int:
- dst->val.btval =
@:valcheck(src->val.ival,bte,lng)@;
- break;
- case TYPE_bat:
- dst->val.btval =
@:valcheck(src->val.bval,bte,lng)@;
- break;
- case TYPE_oid:
- dst->val.btval =
@:valcheck_r(src->val.oval,bte,lng)@;
- break;
- case TYPE_wrd:
- dst->val.btval =
@:valcheck(src->val.wval,bte,lng)@;
- break;
- case TYPE_lng:
- dst->val.btval =
@:valcheck(src->val.lval,bte,lng)@;
- break;
- case TYPE_flt:
- dst->val.btval =
@:valcheck(src->val.fval,bte,dbl)@;
- break;
- case TYPE_dbl:
- dst->val.btval =
@:valcheck(src->val.dval,bte,dbl)@;
- break;
- }
- break;
- case TYPE_sht:
- switch (src_tpe) {
- case TYPE_bit:
- case TYPE_bte:
- dst->val.shval = (sht) src->val.btval;
- break;
- case TYPE_sht:
- dst->val.shval = (sht) src->val.shval;
- break;
- case TYPE_int:
- dst->val.shval =
@:valcheck(src->val.ival,sht,lng)@;
- break;
- case TYPE_bat:
- dst->val.shval =
@:valcheck(src->val.bval,sht,lng)@;
- break;
- case TYPE_oid:
- dst->val.shval =
@:valcheck_r(src->val.oval,sht,lng)@;
- break;
- case TYPE_wrd:
- dst->val.shval =
@:valcheck(src->val.wval,sht,lng)@;
- break;
- case TYPE_lng:
- dst->val.shval =
@:valcheck(src->val.lval,sht,lng)@;
- break;
- case TYPE_flt:
- dst->val.shval =
@:valcheck(src->val.fval,sht,dbl)@;
- break;
- case TYPE_dbl:
- dst->val.shval =
@:valcheck(src->val.dval,sht,dbl)@;
- break;
- }
- break;
- case TYPE_int:
- switch (src_tpe) {
- case TYPE_bit:
- case TYPE_bte:
- dst->val.ival = (int) src->val.btval;
- break;
- case TYPE_sht:
- dst->val.ival = (int) src->val.shval;
- break;
- case TYPE_int:
- dst->val.ival = (int) src->val.ival;
- break;
- case TYPE_bat:
- dst->val.ival = (int) src->val.bval;
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list