Papierkorb / bindgen

Binding and wrapper generator for C/C++ libraries
GNU General Public License v3.0
179 stars 18 forks source link

Regression: maintain object key order of parser document JSON #88

Closed HertzDevil closed 4 years ago

HertzDevil commented 4 years ago

Follow-up to #84.

Some processors rely on the object key order of the JSON document generated by the Clang parser; most notably, the Crystal wrapper generators assume that every class appears before its subclasses, so that subclasses never inherit from undefined base classes. This class order is directly derived from the Clang parser. However, using std::map means the keys are always sorted in alphabetical order, so code like below breaks because A will be added to the JSON before B:

struct B { };
struct A : B { };
# cannot use `B` before it is defined
class A < B
end

class B
end

The simplest fix is to use a custom std::map-like container in the Document struct that keeps track of the key insertion order. This patch requires no changes on the Crystal side.