/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2014,2015, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
#include "gromacs/utility/arrayref.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/gmxassert.h"
-#include "gromacs/utility/messagestringcollector.h"
#include "gromacs/utility/stringutil.h"
#include "options-impl.h"
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2009,2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
switch (value->type)
{
case INT_VALUE:
+ {
+ bool bTooManyValues;
if (value->u.i.i1 <= value->u.i.i2)
{
for (j = value->u.i.i1; j <= value->u.i.i2 && i < param->val.nr; ++j)
{
param->val.u.i[i++] = j;
}
- if (j != value->u.i.i2 + 1)
- {
- _gmx_selparser_error(scanner, "extra values skipped");
- }
+ bTooManyValues = (j != value->u.i.i2 + 1);
}
else
{
{
param->val.u.i[i++] = j;
}
- if (j != value->u.i.i2 - 1)
- {
- _gmx_selparser_error(scanner, "extra values skipped");
- }
+ bTooManyValues = (j != value->u.i.i2 - 1);
+ }
+ if (bTooManyValues)
+ {
+ std::string text(_gmx_sel_lexer_get_text(scanner, value->location()));
+ std::string message
+ = formatString("Range ('%s') produces more values than is "
+ "accepted in this context",
+ text.c_str());
+ GMX_THROW(InvalidInputError(message));
}
--i;
break;
+ }
case REAL_VALUE:
if (value->u.r.r1 != value->u.r.r2)
{
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2009,2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
#include "gromacs/utility/cstringutil.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/file.h"
-#include "gromacs/utility/messagestringcollector.h"
#include "gromacs/utility/smalloc.h"
#include "gromacs/utility/stringutil.h"
} // namespace
-void
-_gmx_selparser_error(yyscan_t scanner, const char *fmt, ...)
-{
- gmx::MessageStringCollector *errors = _gmx_sel_lexer_error_reporter(scanner);
- // FIXME: Use an arbitrary length buffer.
- char buf[1024];
- va_list ap;
- va_start(ap, fmt);
- vsnprintf(buf, 1024, fmt, ap);
- va_end(ap);
- errors->append(buf);
-}
-
bool
_gmx_selparser_handle_exception(yyscan_t scanner, std::exception *ex)
{
const gmx::SelectionTreeElementPointer &right,
const char *cmpop, yyscan_t scanner)
{
- gmx::MessageStringCollector *errors = _gmx_sel_lexer_error_reporter(scanner);
- gmx::MessageStringContext context(errors, formatCurrentErrorContext(scanner));
-
SelectionTreeElementPointer sel(
new SelectionTreeElement(
SEL_EXPRESSION, _gmx_sel_lexer_get_current_location(scanner)));
{
gmx_ana_selcollection_t *sc = _gmx_sel_lexer_selcollection(scanner);
- gmx::MessageStringCollector *errors = _gmx_sel_lexer_error_reporter(scanner);
- gmx::MessageStringContext context(errors, formatCurrentErrorContext(scanner));
-
if (method->nparams > 0)
{
// TODO: Would assert be better?
const gmx::SelectionTreeElementPointer &group,
const char *rpost, yyscan_t scanner)
{
- gmx::MessageStringCollector *errors = _gmx_sel_lexer_error_reporter(scanner);
- gmx::MessageStringContext context(errors, formatCurrentErrorContext(scanner));
-
+ // TODO Provide an error if rpost is provided.
GMX_UNUSED_VALUE(rpost);
return _gmx_sel_init_keyword_evaluator(method, group, scanner);
}
{
gmx_ana_selcollection_t *sc = _gmx_sel_lexer_selcollection(scanner);
- gmx::MessageStringCollector *errors = _gmx_sel_lexer_error_reporter(scanner);
- gmx::MessageStringContext context(errors, formatCurrentErrorContext(scanner));
-
_gmx_sel_finish_method(scanner);
/* The "same" keyword needs some custom massaging of the parameters. */
_gmx_selelem_custom_init_same(&method, params, scanner);
const gmx::SelectionTreeElementPointer &sel,
yyscan_t scanner)
{
- gmx::MessageStringCollector *errors = _gmx_sel_lexer_error_reporter(scanner);
- gmx::MessageStringContext context(errors, formatCurrentErrorContext(scanner));
-
_gmx_sel_finish_method(scanner);
SelectionTreeElementPointer modifier(
new SelectionTreeElement(
_gmx_sel_init_position(const gmx::SelectionTreeElementPointer &expr,
const char *type, yyscan_t scanner)
{
- gmx::MessageStringCollector *errors = _gmx_sel_lexer_error_reporter(scanner);
- gmx::MessageStringContext context(errors, formatCurrentErrorContext(scanner));
-
SelectionTreeElementPointer root(
new SelectionTreeElement(
SEL_EXPRESSION, _gmx_sel_lexer_get_current_location(scanner)));
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2009,2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
} // namespace gmx
-/** Error reporting function for the selection parser. */
-void
-_gmx_selparser_error(void *scanner, const char *fmt, ...);
/*! \brief
* Handles exceptions caught within the Bison code.
*
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2009,2010,2011,2012,2014, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,2014,2015, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
#include "parser.h"
-namespace gmx
-{
-class MessageStringCollector;
-}
-
struct gmx_ana_indexgrps_t;
struct gmx_ana_selcollection_t;
/** Frees memory allocated for the selection scanner. */
void
_gmx_sel_free_lexer(yyscan_t scanner);
-/** Sets the error reporter object for the selection scanner. */
-void
-_gmx_sel_set_lexer_error_reporter(yyscan_t scanner,
- gmx::MessageStringCollector *errors);
/** Stores an exception that is caught during parsing. */
void
_gmx_sel_lexer_set_exception(yyscan_t scanner,
/** Returns the selection collection for the scanner. */
struct gmx_ana_selcollection_t *
_gmx_sel_lexer_selcollection(yyscan_t scanner);
-/** Returns the error reporter for the scanner. */
-gmx::MessageStringCollector *
-_gmx_sel_lexer_error_reporter(yyscan_t scanner);
/** Returns true if the external index groups for the scanner are set. */
bool
_gmx_sel_lexer_has_groups_set(yyscan_t scanner);
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2009,2010,2011,2012,2014, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,2014,2015, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
#include "gromacs/utility/cstringutil.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/gmxassert.h"
-#include "gromacs/utility/messagestringcollector.h"
#include "gromacs/utility/smalloc.h"
#include "gromacs/utility/stringutil.h"
gmx_sel_lexer_t *state = new gmx_sel_lexer_t;
state->sc = sc;
- state->errors = NULL;
state->bGroups = bGroups;
state->grps = grps;
state->nexpsel = (maxnr > 0 ? static_cast<int>(sc->sel.size()) + maxnr : -1);
_gmx_sel_yylex_destroy(scanner);
}
-void
-_gmx_sel_set_lexer_error_reporter(yyscan_t scanner,
- gmx::MessageStringCollector *errors)
-{
- gmx_sel_lexer_t *state = _gmx_sel_yyget_extra(scanner);
- state->errors = errors;
-}
-
void
_gmx_sel_lexer_set_exception(yyscan_t scanner,
const boost::exception_ptr &ex)
return state->sc;
}
-gmx::MessageStringCollector *
-_gmx_sel_lexer_error_reporter(yyscan_t scanner)
-{
- gmx_sel_lexer_t *state = _gmx_sel_yyget_extra(scanner);
- GMX_RELEASE_ASSERT(state->errors != NULL, "Error reporter not set");
- return state->errors;
-}
-
bool
_gmx_sel_lexer_has_groups_set(yyscan_t scanner)
{
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2009,2010,2011,2012,2014, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,2014,2015, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
namespace gmx
{
-class MessageStringCollector;
class SelectionParserSymbol;
}
{
//! Selection collection to put parsed selections in.
struct gmx_ana_selcollection_t *sc;
- //! Error reporter object.
- gmx::MessageStringCollector *errors;
//! Stores an exception that occurred during parsing.
boost::exception_ptr exception;
//! Whether external index groups have been set.
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/file.h"
#include "gromacs/utility/gmxassert.h"
-#include "gromacs/utility/messagestringcollector.h"
#include "gromacs/utility/smalloc.h"
#include "gromacs/utility/stringutil.h"
gmx_ana_selcollection_t *sc = _gmx_sel_lexer_selcollection(scanner);
gmx_ana_indexgrps_t *grps = _gmx_sel_lexer_indexgrps(scanner);
- MessageStringCollector errors;
- _gmx_sel_set_lexer_error_reporter(scanner, &errors);
-
- size_t oldCount = sc->sel.size();
- bool bOk = false;
+ size_t oldCount = sc->sel.size();
{
boost::shared_ptr<_gmx_sel_yypstate> parserState(
_gmx_sel_yypstate_new(), &_gmx_sel_yypstate_delete);
// error/warning if some input was ignored.
goto early_termination;
}
- if (!errors.isEmpty() && bInteractive)
- {
- fprintf(stderr, "%s", errors.toString().c_str());
- errors.clear();
- }
}
{
YYLTYPE location;
status = _gmx_sel_yypush_parse(parserState.get(), 0, NULL,
&location, scanner);
}
+ // TODO: Remove added selections from the collection if parsing failed?
_gmx_sel_lexer_rethrow_exception_if_occurred(scanner);
early_termination:
- bOk = (status == 0);
+ GMX_RELEASE_ASSERT(status == 0,
+ "Parser errors should have resulted in an exception");
}
else
{
int status = runParserLoop(scanner, parserState.get(), false);
- bOk = (status == 0);
+ GMX_RELEASE_ASSERT(status == 0,
+ "Parser errors should have resulted in an exception");
}
}
scannerGuard.reset();
int nr = sc->sel.size() - oldCount;
if (maxnr > 0 && nr != maxnr)
{
- bOk = false;
- errors.append("Too few selections provided");
- }
-
- // TODO: Remove added selections from the collection if parsing failed?
- if (!bOk || !errors.isEmpty())
- {
- GMX_ASSERT(!bOk && !errors.isEmpty(), "Inconsistent error reporting");
- GMX_THROW(InvalidInputError(errors.toString()));
+ std::string message
+ = formatString("Too few selections provided; got %d, expected %d",
+ nr, maxnr);
+ GMX_THROW(InvalidInputError(message));
}
SelectionList result;
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
void SelectionOptionStorage::setAllowedValueCount(int count)
{
// TODO: It should be possible to have strong exception safety here.
+ // TODO: Use ExceptionInitializer here.
MessageStringCollector errors;
errors.startContext("In option '" + name() + "'");
if (count >= 0)
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2009,2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/gmxregex.h"
-#include "gromacs/utility/messagestringcollector.h"
#include "gromacs/utility/smalloc.h"
#include "gromacs/utility/stringutil.h"
const gmx::SelectionTreeElementPointer &child,
void *scanner)
{
- gmx::MessageStringCollector *errors = _gmx_sel_lexer_error_reporter(scanner);
- char buf[1024];
- sprintf(buf, "In evaluation of '%s'", method->name);
- gmx::MessageStringContext context(errors, buf);
-
gmx::SelectionParserParameterList params;
params.push_back(
gmx::SelectionParserParameter::createFromExpression(NULL, child));