diff options
| author | Jimmi Holst Christensen <jimmiholstchristensen@gmail.com> | 2018-11-13 05:08:37 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-11-13 05:08:37 -0800 |
| commit | 8139c5a516eaa217ed76acdf09496895451c5c5c (patch) | |
| tree | 89841cec818c5650471c7f2c11141013f8640bf7 /std/debug/index.zig | |
| parent | 67fbb0434f7104801c66e821b5057a8323e377df (diff) | |
| download | zig-8139c5a516eaa217ed76acdf09496895451c5c5c.tar.gz zig-8139c5a516eaa217ed76acdf09496895451c5c5c.zip | |
New Zig formal grammar (#1685)
Reverted #1628 and changed the grammar+parser of the language to not allow certain expr where types are expected
Diffstat (limited to 'std/debug/index.zig')
| -rw-r--r-- | std/debug/index.zig | 124 |
1 files changed, 62 insertions, 62 deletions
diff --git a/std/debug/index.zig b/std/debug/index.zig index a0d2f65339..c256932b24 100644 --- a/std/debug/index.zig +++ b/std/debug/index.zig @@ -21,7 +21,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, @@ -125,7 +125,7 @@ pub fn assert(ok: bool) void { /// TODO: add `==` operator for `error_union == error_set`, and then /// remove this function -pub fn assertError(value: var, expected_error: error) void { +pub fn assertError(value: var, expected_error: anyerror) void { if (value) { @panic("expected error"); } else |actual_error| { @@ -213,7 +213,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, }; @@ -222,7 +222,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; } @@ -377,7 +377,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, @@ -444,7 +444,7 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres } } -const TtyColor = enum.{ +const TtyColor = enum { Red, Green, Cyan, @@ -478,7 +478,7 @@ fn setTtyColor(tty_color: TtyColor) void { }, } } else { - const S = struct.{ + const S = struct { var attrs: windows.WORD = undefined; var init_attrs = false; }; @@ -685,7 +685,7 @@ fn printLineInfo( } // TODO use this -pub const OpenSelfDebugInfoError = error.{ +pub const OpenSelfDebugInfoError = error{ MissingDebugInfo, OutOfMemory, UnsupportedOperatingSystem, @@ -705,7 +705,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, @@ -715,7 +715,7 @@ fn openSelfDebugInfoWindows(allocator: *mem.Allocator) !DebugInfo { .age = undefined, }; - var di = DebugInfo.{ + var di = DebugInfo{ .coff = coff_obj, .pdb = undefined, .sect_contribs = undefined, @@ -747,7 +747,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, @@ -768,7 +768,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, }; @@ -816,7 +816,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, @@ -875,7 +875,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, @@ -962,7 +962,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, @@ -980,7 +980,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, @@ -995,7 +995,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, @@ -1034,7 +1034,7 @@ fn printLineFromFile(out_stream: var, line_info: LineInfo) !void { } } -const MachoSymbol = struct.{ +const MachoSymbol = struct { nlist: *macho.nlist_64, ofile: ?*macho.nlist_64, reloc: u64, @@ -1049,14 +1049,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, @@ -1072,13 +1072,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, @@ -1107,12 +1107,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, @@ -1122,25 +1122,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, @@ -1154,7 +1154,7 @@ const FormValue = union(enum).{ StrPtr: u64, }; -const Constant = struct.{ +const Constant = struct { payload: []u8, signed: bool, @@ -1165,12 +1165,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, }; @@ -1217,14 +1217,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, @@ -1235,7 +1235,7 @@ const LineInfo = struct.{ } }; -const LineNumberProgram = struct.{ +const LineNumberProgram = struct { address: usize, file: usize, line: isize, @@ -1257,7 +1257,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, @@ -1293,7 +1293,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, @@ -1337,7 +1337,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 { @@ -1346,8 +1346,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), }, @@ -1364,7 +1364,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 { @@ -1372,7 +1372,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, @@ -1381,7 +1381,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), @@ -1401,11 +1401,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), @@ -1416,11 +1416,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); @@ -1437,7 +1437,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, @@ -1449,7 +1449,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, }); @@ -1466,7 +1466,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), }); @@ -1487,14 +1487,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), }; @@ -1509,7 +1509,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, @@ -1600,7 +1600,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, @@ -1631,7 +1631,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, @@ -1773,7 +1773,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, @@ -1805,7 +1805,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, @@ -1922,7 +1922,7 @@ fn scanAllCompileUnits(st: *DebugInfo) !void { }, else => return error.InvalidDebugInfo, }; - break :x PcRange.{ + break :x PcRange{ .start = low_pc, .end = pc_end, }; @@ -1935,7 +1935,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, |
