[m-rev.] for review: switches on type_ctor_reps

Zoltan Somogyi zs at cs.mu.OZ.AU
Mon May 12 02:45:40 AEST 2003


For review by Fergus.

Zoltan.

Make sure that every switch in the runtime on type constructor representations
covers all the possible type_ctor_rep values. By using switches with no default
value, gcc will warn about any missing cases. To protect against illegal
values, we check whether the integer we convert to the MR_TypeCtorRep enum
is the right range. To protect against silent failures on platforms which
do not have a warning for missing cases, enforce a rule that all switch cases
return to the caller, instead of falling through to code that returns. (We
had no switches that were followed by any code more substantial than return,
and we are not likely to need one in the future either.)

runtime/mercury_construct.c:
runtime/mercury_deconstruct.c:
runtime/mercury_deep_copy_body.h:
runtime/mercury_ml_expand_body.h:
runtime/mercury_tabling.c:
runtime/mercury_unify_compare_body.h:
	Make the change described above. In some files, eliminating gcc
	warnings required adding previously unhandled cases.

runtime/mercury_type_info.h:
	Add a macro for doing the range test.

cvs diff: Diffing .
cvs diff: Diffing analysis
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/doc
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing boehm_gc/tests
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing deep_profiler
cvs diff: Diffing deep_profiler/notes
cvs diff: Diffing doc
cvs diff: Diffing extras
cvs diff: Diffing extras/aditi
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/concurrency
cvs diff: Diffing extras/curs
cvs diff: Diffing extras/curs/samples
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/error
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/lex
cvs diff: Diffing extras/lex/samples
cvs diff: Diffing extras/lex/tests
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/morphine
cvs diff: Diffing extras/morphine/non-regression-tests
cvs diff: Diffing extras/morphine/scripts
cvs diff: Diffing extras/morphine/source
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/quickcheck
cvs diff: Diffing extras/quickcheck/tutes
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/stream
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/xml
cvs diff: Diffing extras/xml/samples
cvs diff: Diffing java
cvs diff: Diffing java/library
cvs diff: Diffing java/runtime
cvs diff: Diffing library
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
Index: runtime/mercury_construct.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_construct.c,v
retrieving revision 1.9
diff -u -b -r1.9 mercury_construct.c
--- runtime/mercury_construct.c	10 Mar 2003 14:25:43 -0000	1.9
+++ runtime/mercury_construct.c	10 May 2003 05:08:05 -0000
@@ -45,6 +45,10 @@
     type_ctor_info = MR_TYPEINFO_GET_TYPE_CTOR_INFO(type_info);
     construct_info->type_ctor_rep = MR_type_ctor_rep(type_ctor_info);
 
+    if (! MR_type_ctor_has_valid_rep(type_ctor_info)) {
+        MR_fatal_error("MR_get_functor_info: term of unknown representation");
+    }
+
     switch(MR_type_ctor_rep(type_ctor_info)) {
 
     case MR_TYPECTOR_REP_RESERVED_ADDR:
@@ -71,7 +75,7 @@
             construct_info->arg_names =
                 functor_desc->MR_du_functor_arg_names;
         }
-        break;
+        return MR_TRUE;
 
     case MR_TYPECTOR_REP_ENUM:
     case MR_TYPECTOR_REP_ENUM_USEREQ:
@@ -93,7 +97,7 @@
             construct_info->arg_pseudo_type_infos = NULL;
             construct_info->arg_names = NULL;
         }
-        break;
+        return MR_TRUE;
 
     case MR_TYPECTOR_REP_NOTAG:
     case MR_TYPECTOR_REP_NOTAG_USEREQ:
@@ -117,7 +121,7 @@
             construct_info->arg_names =
                 &functor_desc->MR_notag_functor_arg_name;
         }
-        break;
+        return MR_TRUE;
 
     case MR_TYPECTOR_REP_EQUIV_GROUND:
     case MR_TYPECTOR_REP_EQUIV:
@@ -134,7 +138,7 @@
         /* Tuple types don't have pseudo-type_infos for the functors. */
         construct_info->arg_pseudo_type_infos = NULL;
         construct_info->arg_names = NULL;
-        break;
+        return MR_TRUE;
 
     case MR_TYPECTOR_REP_INT:
     case MR_TYPECTOR_REP_CHAR:
@@ -163,12 +167,14 @@
     case MR_TYPECTOR_REP_REFERENCE:
         return MR_FALSE;
 
+    case MR_TYPECTOR_REP_UNIV:
+        MR_fatal_error("MR_get_functor_info: bad type_ctor_rep");
+
     case MR_TYPECTOR_REP_UNKNOWN:
-    default:
-        MR_fatal_error(":construct - unexpected type.");
+        MR_fatal_error("MR_get_functor_info: unknown type_ctor_rep");
     }
 
