[Rcpp-commits] r4519 - in pkg/Rcpp: . R inst man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Sep 19 10:01:51 CEST 2013


Author: romain
Date: 2013-09-19 10:01:51 +0200 (Thu, 19 Sep 2013)
New Revision: 4519

Added:
   pkg/Rcpp/man/demangle.Rd
Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/NAMESPACE
   pkg/Rcpp/R/Attributes.R
   pkg/Rcpp/inst/NEWS.Rd
Log:
new demangle function

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2013-09-19 07:08:31 UTC (rev 4518)
+++ pkg/Rcpp/ChangeLog	2013-09-19 08:01:51 UTC (rev 4519)
@@ -2,6 +2,8 @@
 
         * include/Rcpp/traits/r_sexptype_traits.h : unsigned int wrapped as REALSXP
         long standing feature request from Murray. 
+        * R/Attributes.R : Added the helper demangle function
+        * man/demangle.Rd : Documentation for demangle
 
 2013-09-18  JJ Allaire  <jj at rstudio.org>
 

Modified: pkg/Rcpp/NAMESPACE
===================================================================
--- pkg/Rcpp/NAMESPACE	2013-09-19 07:08:31 UTC (rev 4518)
+++ pkg/Rcpp/NAMESPACE	2013-09-19 08:01:51 UTC (rev 4519)
@@ -24,7 +24,8 @@
        sourceCpp,
        compileAttributes,
        registerPlugin,
-       RcppLdFlags
+       RcppLdFlags, 
+       demangle
        )
 
 exportClass(RcppClass)

Modified: pkg/Rcpp/R/Attributes.R
===================================================================
--- pkg/Rcpp/R/Attributes.R	2013-09-19 07:08:31 UTC (rev 4518)
+++ pkg/Rcpp/R/Attributes.R	2013-09-19 08:01:51 UTC (rev 4519)
@@ -252,6 +252,19 @@
     }
 }
 
+# demangling a type
+demangle <- function( type = "int", ... ){
+    code <- sprintf( '
+    String demangle_this_type(){
+        typedef %s type ;
+        return DEMANGLE(type) ;
+    }', type )
+    dots <- list( code, ... )
+    dots[["env"]] <- environment()
+    do.call( cppFunction, dots )
+    demangle_this_type()
+}
+
 # Evaluate a simple c++ expression
 evalCpp <- function(code,
                     depends = character(),

Modified: pkg/Rcpp/inst/NEWS.Rd
===================================================================
--- pkg/Rcpp/inst/NEWS.Rd	2013-09-19 07:08:31 UTC (rev 4518)
+++ pkg/Rcpp/inst/NEWS.Rd	2013-09-19 08:01:51 UTC (rev 4519)
@@ -4,9 +4,13 @@
 
 \section{Changes in Rcpp version 0.10.5 (future)}{
   \itemize{
+    \item Changes in R code:
+    \itemize{
+      \item New R function \code{demangle} that calls the \code{DEMANGLE} macro.     
+    }
     \item Changes in Rcpp API:
     \itemize{
-      \item Add \code{#defined(__sun)} to lists of operating systems to
+      \item Add \code{defined(__sun)} to lists of operating systems to
       test for when checking for lack of \code{backtrace()} needed for
       stack traces.
       \item \code{as<T*>}, \code{as<const T*>}, \code{as<T&>} and

Added: pkg/Rcpp/man/demangle.Rd
===================================================================
--- pkg/Rcpp/man/demangle.Rd	                        (rev 0)
+++ pkg/Rcpp/man/demangle.Rd	2013-09-19 08:01:51 UTC (rev 4519)
@@ -0,0 +1,56 @@
+\name{demangle}
+\alias{demangle}
+\title{
+demanging c++ types 
+}
+\description{
+    This uses the compiler functionality (if available) to demangle type. If the compiler
+    cannot demangle, then it will return its argument as is
+}
+\usage{
+    demangle(type = "int", ...)
+}
+\arguments{
+    \item{type}{The type we want to demangle}
+    \item{\dots}{Further argument for \code{\link{cppFunction}} }
+}
+\details{
+    The following function is compiled and invoked: 
+    
+    \preformatted{%
+        String demangle_this_type(){
+            typedef %s type ;
+            return DEMANGLE(type) ;
+        }         
+    }    
+    
+    \code{DEMANGLE} is a macro in \samp{Rcpp} that does the work. 
+}
+\value{
+    The demangled type, as a string. 
+}
+\references{
+    See this \href{http://gcc.gnu.org/onlinedocs/libstdc++/manual/ext_demangling.html}{chapter}
+    from the GNU C++ library manual. 
+}
+\author{
+    Romain Francois <romain at r-enthusiasts.com>
+}
+\note{
+    We only know how to demangle with gcc. If you know how to demangle types
+    with your compiler, let us know. 
+}
+\seealso{
+    \code{\link{cppFunction}} is used to compile the function \code{demangle} creates. 
+}
+\examples{
+\dontrun{
+    demangle( "int64_t" )
+    demangle( "uint64_t" )
+
+    demangle( "NumericVector" )
+    demangle( "std::map<std::string,double>" )
+}
+}
+\keyword{programming}
+



More information about the Rcpp-commits mailing list