Spicy
hilti
toolchain
include
ast
statements
if.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
#include <hilti/base/logger.h>
12
13
namespace
hilti::statement {
14
16
class
If
:
public
Statement
{
17
public
:
18
auto
init()
const
{
return
child<hilti::declaration::LocalVariable>(0); }
19
auto
condition()
const
{
return
child<::hilti::Expression>(1); }
20
auto
true_()
const
{
return
child<hilti::Statement>(2); }
21
auto
false_()
const
{
return
child<Statement>(3); }
22
23
void
setCondition(
ASTContext
* ctx,
hilti::Expression
* c) {
setChild
(ctx, 1, c); }
24
25
static
auto
create(
ASTContext
* ctx,
26
hilti::Declaration
* init,
27
hilti::Expression
* cond,
28
Statement
* true_,
29
Statement
* false_,
30
Meta
meta
= {}) {
31
return
ctx->
make
<
If
>(ctx, {init, cond, true_, false_}, std::move(
meta
));
32
}
33
34
static
auto
create(
ASTContext
* ctx,
hilti::Expression
* cond,
Statement
* true_,
Statement
* false_,
Meta
meta
= {}) {
35
return
ctx->
make
<
If
>(ctx, {
nullptr
, cond, true_, false_}, std::move(
meta
));
36
}
37
38
protected
:
39
If
(
ASTContext
* ctx,
Nodes
children
,
Meta
meta
) :
Statement
(ctx, NodeTags, std::move(
children
), std::move(
meta
)) {
40
if
(
child
(0) && !
child
(0)->isA<declaration::LocalVariable>() )
41
logger().internalError(
"initialization for 'if' must be a local declaration"
);
42
}
43
44
HILTI_NODE_1(
statement::If
,
Statement
,
final
);
45
};
46
47
}
// namespace hilti::statement
hilti::ASTContext
Definition:
ast-context.h:128
hilti::ASTContext::make
T * make(Args &&... args)
Definition:
ast-context.h:382
hilti::Declaration
Definition:
declaration.h:53
hilti::Expression
Definition:
expression.h:15
hilti::Meta
Definition:
meta.h:30
hilti::Node::setChild
void setChild(ASTContext *ctx, size_t idx, Node *n)
Definition:
node.h:631
hilti::Node::children
const auto & children() const
Definition:
node.h:382
hilti::Node::meta
const auto & meta() const
Definition:
node.h:324
hilti::Node::child
T * child(int i) const
Definition:
node.h:393
hilti::Nodes
Definition:
forward.h:757
hilti::Statement
Definition:
statement.h:15
hilti::statement::If
Definition:
if.h:16
Generated by
1.9.1