-    return MR_TRUE;
+    MR_fatal_error("MR_get_functor_info: unexpected fallthrough");
 }
 
 /*
@@ -195,7 +201,7 @@
     int             comp;
     int             i;
 
-        /* Type check list of arguments */
+    /* Type check the list of arguments */
 
     for (i = 0; i < arity; i++) {
         if (MR_list_is_empty(arg_list)) {
@@ -269,6 +275,10 @@
 
     type_ctor_info = MR_TYPEINFO_GET_TYPE_CTOR_INFO(type_info);
 
+    if (! MR_type_ctor_has_valid_rep(type_ctor_info)) {
+        MR_fatal_error("MR_get_num_functors: term of unknown representation");
+    }
+
     switch(MR_type_ctor_rep(type_ctor_info)) {
         case MR_TYPECTOR_REP_DU:
         case MR_TYPECTOR_REP_DU_USEREQ:
@@ -276,23 +286,20 @@
         case MR_TYPECTOR_REP_RESERVED_ADDR_USEREQ:
         case MR_TYPECTOR_REP_ENUM:
         case MR_TYPECTOR_REP_ENUM_USEREQ:
-            functors = MR_type_ctor_num_functors(type_ctor_info);
-            break;
+            return MR_type_ctor_num_functors(type_ctor_info);
 
         case MR_TYPECTOR_REP_NOTAG:
         case MR_TYPECTOR_REP_NOTAG_USEREQ:
         case MR_TYPECTOR_REP_NOTAG_GROUND:
         case MR_TYPECTOR_REP_NOTAG_GROUND_USEREQ:
         case MR_TYPECTOR_REP_TUPLE:
-            functors = 1;
-            break;
+            return 1;
 
         case MR_TYPECTOR_REP_EQUIV_GROUND:
         case MR_TYPECTOR_REP_EQUIV:
-            functors = MR_get_num_functors(
+            return MR_get_num_functors(
                 MR_create_type_info((MR_TypeInfo *) type_info,
                     MR_type_ctor_layout(type_ctor_info).MR_layout_equiv));
-            break;
 
         case MR_TYPECTOR_REP_INT:
         case MR_TYPECTOR_REP_CHAR:
@@ -319,13 +326,14 @@
         case MR_TYPECTOR_REP_TICKET:
         case MR_TYPECTOR_REP_FOREIGN:
         case MR_TYPECTOR_REP_REFERENCE:
-            functors = -1;
-            break;
+            return -1;
+
+        case MR_TYPECTOR_REP_UNIV:
+            MR_fatal_error("MR_get_num_functors: bad type_ctor_rep");
 
         case MR_TYPECTOR_REP_UNKNOWN:
-        default:
             MR_fatal_error("MR_get_num_functors: unknown type_ctor_rep");
     }
 
-    return functors;
+    MR_fatal_error("MR_get_num_functors: unexpected fallthrough");
 }
Index: runtime/mercury_deconstruct.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_deconstruct.c,v
retrieving revision 1.13
diff -u -b -r1.13 mercury_deconstruct.c
--- runtime/mercury_deconstruct.c	2 May 2003 21:44:16 -0000	1.13
+++ runtime/mercury_deconstruct.c	10 May 2003 05:08:05 -0000
@@ -139,6 +139,10 @@
 
     type_ctor_info = MR_TYPEINFO_GET_TYPE_CTOR_INFO(type_info);
 
+    if (! MR_type_ctor_has_valid_rep(type_ctor_info)) {
+        MR_fatal_error("MR_named_arg_num: term of unknown representation");
+    }
+
     switch (MR_type_ctor_rep(type_ctor_info)) {
         case MR_TYPECTOR_REP_RESERVED_ADDR_USEREQ:
         case MR_TYPECTOR_REP_RESERVED_ADDR:
@@ -261,9 +265,42 @@
 
             return MR_FALSE;
 
-        default:
+        case MR_TYPECTOR_REP_ENUM:
+        case MR_TYPECTOR_REP_ENUM_USEREQ:
+        case MR_TYPECTOR_REP_INT:
+        case MR_TYPECTOR_REP_FLOAT:
+        case MR_TYPECTOR_REP_CHAR:
+        case MR_TYPECTOR_REP_STRING:
+        case MR_TYPECTOR_REP_FUNC:
+        case MR_TYPECTOR_REP_PRED:
+        case MR_TYPECTOR_REP_VOID:
+        case MR_TYPECTOR_REP_C_POINTER:
+        case MR_TYPECTOR_REP_TYPEINFO:
+        case MR_TYPECTOR_REP_TYPECTORINFO:
+        case MR_TYPECTOR_REP_TYPEDESC:
+        case MR_TYPECTOR_REP_TYPECTORDESC:
+        case MR_TYPECTOR_REP_TYPECLASSINFO:
+        case MR_TYPECTOR_REP_BASETYPECLASSINFO:
+        case MR_TYPECTOR_REP_SUCCIP:
+        case MR_TYPECTOR_REP_HP:
+        case MR_TYPECTOR_REP_CURFR:
+        case MR_TYPECTOR_REP_MAXFR:
+        case MR_TYPECTOR_REP_REDOFR:
+        case MR_TYPECTOR_REP_REDOIP:
+        case MR_TYPECTOR_REP_TICKET:
+        case MR_TYPECTOR_REP_TRAIL_PTR:
+        case MR_TYPECTOR_REP_REFERENCE:
+        case MR_TYPECTOR_REP_TUPLE:
+        case MR_TYPECTOR_REP_ARRAY:
+        case MR_TYPECTOR_REP_FOREIGN:
+        case MR_TYPECTOR_REP_UNKNOWN:
             return MR_FALSE;
+
+        case MR_TYPECTOR_REP_UNIV:
+            MR_fatal_error("MR_named_arg_num: bad type_ctor_rep");
     }
+
+    MR_fatal_error("MR_named_arg_num: unexpected fallthrough");
 }
 
 static MR_ConstString
Index: runtime/mercury_deep_copy_body.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_deep_copy_body.h,v
retrieving revision 1.59
diff -u -b -r1.59 mercury_deep_copy_body.h
--- runtime/mercury_deep_copy_body.h	21 Mar 2003 08:00:29 -0000	1.59
+++ runtime/mercury_deep_copy_body.h	10 May 2003 05:08:05 -0000
@@ -92,12 +92,15 @@
 try_again:
     type_ctor_info = MR_TYPEINFO_GET_TYPE_CTOR_INFO(type_info);
 
+    if (! MR_type_ctor_has_valid_rep(type_ctor_info)) {
+        MR_fatal_error(MR_STRINGIFY(copy) ": term of unknown representation");
+    }
+
     switch (MR_type_ctor_rep(type_ctor_info)) {
 
     case MR_TYPECTOR_REP_ENUM:
     case MR_TYPECTOR_REP_ENUM_USEREQ:
-        new_data = data;    /* just a copy of the actual item */
-        break;
+        return data;    /* just a copy of the actual item */
 
     case MR_TYPECTOR_REP_RESERVED_ADDR:
     case MR_TYPECTOR_REP_RESERVED_ADDR_USEREQ:
@@ -115,8 +118,7 @@
             if ((MR_Unsigned) data <
                 (MR_Unsigned) ra_layout->MR_ra_num_res_numeric_addrs)
             {
-                new_data = data;
-                break;
+                return data;
             }
 
             /*
@@ -160,8 +162,7 @@
 
             switch (ptag_layout->MR_sectag_locn) {
             case MR_SECTAG_LOCAL:
-                new_data = data;    /* just a copy of the actual item */
-                break;
+                return data;    /* just a copy of the actual item */
 
             /* case MR_SECTAG_REMOTE: */
             /* case MR_SECTAG_NONE: */
@@ -292,12 +293,12 @@
             case MR_SECTAG_REMOTE:
                 /* see comments above */
                 MR_handle_sectag_remote_or_none(MR_TRUE);
-                break;
+                return new_data;
 
             case MR_SECTAG_NONE:
                 /* see comments above */
                 MR_handle_sectag_remote_or_none(MR_FALSE);
-                break;
+                return new_data;
 
             case MR_SECTAG_VARIABLE:
                 MR_fatal_error("copy(): attempt to copy variable");
@@ -311,11 +312,10 @@
 
     case MR_TYPECTOR_REP_NOTAG:
     case MR_TYPECTOR_REP_NOTAG_USEREQ:
-        new_data = copy_arg(NULL, data, NULL,
+        return copy_arg(NULL, data, NULL,
             MR_TYPEINFO_GET_FIXED_ARITY_ARG_VECTOR(type_info),
             MR_type_ctor_layout(type_ctor_info).MR_layout_notag->
             MR_notag_functor_arg_type, lower_limit, upper_limit);
-        break;
 
     case MR_TYPECTOR_REP_NOTAG_GROUND:
     case MR_TYPECTOR_REP_NOTAG_GROUND_USEREQ:
@@ -323,25 +323,21 @@
             MR_type_ctor_layout(type_ctor_info).MR_layout_notag
             ->MR_notag_functor_arg_type);
         goto try_again;
-        break;
 
     case MR_TYPECTOR_REP_EQUIV:
-        new_data = copy_arg(NULL, data, NULL,
+        return copy_arg(NULL, data, NULL,
             MR_TYPEINFO_GET_FIXED_ARITY_ARG_VECTOR(type_info),
             MR_type_ctor_layout(type_ctor_info).MR_layout_equiv,
             lower_limit, upper_limit);
-        break;
 
     case MR_TYPECTOR_REP_EQUIV_GROUND:
         type_info = MR_pseudo_type_info_is_ground(
             MR_type_ctor_layout(type_ctor_info).MR_layout_equiv);
         goto try_again;
-        break;
 
     case MR_TYPECTOR_REP_INT:  /* fallthru */
     case MR_TYPECTOR_REP_CHAR:
-        new_data = data;
-        break;
+        return data;
 
     case MR_TYPECTOR_REP_FLOAT:
         #ifdef MR_BOXED_FLOAT
@@ -373,7 +369,7 @@
         #else
             new_data = data;
         #endif
-        break;
+        return new_data;
 
     case MR_TYPECTOR_REP_STRING:
         {
@@ -394,7 +390,7 @@
                 leave_forwarding_pointer(data, 0, new_data);
             }
         }
-        break;
+        return new_data;
 
     case MR_TYPECTOR_REP_FUNC:
     case MR_TYPECTOR_REP_PRED:
@@ -404,8 +400,8 @@
             assert(MR_tag(data) == 0);
             data_value = (MR_Word *) MR_body(data, MR_mktag(0));
 
-            RETURN_IF_OUT_OF_RANGE(data, data_value, CLOSURE_FORWARDING_PTR_OFFSET,
-                    MR_Word);
+            RETURN_IF_OUT_OF_RANGE(data, data_value,
+                    CLOSURE_FORWARDING_PTR_OFFSET, MR_Word);
 
             /*
             ** Closures have the structure given by the MR_Closure type.
@@ -463,7 +459,7 @@
                     new_data);
             }
         }
-        break;
+        return new_data;
 
     case MR_TYPECTOR_REP_TUPLE:
         {
@@ -500,11 +496,10 @@
                 }
             }
         }
-        break;
+        return new_data;
 
     case MR_TYPECTOR_REP_VOID:
         MR_fatal_error("Cannot copy a void type");
-        break;
 
     case MR_TYPECTOR_REP_ARRAY:
         {
@@ -535,36 +530,31 @@
                 leave_forwarding_pointer(data, 0, new_data);
             }
         }
-        break;
+        return new_data;
 
     case MR_TYPECTOR_REP_TYPEINFO:
     case MR_TYPECTOR_REP_TYPEDESC:
-        new_data = (MR_Word) copy_type_info((MR_TypeInfo) data,
+        return (MR_Word) copy_type_info((MR_TypeInfo) data,
             lower_limit, upper_limit);
-        break;
 
     case MR_TYPECTOR_REP_TYPECTORINFO:
         /* type_ctor_infos are always pointers to static data */
-        new_data = data;
-        break;
+        return data;
 
     case MR_TYPECTOR_REP_TYPECTORDESC:
         /*
         ** type_ctor_descs are always either encoded integers,
         ** or pointers to static data
         */
-        new_data = data;
-        break;
+        return data;
 
     case MR_TYPECTOR_REP_TYPECLASSINFO:
-        new_data = (MR_Word) copy_typeclass_info(data,
+        return (MR_Word) copy_typeclass_info(data,
             lower_limit, upper_limit);
-        break;
 
     case MR_TYPECTOR_REP_BASETYPECLASSINFO:
         /* base_typeclass_infos are always pointers to static data */
-        new_data = data;
-        break;
+        return data;
 
     case MR_TYPECTOR_REP_C_POINTER:
         {
@@ -586,13 +576,12 @@
                 new_data = data;
             }
         }
-        break;
+        return new_data;
 
     case MR_TYPECTOR_REP_SUCCIP: /* fallthru */
     case MR_TYPECTOR_REP_REDOIP:
         /* code addresses are never relocated */
-        new_data = data;
-        break;
+        return data;
 
     case MR_TYPECTOR_REP_HP:
         assert(MR_tag(data) == 0);
@@ -601,18 +590,18 @@
         } else {
             new_data = data;
         }
+        return new_data;
 
     case MR_TYPECTOR_REP_CURFR: /* fallthru */
-    case MR_TYPECTOR_REP_MAXFR:
+    case MR_TYPECTOR_REP_MAXFR: /* fallthru */
+    case MR_TYPECTOR_REP_REDOFR:
         /* we do not modify the layout of the nondet stack */
-        new_data = data;
-        break;
+        return data;
 
     case MR_TYPECTOR_REP_TRAIL_PTR:
     case MR_TYPECTOR_REP_TICKET:
         /* XXX we do not yet compress the trail when doing gc */
-        new_data = data;
-        break;
+        return data;
 
     case MR_TYPECTOR_REP_REFERENCE:
         {
@@ -632,16 +621,19 @@
                         (const MR_PseudoTypeInfo) 1, lower_limit, upper_limit);
             leave_forwarding_pointer(data, 0, new_data);
         }
