#include <msp/core/algorithm.h>
+#include <msp/core/raii.h>
#include "reflect.h"
using namespace std;
}
-set<VariableDeclaration *> AssignmentCollector::apply(Node &node)
+set<Node *> AssignmentCollector::apply(Node &node)
{
node.visit(*this);
return assigned_variables;
}
+void AssignmentCollector::visit(VariableReference &var)
+{
+ if(assignment_target)
+ assigned_variables.insert(var.declaration);
+}
+
+void AssignmentCollector::visit(InterfaceBlockReference &iface)
+{
+ if(assignment_target)
+ assigned_variables.insert(iface.declaration);
+}
+
+void AssignmentCollector::visit(UnaryExpression &unary)
+{
+ SetFlag set_assignment(assignment_target, (unary.oper->token[1]=='+' || unary.oper->token[1]=='-'));
+ TraversingVisitor::visit(unary);
+}
+
+void AssignmentCollector::visit(BinaryExpression &binary)
+{
+ binary.left->visit(*this);
+ SetFlag clear_assignment(assignment_target, false);
+ binary.right->visit(*this);
+}
+
void AssignmentCollector::visit(Assignment &assign)
{
- if(VariableDeclaration *var = dynamic_cast<VariableDeclaration *>(assign.target.declaration))
- assigned_variables.insert(var);
+ {
+ SetFlag set_assignment(assignment_target);
+ assign.left->visit(*this);
+ }
+ assign.right->visit(*this);
}
} // namespace SL
class AssignmentCollector: private TraversingVisitor
{
private:
- std::set<VariableDeclaration *> assigned_variables;
+ bool assignment_target = false;
+ std::set<Node *> assigned_variables;
public:
- std::set<VariableDeclaration *> apply(Node &);
+ std::set<Node *> apply(Node &);
private:
+ virtual void visit(VariableReference &);
+ virtual void visit(InterfaceBlockReference &);
+ virtual void visit(UnaryExpression &);
+ virtual void visit(BinaryExpression &);
virtual void visit(Assignment &);
};
if(iter.init_statement)
iter.init_statement->visit(*this);
- for(VariableDeclaration *v: AssignmentCollector().apply(iter))
- variable_load_ids.erase(v);
+ for(Node *n: AssignmentCollector().apply(iter))
+ if(VariableDeclaration *var = dynamic_cast<VariableDeclaration *>(n))
+ variable_load_ids.erase(var);
Id header_id = next_id++;
Id continue_id = next_id++;