/*
- * Copyright (c) 2015 ARM Limited
+ * Copyright (c) 2016, 2020 ARM Limited
* All rights reserved
*
* The license below extends only to copyright in the software and shall
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Authors: David Guillen Fandos
*/
#ifndef __SIM_MATHEXPR_HH__
#define __SIM_MATHEXPR_HH__
#include <algorithm>
+#include <array>
#include <functional>
#include <string>
+#include <vector>
class MathExpr {
public:
*/
double eval(EvalCallback fn) const { return eval(root, fn); }
+ /**
+ * Return all variables in the this expression.
+ *
+ * This function starts from the root node and traverses all nodes
+ * while adding the variables it finds to a vector. Returns the
+ * found variables in a vector of strings
+ *
+ * @return A Vector with the names of all variables
+ */
+ std::vector<std::string> getVariables() const
+ {
+ std::vector<std::string> vars;
+ getVariables(root, vars);
+ return vars;
+ }
+
private:
enum Operator {
bAdd, bSub, bMul, bDiv, bPow, uNeg, sValue, sVariable, nInvalid
/** Eval a node */
double eval(const Node *n, EvalCallback fn) const;
+
+ /** Return all variable reachable from a node to a vector of
+ * strings */
+ void getVariables(const Node *n, std::vector<std::string> &vars) const;
};
#endif
-
-