-        break;
+        return new_data;
+
+    case MR_TYPECTOR_REP_FOREIGN:
+        MR_fatal_error("Cannot copy foreign types");
+
+    case MR_TYPECTOR_REP_UNIV:
+        MR_fatal_error(MR_STRINGIFY(copy) ": bad type_ctor_rep");
 
-    case MR_TYPECTOR_REP_FOREIGN: /* fallthru */
     case MR_TYPECTOR_REP_UNKNOWN: /* fallthru */
-    default:
         MR_fatal_error("Unknown layout type in deep copy");
-        break;
     }
 
-    return new_data;
+    MR_fatal_error(MR_STRINGIFY(copy) ": unexpected fallthough");
 }
 
 /*
Index: runtime/mercury_ml_expand_body.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_ml_expand_body.h,v
retrieving revision 1.26
diff -u -b -r1.26 mercury_ml_expand_body.h
--- runtime/mercury_ml_expand_body.h	2 May 2003 21:44:16 -0000	1.26
+++ runtime/mercury_ml_expand_body.h	10 May 2003 05:08:06 -0000
@@ -267,6 +267,11 @@
     expand_info->limit_reached = MR_FALSE;
 #endif  /* EXPAND_APPLY_LIMIT */
 
+    if (! MR_type_ctor_has_valid_rep(type_ctor_info)) {
+        MR_fatal_error(MR_STRINGIFY(EXPAND_FUNCTION_NAME)
+            ": term of unknown representation");
+    }
+
     switch(MR_type_ctor_rep(type_ctor_info)) {
 
         case MR_TYPECTOR_REP_ENUM_USEREQ:
@@ -274,11 +279,11 @@
                 /* XXX should throw an exception */
                 MR_fatal_error(MR_STRINGIFY(EXPAND_FUNCTION_NAME)
                     ": attempt to deconstruct noncanonical term");
-                break;
+                return;
             } else if (noncanon == MR_NONCANON_ALLOW) {
                 handle_noncanonical_name(type_ctor_info);
                 handle_zero_arity_args();
-                break;
+                return;
             }
             /* else fall through */
 
