bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Use string_cast in the bench.


From: Akim Demaille
Subject: [PATCH] Use string_cast in the bench.
Date: Tue, 11 Nov 2008 14:42:42 -0000

        * etc/bench.pl.in (generate_grammar_list): Define and use
        string_cast.
---
 ChangeLog       |    6 ++++++
 etc/bench.pl.in |   24 +++++++++++++-----------
 2 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 41c2490..4216d42 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2008-11-11  Akim Demaille  <address@hidden>
 
+       Use string_cast in the bench.
+       * etc/bench.pl.in (generate_grammar_list): Define and use
+       string_cast.
+
+2008-11-11  Akim Demaille  <address@hidden>
+
        Replace yychar with a Boolean.
        * data/lalr1.cc (parse::yychar): Replace by...
        (parse::yyempty): this.
diff --git a/etc/bench.pl.in b/etc/bench.pl.in
index 0e53629..1ee98b7 100755
--- a/etc/bench.pl.in
+++ b/etc/bench.pl.in
@@ -615,6 +615,17 @@ static yy::parser::token_type 
yylex(yy::parser::semantic_type* yylval);
 #else
 # define IF_ONE_STAGE_BUILD(True, False) False
 #endif
+
+  // Conversion to string.
+  template <typename T>
+    inline
+    std::string
+    string_cast (const T& t)
+  {
+    std::ostringstream o;
+    o << t;
+    return o.str ();
+  }
 }
 EOF
 
@@ -636,11 +647,7 @@ result:
 text:
   /* nothing */                { /* This will generate an empty string */ }
 | text TEXT            { std::swap ($$, $2); }
-| text NUMBER          {
-                         std::ostringstream ss;
-                         ss << ' ' << $2;
-                         $$ = ss.str();
-                        }
+| text NUMBER          { $$ = string_cast($2); }
 ;
 EOF
     }
@@ -664,12 +671,7 @@ result:
 text:
   /* nothing */                { $$ = new std::string; }
 | text TEXT            { delete $1; $$ = $2; }
-| text NUMBER          {
-                          delete $1;
-                          std::ostringstream ss;
-                         ss << ' ' << $2;
-                         $$ = new std::string (ss.str());
-                        }
+| text NUMBER          { delete $1; $$ = new std::string (string_cast ($2)); }
 ;
 EOF
     }
-- 
1.6.0.2.588.g3102





reply via email to

[Prev in Thread] Current Thread [Next in Thread]