Fixing copyright issues and code contributors
[alexxy/gromacs.git] / src / gmxlib / selection / parsetree.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5  * Copyright (c) 2001-2009, The GROMACS development team,
6  * check out http://www.gromacs.org for more information.
7  * Copyright (c) 2012,2013, by the GROMACS development team, led by
8  * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9  * others, as listed in the AUTHORS file in the top-level source
10  * directory and at http://www.gromacs.org.
11  *
12  * GROMACS is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public License
14  * as published by the Free Software Foundation; either version 2.1
15  * of the License, or (at your option) any later version.
16  *
17  * GROMACS is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with GROMACS; if not, see
24  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
26  *
27  * If you want to redistribute modifications to GROMACS, please
28  * consider that scientific software is very special. Version
29  * control is crucial - bugs must be traceable. We will be happy to
30  * consider code for inclusion in the official distribution, but
31  * derived work must not be called official GROMACS. Details are found
32  * in the README & COPYING files - if they are missing, get the
33  * official version at http://www.gromacs.org.
34  *
35  * To help us fund GROMACS development, we humbly ask that you cite
36  * the research papers on the package. Check out http://www.gromacs.org.
37  */
38 /*! \internal \file
39  * \brief Handling of intermediate selection parser data.
40  *
41  * The data types declared in this header are used by the parser to store
42  * intermediate data when constructing method expressions.
43  * In particular, the parameters for the method are stored.
44  * The intermediate data is freed once a \c t_selelem object can be
45  * constructed.
46  * 
47  * This is an implementation header: there should be no need to use it outside
48  * this directory.
49  */
50 #ifndef SELECTION_PARSETREE_H
51 #define SELECTION_PARSETREE_H
52
53 /*#include <typedefs.h>*/
54 #include <types/simple.h>
55
56
57 #include <selvalue.h>
58
59 struct t_selelem;
60 struct gmx_ana_indexgrps_t;
61 struct gmx_ana_selmethod_t;
62 struct gmx_ana_selparam_t;
63
64 /*! \internal \brief
65  * Describes a parsed value, possibly resulting from expression evaluation.
66  */
67 typedef struct t_selexpr_value
68 {
69     /** Type of the value. */
70     e_selvalue_t            type;
71     /** TRUE if the value is the result of an expression. */
72     gmx_bool                    bExpr;
73     union {
74         /** The integer value/range (\p type INT_VALUE); */
75         struct {
76             /** Beginning of the range. */
77             int             i1;
78             /** End of the range; equals \p i1 for a single integer. */
79             int             i2;
80         }                   i;
81         /** The real value/range (\p type REAL_VALUE); */
82         struct {
83             /** Beginning of the range. */
84             real            r1;
85             /** End of the range; equals \p r1 for a single number. */
86             real            r2;
87         }                   r;
88         /** The string value (\p type STR_VALUE); */
89         char               *s;
90         /** The position value (\p type POS_VALUE); */
91         rvec                x;
92         /** The expression if \p bExpr is TRUE. */
93         struct t_selelem   *expr;
94     }                       u;
95     /** Pointer to the next value. */
96     struct t_selexpr_value *next;
97 } t_selexpr_value;
98
99 /*! \internal \brief
100  * Describes a parsed method parameter.
101  */
102 typedef struct t_selexpr_param
103 {
104     /** Name of the parameter. */
105     char                   *name;
106     /** Number of values given for this parameter. */
107     int                     nval;
108     /** Pointer to the first value. */
109     struct t_selexpr_value *value;
110     /** Pointer to the next parameter. */
111     struct t_selexpr_param *next;
112 } t_selexpr_param;
113
114 /** Error reporting function for the selection parser. */
115 void
116 _gmx_selparser_error(const char *fmt, ...);
117
118 /** Allocates and initializes a constant \c t_selexpr_value. */
119 t_selexpr_value *
120 _gmx_selexpr_create_value(e_selvalue_t type);
121 /** Allocates and initializes an expression \c t_selexpr_value. */
122 t_selexpr_value *
123 _gmx_selexpr_create_value_expr(struct t_selelem *expr);
124 /** Allocates and initializes a \c t_selexpr_param. */
125 t_selexpr_param *
126 _gmx_selexpr_create_param(char *name);
127
128 /** Frees the memory allocated for a chain of values. */
129 void
130 _gmx_selexpr_free_values(t_selexpr_value *value);
131 /** Frees the memory allocated for a chain of parameters. */
132 void
133 _gmx_selexpr_free_params(t_selexpr_param *param);
134
135 /** Propagates the flags for selection elements. */
136 int
137 _gmx_selelem_update_flags(struct t_selelem *sel);
138
139 /** Initializes the method parameter data of \ref SEL_EXPRESSION and
140  * \ref SEL_MODIFIER elements. */
141 void
142 _gmx_selelem_init_method_params(struct t_selelem *sel, void *scanner);
143 /** Initializes the method for a \ref SEL_EXPRESSION selection element. */
144 void
145 _gmx_selelem_set_method(struct t_selelem *sel,
146                         struct gmx_ana_selmethod_t *method, void *scanner);
147
148 /** Creates a \c t_selelem for arithmetic expression evaluation. */
149 struct t_selelem *
150 _gmx_sel_init_arithmetic(struct t_selelem *left, struct t_selelem *right,
151                          char op, void *scanner);
152 /** Creates a \c t_selelem for comparsion expression evaluation. */
153 struct t_selelem *
154 _gmx_sel_init_comparison(struct t_selelem *left, struct t_selelem *right,
155                          char *cmpop, void *scanner);
156 /** Creates a \c t_selelem for a keyword expression from the parsed data. */
157 struct t_selelem *
158 _gmx_sel_init_keyword(struct gmx_ana_selmethod_t *method,
159                       t_selexpr_value *args, const char *rpost, void *scanner);
160 /** Creates a \c t_selelem for a method expression from the parsed data. */
161 struct t_selelem *
162 _gmx_sel_init_method(struct gmx_ana_selmethod_t *method,
163                      t_selexpr_param *params, const char *rpost,
164                      void *scanner);
165 /** Creates a \c t_selelem for a modifier expression from the parsed data. */
166 struct t_selelem *
167 _gmx_sel_init_modifier(struct gmx_ana_selmethod_t *mod, t_selexpr_param *params,
168                        struct t_selelem *sel, void *scanner);
169 /** Creates a \c t_selelem for evaluation of reference positions. */
170 struct t_selelem *
171 _gmx_sel_init_position(struct t_selelem *expr, const char *type, void *scanner);
172
173 /** Creates a \c t_selelem for a constant position. */
174 struct t_selelem *
175 _gmx_sel_init_const_position(real x, real y, real z);
176 /** Creates a \c t_selelem for a index group expression using group name. */
177 struct t_selelem *
178 _gmx_sel_init_group_by_name(const char *name, void *scanner);
179 /** Creates a \c t_selelem for a index group expression using group index. */
180 struct t_selelem *
181 _gmx_sel_init_group_by_id(int id, void *scanner);
182 /** Creates a \c t_selelem for a variable reference */
183 struct t_selelem *
184 _gmx_sel_init_variable_ref(struct t_selelem *sel);
185
186 /** Creates a root \c t_selelem for a selection. */
187 struct t_selelem *
188 _gmx_sel_init_selection(char *name, struct t_selelem *sel, void *scanner);
189 /** Creates a root \c t_selelem elements for a variable assignment. */
190 struct t_selelem *
191 _gmx_sel_assign_variable(char *name, struct t_selelem *expr, void *scanner);
192 /** Appends a root \c t_selelem to a selection collection. */
193 struct t_selelem *
194 _gmx_sel_append_selection(struct t_selelem *sel, struct t_selelem *last,
195                           void *scanner);
196 /** Check whether the parser should finish. */
197 gmx_bool
198 _gmx_sel_parser_should_finish(void *scanner);
199
200 /** Handle empty commands. */
201 void
202 _gmx_sel_handle_empty_cmd(void *scanner);
203 /** Process help commands. */
204 void
205 _gmx_sel_handle_help_cmd(char *topic, void *scanner);
206
207 /* In params.c */
208 /** Initializes an array of parameters based on input from the selection parser. */
209 gmx_bool
210 _gmx_sel_parse_params(t_selexpr_param *pparams, int nparam,
211                       struct gmx_ana_selparam_t *param, struct t_selelem *root,
212                       void *scanner);
213
214 #endif