Skip to content
← Back

src/syntax/trees/definitions/function.ghul

1
namespace Syntax.Trees.Definitions is
2
use IO.Std;
3
4
use Source;
5
6
class FUNCTION(
7
location: LOCATION,
8
name: Identifiers.Identifier?,
9
generic_arguments: TypeExpressions.LIST,
10
arguments: Variables.LIST public,
11
type_expression: TypeExpressions.TypeExpression,
12
modifiers: Modifiers.LIST,
13
body: Bodies.Body? public
14
): MODIFIABLE, ScopeCarrier is
15
scope: Semantic.Scope? public;
16
17
// True when the body contains an `await` expression (not in
18
// a nested lambda). Set by declare-symbols. Drives async
19
// classification + downstream IL emission decisions.
20
contains_let_await: bool public;
21
22
// True when `contains_let_await` is set AND the body has no
23
// value-returning `return X;` statements — meaning the
24
// function returns the non-generic `Tasks.TASK` (rather than
25
// `Tasks.TASK[T]` for some T).
26
is_void_async: bool public;
27
28
// Set on the `init` FUNCTION synthesised by
29
// rewrite-primary-constructors from a class's primary-constructor
30
// header. Lets declare-symbols record the primary constructor on
31
// the owning type (a class can have secondary constructors too, so
32
// the primary is not simply the only `init`).
33
is_primary_constructor: bool public;
34
35
for_property: PROPERTY? public;
36
37
// Set on the accessor FUNCTIONs synthesised by add-accessors-for-
38
// properties when the owning property is underscore-prefixed. The
39
// accessor's own IL name ($get_/$set_) does not start with an
40
// underscore, so this carries the property's underscore scope
41
// through to declare-symbols, where it drives the access policy.
42
is_underscore_scoped: bool public;
43
44
// Set on FUNCTIONs synthesised by add-accessors-for-
45
// properties from a `[index]: T` indexer. The CLR-required
46
// names `get_Item` / `set_Item` aren't user-chosen, so
47
// diagnostics that target user naming (e.g. the snake_case
48
// member-name warning) gate on `!for_indexer?`.
49
for_indexer: INDEXER? public;
50
51
super(location, modifiers);
52
53
accept(visitor: Visitor) is
54
visitor.visit(self);
55
si
56
57
walk(visitor: Visitor) is
58
if !visitor.pre(self) then
59
// the children can be left null when the parser hits
60
// catastrophic input and unwinds out of the declaration
61
if name? then
62
name.walk(visitor);
63
fi
64
65
arguments.walk(visitor);
66
67
type_expression.walk(visitor);
68
69
if body? then
70
body.walk(visitor);
71
fi
72
fi
73
74
accept(visitor);
75
si
76
si
77
si