Re: How to adapt an AST involving forward declared meta data

Larry Evans <[email protected]> Fri, 2 Nov 2018 10:29:30 -0500
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <[email protected]>
On 11/1/18 9:05 AM, Michael Powell wrote:
> On Wed, Oct 31, 2018 at 10:15 PM Michael Powell <[email protected]> wrote:
>>
>> Hello,
>>
>> Like the subject says, I've got some structs in my AST that have to be
>> forward declared.
> 
> Okay, I've worked through the basic AST concepts I think I need for
> this problem. However, the VS2017 C2079 error is not going away, not
> without modifying the approach:
> 
> One possible way is to "introduce" pointers into the AST. Question
> along these lines, how good is Spirit Qi at working with AST,
> pointers, etc? Smart pointers preferred, I think, if possible.
> 
> struct bool_t {
>      std::string val;
> };
> 
> struct str_t {
>      std::string quoted_text;
> };
> 
> struct full_id_t {
>      std::string full_id;
> };
> 
> struct int_t {
>      std::string val;
> };
> 
> struct float_t {
>      std::string val;
> };
> 
IIRC, one problem with boost::variant and possible spirit::variant is 
the ambiguity when types or duplicated.  IOW:

   variant<T,T,T> v3t;

doesn't work because assignment:

   v3t = T{};

doesn't know which of the 3 T's is meant.  T, in your case, is 
std::string.  You've solved it by essentially repeated the
same value type (i.e. std::string) wrapped in a different class.

A possible simplification is:

enum types
{ bool_t
, str_t
, full_id_t
, int_t
, float_t
};

template<types Type>
struct value_t
{ std::string value_v
};

It would save a little typing.

-regards,
Larry