+/********************************************************************
+ * REQUIRED ATOMS ANALYSIS
+ ********************************************************************/
+
+/*! \brief
+ * Finds the highest atom index required to evaluate a selection subtree.
+ *
+ * \param[in] sel Root of the selection subtree to process.
+ * \param[in,out] maxAtomIndex The highest atom index required to evaluate the
+ * subtree. The existing value is never decreased, so multiple calls with
+ * the same parameter will compute the maximum over several subtrees.
+ *
+ * For evaluation that starts from a \ref SEL_ROOT element with a fixed group,
+ * children will never extend the evaluation group except for method parameter
+ * evaluation (which have their own root element), so it is sufficient to check
+ * the root. However, children of \ref SEL_EXPRESSION elements (i.e., the
+ * method parameters) may have been independently evaluated to a static group
+ * that no longer has a separate root, so those need to be checked as well.
+ *
+ * Position calculations are not considered here, but are analyzed through the
+ * position calculation collection in the main compilation method.
+ */
+static void
+init_required_atoms(const SelectionTreeElementPointer &sel, int *maxAtomIndex)
+{
+ // Process children.
+ if (sel->type != SEL_SUBEXPRREF)
+ {
+ SelectionTreeElementPointer child = sel->child;
+ while (child)
+ {
+ init_required_atoms(child, maxAtomIndex);
+ child = child->next;
+ }
+ }
+
+ if (sel->type == SEL_ROOT
+ || (sel->type == SEL_CONST && sel->v.type == GROUP_VALUE))
+ {
+ if (sel->u.cgrp.isize > 0)
+ {
+ *maxAtomIndex =
+ std::max(*maxAtomIndex, gmx_ana_index_get_max_index(&sel->u.cgrp));
+ }
+ }
+}
+
+