next up previous
Next: Dealing with private Up: The Scanner Output Previous: The Scanner Output

Macros to be inserted by the scanner

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)

This is all that needs to be added by the scanner.



send comments or suggestions to J.Poole@cs.ucl.ac.uk

Click here for more information on UCL-CS.