hare::ast+x86_64 +linux
ast: abstract syntax tree for the Hare grammar
Index
Types
type _null; type _type; type access_expr; type access_field; type access_identifier; type access_index; type access_tuple; type alias_type; type align_expr; type alloc_expr; type alloc_form; type append_expr; type array_literal; type assert_expr; type assign_expr; type binarithm_expr; type binarithm_op; type binding; type binding_expr; type binding_kind; type break_expr; type break_yield; type builtin_type; type call_expr; type cast_expr; type cast_kind; type compound_expr; type continue_expr; type decl; type decl_const; type decl_func; type decl_global; type decl_type; type defer_expr; type delete_expr; type enum_field; type enum_type; type error_assert_expr; type error_type; type expr; type fndecl_attr; type for_expr; type for_kind; type free_expr; type func_param; type func_type; type ident; type if_expr; type import; type import_alias; type import_members; type import_wildcard; type insert_expr; type label; type len_contextual; type len_expr; type len_slice; type len_unbounded; type list_type; type literal_expr; type location; type match_case; type match_expr; type offset_expr; type plain_literal; type pointer_flag; type pointer_type; type propagate_expr; type return_expr; type size_expr; type slice_expr; type struct_alias; type struct_embedded; type struct_field; type struct_literal; type struct_member; type struct_type; type struct_value; type subunit; type switch_case; type switch_expr; type tagged_type; type tuple_literal; type tuple_type; type unarithm_expr; type unarithm_op; type undefined_expr; type union_type; type vaarg_expr; type vaend_expr; type value; type variadic_expr; type variadism; type vastart_expr; type yield_expr; // Undocumented types: type struct_union_type;
Constants
def IDENT_MAX: size = 255;
Functions
fn decl_finish(d: decl) void; fn expr_finish(e: nullable *expr) void; fn ident_dup(id: ident) ident; fn ident_eq(a: ident, b: ident) bool; fn ident_free(ident: ident) void; fn import_finish(import: import) void; fn imports_finish(imports: []import) void; fn subunit_finish(u: subunit) void; fn type_finish(t: nullable *_type) void;
Types
type _null[permalink] [source]
type _null = void;
The value "null".
type _type[permalink] [source]
type _type = struct { loc: location, repr: (alias_type | builtin_type | enum_type | error_type | func_type | list_type | pointer_type | struct_type | union_type | tagged_type | tuple_type), };
A Hare type.
type access_expr[permalink] [source]
type access_expr = (access_identifier | access_index | access_field | access_tuple);
An access expression.
type access_field[permalink] [source]
type access_field = struct { object: *expr, field: str, };
A struct field access expression.
foo.bar
type access_identifier[permalink] [source]
type access_identifier = ident;
An identifier access expression.
foo
type access_index[permalink] [source]
type access_index = struct { object: *expr, index: *expr, };
An index access expression.
foo[0]
type access_tuple[permalink] [source]
type access_tuple = struct { object: *expr, value: *expr, };
A tuple field access expression.
foo.1
type alias_type[permalink] [source]
type alias_type = ident;
A type alias.
type align_expr[permalink] [source]
type align_expr = *_type;
An align expression.
align(int)
type alloc_expr[permalink] [source]
type alloc_expr = struct { init: *expr, form: alloc_form, capacity: nullable *expr, };
An allocation expression.
alloc(foo) alloc(foo...) alloc(foo, bar)
type alloc_form[permalink] [source]
type alloc_form = enum { OBJECT, COPY, };
The form of an allocation expression.
alloc(foo) // OBJECT alloc(foo...) // COPY
type append_expr[permalink] [source]
type append_expr = struct { object: *expr, value: *expr, length: nullable *expr, variadic: bool, is_static: bool, };
An append expression.
append(foo, bar); append(foo, bar...); append(foo, [0...], bar);
type array_literal[permalink] [source]
type array_literal = struct { expand: bool, values: []*expr, };
An array literal.
[foo, bar, ...]
type assert_expr[permalink] [source]
type assert_expr = struct { cond: nullable *expr, message: nullable *expr, is_static: bool, };
An assertion expression.
assert(foo)
assert(foo, "error")
abort()
abort("error")
type assign_expr[permalink] [source]
type assign_expr = struct { op: (binarithm_op | void), // null for _ object: nullable *expr, value: *expr, };
An assignment expression.
foo = bar
type binarithm_expr[permalink] [source]
type binarithm_expr = struct { op: binarithm_op, lvalue: *expr, rvalue: *expr, };
A binary arithmetic expression.
foo * bar
type binarithm_op[permalink] [source]
type binarithm_op = enum { BAND, // & BOR, // | DIV, // / GT, // > GTEQ, // >= LAND, // && LEQUAL, // == LESS, // < LESSEQ, // <= LOR, // || LSHIFT, // << LXOR, // ^^ MINUS, // - MODULO, // % NEQUAL, // != PLUS, // + RSHIFT, // >> TIMES, // * BXOR, // ^ };
A binary arithmetic operator
type binding[permalink] [source]
type binding = struct { // empty slice for _ names: [](str, location), _type: nullable *_type, init: *expr, };
A single variable biding.
foo: int = bar (foo, _, foo2): (int, int, int) = bar _ = bar
type binding_expr[permalink] [source]
type binding_expr = struct { is_static: bool, kind: binding_kind, bindings: []binding, };
A variable binding expression.
let foo: int = bar, ...
type binding_kind[permalink] [source]
type binding_kind = enum { CONST, DEF, LET, };
The kind of binding expression being used.
type break_expr[permalink] [source]
type break_expr = break_yield;
A break expression. The label is set to empty string if absent.
break :label, expr
type break_yield[permalink] [source]
type break_yield = struct { label: label, value: nullable *expr, };
Structure common to breaks and yields.
type builtin_type[permalink] [source]
type builtin_type = enum { BOOL, DONE, F32, F64, FCONST, I16, I32, I64, I8, ICONST, INT, NEVER, NOMEM, NULL, OPAQUE, RCONST, RUNE, SIZE, STR, U16, U32, U64, U8, UINT, UINTPTR, UNDEFINED, VALIST, VOID, };
A built-in primitive type (int, bool, str, etc).
type call_expr[permalink] [source]
type call_expr = struct { lvalue: *expr, variadic: bool, args: []*expr, };
A function call expression.
foo(bar)
type cast_expr[permalink] [source]
type cast_expr = struct { kind: cast_kind, value: *expr, _type: *_type, };
A cast expression.
foo: int foo as int foo is int
type cast_kind[permalink] [source]
type cast_kind = enum { CAST, ASSERTION, TEST, };
The kind of cast expression being used.
type compound_expr[permalink] [source]
type compound_expr = struct { exprs: []*expr, label: label, };
A compound expression.
{
foo;
bar;
// ...
}
type continue_expr[permalink] [source]
type continue_expr = label;
A continue expression. The label is set to empty string if absent.
continue :label
type decl[permalink] [source]
type decl = struct { exported: bool, loc: location, decl: (decl_const | decl_global | decl_type | decl_func | assert_expr), // Only valid if the lexer has comments enabled docs: str, };
A Hare declaration.
type decl_const[permalink] [source]
type decl_const = struct { ident: ident, _type: nullable *_type, init: *expr, };
A constant declaration.
def foo: int = 0;
type decl_func[permalink] [source]
type decl_func = struct { symbol: str, ident: ident, prototype: *_type, body: nullable *expr, attrs: fndecl_attr, };
A function declaration.
fn main() void = void;
type decl_global[permalink] [source]
type decl_global = struct { is_const: bool, is_threadlocal: bool, symbol: str, ident: ident, _type: nullable *_type, init: nullable *expr, };
A global declaration.
let foo: int = 0; const foo: int = 0;
type decl_type[permalink] [source]
type decl_type = struct { ident: ident, _type: *_type, };
A type declaration.
type foo = int;
type defer_expr[permalink] [source]
type defer_expr = *expr;
A deferred expression.
defer foo
type delete_expr[permalink] [source]
type delete_expr = struct { object: *expr, is_static: bool, };
A delete expression.
delete(foo[10]) delete(foo[4..42])
type enum_field[permalink] [source]
type enum_field = struct { name: str, value: nullable *expr, loc: location, docs: str, };
An enumeration field (and optional value).
type enum_type[permalink] [source]
type enum_type = struct { storage: builtin_type, values: []enum_field, };
enum { FOO = 0, BAR, ... }
type error_assert_expr[permalink] [source]
type error_assert_expr = *expr;
An error assertion expression.
foo!
type error_type[permalink] [source]
type error_type = *_type;
!t
type expr[permalink] [source]
type expr = struct { loc: location, expr: (access_expr | align_expr | alloc_expr | append_expr | assert_expr | assign_expr | binarithm_expr | binding_expr | break_expr | call_expr | cast_expr | literal_expr | continue_expr | defer_expr | delete_expr | for_expr | free_expr | error_assert_expr | if_expr | insert_expr | compound_expr | match_expr | len_expr | size_expr | offset_expr | propagate_expr | return_expr | slice_expr | switch_expr | unarithm_expr | undefined_expr | variadic_expr | yield_expr), };
A Hare expression.
type fndecl_attr[permalink] [source]
type fndecl_attr = enum { NONE, FINI, INIT, TEST, };
Attributes applicable to a function declaration.
type for_expr[permalink] [source]
type for_expr = struct { kind: for_kind, bindings: nullable *expr, cond: nullable *expr, afterthought: nullable *expr, body: *expr, else_branch: nullable *expr, label: label, };
A for loop.
for (let foo = 0; foo < bar; baz) quux for (let line => next_line()) quux for (let number .. [1, 2, 3]) quux for (let ptr &.. [1, 2, 3]) quux
type for_kind[permalink] [source]
type for_kind = enum { ACCUMULATOR, EACH_VALUE, EACH_POINTER, ITERATOR, };
The kind of for expression being used.
type free_expr[permalink] [source]
type free_expr = *expr;
A free expression.
free(foo)
type func_param[permalink] [source]
type func_param = struct { loc: location, name: str, _type: *_type, default_value: (void | expr), };
A parameter to a function type.
type func_type[permalink] [source]
type func_type = struct { result: *_type, variadism: variadism, params: []func_param, };
fn(foo: int, baz: int...) int
type ident[permalink] [source]
type ident = []str;
Identifies a single object, e.g. foo::bar::baz.
type if_expr[permalink] [source]
type if_expr = struct { cond: *expr, tbranch: *expr, fbranch: nullable *expr, };
An if or if..else expression.
if (foo) bar else baz
type import[permalink] [source]
type import = struct { loc: location, ident: ident, bindings: (void | import_alias | import_members | import_wildcard), };
An imported module.
use foo;
use foo = bar;
use foo::{bar, baz};
use foo::*;
type import_alias[permalink] [source]
type import_alias = str;
An import alias.
use foo = bar;
type import_members[permalink] [source]
type import_members = []str;
An import members list.
use foo::{bar, baz};
type import_wildcard[permalink] [source]
type import_wildcard = void;
An import wildcard.
use foo::*;
type insert_expr[permalink] [source]
type insert_expr = append_expr;
An insert expression.
insert(foo[0], bar); insert(foo[0], bar...); insert(foo[0], [0...], bar);
type label[permalink] [source]
type label = str;
:label. The ":" character is not included.
type len_contextual[permalink] [source]
type len_contextual = void;
The length for a list type which is inferred from context (e.g. [_]int).
type len_expr[permalink] [source]
type len_expr = *expr;
A length expression.
len(foo)
type len_slice[permalink] [source]
type len_slice = void;
The length for a list type which is a slice (e.g. []int).
type len_unbounded[permalink] [source]
type len_unbounded = void;
The length for a list type which is unbounded (e.g. [*]int).
type list_type[permalink] [source]
type list_type = struct { length: (*expr | len_slice | len_unbounded | len_contextual), members: *_type, };
[]int, [*]int, [_]int, [foo]int
type literal_expr[permalink] [source]
type literal_expr = (plain_literal | array_literal | struct_literal | tuple_literal);
A literal expression.
type location[permalink] [source]
type location = struct { // The location of the start of the AST node start: lex::location, // The location of the end of the AST node end: lex::location, };
The location of an AST node
type match_case[permalink] [source]
type match_case = struct { // empty string for default case name: (str, location), // null for default case _type: nullable *_type, exprs: []*expr, };
A match case.
case type => exprs case let name: type => exprs
type match_expr[permalink] [source]
type match_expr = struct { value: *expr, cases: []match_case, label: label, };
A match expression.
match (foo) { case int => bar; ... }
type offset_expr[permalink] [source]
type offset_expr = *expr;
An offset expression.
offset(foo.bar)
type plain_literal[permalink] [source]
type plain_literal = struct { storage: builtin_type, value: value, };
A plain literal.
type pointer_flag[permalink] [source]
type pointer_flag = enum uint { NONE = 0, NULLABLE = 1 << 0, };
Flags which apply to a pointer type.
type pointer_type[permalink] [source]
type pointer_type = struct { referent: *_type, flags: pointer_flag, };
*int
type propagate_expr[permalink] [source]
type propagate_expr = *expr;
An error propagation expression.
foo?
type return_expr[permalink] [source]
type return_expr = nullable *expr;
A return statement.
return foo
type size_expr[permalink] [source]
type size_expr = *_type;
A size expression.
size(int)
type slice_expr[permalink] [source]
type slice_expr = struct { object: *expr, start: nullable *expr, end: nullable *expr, };
A slicing expression.
foo[bar..baz]
type struct_alias[permalink] [source]
type struct_alias = ident;
An embedded type alias.
type struct_embedded[permalink] [source]
type struct_embedded = *_type;
An embedded struct type.
type struct_field[permalink] [source]
type struct_field = struct { // may be "_" name: str, _type: *_type, };
A single field of a struct type.
type struct_literal[permalink] [source]
type struct_literal = struct { autofill: bool, undefined: bool, // [] for anonymous alias: ident, fields: [](struct_value | *struct_literal), };
A struct literal.
struct { foo: int = bar, struct { baz = quux }, ... }
type struct_member[permalink] [source]
type struct_member = struct { member: (struct_field | struct_embedded | struct_alias), // Only valid if the lexer has comments enabled docs: str, };
struct { foo: int, struct { bar: int }, baz::quux }
type struct_type[permalink] [source]
type struct_type = struct { packed: bool, members: []struct_member, };
struct { ... }
type struct_value[permalink] [source]
type struct_value = struct { name: str, _type: nullable *_type, init: *expr, };
A single struct field and value.
foo: int = 10
type subunit[permalink] [source]
type subunit = struct { imports: []import, decls: []decl, };
A sub-unit, typically representing a single source file.
type switch_case[permalink] [source]
type switch_case = struct { // [] for default case options: []*expr, exprs: []*expr, };
A switch case.
case value => exprs
type switch_expr[permalink] [source]
type switch_expr = struct { value: *expr, cases: []switch_case, label: label, };
A switch expression.
switch (foo) { case bar => baz; ... }
type tagged_type[permalink] [source]
type tagged_type = [](*_type, bool);
(int | bool)
type tuple_literal[permalink] [source]
type tuple_literal = []*expr;
A tuple literal.
(foo, bar, ...)
type tuple_type[permalink] [source]
type tuple_type = []*_type;
(int, bool, ...)
type unarithm_expr[permalink] [source]
type unarithm_expr = struct { op: unarithm_op, operand: *expr, };
A unary arithmetic expression.
!example
type unarithm_op[permalink] [source]
type unarithm_op = enum { ADDR, // & BNOT, // ~ DEREF, // * LNOT, // ! MINUS, // - };
A unary operator
type undefined_expr[permalink] [source]
type undefined_expr = void;
An expression with an undefined result (@undefined).
type union_type[permalink] [source]
type union_type = []struct_member;
union { ... }
type vaarg_expr[permalink] [source]
type vaarg_expr = struct { ap: *expr, _type: *_type, };
A vaarg expression.
vaarg(ap, int)
type vaend_expr[permalink] [source]
type vaend_expr = *expr;
A vaend expression.
vaend(ap)
type value[permalink] [source]
type value = (...lex::value | bool | done | nomem | _null);
The contents of a plain literal.
type variadic_expr[permalink] [source]
type variadic_expr = (vastart_expr | vaarg_expr | vaend_expr);
A C-style variadic expression.
type variadism[permalink] [source]
type variadism = enum { NONE, C, HARE, };
The variadism strategy for a function type.
type vastart_expr[permalink] [source]
type vastart_expr = void;
A vastart expression.
vastart()
type yield_expr[permalink] [source]
type yield_expr = break_yield;
A yield expression.
yield foo
type struct_union_type[permalink] [source]
Show undocumented member
type struct_union_type = (struct_type | union_type);
Constants
def IDENT_MAX[permalink] [source]
def IDENT_MAX: size = 255;
Maximum length of an identifier, as the sum of the lengths of its parts plus one for each namespace deliniation.
In other words, the length of "a::b::c" is 5.
Functions
fn decl_finish[permalink] [source]
fn decl_finish(d: decl) void;
Frees resources associated with a declaration.
fn expr_finish[permalink] [source]
fn expr_finish(e: nullable *expr) void;
Frees resources associated with a Hare expression.
fn ident_dup[permalink] [source]
fn ident_dup(id: ident) ident;
Duplicates an ident.
fn ident_eq[permalink] [source]
fn ident_eq(a: ident, b: ident) bool;
Returns true if two idents are identical.
fn ident_free[permalink] [source]
fn ident_free(ident: ident) void;
Frees resources associated with an identifier.
fn import_finish[permalink] [source]
fn import_finish(import: import) void;
Frees resources associated with an import.
fn imports_finish[permalink] [source]
fn imports_finish(imports: []import) void;
Frees resources associated with each import in a slice, and then frees the slice itself.
fn subunit_finish[permalink] [source]
fn subunit_finish(u: subunit) void;
Frees resources associated with a subunit.
fn type_finish[permalink] [source]
fn type_finish(t: nullable *_type) void;
Frees resources associated with a _type.