Commit 1c3d05b5 authored by go kikuta's avatar go kikuta

refactor class.c methods (fix indent, remove unneed temp value. )

parent ea959d44
...@@ -1392,7 +1392,7 @@ mrb_module_new(mrb_state *mrb) ...@@ -1392,7 +1392,7 @@ mrb_module_new(mrb_state *mrb)
MRB_API struct RClass* MRB_API struct RClass*
mrb_obj_class(mrb_state *mrb, mrb_value obj) mrb_obj_class(mrb_state *mrb, mrb_value obj)
{ {
return mrb_class_real(mrb_class(mrb, obj)); return mrb_class_real(mrb_class(mrb, obj));
} }
MRB_API void MRB_API void
...@@ -1444,7 +1444,7 @@ mrb_mod_to_s(mrb_state *mrb, mrb_value klass) ...@@ -1444,7 +1444,7 @@ mrb_mod_to_s(mrb_state *mrb, mrb_value klass)
mrb_str_append(mrb, str, mrb_any_to_s(mrb, v)); mrb_str_append(mrb, str, mrb_any_to_s(mrb, v));
break; break;
} }
mrb_str_cat_lit(mrb, str, ">"); return mrb_str_cat_lit(mrb, str, ">");
} }
else { else {
struct RClass *c; struct RClass *c;
...@@ -1470,14 +1470,12 @@ mrb_mod_to_s(mrb_state *mrb, mrb_value klass) ...@@ -1470,14 +1470,12 @@ mrb_mod_to_s(mrb_state *mrb, mrb_value klass)
break; break;
} }
mrb_str_concat(mrb, str, mrb_ptr_to_str(mrb, c)); mrb_str_concat(mrb, str, mrb_ptr_to_str(mrb, c));
mrb_str_cat_lit(mrb, str, ">"); return mrb_str_cat_lit(mrb, str, ">");
} }
else { else {
str = path; return path;
} }
} }
return str;
} }
static mrb_value static mrb_value
...@@ -1610,25 +1608,23 @@ static mrb_value ...@@ -1610,25 +1608,23 @@ static mrb_value
mrb_mod_cvar_defined(mrb_state *mrb, mrb_value mod) mrb_mod_cvar_defined(mrb_state *mrb, mrb_value mod)
{ {
mrb_value id; mrb_value id;
mrb_bool defined_p;
id = get_sym_or_str_arg(mrb); id = get_sym_or_str_arg(mrb);
if (mrb_symbol_p(id)) { if (mrb_symbol_p(id)) {
check_cv_name_sym(mrb, mrb_symbol(id)); check_cv_name_sym(mrb, mrb_symbol(id));
defined_p = mrb_cv_defined(mrb, mod, mrb_symbol(id)); return mrb_bool_value(mrb_cv_defined(mrb, mod, mrb_symbol(id)));
} }
else { else {
mrb_value sym; mrb_value sym;
check_cv_name_str(mrb, id); check_cv_name_str(mrb, id);
sym = mrb_check_intern_str(mrb, id); sym = mrb_check_intern_str(mrb, id);
if (mrb_nil_p(sym)) { if (mrb_nil_p(sym)) {
defined_p = FALSE; return mrb_bool_value(FALSE);
} }
else { else {
defined_p = mrb_cv_defined(mrb, mod, mrb_symbol(sym)); return mrb_bool_value(mrb_cv_defined(mrb, mod, mrb_symbol(sym)));
} }
} }
return mrb_bool_value(defined_p);
} }
/* 15.2.2.4.17 */ /* 15.2.2.4.17 */
...@@ -1764,22 +1760,20 @@ static mrb_value ...@@ -1764,22 +1760,20 @@ static mrb_value
mrb_mod_method_defined(mrb_state *mrb, mrb_value mod) mrb_mod_method_defined(mrb_state *mrb, mrb_value mod)
{ {
mrb_value id; mrb_value id;
mrb_bool method_defined_p;
id = get_sym_or_str_arg(mrb); id = get_sym_or_str_arg(mrb);
if (mrb_symbol_p(id)) { if (mrb_symbol_p(id)) {
method_defined_p = mrb_obj_respond_to(mrb, mrb_class_ptr(mod), mrb_symbol(id)); return mrb_bool_value(mrb_obj_respond_to(mrb, mrb_class_ptr(mod), mrb_symbol(id)));
} }
else { else {
mrb_value sym = mrb_check_intern_str(mrb, id); mrb_value sym = mrb_check_intern_str(mrb, id);
if (mrb_nil_p(sym)) { if (mrb_nil_p(sym)) {
method_defined_p = FALSE; return mrb_false_value();
} }
else { else {
method_defined_p = mrb_obj_respond_to(mrb, mrb_class_ptr(mod), mrb_symbol(sym)); return mrb_bool_value(mrb_obj_respond_to(mrb, mrb_class_ptr(mod), mrb_symbol(sym)));
} }
} }
return mrb_bool_value(method_defined_p);
} }
static void static void
...@@ -1824,17 +1818,7 @@ mrb_mod_remove_method(mrb_state *mrb, mrb_value mod) ...@@ -1824,17 +1818,7 @@ mrb_mod_remove_method(mrb_state *mrb, mrb_value mod)
return mod; return mod;
} }
static void
check_const_name_sym(mrb_state *mrb, mrb_sym id)
{
const char *s;
mrb_int len;
s = mrb_sym2name_len(mrb, id, &len);
if (len < 1 || !ISUPPER(*s)) {
mrb_name_error(mrb, id, "wrong constant name %S", mrb_sym2str(mrb, id));
}
}
static void static void
check_const_name_str(mrb_state *mrb, mrb_value str) check_const_name_str(mrb_state *mrb, mrb_value str)
...@@ -1844,30 +1828,33 @@ check_const_name_str(mrb_state *mrb, mrb_value str) ...@@ -1844,30 +1828,33 @@ check_const_name_str(mrb_state *mrb, mrb_value str)
} }
} }
static void
check_const_name_sym(mrb_state *mrb, mrb_sym id)
{
check_const_name_str(mrb, mrb_sym2str(mrb, id));
}
static mrb_value static mrb_value
mrb_mod_const_defined(mrb_state *mrb, mrb_value mod) mrb_mod_const_defined(mrb_state *mrb, mrb_value mod)
{ {
mrb_value id; mrb_value id;
mrb_bool const_defined_p;
id = get_sym_or_str_arg(mrb); id = get_sym_or_str_arg(mrb);
if (mrb_type(id) == MRB_TT_SYMBOL) { if (mrb_type(id) == MRB_TT_SYMBOL) {
check_const_name_sym(mrb, mrb_symbol(id)); check_const_name_sym(mrb, mrb_symbol(id));
const_defined_p = mrb_const_defined(mrb, mod, mrb_symbol(id)); return mrb_bool_value(mrb_const_defined(mrb, mod, mrb_symbol(id)));
} }
else { else {
mrb_value sym; mrb_value sym;
check_const_name_str(mrb, id); check_const_name_str(mrb, id);
sym = mrb_check_intern_str(mrb, id); sym = mrb_check_intern_str(mrb, id);
if (mrb_nil_p(sym)) { if (mrb_nil_p(sym)) {
const_defined_p = FALSE; return mrb_false_value();
} }
else { else {
const_defined_p = mrb_const_defined(mrb, mod, mrb_symbol(sym)); return mrb_bool_value(mrb_const_defined(mrb, mod, mrb_symbol(sym)));
} }
} }
return mrb_bool_value(const_defined_p);
} }
static mrb_value static mrb_value
......
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