gecko-dev/xpcom/idl-parser/xpidl
Nika Layzell 04547a4a00 Bug 1444745 - Part 4: Rewrite xptinfo, and write a new xptcodegen.py to generate the required datastructures, r=mccr8
This patch contains the meat of the changes here. The following summarize the changes:
1. xptinfo.h is rewritten to expose the new interface for reading the XPT data,

The nsXPTInterfaceInfo object exposes methods with the same signatures as
the methods on nsIInterfaceInfo, to make converting code which used
nsIInterfaceInfo as easy as possible, even when those methods don't have
signatures which make a ton of sense anymore. There are also a few methods
which are unnecessary (they return `true` or similar), which should be
removed over time.

Members of the data structures are made private in order to prevent reading
them directly. Code should instead call the getter methods. This should make
it easier to change their memory representation in the future. Constructing
these structs is made possible by making the structs `friend class` with the
XPTConstruct class, which is implemented by the code generator, and is able
to access the private fields.

In addition, rather than using integers with flag constants, I opted for
using C++ bitfields to store individual flags, as I found it made it easier
to both write the code generator, and reason about the layouts of the types.

I was able to shave a byte off of each nsXPTParamInfo (4 bytes -> 3 bytes)
by shoving the flags into spare bits in the nsXPTType. Unfortunately there
was not enough room for the retval flag. Fortunately, we already depend in
our code on the retval parameter being the last parameter, so I worked
around this by removing the retval flag and instead having a `hasretval`
flag on the method itself.

2. An xptinfo.cpp file is added for out-of-line definitions of more complex
methods, and the internal implementation details of the perfect hash.

Notable is the handling of xptshim interfaces. As the type is uniform, a
flag is checked when trying to read constant information, and a different
table with pointers into webidl data structures is checked when the type is
determined to be a shim.

Ideally we could remove this once we remove the remaining consumers of the
existing shim interfaces.

3. A python code generator which takes in the json XPT files generated in the
previous part, and emits a xptdata.cpp file with the data structures. I did
my best to heavily comment the code.

This code uses the friend class trick to construct the private fields of the
structs, and avoid a dependency on the ordering of fields in xptinfo.h.

The sInterfaces array's order is determined by a generated perfect hash
which is also written into the binary. This should allow for fast lookups by
IID or name of interfaces in memory. The hash function used for the perfect
hash is a simple FNV hash, as they're pretty fast.

For perfect hashing of names, another table is created which contains
indexes into the sInterfaces table. Lookup by name is less common, and this
form of lookup should still be very fast.

4. The necessary Makefiles are updated to use the new code generator, and
generate the file correctly.
2018-04-17 19:20:55 -04:00
..
__init__.py
header.py Bug 1387803 - Remove the [deprecated] annotation from XPIDL. r=froydnj 2017-08-06 14:25:57 +09:00
jsonxpt.py Bug 1444745 - Part 4: Rewrite xptinfo, and write a new xptcodegen.py to generate the required datastructures, r=mccr8 2018-04-17 19:20:55 -04:00
moz.build
python.ini
runtests.py Bug 1339178 - Use pytest to run python-tests, r=davehunt 2017-08-29 14:50:33 -04:00
rust_macros.py Bug 1293362 - Part 5: Allow implementing xpcom interfaces from rust code with a custom derive, r=froydnj 2018-01-23 17:27:28 -05:00
rust.py Bug 1293362 - Part 4: Generate runtime bindings for calling xpcom methods from rust, r=froydnj 2018-01-23 17:27:26 -05:00
xpidl.py Bug 1444745 - Part 4: Rewrite xptinfo, and write a new xptcodegen.py to generate the required datastructures, r=mccr8 2018-04-17 19:20:55 -04:00