@@ -286,18 +291,18 @@
             handle_functor_name(MR_type_ctor_layout(type_ctor_info).
                     MR_layout_enum[*data_word_ptr]->MR_enum_functor_name);
             handle_zero_arity_args();
-            break;
+            return;
 
         case MR_TYPECTOR_REP_RESERVED_ADDR_USEREQ:
             if (noncanon == MR_NONCANON_ABORT) {
                 /* XXX should throw an exception */
                 MR_fatal_error(MR_STRINGIFY(EXPAND_FUNCTION_NAME)
                     ": attempt to deconstruct noncanonical term");
-                break;
+                return;
             } else if (noncanon == MR_NONCANON_ALLOW) {
                 handle_noncanonical_name(type_ctor_info);
                 handle_zero_arity_args();
-                break;
+                return;
             }
             /* else fall through */
 
@@ -321,7 +326,7 @@
 					handle_functor_name(ra_layout->MR_ra_constants[data]->
 							MR_ra_functor_name);
 					handle_zero_arity_args();
-					break;
+					return;
 				}
 
 				/*
@@ -355,11 +360,11 @@
                 /* XXX should throw an exception */
                 MR_fatal_error(MR_STRINGIFY(EXPAND_FUNCTION_NAME)
                     ": attempt to deconstruct noncanonical term");
-                break;
+                return;
             } else if (noncanon == MR_NONCANON_ALLOW) {
                 handle_noncanonical_name(type_ctor_info);
                 handle_zero_arity_args();
-                break;
+                return;
             }
             /* else fall through */
 
