From: Akim Demaille Date: Thu, 7 Aug 2008 22:38:07 +0000 (+0200) Subject: Support constructor with an argument. X-Git-Tag: v2.7.90~1107 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/e5eb92e79462c0f3805c09885ae8a1fe86ee28c6 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. --- diff --git a/ChangeLog b/ChangeLog index d7921b14..cba6f7c1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-11-10 Akim Demaille + + 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 Test variants. diff --git a/data/lalr1.cc b/data/lalr1.cc index 5798edf6..5854390e 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -247,6 +247,16 @@ dnl FIXME: This is wrong, we want computed header guards. return *new (buffer) T; } + /// Instantiate a \a T in here from \a t. + template + 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 inline T& diff --git a/tests/c++.at b/tests/c++.at index d351d41b..fefeda37 100644 --- a/tests/c++.at +++ b/tests/c++.at @@ -33,6 +33,8 @@ AT_DATA([list.yy], %skeleton "lalr1.cc" %defines %define variant +]m4_bpatsubst([$1], [\\n], [ +])[ %code requires // code for the .hh file { @@ -87,7 +89,7 @@ typedef std::list strings_type; %% result: - list { std::cout << $][1; } + list { std::cout << $][1; } ; list: @@ -111,19 +113,24 @@ yylex(yy::parser::semantic_type* yylval) switch (stage) { case 0: - yylval->build() = std::string("BEGIN"); + case 4: +#ifdef ONE_STAGE_BUILD + yylval->build(string_cast(stage)); +#else + yylval->build() = string_cast(stage); +#endif result = yy::parser::token::TEXT; break; case 1: case 2: case 3: +#ifdef ONE_STAGE_BUILD + yylval->build(stage); +#else yylval->build() = stage; +#endif result = yy::parser::token::NUMBER; break; - case 4: - yylval->build() = std::string("END"); - result = yy::parser::token::TEXT; - break; default: result = yy::parser::token::END_OF_FILE; break; @@ -133,7 +140,6 @@ yylex(yy::parser::semantic_type* yylval) return result; } -// Mandatory error function void yy::parser::error(const yy::parser::location_type& yylloc, const std::string& message) @@ -141,7 +147,8 @@ yy::parser::error(const yy::parser::location_type& yylloc, 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")); @@ -149,14 +156,14 @@ int main(int argc, char *argv[]) } ]]) -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, -[BEGIN +[0 1 2 3 -END +4 ]) AT_CLEANUP @@ -164,6 +171,7 @@ AT_CLEANUP AT_CHECK_VARIANTS([]) AT_CHECK_VARIANTS([%define assert]) +AT_CHECK_VARIANTS([[%define assert %code {\n#define ONE_STAGE_BUILD\n}]]) ## ----------------------- ##