aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
diff options
context:
space:
mode:
authorjoachimschmidt557 <joachim.schmidt557@outlook.com>2021-07-09 20:43:19 +0800
committerjoachimschmidt557 <joachim.schmidt557@outlook.com>2021-08-04 09:33:12 +0200
commit16c11988587ad78cd47ec571e1120c052abd47ed (patch)
tree602ffc9c167b22dcab3e6523e3ffb47bc8148dee /src/Module.zig
parentfcdc5c6b3ccca5cc4e1c2353f280068d1c427153 (diff)
downloadzig-16c11988587ad78cd47ec571e1120c052abd47ed.tar.gz
zig-16c11988587ad78cd47ec571e1120c052abd47ed.zip
stage2 Sema: Resolve LazySrcLocs for bitwise and arithmetic exprs
Diffstat (limited to 'src/Module.zig')
-rw-r--r--src/Module.zig51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/Module.zig b/src/Module.zig
index 84b721369d..e007a3c8ae 100644
--- a/src/Module.zig
+++ b/src/Module.zig
@@ -4268,6 +4268,57 @@ pub const SwitchProngSrc = union(enum) {
}
};
+pub const PeerTypeCandidateSrc = union(enum) {
+ /// Do not print out error notes for candidate sources
+ none: void,
+ /// When we want to know the the src of candidate i, look up at
+ /// index i in this slice
+ override: []LazySrcLoc,
+ /// resolvePeerTypes originates from a @TypeOf(...) call
+ typeof_builtin_call_node_offset: i32,
+
+ pub fn resolve(
+ self: PeerTypeCandidateSrc,
+ gpa: *Allocator,
+ decl: *Decl,
+ candidates: usize,
+ candidate_i: usize,
+ ) ?LazySrcLoc {
+ @setCold(true);
+
+ switch (self) {
+ .none => {
+ return null;
+ },
+ .override => |candidate_srcs| {
+ return candidate_srcs[candidate_i];
+ },
+ .typeof_builtin_call_node_offset => |node_offset| {
+ if (candidates <= 2) {
+ switch (candidate_i) {
+ 0 => return LazySrcLoc{ .node_offset_builtin_call_arg0 = node_offset },
+ 1 => return LazySrcLoc{ .node_offset_builtin_call_arg1 = node_offset },
+ else => unreachable,
+ }
+ }
+
+ const tree = decl.namespace.file_scope.getTree(gpa) catch |err| {
+ // In this case we emit a warning + a less precise source location.
+ log.warn("unable to load {s}: {s}", .{
+ decl.namespace.file_scope.sub_file_path, @errorName(err),
+ });
+ return LazySrcLoc{ .node_offset = 0 };
+ };
+ const node = decl.relativeToNodeIndex(node_offset);
+ const node_datas = tree.nodes.items(.data);
+ const params = tree.extra_data[node_datas[node].lhs..node_datas[node].rhs];
+
+ return LazySrcLoc{ .node_abs = params[candidate_i] };
+ },
+ }
+ }
+};
+
pub fn analyzeStructFields(mod: *Module, struct_obj: *Struct) CompileError!void {
const tracy = trace(@src());
defer tracy.end();