From 20bfc1a83cb4e8ec61f372cb5657f8937e1c1377 Mon Sep 17 00:00:00 2001 From: "joaquin.f.fernandez" Date: Thu, 3 Nov 2022 09:45:46 -0300 Subject: [PATCH] Added getUsedVariables method to expression. --- src/mmoc/ir/expression.cpp | 11 +++++++++-- src/mmoc/ir/expression.h | 4 +++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/mmoc/ir/expression.cpp b/src/mmoc/ir/expression.cpp index c88a9099..4f23957e 100644 --- a/src/mmoc/ir/expression.cpp +++ b/src/mmoc/ir/expression.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -161,8 +162,8 @@ std::ostream& operator<<(std::ostream& out, const Expression& s) out << s.print(); return out; } -bool Expression::operator<(const Expression &other) const -{ +bool Expression::operator<(const Expression& other) const +{ std::stringstream cmp_this; std::stringstream cmp_other; cmp_this << *this; @@ -170,5 +171,11 @@ bool Expression::operator<(const Expression &other) const return cmp_this.str() < cmp_other.str(); } +std::multimap Expression::usedVariables() const +{ + GetIndexVariables used_variables; + return used_variables.apply(_exp); +} + } // namespace IR } // namespace MicroModelica diff --git a/src/mmoc/ir/expression.h b/src/mmoc/ir/expression.h index ed0aecfd..fb0ae688 100644 --- a/src/mmoc/ir/expression.h +++ b/src/mmoc/ir/expression.h @@ -43,10 +43,12 @@ class Expression { bool isScalar() const; list indexes() const; static Expression generate(std::string var_name, std::vector indices); - bool operator<(const Expression &other) const; + bool operator<(const Expression& other) const; friend std::ostream& operator<<(std::ostream& out, const Expression& s); + std::multimap usedVariables() const; + protected: std::vector usageExps() const;