[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
c++: minor changes
From: |
Akim Demaille |
Subject: |
c++: minor changes |
Date: |
Mon, 22 Oct 2018 08:41:12 +0200 |
commit 4b0efdeb28ce5f35f46db161b57abf3b3a3b6e21
Author: Akim Demaille <address@hidden>
Date: Mon Oct 22 08:18:54 2018 +0200
c++: minor changes
* data/lalr1.cc: Fix oldish comment.
* data/stack.hh: Prefer typename for type names.
Use size() instead of duplicating it.
* examples/variant-11.yy, examples/variant.yy (yylex): Use int,
as this is the type of the semantic value.
diff --git a/TODO b/TODO
index 4836eb60..4e3258dc 100644
--- a/TODO
+++ b/TODO
@@ -1,4 +1,10 @@
* Short term
+** C++
+Move to int everywhere instead of unsigned? stack_size, etc. The parser
+itself uses int (for yylen for instance), yet stack is based on size_t.
+
+Maybe locations should also move to ints.
+
** Graphviz display code thoughts
The code for the --graph option is over two files: print_graph, and
graphviz. This is because Bison used to also produce VCG graphs, but since
diff --git a/data/lalr1.cc b/data/lalr1.cc
index 467a5fde..0f470994 100644
--- a/data/lalr1.cc
+++ b/data/lalr1.cc
@@ -359,7 +359,7 @@ m4_define([b4_shared_declarations],
/// \warning the contents of \a sym.value is stolen.
void yypush_ (const char* m, state_type s, YY_MOVE_REF (symbol_type) sym);
- /// Pop \a n symbols the three stacks.
+ /// Pop \a n symbols from the stack.
void yypop_ (unsigned n = 1);
/// Constants.
diff --git a/data/stack.hh b/data/stack.hh
index e04ca023..4f712159 100644
--- a/data/stack.hh
+++ b/data/stack.hh
@@ -27,7 +27,7 @@ b4_defines_if([b4_required_version_if([302], [],
# ---------------
m4_define([b4_stack_define],
[[ /// A stack with random access from its top.
- template <class T, class S = std::vector<T> >
+ template <typename T, typename S = std::vector<T> >
class stack
{
public:
@@ -46,7 +46,7 @@ m4_define([b4_stack_define],
T&
operator[] (size_type i)
{
- return seq_[seq_.size () - 1 - i];
+ return seq_[size () - 1 - i];
}
/// Random access.
@@ -55,7 +55,7 @@ m4_define([b4_stack_define],
const T&
operator[] (size_type i) const
{
- return seq_[seq_.size () - 1 - i];
+ return seq_[size () - 1 - i];
}
/// Steal the contents of \a t.
@@ -107,7 +107,7 @@ m4_define([b4_stack_define],
};
/// Present a slice of the top of a stack.
- template <class T, class S = stack<T> >
+ template <typename T, typename S = stack<T> >
class slice
{
public:
diff --git a/doc/bison.texi b/doc/bison.texi
index 00c59a37..aeca17a6 100644
--- a/doc/bison.texi
+++ b/doc/bison.texi
@@ -11723,7 +11723,7 @@ The rules are simple. The driver is used to report
errors.
if (! (INT_MIN <= n && n <= INT_MAX && errno != ERANGE))
throw yy::parser::syntax_error (loc, "integer is out of range: "
+ std::string(yytext));
- return yy::parser::make_NUMBER (n, loc);
+ return yy::parser::make_NUMBER (int (n), loc);
@}
@end group
@address@hidden return yy::parser::make_IDENTIFIER (yytext, loc);
diff --git a/examples/variant-11.yy b/examples/variant-11.yy
index ba01c6c4..64afd3ee 100644
--- a/examples/variant-11.yy
+++ b/examples/variant-11.yy
@@ -124,10 +124,10 @@ namespace yy
parser::symbol_type
yylex ()
{
- static auto count = 0u;
- const auto stage = count;
+ static int count = 0;
+ const int stage = count;
++count;
- auto loc = parser::location_type{nullptr, stage + 1, stage + 1};
+ auto loc = parser::location_type{nullptr, unsigned (stage + 1), unsigned
(stage + 1)};
if (stage == 0)
return parser::make_TEXT (make_string_uptr ("I have numbers for you."),
std::move (loc));
else if (stage < max)
diff --git a/examples/variant.yy b/examples/variant.yy
index 2938c50c..109eb53a 100644
--- a/examples/variant.yy
+++ b/examples/variant.yy
@@ -114,9 +114,10 @@ namespace yy
parser::symbol_type
yylex ()
{
- static int stage = -1;
- ++stage;
- parser::location_type loc (nullptr, stage + 1, stage + 1);
+ static int count = 0;
+ const int stage = count;
+ ++count;
+ parser::location_type loc (nullptr, unsigned (stage + 1), unsigned (stage
+ 1));
switch (stage)
{
case 0:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- c++: minor changes,
Akim Demaille <=