mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2026-01-01 03:12:23 +08:00
Make function constexpr
This commit is contained in:
parent
ddb2f352cd
commit
535c0344b7
@ -55,14 +55,14 @@ namespace chaiscript
|
||||
return opers[static_cast<int>(t_oper)];
|
||||
}
|
||||
|
||||
static Opers to_operator(const std::string &t_str, bool t_is_unary = false) noexcept
|
||||
constexpr static Opers to_operator(const char * const t_str, bool t_is_unary = false) noexcept
|
||||
{
|
||||
#ifdef CHAISCRIPT_MSVC
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4307)
|
||||
#endif
|
||||
|
||||
const auto op_hash = utility::fnv1a_32(t_str.c_str());
|
||||
const auto op_hash = utility::fnv1a_32(t_str);
|
||||
switch (op_hash) {
|
||||
case utility::fnv1a_32("=="): { return Opers::equals; }
|
||||
case utility::fnv1a_32("<"): { return Opers::less_than; }
|
||||
|
||||
@ -159,7 +159,7 @@ namespace chaiscript
|
||||
struct Fold_Right_Binary_Operator_AST_Node : AST_Node_Impl<T> {
|
||||
Fold_Right_Binary_Operator_AST_Node(const std::string &t_oper, Parse_Location t_loc, std::vector<AST_Node_Impl_Ptr<T>> t_children, Boxed_Value t_rhs) :
|
||||
AST_Node_Impl<T>(t_oper, AST_Node_Type::Binary, std::move(t_loc), std::move(t_children)),
|
||||
m_oper(Operators::to_operator(t_oper)),
|
||||
m_oper(Operators::to_operator(t_oper.c_str())),
|
||||
m_rhs(std::move(t_rhs))
|
||||
{ }
|
||||
|
||||
@ -204,7 +204,7 @@ namespace chaiscript
|
||||
struct Binary_Operator_AST_Node : AST_Node_Impl<T> {
|
||||
Binary_Operator_AST_Node(const std::string &t_oper, Parse_Location t_loc, std::vector<AST_Node_Impl_Ptr<T>> t_children) :
|
||||
AST_Node_Impl<T>(t_oper, AST_Node_Type::Binary, std::move(t_loc), std::move(t_children)),
|
||||
m_oper(Operators::to_operator(t_oper))
|
||||
m_oper(Operators::to_operator(t_oper.c_str()))
|
||||
{ }
|
||||
|
||||
Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override {
|
||||
@ -420,7 +420,7 @@ namespace chaiscript
|
||||
struct Equation_AST_Node final : AST_Node_Impl<T> {
|
||||
Equation_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_Node_Impl_Ptr<T>> t_children) :
|
||||
AST_Node_Impl<T>(std::move(t_ast_node_text), AST_Node_Type::Equation, std::move(t_loc), std::move(t_children)),
|
||||
m_oper(Operators::to_operator(this->text))
|
||||
m_oper(Operators::to_operator(this->text.c_str()))
|
||||
{ assert(this->children.size() == 2); }
|
||||
|
||||
|
||||
@ -1162,7 +1162,7 @@ namespace chaiscript
|
||||
struct Prefix_AST_Node final : AST_Node_Impl<T> {
|
||||
Prefix_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_Node_Impl_Ptr<T>> t_children) :
|
||||
AST_Node_Impl<T>(std::move(t_ast_node_text), AST_Node_Type::Prefix, std::move(t_loc), std::move(t_children)),
|
||||
m_oper(Operators::to_operator(this->text, true))
|
||||
m_oper(Operators::to_operator(this->text.c_str(), true))
|
||||
{ }
|
||||
|
||||
Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override{
|
||||
|
||||
@ -241,7 +241,7 @@ namespace chaiscript {
|
||||
{
|
||||
try {
|
||||
const auto &oper = node->text;
|
||||
const auto parsed = Operators::to_operator(oper);
|
||||
const auto parsed = Operators::to_operator(oper.c_str());
|
||||
if (parsed != Operators::Opers::invalid) {
|
||||
const auto rhs = dynamic_cast<eval::Constant_AST_Node<T> *>(node->children[1].get())->m_value;
|
||||
if (rhs.get_type_info().is_arithmetic()) {
|
||||
@ -268,7 +268,7 @@ namespace chaiscript {
|
||||
{
|
||||
try {
|
||||
const auto &oper = node->text;
|
||||
const auto parsed = Operators::to_operator(oper, true);
|
||||
const auto parsed = Operators::to_operator(oper.c_str(), true);
|
||||
const auto lhs = dynamic_cast<const eval::Constant_AST_Node<T> *>(node->children[0].get())->m_value;
|
||||
const auto match = oper + node->children[0]->text;
|
||||
|
||||
@ -308,7 +308,7 @@ namespace chaiscript {
|
||||
{
|
||||
try {
|
||||
const auto &oper = node->text;
|
||||
const auto parsed = Operators::to_operator(oper);
|
||||
const auto parsed = Operators::to_operator(oper.c_str());
|
||||
if (parsed != Operators::Opers::invalid) {
|
||||
const auto lhs = dynamic_cast<const eval::Constant_AST_Node<T> &>(*node->children[0]).m_value;
|
||||
const auto rhs = dynamic_cast<const eval::Constant_AST_Node<T> &>(*node->children[1]).m_value;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user