@@ -409,7 +414,6 @@
                             /* XXX should throw an exception */
                             MR_fatal_error(MR_STRINGIFY(EXPAND_FUNCTION_NAME)
                                 ": attempt to deconstruct variable");
-                            break;
                         } 
 
                         handle_functor_name("<<variable>>");
@@ -505,18 +509,18 @@
                 }
 #endif  /* EXPAND_ONE_ARG */
             }
-            break;
+            return;
 
         case MR_TYPECTOR_REP_NOTAG_USEREQ:
             if (noncanon == MR_NONCANON_ABORT) {
                 /* XXX should throw an exception */
                 MR_fatal_error(MR_STRINGIFY(EXPAND_FUNCTION_NAME)
                     ": attempt to deconstruct noncanonical term");
-                break;
+                return;
             } else if (noncanon == MR_NONCANON_ALLOW) {
                 handle_noncanonical_name(type_ctor_info);
                 handle_zero_arity_args();
-                break;
+                return;
             }
             /* else fall through */
 
@@ -561,18 +565,18 @@
                 expand_info->chosen_index_exists = MR_FALSE;
             }
 #endif  /* EXPAND_ONE_ARG */
-            break;
+            return;
 
         case MR_TYPECTOR_REP_NOTAG_GROUND_USEREQ:
             if (noncanon == MR_NONCANON_ABORT) {
                 /* XXX should throw an exception */
                 MR_fatal_error(MR_STRINGIFY(EXPAND_FUNCTION_NAME)
                     ": attempt to deconstruct noncanonical term");
-                break;
+                return;
             } else if (noncanon == MR_NONCANON_ALLOW) {
                 handle_noncanonical_name(type_ctor_info);
                 handle_zero_arity_args();
-                break;
+                return;
             }
             /* else fall through */
 
@@ -615,7 +619,7 @@
                 expand_info->chosen_index_exists = MR_FALSE;
             }
 #endif  /* EXPAND_ONE_ARG */
-            break;
+            return;
 
         case MR_TYPECTOR_REP_EQUIV:
             {
@@ -627,13 +631,13 @@
                 EXPAND_FUNCTION_NAME(eqv_type_info, data_word_ptr, noncanon,
                     EXTRA_ARGS expand_info);
             }
-            break;
+            return;
 
         case MR_TYPECTOR_REP_EQUIV_GROUND:
             EXPAND_FUNCTION_NAME(MR_pseudo_type_info_is_ground(
                 MR_type_ctor_layout(type_ctor_info).MR_layout_equiv),
                 data_word_ptr, noncanon, EXTRA_ARGS expand_info);
-            break;
+            return;
 
         case MR_TYPECTOR_REP_INT:
 #ifdef  EXPAND_FUNCTOR_FIELD
@@ -652,7 +656,7 @@
 #endif  /* EXPAND_FUNCTOR_FIELD */
 
             handle_zero_arity_args();
-            break;
+            return;
 
         case MR_TYPECTOR_REP_CHAR:
 #ifdef  EXPAND_FUNCTOR_FIELD
@@ -670,7 +674,7 @@
 #endif  /* EXPAND_FUNCTOR_FIELD */
 
             handle_zero_arity_args();
-            break;
+            return;
 
         case MR_TYPECTOR_REP_FLOAT:
 #ifdef  EXPAND_FUNCTOR_FIELD
@@ -691,7 +695,7 @@
 #endif  /* EXPAND_FUNCTOR_FIELD */
 
             handle_zero_arity_args();
-            break;
+            return;
 
         case MR_TYPECTOR_REP_STRING:
 #ifdef  EXPAND_FUNCTOR_FIELD
@@ -710,18 +714,18 @@
 #endif  /* EXPAND_FUNCTOR_FIELD */
 
             handle_zero_arity_args();
-            break;
+            return;
 
         case MR_TYPECTOR_REP_FUNC:
             if (noncanon == MR_NONCANON_ABORT) {
                 /* XXX should throw an exception */
                 MR_fatal_error(MR_STRINGIFY(EXPAND_FUNCTION_NAME)
                     ": attempt to deconstruct noncanonical term");
-                break;
+                return;
             } else if (higher_order_test(noncanon == MR_NONCANON_ALLOW)) {
                 handle_functor_name("<<function>>");
                 handle_zero_arity_args();
-                break;
+                return;
             } else {
                 goto predfunc;
             }
@@ -731,11 +735,11 @@
                 /* XXX should throw an exception */
                 MR_fatal_error(MR_STRINGIFY(EXPAND_FUNCTION_NAME)
                     ": attempt to deconstruct noncanonical term");
-                break;
+                return;
             } else if (higher_order_test(noncanon == MR_NONCANON_ALLOW)) {
                 handle_functor_name("<<predicate>>");
                 handle_zero_arity_args();
-                break;
+                return;
             } else {
                 goto predfunc;
             }
@@ -827,7 +831,7 @@
 #endif  /* EXPAND_NAMED_ARG */
             }
 
-            break;
+            return;
 
         case MR_TYPECTOR_REP_TUPLE:
             expand_info->arity = MR_TYPEINFO_GET_VAR_ARITY_ARITY(type_info);
@@ -866,7 +870,7 @@
                 expand_info->chosen_index_exists = MR_FALSE;
             }
 #endif  /* EXPAND_ONE_ARG */
-            break;
+            return;
 
         case MR_TYPECTOR_REP_UNIV: {
             MR_Word data_word;
@@ -881,7 +885,7 @@
             MR_unravel_univ(data_word, univ_type_info, univ_data);
             EXPAND_FUNCTION_NAME(univ_type_info, &univ_data, noncanon,
                 EXTRA_ARGS expand_info);
-            break;
+            return;
         }
 
         case MR_TYPECTOR_REP_VOID:
