tiny.chant.ast.expr
Defined in ast.
API (16)
Types and contracts
Public types and contracts.
AssignBinaryBinaryOpCallCastConditionalExprFloatLiteralIdentifierIndexInitializerItemInitializerListIntegerLiteralStringLiteralUnaryUnaryOp
Source
Source: lib/chant/src/ast/expr.zig
zig
const std = @import("std");const types = @import("type/root.zig");pub const BinaryOp = enum { add, sub, mul, div, rem, lt, gt, le, ge, eq, ne, logical_and, logical_or, bit_and, bit_or, bit_xor, shl, shr,};pub const UnaryOp = enum { negate, logical_not, bit_not, address_of, deref,};pub const IntegerLiteral = struct { value: u64, type: *const types.Type,};pub const FloatLiteral = struct { value: f64, type: *const types.Type,};pub const StringLiteral = struct { text: []const u8,};pub const Identifier = struct { name: []const u8,};pub const Binary = struct { op: BinaryOp, lhs: *Expr, rhs: *Expr,};pub const Unary = struct { op: UnaryOp, operand: *Expr,};pub const Assign = struct { op: ?BinaryOp, target: *Expr, value: *Expr,};pub const Conditional = struct { condition: *Expr, then_value: *Expr, else_value: *Expr,};pub const Call = struct { callee: []const u8, arguments: []*Expr,};pub const Index = struct { base: *Expr, subscript: *Expr,};pub const Cast = struct { target: *const types.Type, operand: *Expr,};pub const InitializerItem = struct { designator: []const u64 = &.{}, value: *Expr,};pub const InitializerList = struct { type: *const types.Type, items: []InitializerItem,};pub const Expr = union(enum) { integer_literal: IntegerLiteral, float_literal: FloatLiteral, string_literal: StringLiteral, identifier: Identifier, binary: Binary, unary: Unary, assign: Assign, conditional: Conditional, call: Call, index: Index, cast: Cast, initializer_list: InitializerList,};test "expressions compose as arena nodes" { var arena = std.heap.ArenaAllocator.init(std.testing.allocator); defer arena.deinit(); const allocator = arena.allocator(); const lhs = try allocator.create(Expr); lhs.* = .{ .identifier = .{ .name = "i" } }; const rhs = try allocator.create(Expr); rhs.* = .{ .integer_literal = .{ .value = 1, .type = &types.int_type } }; const sum = try allocator.create(Expr); sum.* = .{ .binary = .{ .op = .add, .lhs = lhs, .rhs = rhs } }; try std.testing.expectEqual(BinaryOp.add, sum.binary.op); try std.testing.expectEqualStrings("i", sum.binary.lhs.identifier.name);}Source: lib/chant/src/ast/root.zig:2
zig
pub const expr = @import("expr.zig");Audit
| Definitions | 17 |
|---|---|
| Public names | 18 |
| Members | 62 |
| Version | 26.7.0 |
| Revision | daab053ee433 |