CXXR (C++ R)
Public Types | Public Member Functions | Static Public Member Functions | Friends
CXXR::BuiltInFunction Class Reference

R function implemented within the interpreter. More...

#include <BuiltInFunction.h>

Inheritance diagram for CXXR::BuiltInFunction:
Inheritance graph
[legend]
Collaboration diagram for CXXR::BuiltInFunction:
Collaboration graph
[legend]

List of all members.

Public Types

enum  Kind {
  PP_INVALID = 0, PP_ASSIGN = 1, PP_ASSIGN2 = 2, PP_BINARY = 3,
  PP_BINARY2 = 4, PP_BREAK = 5, PP_CURLY = 6, PP_FOR = 7,
  PP_FUNCALL = 8, PP_FUNCTION = 9, PP_IF = 10, PP_NEXT = 11,
  PP_PAREN = 12, PP_RETURN = 13, PP_SUBASS = 14, PP_SUBSET = 15,
  PP_WHILE = 16, PP_UNARY = 17, PP_DOLLAR = 18, PP_FOREIGN = 19,
  PP_REPEAT = 20
}
 Kind of function, used mainly in deparsing.
enum  Precedence {
  PREC_FN = 0, PREC_LEFT = 1, PREC_EQ = 2, PREC_RIGHT = 3,
  PREC_TILDE = 4, PREC_OR = 5, PREC_AND = 6, PREC_NOT = 7,
  PREC_COMPARE = 8, PREC_SUM = 9, PREC_PROD = 10, PREC_PERCENT = 11,
  PREC_COLON = 12, PREC_SIGN = 13, PREC_POWER = 14, PREC_DOLLAR = 15,
  PREC_NS = 16, PREC_SUBSET = 17
}
 Precedence level of function.

Public Member Functions

int arity () const
 'Arity' of the function.
void checkNumArgs (const PairList *args, const Expression *call) const
 Report error if argument list is wrong length.
CCODE function () const
 C/C++ function implementing this R function.
Kind kind () const
 Kind of built-in function.
const char * name () const
 Name of function.
unsigned int offset () const
 Get table offset.
Precedence precedence () const
 Precedence of built-in function.
int printHandling () const
 (Not for general use.)
bool rightAssociative () const
 Is a built-in function right-associative?
unsigned int variant () const
 Index of variant behaviour.
bool viaDotInternal () const
 Must this function be called via .Internal()?
const char * typeName () const
 Name within R of this type of object.
RObjectapply (ArgList *arglist, Environment *env, const Expression *call) const
 Apply the function.
- Public Member Functions inherited from CXXR::FunctionBase
void maybeTrace (const Expression *call) const
 Produce a tracing report if appropriate.
void setTracing (bool on)
 Set tracing status.
bool traced () const
 Is this function being traced?
- Public Member Functions inherited from CXXR::RObject
virtual const PairListattributes () const
 Get object attributes.
virtual void clearAttributes ()
 Remove all attributes.
virtual RObjectclone () const
 Return pointer to a copy of this object.
void copyAttribute (const Symbol *name, const RObject *source)
 Copy an attribute from one RObject to another.
void copyAttributes (const RObject *source, bool copyS4)
 Copy attributes from one RObject to another.
virtual RObjectevaluate (Environment *env)
 Evaluate object in a specified Environment.
virtual RObjectgetAttribute (const Symbol *name) const
 Get the value a particular attribute.
virtual bool hasAttributes () const
 Has this object any attributes?
bool hasClass () const
 Has this object the class attribute?
bool isS4Object () const
 Is this an S4 object?
void maybeTraceMemory (const RObject *src)
 Carry out memory tracing.
void maybeTraceMemory (const RObject *src1, const RObject *src2)
 Carry out memory tracing.
void maybeTraceMemory (const RObject *src1, const RObject *src2, const RObject *src3)
 Carry out memory tracing.
bool memoryTraced () const
 Is copying etc. of this object being traced?
virtual unsigned int packGPBits () const
 Reproduce the gp bits field used in CR.
virtual void setAttribute (const Symbol *name, RObject *value)
 Set or remove an attribute.
void setAttributes (const PairList *new_attributes)
 Replace the attributes of an object.
void setMemoryTracing (bool on)
 Enable/disable tracing of copying etc.
void setS4Object (bool on)
 Set the status of this RObject as an S4 object.
SEXPTYPE sexptype () const
 Get an object's SEXPTYPE.
virtual void unpackGPBits (unsigned int gpbits)
 Interpret the gp bits field used in CR.
void detachReferents ()
 Null out all references from this node to other nodes.
void visitReferents (const_visitor *v) const
 Conduct a visitor to the nodes referred to by this one.
- Public Member Functions inherited from CXXR::GCNode
void expose () const
 Record that construction of a node is complete.
bool isExposed () const
 Has this node been exposed to garbage collection?

Static Public Member Functions

static BuiltInFunctionobtain (const std::string &name)
 Get a pointer to a BuiltInFunction object.
static const char * staticTypeName ()
 The names by which this type is known in R.
- Static Public Member Functions inherited from CXXR::FunctionBase
static void enableTracing (bool on)
 Enable/disable function tracing.
static bool isA (const RObject *obj)
 Is an RObject a FunctionBase?
static bool tracingEnabled ()
 If function tracing currently enabled?
- Static Public Member Functions inherited from CXXR::RObject
template<class T >
static T * clone (const T *pattern)
 Return a pointer to a copy of an object.
