Commit Graph

131 Commits

Author SHA1 Message Date
Omar Sandoval
8f46673649 Add member designator parser
A member designator is the second argument to the C offsetof() macro.
2018-05-13 00:41:20 -07:00
Omar Sandoval
b43e2094ff typename: split lexer out into a separate module
It will be used for parsing member designators next.
2018-05-13 00:40:28 -07:00
Omar Sandoval
3d5af98a90 type/typename: fix anonymous and incomplete type annotations 2018-05-12 15:43:58 -07:00
Omar Sandoval
90ca412a33 typeindex: fix mypy errors in drgn.program 2018-05-12 15:34:00 -07:00
Omar Sandoval
10cf1097b5 program: fix mypy errors regarding array rvalues
We don't support array rvalues, so just add some asserts.
2018-05-12 12:02:50 -07:00
Omar Sandoval
6e208005a2 typeindex: fix some more mypy errors 2018-05-12 11:51:20 -07:00
Omar Sandoval
f299bea98a type/typeindex: implement saner typing for EnumType
This is a big change that makes EnumType have a compatible integer type
member instead of copying the fields, which ends up touching a lot of
stuff but also fixing a bunch of static typing errors.
2018-05-11 23:57:52 -07:00
Omar Sandoval
333b782172 dwarf: fix some type errors
Not real bugs.
2018-05-11 22:33:09 -07:00
Omar Sandoval
80df521452 type: handle some type errors caused by optional members
I don't know why mypy suddenly started warning about these where it
didn't before, but they're real bugs.
2018-05-09 02:11:39 -07:00
Omar Sandoval
07bcded124 typename: fix some harmless type errors
These aren't actual bugs, but silence mypy anyways.
2018-05-09 01:55:42 -07:00
Omar Sandoval
0a089e6ac9 cli: add history and tab completion
rlcompleter won't complete getitem or any function calls, so that can be
improved upon, but this is already much better than nothing.
2018-05-09 01:52:21 -07:00
Omar Sandoval
35271231fe program: swap ProgramObject arguments
type, address, value makes more sense and looks more like C.
2018-05-07 22:48:00 -07:00
Omar Sandoval
15ea6e8d97 program: implement ProgramObject binary operators 2018-05-07 18:48:10 -07:00
Omar Sandoval
9560b913f3 typeindex: change Type.unqualified() to TypeIndex.operand_type()
Converting an lvalue to an operand has to do a little bit more than
remove qualifiers:

- Convert array types to pointer types
- Convert function types to pointer types
2018-05-06 21:29:59 -07:00
Omar Sandoval
987f9be6db type: add Type.is_arithmetic() and Type.is_integer()
This will be used for ProgramObject operators as a shortcut for
isinstance(type.real_type(), (ArithmeticType, BitFieldType).
2018-05-06 00:28:07 -07:00
Omar Sandoval
da83e0adb3 program: add ProgramObject tests 2018-05-03 23:26:43 -07:00
Omar Sandoval
bad1ab23b0 typeindex: add TypeIndex.array()
Similar to TypeIndex.pointer(), just constructs an array type.
2018-05-03 23:21:53 -07:00
Omar Sandoval
b921d884df program: add ProgramObject.address_of_()
Basically the "&" operator in C.
2018-05-03 23:21:23 -07:00
Omar Sandoval
38262f8d53 typeindex: add TypeIndex.pointer() 2018-05-03 22:34:35 -07:00
Omar Sandoval
18e5e8f9bf typeindex: move easy types into base TypeIndex class
Some types don't actually have to go through find_dwarf_type(), so they
can be handled in the common code. This allows us to add a MockTypeIndex
to the tests.
2018-05-03 20:38:00 -07:00
Omar Sandoval
9f325f5fdc typeindex: fix some type errors in literal_type() 2018-05-02 23:38:55 -07:00
Omar Sandoval
3cc11f3f5e typeindex: rename usual_arithmetic_conversions() to common_real_type()
It doesn't actually do the conversion, it just finds the common type.
While we're here, don't make the types unqualied; the caller should do
that.
2018-05-02 23:36:39 -07:00
Omar Sandoval
928048be97 tests: use mocked TypeIndex for type conversion tests
Instead of a real DwarfTypeIndex.
2018-05-02 23:19:05 -07:00
Omar Sandoval
4891a6341f typeindex: add method for getting type of literal
This will be used for ProgramObject operators where one operand is not a
ProgramObject.
2018-05-02 22:56:16 -07:00
Omar Sandoval
b060c9dcf7 typeindex: make sure we can find base types
The compiler might call a base type by any variation of its name (e.g.,
long or long int). Make sure we find it no matter what it chose.
2018-05-02 22:41:26 -07:00
Omar Sandoval
d7236962db type: fix BoolType.__repr__()
It shouldn't include self.signed.
2018-05-02 01:20:30 -07:00
Omar Sandoval
389f483dbb program: implement unary operators for ProgramObject 2018-05-01 23:52:02 -07:00
Omar Sandoval
eb32ef6756 program: pass TypeIndex to Program instead of callback 2018-05-01 23:42:25 -07:00
Omar Sandoval
e458348409 type: rename EnumType.compatible to compatible_name
More descriptive but not too verbose.
2018-05-01 21:07:38 -07:00
Omar Sandoval
90f6913242 program: convert value when creating rvalue
This is useful for a few cases:

- We should make sure that the value of an object is actually valid for
  its type
- When casting, the value should be converted to the new type where
  appropriate
- For the upcoming ProgramObject operators
2018-05-01 20:58:37 -07:00
Omar Sandoval
c3dbe939ad program: fix Program.object() type annotation
It can also be used to create rvalues, so make the address optional.
2018-05-01 20:56:50 -07:00
Omar Sandoval
812951c340 type: add Type.convert()
For converting a value to a valid value of that type (i.e., casting).
2018-05-01 20:49:49 -07:00
Omar Sandoval
68462da720 typeindex: add usual arithmetic conversions
The rules are really subtle and not completely specified, so hopefully
this covers all of the corner cases... This will be used for
ProgramObject operators.
2018-05-01 00:17:20 -07:00
Omar Sandoval
78a745588a type: add TypedefType.real_type()
Instead of open-coding it in ProgramObject.
2018-04-30 22:23:55 -07:00
Omar Sandoval
c49426359b type: add Type.unqualified()
Used to get the same type with no qualifiers.
2018-04-30 22:16:44 -07:00
Omar Sandoval
26d8e0f7e9 type: add compatible integer type to EnumType 2018-04-30 19:33:40 -07:00
Omar Sandoval
22ddd198ce type: rename BasicType to ArithmeticType
This is more descriptive and allows for future expansion to complex
types.
2018-04-30 19:11:52 -07:00
Omar Sandoval
da4ff78f36 type: make BoolType a subclass of IntType
_Bool is a standard unsigned integer type.
2018-04-30 19:05:24 -07:00
Omar Sandoval
cef86a18c0 Move from_dwarf_type{,_name}() logic to a class 2018-04-30 18:11:28 -07:00
Omar Sandoval
80d3058b17 type: canonicalize basic type names
Instead of using whatever the compiler emits, make sure we are
consistent with naming.
2018-04-30 00:01:18 -07:00
Omar Sandoval
e1673f9f29 typename: use a better canonical formatting for integer types
I.e., omit "int" for "short", "long", and "long long".
2018-04-29 23:56:31 -07:00
Omar Sandoval
8a7bf0edf7 program: implement ProgramObject.__iter__() 2018-04-28 23:18:49 -07:00
Omar Sandoval
41c74593b3 program: implement ProgramObject.__len__() 2018-04-28 23:12:53 -07:00
Omar Sandoval
322b35259b program: better error message for ProgramObject.__getattr__() on non-struct
Instead of propagating the "not a struct or union" from member_(),
provide the usual attribute error message.
2018-04-28 23:03:49 -07:00
Omar Sandoval
6ca83a3775 program: implement ProgramObject.__dir__() 2018-04-28 22:54:03 -07:00
Omar Sandoval
e38ddba9c6 type: fix pretty-print of array of structs
We need to handle indentation like we do with nested structs.
2018-04-28 22:42:01 -07:00
Omar Sandoval
650896b619 dwarfindex: fix variable shadowing warning 2018-04-15 23:32:53 -07:00
Omar Sandoval
bb22a8e417 Add more documentation 2018-04-15 23:21:57 -07:00
Omar Sandoval
0713c57217 Add version information 2018-04-15 15:30:54 -07:00
Omar Sandoval
a4768ba2a4 License under GPL-3.0 or later 2018-04-15 15:03:33 -07:00