This improves the "list" bench by 2%.
* data/lalr1.cc (variant::build): Add an overloaded version with
an argument.
* tests/c++.at (AT_CHECK_VARIANT): Check it.
+2008-11-10 Akim Demaille <demaille@gostai.com>
+
+ Support constructor with an argument.
+ This improves the "list" bench by 2%.
+
+ * data/lalr1.cc (variant::build): Add an overloaded version with
+ an argument.
+ * tests/c++.at (AT_CHECK_VARIANT): Check it.
+
2008-11-10 Akim Demaille <demaille@gostai.com>
Test variants.
2008-11-10 Akim Demaille <demaille@gostai.com>
Test variants.
return *new (buffer) T;
}
return *new (buffer) T;
}
+ /// Instantiate a \a T in here from \a t.
+ template <typename T>
+ inline T&
+ build(const T& t)
+ {]b4_assert_if([
+ assert(!built);
+ built = true;])[
+ return *new (buffer) T(t);
+ }
+
/// Accessor to a built \a T.
template <typename T>
inline T&
/// Accessor to a built \a T.
template <typename T>
inline T&
%skeleton "lalr1.cc"
%defines
%define variant
%skeleton "lalr1.cc"
%defines
%define variant
+]m4_bpatsubst([$1], [\\n], [
+])[
%code requires // code for the .hh file
{
%code requires // code for the .hh file
{
- list { std::cout << $][1; }
+ list { std::cout << $][1; }
- yylval->build<std::string>() = std::string("BEGIN");
+ case 4:
+#ifdef ONE_STAGE_BUILD
+ yylval->build(string_cast(stage));
+#else
+ yylval->build<std::string>() = string_cast(stage);
+#endif
result = yy::parser::token::TEXT;
break;
case 1:
case 2:
case 3:
result = yy::parser::token::TEXT;
break;
case 1:
case 2:
case 3:
+#ifdef ONE_STAGE_BUILD
+ yylval->build(stage);
+#else
yylval->build<int>() = stage;
yylval->build<int>() = stage;
result = yy::parser::token::NUMBER;
break;
result = yy::parser::token::NUMBER;
break;
- case 4:
- yylval->build<std::string>() = std::string("END");
- result = yy::parser::token::TEXT;
- break;
default:
result = yy::parser::token::END_OF_FILE;
break;
default:
result = yy::parser::token::END_OF_FILE;
break;
-// Mandatory error function
void
yy::parser::error(const yy::parser::location_type& yylloc,
const std::string& message)
void
yy::parser::error(const yy::parser::location_type& yylloc,
const std::string& message)
std::cerr << yylloc << ": " << message << std::endl;
}
std::cerr << yylloc << ": " << message << std::endl;
}
-int main(int argc, char *argv[])
+int
+main(int argc, char *argv[])
{
yy::parser p;
p.set_debug_level(!!getenv("YYDEBUG"));
{
yy::parser p;
p.set_debug_level(!!getenv("YYDEBUG"));
-AT_BISON_CHECK([-o list.cc list.yy], 0)
+AT_BISON_CHECK([-o list.cc list.yy])
AT_COMPILE_CXX([list])
AT_CHECK([./list], 0,
AT_COMPILE_CXX([list])
AT_CHECK([./list], 0,
AT_CHECK_VARIANTS([])
AT_CHECK_VARIANTS([%define assert])
AT_CHECK_VARIANTS([])
AT_CHECK_VARIANTS([%define assert])
+AT_CHECK_VARIANTS([[%define assert %code {\n#define ONE_STAGE_BUILD\n}]])
## ----------------------- ##
## ----------------------- ##