Possible Boost.Variant issue with JSON AST

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Possible Boost.Variant issue with JSON AST

Boost - Users mailing list
Hello,

I've got an AST I am developing to support JSON parsing using the
latest VC++ (15.9.5), however, I am having difficulty persuading the
compiler with my forward declarations.

i.e. 1>d:\dev\boost.org\boost_1_69_0\boost\mpl\sizeof.hpp(27): error
C2027: use of undefined type 'kingdom::json::object_t'

In terms of JSON AST modeling, the rub appears to be in a couple of
places: defining the JSON AST Array, and making the JSON AST Object
available to Value. Re: semantic terminology, Value is interchangeable
with Element, in view of the JSON grammar.

Here's my attempt at a flattened single source example:

https://wandbox.org/permlink/83c3VXZ4W1DHoEBc

I seem to recall there being future issues with C++ forward
declarations, but this seems to be like a bad language design decision
to restrict this, especially in light of this kind of approach.

I'm not sure how better to sort this out. At minimum, at least Value
needs a forward declaration depending on how I arrange my headers,
includes, etc. But then I still run into Value forward declaration
undefined type issues.

I'm not sure it's as much a language issue as much as it is possible a
Boost.Variant issue, per se.

Suggestions?

Thanks!

Michael Powell
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Possible Boost.Variant issue with JSON AST

Boost - Users mailing list
On 11/01/2019 07:36, Michael Powell wrote:
> Here's my attempt at a flattened single source example:
>
> https://wandbox.org/permlink/83c3VXZ4W1DHoEBc

The problems in that code are that you're using completely the wrong types.

In key_t, you're inheriting the base_type copy-constructor and
copy-assignment, and then creating new shadowing constructors and
assignment operators for the base_type (note: these are *not* a
copy-constructor nor copy-assignment operator for key_t itself!).

In numeric_t(const sign_type& other), you're getting compile errors
because you probably intended to use numeric_t instead of sign_type as
the parameter.
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Possible Boost.Variant issue with JSON AST

Boost - Users mailing list
On Thu, Jan 10, 2019 at 6:15 PM Gavin Lambert via Boost-users
<[hidden email]> wrote:
>
> On 11/01/2019 07:36, Michael Powell wrote:
> > Here's my attempt at a flattened single source example:
> >
> > https://wandbox.org/permlink/83c3VXZ4W1DHoEBc
>
> The problems in that code are that you're using completely the wrong types.

Fair observations. I've updated a bit, which I think is now tracking
with my local progress. Chiefly now, issues with "incompatible
skipper"?

https://wandbox.org/permlink/4spQR8yXweIcVfdB

Perhaps a repeated tuple issue of some sort? Otherwise, I'm not sure I
see what's going on there...

I'd also tried forward declared structs to capture Member, Object,
Array, etc, but this was running into Boost.Variant incomplete type
issues.

> In key_t, you're inheriting the base_type copy-constructor and
> copy-assignment, and then creating new shadowing constructors and
> assignment operators for the base_type (note: these are *not* a
> copy-constructor nor copy-assignment operator for key_t itself!).
>
> In numeric_t(const sign_type& other), you're getting compile errors
> because you probably intended to use numeric_t instead of sign_type as
> the parameter.
> _______________________________________________
> Boost-users mailing list
> [hidden email]
> https://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Possible Boost.Variant issue with JSON AST

Boost - Users mailing list
On Thu, Jan 10, 2019 at 6:36 PM Michael Powell <[hidden email]> wrote:

>
> On Thu, Jan 10, 2019 at 6:15 PM Gavin Lambert via Boost-users
> <[hidden email]> wrote:
> >
> > On 11/01/2019 07:36, Michael Powell wrote:
> > > Here's my attempt at a flattened single source example:
> > >
> > > https://wandbox.org/permlink/83c3VXZ4W1DHoEBc
> >
> > The problems in that code are that you're using completely the wrong types.
>
> Fair observations. I've updated a bit, which I think is now tracking
> with my local progress. Chiefly now, issues with "incompatible
> skipper"?
>
> https://wandbox.org/permlink/4spQR8yXweIcVfdB

I think I got it sorted pending testing, although I am unclear why a
couple of the rules skippers' should not be specified.

