[svn:parrot] r48689 - trunk/src/pmc

NotFound at svn.parrot.org NotFound at svn.parrot.org
Fri Aug 27 07:09:36 UTC 2010


Author: NotFound
Date: Fri Aug 27 07:09:35 2010
New Revision: 48689
URL: https://trac.parrot.org/parrot/changeset/48689

Log:
avoid duplicated code in Exception vtable functions

Modified:
   trunk/src/pmc/exception.pmc

Modified: trunk/src/pmc/exception.pmc
==============================================================================
--- trunk/src/pmc/exception.pmc	Fri Aug 27 06:51:45 2010	(r48688)
+++ trunk/src/pmc/exception.pmc	Fri Aug 27 07:09:35 2010	(r48689)
@@ -301,7 +301,7 @@
 
 /*
 
-=item C<INTVAL get_integer_keyed(PMC *key)>
+=item C<INTVAL get_integer_keyed_str(STRING *key)>
 
 Returns the integer value for C<*key>.
 
@@ -309,11 +309,9 @@
 
 */
 
-    VTABLE INTVAL get_integer_keyed(PMC *key) {
-        STRING * const name = VTABLE_get_string(INTERP, key);
-        INTVAL  result = 0;
-
-        switch (getAttrEnum(INTERP, name)) {
+    VTABLE INTVAL get_integer_keyed_str(STRING *key) {
+        INTVAL result = 0;
+        switch (getAttrEnum(INTERP, key)) {
           case attr_type:
             GET_ATTR_type(INTERP, SELF, result);
             break;
@@ -329,7 +327,7 @@
           default:
             /* If unknown attribute name, throw an exception. */
             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ATTRIB_NOT_FOUND,
-                "No such integer attribute '%S'", name);
+                "No such integer attribute '%S'", key);
         }
 
         return result;
@@ -337,7 +335,7 @@
 
 /*
 
-=item C<INTVAL get_integer_keyed_str(STRING *key)>
+=item C<INTVAL get_integer_keyed(PMC *key)>
 
 Returns the integer value for C<*key>.
 
@@ -345,28 +343,9 @@
 
 */
 
-    VTABLE INTVAL get_integer_keyed_str(STRING *key) {
-        INTVAL result = 0;
-        switch (getAttrEnum(INTERP, key)) {
-          case attr_type:
-            GET_ATTR_type(INTERP, SELF, result);
-            break;
-          case attr_severity:
-            GET_ATTR_severity(INTERP, SELF, result);
-            break;
-          case attr_exit_code:
-            GET_ATTR_exit_code(INTERP, SELF, result);
-            break;
-          case attr_handled:
-            GET_ATTR_handled(INTERP, SELF, result);
-            break;
-          default:
-            /* If unknown attribute name, throw an exception. */
-            Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ATTRIB_NOT_FOUND,
-                "No such integer attribute '%S'", key);
-        }
-
-        return result;
+    VTABLE INTVAL get_integer_keyed(PMC *key) {
+        STRING * const name = VTABLE_get_string(INTERP, key);
+        return SELF.get_integer_keyed_str(name);
     }
 
 /*
@@ -454,7 +433,7 @@
 
 /*
 
-=item C<void set_integer_keyed(PMC *key, INTVAL value)>
+=item C<void set_integer_keyed_str(STRING *key, INTVAL value) >
 
 Sets the integer value for C<*key>.
 
@@ -462,9 +441,8 @@
 
 */
 
-    VTABLE void set_integer_keyed(PMC *key, INTVAL value) {
-        STRING * const name = VTABLE_get_string(INTERP, key);
-        switch (getAttrEnum(INTERP, name)) {
+    VTABLE void set_integer_keyed_str(STRING *key, INTVAL value) {
+        switch (getAttrEnum(INTERP, key)) {
           case attr_type:
             SET_ATTR_type(INTERP, SELF, value);
             break;
@@ -480,13 +458,13 @@
           default:
             /* If unknown attribute name, throw an exception. */
             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ATTRIB_NOT_FOUND,
-                "No such integer attribute '%S'", name);
+                "No such integer attribute '%S'", key);
         }
     }
 
 /*
 
-=item C<void set_integer_keyed_str(STRING *key, INTVAL value) >
+=item C<void set_integer_keyed(PMC *key, INTVAL value)>
 
 Sets the integer value for C<*key>.
 
@@ -494,25 +472,9 @@
 
 */
 
-    VTABLE void set_integer_keyed_str(STRING *key, INTVAL value) {
-        switch (getAttrEnum(INTERP, key)) {
-          case attr_type:
-            SET_ATTR_type(INTERP, SELF, value);
-            break;
-          case attr_severity:
-            SET_ATTR_severity(INTERP, SELF, value);
-            break;
-          case attr_exit_code:
-            SET_ATTR_exit_code(INTERP, SELF, value);
-            break;
-          case attr_handled:
-            SET_ATTR_handled(INTERP, SELF, value);
-            break;
-          default:
-            /* If unknown attribute name, throw an exception. */
-            Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ATTRIB_NOT_FOUND,
-                "No such integer attribute '%S'", key);
-        }
+    VTABLE void set_integer_keyed(PMC *key, INTVAL value) {
+        STRING * const name = VTABLE_get_string(INTERP, key);
+        SELF.set_integer_keyed_str(name, value);
     }
 
 /*


More information about the parrot-commits mailing list