Skip to content
Snippets Groups Projects
Commit 08dc654e authored by Adam Welc's avatar Adam Welc
Browse files

Implemented some native functions related to type/string conversions.

parent 40f65275
Branches
No related tags found
No related merge requests found
......@@ -18,6 +18,69 @@
// selected functions from util.c:
const static struct {
const char * const str;
const int type;
}
TypeTable[] = {
{ "NULL", NILSXP }, /* real types */
{ "symbol", SYMSXP },
{ "pairlist", LISTSXP },
{ "closure", CLOSXP },
{ "environment", ENVSXP },
{ "promise", PROMSXP },
{ "language", LANGSXP },
{ "special", SPECIALSXP },
{ "builtin", BUILTINSXP },
{ "char", CHARSXP },
{ "logical", LGLSXP },
{ "integer", INTSXP },
{ "double", REALSXP }, /*- "real", for R <= 0.61.x */
{ "complex", CPLXSXP },
{ "character", STRSXP },
{ "...", DOTSXP },
{ "any", ANYSXP },
{ "expression", EXPRSXP },
{ "list", VECSXP },
{ "externalptr", EXTPTRSXP },
{ "bytecode", BCODESXP },
{ "weakref", WEAKREFSXP },
{ "raw", RAWSXP },
{ "S4", S4SXP },
/* aliases : */
{ "numeric", REALSXP },
{ "name", SYMSXP },
{ (char *)NULL, -1 }
};
const char *Rf_type2char(SEXPTYPE t) {
int i;
for (i = 0; TypeTable[i].str; i++) {
if (TypeTable[i].type == t)
return TypeTable[i].str;
}
warning(_("type %d is unimplemented in '%s'"), t, "type2char");
static char buf[50];
snprintf(buf, 50, "unknown type #%d", t);
return buf;
}
SEXP Rf_type2str(SEXPTYPE t) {
// implementation copied (almost) verbatim from util.c
int i;
for (i = 0; TypeTable[i].str; i++) {
if (TypeTable[i].type == t)
return mkChar(TypeTable[i].str);
}
warning(_("type %d is unimplemented in '%s'"), t, "type2str");
char buf[50];
snprintf(buf, 50, "unknown type #%d", t);
return Rf_mkChar(buf);
}
void init_util() {
}
......
......@@ -574,17 +574,6 @@ const char *Rf_translateCharUTF8(SEXP x) {
return NULL;
}
const char *Rf_type2char(SEXPTYPE x) {
unimplemented("Rf_type2char");
return NULL;
}
SEXP Rf_type2str(SEXPTYPE x) {
unimplemented("Rf_type2str");
return R_NilValue;
return NULL;
}
SEXP R_FindNamespace(SEXP info) {
JNIEnv *thisenv = getEnv();
SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, R_FindNamespaceMethodID, info);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment