Overcoming AST forward declaration (includes online example)

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

Overcoming AST forward declaration (includes online example)

Boost - Users mailing list
Hello,

Please find the example posted here:

http://wandbox.org/permlink/NI2Luvrw1HF7lF1E

The couple of concerns I have in question at the moment are:

* How to best handle variants throughout the grammar. Can I use
std::variant? Do I need to use boost::variant? Are there additional
Spirit features that make this doable?

* Embedded in that question is what to do with "nil" or "empty
statements" which occurs throughout the grammar at times. I wondered
if "empty statement" could synthesize "nothing", literally, not
contribute to a variant alternative, for instance. Other AST examples
seemed to inject a "struct nil {}" pattern, so I figured maybe this
was the better approach?

* The real kerfuffle for me at the moment is the AST forward
declaration. From what I gather in the protocol, this is an absolute
must have. It most occur before Group, and is also used by Message.

Thoughts? Suggestions?

And, please, before you suggest there are "proto compilers" already
available: yes, I know, I've been down that road. I am not looking to
parse the proto itself, per se, but rather do some code generation for
target language artifacts other than the proto itself.

Toward which end, I am also investigating a protoc compiler plugin
approach. But I figured, I'd pursue this as a  viable path to solving
the problem as well, notwithstanding the above challenges.

Thanks in advance!

Cheers,

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: Overcoming AST forward declaration (includes online example)

Boost - Users mailing list
On Fri, Nov 2, 2018 at 5:16 PM Michael Powell <[hidden email]> wrote:
>
> Hello,
>
> Please find the example posted here:
>
> http://wandbox.org/permlink/NI2Luvrw1HF7lF1E

A couple of obvious typos resolved, I think the main culprit(s) now
are the forward declaration concerns:

https://wandbox.org/permlink/tM6vQilplqDOL4v5

> The couple of concerns I have in question at the moment are:
>
> * How to best handle variants throughout the grammar. Can I use
> std::variant? Do I need to use boost::variant? Are there additional
> Spirit features that make this doable?
>
> * Embedded in that question is what to do with "nil" or "empty
> statements" which occurs throughout the grammar at times. I wondered
> if "empty statement" could synthesize "nothing", literally, not
> contribute to a variant alternative, for instance. Other AST examples
> seemed to inject a "struct nil {}" pattern, so I figured maybe this
> was the better approach?
>
> * The real kerfuffle for me at the moment is the AST forward
> declaration. From what I gather in the protocol, this is an absolute
> must have. It most occur before Group, and is also used by Message.
>
> Thoughts? Suggestions?
>
> And, please, before you suggest there are "proto compilers" already
> available: yes, I know, I've been down that road. I am not looking to
> parse the proto itself, per se, but rather do some code generation for
> target language artifacts other than the proto itself.
>
> Toward which end, I am also investigating a protoc compiler plugin
> approach. But I figured, I'd pursue this as a  viable path to solving
> the problem as well, notwithstanding the above challenges.
>
> Thanks in advance!
>
> Cheers,
>
> 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: Overcoming AST forward declaration (includes online example)

Boost - Users mailing list
On Fri, Nov 2, 2018 at 5:32 PM Michael Powell <[hidden email]> wrote:

>
> On Fri, Nov 2, 2018 at 5:16 PM Michael Powell <[hidden email]> wrote:
> >
> > Hello,
> >
> > Please find the example posted here:
> >
> > http://wandbox.org/permlink/NI2Luvrw1HF7lF1E
>
> A couple of obvious typos resolved, I think the main culprit(s) now
> are the forward declaration concerns:
>
> https://wandbox.org/permlink/tM6vQilplqDOL4v5

The forward declaration errors now the top most errors:

https://wandbox.org/permlink/WeRqkmDR93Wqu8BI

