Spicy
for.h
1 // Copyright (c) 2020-now 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 Statement {
16 public:
17  auto local() const { return child<hilti::declaration::LocalVariable>(0); }
18  auto sequence() const { return child<::hilti::Expression>(1); }
19  auto body() const { return child<hilti::Statement>(2); }
20 
21  static auto create(ASTContext* ctx, const hilti::ID& id, hilti::Expression* seq, Statement* body, Meta meta = {}) {
22  auto* local = declaration::LocalVariable::create(ctx, id, meta);
23  return ctx->make<For>(ctx, {local, seq, body}, std::move(meta));
24  }
25 
26 protected:
27  For(ASTContext* ctx, Nodes children, Meta meta) : Statement(ctx, NodeTags, std::move(children), std::move(meta)) {}
28 
29  HILTI_NODE_1(statement::For, Statement, final);
30 };
31 
32 } // namespace hilti::statement
Definition: ast-context.h:121
T * make(Args &&... args)
Definition: ast-context.h:366
Definition: expression.h:15
Definition: id.h:15
Definition: meta.h:30
const auto & children() const
Definition: node.h:364
const auto & meta() const
Definition: node.h:306
Definition: forward.h:758
Definition: statement.h:15
Definition: for.h:15