Skip to content

Commit

Permalink
Added getUsedVariables method to expression.
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquinffernandez committed Nov 3, 2022
1 parent 05b106c commit 20bfc1a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/mmoc/ir/expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <util/model_config.h>
#include <util/util.h>
#include <util/visitors/expression_printer.h>
#include <util/visitors/get_index_variables.h>
#include <util/visitors/is_constant_index.h>
#include <util/visitors/partial_eval_exp.h>

Expand Down Expand Up @@ -161,14 +162,20 @@ 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;
cmp_other << other;
return cmp_this.str() < cmp_other.str();
}

std::multimap<std::string, int> Expression::usedVariables() const
{
GetIndexVariables used_variables;
return used_variables.apply(_exp);
}

} // namespace IR
} // namespace MicroModelica
4 changes: 3 additions & 1 deletion src/mmoc/ir/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ class Expression {
bool isScalar() const;
list<Expression> indexes() const;
static Expression generate(std::string var_name, std::vector<std::string> 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<std::string, int> usedVariables() const;

protected:
std::vector<Expression> usageExps() const;

Expand Down

0 comments on commit 20bfc1a

Please sign in to comment.