Skip to content
← Back

src/syntax/trees/expressions/statement.ghul

1
namespace Syntax.Trees.Expressions is
2
use Source
3
4
class STATEMENT: Expression is
5
statement: Statements.Statement
6
temp: IR.TEMP? public => statement_state.temp, = value is statement_state.temp = value si
7
8
// Set by the wrapping context (compile-expressions). Drives
9
// whether the inner statement must yield a value: an
10
// `if`/`case` in expression position always must; a
11
// `val ... lav` block must when its result is consumed and
12
// is void-tolerant otherwise (e.g. expression-statement
13
// position, or a void-returning `=>` body). The wrapping
14
// Statements.EXPRESSION.pre pushes its own want_value down
15
// when this expression is a STATEMENT.
16
want_value: bool public => statement_state.want_value, = value is statement_state.want_value = value si
17
18
// True where a value is wanted but a void one is acceptable —
19
// the body of a function literal whose return type is still
20
// being inferred. Pushed onto the inner statement so a
21
// void-armed `if` / `case` there can decline to produce a
22
// value instead of being reported for having none.
23
void_tolerated: bool public => statement_state.void_tolerated, = value is statement_state.void_tolerated = value si
24
25
statement_state: Syntax.Process.STATEMENT_EXPRESSION_STATE field
26
27
is_tuple_literal: bool => statement.is_tuple_literal
28
29
init(location: LOCATION, statement: Statements.Statement) is
30
super.init(location)
31
32
self.statement = statement
33
self.want_value = true
34
self.void_tolerated = false
35
si
36
37
clear() is
38
super.clear()
39
statement_state.clear()
40
si
41
42
clear_outputs() is
43
super.clear_outputs()
44
statement_state.clear_outputs()
45
si
46
47
set_expected_type(expected_type: Semantic.Types.Type?, error_message: string?) is
48
statement.set_expected_type(expected_type, error_message)
49
si
50
51
clear_expected_type() is
52
statement.clear_expected_type()
53
si
54
55
accept(visitor: Visitor) is
56
visitor.visit(self)
57
si
58
59
walk(visitor: Visitor) is
60
if !visitor.pre(self) then
61
statement.walk(visitor)
62
fi
63
64
accept(visitor)
65
si
66
si
67
si