@@ -897,12 +901,12 @@
                 /* XXX should throw an exception */
                 MR_fatal_error(MR_STRINGIFY(EXPAND_FUNCTION_NAME)
                     ": attempt to deconstruct noncanonical term");
-                break;
+                return;
             }
 
             handle_functor_name("<<c_pointer>>");
             handle_zero_arity_args();
-            break;
+            return;
 
         case MR_TYPECTOR_REP_TYPEINFO:
         case MR_TYPECTOR_REP_TYPEDESC:
@@ -989,7 +993,7 @@
 #endif  /* EXPAND_ONE_ARG */
             }
 
-            break;
+            return;
 
         case MR_TYPECTOR_REP_TYPECTORINFO:
             {
@@ -1006,7 +1010,7 @@
                 handle_zero_arity_args();
             }
 
-            break;
+            return;
 
         case MR_TYPECTOR_REP_TYPECTORDESC:
             {
@@ -1032,31 +1036,31 @@
                 handle_zero_arity_args();
             }
 
-            break;
+            return;
 
         case MR_TYPECTOR_REP_TYPECLASSINFO:
             if (noncanon == MR_NONCANON_ABORT) {
                 /* XXX should throw an exception */
                 MR_fatal_error(MR_STRINGIFY(EXPAND_FUNCTION_NAME)
                     ": attempt to deconstruct noncanonical term");
-                break;
+                return;
             }
 
             handle_functor_name("<<typeclassinfo>>");
             handle_zero_arity_args();
-            break;
+            return;
 
         case MR_TYPECTOR_REP_BASETYPECLASSINFO:
             if (noncanon == MR_NONCANON_ABORT) {
                 /* XXX should throw an exception */
                 MR_fatal_error(MR_STRINGIFY(EXPAND_FUNCTION_NAME)
                     ": attempt to deconstruct noncanonical term");
-                break;
+                return;
             }
 
             handle_functor_name("<<basetypeclassinfo>>");
             handle_zero_arity_args();
-            break;
+            return;
 
         case MR_TYPECTOR_REP_ARRAY:
             {
@@ -1105,47 +1109,47 @@
                 }
 #endif  /* EXPAND_ONE_ARG */
             }
-            break;
+            return;
 
         case MR_TYPECTOR_REP_SUCCIP:
             handle_functor_name("<<succip>>");
             handle_zero_arity_args();
-            break;
+            return;
 
         case MR_TYPECTOR_REP_HP:
             handle_functor_name("<<hp>>");
             handle_zero_arity_args();
-            break;
+            return;
 
         case MR_TYPECTOR_REP_CURFR:
             handle_functor_name("<<curfr>>");
             handle_zero_arity_args();
-            break;
+            return;
 
         case MR_TYPECTOR_REP_MAXFR:
             handle_functor_name("<<maxfr>>");
             handle_zero_arity_args();
-            break;
+            return;
 
         case MR_TYPECTOR_REP_REDOFR:
             handle_functor_name("<<redofr>>");
             handle_zero_arity_args();
-            break;
+            return;
 
         case MR_TYPECTOR_REP_REDOIP:
             handle_functor_name("<<redoip>>");
             handle_zero_arity_args();
-            break;
+            return;
 
         case MR_TYPECTOR_REP_TRAIL_PTR:
             handle_functor_name("<<trail_ptr>>");
             handle_zero_arity_args();
-            break;
+            return;
 
         case MR_TYPECTOR_REP_TICKET:
             handle_functor_name("<<ticket>>");
             handle_zero_arity_args();
-            break;
+            return;
 
         case MR_TYPECTOR_REP_FOREIGN:
 #ifdef  MR_USE_MINIMAL_MODEL
@@ -1163,25 +1167,23 @@
             handle_functor_name("<<foreign>>");
 #endif
             handle_zero_arity_args();
-            break;
+            return;
 
         case MR_TYPECTOR_REP_REFERENCE:
             if (noncanon == MR_NONCANON_ABORT) {
                 /* XXX should throw an exception */
                 MR_fatal_error(MR_STRINGIFY(EXPAND_FUNCTION_NAME)
                     ": attempt to deconstruct noncanonical term");
-                break;
+                return;
             }
 
             handle_functor_name("<<reference>>");
             handle_zero_arity_args();
-            break;
+            return;
 
         case MR_TYPECTOR_REP_UNKNOWN:    /* fallthru */
-        default:
             MR_fatal_error(MR_STRINGIFY(EXPAND_FUNCTION_NAME)
                 ": cannot expand -- unknown data type");
-            break;
     }
 }
 
Index: runtime/mercury_tabling.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_tabling.c,v
retrieving revision 1.57
diff -u -b -r1.57 mercury_tabling.c
--- runtime/mercury_tabling.c	21 Mar 2003 08:00:30 -0000	1.57
+++ runtime/mercury_tabling.c	10 May 2003 05:08:06 -0000
@@ -851,12 +851,16 @@
     }
 #endif  /* MR_TABLE_DEBUG */
 
+    if (! MR_type_ctor_has_valid_rep(type_ctor_info)) {
+        MR_fatal_error("MR_table_type: term of unknown representation");
+    }
+
     switch (MR_type_ctor_rep(type_ctor_info)) {
         case MR_TYPECTOR_REP_ENUM: 
         case MR_TYPECTOR_REP_ENUM_USEREQ: 
             MR_DEBUG_TABLE_ENUM(table,
                 MR_type_ctor_num_functors(type_ctor_info), data);
-            break;
+            return table;
 
         case MR_TYPECTOR_REP_RESERVED_ADDR: 
         case MR_TYPECTOR_REP_RESERVED_ADDR_USEREQ: 
@@ -907,7 +911,6 @@
                 goto du_type;
             }
 
