MADARA  3.4.1
SystemCallType.cpp
Go to the documentation of this file.
1 
2 #ifndef _MADARA_NO_KARL_
3 
7 
10  : SystemCallNode(context, nodes)
11 {
12 }
13 
14 // Dtor
16 
18  void) const
19 {
20  return madara::knowledge::KnowledgeRecord(nodes_.size());
21 }
22 
27  bool& can_change)
28 {
29  // user can always change a function, and we have no control over
30  // what it does. Consequently, a function node cannot be pruned out
31  // under any situation
32  can_change = true;
33 
35 
36  if (nodes_.size() > 0)
37  {
38  bool arg_can_change = false;
39  result = nodes_[0]->prune(arg_can_change);
40 
41  if (!arg_can_change && dynamic_cast<LeafNode*>(nodes_[0]) == 0)
42  {
43  delete nodes_[0];
44  nodes_[0] = new LeafNode(*(this->logger_), result);
45  }
46  }
47  else
48  {
50  "madara::expression::SystemCallType: "
51  "KARL COMPILE ERROR:"
52  "System call type requires an argument\n");
53 
54  throw exceptions::KarlException("madara::expression::SystemCallType: "
55  "KARL COMPILE ERROR: "
56  "System call type requires an argument\n");
57  }
58 
59  return result;
60 }
61 
66 {
67  knowledge::KnowledgeRecord return_value;
68 
69  if (nodes_.size() > 0)
70  {
72  "madara::expression::SystemCallType: "
73  "System call type is returning the type of its first argument\n");
74 
76  nodes_[0]->evaluate(settings).type());
77  }
78  else
79  {
81  "madara::expression::SystemCallType: "
82  "KARL RUNTIME ERROR:"
83  "System call type requires an argument\n");
84 
85  throw exceptions::KarlException("madara::expression::SystemCallType: "
86  "KARL RUNTIME ERROR: "
87  "System call type requires an argument\n");
88  }
89 
90  return return_value;
91 }
92 
93 // accept a visitor
95  madara::expression::Visitor& visitor) const
96 {
97  visitor.visit(*this);
98 }
99 
100 #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
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
Interface for a MADARA system call.
virtual void accept(Visitor &visitor) const
Accepts a visitor subclassed from the Visitor class.
virtual madara::knowledge::KnowledgeRecord prune(bool &can_change)
Prunes the expression tree of unnecessary nodes.
virtual madara::knowledge::KnowledgeRecord item(void) const
Returns the value of the node.
virtual ~SystemCallType(void)
Destructor.
SystemCallType(madara::knowledge::ThreadSafeContext &context, const ComponentNodes &nodes)
Constructor.
virtual madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings)
Evaluates the expression tree.
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