2
0

objpas.inc 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1997,98 by Florian Klaempfl
  5. member of the Free Pascal development team
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {***********************************************************************
  13. This file includes the system and processor independed
  14. implementations of some Object Pascal features
  15. This file is intended to be used with Free Pascal and should be
  16. included in the system unit.
  17. ***********************************************************************}
  18. {************************************************************************}
  19. { misc. routines }
  20. {************************************************************************}
  21. { the reverse order of the parameters make code generation easier }
  22. function _is(aclass : tclass;aobject : tobject) : boolean;[public,alias: 'DO_IS'];
  23. begin
  24. _is:=aobject.inheritsfrom(aclass);
  25. end;
  26. { the reverse order of the parameters make code generation easier }
  27. procedure _as(aclass : tclass;aobject : tobject);[public,alias: 'DO_AS'];
  28. begin
  29. if assigned(aobject) and not(aobject.inheritsfrom(aclass)) then
  30. { throw an exception }
  31. end;
  32. procedure abstracterror;[public,alias: 'ABSTRACTERROR'];
  33. type
  34. proc = procedure;
  35. begin
  36. if assigned(abstracterrorproc) then
  37. proc(abstracterrorproc)()
  38. else
  39. runerror(210);
  40. end;
  41. {************************************************************************}
  42. { TOBJECT }
  43. {************************************************************************}
  44. constructor tobject.create;
  45. begin
  46. end;
  47. destructor tobject.destroy;
  48. begin
  49. end;
  50. procedure tobject.free;
  51. begin
  52. if self<>nil then
  53. destroy;
  54. end;
  55. class function tobject.instancesize : longint;
  56. type
  57. plongint = ^longint;
  58. begin
  59. { type of self is class of tobject => it points to the vmt }
  60. { the size is saved at offset 0 }
  61. instancesize:=plongint(self)^;
  62. end;
  63. class function tobject.initinstance(instance : pointer) : tobject;
  64. type
  65. ppointer = ^pointer;
  66. begin
  67. fillchar(instance^,self.instancesize,0);
  68. { insert VMT pointer into the new created memory area }
  69. { (in class methods self contains the VMT!) }
  70. ppointer(instance)^:=pointer(self);
  71. initinstance:=tobject(instance);
  72. end;
  73. class function tobject.classparent : tclass;
  74. type
  75. ptclass = ^tclass;
  76. begin
  77. { type of self is class of tobject => it points to the vmt }
  78. { the parent vmt is saved at offset 8 }
  79. classparent:=(ptclass(self)+8)^;
  80. end;
  81. class function tobject.newinstance : tobject;
  82. var
  83. p : pointer;
  84. begin
  85. getmem(p,instancesize);
  86. initinstance(p);
  87. newinstance:=tobject(p);
  88. end;
  89. procedure tobject.freeinstance;
  90. var
  91. p : pointer;
  92. begin
  93. { !!! we should finalize some data }
  94. { self is a register, so we can't pass it call by reference }
  95. p:=pointer(self);
  96. freemem(p,instancesize);
  97. end;
  98. function tobject.classtype : tclass;
  99. begin
  100. classtype:=tclass(pointer(self)^)
  101. end;
  102. class function tobject.methodaddress(const name : shortstring) : pointer;
  103. begin
  104. end;
  105. class function tobject.methodname(address : pointer) : shortstring;
  106. begin
  107. end;
  108. function tobject.fieldaddress(const name : shortstring) : pointer;
  109. begin
  110. end;
  111. function tobject.safecallexception(exceptobject : tobject;
  112. exceptaddr : pointer) : integer;
  113. begin
  114. end;
  115. class function tobject.classinfo : pointer;
  116. begin
  117. end;
  118. class function tobject.classname : shortstring;
  119. begin
  120. end;
  121. class function tobject.classnameis(const name : string) : boolean;
  122. begin
  123. end;
  124. class function tobject.inheritsfrom(aclass : tclass) : boolean;
  125. var
  126. c : tclass;
  127. begin
  128. c:=self;
  129. while assigned(c) do
  130. begin
  131. if c=aclass then
  132. begin
  133. inheritsfrom:=true;
  134. exit;
  135. end;
  136. c:=c.classparent;
  137. end;
  138. inheritsfrom:=false;
  139. end;
  140. procedure tobject.dispatch(var message);
  141. begin
  142. end;
  143. procedure tobject.defaulthandler(var message);
  144. begin
  145. end;
  146. procedure tobject.cleanupinstance;
  147. begin
  148. end;
  149. {
  150. $Log$
  151. Revision 1.1 1998-03-25 11:18:43 root
  152. Initial revision
  153. Revision 1.9 1998/02/03 22:12:25 florian
  154. + helper routines for is and as
  155. * fix of tobject.classparent
  156. + tobject.inheritsfrom
  157. Revision 1.8 1998/01/27 22:05:09 florian
  158. * again small fixes to DOM (Delphi Object Model)
  159. Revision 1.7 1998/01/26 12:00:18 michael
  160. + Added log at the end
  161. Working file: rtl/inc/objpas.inc
  162. description:
  163. ----------------------------
  164. revision 1.6
  165. date: 1998/01/25 22:30:49; author: florian; state: Exp; lines: +3 -3
  166. * DOM: some fixes to tobject and the con-/destructor help routines
  167. ----------------------------
  168. revision 1.5
  169. date: 1998/01/23 18:08:31; author: florian; state: Exp; lines: +19 -6
  170. * more bugs in FCL object model removed
  171. ----------------------------
  172. revision 1.4
  173. date: 1998/01/23 10:48:32; author: florian; state: Exp; lines: +63 -7
  174. * syntax errors fixed
  175. + implementation of all methods added, at least with empty body
  176. ----------------------------
  177. revision 1.3
  178. date: 1998/01/16 23:10:53; author: florian; state: Exp; lines: +19 -1
  179. + some tobject stuff
  180. ----------------------------
  181. revision 1.2
  182. date: 1998/01/10 11:08:58; author: florian; state: Exp; lines: +53 -1
  183. + start of tobject impkentations
  184. ----------------------------
  185. revision 1.1
  186. date: 1998/01/09 16:05:43; author: florian; state: Exp;
  187. + ojbpash.inc and objpas.inc
  188. * $E- from objects.pp removed to avoid a warning
  189. =============================================================================
  190. }