| ... | @@ -192,8 +192,8 @@ fn prepopulateGlobalNameTable(c: *Context) !void { | ... | @@ -192,8 +192,8 @@ fn prepopulateGlobalNameTable(c: *Context) !void { |
| 192 | const node_types = c.tree.nodes.items(.ty); | 192 | const node_types = c.tree.nodes.items(.ty); |
| 193 | const node_data = c.tree.nodes.items(.data); | 193 | const node_data = c.tree.nodes.items(.data); |
| 194 | for (c.tree.root_decls) |node| { | 194 | for (c.tree.root_decls) |node| { |
| 195 | const data = node_data[@enumToInt(node)]; | 195 | const data = node_data[@intFromEnum(node)]; |
| 196 | const decl_name = switch (node_tags[@enumToInt(node)]) { | 196 | const decl_name = switch (node_tags[@intFromEnum(node)]) { |
| 197 | .typedef => @panic("TODO"), | 197 | .typedef => @panic("TODO"), |
| 198 | | 198 | |
| 199 | .static_assert, | 199 | .static_assert, |
| ... | @@ -202,7 +202,7 @@ fn prepopulateGlobalNameTable(c: *Context) !void { | ... | @@ -202,7 +202,7 @@ fn prepopulateGlobalNameTable(c: *Context) !void { |
| 202 | .struct_decl, | 202 | .struct_decl, |
| 203 | .union_decl, | 203 | .union_decl, |
| 204 | => blk: { | 204 | => blk: { |
| 205 | const ty = node_types[@enumToInt(node)]; | 205 | const ty = node_types[@intFromEnum(node)]; |
| 206 | const name_id = ty.data.record.name; | 206 | const name_id = ty.data.record.name; |
| 207 | break :blk c.mapper.lookup(name_id); | 207 | break :blk c.mapper.lookup(name_id); |
| 208 | }, | 208 | }, |
| ... | @@ -210,7 +210,7 @@ fn prepopulateGlobalNameTable(c: *Context) !void { | ... | @@ -210,7 +210,7 @@ fn prepopulateGlobalNameTable(c: *Context) !void { |
| 210 | .enum_decl_two, | 210 | .enum_decl_two, |
| 211 | .enum_decl, | 211 | .enum_decl, |
| 212 | => blk: { | 212 | => blk: { |
| 213 | const ty = node_types[@enumToInt(node)]; | 213 | const ty = node_types[@intFromEnum(node)]; |
| 214 | const name_id = ty.data.@"enum".name; | 214 | const name_id = ty.data.@"enum".name; |
| 215 | break :blk c.mapper.lookup(name_id); | 215 | break :blk c.mapper.lookup(name_id); |
| 216 | }, | 216 | }, |
| ... | @@ -240,8 +240,8 @@ fn transTopLevelDecls(c: *Context) !void { | ... | @@ -240,8 +240,8 @@ fn transTopLevelDecls(c: *Context) !void { |
| 240 | const node_tags = c.tree.nodes.items(.tag); | 240 | const node_tags = c.tree.nodes.items(.tag); |
| 241 | const node_data = c.tree.nodes.items(.data); | 241 | const node_data = c.tree.nodes.items(.data); |
| 242 | for (c.tree.root_decls) |node| { | 242 | for (c.tree.root_decls) |node| { |
| 243 | const data = node_data[@enumToInt(node)]; | 243 | const data = node_data[@intFromEnum(node)]; |
| 244 | switch (node_tags[@enumToInt(node)]) { | 244 | switch (node_tags[@intFromEnum(node)]) { |
| 245 | .typedef => { | 245 | .typedef => { |
| 246 | try transTypeDef(c, &c.global_scope.base, node); | 246 | try transTypeDef(c, &c.global_scope.base, node); |
| 247 | }, | 247 | }, |
| ... | @@ -255,16 +255,14 @@ fn transTopLevelDecls(c: *Context) !void { | ... | @@ -255,16 +255,14 @@ fn transTopLevelDecls(c: *Context) !void { |
| 255 | try transRecordDecl(c, &c.global_scope.base, node); | 255 | try transRecordDecl(c, &c.global_scope.base, node); |
| 256 | }, | 256 | }, |
| 257 | | 257 | |
| 258 | .enum_decl_two, | 258 | .enum_decl_two => { |
| 259 | => { | | |
| 260 | var fields = [2]NodeIndex{ data.bin.lhs, data.bin.rhs }; | 259 | var fields = [2]NodeIndex{ data.bin.lhs, data.bin.rhs }; |
| 261 | var field_count: u8 = 0; | 260 | var field_count: u8 = 0; |
| 262 | if (fields[0] != .none) field_count += 1; | 261 | if (fields[0] != .none) field_count += 1; |
| 263 | if (fields[1] != .none) field_count += 1; | 262 | if (fields[1] != .none) field_count += 1; |
| 264 | try transEnumDecl(c, &c.global_scope.base, node, fields[0..field_count]); | 263 | try transEnumDecl(c, &c.global_scope.base, node, fields[0..field_count]); |
| 265 | }, | 264 | }, |
| 266 | .enum_decl, | 265 | .enum_decl => { |
| 267 | => { | | |
| 268 | const fields = c.tree.data[data.range.start..data.range.end]; | 266 | const fields = c.tree.data[data.range.start..data.range.end]; |
| 269 | try transEnumDecl(c, &c.global_scope.base, node, fields); | 267 | try transEnumDecl(c, &c.global_scope.base, node, fields); |
| 270 | }, | 268 | }, |
| ... | @@ -309,9 +307,9 @@ fn transVarDecl(_: *Context, _: NodeIndex, _: ?usize) Error!void { | ... | @@ -309,9 +307,9 @@ fn transVarDecl(_: *Context, _: NodeIndex, _: ?usize) Error!void { |
| 309 | } | 307 | } |
| 310 | fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: NodeIndex, field_nodes: []const NodeIndex) Error!void { | 308 | fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: NodeIndex, field_nodes: []const NodeIndex) Error!void { |
| 311 | const node_types = c.tree.nodes.items(.ty); | 309 | const node_types = c.tree.nodes.items(.ty); |
| 312 | const ty = node_types[@enumToInt(enum_decl)]; | 310 | const ty = node_types[@intFromEnum(enum_decl)]; |
| 313 | const node_data = c.tree.nodes.items(.data); | 311 | const node_data = c.tree.nodes.items(.data); |
| 314 | if (c.decl_table.get(@ptrToInt(ty.data.@"enum"))) |_| | 312 | if (c.decl_table.get(@intFromPtr(ty.data.@"enum"))) |_| |
| 315 | return; // Avoid processing this decl twice | 313 | return; // Avoid processing this decl twice |
| 316 | const toplevel = scope.id == .root; | 314 | const toplevel = scope.id == .root; |
| 317 | const bs: *Scope.Block = if (!toplevel) try scope.findBlockScope(c) else undefined; | 315 | const bs: *Scope.Block = if (!toplevel) try scope.findBlockScope(c) else undefined; |
| ... | @@ -319,7 +317,7 @@ fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: NodeIndex, field_nodes: | ... | @@ -319,7 +317,7 @@ fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: NodeIndex, field_nodes: |
| 319 | var is_unnamed = false; | 317 | var is_unnamed = false; |
| 320 | var bare_name: []const u8 = c.mapper.lookup(ty.data.@"enum".name); | 318 | var bare_name: []const u8 = c.mapper.lookup(ty.data.@"enum".name); |
| 321 | var name = bare_name; | 319 | var name = bare_name; |
| 322 | if (c.unnamed_typedefs.get(@ptrToInt(ty.data.@"enum"))) |typedef_name| { | 320 | if (c.unnamed_typedefs.get(@intFromPtr(ty.data.@"enum"))) |typedef_name| { |
| 323 | bare_name = typedef_name; | 321 | bare_name = typedef_name; |
| 324 | name = typedef_name; | 322 | name = typedef_name; |
| 325 | } else { | 323 | } else { |
| ... | @@ -330,7 +328,7 @@ fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: NodeIndex, field_nodes: | ... | @@ -330,7 +328,7 @@ fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: NodeIndex, field_nodes: |
| 330 | name = try std.fmt.allocPrint(c.arena, "enum_{s}", .{bare_name}); | 328 | name = try std.fmt.allocPrint(c.arena, "enum_{s}", .{bare_name}); |
| 331 | } | 329 | } |
| 332 | if (!toplevel) name = try bs.makeMangledName(c, name); | 330 | if (!toplevel) name = try bs.makeMangledName(c, name); |
| 333 | try c.decl_table.putNoClobber(c.gpa, @ptrToInt(ty.data.@"enum"), name); | 331 | try c.decl_table.putNoClobber(c.gpa, @intFromPtr(ty.data.@"enum"), name); |
| 334 | | 332 | |
| 335 | const enum_type_node = if (!ty.data.@"enum".isIncomplete()) blk: { | 333 | const enum_type_node = if (!ty.data.@"enum".isIncomplete()) blk: { |
| 336 | for (ty.data.@"enum".fields, field_nodes) |field, field_node| { | 334 | for (ty.data.@"enum".fields, field_nodes) |field, field_node| { |
| ... | @@ -348,7 +346,7 @@ fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: NodeIndex, field_nodes: | ... | @@ -348,7 +346,7 @@ fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: NodeIndex, field_nodes: |
| 348 | .name = enum_val_name, | 346 | .name = enum_val_name, |
| 349 | .is_public = toplevel, | 347 | .is_public = toplevel, |
| 350 | .type = enum_const_type_node, | 348 | .type = enum_const_type_node, |
| 351 | .value = transExpr(c, node_data[@enumToInt(field_node)].decl.node, .used) catch @panic("TODO"), | 349 | .value = transExpr(c, node_data[@intFromEnum(field_node)].decl.node, .used) catch @panic("TODO"), |
| 352 | }); | 350 | }); |
| 353 | if (toplevel) | 351 | if (toplevel) |
| 354 | try addTopLevelDecl(c, enum_val_name, enum_const_def) | 352 | try addTopLevelDecl(c, enum_val_name, enum_const_def) |
| ... | @@ -365,14 +363,14 @@ fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: NodeIndex, field_nodes: | ... | @@ -365,14 +363,14 @@ fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: NodeIndex, field_nodes: |
| 365 | else => |e| return e, | 363 | else => |e| return e, |
| 366 | }; | 364 | }; |
| 367 | } else blk: { | 365 | } else blk: { |
| 368 | try c.opaque_demotes.put(c.gpa, @ptrToInt(ty.data.@"enum"), {}); | 366 | try c.opaque_demotes.put(c.gpa, @intFromPtr(ty.data.@"enum"), {}); |
| 369 | break :blk ZigTag.opaque_literal.init(); | 367 | break :blk ZigTag.opaque_literal.init(); |
| 370 | }; | 368 | }; |
| 371 | | 369 | |
| 372 | const is_pub = toplevel and !is_unnamed; | 370 | const is_pub = toplevel and !is_unnamed; |
| 373 | const payload = try c.arena.create(ast.Payload.SimpleVarDecl); | 371 | const payload = try c.arena.create(ast.Payload.SimpleVarDecl); |
| 374 | payload.* = .{ | 372 | payload.* = .{ |
| 375 | .base = .{ .tag = ([2]ZigTag{ .var_simple, .pub_var_simple })[@boolToInt(is_pub)] }, | 373 | .base = .{ .tag = ([2]ZigTag{ .var_simple, .pub_var_simple })[@intFromBool(is_pub)] }, |
| 376 | .data = .{ | 374 | .data = .{ |
| 377 | .init = enum_type_node, | 375 | .init = enum_type_node, |
| 378 | .name = name, | 376 | .name = name, |
| ... | @@ -427,7 +425,7 @@ fn transStmt(c: *Context, node: NodeIndex) TransError!void { | ... | @@ -427,7 +425,7 @@ fn transStmt(c: *Context, node: NodeIndex) TransError!void { |
| 427 | | 425 | |
| 428 | fn transExpr(c: *Context, node: NodeIndex, result_used: ResultUsed) TransError!ZigNode { | 426 | fn transExpr(c: *Context, node: NodeIndex, result_used: ResultUsed) TransError!ZigNode { |
| 429 | std.debug.assert(node != .none); | 427 | std.debug.assert(node != .none); |
| 430 | const ty = c.tree.nodes.items(.ty)[@enumToInt(node)]; | 428 | const ty = c.tree.nodes.items(.ty)[@intFromEnum(node)]; |
| 431 | if (c.tree.value_map.get(node)) |val| { | 429 | if (c.tree.value_map.get(node)) |val| { |
| 432 | // TODO handle other values | 430 | // TODO handle other values |
| 433 | const str = try std.fmt.allocPrint(c.arena, "{d}", .{val.data.int}); | 431 | const str = try std.fmt.allocPrint(c.arena, "{d}", .{val.data.int}); |
| ... | @@ -439,7 +437,7 @@ fn transExpr(c: *Context, node: NodeIndex, result_used: ResultUsed) TransError!Z | ... | @@ -439,7 +437,7 @@ fn transExpr(c: *Context, node: NodeIndex, result_used: ResultUsed) TransError!Z |
| 439 | return maybeSuppressResult(c, result_used, as_node); | 437 | return maybeSuppressResult(c, result_used, as_node); |
| 440 | } | 438 | } |
| 441 | const node_tags = c.tree.nodes.items(.tag); | 439 | const node_tags = c.tree.nodes.items(.tag); |
| 442 | switch (node_tags[@enumToInt(node)]) { | 440 | switch (node_tags[@intFromEnum(node)]) { |
| 443 | else => unreachable, // Not an expression. | 441 | else => unreachable, // Not an expression. |
| 444 | } | 442 | } |
| 445 | return .none; | 443 | return .none; |