]> git.saurik.com Git - bison.git/blobdiff - data/variant.hh
m4: generate a basic_symbol constructor for each symbol type
[bison.git] / data / variant.hh
index 84ea7798b20700ad5a5a4edfdd2b6706fedce3a2..3b21329c01a2e0dcd5f43c0f87fd1e4197580b4f 100644 (file)
@@ -311,15 +311,43 @@ m4_define([b4_symbol_constructor_define_],
   b4_parser_class_name::make_[]b4_symbol_([$1], [id]) (dnl
 b4_join(b4_symbol_if([$1], [has_type],
                      [const b4_symbol([$1], [type])& v]),
-        b4_locations_if([const location_type& l])))[
+        b4_locations_if([const location_type& l])))
   {
-    symbol_type res (token::]b4_symbol([$1], [id])[]b4_locations_if([, l])[);
-    ]b4_symbol_if([$1], [has_type], [res.value.build (v);
-    ])[return res;
+    return symbol_type (b4_join([token::b4_symbol([$1], [id])],
+                                b4_symbol_if([$1], [has_type], [v]),
+                                b4_locations_if([l])));
+
   }
 
-]])])])
+])])])
+
 
+# b4_basic_symbol_constructor_declare
+# ----------------------------------
+# Generate a constructor declaration for basic_symbol from given type.
+m4_define([b4_basic_symbol_constructor_declare],
+[[
+  basic_symbol (]b4_join(
+          [typename Base::kind_type t],
+          b4_symbol_if([$1], [has_type], const b4_symbol([$1], [type])[ v]),
+          b4_locations_if([const location_type& l]))[);
+]])
+
+# b4_basic_symbol_constructor_define
+# ----------------------------------
+# Generate a constructor implementation for basic_symbol from given type.
+m4_define([b4_basic_symbol_constructor_define],
+[[
+  template <typename Base>
+  ]b4_parser_class_name[::basic_symbol<Base>::basic_symbol (]b4_join(
+          [typename Base::kind_type t],
+          b4_symbol_if([$1], [has_type], const b4_symbol([$1], [type])[ v]),
+          b4_locations_if([const location_type& l]))[)
+    : Base (t)
+    , value (]b4_symbol_if([$1], [has_type], [v])[)]b4_locations_if([
+    , location (l)])[
+  {}
+]])
 
 # b4_symbol_constructor_define
 # ----------------------------