Move to module level statics from function level

This commit is contained in:
Jason Turner 2017-09-20 16:44:32 -06:00
parent c5a9cab3dd
commit 6cae70c208

View File

@ -286,7 +286,7 @@ namespace chaiscript
constexpr static utility::Static_String m_singleline_comment{"//"}; constexpr static utility::Static_String m_singleline_comment{"//"};
constexpr static utility::Static_String m_annotation{"#"}; constexpr static utility::Static_String m_annotation{"#"};
constexpr static utility::Static_String m_cr_lf{"\r\n"}; constexpr static utility::Static_String m_cr_lf{"\r\n"};
constexpr static auto m_operators = create_operators();
std::shared_ptr<std::string> m_filename; std::shared_ptr<std::string> m_filename;
std::vector<eval::AST_Node_Impl_Ptr<Tracer>> m_match_stack; std::vector<eval::AST_Node_Impl_Ptr<Tracer>> m_match_stack;
@ -429,10 +429,12 @@ namespace chaiscript
ChaiScript_Parser(ChaiScript_Parser &&) = default; ChaiScript_Parser(ChaiScript_Parser &&) = default;
ChaiScript_Parser &operator=(ChaiScript_Parser &&) = delete; ChaiScript_Parser &operator=(ChaiScript_Parser &&) = delete;
constexpr static auto m_alphabet = build_alphabet();
constexpr static Operator_Matches m_operator_matches{};
/// test a char in an m_alphabet /// test a char in an m_alphabet
constexpr bool char_in_alphabet(char c, detail::Alphabet a) const noexcept { constexpr bool char_in_alphabet(char c, detail::Alphabet a) const noexcept {
constexpr auto alphabet = build_alphabet(); return m_alphabet[a][static_cast<uint8_t>(c)];
return alphabet[a][static_cast<uint8_t>(c)];
} }
/// Prints the parsed ast_nodes as a tree /// Prints the parsed ast_nodes as a tree
@ -1421,8 +1423,7 @@ namespace chaiscript
} }
bool is_operator(const std::string &t_s) const noexcept { bool is_operator(const std::string &t_s) const noexcept {
constexpr Operator_Matches operator_matches; return m_operator_matches.is_match(t_s);
return operator_matches.is_match(t_s);
} }
/// Reads (and potentially captures) a symbol group from input if it matches the parameter /// Reads (and potentially captures) a symbol group from input if it matches the parameter
@ -2320,14 +2321,12 @@ namespace chaiscript
SS{"~"} SS{"~"}
}}; }};
constexpr auto operators = create_operators();
for (const auto &oper : prefix_opers) for (const auto &oper : prefix_opers)
{ {
const bool is_char = oper.size() == 1; const bool is_char = oper.size() == 1;
if ((is_char && Char(oper.c_str()[0])) || (!is_char && Symbol(oper))) if ((is_char && Char(oper.c_str()[0])) || (!is_char && Symbol(oper)))
{ {
if (!Operator(operators.size()-1)) { if (!Operator(m_operators.size()-1)) {
throw exception::eval_error("Incomplete prefix '" + std::string(oper.c_str()) + "' expression", File_Position(m_position.line, m_position.col), *m_filename); throw exception::eval_error("Incomplete prefix '" + std::string(oper.c_str()) + "' expression", File_Position(m_position.line, m_position.col), *m_filename);
} }
@ -2345,8 +2344,7 @@ namespace chaiscript
} }
bool Operator_Helper(const size_t t_precedence, std::string &oper) { bool Operator_Helper(const size_t t_precedence, std::string &oper) {
constexpr Operator_Matches operator_matches; return m_operator_matches.any_of(t_precedence,
return operator_matches.any_of(t_precedence,
[&oper, this](const auto &elem){ [&oper, this](const auto &elem){
if (Symbol(elem)) { if (Symbol(elem)) {
oper = elem.c_str(); oper = elem.c_str();
@ -2362,9 +2360,7 @@ namespace chaiscript
bool retval = false; bool retval = false;
const auto prev_stack_top = m_match_stack.size(); const auto prev_stack_top = m_match_stack.size();
constexpr auto operators = create_operators(); if (m_operators[t_precedence] != Operator_Precidence::Prefix) {
if (operators[t_precedence] != Operator_Precidence::Prefix) {
if (Operator(t_precedence+1)) { if (Operator(t_precedence+1)) {
retval = true; retval = true;
std::string oper; std::string oper;
@ -2375,7 +2371,7 @@ namespace chaiscript
File_Position(m_position.line, m_position.col), *m_filename); File_Position(m_position.line, m_position.col), *m_filename);
} }
switch (operators[t_precedence]) { switch (m_operators[t_precedence]) {
case(Operator_Precidence::Ternary_Cond) : case(Operator_Precidence::Ternary_Cond) :
if (Symbol(":")) { if (Symbol(":")) {
if (!Operator(t_precedence+1)) { if (!Operator(t_precedence+1)) {