[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Support for methods in union types
From: |
Jose E. Marchesi |
Subject: |
Support for methods in union types |
Date: |
Wed, 26 Aug 2020 17:24:00 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Hi peoples!
Just a FYI. This morning I pushed support for having methods in union
types.
Methods are particularly useful in unions, for both pretty-printing and
getters/setters.
Example:
deftype Dwarf_Initial_Length =
union
{
struct
{
uint<32> marker : (marker == 0xffffffff
&& dwarf_set_bits (64));
offset<uint<64>,B> length;
} l64;
offset<uint<32>,B> l32 : (l32 < 0xfffffff0#B
&& dwarf_set_bits (32));
method get_value = offset<uint<64>,B>:
{
try return l32;
catch if E_elem { return l64.length; }
}
method _print = void:
{
print ("#<");
try printf ("%v", l64.length);
catch if E_elem { printf ("%v", l32); }
print (">");
}
};
[...]
/* Compilation unit header. */
deftype Dwarf_CU_Header =
struct
{
/* Length of the .debug_info contribution for this CU, not
including the length field itself. */
Dwarf_Initial_Length unit_length;
/* Version of the DWARF information for the compilation unit. */
uint<16> version : (version in [2, 3, 4, 5]
&& dwarf_set_version (version));
/* Offset into the .debug_abbrev section that associates the
compilation unit with a particular set of debugging information
entry abbreviations. */
Dwarf_Section_Offset debug_abbrev_offset;
/* Size of an address on the target architecture. */
offset<uint<8>,B> address_size;
};
Session:
(poke) .file foo.o
[elf](poke) $elf::debug_info
Dwarf_CU_Header {
unit_length=#<0x4bU#B>,
version=0x4UH,
debug_abbrev_offset=#<0x0U#B>,
address_size=0x8UB#B
}
[elf](poke) $elf::debug_info.unit_length.get_value
0x4bUL#B
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Support for methods in union types,
Jose E. Marchesi <=