Macros to be inserted by the Scanner

Jonathan Poole

For a class, the scanner generates code as follows:

  1. All classes that are to be UC++ classes have UCPP added as a virtual, public base class.

  2. Each public constructor has a macro inserted as the first line of its body as follows

      CONSTRUCTOR_N(id, classname, param type, param name, ...)
    

    where

  3. Each public member function has a macro inserted as the first line of its body as follows.

    where the meanings are as for the constructor, but with the addition of the return type for the non-void function.

  4. Each UCPP class has the macro UCPP_CLASS(classname) declared at file scope (outside the class body)

  5. For each constructor and function of the class, there is a HOOK function called at file scope with the form

    HOOK_<macro-form-in-class>
    

The easiest way to illustrate all this is with an example, as shown below.

class MyClass : public virtual UCPP {
public:
  MyClass()
  {
    C0NSTRUCTOR_0(1,MyClass);
    ...code...
  }

  MyClass(int i)
  {
    CONSTRUCTOR_1(2,MyClass,int,i);
    ...code...
  }
 
  void doWork()
  {
    FUNCTION_VOID_0(3,MyClass,doWork);
    ...code...
  }

  myType somethingElse(const char* x, double d)
  {
    FUNCTION_2(4,MyClass,somethingElse,myType,const char *,x,double,d);
    ...code...
  }
private:
  ...code...
};

UCPP_CLASS(MyClass)
HOOK_CONSTRUCTOR_0(1,MyClass)
HOOK_CONSTRUCTOR_1(2,MyClass,int,i)
HOOK_FUNCTION_VOID_0(3,MyClass,doWork)
HOOK_FUNCTION_2(4,MyClass,somethingElse,myType,const char *,x,double,d)

Special Cases

Template parameters

The C/C++ preprocessor is not template aware. Parameter arguments to a macro cannot contain commas, so the macro call

  MACRO_CALL(PAIR<int, double>);
is treated as a two paramter call to MACRO_CALL, the first parameter being ` PAIR<int' and the second ` double>'. To get round this I have defined a macro COMMA that could be used as follows:

  MACRO_CALL(PAIR<int COMMA double>);

All type name containing comma (i.e. paramterized types with two or more parameters) need to have their commas replaced by the macro COMMA inside the calls to all macros.

Dealing with private and protected member functions

There is a problem with private and protected member functions. The hook function will not have permission to call the private and protected method on the remote object. We need therefore to either use the friend notation to create each hook for a private or protected member a friend (will mean putting an extra macro in for each member function) or fobid the calling of private members on remote objects.

Is there a better alternative, such as going via a template function (a 'FunctionCaller') that takes an arbitary function name and set of parameters and calls that function with those parameters. This template function could be declared a friend of the class UCPP. This would seem to give the possibility of getting round the protection without requiring any extra work from the scanner.

About this document ...

Macros to be inserted by the Scanner

This document was generated using the LaTeX2HTML translator Version 95.1 (Fri Jan 20 1995) Copyright © 1993, 1994, Nikos Drakos, Computer Based Learning Unit, University of Leeds.

The command line arguments were:
latex2html -split 0 -link 3 -address scanner.tex.

The translation was initiated by Jonathan Poole on Mon Jul 3 11:25:36 BST 1995