Spicy
for.h
1 // Copyright (c) 2020-2021 by the Zeek Project. See LICENSE for details.
2 
3 #pragma once
4 
5 #include <memory>
6 #include <utility>
7 
8 #include <hilti/ast/declarations/local-variable.h>
9 #include <hilti/ast/expression.h>
10 #include <hilti/ast/statement.h>
11 
12 namespace hilti::statement {
13 
15 class For : public NodeBase, public hilti::trait::isStatement {
16 public:
17  For(hilti::ID id, hilti::Expression seq, Statement body, Meta m = Meta())
18  : NodeBase(nodes(declaration::LocalVariable(std::move(id), true, id.meta()), std::move(seq), std::move(body)),
19  std::move(m)) {}
20 
21  const auto& local() const { return child<hilti::declaration::LocalVariable>(0); }
22  auto localRef() const { return NodeRef(children()[0]); }
23  const auto& sequence() const { return child<hilti::Expression>(1); }
24  const auto& body() const { return child<hilti::Statement>(2); }
25 
26  void setLocalType(const Type& t) { children()[0].as<declaration::LocalVariable>().setType(t); }
27 
28  bool operator==(const For& other) const {
29  return local() == other.local() && sequence() == other.sequence() && body() == other.body();
30  }
31 
33  auto& _sequenceNode() { return children()[1]; }
34 
36  auto& _bodyNode() { return children()[2]; }
37 
39  auto isEqual(const Statement& other) const { return node::isEqual(this, other); }
40 
42  auto properties() const { return node::Properties{}; }
43 };
44 
45 } // namespace hilti::statement
Definition: local-variable.h:18
Definition: for.h:15
auto & _bodyNode()
Definition: for.h:36
const auto & children() const
Definition: node.h:471
Definition: meta.h:19
auto properties() const
Definition: for.h:42
Definition: type.h:160
Definition: statement.h:14
auto isEqual(const Statement &other) const
Definition: for.h:39
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:97
Definition: node-ref.h:45
auto & _sequenceNode()
Definition: for.h:33
auto & meta() const
Definition: node.h:475
Definition: id.h:18
Definition: node.h:359