authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-11-17 21:33:26+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-11-18 00:52:56+02:00
logbace1181b2f6d63e51b6e511aa8318481e2eafee
tree9b39b68f01cebd79808f051b6f6bc5e85491ca40
parentc1e19f4c0a62047c26d5baabe25887e533cc739f
signature Commit is signed but in an unrecognized format.

stage2: handle opaque containers


3 files changed, 50 insertions(+), 4 deletions(-)

src/Module.zig+1-1
......@@ -1515,7 +1515,6 @@ pub fn analyzeContainer(self: *Module, container_scope: *Scope.Container) !void
15151515 // an incremental update. This code handles both cases.
15161516 const tree = try self.getAstTree(container_scope);
15171517 const decls = tree.root_node.decls();
1518 // const decls = container_scope.root_node.decls();
15191518
15201519 try self.comp.work_queue.ensureUnusedCapacity(decls.len);
15211520 try container_scope.decls.ensureCapacity(self.gpa, decls.len);
......@@ -2302,6 +2301,7 @@ pub fn createContainerDecl(
23022301}
23032302
23042303fn getAnonTypeName(self: *Module, scope: *Scope, base_token: std.zig.ast.TokenIndex) ![]u8 {
2304 // TODO add namespaces, generic function signatrues
23052305 const tree = scope.tree();
23062306 const base_name = switch (tree.token_ids[base_token]) {
23072307 .Keyword_struct => "struct",
src/astgen.zig+13-1
......@@ -913,7 +913,19 @@ fn containerDecl(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node.Con
913913 };
914914 break :blk Type.initPayload(&union_type.base);
915915 },
916 .Keyword_opaque => return mod.fail(scope, src, "TODO opaque containers", .{}),
916 .Keyword_opaque => blk: {
917 if (fields.items.len > 0) {
918 return mod.fail(scope, fields.items[0].src, "opaque types cannot have fields", .{});
919 }
920 const opaque_type = try arena.create(Type.Payload.Opaque);
921 opaque_type.* = .{
922 .scope = .{
923 .file_scope = scope.getFileScope(),
924 .ty = Type.initPayload(&opaque_type.base),
925 },
926 };
927 break :blk Type.initPayload(&opaque_type.base);
928 },
917929 else => unreachable,
918930 };
919931 const type_payload = try arena.create(Value.Payload.Ty);
src/type.zig+36-2
......@@ -49,7 +49,7 @@ pub const Type = extern union {
4949 .f128,
5050 => return .Float,
5151
52 .c_void => return .Opaque,
52 .c_void, .@"opaque" => return .Opaque,
5353 .bool => return .Bool,
5454 .void => return .Void,
5555 .type => return .Type,
......@@ -449,6 +449,7 @@ pub const Type = extern union {
449449 .@"enum" => return self,
450450 .@"struct" => return self,
451451 .@"union" => return self,
452 .@"opaque" => return self,
452453 }
453454 }
454455
......@@ -680,10 +681,11 @@ pub const Type = extern union {
680681 const payload = @fieldParentPtr(Payload.ErrorSetSingle, "base", ty.ptr_otherwise);
681682 return out_stream.print("error{{{}}}", .{payload.name});
682683 },
683 // TODO improve
684 // TODO use declaration name
684685 .@"enum" => return out_stream.writeAll("enum {}"),
685686 .@"struct" => return out_stream.writeAll("struct {}"),
686687 .@"union" => return out_stream.writeAll("union {}"),
688 .@"opaque" => return out_stream.writeAll("opaque {}"),
687689 }
688690 unreachable;
689691 }
......@@ -809,6 +811,7 @@ pub const Type = extern union {
809811 .@"undefined",
810812 .enum_literal,
811813 .empty_struct,
814 .@"opaque",
812815 => false,
813816 };
814817 }
......@@ -937,6 +940,7 @@ pub const Type = extern union {
937940 .@"undefined",
938941 .enum_literal,
939942 .empty_struct,
943 .@"opaque",
940944 => unreachable,
941945 };
942946 }
......@@ -960,6 +964,7 @@ pub const Type = extern union {
960964 .enum_literal => unreachable,
961965 .single_const_pointer_to_comptime_int => unreachable,
962966 .empty_struct => unreachable,
967 .@"opaque" => unreachable,
963968
964969 .u8,
965970 .i8,
......@@ -1143,6 +1148,7 @@ pub const Type = extern union {
11431148 .@"enum",
11441149 .@"struct",
11451150 .@"union",
1151 .@"opaque",
11461152 => false,
11471153
11481154 .single_const_pointer,
......@@ -1221,6 +1227,7 @@ pub const Type = extern union {
12211227 .@"enum",
12221228 .@"struct",
12231229 .@"union",
1230 .@"opaque",
12241231 => false,
12251232
12261233 .const_slice,
......@@ -1296,6 +1303,7 @@ pub const Type = extern union {
12961303 .@"enum",
12971304 .@"struct",
12981305 .@"union",
1306 .@"opaque",
12991307 => false,
13001308
13011309 .single_const_pointer,
......@@ -1380,6 +1388,7 @@ pub const Type = extern union {
13801388 .@"enum",
13811389 .@"struct",
13821390 .@"union",
1391 .@"opaque",
13831392 => false,
13841393
13851394 .pointer => {
......@@ -1459,6 +1468,7 @@ pub const Type = extern union {
14591468 .@"enum",
14601469 .@"struct",
14611470 .@"union",
1471 .@"opaque",
14621472 => false,
14631473
14641474 .pointer => {
......@@ -1580,6 +1590,7 @@ pub const Type = extern union {
15801590 .@"enum",
15811591 .@"struct",
15821592 .@"union",
1593 .@"opaque",
15831594 => unreachable,
15841595
15851596 .array => self.cast(Payload.Array).?.elem_type,
......@@ -1711,6 +1722,7 @@ pub const Type = extern union {
17111722 .@"enum",
17121723 .@"struct",
17131724 .@"union",
1725 .@"opaque",
17141726 => unreachable,
17151727
17161728 .array => self.cast(Payload.Array).?.len,
......@@ -1780,6 +1792,7 @@ pub const Type = extern union {
17801792 .@"enum",
17811793 .@"struct",
17821794 .@"union",
1795 .@"opaque",
17831796 => unreachable,
17841797
17851798 .single_const_pointer,
......@@ -1866,6 +1879,7 @@ pub const Type = extern union {
18661879 .@"enum",
18671880 .@"struct",
18681881 .@"union",
1882 .@"opaque",
18691883 => false,
18701884
18711885 .int_signed,
......@@ -1944,6 +1958,7 @@ pub const Type = extern union {
19441958 .@"enum",
19451959 .@"struct",
19461960 .@"union",
1961 .@"opaque",
19471962 => false,
19481963
19491964 .int_unsigned,
......@@ -2012,6 +2027,7 @@ pub const Type = extern union {
20122027 .@"enum",
20132028 .@"struct",
20142029 .@"union",
2030 .@"opaque",
20152031 => unreachable,
20162032
20172033 .int_unsigned => .{ .signed = false, .bits = self.cast(Payload.IntUnsigned).?.bits },
......@@ -2098,6 +2114,7 @@ pub const Type = extern union {
20982114 .@"enum",
20992115 .@"struct",
21002116 .@"union",
2117 .@"opaque",
21012118 => false,
21022119
21032120 .usize,
......@@ -2213,6 +2230,7 @@ pub const Type = extern union {
22132230 .@"enum",
22142231 .@"struct",
22152232 .@"union",
2233 .@"opaque",
22162234 => unreachable,
22172235 };
22182236 }
......@@ -2294,6 +2312,7 @@ pub const Type = extern union {
22942312 .@"enum",
22952313 .@"struct",
22962314 .@"union",
2315 .@"opaque",
22972316 => unreachable,
22982317 }
22992318 }
......@@ -2374,6 +2393,7 @@ pub const Type = extern union {
23742393 .@"enum",
23752394 .@"struct",
23762395 .@"union",
2396 .@"opaque",
23772397 => unreachable,
23782398 }
23792399 }
......@@ -2454,6 +2474,7 @@ pub const Type = extern union {
24542474 .@"enum",
24552475 .@"struct",
24562476 .@"union",
2477 .@"opaque",
24572478 => unreachable,
24582479 };
24592480 }
......@@ -2531,6 +2552,7 @@ pub const Type = extern union {
25312552 .@"enum",
25322553 .@"struct",
25332554 .@"union",
2555 .@"opaque",
25342556 => unreachable,
25352557 };
25362558 }
......@@ -2608,6 +2630,7 @@ pub const Type = extern union {
26082630 .@"enum",
26092631 .@"struct",
26102632 .@"union",
2633 .@"opaque",
26112634 => unreachable,
26122635 };
26132636 }
......@@ -2685,6 +2708,7 @@ pub const Type = extern union {
26852708 .@"enum",
26862709 .@"struct",
26872710 .@"union",
2711 .@"opaque",
26882712 => false,
26892713 };
26902714 }
......@@ -2742,6 +2766,7 @@ pub const Type = extern union {
27422766 .error_union,
27432767 .error_set,
27442768 .error_set_single,
2769 .@"opaque",
27452770 => return null,
27462771
27472772 .@"enum" => @panic("TODO onePossibleValue enum"),
......@@ -2860,6 +2885,7 @@ pub const Type = extern union {
28602885 .@"enum",
28612886 .@"struct",
28622887 .@"union",
2888 .@"opaque",
28632889 => return false,
28642890
28652891 .c_const_pointer,
......@@ -2951,6 +2977,7 @@ pub const Type = extern union {
29512977 .@"enum" => &self.cast(Type.Payload.Enum).?.scope,
29522978 .@"struct" => &self.cast(Type.Payload.Struct).?.scope,
29532979 .@"union" => &self.cast(Type.Payload.Union).?.scope,
2980 .@"opaque" => &self.cast(Type.Payload.Union).?.scope,
29542981 };
29552982 }
29562983
......@@ -3105,6 +3132,7 @@ pub const Type = extern union {
31053132 @"enum",
31063133 @"struct",
31073134 @"union",
3135 @"opaque",
31083136
31093137 pub const last_no_payload_tag = Tag.const_slice_u8;
31103138 pub const no_payload_count = @enumToInt(last_no_payload_tag) + 1;
......@@ -3221,6 +3249,12 @@ pub const Type = extern union {
32213249 scope: *Module.Scope.Container,
32223250 };
32233251
3252 pub const Opaque = struct {
3253 base: Payload = .{ .tag = .@"opaque" },
3254
3255 scope: Module.Scope.Container,
3256 };
3257
32243258 pub const Enum = @import("type/Enum.zig");
32253259 pub const Struct = @import("type/Struct.zig");
32263260 pub const Union = @import("type/Union.zig");