getDeclaration
Function parameters
Parameters
The data stored at byte offset 0 when ZIR is stored in a file.
Types
- Header
- The data stored at byte offset 0 when ZIR is stored in a file.
- Inst
- These are untyped instructions generated from an Abstract Syntax Tree.
- DeclContents
- `DeclContents` contains all "interesting" instructions found within a declaration by `findTrackable`.
Returns the requested data, as well as the new index which is at the start of the
Functions
- extraData
- Returns the requested data, as well as the new index which is at the start of the
- nullTerminatedString
- Given an index into `string_bytes` returns the null-terminated string found there.
- findTrackable
- Find all tracked ZIR instructions, recursively, within a `declaration` instruction.
- findTrackableRoot
- Like `findTrackable`, but only considers the `main_struct_inst` instruction.
- assertTrackable
- Asserts that a ZIR instruction is tracked across incremental updates, and
When the ZIR update tracking logic must be modified to consider new instructions,
Values
- inst_tracking_version
- When the ZIR update tracking logic must be modified to consider new instructions,
Source
Implementation
pub fn getDeclaration(zir: Zir, inst: Zir.Inst.Index) Inst.Declaration.Unwrapped {
assert(zir.instructions.items(.tag)[@intFromEnum(inst)] == .declaration);
const pl_node = zir.instructions.items(.data)[@intFromEnum(inst)].declaration;
const extra = zir.extraData(Inst.Declaration, pl_node.payload_index);
const flags_vals: [2]u32 = .{ extra.data.flags_0, extra.data.flags_1 };
const flags: Inst.Declaration.Flags = @bitCast(flags_vals);
var extra_index = extra.end;
const name: NullTerminatedString = if (flags.id.hasName()) name: {
const name = zir.extra[extra_index];
extra_index += 1;
break :name @enumFromInt(name);
} else .empty;
const lib_name: NullTerminatedString = if (flags.id.hasLibName()) lib_name: {
const lib_name = zir.extra[extra_index];
extra_index += 1;
break :lib_name @enumFromInt(lib_name);
} else .empty;
const type_body_len: u32 = if (flags.id.hasTypeBody()) len: {
const len = zir.extra[extra_index];
extra_index += 1;
break :len len;
} else 0;
const align_body_len: u32, const linksection_body_len: u32, const addrspace_body_len: u32 = lens: {
if (!flags.id.hasSpecialBodies()) break :lens .{ 0, 0, 0 };
const lens = zir.extra[extra_index..][0..3].*;
extra_index += 3;
break :lens lens;
};
const value_body_len: u32 = if (flags.id.hasValueBody()) len: {
const len = zir.extra[extra_index];
extra_index += 1;
break :len len;
} else 0;
const type_body = zir.bodySlice(extra_index, type_body_len);
extra_index += type_body_len;
const align_body = zir.bodySlice(extra_index, align_body_len);
extra_index += align_body_len;
const linksection_body = zir.bodySlice(extra_index, linksection_body_len);
extra_index += linksection_body_len;
const addrspace_body = zir.bodySlice(extra_index, addrspace_body_len);
extra_index += addrspace_body_len;
const value_body = zir.bodySlice(extra_index, value_body_len);
extra_index += value_body_len;
return .{
.src_node = pl_node.src_node,
.src_line = flags.src_line,
.src_column = flags.src_column,
.kind = flags.id.kind(),
.name = name,
.is_pub = flags.id.isPub(),
.is_threadlocal = flags.id.isThreadlocal(),
.linkage = flags.id.linkage(),
.lib_name = lib_name,
.type_body = if (type_body_len == 0) null else type_body,
.align_body = if (align_body_len == 0) null else align_body,
.linksection_body = if (linksection_body_len == 0) null else linksection_body,
.addrspace_body = if (addrspace_body_len == 0) null else addrspace_body,
.value_body = if (value_body_len == 0) null else value_body,
};
}