* Each element has exactly two children (one for unary negation elements),
* which are in the order given in the input.
*/
-#include <stdio.h>
+#include "gmxpre.h"
+
+#include "parsetree.h"
+
#include <stdarg.h>
+#include <stdio.h>
#include <boost/exception_ptr.hpp>
#include <boost/shared_ptr.hpp>
-#include "gromacs/selection/poscalc.h"
#include "gromacs/selection/selection.h"
-#include "gromacs/selection/selmethod.h"
+#include "gromacs/utility/cstringutil.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/file.h"
#include "gromacs/utility/messagestringcollector.h"
#include "gromacs/utility/stringutil.h"
#include "keywords.h"
-#include "parsetree.h"
+#include "poscalc.h"
+#include "scanner.h"
#include "selectioncollection-impl.h"
#include "selelem.h"
+#include "selmethod.h"
#include "symrec.h"
-#include "scanner.h"
-
using gmx::SelectionParserValue;
using gmx::SelectionParserValueList;
using gmx::SelectionParserValueListPointer;
buf[0] = op;
buf[1] = 0;
sel->setName(buf);
- sel->u.arith.opstr = strdup(buf);
+ sel->u.arith.opstr = gmx_strdup(buf);
sel->child = left;
sel->child->next = right;
return sel;
SelectionTreeElementPointer sel(new SelectionTreeElement(SEL_GROUPREF));
_gmx_selelem_set_vtype(sel, GROUP_VALUE);
sel->setName(gmx::formatString("group \"%s\"", name));
- sel->u.gref.name = strdup(name);
+ sel->u.gref.name = gmx_strdup(name);
sel->u.gref.id = -1;
if (_gmx_sel_lexer_has_groups_set(scanner))
{
- gmx_ana_indexgrps_t *grps = _gmx_sel_lexer_indexgrps(scanner);
- sel->resolveIndexGroupReference(grps);
+ gmx_ana_indexgrps_t *grps = _gmx_sel_lexer_indexgrps(scanner);
+ gmx_ana_selcollection_t *sc = _gmx_sel_lexer_selcollection(scanner);
+ sel->resolveIndexGroupReference(grps, sc->gall.isize);
}
return sel;
if (_gmx_sel_lexer_has_groups_set(scanner))
{
- gmx_ana_indexgrps_t *grps = _gmx_sel_lexer_indexgrps(scanner);
- sel->resolveIndexGroupReference(grps);
+ gmx_ana_indexgrps_t *grps = _gmx_sel_lexer_indexgrps(scanner);
+ gmx_ana_selcollection_t *sc = _gmx_sel_lexer_selcollection(scanner);
+ sel->resolveIndexGroupReference(grps, sc->gall.isize);
}
return sel;
}
/* Update the flags */
_gmx_selelem_update_flags(root);
+ gmx::ExceptionInitializer errors("Invalid index group reference(s)");
+ root->checkUnsortedAtoms(true, &errors);
+ if (errors.hasNestedExceptions())
+ {
+ GMX_THROW(gmx::InconsistentInputError(errors));
+ }
root->fillNameIfMissing(_gmx_sel_lexer_pselstr(scanner));
{
/* If so, just assign the constant value to the variable */
sc->symtab->addVariable(name, expr);
- goto finish;
}
/* Check if we are assigning a variable to another variable */
- if (expr->type == SEL_SUBEXPRREF)
+ else if (expr->type == SEL_SUBEXPRREF)
{
/* If so, make a simple alias */
sc->symtab->addVariable(name, expr->child);
- goto finish;
}
- /* Create the root element */
- root.reset(new SelectionTreeElement(SEL_ROOT));
- root->setName(name);
- /* Create the subexpression element */
- root->child.reset(new SelectionTreeElement(SEL_SUBEXPR));
- root->child->setName(name);
- _gmx_selelem_set_vtype(root->child, expr->v.type);
- root->child->child = expr;
- /* Update flags */
- _gmx_selelem_update_flags(root);
- /* Add the variable to the symbol table */
- sc->symtab->addVariable(name, root->child);
-finish:
+ else
+ {
+ /* Create the root element */
+ root.reset(new SelectionTreeElement(SEL_ROOT));
+ root->setName(name);
+ /* Create the subexpression element */
+ root->child.reset(new SelectionTreeElement(SEL_SUBEXPR));
+ root->child->setName(name);
+ _gmx_selelem_set_vtype(root->child, expr->v.type);
+ root->child->child = expr;
+ /* Update flags */
+ _gmx_selelem_update_flags(root);
+ gmx::ExceptionInitializer errors("Invalid index group reference(s)");
+ root->checkUnsortedAtoms(true, &errors);
+ if (errors.hasNestedExceptions())
+ {
+ GMX_THROW(gmx::InconsistentInputError(errors));
+ }
+ /* Add the variable to the symbol table */
+ sc->symtab->addVariable(name, root->child);
+ }
srenew(sc->varstrs, sc->nvars + 1);
- sc->varstrs[sc->nvars] = strdup(pselstr);
+ sc->varstrs[sc->nvars] = gmx_strdup(pselstr);
++sc->nvars;
if (_gmx_sel_is_lexer_interactive(scanner))
{