-            
         case MR_TYPECTOR_REP_DU: 
         case MR_TYPECTOR_REP_DU_USEREQ: 
             du_type_layout = MR_type_ctor_layout(type_ctor_info).MR_layout_du;
@@ -1012,7 +1015,7 @@
 
                 MR_deallocate(allocated_memory_cells);
             }
-            break;
+            return table;
 
         case MR_TYPECTOR_REP_NOTAG: 
         case MR_TYPECTOR_REP_NOTAG_USEREQ:
@@ -1027,14 +1030,14 @@
                 MR_DEBUG_TABLE_ANY(table, eqv_type_info, data);
                 MR_deallocate(allocated_memory_cells);
             }
-            break;
+            return table;
 
         case MR_TYPECTOR_REP_NOTAG_GROUND: 
         case MR_TYPECTOR_REP_NOTAG_GROUND_USEREQ:
             MR_DEBUG_TABLE_ANY(table, MR_pseudo_type_info_is_ground(
                 MR_type_ctor_layout(type_ctor_info).MR_layout_notag->
                 MR_notag_functor_arg_type), data);
-            break;
+            return table;
 
         case MR_TYPECTOR_REP_EQUIV:
             {
@@ -1048,28 +1051,29 @@
                 MR_DEBUG_TABLE_ANY(table, eqv_type_info, data);
                 MR_deallocate(allocated_memory_cells);
             }
-            break;
+
+            return table;
 
         case MR_TYPECTOR_REP_EQUIV_GROUND:
             MR_DEBUG_TABLE_ANY(table, MR_pseudo_type_info_is_ground(
                 MR_type_ctor_layout(type_ctor_info).MR_layout_equiv), data);
-            break;
+            return table;
 
         case MR_TYPECTOR_REP_INT:
             MR_DEBUG_TABLE_INT(table, data);
-            break;
+            return table;
 
         case MR_TYPECTOR_REP_CHAR:
             MR_DEBUG_TABLE_CHAR(table, data);
-            break;
+            return table;
 
         case MR_TYPECTOR_REP_FLOAT:
             MR_DEBUG_TABLE_FLOAT(table, data);
-            break;
+            return table;
 
         case MR_TYPECTOR_REP_STRING:
             MR_DEBUG_TABLE_STRING(table, (MR_String) data);
-            break;
+            return table;
 
         case MR_TYPECTOR_REP_FUNC:
         case MR_TYPECTOR_REP_PRED:
@@ -1099,7 +1103,8 @@
                 */
                 MR_DEBUG_TABLE_INT(table, data);
         #endif
-                break;
+
+                return table;
             }
 
         case MR_TYPECTOR_REP_TUPLE:
@@ -1118,37 +1123,32 @@
                     MR_DEBUG_TABLE_ANY(table, arg_type_info_vector[i + 1],
                         data_value[i]);
                 }
-                break;
+
+                return table;
             }
 
         case MR_TYPECTOR_REP_VOID:
             MR_fatal_error("Cannot table a void type");
-            break;
 
         case MR_TYPECTOR_REP_C_POINTER:
             MR_fatal_error("Attempt to table a C_POINTER");
-            break;
 
         case MR_TYPECTOR_REP_TYPEINFO:
         case MR_TYPECTOR_REP_TYPEDESC:
             MR_DEBUG_TABLE_TYPEINFO(table, (MR_TypeInfo) data);
-            break;
+            return table;
 
         case MR_TYPECTOR_REP_TYPECTORINFO:
             MR_fatal_error("Attempt to table a type_ctor_info");
-            break;
 
         case MR_TYPECTOR_REP_TYPECTORDESC:
             MR_fatal_error("Attempt to table a type_ctor_desc");
-            break;
 
         case MR_TYPECTOR_REP_TYPECLASSINFO:
             MR_fatal_error("Attempt to table a type_class_info");
-            break;
 
         case MR_TYPECTOR_REP_BASETYPECLASSINFO:
             MR_fatal_error("Attempt to table a base_type_class_info");
-            break;
 
         case MR_TYPECTOR_REP_ARRAY:
             {
@@ -1171,57 +1171,48 @@
                 }
 
                 MR_deallocate(allocated_memory_cells);
-                break;
+                return table;
             }
 
         case MR_TYPECTOR_REP_SUCCIP:
             MR_fatal_error("Attempt to table a saved succip");
-            break;
 
         case MR_TYPECTOR_REP_HP:
             MR_fatal_error("Attempt to table a saved hp");
-            break;
 
         case MR_TYPECTOR_REP_CURFR:
             MR_fatal_error("Attempt to table a saved curfr");
-            break;
 
         case MR_TYPECTOR_REP_MAXFR:
             MR_fatal_error("Attempt to table a saved maxfr");
-            break;
 
         case MR_TYPECTOR_REP_REDOFR:
             MR_fatal_error("Attempt to table a saved redofr");
-            break;
 
         case MR_TYPECTOR_REP_REDOIP:
             MR_fatal_error("Attempt to table a saved redoip");
-            break;
 
         case MR_TYPECTOR_REP_TRAIL_PTR:
             MR_fatal_error("Attempt to table a saved trail pointer");
-            break;
 
         case MR_TYPECTOR_REP_TICKET:
             MR_fatal_error("Attempt to table a saved ticket");
-            break;
 
         case MR_TYPECTOR_REP_FOREIGN:
             MR_fatal_error("Attempt to table a value of a foreign type");
