[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Support constructor with an argument.
From: |
Akim Demaille |
Subject: |
[PATCH] Support constructor with an argument. |
Date: |
Mon, 10 Nov 2008 10:08:12 -0000 |
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.
---
ChangeLog | 9 +++++++++
data/lalr1.cc | 10 ++++++++++
tests/c++.at | 30 +++++++++++++++++++-----------
3 files changed, 38 insertions(+), 11 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index d7921b1..cba6f7c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
2008-11-10 Akim Demaille <address@hidden>
+ 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 <address@hidden>
+
Test variants.
* tests/c++.at (AT_CHECK_VARIANTS): New.
Use it with and without %define assert.
diff --git a/data/lalr1.cc b/data/lalr1.cc
index 5798edf..5854390 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 <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&
diff --git a/tests/c++.at b/tests/c++.at
index d351d41..fefeda3 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<std::string> 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>() = 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:
+#ifdef ONE_STAGE_BUILD
+ yylval->build(stage);
+#else
yylval->build<int>() = stage;
+#endif
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;
@@ -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}]])
## ----------------------- ##
--
1.6.0.2.588.g3102
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] Support constructor with an argument.,
Akim Demaille <=