123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- {
- $Id$
- This file is part of the Free Pascal run time library.
- Copyright (c) 1997,98 by Florian Klaempfl
- member of the Free Pascal development team
- See the file COPYING.FPC, included in this distribution,
- for details about the copyright.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- **********************************************************************}
- {***********************************************************************
- This file includes the system and processor independed
- implementations of some Object Pascal features
- This file is intended to be used with Free Pascal and should be
- included in the system unit.
- ***********************************************************************}
- {************************************************************************}
- { misc. routines }
- {************************************************************************}
- { the reverse order of the parameters make code generation easier }
- function _is(aclass : tclass;aobject : tobject) : boolean;[public,alias: 'DO_IS'];
- begin
- _is:=aobject.inheritsfrom(aclass);
- end;
- { the reverse order of the parameters make code generation easier }
- procedure _as(aclass : tclass;aobject : tobject);[public,alias: 'DO_AS'];
- begin
- if assigned(aobject) and not(aobject.inheritsfrom(aclass)) then
- { throw an exception }
- end;
- procedure abstracterror;[public,alias: 'ABSTRACTERROR'];
- type
- proc = procedure;
- begin
- if assigned(abstracterrorproc) then
- proc(abstracterrorproc)()
- else
- runerror(210);
- end;
- {************************************************************************}
- { TOBJECT }
- {************************************************************************}
- constructor tobject.create;
- begin
- end;
- destructor tobject.destroy;
- begin
- end;
- procedure tobject.free;
- begin
- if self<>nil then
- destroy;
- end;
- class function tobject.instancesize : longint;
- type
- plongint = ^longint;
- begin
- { type of self is class of tobject => it points to the vmt }
- { the size is saved at offset 0 }
- instancesize:=plongint(self)^;
- end;
- class function tobject.initinstance(instance : pointer) : tobject;
- type
- ppointer = ^pointer;
- begin
- fillchar(instance^,self.instancesize,0);
- { insert VMT pointer into the new created memory area }
- { (in class methods self contains the VMT!) }
- ppointer(instance)^:=pointer(self);
- initinstance:=tobject(instance);
- end;
- class function tobject.classparent : tclass;
- type
- ptclass = ^tclass;
- begin
- { type of self is class of tobject => it points to the vmt }
- { the parent vmt is saved at offset 8 }
- classparent:=(ptclass(self)+8)^;
- end;
- class function tobject.newinstance : tobject;
- var
- p : pointer;
- begin
- getmem(p,instancesize);
- initinstance(p);
- newinstance:=tobject(p);
- end;
- procedure tobject.freeinstance;
- var
- p : pointer;
- begin
- { !!! we should finalize some data }
- { self is a register, so we can't pass it call by reference }
- p:=pointer(self);
- freemem(p,instancesize);
- end;
- function tobject.classtype : tclass;
- begin
- classtype:=tclass(pointer(self)^)
- end;
- class function tobject.methodaddress(const name : shortstring) : pointer;
- begin
- end;
- class function tobject.methodname(address : pointer) : shortstring;
- begin
- end;
- function tobject.fieldaddress(const name : shortstring) : pointer;
- begin
- end;
- function tobject.safecallexception(exceptobject : tobject;
- exceptaddr : pointer) : integer;
- begin
- end;
- class function tobject.classinfo : pointer;
- begin
- end;
- class function tobject.classname : shortstring;
- begin
- end;
- class function tobject.classnameis(const name : string) : boolean;
- begin
- end;
- class function tobject.inheritsfrom(aclass : tclass) : boolean;
- var
- c : tclass;
- begin
- c:=self;
- while assigned(c) do
- begin
- if c=aclass then
- begin
- inheritsfrom:=true;
- exit;
- end;
- c:=c.classparent;
- end;
- inheritsfrom:=false;
- end;
- procedure tobject.dispatch(var message);
- begin
- end;
- procedure tobject.defaulthandler(var message);
- begin
- end;
- procedure tobject.cleanupinstance;
- begin
- end;
- {
- $Log$
- Revision 1.1 1998-03-25 11:18:43 root
- Initial revision
- Revision 1.9 1998/02/03 22:12:25 florian
- + helper routines for is and as
- * fix of tobject.classparent
- + tobject.inheritsfrom
- Revision 1.8 1998/01/27 22:05:09 florian
- * again small fixes to DOM (Delphi Object Model)
- Revision 1.7 1998/01/26 12:00:18 michael
- + Added log at the end
-
- Working file: rtl/inc/objpas.inc
- description:
- ----------------------------
- revision 1.6
- date: 1998/01/25 22:30:49; author: florian; state: Exp; lines: +3 -3
- * DOM: some fixes to tobject and the con-/destructor help routines
- ----------------------------
- revision 1.5
- date: 1998/01/23 18:08:31; author: florian; state: Exp; lines: +19 -6
- * more bugs in FCL object model removed
- ----------------------------
- revision 1.4
- date: 1998/01/23 10:48:32; author: florian; state: Exp; lines: +63 -7
- * syntax errors fixed
- + implementation of all methods added, at least with empty body
- ----------------------------
- revision 1.3
- date: 1998/01/16 23:10:53; author: florian; state: Exp; lines: +19 -1
- + some tobject stuff
- ----------------------------
- revision 1.2
- date: 1998/01/10 11:08:58; author: florian; state: Exp; lines: +53 -1
- + start of tobject impkentations
- ----------------------------
- revision 1.1
- date: 1998/01/09 16:05:43; author: florian; state: Exp;
- + ojbpash.inc and objpas.inc
- * $E- from objects.pp removed to avoid a warning
- =============================================================================
- }
|