From 6cae70c20846dc73e570c293c1333202fafd8687 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Wed, 20 Sep 2017 16:44:32 -0600 Subject: [PATCH] Move to module level statics from function level --- .../chaiscript/language/chaiscript_parser.hpp | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index 2b7e7930..413e12b0 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -286,7 +286,7 @@ namespace chaiscript constexpr static utility::Static_String m_singleline_comment{"//"}; constexpr static utility::Static_String m_annotation{"#"}; constexpr static utility::Static_String m_cr_lf{"\r\n"}; - + constexpr static auto m_operators = create_operators(); std::shared_ptr m_filename; std::vector> m_match_stack; @@ -429,10 +429,12 @@ namespace chaiscript ChaiScript_Parser(ChaiScript_Parser &&) = default; 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 constexpr bool char_in_alphabet(char c, detail::Alphabet a) const noexcept { - constexpr auto alphabet = build_alphabet(); - return alphabet[a][static_cast(c)]; + return m_alphabet[a][static_cast(c)]; } /// Prints the parsed ast_nodes as a tree @@ -1421,8 +1423,7 @@ namespace chaiscript } bool is_operator(const std::string &t_s) const noexcept { - constexpr Operator_Matches operator_matches; - return operator_matches.is_match(t_s); + return m_operator_matches.is_match(t_s); } /// Reads (and potentially captures) a symbol group from input if it matches the parameter @@ -2320,14 +2321,12 @@ namespace chaiscript SS{"~"} }}; - constexpr auto operators = create_operators(); - for (const auto &oper : prefix_opers) { const bool is_char = oper.size() == 1; 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); } @@ -2345,8 +2344,7 @@ namespace chaiscript } bool Operator_Helper(const size_t t_precedence, std::string &oper) { - constexpr Operator_Matches operator_matches; - return operator_matches.any_of(t_precedence, + return m_operator_matches.any_of(t_precedence, [&oper, this](const auto &elem){ if (Symbol(elem)) { oper = elem.c_str(); @@ -2362,9 +2360,7 @@ namespace chaiscript bool retval = false; const auto prev_stack_top = m_match_stack.size(); - constexpr auto operators = create_operators(); - - if (operators[t_precedence] != Operator_Precidence::Prefix) { + if (m_operators[t_precedence] != Operator_Precidence::Prefix) { if (Operator(t_precedence+1)) { retval = true; std::string oper; @@ -2375,7 +2371,7 @@ namespace chaiscript File_Position(m_position.line, m_position.col), *m_filename); } - switch (operators[t_precedence]) { + switch (m_operators[t_precedence]) { case(Operator_Precidence::Ternary_Cond) : if (Symbol(":")) { if (!Operator(t_precedence+1)) {