3 #ifndef _ASSIGNMENT_NODE_CPP_
4 #define _ASSIGNMENT_NODE_CPP_
6 #ifndef _MADARA_NO_KARL_
36 bool left_child_can_change =
false;
37 bool right_child_can_change =
false;
40 if (this->var_ != 0 || this->array_ != 0)
41 left_child_can_change =
true;
45 "CompositeAssignmentNode: "
46 "KARL COMPILE ERROR (=): "
47 "Assignments must have a variable left hand side.\n");
50 "CompositeAssignmentNode: "
51 "KARL COMPILE ERROR (=): "
52 "Assignments must have a variable left hand side");
57 right_value = this->right_->prune(right_child_can_change);
58 if (!right_child_can_change &&
dynamic_cast<LeafNode*
>(right_) == 0)
61 this->right_ =
new LeafNode(*(this->logger_), right_value);
68 "CompositeAssignmentNode: KARL COMPILE ERROR: "
69 "Assignment has no right expression\n");
72 "CompositeAssignmentNode: KARL COMPILE ERROR: "
73 "Assignment has no right expression\n");
76 can_change = left_child_can_change || right_child_can_change;
94 "CompositeAssignmentNode::evaluate: "
95 "Attempting to set variable %s to %s.\n",
96 var_->expand_key().c_str(), rhs.
to_string().c_str());
98 var_->set(rhs, settings);
103 "CompositeAssignmentNode::evaluate: "
104 "Attempting to set index of var %s to %s.\n",
105 array_->expand_key().c_str(), rhs.
to_string().c_str());
107 array_->set(rhs, settings);
112 "left hand side was neither a variable nor an array reference. "
113 "Check your expression for errors.\n");
123 visitor.
visit(*
this);
#define madara_logger_ptr_log(loggering, level,...)
Fast version of the madara::logger::log method for Logger pointers.
madara::knowledge::KnowledgeRecord KnowledgeRecord
An exception for unrecoverable KaRL compilation issues.
An abstract base class defines a simple abstract implementation of an expression tree node.
virtual ComponentNode * left(void) const
Returns the left expression.
Defines a terminal node of that references the current value stored in a variable.
virtual madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings)
Evaluates the expression tree.
virtual madara::knowledge::KnowledgeRecord prune(bool &can_change)
Prunes the expression tree of unnecessary nodes.
virtual void accept(Visitor &visitor) const
Accepts a visitor subclassed from the Visitor class.
CompositeAssignmentNode(logger::Logger &logger, ComponentNode *left, ComponentNode *right)
Constructor.
virtual madara::knowledge::KnowledgeRecord item(void) const
Returns the printable character of the node.
CompositeArrayReference * array_
VariableNode * var_
Left should always be a variable node.
Encapsulates a single expression tree.
Defines a node that contains a madara::knowledge::KnowledgeRecord::Integer value.
Defines a terminal node of that references the current value stored in a variable.
Abstract base class for all visitors to all classes that derive from ComponentNode.
virtual void visit(const LeafNode &node)=0
Visit a LeafNode.
This class encapsulates an entry in a KnowledgeBase.
std::string to_string(const std::string &delimiter=", ") const
converts the value to a string.
Settings for applying knowledge updates.
A multi-threaded logger for logging to one or more destinations.
Provides knowledge logging services to files and terminals.