Commit 2f562cfb authored by Dominik Charousset's avatar Dominik Charousset

Undefine FSM parser DSL macros after use

parent 43e2d1e0
......@@ -36,6 +36,7 @@ set(LIBCAF_CORE_SRCS
src/behavior_stack.cpp
src/blocking_actor.cpp
src/blocking_behavior.cpp
src/chars.cpp
src/concatenated_tuple.cpp
src/config_option.cpp
src/config_option_adder.cpp
......@@ -55,7 +56,6 @@ set(LIBCAF_CORE_SRCS
src/execution_unit.cpp
src/exit_reason.cpp
src/forwarding_actor_proxy.cpp
src/fsm.cpp
src/get_mac_addresses.cpp
src/get_process_id.cpp
src/get_root_uuid.cpp
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2018 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#pragma once
#include <cstring>
namespace caf {
namespace detail {
namespace parser {
struct any_char_t {};
constexpr any_char_t any_char = any_char_t{};
constexpr bool in_whitelist(any_char_t, char) {
return true;
}
constexpr bool in_whitelist(char whitelist, char ch) {
return whitelist == ch;
}
inline bool in_whitelist(const char* whitelist, char ch) {
return strchr(whitelist, ch) != nullptr;
}
inline bool in_whitelist(bool (*filter)(char), char ch) {
return filter(ch);
}
extern const char alphanumeric_chars[63];
extern const char alphabetic_chars[53];
extern const char hexadecimal_chars[23];
extern const char decimal_chars[11];
extern const char octal_chars[9];
} // namespace parser
} // namespace detail
} // namespace caf
......@@ -16,45 +16,11 @@
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#pragma once
// This header intentionally has no `#pragma once`. Any parser that uses this
// DSL is supposed to clean up all defines made in this header via
// `include "caf/detail/parser/fsm_undef.hpp"` at the end.
#include <cstring>
#include "caf/config.hpp"
#include "caf/detail/pp.hpp"
#include "caf/pec.hpp"
namespace caf {
namespace detail {
struct any_char_t {};
constexpr any_char_t any_char = any_char_t{};
inline constexpr bool in_whitelist(any_char_t, char) {
return true;
}
inline constexpr bool in_whitelist(char whitelist, char ch) {
return whitelist == ch;
}
inline bool in_whitelist(const char* whitelist, char ch) {
return strchr(whitelist, ch) != nullptr;
}
inline bool in_whitelist(bool (*filter)(char), char ch) {
return filter(ch);
}
extern const char alphanumeric_chars[63];
extern const char alphabetic_chars[53];
extern const char hexadecimal_chars[23];
extern const char decimal_chars[11];
extern const char octal_chars[9];
} // namespace detail
} // namespace caf
#define CAF_FSM_EVAL_MISMATCH_EC \
if (mismatch_ec == caf::pec::unexpected_character) \
......@@ -109,18 +75,18 @@ extern const char octal_chars[9];
goto s_##target;
#define CAF_TRANSITION_IMPL2(target, whitelist) \
if (::caf::detail::in_whitelist(whitelist, ch)) { \
if (::caf::detail::parser::in_whitelist(whitelist, ch)) { \
CAF_TRANSITION_IMPL1(target) \
}
#define CAF_TRANSITION_IMPL3(target, whitelist, action) \
if (::caf::detail::in_whitelist(whitelist, ch)) { \
if (::caf::detail::parser::in_whitelist(whitelist, ch)) { \
action; \
CAF_TRANSITION_IMPL1(target) \
}
#define CAF_TRANSITION_IMPL4(target, whitelist, action, error_code) \
if (::caf::detail::in_whitelist(whitelist, ch)) { \
if (::caf::detail::parser::in_whitelist(whitelist, ch)) { \
if (!action) { \
ps.code = error_code; \
return; \
......@@ -129,7 +95,7 @@ extern const char octal_chars[9];
}
#define CAF_ERROR_TRANSITION_IMPL2(error_code, whitelist) \
if (::caf::detail::in_whitelist(whitelist, ch)) { \
if (::caf::detail::parser::in_whitelist(whitelist, ch)) { \
ps.code = error_code; \
return; \
}
......@@ -141,18 +107,18 @@ extern const char octal_chars[9];
#define CAF_EPSILON_IMPL1(target) goto s_##target;
#define CAF_EPSILON_IMPL2(target, whitelist) \
if (::caf::detail::in_whitelist(whitelist, ch)) { \
if (::caf::detail::parser::in_whitelist(whitelist, ch)) { \
CAF_EPSILON_IMPL1(target) \
}
#define CAF_EPSILON_IMPL3(target, whitelist, action) \
if (::caf::detail::in_whitelist(whitelist, ch)) { \
if (::caf::detail::parser::in_whitelist(whitelist, ch)) { \
action; \
CAF_EPSILON_IMPL1(target) \
}
#define CAF_EPSILON_IMPL4(target, whitelist, action, error_code) \
if (::caf::detail::in_whitelist(whitelist, ch)) { \
if (::caf::detail::parser::in_whitelist(whitelist, ch)) { \
if (!action) { \
ps.code = error_code; \
return; \
......@@ -169,19 +135,19 @@ extern const char octal_chars[9];
goto s_##target;
#define CAF_FSM_TRANSITION_IMPL3(fsm_call, target, whitelist) \
if (::caf::detail::in_whitelist(whitelist, ch)) { \
if (::caf::detail::parser::in_whitelist(whitelist, ch)) { \
CAF_FSM_TRANSITION_IMPL2(fsm_call, target) \
}
#define CAF_FSM_TRANSITION_IMPL4(fsm_call, target, whitelist, action) \
if (::caf::detail::in_whitelist(whitelist, ch)) { \
if (::caf::detail::parser::in_whitelist(whitelist, ch)) { \
action; \
CAF_FSM_TRANSITION_IMPL2(fsm_call, target) \
}
#define CAF_FSM_TRANSITION_IMPL5(fsm_call, target, whitelist, action, \
error_code) \
if (::caf::detail::in_whitelist(whitelist, ch)) { \
if (::caf::detail::parser::in_whitelist(whitelist, ch)) { \
if (!action) { \
ps.code = error_code; \
return; \
......@@ -197,18 +163,18 @@ extern const char octal_chars[9];
goto s_##target;
#define CAF_FSM_EPSILON_IMPL3(fsm_call, target, whitelist) \
if (::caf::detail::in_whitelist(whitelist, ch)) { \
if (::caf::detail::parser::in_whitelist(whitelist, ch)) { \
CAF_FSM_EPSILON_IMPL2(fsm_call, target) \
}
#define CAF_FSM_EPSILON_IMPL4(fsm_call, target, whitelist, action) \
if (::caf::detail::in_whitelist(whitelist, ch)) { \
if (::caf::detail::parser::in_whitelist(whitelist, ch)) { \
action; \
CAF_FSM_EPSILON_IMPL2(fsm_call, target) \
}
#define CAF_FSM_EPSILON_IMPL5(fsm_call, target, whitelist, action, error_code) \
if (::caf::detail::in_whitelist(whitelist, ch)) { \
if (::caf::detail::parser::in_whitelist(whitelist, ch)) { \
if (!action) { \
ps.code = error_code; \
return; \
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2018 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
// This header intentionally has no `#pragma once`. See fsm.hpp.
#undef CAF_FSM_EVAL_MISMATCH_EC
#undef start
#undef state
#undef term_state
#undef fin
#undef CAF_TRANSITION_IMPL1
#undef CAF_TRANSITION_IMPL2
#undef CAF_TRANSITION_IMPL3
#undef CAF_TRANSITION_IMPL4
#undef CAF_ERROR_TRANSITION_IMPL2
#undef CAF_ERROR_TRANSITION_IMPL1
#undef CAF_EPSILON_IMPL1
#undef CAF_EPSILON_IMPL2
#undef CAF_EPSILON_IMPL3
#undef CAF_EPSILON_IMPL4
#undef CAF_FSM_TRANSITION_IMPL2
#undef CAF_FSM_TRANSITION_IMPL3
#undef CAF_FSM_TRANSITION_IMPL4
#undef CAF_FSM_TRANSITION_IMPL5
#undef CAF_FSM_EPSILON_IMPL2
#undef CAF_FSM_EPSILON_IMPL3
#undef CAF_FSM_EPSILON_IMPL4
#undef CAF_FSM_EPSILON_IMPL5
#undef transition
#undef error_transition
#undef epsilon
#undef fsm_transition
#undef fsm_epsilon
#undef epsilon_if
#undef fsm_transition_if
#undef fsm_epsilon_if
......@@ -24,7 +24,7 @@
#include "caf/atom.hpp"
#include "caf/config.hpp"
#include "caf/detail/parser/fsm.hpp"
#include "caf/detail/parser/chars.hpp"
#include "caf/detail/parser/is_char.hpp"
#include "caf/detail/parser/state.hpp"
#include "caf/detail/scope_guard.hpp"
......@@ -32,6 +32,8 @@
CAF_PUSH_UNUSED_LABEL_WARNING
#include "caf/detail/parser/fsm.hpp"
namespace caf {
namespace detail {
namespace parser {
......@@ -75,4 +77,6 @@ void read_atom(state<Iterator, Sentinel>& ps, Consumer& consumer) {
} // namespace detail
} // namespace caf
#include "caf/detail/parser/fsm_undef.hpp"
CAF_POP_WARNINGS
......@@ -22,7 +22,7 @@
#include <string>
#include "caf/config.hpp"
#include "caf/detail/parser/fsm.hpp"
#include "caf/detail/parser/chars.hpp"
#include "caf/detail/parser/is_char.hpp"
#include "caf/detail/parser/state.hpp"
#include "caf/detail/scope_guard.hpp"
......@@ -30,6 +30,8 @@
CAF_PUSH_UNUSED_LABEL_WARNING
#include "caf/detail/parser/fsm.hpp"
namespace caf {
namespace detail {
namespace parser {
......@@ -78,4 +80,6 @@ void read_bool(state<Iterator, Sentinel>& ps, Consumer& consumer) {
} // namespace detail
} // namespace caf
#include "caf/detail/parser/fsm_undef.hpp"
CAF_POP_WARNINGS
......@@ -23,7 +23,7 @@
#include <stack>
#include "caf/config.hpp"
#include "caf/detail/parser/fsm.hpp"
#include "caf/detail/parser/chars.hpp"
#include "caf/detail/parser/read_atom.hpp"
#include "caf/detail/parser/read_bool.hpp"
#include "caf/detail/parser/read_number_or_timespan.hpp"
......@@ -33,6 +33,8 @@
CAF_PUSH_UNUSED_LABEL_WARNING
#include "caf/detail/parser/fsm.hpp"
namespace caf {
namespace detail {
namespace parser {
......@@ -247,4 +249,6 @@ void read_ini(state<Iterator, Sentinel>& ps, Consumer&& consumer) {
} // namespace detail
} // namespace caf
#include "caf/detail/parser/fsm_undef.hpp"
CAF_POP_WARNINGS
......@@ -20,8 +20,9 @@
#include <cstdint>
#include "caf/config.hpp"
#include "caf/detail/parser/chars.hpp"
#include "caf/detail/parser/add_ascii.hpp"
#include "caf/detail/parser/fsm.hpp"
#include "caf/detail/parser/is_char.hpp"
#include "caf/detail/parser/is_digit.hpp"
#include "caf/detail/parser/state.hpp"
......@@ -31,6 +32,8 @@
CAF_PUSH_UNUSED_LABEL_WARNING
#include "caf/detail/parser/fsm.hpp"
namespace caf {
namespace detail {
namespace parser {
......@@ -239,4 +242,6 @@ void read_number(state<Iterator, Sentinel>& ps, Consumer& consumer) {
} // namespace detail
} // namespace caf
#include "caf/detail/parser/fsm_undef.hpp"
CAF_POP_WARNINGS
......@@ -22,7 +22,8 @@
#include <cstdint>
#include <string>
#include "caf/detail/parser/fsm.hpp"
#include "caf/config.hpp"
#include "caf/detail/parser/chars.hpp"
#include "caf/detail/parser/is_char.hpp"
#include "caf/detail/parser/read_number.hpp"
#include "caf/detail/parser/state.hpp"
......@@ -35,6 +36,8 @@
CAF_PUSH_UNUSED_LABEL_WARNING
#include "caf/detail/parser/fsm.hpp"
namespace caf {
namespace detail {
namespace parser {
......@@ -111,4 +114,6 @@ void read_number_or_timespan(state<Iterator, Sentinel>& ps,
} // namespace detail
} // namespace caf
#include "caf/detail/parser/fsm_undef.hpp"
CAF_POP_WARNINGS
......@@ -21,15 +21,17 @@
#include <cstdint>
#include <string>
#include "caf/detail/scope_guard.hpp"
#include "caf/detail/parser/fsm.hpp"
#include "caf/config.hpp"
#include "caf/detail/parser/chars.hpp"
#include "caf/detail/parser/is_char.hpp"
#include "caf/detail/parser/state.hpp"
#include "caf/detail/scope_guard.hpp"
#include "caf/pec.hpp"
CAF_PUSH_UNUSED_LABEL_WARNING
#include "caf/detail/parser/fsm.hpp"
namespace caf {
namespace detail {
namespace parser {
......@@ -72,4 +74,6 @@ void read_string(state<Iterator, Sentinel>& ps, Consumer& consumer) {
} // namespace detail
} // namespace caf
#include "caf/detail/parser/fsm_undef.hpp"
CAF_POP_WARNINGS
......@@ -31,8 +31,21 @@ struct state {
Iterator i;
Sentinel e;
pec code;
int32_t line = 1;
int32_t column = 1;
int32_t line;
int32_t column;
state() : code(pec::success), line(1), column(1) {
// nop
}
explicit state(Iterator first) : state() {
i = first;
}
state(Iterator first, Sentinel last) : state() {
i = first;
e = last;
}
/// Returns the null terminator when reaching the end of the string,
/// otherwise the next character.
......
......@@ -103,6 +103,8 @@ class forwarding_actor_proxy;
class group;
class group_module;
class inbound_path;
class ipv4_address;
class ipv6_address;
class local_actor;
class mailbox_element;
class message;
......
......@@ -16,10 +16,11 @@
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/detail/parser/fsm.hpp"
#include "caf/detail/parser/chars.hpp"
namespace caf {
namespace detail {
namespace parser {
const char alphanumeric_chars[63] = "0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
......@@ -34,6 +35,7 @@ const char decimal_chars[11] = "0123456789";
const char octal_chars[9] = "01234567";
} // namespace parser
} // namespace detail
} // namespace caf
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment