mirror of
https://github.com/ziglang/zig.git
synced 2026-02-17 23:10:09 +00:00
Merge pull request #6048 from pixelherodev/cleanup
Some minor cleanup and error handling
This commit is contained in:
commit
6b141620a6
@ -1580,6 +1580,8 @@ fn analyzeRootSrcFile(self: *Module, root_scope: *Scope.File) !void {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
std.debug.panic("TODO: analyzeRootSrcFile {}", .{src_decl.tag});
|
||||
}
|
||||
// TODO also look for global variable declarations
|
||||
// TODO also look for comptime blocks and exported globals
|
||||
|
||||
@ -335,76 +335,49 @@ fn varDecl(
|
||||
// Depending on the type of AST the initialization expression is, we may need an lvalue
|
||||
// or an rvalue as a result location. If it is an rvalue, we can use the instruction as
|
||||
// the variable, no memory location needed.
|
||||
if (nodeMayNeedMemoryLocation(init_node)) {
|
||||
const result_loc = if (nodeMayNeedMemoryLocation(init_node)) r: {
|
||||
if (node.getTrailer("type_node")) |type_node| {
|
||||
const type_inst = try typeExpr(mod, scope, type_node);
|
||||
const alloc = try addZIRUnOp(mod, scope, name_src, .alloc, type_inst);
|
||||
const result_loc: ResultLoc = .{ .ptr = alloc };
|
||||
const init_inst = try expr(mod, scope, result_loc, init_node);
|
||||
const sub_scope = try block_arena.create(Scope.LocalVal);
|
||||
sub_scope.* = .{
|
||||
.parent = scope,
|
||||
.gen_zir = scope.getGenZIR(),
|
||||
.name = ident_name,
|
||||
.inst = init_inst,
|
||||
};
|
||||
return &sub_scope.base;
|
||||
break :r ResultLoc{ .ptr = alloc };
|
||||
} else {
|
||||
const alloc = try addZIRNoOpT(mod, scope, name_src, .alloc_inferred);
|
||||
const result_loc: ResultLoc = .{ .inferred_ptr = alloc };
|
||||
const init_inst = try expr(mod, scope, result_loc, init_node);
|
||||
const sub_scope = try block_arena.create(Scope.LocalVal);
|
||||
sub_scope.* = .{
|
||||
.parent = scope,
|
||||
.gen_zir = scope.getGenZIR(),
|
||||
.name = ident_name,
|
||||
.inst = init_inst,
|
||||
};
|
||||
return &sub_scope.base;
|
||||
break :r ResultLoc{ .inferred_ptr = alloc };
|
||||
}
|
||||
} else {
|
||||
const result_loc: ResultLoc = if (node.getTrailer("type_node")) |type_node|
|
||||
.{ .ty = try typeExpr(mod, scope, type_node) }
|
||||
} else r: {
|
||||
if (node.getTrailer("type_node")) |type_node|
|
||||
break :r ResultLoc{ .ty = try typeExpr(mod, scope, type_node) }
|
||||
else
|
||||
.none;
|
||||
const init_inst = try expr(mod, scope, result_loc, init_node);
|
||||
const sub_scope = try block_arena.create(Scope.LocalVal);
|
||||
sub_scope.* = .{
|
||||
.parent = scope,
|
||||
.gen_zir = scope.getGenZIR(),
|
||||
.name = ident_name,
|
||||
.inst = init_inst,
|
||||
};
|
||||
return &sub_scope.base;
|
||||
}
|
||||
break :r .none;
|
||||
};
|
||||
const init_inst = try expr(mod, scope, result_loc, init_node);
|
||||
const sub_scope = try block_arena.create(Scope.LocalVal);
|
||||
sub_scope.* = .{
|
||||
.parent = scope,
|
||||
.gen_zir = scope.getGenZIR(),
|
||||
.name = ident_name,
|
||||
.inst = init_inst,
|
||||
};
|
||||
return &sub_scope.base;
|
||||
},
|
||||
.Keyword_var => {
|
||||
if (node.getTrailer("type_node")) |type_node| {
|
||||
const var_data: struct { result_loc: ResultLoc, alloc: *zir.Inst } = if (node.getTrailer("type_node")) |type_node| a: {
|
||||
const type_inst = try typeExpr(mod, scope, type_node);
|
||||
const alloc = try addZIRUnOp(mod, scope, name_src, .alloc, type_inst);
|
||||
const result_loc: ResultLoc = .{ .ptr = alloc };
|
||||
const init_inst = try expr(mod, scope, result_loc, init_node);
|
||||
const sub_scope = try block_arena.create(Scope.LocalPtr);
|
||||
sub_scope.* = .{
|
||||
.parent = scope,
|
||||
.gen_zir = scope.getGenZIR(),
|
||||
.name = ident_name,
|
||||
.ptr = alloc,
|
||||
};
|
||||
return &sub_scope.base;
|
||||
} else {
|
||||
break :a .{ .alloc = try addZIRUnOp(mod, scope, name_src, .alloc, type_inst), .result_loc = .{ .ptr = alloc } };
|
||||
} else a: {
|
||||
const alloc = try addZIRNoOp(mod, scope, name_src, .alloc_inferred);
|
||||
const result_loc = .{ .inferred_ptr = alloc.castTag(.alloc_inferred).? };
|
||||
const init_inst = try expr(mod, scope, result_loc, init_node);
|
||||
const sub_scope = try block_arena.create(Scope.LocalPtr);
|
||||
sub_scope.* = .{
|
||||
.parent = scope,
|
||||
.gen_zir = scope.getGenZIR(),
|
||||
.name = ident_name,
|
||||
.ptr = alloc,
|
||||
};
|
||||
return &sub_scope.base;
|
||||
}
|
||||
break :a .{ .alloc = alloc, .result_loc = .{ .inferred_ptr = alloc.castTag(.alloc_inferred).? } };
|
||||
};
|
||||
const init_inst = try expr(mod, scope, var_data.result_loc, init_node);
|
||||
const sub_scope = try block_arena.create(Scope.LocalPtr);
|
||||
sub_scope.* = .{
|
||||
.parent = scope,
|
||||
.gen_zir = scope.getGenZIR(),
|
||||
.name = ident_name,
|
||||
.ptr = var_data.alloc,
|
||||
};
|
||||
return &sub_scope.base;
|
||||
},
|
||||
else => unreachable,
|
||||
}
|
||||
|
||||
@ -11,8 +11,8 @@ const C = link.File.C;
|
||||
const Decl = Module.Decl;
|
||||
const mem = std.mem;
|
||||
|
||||
/// Maps a name from Zig source to C. This will always give the same output for
|
||||
/// any given input.
|
||||
/// Maps a name from Zig source to C. Currently, this will always give the same
|
||||
/// output for any given input, sometimes resulting in broken identifiers.
|
||||
fn map(allocator: *std.mem.Allocator, name: []const u8) ![]const u8 {
|
||||
return allocator.dupe(u8, name);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user