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 {
13 namespace statement {
14 
16 class For : public NodeBase, public hilti::trait::isStatement {
17 public:
18  For(hilti::ID id, hilti::Expression seq, Statement body, Meta m = Meta())
19  : NodeBase(nodes(declaration::LocalVariable(std::move(id), true, id.meta()), std::move(seq), std::move(body)),
20  std::move(m)) {}
21 
22  const auto& local() const { return child<hilti::declaration::LocalVariable>(0); }
23  auto localRef() const { return NodeRef(children()[0]); }
24  const auto& sequence() const { return child<hilti::Expression>(1); }
25  const auto& body() const { return child<hilti::Statement>(2); }
26 
27  void setLocalType(Type t) { children()[0].as<declaration::LocalVariable>().setType(std::move(t)); }
28 
29  bool operator==(const For& other) const {
30  return local() == other.local() && sequence() == other.sequence() && body() == other.body();
31  }
32 
34  auto& _sequenceNode() { return children()[1]; }
35 
37  auto& _bodyNode() { return children()[2]; }
38 
40  auto isEqual(const Statement& other) const { return node::isEqual(this, other); }
41 
43  auto properties() const { return node::Properties{}; }
44 };
45 
46 } // namespace statement
47 } // namespace hilti
Definition: local-variable.h:19
Definition: for.h:16
auto & _bodyNode()
Definition: for.h:37
const auto & children() const
Definition: node.h:470
Definition: meta.h:18
auto properties() const
Definition: for.h:43
Definition: type.h:159
Definition: statement.h:14
auto isEqual(const Statement &other) const
Definition: for.h:40
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:99
Definition: node-ref.h:44
auto & _sequenceNode()
Definition: for.h:34
auto & meta() const
Definition: node.h:474
Definition: id.h:18
Definition: node.h:358