tiny.chant.parse.thread
Defined in parse.
API (5)
Actions
Public operations.
Types and contracts
Public types and contracts.
Source
Source: lib/chant/src/parse/root.zig:13
zig
pub const thread = @import("thread.zig");Source: lib/chant/src/parse/thread.zig
zig
const ast = @import("../ast/root.zig");const constant = @import("constant.zig");const state = @import("state/root.zig");const Error = @import("error.zig").Error;const diagnostic = state.diagnostic;const Parser = state.Parser;pub const Scope = enum { file, block,};pub fn validateTypedef(parser: *Parser, is_thread_local: bool) Error!void { if (is_thread_local) { return diagnostic.fail(parser, error.UnsupportedConstruct, "typedef cannot be thread_local"); }}pub fn validateFunction(parser: *Parser, is_thread_local: bool) Error!void { if (is_thread_local) { return diagnostic.fail(parser, error.UnsupportedConstruct, "function declarations cannot be thread_local"); }}pub fn validateParameter(parser: *Parser, is_thread_local: bool) Error!void { if (is_thread_local) { return diagnostic.fail(parser, error.UnsupportedConstruct, "parameters cannot be thread_local"); }}pub fn validateObject(parser: *Parser, scope: Scope, storage: ast.Storage, c_type: *const ast.Type, initializer: ?*ast.Expr, is_thread_local: bool) Error!void { if (!is_thread_local) return; if (scope == .block and storage != .static and storage != .extern_storage) { return diagnostic.fail(parser, error.UnsupportedConstruct, "block-scope thread_local requires static or extern"); } if (isVariablyModified(c_type)) { return diagnostic.fail(parser, error.UnsupportedConstruct, "thread_local object cannot have variably modified type"); } if (initializer) |expr| { if (!try constant.isInitializer(parser, expr)) { return diagnostic.fail(parser, error.InvalidConstant, "thread_local initializer is not a constant initializer"); } }}fn isVariablyModified(c_type: *const ast.Type) bool { switch (c_type.kind) { .array => { if (c_type.vla_len != null) return true; if (c_type.child) |child| return isVariablyModified(child); return false; }, .pointer => { if (c_type.child) |child| return isVariablyModified(child); return false; }, .function => { if (c_type.child) |child| { if (isVariablyModified(child)) return true; } for (c_type.params) |param| { if (isVariablyModified(param.type)) return true; } return false; }, else => return false, }}Audit
| Definitions | 6 |
|---|---|
| Public names | 6 |
| Members | 2 |
| Version | 26.7.0 |
| Revision | daab053ee433 |