lib/chant/src/ast/decl.zig
daab053ee43316e1809a84551d573ddd1e5bf3d2
1 const std = @import("std");
2 const types = @import("type/root.zig");
3 const stmt = @import("stmt.zig");
4 const storage = @import("storage.zig");
5 const variable = @import("variable.zig");
6
7 pub const Function = struct {
8 name: []const u8,
9 type: *const types.Type,
10 storage: storage.Storage = .none,
11 body: ?*stmt.Stmt = null,
12 };
13
14 pub const Decl = union(enum) {
15 variable: variable.Variable,
16 function: Function,
17 };
18
19 pub const TranslationUnit = struct {
20 declarations: []Decl,
21 };
22
23 test "declarations model functions and globals" {
24 const fn_type = types.Type{
25 .kind = .function,
26 .child = &types.void_type,
27 .params = &.{.{ .name = "n", .type = &types.int_type }},
28 };
29 const function = Function{ .name = "kernel", .type = &fn_type, .storage = .static };
30 try std.testing.expectEqualStrings("kernel", function.name);
31 try std.testing.expect(function.body == null);
32 }