-            break;
 
         case MR_TYPECTOR_REP_REFERENCE:
             MR_fatal_error("Attempt to table a value of a reference type");
-            break;
+
+        case MR_TYPECTOR_REP_UNIV:
+            MR_fatal_error("MR_table_any: bad type_ctor_rep");
 
         case MR_TYPECTOR_REP_UNKNOWN: /* fallthru */
-        default:
             MR_fatal_error("Unknown layout tag in table_any");
-            break;
     }
 
-    return table;
-} /* end table_any() */
+    MR_fatal_error("MR_table_type:unexpected fallthrough");
+}
 
 /*---------------------------------------------------------------------------*/
 
Index: runtime/mercury_type_info.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_type_info.h,v
retrieving revision 1.102
diff -u -b -r1.102 mercury_type_info.h
--- runtime/mercury_type_info.h	21 Mar 2003 08:00:31 -0000	1.102
+++ runtime/mercury_type_info.h	10 May 2003 05:08:07 -0000
@@ -1046,6 +1046,15 @@
 */
 };
 
+/*
+** Check whether an MR_TypeCtorRepInt is a valid MR_TypeCtorRep value.
+*/
+
+#define MR_type_ctor_rep_is_valid(rep_int)                                  \
+    ((unsigned) (rep_int) <= (unsigned) MR_TYPECTOR_REP_UNKNOWN)
+#define MR_type_ctor_has_valid_rep(type_ctor_info)                          \
+    (MR_type_ctor_rep_is_valid(type_ctor_info->MR_type_ctor_rep_CAST_ME))
+
 #define MR_type_ctor_rep(tci)                                               \
     ((MR_TypeCtorRep) ((tci)->MR_type_ctor_rep_CAST_ME))
 
Index: runtime/mercury_unify_compare_body.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_unify_compare_body.h,v
retrieving revision 1.30
diff -u -b -r1.30 mercury_unify_compare_body.h
--- runtime/mercury_unify_compare_body.h	16 Feb 2003 13:25:28 -0000	1.30
+++ runtime/mercury_unify_compare_body.h	10 May 2003 05:08:07 -0000
@@ -90,6 +90,10 @@
     MR_register_type_ctor_stat(&type_stat_struct, type_ctor_info);
 #endif
 
+    if (! MR_type_ctor_has_valid_rep(type_ctor_info)) {
+        MR_fatal_error(attempt_msg "terms of unknown representation");
+    }
+
     switch (MR_type_ctor_rep(type_ctor_info)) {
 
 #if defined(MR_COMPARE_BY_RTTI) || defined(include_compare_rep_code)
@@ -369,7 +373,7 @@
   #endif
             }
 
-            break;
+            MR_fatal_error(MR_STRINGIFY(start_label) ": expected fall thru");
 
 #endif  /* defined(MR_COMPARE_BY_RTTI) || defined(include_compare_rep_code) */
 
@@ -678,6 +682,34 @@
         case MR_TYPECTOR_REP_BASETYPECLASSINFO:
             MR_fatal_error(attempt_msg "base_typeclass_infos");
 
+        case MR_TYPECTOR_REP_UNIV:
+            /* univ is now implemented as a user-defined type */
+            MR_fatal_error(attempt_msg "univ");
+
+        case MR_TYPECTOR_REP_HP:
+            MR_fatal_error(attempt_msg "hp");
+
+        case MR_TYPECTOR_REP_SUCCIP:
+            MR_fatal_error(attempt_msg "succip");
+
+        case MR_TYPECTOR_REP_CURFR:
+            MR_fatal_error(attempt_msg "curfr");
+
+        case MR_TYPECTOR_REP_MAXFR:
+            MR_fatal_error(attempt_msg "maxfr");
+
+        case MR_TYPECTOR_REP_REDOFR:
+            MR_fatal_error(attempt_msg "redofr");
+
+        case MR_TYPECTOR_REP_REDOIP:
+            MR_fatal_error(attempt_msg "redoip");
+
+        case MR_TYPECTOR_REP_TICKET:
+            MR_fatal_error(attempt_msg "ticket");
+
+        case MR_TYPECTOR_REP_TRAIL_PTR:
+            MR_fatal_error(attempt_msg "trail_ptr");
+
         case MR_TYPECTOR_REP_REFERENCE:
 #ifdef  select_compare_code
             /*
@@ -692,10 +724,9 @@
 
         case MR_TYPECTOR_REP_UNKNOWN:
             MR_fatal_error(attempt_msg "terms of unknown type");
-
-        default:
-            MR_fatal_error(attempt_msg "terms of unknown representation");
     }
+
+    MR_fatal_error("got to the end of " MR_STRINGIFY(start_label));
 
 #ifdef  select_compare_code
   #undef    return_compare_answer
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/tests
cvs diff: Diffing samples/tests/c_interface
cvs diff: Diffing samples/tests/c_interface/c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/tests/c_interface/mercury_calls_c
cvs diff: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/tests/diff
cvs diff: Diffing samples/tests/muz
cvs diff: Diffing samples/tests/rot13
cvs diff: Diffing samples/tests/solutions
cvs diff: Diffing samples/tests/toplevel
cvs diff: Diffing scripts
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/debugger/declarative
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/general/accumulator
cvs diff: Diffing tests/general/string_format
cvs diff: Diffing tests/general/structure_reuse
cvs diff: Diffing tests/grade_subdirs
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/purity
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/invalid/purity
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/mmc_make
cvs diff: Diffing tests/mmc_make/lib
cvs diff: Diffing tests/recompilation
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trace
cvs diff: Diffing util
cvs diff: Diffing vim
cvs diff: Diffing vim/after
cvs diff: Diffing vim/ftplugin
cvs diff: Diffing vim/syntax
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list