Gromacs
2024.3
|
#include "gmxpre.h"
#include "parsetree.h"
#include <cstdarg>
#include <cstdio>
#include <exception>
#include <memory>
#include "gromacs/selection/selection.h"
#include "gromacs/utility/cstringutil.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/smalloc.h"
#include "gromacs/utility/stringutil.h"
#include "gromacs/utility/textwriter.h"
#include "keywords.h"
#include "poscalc.h"
#include "scanner.h"
#include "selectioncollection_impl.h"
#include "selelem.h"
#include "selmethod.h"
#include "symrec.h"
Implements functions in parsetree.h.
Functions | |
std::string | anonymous_namespace{parsetree.cpp}::formatCurrentErrorContext (yyscan_t scanner) |
Formats context string for errors. More... | |
bool | _gmx_selparser_handle_exception (yyscan_t scanner, std::exception *ex) |
Handles exceptions caught within the Bison code. More... | |
bool | _gmx_selparser_handle_error (yyscan_t scanner) |
Handles errors in the selection parser. More... | |
void | _gmx_selelem_update_flags (const gmx::SelectionTreeElementPointer &sel) |
Propagates the flags for selection elements. More... | |
void | _gmx_selelem_init_method_params (const gmx::SelectionTreeElementPointer &sel, yyscan_t scanner) |
Initializes the method parameter data of SEL_EXPRESSION and SEL_MODIFIER elements. More... | |
void | _gmx_selelem_set_method (const gmx::SelectionTreeElementPointer &sel, gmx_ana_selmethod_t *method, yyscan_t scanner) |
Initializes the method for a SEL_EXPRESSION selection element. More... | |
static void | set_refpos_type (gmx::PositionCalculationCollection *pcc, const SelectionTreeElementPointer &sel, const char *rpost) |
Initializes the reference position calculation for a SEL_EXPRESSION element. More... | |
gmx::SelectionTreeElementPointer | _gmx_sel_init_arithmetic (const gmx::SelectionTreeElementPointer &left, const gmx::SelectionTreeElementPointer &right, char op, yyscan_t scanner) |
Creates a gmx::SelectionTreeElement for arithmetic expression evaluation. More... | |
SelectionTreeElementPointer | _gmx_sel_init_comparison (const gmx::SelectionTreeElementPointer &left, const gmx::SelectionTreeElementPointer &right, const char *cmpop, yyscan_t scanner) |
Creates a gmx::SelectionTreeElement for comparsion expression evaluation. More... | |
static SelectionTreeElementPointer | init_keyword_internal (gmx_ana_selmethod_t *method, gmx::SelectionStringMatchType matchType, SelectionParserValueListPointer args, const char *rpost, yyscan_t scanner) |
Implementation method for keyword expression creation. More... | |
SelectionTreeElementPointer | _gmx_sel_init_keyword (gmx_ana_selmethod_t *method, gmx::SelectionParserValueListPointer args, const char *rpost, yyscan_t scanner) |
Creates a gmx::SelectionTreeElement for a keyword expression from the parsed data. More... | |
SelectionTreeElementPointer | _gmx_sel_init_keyword_strmatch (gmx_ana_selmethod_t *method, gmx::SelectionStringMatchType matchType, gmx::SelectionParserValueListPointer args, const char *rpost, yyscan_t scanner) |
Creates a gmx::SelectionTreeElement for string-matching keyword expression. More... | |
SelectionTreeElementPointer | _gmx_sel_init_keyword_of (gmx_ana_selmethod_t *method, const gmx::SelectionTreeElementPointer &group, const char *rpost, yyscan_t scanner) |
Creates a gmx::SelectionTreeElement for "keyword of" expression. More... | |
SelectionTreeElementPointer | _gmx_sel_init_method (gmx_ana_selmethod_t *method, gmx::SelectionParserParameterListPointer params, const char *rpost, yyscan_t scanner) |
Creates a gmx::SelectionTreeElement for a method expression from the parsed data. More... | |
SelectionTreeElementPointer | _gmx_sel_init_modifier (gmx_ana_selmethod_t *method, gmx::SelectionParserParameterListPointer params, const gmx::SelectionTreeElementPointer &sel, yyscan_t scanner) |
Creates a gmx::SelectionTreeElement for a modifier expression from the parsed data. More... | |
SelectionTreeElementPointer | _gmx_sel_init_position (const gmx::SelectionTreeElementPointer &expr, const char *type, yyscan_t scanner) |
Creates a gmx::SelectionTreeElement for evaluation of reference positions. More... | |
SelectionTreeElementPointer | _gmx_sel_init_const_position (real x, real y, real z, yyscan_t scanner) |
Creates a gmx::SelectionTreeElement for a constant position. More... | |
SelectionTreeElementPointer | _gmx_sel_init_group_by_name (const char *name, yyscan_t scanner) |
Creates a gmx::SelectionTreeElement for a index group expression using group name. More... | |
SelectionTreeElementPointer | _gmx_sel_init_group_by_id (int id, yyscan_t scanner) |
Creates a gmx::SelectionTreeElement for a index group expression using group index. More... | |
SelectionTreeElementPointer | _gmx_sel_init_variable_ref (const gmx::SelectionTreeElementPointer &sel, yyscan_t scanner) |
Creates a gmx::SelectionTreeElement for a variable reference. More... | |
SelectionTreeElementPointer | _gmx_sel_init_selection (const char *name, const gmx::SelectionTreeElementPointer &sel, yyscan_t scanner) |
Creates a root gmx::SelectionTreeElement for a selection. More... | |
SelectionTreeElementPointer | _gmx_sel_assign_variable (const char *name, const gmx::SelectionTreeElementPointer &expr, yyscan_t scanner) |
Creates a root gmx::SelectionTreeElement elements for a variable assignment. More... | |
SelectionTreeElementPointer | _gmx_sel_append_selection (const gmx::SelectionTreeElementPointer &sel, gmx::SelectionTreeElementPointer last, yyscan_t scanner) |
Appends a root gmx::SelectionTreeElement to a selection collection. More... | |
bool | _gmx_sel_parser_should_finish (yyscan_t scanner) |
Check whether the parser should finish. More... | |
SelectionTreeElementPointer _gmx_sel_append_selection | ( | const gmx::SelectionTreeElementPointer & | sel, |
gmx::SelectionTreeElementPointer | last, | ||
yyscan_t | scanner | ||
) |
Appends a root gmx::SelectionTreeElement to a selection collection.
sel | Selection to append (can be NULL, in which case nothing is done). |
last | Last selection, or NULL if not present or not known. |
scanner | Scanner data structure. |
Appends sel
after the last root element, and returns either sel
(if it was non-NULL) or the last element (if sel
was NULL).
SelectionTreeElementPointer _gmx_sel_assign_variable | ( | const char * | name, |
const gmx::SelectionTreeElementPointer & | expr, | ||
yyscan_t | scanner | ||
) |
Creates a root gmx::SelectionTreeElement elements for a variable assignment.
[in] | name | Name of the variable. |
[in] | expr | The selection element that evaluates the variable. |
scanner | Scanner data structure. |
This function handles the creation of root gmx::SelectionTreeElement objects for variable assignments. A SEL_ROOT element and a SEL_SUBEXPR element are both created.
gmx::SelectionTreeElementPointer _gmx_sel_init_arithmetic | ( | const gmx::SelectionTreeElementPointer & | left, |
const gmx::SelectionTreeElementPointer & | right, | ||
char | op, | ||
yyscan_t | scanner | ||
) |
Creates a gmx::SelectionTreeElement for arithmetic expression evaluation.
[in] | left | Selection element for the left hand side. |
[in] | right | Selection element for the right hand side. |
[in] | op | String representation of the operator. |
[in] | scanner | Scanner data structure. |
This function handles the creation of a gmx::SelectionTreeElement object for arithmetic expressions.
SelectionTreeElementPointer _gmx_sel_init_comparison | ( | const gmx::SelectionTreeElementPointer & | left, |
const gmx::SelectionTreeElementPointer & | right, | ||
const char * | cmpop, | ||
yyscan_t | scanner | ||
) |
Creates a gmx::SelectionTreeElement for comparsion expression evaluation.
[in] | left | Selection element for the left hand side. |
[in] | right | Selection element for the right hand side. |
[in] | cmpop | String representation of the comparison operator. |
[in] | scanner | Scanner data structure. |
This function handles the creation of a gmx::SelectionTreeElement object for comparison expressions.
SelectionTreeElementPointer _gmx_sel_init_const_position | ( | real | x, |
real | y, | ||
real | z, | ||
yyscan_t | scanner | ||
) |
Creates a gmx::SelectionTreeElement for a constant position.
[in] | x,y,z | Coordinates for the position. |
[in] | scanner | Scanner data structure. |
SelectionTreeElementPointer _gmx_sel_init_group_by_id | ( | int | id, |
yyscan_t | scanner | ||
) |
Creates a gmx::SelectionTreeElement for a index group expression using group index.
[in] | id | Zero-based index number of the group to extract. |
[in] | scanner | Scanner data structure. |
SelectionTreeElementPointer _gmx_sel_init_group_by_name | ( | const char * | name, |
yyscan_t | scanner | ||
) |
Creates a gmx::SelectionTreeElement for a index group expression using group name.
[in] | name | Name of an index group to search for. |
[in] | scanner | Scanner data structure. |
See gmx_ana_indexgrps_find() for information on how name
is matched against the index groups.
SelectionTreeElementPointer _gmx_sel_init_keyword | ( | gmx_ana_selmethod_t * | method, |
gmx::SelectionParserValueListPointer | args, | ||
const char * | rpost, | ||
yyscan_t | scanner | ||
) |
Creates a gmx::SelectionTreeElement for a keyword expression from the parsed data.
[in] | method | Method to use. |
[in] | args | Pointer to the first argument. |
[in] | rpost | Reference position type to use (NULL = default). |
[in] | scanner | Scanner data structure. |
This function handles the creation of a gmx::SelectionTreeElement object for selection methods that do not take parameters.
SelectionTreeElementPointer _gmx_sel_init_keyword_of | ( | gmx_ana_selmethod_t * | method, |
const gmx::SelectionTreeElementPointer & | group, | ||
const char * | rpost, | ||
yyscan_t | scanner | ||
) |
Creates a gmx::SelectionTreeElement for "keyword of" expression.
[in] | method | Method to use for initialization. |
[in] | group | Selection in which the keyword should be evaluated. |
[in] | rpost | Reference position type to use (NULL = default). |
[in] | scanner | Scanner data structure. |
This function handles the creation of a gmx::SelectionTreeElement object for expressions like "z of ...".
SelectionTreeElementPointer _gmx_sel_init_keyword_strmatch | ( | gmx_ana_selmethod_t * | method, |
gmx::SelectionStringMatchType | matchType, | ||
gmx::SelectionParserValueListPointer | args, | ||
const char * | rpost, | ||
yyscan_t | scanner | ||
) |
Creates a gmx::SelectionTreeElement for string-matching keyword expression.
[in] | method | Method to use. |
[in] | matchType | String matching type. |
[in] | args | Pointer to the first argument. |
[in] | rpost | Reference position type to use (NULL = default). |
[in] | scanner | Scanner data structure. |
This function handles the creation of a gmx::SelectionTreeElement object for keyword string matching.
SelectionTreeElementPointer _gmx_sel_init_method | ( | gmx_ana_selmethod_t * | method, |
gmx::SelectionParserParameterListPointer | params, | ||
const char * | rpost, | ||
yyscan_t | scanner | ||
) |
Creates a gmx::SelectionTreeElement for a method expression from the parsed data.
[in] | method | Method to use for initialization. |
[in] | params | Pointer to the first parameter. |
[in] | rpost | Reference position type to use (NULL = default). |
[in] | scanner | Scanner data structure. |
This function handles the creation of a gmx::SelectionTreeElement object for selection methods that take parameters.
Part of the behavior of the same
selection keyword is hardcoded into this function (or rather, into _gmx_selelem_custom_init_same()) to allow the use of any keyword in "same KEYWORD as"
without requiring special handling somewhere else (or sacrificing the simple syntax).
SelectionTreeElementPointer _gmx_sel_init_modifier | ( | gmx_ana_selmethod_t * | method, |
gmx::SelectionParserParameterListPointer | params, | ||
const gmx::SelectionTreeElementPointer & | sel, | ||
yyscan_t | scanner | ||
) |
Creates a gmx::SelectionTreeElement for a modifier expression from the parsed data.
[in] | method | Modifier to use for initialization. |
[in] | params | Pointer to the first parameter. |
[in] | sel | Selection element that the modifier should act on. |
[in] | scanner | Scanner data structure. |
This function handles the creation of a gmx::SelectionTreeElement object for selection modifiers.
SelectionTreeElementPointer _gmx_sel_init_position | ( | const gmx::SelectionTreeElementPointer & | expr, |
const char * | type, | ||
yyscan_t | scanner | ||
) |
Creates a gmx::SelectionTreeElement for evaluation of reference positions.
[in] | expr | Input selection element for the position calculation. |
[in] | type | Reference position type or NULL for default. |
[in] | scanner | Scanner data structure. |
This function handles the creation of a gmx::SelectionTreeElement object for evaluation of reference positions.
SelectionTreeElementPointer _gmx_sel_init_selection | ( | const char * | name, |
const gmx::SelectionTreeElementPointer & | sel, | ||
yyscan_t | scanner | ||
) |
Creates a root gmx::SelectionTreeElement for a selection.
[in] | name | Name for the selection (if NULL, a default name is constructed). |
[in] | sel | The selection element that evaluates the selection. |
scanner | Scanner data structure. |
This function handles the creation of root (SEL_ROOT) gmx::SelectionTreeElement objects for selections.
SelectionTreeElementPointer _gmx_sel_init_variable_ref | ( | const gmx::SelectionTreeElementPointer & | sel, |
yyscan_t | scanner | ||
) |
Creates a gmx::SelectionTreeElement for a variable reference.
[in,out] | sel | Value of the variable. |
scanner | Scanner data structure. |
sel
.The reference count of sel
is updated, but no other modifications are made.
bool _gmx_sel_parser_should_finish | ( | yyscan_t | scanner | ) |
Check whether the parser should finish.
[in] | scanner | Scanner data structure. |
This function is called always after _gmx_sel_append_selection() to check whether a sufficient number of selections has already been provided. This is used to terminate interactive parsers when the correct number of selections has been provided.
void _gmx_selelem_init_method_params | ( | const gmx::SelectionTreeElementPointer & | sel, |
yyscan_t | scanner | ||
) |
Initializes the method parameter data of SEL_EXPRESSION and SEL_MODIFIER elements.
[in,out] | sel | Selection element to initialize. |
[in] | scanner | Scanner data structure. |
A deep copy of the parameters is made to allow several expressions with the same method to coexist peacefully. Calls sel_datafunc() if one is specified for the method.
void _gmx_selelem_set_method | ( | const gmx::SelectionTreeElementPointer & | sel, |
gmx_ana_selmethod_t * | method, | ||
yyscan_t | scanner | ||
) |
Initializes the method for a SEL_EXPRESSION selection element.
[in,out] | sel | Selection element to initialize. |
[in] | method | Selection method to set. |
[in] | scanner | Scanner data structure. |
Makes a copy of method
and stores it in sel->u.expr.method
, and calls _gmx_selelem_init_method_params();
void _gmx_selelem_update_flags | ( | const gmx::SelectionTreeElementPointer & | sel | ) |
Propagates the flags for selection elements.
[in,out] | sel | Root of the selection element tree to initialize. |
Propagates the SEL_DYNAMIC flag from the children of sel
to sel
(if any child of sel
is dynamic, sel
is also marked as such). The SEL_DYNAMIC flag is also set for SEL_EXPRESSION elements with a dynamic method. Also, sets one of the SEL_SINGLEVAL, SEL_ATOMVAL, or SEL_VARNUMVAL flags, either based on the children or on the type of the selection method. If the types of the children conflict, an error is returned.
The flags of the children of sel
are also updated if not done earlier. The flags are initialized only once for any element; if SEL_FLAGSSET is set for an element, the function returns immediately, and the recursive operation does not descend beyond such elements.
bool _gmx_selparser_handle_error | ( | void * | scanner | ) |
Handles errors in the selection parser.
true
if parsing can continue with the next selection. std::bad_alloc | if out of memory during the error processing. |
unspecified | Can throw the stored exception if recovery from that exception is not possible. |
This function is called during error recovery, after Bison has discarded all the symbols for the erroneous selection. At this point, the full selection that caused the error is known, and can be added to the error context.
For an interactive parser, this function returns true
to let the parsing continue with the next selection, or to let the user enter the next selection, if it was possible to recover from the exception. For other cases, this will either rethrow the original exception with added context, or return false
after adding the context to the error reporter. Any exceptions thrown from this method are again caught by Bison and result in termination of the parsing; the caller can then rethrow them.
bool _gmx_selparser_handle_exception | ( | void * | scanner, |
std::exception * | ex | ||
) |
Handles exceptions caught within the Bison code.
<tt>true</tt> | if the parser should attempt error recovery. |
<tt>false</tt> | if the parser should immediately abort. |
This function is called whenever an exception is caught within Bison actions. Since exceptions cannot propagate through Bison code, the exception is saved (potentially with some extra context information) so that the caller of the parser can rethrow the exception.
If it is possible to recover from the exception, then the function returns true
, and Bison enters error recovery state. At the end of the recovery, _gmx_selparser_handle_error() is called. If this function returns false, then Bison immediately aborts the parsing so that the caller can rethrow the exception.
|
static |
Implementation method for keyword expression creation.
[in] | method | Method to use. |
[in] | matchType | String matching type (only used if method is a string keyword and args is not empty. |
[in] | args | Pointer to the first argument. |
[in] | rpost | Reference position type to use (NULL = default). |
[in] | scanner | Scanner data structure. |
This function handles the creation of a gmx::SelectionTreeElement object for selection methods that do not take parameters.
|
static |
Initializes the reference position calculation for a SEL_EXPRESSION element.
[in,out] | pcc | Position calculation collection to use. |
[in,out] | sel | Selection element to initialize. |
[in] | rpost | Reference position type to use (NULL = default). |