- Static Public Member Functions inherited from CXXR::GCNode
static void * operator new (size_t bytes)
 Allocate memory.
static void * operator new (size_t, void *where)
 Placement new for GCNode.
static void operator delete (void *p, size_t bytes)
 Deallocate memory.
static bool check ()
 Integrity check.
template<class T >
static T * expose (T *node)
 Record that construction of a node is complete.
static void gc ()
 Initiate a garbage collection.
static void gclite ()
 Lightweight garbage collection.
static void maybeCheckExposed (const GCNode *node)
 Subject to configuration, check that a GCNode is exposed.
static size_t numNodes ()
 Number of GCNode objects in existence.

Friends

class boost::serialization::access
class SchwarzCounter< BuiltInFunction >

Additional Inherited Members

- Protected Member Functions inherited from CXXR::FunctionBase
 FunctionBase (SEXPTYPE stype)
 FunctionBase (const FunctionBase &pattern)
 Copy constructor.
- Protected Member Functions inherited from CXXR::RObject
 RObject (SEXPTYPE stype=CXXSXP)
 RObject (const RObject &pattern)
 Copy constructor.
- Protected Member Functions inherited from CXXR::GCNode
virtual ~GCNode ()

Detailed Description

R function implemented within the interpreter.

A BuiltInFunction object represents an R function that is implemented within the interpreter by a function in C++ or C. These objects are of two kinds, according to whether the arguments passed to BuiltInFunction::apply() are evaluated before being passed on to the encapsulated C/C++ function (CR's BUILTINSXP), or are passed on unevaluated (SPECIALSXP).

A BuiltInFunction object is implemented essentially as an offset into a table of function information, which in CXXR is a private static member (s_function_table) of this class.


Member Function Documentation

RObject * BuiltInFunction::apply ( ArgList arglist,
Environment env,
const Expression call 
) const
virtual

Apply the function.

Parameters:
arglistNon-null pointer to the ArgList containing the list of arguments with which the function is to be invoked.
envPointer to the Environment in which the function is to be evaluated.
callPointer to the Expression calling the function.
Returns:
The result of applying the function.

Implements CXXR::FunctionBase.

int CXXR::BuiltInFunction::arity ( ) const
inline

'Arity' of the function.

Returns:
The number of arguments expected by the function. A return value of -1 signifies that any number of arguments is acceptable.
void BuiltInFunction::checkNumArgs ( const PairList args,
const Expression call 
) const

Report error if argument list is wrong length.

This function raises an error if args is not of a permissible length for all call to this BuiltInFunction.

Parameters:
argsArgument list to be checked, possibly null.
callThe call being processed (for error reporting).
Note:
This would be called checkArity(), except that in code inherited from CR this would get macro-expanded to Rf_checkArityCall.
CCODE CXXR::BuiltInFunction::function ( ) const
inline

C/C++ function implementing this R function.

Returns:
Pointer to the C/C++ function implementing this R function.
Kind CXXR::BuiltInFunction::kind ( ) const
inline

Kind of built-in function.

(Used mainly in deparsing.)

Returns:
The Kind of the function.
const char* CXXR::BuiltInFunction::name ( ) const
inline

Name of function.

Returns:
The textual name of this function.
BuiltInFunction * BuiltInFunction::obtain ( const std::string &  name)
static

Get a pointer to a BuiltInFunction object.

If name is not the name of a built-in function this function will raise a warning and return a null pointer. Otherwise the function will return a pointer to the (unique) BuiltInFunction object embodying that function. If no such object already exists, one will be created.

Parameters:
nameThe name of the built-in function.
Returns:
a pointer to the BuiltInFunction object representing the function with the specified name, or a null pointer if name is not the name of a built-in function.
Note:
The reason this function raises a warning and not an error if passed an inappropriate name is so that loading an archive will not fail completely simply because it refers to an obsolete built-in function.
unsigned int CXXR::BuiltInFunction::offset ( ) const
inline

Get table offset.

Returns:
The offset into the table of functions.
Precedence CXXR::BuiltInFunction::precedence ( ) const
inline

Precedence of built-in function.

Returns:
The Precedence of the function.
int CXXR::BuiltInFunction::printHandling ( ) const
inline

(Not for general use.)

This function is used to implement PRIMPRINT, and is likely to be removed in future refactorisation.

Returns:
Code for handling R_Visible within the function, as documented in names.cpp for the eval field of the function table.
bool CXXR::BuiltInFunction::rightAssociative ( ) const
inline

Is a built-in function right-associative?

Returns:
true iff the function is right-associative.
static const char* CXXR::BuiltInFunction::staticTypeName ( )
inlinestatic

The names by which this type is known in R.

Returns:
The names by which this type is known in R.

Reimplemented from CXXR::FunctionBase.

const char * BuiltInFunction::typeName ( ) const
virtual

Name within R of this type of object.

Returns:
the name by which this type of object is known within R.

Reimplemented from CXXR::RObject.

unsigned int CXXR::BuiltInFunction::variant ( ) const
inline

Index of variant behaviour.

Where a single C/C++ function implements more than one built-in R function, this function provides the C/C++ code with an index indicating which R function is to be implemented.

Returns:
index of the required behaviour; interpretation is up to the C/C++ function called.
bool CXXR::BuiltInFunction::viaDotInternal ( ) const
inline

Must this function be called via .Internal()?

Returns:
true iff this function must be called via .Internal()?

The documentation for this class was generated from the following files: