error.c: map by index
* error.c (rb_builtin_type_name): map by index. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36441 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
40ce1eb403
commit
6e018e3f49
@ -1,3 +1,7 @@
|
|||||||
|
Wed Jul 18 17:45:26 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* error.c (rb_builtin_type_name): map by index.
|
||||||
|
|
||||||
Wed Jul 18 16:17:40 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Wed Jul 18 16:17:40 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* lib/mkmf.rb (have_framework): get rid of separating -framework
|
* lib/mkmf.rb (have_framework): get rid of separating -framework
|
||||||
|
71
error.c
71
error.c
@ -25,6 +25,8 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define numberof(array) (int)(sizeof(array) / sizeof((array)[0]))
|
||||||
|
|
||||||
#ifndef EXIT_SUCCESS
|
#ifndef EXIT_SUCCESS
|
||||||
#define EXIT_SUCCESS 0
|
#define EXIT_SUCCESS 0
|
||||||
#endif
|
#endif
|
||||||
@ -387,45 +389,46 @@ rb_compile_bug(const char *file, int line, const char *fmt, ...)
|
|||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct types {
|
static const char builtin_types[][10] = {
|
||||||
int type;
|
"", /* 0x00, */
|
||||||
const char *name;
|
"Object",
|
||||||
} builtin_types[] = {
|
"Class",
|
||||||
{T_NIL, "nil"},
|
"Module",
|
||||||
{T_OBJECT, "Object"},
|
"Float",
|
||||||
{T_CLASS, "Class"},
|
"String",
|
||||||
{T_ICLASS, "iClass"}, /* internal use: mixed-in module holder */
|
"Regexp",
|
||||||
{T_MODULE, "Module"},
|
"Array",
|
||||||
{T_FLOAT, "Float"},
|
"Hash",
|
||||||
{T_STRING, "String"},
|
"Struct",
|
||||||
{T_REGEXP, "Regexp"},
|
"Bignum",
|
||||||
{T_ARRAY, "Array"},
|
"File",
|
||||||
{T_FIXNUM, "Fixnum"},
|
"Data", /* internal use: wrapped C pointers */
|
||||||
{T_HASH, "Hash"},
|
"MatchData", /* data of $~ */
|
||||||
{T_STRUCT, "Struct"},
|
"Complex",
|
||||||
{T_BIGNUM, "Bignum"},
|
"Rational",
|
||||||
{T_FILE, "File"},
|
"", /* 0x10 */
|
||||||
{T_RATIONAL,"Rational"},
|
"nil",
|
||||||
{T_COMPLEX, "Complex"},
|
"true",
|
||||||
{T_TRUE, "true"},
|
"false",
|
||||||
{T_FALSE, "false"},
|
"Symbol", /* :symbol */
|
||||||
{T_SYMBOL, "Symbol"}, /* :symbol */
|
"Fixnum",
|
||||||
{T_DATA, "Data"}, /* internal use: wrapped C pointers */
|
"", /* 0x16 */
|
||||||
{T_MATCH, "MatchData"}, /* data of $~ */
|
"", /* 0x17 */
|
||||||
{T_NODE, "Node"}, /* internal use: syntax tree node */
|
"", /* 0x18 */
|
||||||
{T_UNDEF, "undef"}, /* internal use: #undef; should not happen */
|
"", /* 0x19 */
|
||||||
|
{}, /* 0x1a */
|
||||||
|
"undef", /* internal use: #undef; should not happen */
|
||||||
|
"Node", /* internal use: syntax tree node */
|
||||||
|
"iClass", /* internal use: mixed-in module holder */
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
rb_builtin_type_name(int t)
|
rb_builtin_type_name(int t)
|
||||||
{
|
{
|
||||||
const struct types *type = builtin_types;
|
const char *name;
|
||||||
const struct types *const typeend = builtin_types +
|
if ((unsigned int)t > numberof(builtin_types)) return 0;
|
||||||
sizeof(builtin_types) / sizeof(builtin_types[0]);
|
name = builtin_types[t];
|
||||||
while (type < typeend) {
|
if (*name) return name;
|
||||||
if (type->type == t) return type->name;
|
|
||||||
type++;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user