Remove remaining GMX_ERROR uses.
authorTeemu Murtola <teemu.murtola@gmail.com>
Thu, 23 Aug 2012 17:44:31 +0000 (20:44 +0300)
committerTeemu Murtola <teemu.murtola@gmail.com>
Tue, 28 Aug 2012 03:43:07 +0000 (06:43 +0300)
Replaced those still left in selection parsing code by exceptions or
assertions.

Related to #655 and #880.

Change-Id: I89bff0c03eb15176e699529888aaae532f0c4138

src/gromacs/selection/params.cpp
src/gromacs/selection/parsetree.cpp
src/gromacs/selection/scanner_internal.cpp
src/gromacs/selection/selmethod.h

index e83f7074ac5b95c2b418af0ec4405a0971e2e2ea..58fdca9cc8f6e0044e282202e9262ab57cb53010 100644 (file)
@@ -45,7 +45,6 @@
 #include "gromacs/selection/position.h"
 #include "gromacs/selection/selmethod.h"
 #include "gromacs/selection/selparam.h"
-#include "gromacs/utility/errorcodes.h"
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/messagestringcollector.h"
@@ -303,11 +302,8 @@ parse_values_range(const SelectionParserValueList &values,
     int                 i, j, n;
 
     param->flags &= ~SPAR_DYNAMIC;
-    if (param->val.type != INT_VALUE && param->val.type != REAL_VALUE)
-    {
-        GMX_ERROR_NORET(gmx::eeInternalError, "Invalid range parameter type");
-        return false;
-    }
+    GMX_RELEASE_ASSERT(param->val.type == INT_VALUE || param->val.type == REAL_VALUE,
+                       "Invalid range parameter type");
     idata = NULL;
     rdata = NULL;
     if (param->val.type == INT_VALUE)
@@ -327,11 +323,8 @@ parse_values_range(const SelectionParserValueList &values,
             _gmx_selparser_error(scanner, "expressions not supported within range parameters");
             return false;
         }
-        if (value->type != param->val.type)
-        {
-            GMX_ERROR_NORET(gmx::eeInternalError, "Invalid range value type");
-            return false;
-        }
+        GMX_RELEASE_ASSERT(value->type == param->val.type,
+                           "Invalid range value type (should have been caught earlier)");
         if (param->val.type == INT_VALUE)
         {
             int i1 = std::min(value->u.i.i1, value->u.i.i2);
@@ -491,9 +484,7 @@ parse_values_varnum(const SelectionParserValueList &values,
     if (param->val.type != INT_VALUE && param->val.type != REAL_VALUE
         && param->val.type != STR_VALUE && param->val.type != POS_VALUE)
     {
-        GMX_ERROR_NORET(gmx::eeInternalError,
-                        "Variable-count value type not implemented");
-        return false;
+        GMX_THROW(gmx::InternalError("Variable-count value type not implemented"));
     }
 
     /* Reserve appropriate amount of memory */
@@ -517,11 +508,8 @@ parse_values_varnum(const SelectionParserValueList &values,
             _gmx_selparser_error(scanner, "expressions not supported within value lists");
             return false;
         }
-        if (value->type != param->val.type)
-        {
-            GMX_ERROR_NORET(gmx::eeInternalError, "Invalid value type");
-            return false;
-        }
+        GMX_RELEASE_ASSERT(value->type == param->val.type,
+                           "Invalid value type (should have been caught earlier)");
         switch (param->val.type)
         {
             case INT_VALUE:
@@ -553,8 +541,7 @@ parse_values_varnum(const SelectionParserValueList &values,
                 break;
             case POS_VALUE:  copy_rvec(value->u.x, param->val.u.p->x[i++]); break;
             default: /* Should not be reached */
-                GMX_ERROR_NORET(gmx::eeInternalError, "Invalid value type");
-                return false;
+                GMX_THROW(gmx::InternalError("Variable-count value type not implemented"));
         }
     }
     param->val.nr = i;
@@ -657,11 +644,8 @@ parse_values_varnum_expr(const SelectionParserValueList &values,
                          const SelectionTreeElementPointer &root,
                          void *scanner)
 {
-    if (values.size() != 1 || !values.front().hasExpressionValue())
-    {
-        GMX_ERROR_NORET(gmx::eeInternalError, "Invalid expression value");
-        return false;
-    }
+    GMX_RELEASE_ASSERT(values.size() == 1 && values.front().hasExpressionValue(),
+            "Called with an invalid type of value");
 
     SelectionTreeElementPointer child
         = add_child(root, param, values.front().expr, scanner);
@@ -730,8 +714,7 @@ set_expr_value_store(const SelectionTreeElementPointer &sel,
         case POS_VALUE:   sel->v.u.p = &param->val.u.p[i]; break;
         case GROUP_VALUE: sel->v.u.g = &param->val.u.g[i]; break;
         default: /* Error */
-            GMX_ERROR_NORET(gmx::eeInternalError, "Invalid value type");
-            return false;
+            GMX_THROW(gmx::InternalError("Invalid value type"));
     }
     sel->v.nr = 1;
     sel->v.nalloc = -1;
@@ -886,9 +869,7 @@ parse_values_std(const SelectionParserValueList &values,
                     break;
                 case NO_VALUE:
                 case GROUP_VALUE:
-                    GMX_ERROR_NORET(gmx::eeInternalError,
-                                    "Invalid non-expression value");
-                    return false;
+                    GMX_THROW(gmx::InternalError("Invalid non-expression value type"));
             }
         }
         ++i;
@@ -930,20 +911,15 @@ parse_values_bool(const std::string &name,
                   const SelectionParserValueList &values,
                   gmx_ana_selparam_t *param, void *scanner)
 {
-    bool bSetNo;
-
-    if (param->val.type != NO_VALUE)
-    {
-        GMX_ERROR_NORET(gmx::eeInternalError, "Invalid boolean parameter");
-        return false;
-    }
+    GMX_ASSERT(param->val.type == NO_VALUE,
+            "Boolean parser called for non-boolean parameter");
     if (values.size() > 1 || (!values.empty() && values.front().type != INT_VALUE))
     {
         _gmx_selparser_error(scanner, "parameter takes only a yes/no/on/off/0/1 value");
         return false;
     }
 
-    bSetNo = false;
+    bool bSetNo = false;
     /* Check if the parameter name is given with a 'no' prefix */
     if (name.length() > 2 && name[0] == 'n' && name[1] == 'o'
         && name.compare(2, name.length() - 2, param->name) == 0)
@@ -978,17 +954,16 @@ parse_values_enum(const SelectionParserValueList &values,
                   gmx_ana_selparam_t *param,
                   void *scanner)
 {
+    GMX_ASSERT(param->val.type == STR_VALUE,
+            "Enum parser called for non-string parameter");
     if (values.size() != 1)
     {
         _gmx_selparser_error(scanner, "a single value is required");
         return false;
     }
     const SelectionParserValue &value = values.front();
-    if (value.type != STR_VALUE || param->val.type != STR_VALUE)
-    {
-        GMX_ERROR_NORET(gmx::eeInternalError, "Invalid enum parameter");
-        return false;
-    }
+    GMX_RELEASE_ASSERT(value.type == param->val.type,
+                       "Invalid value type (should have been caught earlier)");
     if (value.hasExpressionValue())
     {
         _gmx_selparser_error(scanner, "expression value for enumerated parameter not supported");
@@ -1051,9 +1026,8 @@ convert_const_values(SelectionParserValueList *values)
                     *value = SelectionParserValue::createPosition(expr->v.u.p->x[0]);
                     break;
                 default:
-                    GMX_ERROR_NORET(gmx::eeInternalError,
-                                    "Unsupported value type");
-                    break;
+                    GMX_THROW(gmx::InternalError(
+                                "Unsupported constant expression value type"));
             }
         }
     }
index a2b8ebc7e3a9b8265bfc6ac1a0e4a00e7cf15b28..05ae205c5f7939f556e7cb1b9bf651c2a59f4027 100644 (file)
 #include "gromacs/selection/poscalc.h"
 #include "gromacs/selection/selection.h"
 #include "gromacs/selection/selmethod.h"
-#include "gromacs/utility/errorcodes.h"
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/file.h"
 #include "gromacs/utility/messagestringcollector.h"
@@ -494,10 +493,6 @@ _gmx_selelem_init_method_params(const SelectionTreeElementPointer &sel,
     if (sel->u.expr.method->init_data)
     {
         mdata = sel->u.expr.method->init_data(nparams, param);
-        if (mdata == NULL)
-        {
-            GMX_ERROR_NORET(gmx::eeInvalidValue, "Method data initialization failed");
-        }
     }
     if (sel->u.expr.method->set_poscoll)
     {
index de589f9e530390aa81cbae07a68a93fb8dd3f37f..1371fd6328bb7f3b0d65190c87967a9fe101eb33 100644 (file)
@@ -60,7 +60,6 @@
 #include "gromacs/legacyheaders/smalloc.h"
 #include "gromacs/legacyheaders/string2.h"
 
-#include "gromacs/utility/errorcodes.h"
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/messagestringcollector.h"
@@ -133,8 +132,7 @@ init_method_token(YYSTYPE *yylval, gmx_ana_selmethod_t *method, bool bPosMod,
             case STR_VALUE:   return KEYWORD_STR;
             case GROUP_VALUE: return KEYWORD_GROUP;
             default:
-                GMX_ERROR_NORET(gmx::eeInternalError, "Unsupported keyword type");
-                return INVALID;
+                GMX_THROW(gmx::InternalError("Unsupported keyword type"));
         }
     }
     else
@@ -175,8 +173,7 @@ init_method_token(YYSTYPE *yylval, gmx_ana_selmethod_t *method, bool bPosMod,
             case GROUP_VALUE: return METHOD_GROUP;
             default:
                 --state->msp;
-                GMX_ERROR_NORET(gmx::eeInternalError, "Unsupported method type");
-                return INVALID;
+                GMX_THROW(gmx::InternalError("Unsupported method type"));
         }
     }
     return INVALID; /* Should not be reached */
@@ -310,9 +307,7 @@ _gmx_sel_lexer_process_identifier(YYSTYPE *yylval, char *yytext, size_t yyleng,
                 case POS_VALUE:
                     break;
                 default:
-                    GMX_ERROR_NORET(gmx::eeInternalError,
-                                    "Unsupported variable type");
-                    return INVALID;
+                    GMX_THROW(gmx::InternalError("Unsupported variable type"));
             }
         }
         yylval->sel = new gmx::SelectionTreeElementPointer(var);
@@ -324,8 +319,7 @@ _gmx_sel_lexer_process_identifier(YYSTYPE *yylval, char *yytext, size_t yyleng,
             case GROUP_VALUE: return VARIABLE_GROUP;
             default:
                 delete yylval->sel;
-                GMX_ERROR_NORET(gmx::eeInternalError,
-                                "Unsupported variable type");
+                GMX_THROW(gmx::InternalError("Unsupported variable type"));
                 return INVALID;
         }
         delete yylval->sel;
index ccca8df62ba224d733fbd2de39f3595fff5cec1e..1aad394ab751d4f982e61b5e349bf5e36555bd57 100644 (file)
@@ -356,8 +356,8 @@ struct gmx_ana_selcollection_t;
  * \returns       Pointer to method-specific data structure.
  *   This pointer will be passed as the last parameter of all other function
  *   calls.
- *   Should return NULL on error (only error that should occur is out of
- *   memory).
+ * \throws        unspecified Any errors should be indicated by throwing an
+ *      exception.
  *
  * Should allocate and initialize any internal data required by the method.
  * Should also initialize the value pointers (\c gmx_ana_selparam_t::val) in