{
  ex6.s

  Contents:

     1. a normal class A
     2. a shell class C whose allowed set contains A. Class C defines
        a method interceptAll that can be optimized.

  Tests:
     1. the optimized version of method interceptAll of shell class C.
        Read comments in this method for more information.

  }


reflective(shell) class A
  private:
    var i :  integer;
  public:
    proc m()
      begin
      end
    proc get() : integer
      begin
      return i;
      end
    proc put( NewI : integer )
      begin
      i = NewI;
      end
endclass


shell class C(A)
  private:
    var k : integer;
  public:
    proc interceptAll( mi : Method; vetArg : array(Object)[] ) : Object
        var obj : Object;
      begin
        { the message send below will be translated into a switch since
          the compiler knows which methods can be invoked. }
      obj = mi.invoke(self, vetArg);
      return obj;
      end
endclass



class Program
  public:
    proc run()
        var
          a : A;
          n : integer;
      begin
      a = A.new();
      a.put(4);
      a.m();
      n = a.get();
      if Reflect.attachShell(a, C.new()) == 0
      then
        a.put(5);
        a.m();
        n = a.get();
        if Reflect.removeShell(a) == 0
        then
          a.put(5);
        endif
      endif
      end
endclass


