Skip to content

Commit 5a83842

Browse files
new demangle function
1 parent 8637de0 commit 5a83842

File tree

5 files changed

+78
-2
lines changed

5 files changed

+78
-2
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
* include/Rcpp/traits/r_sexptype_traits.h : unsigned int wrapped as REALSXP
44
long standing feature request from Murray.
5+
* R/Attributes.R : Added the helper demangle function
6+
* man/demangle.Rd : Documentation for demangle
57

68
2013-09-18 JJ Allaire <jj@rstudio.org>
79

NAMESPACE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ export(Module,
2424
sourceCpp,
2525
compileAttributes,
2626
registerPlugin,
27-
RcppLdFlags
27+
RcppLdFlags,
28+
demangle
2829
)
2930

3031
exportClass(RcppClass)

R/Attributes.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,19 @@ cppFunction <- function(code,
252252
}
253253
}
254254

255+
# demangling a type
256+
demangle <- function( type = "int", ... ){
257+
code <- sprintf( '
258+
String demangle_this_type(){
259+
typedef %s type ;
260+
return DEMANGLE(type) ;
261+
}', type )
262+
dots <- list( code, ... )
263+
dots[["env"]] <- environment()
264+
do.call( cppFunction, dots )
265+
demangle_this_type()
266+
}
267+
255268
# Evaluate a simple c++ expression
256269
evalCpp <- function(code,
257270
depends = character(),

inst/NEWS.Rd

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44

55
\section{Changes in Rcpp version 0.10.5 (future)}{
66
\itemize{
7+
\item Changes in R code:
8+
\itemize{
9+
\item New R function \code{demangle} that calls the \code{DEMANGLE} macro.
10+
}
711
\item Changes in Rcpp API:
812
\itemize{
9-
\item Add \code{#defined(__sun)} to lists of operating systems to
13+
\item Add \code{defined(__sun)} to lists of operating systems to
1014
test for when checking for lack of \code{backtrace()} needed for
1115
stack traces.
1216
\item \code{as<T*>}, \code{as<const T*>}, \code{as<T&>} and

man/demangle.Rd

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
\name{demangle}
2+
\alias{demangle}
3+
\title{
4+
demanging c++ types
5+
}
6+
\description{
7+
This uses the compiler functionality (if available) to demangle type. If the compiler
8+
cannot demangle, then it will return its argument as is
9+
}
10+
\usage{
11+
demangle(type = "int", ...)
12+
}
13+
\arguments{
14+
\item{type}{The type we want to demangle}
15+
\item{\dots}{Further argument for \code{\link{cppFunction}} }
16+
}
17+
\details{
18+
The following function is compiled and invoked:
19+
20+
\preformatted{%
21+
String demangle_this_type(){
22+
typedef %s type ;
23+
return DEMANGLE(type) ;
24+
}
25+
}
26+
27+
\code{DEMANGLE} is a macro in \samp{Rcpp} that does the work.
28+
}
29+
\value{
30+
The demangled type, as a string.
31+
}
32+
\references{
33+
See this \href{http://gcc.gnu.org/onlinedocs/libstdc++/manual/ext_demangling.html}{chapter}
34+
from the GNU C++ library manual.
35+
}
36+
\author{
37+
Romain Francois <romain@r-enthusiasts.com>
38+
}
39+
\note{
40+
We only know how to demangle with gcc. If you know how to demangle types
41+
with your compiler, let us know.
42+
}
43+
\seealso{
44+
\code{\link{cppFunction}} is used to compile the function \code{demangle} creates.
45+
}
46+
\examples{
47+
\dontrun{
48+
demangle( "int64_t" )
49+
demangle( "uint64_t" )
50+
51+
demangle( "NumericVector" )
52+
demangle( "std::map<std::string,double>" )
53+
}
54+
}
55+
\keyword{programming}
56+

0 commit comments

Comments
 (0)