mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
AstGen: cleanup @as invasion
This commit is contained in:
parent
41575fa868
commit
09b0070e87
340
src/AstGen.zig
340
src/AstGen.zig
File diff suppressed because it is too large
Load Diff
40
src/Zir.zig
40
src/Zir.zig
@ -78,12 +78,13 @@ pub fn extraData(code: Zir, comptime T: type, index: usize) ExtraData(T) {
|
||||
inline for (fields) |field| {
|
||||
@field(result, field.name) = switch (field.type) {
|
||||
u32 => code.extra[i],
|
||||
Inst.Ref => @as(Inst.Ref, @enumFromInt(code.extra[i])),
|
||||
i32 => @as(i32, @bitCast(code.extra[i])),
|
||||
Inst.Call.Flags => @as(Inst.Call.Flags, @bitCast(code.extra[i])),
|
||||
Inst.BuiltinCall.Flags => @as(Inst.BuiltinCall.Flags, @bitCast(code.extra[i])),
|
||||
Inst.SwitchBlock.Bits => @as(Inst.SwitchBlock.Bits, @bitCast(code.extra[i])),
|
||||
Inst.FuncFancy.Bits => @as(Inst.FuncFancy.Bits, @bitCast(code.extra[i])),
|
||||
Inst.Ref => @enumFromInt(code.extra[i]),
|
||||
i32,
|
||||
Inst.Call.Flags,
|
||||
Inst.BuiltinCall.Flags,
|
||||
Inst.SwitchBlock.Bits,
|
||||
Inst.FuncFancy.Bits,
|
||||
=> @bitCast(code.extra[i]),
|
||||
else => @compileError("bad field type"),
|
||||
};
|
||||
i += 1;
|
||||
@ -115,8 +116,7 @@ pub fn nullTerminatedString2(code: Zir, index: NullTerminatedString) [:0]const u
|
||||
}
|
||||
|
||||
pub fn refSlice(code: Zir, start: usize, len: usize) []Inst.Ref {
|
||||
const raw_slice = code.extra[start..][0..len];
|
||||
return @as([]Inst.Ref, @ptrCast(raw_slice));
|
||||
return @ptrCast(code.extra[start..][0..len]);
|
||||
}
|
||||
|
||||
pub fn hasCompileErrors(code: Zir) bool {
|
||||
@ -3266,10 +3266,10 @@ pub const DeclIterator = struct {
|
||||
}
|
||||
it.decl_i += 1;
|
||||
|
||||
const flags = @as(u4, @truncate(it.cur_bit_bag));
|
||||
const flags: u4 = @truncate(it.cur_bit_bag);
|
||||
it.cur_bit_bag >>= 4;
|
||||
|
||||
const sub_index = @as(u32, @intCast(it.extra_index));
|
||||
const sub_index: u32 = @intCast(it.extra_index);
|
||||
it.extra_index += 5; // src_hash(4) + line(1)
|
||||
const name = it.zir.nullTerminatedString(it.zir.extra[it.extra_index]);
|
||||
it.extra_index += 3; // name(1) + value(1) + doc_comment(1)
|
||||
@ -3296,7 +3296,7 @@ pub fn declIterator(zir: Zir, decl_inst: u32) DeclIterator {
|
||||
const extended = datas[decl_inst].extended;
|
||||
switch (extended.opcode) {
|
||||
.struct_decl => {
|
||||
const small = @as(Inst.StructDecl.Small, @bitCast(extended.small));
|
||||
const small: Inst.StructDecl.Small = @bitCast(extended.small);
|
||||
var extra_index: usize = extended.operand;
|
||||
extra_index += @intFromBool(small.has_src_node);
|
||||
extra_index += @intFromBool(small.has_fields_len);
|
||||
@ -3319,7 +3319,7 @@ pub fn declIterator(zir: Zir, decl_inst: u32) DeclIterator {
|
||||
return declIteratorInner(zir, extra_index, decls_len);
|
||||
},
|
||||
.enum_decl => {
|
||||
const small = @as(Inst.EnumDecl.Small, @bitCast(extended.small));
|
||||
const small: Inst.EnumDecl.Small = @bitCast(extended.small);
|
||||
var extra_index: usize = extended.operand;
|
||||
extra_index += @intFromBool(small.has_src_node);
|
||||
extra_index += @intFromBool(small.has_tag_type);
|
||||
@ -3334,7 +3334,7 @@ pub fn declIterator(zir: Zir, decl_inst: u32) DeclIterator {
|
||||
return declIteratorInner(zir, extra_index, decls_len);
|
||||
},
|
||||
.union_decl => {
|
||||
const small = @as(Inst.UnionDecl.Small, @bitCast(extended.small));
|
||||
const small: Inst.UnionDecl.Small = @bitCast(extended.small);
|
||||
var extra_index: usize = extended.operand;
|
||||
extra_index += @intFromBool(small.has_src_node);
|
||||
extra_index += @intFromBool(small.has_tag_type);
|
||||
@ -3349,7 +3349,7 @@ pub fn declIterator(zir: Zir, decl_inst: u32) DeclIterator {
|
||||
return declIteratorInner(zir, extra_index, decls_len);
|
||||
},
|
||||
.opaque_decl => {
|
||||
const small = @as(Inst.OpaqueDecl.Small, @bitCast(extended.small));
|
||||
const small: Inst.OpaqueDecl.Small = @bitCast(extended.small);
|
||||
var extra_index: usize = extended.operand;
|
||||
extra_index += @intFromBool(small.has_src_node);
|
||||
const decls_len = if (small.has_decls_len) decls_len: {
|
||||
@ -3545,7 +3545,7 @@ fn findDeclsSwitch(
|
||||
|
||||
const special_prong = extra.data.bits.specialProng();
|
||||
if (special_prong != .none) {
|
||||
const body_len = @as(u31, @truncate(zir.extra[extra_index]));
|
||||
const body_len: u31 = @truncate(zir.extra[extra_index]);
|
||||
extra_index += 1;
|
||||
const body = zir.extra[extra_index..][0..body_len];
|
||||
extra_index += body.len;
|
||||
@ -3558,7 +3558,7 @@ fn findDeclsSwitch(
|
||||
var scalar_i: usize = 0;
|
||||
while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
|
||||
extra_index += 1;
|
||||
const body_len = @as(u31, @truncate(zir.extra[extra_index]));
|
||||
const body_len: u31 = @truncate(zir.extra[extra_index]);
|
||||
extra_index += 1;
|
||||
const body = zir.extra[extra_index..][0..body_len];
|
||||
extra_index += body_len;
|
||||
@ -3573,7 +3573,7 @@ fn findDeclsSwitch(
|
||||
extra_index += 1;
|
||||
const ranges_len = zir.extra[extra_index];
|
||||
extra_index += 1;
|
||||
const body_len = @as(u31, @truncate(zir.extra[extra_index]));
|
||||
const body_len: u31 = @truncate(zir.extra[extra_index]);
|
||||
extra_index += 1;
|
||||
const items = zir.refSlice(extra_index, items_len);
|
||||
extra_index += items_len;
|
||||
@ -3655,7 +3655,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
|
||||
ret_ty_ref = .void_type;
|
||||
},
|
||||
1 => {
|
||||
ret_ty_ref = @as(Inst.Ref, @enumFromInt(zir.extra[extra_index]));
|
||||
ret_ty_ref = @enumFromInt(zir.extra[extra_index]);
|
||||
extra_index += 1;
|
||||
},
|
||||
else => {
|
||||
@ -3709,7 +3709,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
|
||||
ret_ty_body = zir.extra[extra_index..][0..body_len];
|
||||
extra_index += ret_ty_body.len;
|
||||
} else if (extra.data.bits.has_ret_ty_ref) {
|
||||
ret_ty_ref = @as(Inst.Ref, @enumFromInt(zir.extra[extra_index]));
|
||||
ret_ty_ref = @enumFromInt(zir.extra[extra_index]);
|
||||
extra_index += 1;
|
||||
}
|
||||
|
||||
@ -3753,7 +3753,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
|
||||
pub const ref_start_index: u32 = InternPool.static_len;
|
||||
|
||||
pub fn indexToRef(inst: Inst.Index) Inst.Ref {
|
||||
return @as(Inst.Ref, @enumFromInt(ref_start_index + inst));
|
||||
return @enumFromInt(ref_start_index + inst);
|
||||
}
|
||||
|
||||
pub fn refToIndex(inst: Inst.Ref) ?Inst.Index {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user