MADARA  3.4.1
SystemCallExpandStatement.cpp
Go to the documentation of this file.
1 
2 #ifndef _MADARA_NO_KARL_
3 
8 
11  : SystemCallNode(context, nodes)
12 {
13 }
14 
15 // Dtor
17 {
18 }
19 
22 {
23  return madara::knowledge::KnowledgeRecord(nodes_.size());
24 }
25 
31 {
32  // user can always change a function, and we have no control over
33  // what it does. Consequently, a function node cannot be pruned out
34  // under any situation
35  can_change = true;
36 
38 
39  if (nodes_.size() == 1)
40  {
41  bool arg_can_change = false;
42  result = nodes_[0]->prune(arg_can_change);
43 
44  if (!arg_can_change && dynamic_cast<LeafNode*>(nodes_[0]) == 0)
45  {
46  delete nodes_[0];
47  nodes_[0] = new LeafNode(*(this->logger_), result);
48  }
49  }
50  else
51  {
53  "madara::expression::SystemCallExpandStatement: "
54  "KARL COMPILE ERROR:"
55  "System call expand_var requires 1 argument,"
56  "e.g., #expand_statement ('var{.i}')\n");
57 
59  "madara::expression::SystemCallExpandStatement: "
60  "KARL COMPILE ERROR: "
61  "System call expand_var requires 1 argument,"
62  "e.g., #expand_statement ('var{.i}')\n");
63  }
64 
65  return result;
66 }
67 
73 {
74  knowledge::KnowledgeRecord return_value;
75 
76  if (nodes_.size() == 1)
77  {
78  std::string statement(nodes_[0]->evaluate(settings).to_string());
79 
81  "madara::expression::SystemCallExpandStatement: "
82  "System call expand_statement is returning the expansion "
83  "of %s.\n",
84  statement.c_str());
85 
86  return knowledge::KnowledgeRecord(context_.expand_statement(statement));
87  }
88  else
89  {
91  "madara::expression::SystemCallExpandStatement: "
92  "KARL RUNTIME ERROR:"
93  "System call expand_var requires 1 argument,"
94  "e.g., #expand_statement ('var{.i}')\n");
95 
97  "madara::expression::SystemCallExpandStatement: "
98  "KARL RUNTIME ERROR: "
99  "System call expand_var requires 1 argument,"
100  "e.g., #expand_statement ('var{.i}')\n");
101  }
102 
103  return return_value;
104 }
105 
106 // accept a visitor
108  madara::expression::Visitor& visitor) const
109 {
110  visitor.visit(*this);
111 }
112 
113 #endif // _MADARA_NO_KARL_
#define madara_logger_ptr_log(loggering, level,...)
Fast version of the madara::logger::log method for Logger pointers.
Definition: Logger.h:41
const ThreadSafeContext * context_
madara::knowledge::KnowledgeRecord KnowledgeRecord
An exception for unrecoverable KaRL compilation issues.
Definition: KarlException.h:21
Defines a node that contains a madara::knowledge::KnowledgeRecord::Integer value.
Definition: LeafNode.h:25
virtual madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings)
Evaluates the expression tree.
virtual void accept(Visitor &visitor) const
Accepts a visitor subclassed from the Visitor class.
virtual madara::knowledge::KnowledgeRecord item(void) const
Returns the value of the node.
virtual madara::knowledge::KnowledgeRecord prune(bool &can_change)
Prunes the expression tree of unnecessary nodes.
SystemCallExpandStatement(madara::knowledge::ThreadSafeContext &context, const ComponentNodes &nodes)
Constructor.
Interface for a MADARA system call.
Abstract base class for all visitors to all classes that derive from ComponentNode.
Definition: Visitor.h:93
virtual void visit(const LeafNode &node)=0
Visit a LeafNode.
This class encapsulates an entry in a KnowledgeBase.
Settings for applying knowledge updates.
This class stores variables and their values for use by any entity needing state information in a thr...
std::deque< ComponentNode * > ComponentNodes
a vector of Component Nodes
constexpr string_t string