> Perhaps a repeated tuple issue of some sort? Otherwise, I'm not sure I
> see what's going on there...
>
> I'd also tried forward declared structs to capture Member, Object,
> Array, etc, but this was running into Boost.Variant incomplete type
> issues.
>
> > In key_t, you're inheriting the base_type copy-constructor and
> > copy-assignment, and then creating new shadowing constructors and
> > assignment operators for the base_type (note: these are *not* a
> > copy-constructor nor copy-assignment operator for key_t itself!).
> >
> > In numeric_t(const sign_type& other), you're getting compile errors
> > because you probably intended to use numeric_t instead of sign_type as
> > the parameter.
> > _______________________________________________
> > Boost-users mailing list
> > [hidden email]
> > https://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Possible Boost.Variant issue with JSON AST

Boost - Users mailing list
In reply to this post by Boost - Users mailing list
On 1/10/19 5:36 PM, Michael Powell via Boost-users wrote:

> On Thu, Jan 10, 2019 at 6:15 PM Gavin Lambert via Boost-users
> <[hidden email]> wrote:
>>
>> On 11/01/2019 07:36, Michael Powell wrote:
>>> Here's my attempt at a flattened single source example:
>>>
>>> https://wandbox.org/permlink/83c3VXZ4W1DHoEBc
>>
>> The problems in that code are that you're using completely the wrong types.
>
> Fair observations. I've updated a bit, which I think is now tracking
> with my local progress. Chiefly now, issues with "incompatible
> skipper"?
>
> https://wandbox.org/permlink/4spQR8yXweIcVfdB
>
> Perhaps a repeated tuple issue of some sort? Otherwise, I'm not sure I
> see what's going on there...
>
> I'd also tried forward declared structs to capture Member, Object,
> Array, etc, but this was running into Boost.Variant incomplete type
> issues.
>
Try altering what's forward declared:

         struct member_t;

         using members_t = std::vector<member_t>;

         // JSON_PARSER_OBJECT_HPP
         struct object_t {
             members_t members;
             object_t();
             object_t(const object_t& other);
             virtual ~object_t();
         };

         struct value_t
         : boost::variant
           < null_t, boolean_t, str_t
           , floating_point_number_t
           , integer_number_t, object_t, array_t
           >
           {...};

That way, since sizeof(vector<anything>) is known,  sizeof(object_t) is
known.

HTH.

-regards,
Larry



_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Possible Boost.Variant issue with JSON AST

Boost - Users mailing list
On Thu, Jan 10, 2019 at 10:17 PM Larry Evans via Boost-users
<[hidden email]> wrote:

>
> On 1/10/19 5:36 PM, Michael Powell via Boost-users wrote:
> > On Thu, Jan 10, 2019 at 6:15 PM Gavin Lambert via Boost-users
> > <[hidden email]> wrote:
> >>
> >> On 11/01/2019 07:36, Michael Powell wrote:
> >>> Here's my attempt at a flattened single source example:
> >>>
> >>> https://wandbox.org/permlink/83c3VXZ4W1DHoEBc
> >>
> >> The problems in that code are that you're using completely the wrong types.
> >
> > Fair observations. I've updated a bit, which I think is now tracking
> > with my local progress. Chiefly now, issues with "incompatible
> > skipper"?
> >
> > https://wandbox.org/permlink/4spQR8yXweIcVfdB
> >
> > Perhaps a repeated tuple issue of some sort? Otherwise, I'm not sure I
> > see what's going on there...
> >
> > I'd also tried forward declared structs to capture Member, Object,
> > Array, etc, but this was running into Boost.Variant incomplete type
> > issues.
> >
> Try altering what's forward declared:
>
>          struct member_t;
>
>          using members_t = std::vector<member_t>;
>
>          // JSON_PARSER_OBJECT_HPP
>          struct object_t {
>              members_t members;
>              object_t();
>              object_t(const object_t& other);
>              virtual ~object_t();
>          };
>
>          struct value_t
>          : boost::variant
>            < null_t, boolean_t, str_t
>            , floating_point_number_t
>            , integer_number_t, object_t, array_t
>            >
>            {...};
>
> That way, since sizeof(vector<anything>) is known,  sizeof(object_t) is
> known.
>
> HTH.

Thanks, Larry; in fact that's what I ended up doing. value_t is the
hinge upon which everything gets delivered. I defined my types there,
and once defined there, exposed them afterward.

i.e.

struct value_t : boost::variant<...> {
    using member_t = ...;
    using object_t = ...;
    using array_t = ...;
};

using member_t = value_t::member_t;
using object_t = value_t::object_t;
using array_t = value_t::array_t;

Then it is only a minor inconvenience that I use the long hand type in
the variant<...> list.

> -regards,
> Larry
>
>
>
> _______________________________________________
> Boost-users mailing list
> [hidden email]
> https://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users