> > The couple of concerns I have in question at the moment are:
> >
> > * How to best handle variants throughout the grammar. Can I use
> > std::variant? Do I need to use boost::variant? Are there additional
> > Spirit features that make this doable?
> >
> > * Embedded in that question is what to do with "nil" or "empty
> > statements" which occurs throughout the grammar at times. I wondered
> > if "empty statement" could synthesize "nothing", literally, not
> > contribute to a variant alternative, for instance. Other AST examples
> > seemed to inject a "struct nil {}" pattern, so I figured maybe this
> > was the better approach?
> >
> > * The real kerfuffle for me at the moment is the AST forward
> > declaration. From what I gather in the protocol, this is an absolute
> > must have. It most occur before Group, and is also used by Message.
> >
> > Thoughts? Suggestions?
> >
> > And, please, before you suggest there are "proto compilers" already
> > available: yes, I know, I've been down that road. I am not looking to
> > parse the proto itself, per se, but rather do some code generation for
> > target language artifacts other than the proto itself.
> >
> > Toward which end, I am also investigating a protoc compiler plugin
> > approach. But I figured, I'd pursue this as a  viable path to solving
> > the problem as well, notwithstanding the above challenges.
> >
> > Thanks in advance!
> >
> > Cheers,
> >
> > 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: Overcoming AST forward declaration (includes online example)

Boost - Users mailing list
On 3/11/2018 11:34, Michael Powell wrote:
> The forward declaration errors now the top most errors:
>
> https://wandbox.org/permlink/WeRqkmDR93Wqu8BI

Fundamentally you have a cyclic recursion problem.

You're trying to declare that ast_msg_body_t contains by value a variant
which can contain a ast_group_t which can contain an ast_msg_body_t (and
similarly for the other possible variant types).

There is no possible way this could compile, as this requires the type
to be infinite size.

You will need to restructure things; in some cases you can rewrite
things to use lists, although that's probably not appropriate here.  In
this case you probably need to introduce an indirection and kick
something onto the heap rather than the stack.

For example, you could make the body members into unique_ptrs.  This
would also let you make the body type use inheritance-based polymorphism
rather than using a variant (which one is better depends on taste and on
intended usage).

(Also, while I'm not familiar with Spirit: there should be a way to make
it output actual int values rather than strings, unless you need to
preserve the input format.)
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Overcoming AST forward declaration (includes online example)

Boost - Users mailing list
On Mon, Nov 5, 2018 at 12:01 AM Gavin Lambert via Boost-users
<[hidden email]> wrote:
>
> On 3/11/2018 11:34, Michael Powell wrote:
> > The forward declaration errors now the top most errors:
> >
> > https://wandbox.org/permlink/WeRqkmDR93Wqu8BI
>
> Fundamentally you have a cyclic recursion problem.

You're telling me. ;-)

> You're trying to declare that ast_msg_body_t contains by value a variant
> which can contain a ast_group_t which can contain an ast_msg_body_t (and
> similarly for the other possible variant types).
>
> There is no possible way this could compile, as this requires the type
> to be infinite size.
>
> You will need to restructure things; in some cases you can rewrite
> things to use lists, although that's probably not appropriate here.  In
> this case you probably need to introduce an indirection and kick
> something onto the heap rather than the stack.
>
> For example, you could make the body members into unique_ptrs.  This
> would also let you make the body type use inheritance-based polymorphism
> rather than using a variant (which one is better depends on taste and on
> intended usage).

Effectively, "rewriting" the AST in strategic places is what I did. I
had some help, learned a couple of new tricks, and applications to a
couple of old tricks, circa C++11 bits, at any rate, so far as I can
determine.

http://stackoverflow.com/questions/53120135/how-to-overcome-a-boost-spirit-ast-snafu/

And with several follow up posts.

> (Also, while I'm not familiar with Spirit: there should be a way to make
> it output actual int values rather than strings, unless you need to
> preserve the input format.)
> _______________________________________________
> 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
|

Error: final keyword using boost serialization

Boost - Users mailing list
Hello
We have a little problem with the boost serialization. It's seems to have problem with the final keyword (at least in boost v1.55).
Is there any workaround for the example oder got it fixed already in the newest boost version?

class Test final
{
public:
   Test() {}
   Testtime_t t1) : m_t(t1) {}
 
protected:
   friend class boost::serialization::access;
   template<class Archive>
   void serializeArchive & arconst unsigned int version ) {
      ar & m_t;
   }
 
   time_t m_t = 12;
};

int mainint argc , char** argv ){
   Test t1(45);
   std::stringstream ofs;
   boost::archive::binary_oarchive oaofs );
   oa & t1;
}

 
--> compile error:
is_polymorphic.hpp(46) : error C3246: 'boost::detail::is_polymorphic_imp1<T>::d2' : cannot inherit from 'Test' as it has been declared as 'final'

remarks:
- the original class is a non polymorphic POD class that is declared a final. Like in th eexample!



Best regards
SirAnn

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