diff options
| author | Jimmi Holst Christensen <jimmiholstchristensen@gmail.com> | 2018-10-15 09:51:15 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-10-15 09:51:15 -0400 |
| commit | 378d3e44034e817093966ea42c2940d6a0482dd8 (patch) | |
| tree | fe5f454097e1627b1afc65aebfb815dd70a7576d /std/debug/index.zig | |
| parent | 822d4fa216ea8f598e4a9d53161800494f449a94 (diff) | |
| download | zig-378d3e44034e817093966ea42c2940d6a0482dd8.tar.gz zig-378d3e44034e817093966ea42c2940d6a0482dd8.zip | |
Solve the return type ambiguity (#1628)
Changed container and initializer syntax
* <container> { ... } -> <container> . { ... }
* <exrp> { ... } -> <expr> . { ...}
Diffstat (limited to 'std/debug/index.zig')
| -rw-r--r-- | std/debug/index.zig | 122 |
1 files changed, 61 insertions, 61 deletions
diff --git a/std/debug/index.zig b/std/debug/index.zig index edd47b0ab1..66da180802 100644 --- a/std/debug/index.zig +++ b/std/debug/index.zig @@ -20,7 +20,7 @@ pub const runtime_safety = switch (builtin.mode) { builtin.Mode.ReleaseFast, builtin.Mode.ReleaseSmall => false, }; -const Module = struct { +const Module = struct.{ mod_info: pdb.ModInfo, module_name: []u8, obj_file_name: []u8, @@ -210,7 +210,7 @@ pub fn writeCurrentStackTrace(out_stream: var, debug_info: *DebugInfo, tty_color builtin.Os.windows => return writeCurrentStackTraceWindows(out_stream, debug_info, tty_color, start_addr), else => {}, } - const AddressState = union(enum) { + const AddressState = union(enum).{ NotLookingForStartAddress, LookingForStartAddress: usize, }; @@ -219,7 +219,7 @@ pub fn writeCurrentStackTrace(out_stream: var, debug_info: *DebugInfo, tty_color // else AddressState.NotLookingForStartAddress; var addr_state: AddressState = undefined; if (start_addr) |addr| { - addr_state = AddressState{ .LookingForStartAddress = addr }; + addr_state = AddressState.{ .LookingForStartAddress = addr }; } else { addr_state = AddressState.NotLookingForStartAddress; } @@ -374,7 +374,7 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres const col_num_entry = @ptrCast(*pdb.ColumnNumberEntry, &subsect_info[line_index]); break :blk col_num_entry.StartColumn; } else 0; - break :subsections LineInfo{ + break :subsections LineInfo.{ .allocator = allocator, .file_name = source_file_name, .line = line, @@ -441,7 +441,7 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres } } -const TtyColor = enum { +const TtyColor = enum.{ Red, Green, Cyan, @@ -453,7 +453,7 @@ const TtyColor = enum { /// TODO this is a special case hack right now. clean it up and maybe make it part of std.fmt fn setTtyColor(tty_color: TtyColor) void { - const S = struct { + const S = struct.{ var attrs: windows.WORD = undefined; var init_attrs = false; }; @@ -659,7 +659,7 @@ fn printLineInfo( } // TODO use this -pub const OpenSelfDebugInfoError = error{ +pub const OpenSelfDebugInfoError = error.{ MissingDebugInfo, OutOfMemory, UnsupportedOperatingSystem, @@ -679,7 +679,7 @@ fn openSelfDebugInfoWindows(allocator: *mem.Allocator) !DebugInfo { defer self_file.close(); const coff_obj = try allocator.createOne(coff.Coff); - coff_obj.* = coff.Coff{ + coff_obj.* = coff.Coff.{ .in_file = self_file, .allocator = allocator, .coff_header = undefined, @@ -689,7 +689,7 @@ fn openSelfDebugInfoWindows(allocator: *mem.Allocator) !DebugInfo { .age = undefined, }; - var di = DebugInfo{ + var di = DebugInfo.{ .coff = coff_obj, .pdb = undefined, .sect_contribs = undefined, @@ -721,7 +721,7 @@ fn openSelfDebugInfoWindows(allocator: *mem.Allocator) !DebugInfo { const name_bytes = try allocator.alloc(u8, name_bytes_len); try pdb_stream.stream.readNoEof(name_bytes); - const HashTableHeader = packed struct { + const HashTableHeader = packed struct.{ Size: u32, Capacity: u32, @@ -742,7 +742,7 @@ fn openSelfDebugInfoWindows(allocator: *mem.Allocator) !DebugInfo { return error.InvalidDebugInfo; const deleted = try readSparseBitVector(&pdb_stream.stream, allocator); - const Bucket = struct { + const Bucket = struct.{ first: u32, second: u32, }; @@ -790,7 +790,7 @@ fn openSelfDebugInfoWindows(allocator: *mem.Allocator) !DebugInfo { this_record_len += march_forward_bytes; } - try modules.append(Module{ + try modules.append(Module.{ .mod_info = mod_info, .module_name = module_name, .obj_file_name = obj_file_name, @@ -849,7 +849,7 @@ fn readSparseBitVector(stream: var, allocator: *mem.Allocator) ![]usize { } fn openSelfDebugInfoLinux(allocator: *mem.Allocator) !DebugInfo { - var di = DebugInfo{ + var di = DebugInfo.{ .self_exe_file = undefined, .elf = undefined, .debug_info = undefined, @@ -936,7 +936,7 @@ fn openSelfDebugInfoMacOs(allocator: *mem.Allocator) !DebugInfo { if (sym.n_sect == 0) { last_len = sym.n_value; } else { - symbols_buf[symbol_index] = MachoSymbol{ + symbols_buf[symbol_index] = MachoSymbol.{ .nlist = sym, .ofile = ofile, .reloc = reloc, @@ -954,7 +954,7 @@ fn openSelfDebugInfoMacOs(allocator: *mem.Allocator) !DebugInfo { } } const sentinel = try allocator.createOne(macho.nlist_64); - sentinel.* = macho.nlist_64{ + sentinel.* = macho.nlist_64.{ .n_strx = 0, .n_type = 36, .n_sect = 0, @@ -969,7 +969,7 @@ fn openSelfDebugInfoMacOs(allocator: *mem.Allocator) !DebugInfo { // This sort is so that we can binary search later. std.sort.sort(MachoSymbol, symbols, MachoSymbol.addressLessThan); - return DebugInfo{ + return DebugInfo.{ .ofiles = DebugInfo.OFileTable.init(allocator), .symbols = symbols, .strings = strings, @@ -1008,7 +1008,7 @@ fn printLineFromFile(out_stream: var, line_info: *const LineInfo) !void { } } -const MachoSymbol = struct { +const MachoSymbol = struct.{ nlist: *macho.nlist_64, ofile: ?*macho.nlist_64, reloc: u64, @@ -1023,14 +1023,14 @@ const MachoSymbol = struct { } }; -const MachOFile = struct { +const MachOFile = struct.{ bytes: []align(@alignOf(macho.mach_header_64)) const u8, sect_debug_info: ?*const macho.section_64, sect_debug_line: ?*const macho.section_64, }; pub const DebugInfo = switch (builtin.os) { - builtin.Os.macosx => struct { + builtin.Os.macosx => struct.{ symbols: []const MachoSymbol, strings: []const u8, ofiles: OFileTable, @@ -1046,13 +1046,13 @@ pub const DebugInfo = switch (builtin.os) { return self.ofiles.allocator; } }, - builtin.Os.windows => struct { + builtin.Os.windows => struct.{ pdb: pdb.Pdb, coff: *coff.Coff, sect_contribs: []pdb.SectionContribEntry, modules: []Module, }, - builtin.Os.linux => struct { + builtin.Os.linux => struct.{ self_exe_file: os.File, elf: elf.Elf, debug_info: *elf.SectionHeader, @@ -1081,12 +1081,12 @@ pub const DebugInfo = switch (builtin.os) { else => @compileError("Unsupported OS"), }; -const PcRange = struct { +const PcRange = struct.{ start: u64, end: u64, }; -const CompileUnit = struct { +const CompileUnit = struct.{ version: u16, is_64: bool, die: *Die, @@ -1096,25 +1096,25 @@ const CompileUnit = struct { const AbbrevTable = ArrayList(AbbrevTableEntry); -const AbbrevTableHeader = struct { +const AbbrevTableHeader = struct.{ // offset from .debug_abbrev offset: u64, table: AbbrevTable, }; -const AbbrevTableEntry = struct { +const AbbrevTableEntry = struct.{ has_children: bool, abbrev_code: u64, tag_id: u64, attrs: ArrayList(AbbrevAttr), }; -const AbbrevAttr = struct { +const AbbrevAttr = struct.{ attr_id: u64, form_id: u64, }; -const FormValue = union(enum) { +const FormValue = union(enum).{ Address: u64, Block: []u8, Const: Constant, @@ -1128,7 +1128,7 @@ const FormValue = union(enum) { StrPtr: u64, }; -const Constant = struct { +const Constant = struct.{ payload: []u8, signed: bool, @@ -1139,12 +1139,12 @@ const Constant = struct { } }; -const Die = struct { +const Die = struct.{ tag_id: u64, has_children: bool, attrs: ArrayList(Attr), - const Attr = struct { + const Attr = struct.{ id: u64, value: FormValue, }; @@ -1191,14 +1191,14 @@ const Die = struct { } }; -const FileEntry = struct { +const FileEntry = struct.{ file_name: []const u8, dir_index: usize, mtime: usize, len_bytes: usize, }; -const LineInfo = struct { +const LineInfo = struct.{ line: usize, column: usize, file_name: []u8, @@ -1209,7 +1209,7 @@ const LineInfo = struct { } }; -const LineNumberProgram = struct { +const LineNumberProgram = struct.{ address: usize, file: usize, line: isize, @@ -1231,7 +1231,7 @@ const LineNumberProgram = struct { prev_end_sequence: bool, pub fn init(is_stmt: bool, include_dirs: []const []const u8, file_entries: *ArrayList(FileEntry), target_address: usize) LineNumberProgram { - return LineNumberProgram{ + return LineNumberProgram.{ .address = 0, .file = 1, .line = 1, @@ -1267,7 +1267,7 @@ const LineNumberProgram = struct { self.include_dirs[file_entry.dir_index]; const file_name = try os.path.join(self.file_entries.allocator, dir_name, file_entry.file_name); errdefer self.file_entries.allocator.free(file_name); - return LineInfo{ + return LineInfo.{ .line = if (self.prev_line >= 0) @intCast(usize, self.prev_line) else 0, .column = self.prev_column, .file_name = file_name, @@ -1311,7 +1311,7 @@ fn readAllocBytes(allocator: *mem.Allocator, in_stream: var, size: usize) ![]u8 fn parseFormValueBlockLen(allocator: *mem.Allocator, in_stream: var, size: usize) !FormValue { const buf = try readAllocBytes(allocator, in_stream, size); - return FormValue{ .Block = buf }; + return FormValue.{ .Block = buf }; } fn parseFormValueBlock(allocator: *mem.Allocator, in_stream: var, size: usize) !FormValue { @@ -1320,8 +1320,8 @@ fn parseFormValueBlock(allocator: *mem.Allocator, in_stream: var, size: usize) ! } fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: var, signed: bool, size: usize) !FormValue { - return FormValue{ - .Const = Constant{ + return FormValue.{ + .Const = Constant.{ .signed = signed, .payload = try readAllocBytes(allocator, in_stream, size), }, @@ -1338,7 +1338,7 @@ fn parseFormValueTargetAddrSize(in_stream: var) !u64 { fn parseFormValueRefLen(allocator: *mem.Allocator, in_stream: var, size: usize) !FormValue { const buf = try readAllocBytes(allocator, in_stream, size); - return FormValue{ .Ref = buf }; + return FormValue.{ .Ref = buf }; } fn parseFormValueRef(allocator: *mem.Allocator, in_stream: var, comptime T: type) !FormValue { @@ -1346,7 +1346,7 @@ fn parseFormValueRef(allocator: *mem.Allocator, in_stream: var, comptime T: type return parseFormValueRefLen(allocator, in_stream, block_len); } -const ParseFormValueError = error{ +const ParseFormValueError = error.{ EndOfStream, InvalidDebugInfo, EndOfFile, @@ -1355,7 +1355,7 @@ const ParseFormValueError = error{ fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, is_64: bool) ParseFormValueError!FormValue { return switch (form_id) { - DW.FORM_addr => FormValue{ .Address = try parseFormValueTargetAddrSize(in_stream) }, + DW.FORM_addr => FormValue.{ .Address = try parseFormValueTargetAddrSize(in_stream) }, DW.FORM_block1 => parseFormValueBlock(allocator, in_stream, 1), DW.FORM_block2 => parseFormValueBlock(allocator, in_stream, 2), DW.FORM_block4 => parseFormValueBlock(allocator, in_stream, 4), @@ -1375,11 +1375,11 @@ fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, is_64 DW.FORM_exprloc => { const size = try readULeb128(in_stream); const buf = try readAllocBytes(allocator, in_stream, size); - return FormValue{ .ExprLoc = buf }; + return FormValue.{ .ExprLoc = buf }; }, - DW.FORM_flag => FormValue{ .Flag = (try in_stream.readByte()) != 0 }, - DW.FORM_flag_present => FormValue{ .Flag = true }, - DW.FORM_sec_offset => FormValue{ .SecOffset = try parseFormValueDwarfOffsetSize(in_stream, is_64) }, + DW.FORM_flag => FormValue.{ .Flag = (try in_stream.readByte()) != 0 }, + DW.FORM_flag_present => FormValue.{ .Flag = true }, + DW.FORM_sec_offset => FormValue.{ .SecOffset = try parseFormValueDwarfOffsetSize(in_stream, is_64) }, DW.FORM_ref1 => parseFormValueRef(allocator, in_stream, u8), DW.FORM_ref2 => parseFormValueRef(allocator, in_stream, u16), @@ -1390,11 +1390,11 @@ fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, is_64 return parseFormValueRefLen(allocator, in_stream, ref_len); }, - DW.FORM_ref_addr => FormValue{ .RefAddr = try parseFormValueDwarfOffsetSize(in_stream, is_64) }, - DW.FORM_ref_sig8 => FormValue{ .RefSig8 = try in_stream.readIntLe(u64) }, + DW.FORM_ref_addr => FormValue.{ .RefAddr = try parseFormValueDwarfOffsetSize(in_stream, is_64) }, + DW.FORM_ref_sig8 => FormValue.{ .RefSig8 = try in_stream.readIntLe(u64) }, - DW.FORM_string => FormValue{ .String = try readStringRaw(allocator, in_stream) }, - DW.FORM_strp => FormValue{ .StrPtr = try parseFormValueDwarfOffsetSize(in_stream, is_64) }, + DW.FORM_string => FormValue.{ .String = try readStringRaw(allocator, in_stream) }, + DW.FORM_strp => FormValue.{ .StrPtr = try parseFormValueDwarfOffsetSize(in_stream, is_64) }, DW.FORM_indirect => { const child_form_id = try readULeb128(in_stream); return parseFormValue(allocator, in_stream, child_form_id, is_64); @@ -1411,7 +1411,7 @@ fn parseAbbrevTable(st: *DebugInfo) !AbbrevTable { while (true) { const abbrev_code = try readULeb128(in_stream); if (abbrev_code == 0) return result; - try result.append(AbbrevTableEntry{ + try result.append(AbbrevTableEntry.{ .abbrev_code = abbrev_code, .tag_id = try readULeb128(in_stream), .has_children = (try in_stream.readByte()) == DW.CHILDREN_yes, @@ -1423,7 +1423,7 @@ fn parseAbbrevTable(st: *DebugInfo) !AbbrevTable { const attr_id = try readULeb128(in_stream); const form_id = try readULeb128(in_stream); if (attr_id == 0 and form_id == 0) break; - try attrs.append(AbbrevAttr{ + try attrs.append(AbbrevAttr.{ .attr_id = attr_id, .form_id = form_id, }); @@ -1440,7 +1440,7 @@ fn getAbbrevTable(st: *DebugInfo, abbrev_offset: u64) !*const AbbrevTable { } } try st.self_exe_file.seekTo(st.debug_abbrev.offset + abbrev_offset); - try st.abbrev_table_list.append(AbbrevTableHeader{ + try st.abbrev_table_list.append(AbbrevTableHeader.{ .offset = abbrev_offset, .table = try parseAbbrevTable(st), }); @@ -1461,14 +1461,14 @@ fn parseDie(st: *DebugInfo, abbrev_table: *const AbbrevTable, is_64: bool) !Die const abbrev_code = try readULeb128(in_stream); const table_entry = getAbbrevTableEntry(abbrev_table, abbrev_code) orelse return error.InvalidDebugInfo; - var result = Die{ + var result = Die.{ .tag_id = table_entry.tag_id, .has_children = table_entry.has_children, .attrs = ArrayList(Die.Attr).init(st.allocator()), }; try result.attrs.resize(table_entry.attrs.len); for (table_entry.attrs.toSliceConst()) |attr, i| { - result.attrs.items[i] = Die.Attr{ + result.attrs.items[i] = Die.Attr.{ .id = attr.attr_id, .value = try parseFormValue(st.allocator(), in_stream, attr.form_id, is_64), }; @@ -1483,7 +1483,7 @@ fn getLineNumberInfoMacOs(di: *DebugInfo, symbol: MachoSymbol, target_address: u errdefer _ = di.ofiles.remove(ofile); const ofile_path = mem.toSliceConst(u8, di.strings.ptr + ofile.n_strx); - gop.kv.value = MachOFile{ + gop.kv.value = MachOFile.{ .bytes = try std.io.readFileAllocAligned(di.ofiles.allocator, ofile_path, @alignOf(macho.mach_header_64)), .sect_debug_info = null, .sect_debug_line = null, @@ -1574,7 +1574,7 @@ fn getLineNumberInfoMacOs(di: *DebugInfo, symbol: MachoSymbol, target_address: u const dir_index = try readULeb128Mem(&ptr); const mtime = try readULeb128Mem(&ptr); const len_bytes = try readULeb128Mem(&ptr); - try file_entries.append(FileEntry{ + try file_entries.append(FileEntry.{ .file_name = file_name, .dir_index = dir_index, .mtime = mtime, @@ -1605,7 +1605,7 @@ fn getLineNumberInfoMacOs(di: *DebugInfo, symbol: MachoSymbol, target_address: u const dir_index = try readULeb128Mem(&ptr); const mtime = try readULeb128Mem(&ptr); const len_bytes = try readULeb128Mem(&ptr); - try file_entries.append(FileEntry{ + try file_entries.append(FileEntry.{ .file_name = file_name, .dir_index = dir_index, .mtime = mtime, @@ -1747,7 +1747,7 @@ fn getLineNumberInfoLinux(di: *DebugInfo, compile_unit: *const CompileUnit, targ const dir_index = try readULeb128(in_stream); const mtime = try readULeb128(in_stream); const len_bytes = try readULeb128(in_stream); - try file_entries.append(FileEntry{ + try file_entries.append(FileEntry.{ .file_name = file_name, .dir_index = dir_index, .mtime = mtime, @@ -1779,7 +1779,7 @@ fn getLineNumberInfoLinux(di: *DebugInfo, compile_unit: *const CompileUnit, targ const dir_index = try readULeb128(in_stream); const mtime = try readULeb128(in_stream); const len_bytes = try readULeb128(in_stream); - try file_entries.append(FileEntry{ + try file_entries.append(FileEntry.{ .file_name = file_name, .dir_index = dir_index, .mtime = mtime, @@ -1896,7 +1896,7 @@ fn scanAllCompileUnits(st: *DebugInfo) !void { }, else => return error.InvalidDebugInfo, }; - break :x PcRange{ + break :x PcRange.{ .start = low_pc, .end = pc_end, }; @@ -1909,7 +1909,7 @@ fn scanAllCompileUnits(st: *DebugInfo) !void { } }; - try st.compile_unit_list.append(CompileUnit{ + try st.compile_unit_list.append(CompileUnit.{ .version = version, .is_64 = is_64, .pc_range = pc_range, |
