BIND 10 trac2372, updated. 15d6d71ed052c0dc5d6be39a8afe484014887b31 [2372] use specific constatnt values for Options instead of using the << trick
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon Nov 12 20:24:13 UTC 2012
The branch, trac2372 has been updated
via 15d6d71ed052c0dc5d6be39a8afe484014887b31 (commit)
via a3dde49a8210f65d1f37c9dee5638dc62ed92dd3 (commit)
via 6a2d1a5cbdeb2603982abbf148012e0879bba4ee (commit)
via 9fb295c549978ba217384643beb60b25b52ff35a (commit)
via a49d071d0040474aa3fb23cb0e79c92f51f54f71 (commit)
via 626a7de9ad0d9cc7324e024b41f55ef636ee7957 (commit)
from 3446f7e74be156440c4e6b0333955b4c84e5443f (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 15d6d71ed052c0dc5d6be39a8afe484014887b31
Author: JINMEI Tatuya <jinmei at isc.org>
Date: Mon Nov 12 12:22:41 2012 -0800
[2372] use specific constatnt values for Options instead of using the << trick
the previous code doesn't seem to be understandable as I thought, so I
simplfy revert to the more straightforward way.
also added doc for the enum
commit a3dde49a8210f65d1f37c9dee5638dc62ed92dd3
Author: JINMEI Tatuya <jinmei at isc.org>
Date: Mon Nov 12 12:12:58 2012 -0800
[2372] catch a buggy case of bogus ID in State::getInstance
commit 6a2d1a5cbdeb2603982abbf148012e0879bba4ee
Author: JINMEI Tatuya <jinmei at isc.org>
Date: Mon Nov 12 12:05:46 2012 -0800
[2372] made sure entire test sstring is built before starting test case.
The previous code should actually be safe based on the iostream/streambuf
APIs, but it's even much safer to completely give the ownership of the
passed stream to the input source.
commit 9fb295c549978ba217384643beb60b25b52ff35a
Author: JINMEI Tatuya <jinmei at isc.org>
Date: Mon Nov 12 11:05:58 2012 -0800
[2372] hide specific state cleasse inside an unnamed namespace.
they don't have to be (actually they already aren't) visible outside this
translation unit.
commit a49d071d0040474aa3fb23cb0e79c92f51f54f71
Author: JINMEI Tatuya <jinmei at isc.org>
Date: Mon Nov 12 11:02:28 2012 -0800
[2372] a minor documentation wording correction.
commit 626a7de9ad0d9cc7324e024b41f55ef636ee7957
Author: JINMEI Tatuya <jinmei at isc.org>
Date: Mon Nov 12 10:50:48 2012 -0800
[2372] minor editorial cleanup in a comment
-----------------------------------------------------------------------
Summary of changes:
src/lib/dns/master_lexer.cc | 10 ++++-
src/lib/dns/master_lexer.h | 12 ++++--
src/lib/dns/master_lexer_state.h | 2 +-
src/lib/dns/tests/master_lexer_state_unittest.cc | 46 +++++++++++++++-------
4 files changed, 48 insertions(+), 22 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/dns/master_lexer.cc b/src/lib/dns/master_lexer.cc
index 655e537..8ee70c7 100644
--- a/src/lib/dns/master_lexer.cc
+++ b/src/lib/dns/master_lexer.cc
@@ -148,7 +148,7 @@ MasterLexer::Token::getErrorText() const {
namespace master_lexer_internal {
// Below we implement state classes for state transitions of MasterLexer.
// Note that these need to be defined here so that they can refer to
-// the details of of MasterLexerImpl.
+// the details of MasterLexerImpl.
typedef MasterLexer::Token Token; // convenience shortcut
@@ -167,6 +167,7 @@ State::getParenCount(const MasterLexer& lexer) const {
return (lexer.impl_->paren_count_);
}
+namespace {
class CRLF : public State {
public:
CRLF() {}
@@ -200,7 +201,6 @@ public:
}
};
-namespace {
// We use a common instance of a each state in a singleton-like way to save
// construction overhead. They are not singletons in its strict sense as
// we don't prohibit direct construction of these objects. But that doesn't
@@ -218,6 +218,12 @@ State::getInstance(ID state_id) {
case String:
return (STRING_STATE);
}
+
+ // This is a bug of the caller, and this method is only expected to be
+ // used by tests, so we just forcefully make it fail by asserting the
+ // condition.
+ assert(false);
+ return (STRING_STATE); // a dummy return, to silence some compilers.
}
const State*
diff --git a/src/lib/dns/master_lexer.h b/src/lib/dns/master_lexer.h
index 48ba919..58b7a30 100644
--- a/src/lib/dns/master_lexer.h
+++ b/src/lib/dns/master_lexer.h
@@ -50,11 +50,15 @@ class MasterLexer {
public:
class Token; // we define it separately for better readability
+ /// \brief Options for getNextToken.
+ ///
+ /// A compound option, indicating multiple options are set, can be
+ /// specified using the logical OR operator (operator|()).
enum Options {
- NONE = 0, //< No option
- INITIAL_WS = 1, ///< recognize begin-of-line spaces
- QSTRING = INITIAL_WS << 1, ///< recognize quoted string
- NUMBER = QSTRING << 1 ///< recognize numeric text as integer
+ NONE = 0, //< No option
+ INITIAL_WS = 1, ///< recognize begin-of-line spaces
+ QSTRING = 2, ///< recognize quoted string
+ NUMBER = 4 ///< recognize numeric text as integer
};
/// \brief The constructor.
diff --git a/src/lib/dns/master_lexer_state.h b/src/lib/dns/master_lexer_state.h
index 0d00049..86957c5 100644
--- a/src/lib/dns/master_lexer_state.h
+++ b/src/lib/dns/master_lexer_state.h
@@ -35,7 +35,7 @@ namespace master_lexer_internal {
/// context, and updates it as necessary; each \c State derived class is
/// completely stateless.
///
-/// The initial transition takes place a static method of the base class,
+/// The initial transition takes place in a static method of the base class,
/// \c start(). This is mainly for implementation convenience; we need to
/// pass options given to \c MasterLexer::getNextToken() for the initial
/// state, so it makes more sense to separate the interface for the transition
diff --git a/src/lib/dns/tests/master_lexer_state_unittest.cc b/src/lib/dns/tests/master_lexer_state_unittest.cc
index f6d99a9..bcee7fd 100644
--- a/src/lib/dns/tests/master_lexer_state_unittest.cc
+++ b/src/lib/dns/tests/master_lexer_state_unittest.cc
@@ -34,9 +34,7 @@ protected:
s_string(State::getInstance(State::String)),
options(MasterLexer::NONE),
orig_options(options)
- {
- lexer.pushSource(ss);
- }
+ {}
// Specify INITIAL_WS as common initial options.
const MasterLexer::Options common_options;
@@ -61,12 +59,15 @@ eofCheck(const State& state, MasterLexer& lexer) {
TEST_F(MasterLexerStateTest, startAndEnd) {
// A simple case: the input is empty, so we begin with start and
// are immediately done.
+ lexer.pushSource(ss);
EXPECT_EQ(s_null, State::start(lexer, common_options));
eofCheck(s_crlf, lexer);
}
TEST_F(MasterLexerStateTest, startToEOL) {
ss << "\n";
+ lexer.pushSource(ss);
+
EXPECT_EQ(s_null, State::start(lexer, common_options));
EXPECT_TRUE(s_crlf.wasLastEOL(lexer));
EXPECT_EQ(Token::END_OF_LINE, s_crlf.getToken(lexer).getType());
@@ -77,12 +78,15 @@ TEST_F(MasterLexerStateTest, startToEOL) {
}
TEST_F(MasterLexerStateTest, space) {
+ // repeat '\t\n' twice (see below), then space after EOL
+ ss << " \t\n\t\n ";
+ lexer.pushSource(ss);
+
// by default space characters and tabs will be ignored. We check this
// twice; at the second iteration, it's a white space at the beginning
// of line, but since we don't specify INITIAL_WS option, it's treated as
// normal space and ignored.
for (size_t i = 0; i < 2; ++i) {
- ss << " \t\n";
EXPECT_EQ(s_null, State::start(lexer, MasterLexer::NONE));
EXPECT_TRUE(s_crlf.wasLastEOL(lexer));
EXPECT_EQ(Token::END_OF_LINE, s_crlf.getToken(lexer).getType());
@@ -90,7 +94,6 @@ TEST_F(MasterLexerStateTest, space) {
// Now we specify the INITIAL_WS option. It will be recognized and the
// corresponding token will be returned.
- ss << " ";
EXPECT_EQ(s_null, State::start(lexer, MasterLexer::INITIAL_WS));
EXPECT_FALSE(s_crlf.wasLastEOL(lexer));
EXPECT_EQ(Token::INITIAL_WS, s_crlf.getToken(lexer).getType());
@@ -98,6 +101,7 @@ TEST_F(MasterLexerStateTest, space) {
TEST_F(MasterLexerStateTest, parentheses) {
ss << "\n(\na\n )\n "; // 1st \n is to check if 'was EOL' is set to false
+ lexer.pushSource(ss);
EXPECT_EQ(s_null, State::start(lexer, common_options)); // handle \n
@@ -127,6 +131,8 @@ TEST_F(MasterLexerStateTest, parentheses) {
TEST_F(MasterLexerStateTest, nestedParentheses) {
// This is an unusual, but allowed (in this implementation) case.
ss << "(a(b)\n c)\n ";
+ lexer.pushSource(ss);
+
EXPECT_EQ(&s_string, State::start(lexer, common_options)); // consume '('
s_string.handle(lexer); // consume 'a'
EXPECT_EQ(&s_string, State::start(lexer, common_options)); // consume '('
@@ -155,6 +161,8 @@ TEST_F(MasterLexerStateTest, unbalancedParentheses) {
// Only closing paren is provided. We prepend a \n to check if it's
// correctly canceled after detecting the error.
ss << "\n)";
+ ss << "(a";
+ lexer.pushSource(ss);
EXPECT_EQ(s_null, State::start(lexer, common_options)); // consume '\n'
EXPECT_TRUE(s_crlf.wasLastEOL(lexer)); // this \n was remembered
@@ -169,7 +177,6 @@ TEST_F(MasterLexerStateTest, unbalancedParentheses) {
EXPECT_FALSE(s_crlf.wasLastEOL(lexer));
// Reach EOF with a dangling open parenthesis.
- ss << "(a";
EXPECT_EQ(&s_string, State::start(lexer, common_options)); // consume '('
s_string.handle(lexer); // consume 'a'
EXPECT_EQ(1, s_crlf.getParenCount(lexer));
@@ -184,11 +191,14 @@ TEST_F(MasterLexerStateTest, startToComment) {
// the rest of the line, and recognize the new line. Note that the
// second ';' is simply ignored.
ss << " ;a;\n";
+ ss << ";a;"; // Likewise, but the comment ends with EOF.
+ lexer.pushSource(ss);
+
+ // Comment ending with EOL
EXPECT_EQ(s_null, State::start(lexer, common_options));
EXPECT_EQ(Token::END_OF_LINE, s_crlf.getToken(lexer).getType());
- // Likewise, but the comment ends with EOF.
- ss << ";a;";
+ // Comment ending with EOF
EXPECT_EQ(s_null, State::start(lexer, common_options));
EXPECT_EQ(Token::END_OF_FILE, s_crlf.getToken(lexer).getType());
}
@@ -198,6 +208,8 @@ TEST_F(MasterLexerStateTest, commentAfterParen) {
// other tests should also ensure that it works correctly, but we
// check it explicitly.
ss << "( ;this is a comment\na)\n";
+ lexer.pushSource(ss);
+
// consume '(', skip comments, consume 'a', then consume ')'
EXPECT_EQ(&s_string, State::start(lexer, common_options));
s_string.handle(lexer);
@@ -206,30 +218,34 @@ TEST_F(MasterLexerStateTest, commentAfterParen) {
}
TEST_F(MasterLexerStateTest, crlf) {
- // A sequence of \r, \n is recognized as a single 'end-of-line'
- ss << "\r\n";
+ ss << "\r\n"; // case 1
+ ss << "\r "; // case 2
+ ss << "\r;comment\na"; // case 3
+ ss << "\r"; // case 4
+ lexer.pushSource(ss);
+
+ // 1. A sequence of \r, \n is recognized as a single 'end-of-line'
EXPECT_EQ(&s_crlf, State::start(lexer, common_options)); // recognize '\r'
EXPECT_EQ(s_null, s_crlf.handle(lexer)); // recognize '\n'
EXPECT_EQ(Token::END_OF_LINE, s_crlf.getToken(lexer).getType());
EXPECT_TRUE(s_crlf.wasLastEOL(lexer));
- // Single '\r' (not followed by \n) is recognized as a single 'end-of-line'
- ss << "\r "; // then there will be "initial WS"
+ // 2. Single '\r' (not followed by \n) is recognized as a single
+ // 'end-of-line'. then there will be "initial WS"
EXPECT_EQ(&s_crlf, State::start(lexer, common_options)); // recognize '\r'
// see ' ', "unget" it
EXPECT_EQ(s_null, s_crlf.handle(lexer));
EXPECT_EQ(s_null, State::start(lexer, common_options)); // recognize ' '
EXPECT_EQ(Token::INITIAL_WS, s_crlf.getToken(lexer).getType());
- ss << "\r;comment\na";
+ // 3. comment between \r and \n
EXPECT_EQ(&s_crlf, State::start(lexer, common_options)); // recognize '\r'
// skip comments, recognize '\n'
EXPECT_EQ(s_null, s_crlf.handle(lexer));
EXPECT_EQ(Token::END_OF_LINE, s_crlf.getToken(lexer).getType());
EXPECT_EQ(&s_string, State::start(lexer, common_options));
- // \r then EOF
- ss << "\r";
+ // 4. \r then EOF
EXPECT_EQ(&s_crlf, State::start(lexer, common_options)); // recognize '\r'
// see EOF, then "unget" it
EXPECT_EQ(s_null, s_crlf.handle(lexer));
More information about the bind10-changes
mailing list