dpp icon indicating copy to clipboard operation
dpp copied to clipboard

Dpp should generate UDAs for fields so D can check cpp memory layout

Open Laeeth opened this issue 5 years ago • 5 comments

(it's implemented in a first version on my branch)

Laeeth avatar Jan 02 '19 04:01 Laeeth

I don't understand the issue title.

atilaneves avatar Jan 03 '19 10:01 atilaneves

How do you know that the memory layout for a record is correct and will stay correct ? Only by having libclang check it's understanding of the facts with D.

Libclang can send D a little message. Hello, you might want to check you agree that the offset of and size of is what I think it is. That message is written with love on a uda. I said enum but meant uda as it will need some fields. See the link to integrate xenon and my fork which goes this already.

    struct OvernightRateConstraint
    {
    private:
        CurveConstraint __base;
        alias __base this;
            public:
        pragma(mangle, "_ZN5xenon11calibration23OvernightRateConstraintC1ESt10shared_ptrIKNS_11conventions14OvernightIndexEEN5boost9gregorian4dateES9_NS0_13MarketDatumIdEbb") this(shared_ptr!(OvernightIndex), BoostDate, BoostDate, MarketDatumId, bool, bool) @nogc nothrow;
        pragma(mangle, "_ZNK5xenon11calibration23OvernightRateConstraint14error_functionERKNS0_10MarketDataE") shared_ptr!(ConstraintError) error_function(ref const(MarketData)) @nogc nothrow const;
            protected:
        pragma(mangle, "_ZNK5xenon11calibration23OvernightRateConstraint14add_knots_implERSt15insert_iteratorISt3setIN5boost9gregorian4dateESt4lessIS6_ESaIS6_EEEb") void add_knots_impl(ref Opaque!("std.insert_iterator!(std.set!(boost.gregorian.date, std.less!(boost.gregorian.date), std.allocator!(boost.gregorian.date) ) )",FIXME), bool) @nogc nothrow const;
        pragma(mangle, "_ZNK5xenon11calibration23OvernightRateConstraint21add_dependencies_implERNS_5rates16RateDependenciesE") void add_dependencies_impl(ref RateDependencies) @nogc nothrow const;
            private:
        static struct Error
        {
        private:
            ConstraintError __base;
            alias __base this;
                public:
            pragma(mangle, "_ZN5xenon11calibration23OvernightRateConstraint5ErrorC1EOSt10shared_ptrIKNS_5rates15RateCalculationEEd") this(dpp.Move!(Opaque!("std.shared_ptr!(RateCalculation)",16)), double) @nogc nothrow;
            pragma(mangle, "_ZNK5xenon11calibration23OvernightRateConstraint5Error5errorERKNS_5rates13RatesProviderE") double error(ref const(RatesProvider)) @nogc nothrow const;
                private:
            @DppOffsetSize(8,16) Opaque!("std.shared_ptr!(RateCalculation)",16) rate_calculation_;
            @DppOffsetSize(24,8) double target_;
            @disable this();
        }

        @DppOffsetSize(16,16) shared_ptr!(OvernightIndex) index_;
        @DppOffsetSize(32,4) BoostDate start_;
        @DppOffsetSize(36,4) BoostDate end_;
        @DppOffsetSize(40,32) MarketDatumId quote_;
        @disable this();
    }

    struct RatesCurveCostFunction
    {
    private:
            public:
        pragma(mangle, "_ZN5xenon11calibration22RatesCurveCostFunctionC1ESt6vectorISt10shared_ptrIKNS0_15ConstraintErrorEESaIS6_EES3_IKNS_6curves5CurveEES2_ImSaImEE") this(vector!(ConstraintErrorPtr), shared_ptr!(Curve), vector!(size_t)) @nogc nothrow;
        pragma(mangle, "_ZN5xenon11calibration22RatesCurveCostFunction12update_curveEPKdRSt3mapINS_6curves7CurveIdESt10shared_ptrIKNS5_5CurveEESt4lessIS6_ESaISt4pairIKS6_SA_EEE") c_ulong update_curve(const(double)*, ref Opaque!("std.map!(CurveId, std.shared_ptr!(Curve), std.less!(CurveId), std.allocator!(std.pair!(CurveId, std.shared_ptr!(Curve) ) ) )",48)) @nogc nothrow;
        pragma(mangle, "_ZN5xenon11calibration22RatesCurveCostFunction12update_errorEPdRKNS_5rates13RatesProviderE") c_ulong update_error(double*, ref const(RatesProvider)) @nogc nothrow;
        pragma(mangle, "_ZNK5xenon11calibration22RatesCurveCostFunction12update_valueEPd") c_ulong update_value(double*) @nogc nothrow const;
        pragma(mangle, "_ZNK5xenon11calibration22RatesCurveCostFunction20constraint_dimensionEv") c_ulong constraint_dimension() @nogc nothrow const;
        pragma(mangle, "_ZNK5xenon11calibration22RatesCurveCostFunction16params_dimensionEv") c_ulong params_dimension() @nogc nothrow const;
            private:
        pragma(mangle, "_ZNK5xenon11calibration22RatesCurveCostFunction8y_valuesEv") ref const(Opaque!("std.vector!(double, std.allocator!(double) )",24)) y_values() @nogc nothrow const;
        @DppOffsetSize(0,24) Vector!(ConstraintErrorPtr) error_functions_;
        @DppOffsetSize(24,16) shared_ptr!(Curve) current_curve_;
        @DppOffsetSize(40,24) Vector!(size_t) fixed_params_;
        @disable this();
    }

Laeeth avatar Jan 03 '19 23:01 Laeeth

https://github.com/kaleidicforks/dpp/commit/c96fc6ec2607b718d45d52eee53303eb2f3eb237

For the tool. And also see code on fork. Grep for dppoffset

Laeeth avatar Jan 03 '19 23:01 Laeeth

https://github.com/atilaneves/dpp/pull/136

Laeeth avatar Jan 04 '19 00:01 Laeeth

See also #130

atilaneves avatar Jan 04 '19 08:01 atilaneves