system.pp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2006 by Florian Klaempfl
  4. member of the Free Pascal development team.
  5. System unit for embedded systems
  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. Unit system;
  13. {$namespace org.freepascal.rtl}
  14. {*****************************************************************************}
  15. interface
  16. {*****************************************************************************}
  17. {$define FPC_IS_SYSTEM}
  18. {$I-,Q-,H-,R-,V-,P+,T+}
  19. {$implicitexceptions off}
  20. {$mode objfpc}
  21. {$undef FPC_HAS_FEATURE_ANSISTRINGS}
  22. {$undef FPC_HAS_FEATURE_TEXTIO}
  23. {$undef FPC_HAS_FEATURE_VARIANTS}
  24. {$undef FPC_HAS_FEATURE_CLASSES}
  25. {$undef FPC_HAS_FEATURE_EXCEPTIONS}
  26. {$undef FPC_HAS_FEATURE_OBJECTS}
  27. {$undef FPC_HAS_FEATURE_RTTI}
  28. {$undef FPC_HAS_FEATURE_FILEIO}
  29. {$undef FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE}
  30. Type
  31. { The compiler has all integer types defined internally. Here
  32. we define only aliases }
  33. DWord = LongWord;
  34. Cardinal = LongWord;
  35. Integer = SmallInt;
  36. UInt64 = QWord;
  37. SizeInt = Longint;
  38. SizeUInt = Longint;
  39. PtrInt = Longint;
  40. PtrUInt = Longint;
  41. ValReal = Double;
  42. AnsiChar = Char;
  43. UnicodeChar = WideChar;
  44. { map comp to int64 }
  45. Comp = Int64;
  46. HResult = type longint;
  47. PShortString = ^ShortString;
  48. { Java primitive types }
  49. jboolean = boolean;
  50. jbyte = shortint;
  51. jshort = smallint;
  52. jint = longint;
  53. jlong = int64;
  54. jchar = widechar;
  55. jfloat = single;
  56. jdouble = double;
  57. Arr1jboolean = array of jboolean;
  58. Arr1jbyte = array of jbyte;
  59. Arr1jshort = array of jshort;
  60. Arr1jint = array of jint;
  61. Arr1jlong = array of jlong;
  62. Arr1jchar = array of jchar;
  63. Arr1jfloat = array of jfloat;
  64. Arr1jdouble = array of jdouble;
  65. Arr2jboolean = array of Arr1jboolean;
  66. Arr2jbyte = array of Arr1jbyte;
  67. Arr2jshort = array of Arr1jshort;
  68. Arr2jint = array of Arr1jint;
  69. Arr2jlong = array of Arr1jlong;
  70. Arr2jchar = array of Arr1jchar;
  71. Arr2jfloat = array of Arr1jfloat;
  72. Arr2jdouble = array of Arr1jdouble;
  73. Arr3jboolean = array of Arr2jboolean;
  74. Arr3jbyte = array of Arr2jbyte;
  75. Arr3jshort = array of Arr2jshort;
  76. Arr3jint = array of Arr2jint;
  77. Arr3jlong = array of Arr2jlong;
  78. Arr3jchar = array of Arr2jchar;
  79. Arr3jfloat = array of Arr2jfloat;
  80. Arr3jdouble = array of Arr2jdouble;
  81. const
  82. { max. values for longint and int}
  83. maxLongint = $7fffffff;
  84. maxSmallint = 32767;
  85. maxint = maxsmallint;
  86. { Java base class type }
  87. {$i java_sysh.inc}
  88. {$i java_sys.inc}
  89. type
  90. TObject = class(JLObject)
  91. strict private
  92. DestructorCalled: Boolean;
  93. public
  94. procedure Free;
  95. destructor Destroy; virtual;
  96. procedure finalize; override;
  97. end;
  98. FpcEnumValueObtainable = interface
  99. function fpcOrdinal: jint;
  100. function fpcGenericValueOf(__fpc_int: longint): JLEnum;
  101. end;
  102. {$i innr.inc}
  103. {$i jmathh.inc}
  104. {$i jrech.inc}
  105. {$i jseth.inc}
  106. {$i sstringh.inc}
  107. {$i jpvarh.inc}
  108. {$i jdynarrh.inc}
  109. {$i astringh.inc}
  110. {$ifndef nounsupported}
  111. const
  112. vtInteger = 0;
  113. vtBoolean = 1;
  114. vtChar = 2;
  115. {$ifndef FPUNONE}
  116. vtExtended = 3;
  117. {$endif}
  118. vtString = 4;
  119. vtPointer = 5;
  120. vtPChar = 6;
  121. vtObject = 7;
  122. vtClass = 8;
  123. vtWideChar = 9;
  124. vtPWideChar = 10;
  125. vtAnsiString = 11;
  126. vtCurrency = 12;
  127. vtVariant = 13;
  128. vtInterface = 14;
  129. vtWideString = 15;
  130. vtInt64 = 16;
  131. vtQWord = 17;
  132. vtUnicodeString = 18;
  133. type
  134. TVarRec = record
  135. case VType : sizeint of
  136. {$ifdef ENDIAN_BIG}
  137. vtInteger : ({$IFDEF CPU64}integerdummy1 : Longint;{$ENDIF CPU64}VInteger: Longint);
  138. vtBoolean : ({$IFDEF CPU64}booldummy : Longint;{$ENDIF CPU64}booldummy1,booldummy2,booldummy3: byte; VBoolean: Boolean);
  139. vtChar : ({$IFDEF CPU64}chardummy : Longint;{$ENDIF CPU64}chardummy1,chardummy2,chardummy3: byte; VChar: Char);
  140. vtWideChar : ({$IFDEF CPU64}widechardummy : Longint;{$ENDIF CPU64}wchardummy1,VWideChar: WideChar);
  141. {$else ENDIAN_BIG}
  142. vtInteger : (VInteger: Longint);
  143. vtBoolean : (VBoolean: Boolean);
  144. vtChar : (VChar: Char);
  145. vtWideChar : (VWideChar: WideChar);
  146. {$endif ENDIAN_BIG}
  147. // vtString : (VString: PShortString);
  148. // vtPointer : (VPointer: Pointer);
  149. /// vtPChar : (VPChar: PChar);
  150. vtObject : (VObject: TObject);
  151. // vtClass : (VClass: TClass);
  152. // vtPWideChar : (VPWideChar: PWideChar);
  153. vtAnsiString : (VAnsiString: JLObject);
  154. vtCurrency : (VCurrency: Currency);
  155. // vtVariant : (VVariant: PVariant);
  156. vtInterface : (VInterface: JLObject);
  157. vtWideString : (VWideString: JLString);
  158. vtInt64 : (VInt64: Int64);
  159. vtUnicodeString : (VUnicodeString: JLString);
  160. vtQWord : (VQWord: QWord);
  161. end;
  162. {$endif}
  163. Function lo(i : Integer) : byte; [INTERNPROC: fpc_in_lo_Word];
  164. Function lo(w : Word) : byte; [INTERNPROC: fpc_in_lo_Word];
  165. Function lo(l : Longint) : Word; [INTERNPROC: fpc_in_lo_long];
  166. Function lo(l : DWord) : Word; [INTERNPROC: fpc_in_lo_long];
  167. Function lo(i : Int64) : DWord; [INTERNPROC: fpc_in_lo_qword];
  168. Function lo(q : QWord) : DWord; [INTERNPROC: fpc_in_lo_qword];
  169. Function hi(i : Integer) : byte; [INTERNPROC: fpc_in_hi_Word];
  170. Function hi(w : Word) : byte; [INTERNPROC: fpc_in_hi_Word];
  171. Function hi(l : Longint) : Word; [INTERNPROC: fpc_in_hi_long];
  172. Function hi(l : DWord) : Word; [INTERNPROC: fpc_in_hi_long];
  173. Function hi(i : Int64) : DWord; [INTERNPROC: fpc_in_hi_qword];
  174. Function hi(q : QWord) : DWord; [INTERNPROC: fpc_in_hi_qword];
  175. Function chr(b : byte) : AnsiChar; [INTERNPROC: fpc_in_chr_byte];
  176. function RorByte(Const AValue : Byte): Byte;[internproc:fpc_in_ror_x];
  177. function RorByte(Const AValue : Byte;Dist : Byte): Byte;[internproc:fpc_in_ror_x_x];
  178. function RolByte(Const AValue : Byte): Byte;[internproc:fpc_in_rol_x];
  179. function RolByte(Const AValue : Byte;Dist : Byte): Byte;[internproc:fpc_in_rol_x_x];
  180. function RorWord(Const AValue : Word): Word;[internproc:fpc_in_ror_x];
  181. function RorWord(Const AValue : Word;Dist : Byte): Word;[internproc:fpc_in_ror_x_x];
  182. function RolWord(Const AValue : Word): Word;[internproc:fpc_in_rol_x];
  183. function RolWord(Const AValue : Word;Dist : Byte): Word;[internproc:fpc_in_rol_x_x];
  184. function RorDWord(Const AValue : DWord): DWord;[internproc:fpc_in_ror_x];
  185. function RorDWord(Const AValue : DWord;Dist : Byte): DWord;[internproc:fpc_in_ror_x_x];
  186. function RolDWord(Const AValue : DWord): DWord;[internproc:fpc_in_rol_x];
  187. function RolDWord(Const AValue : DWord;Dist : Byte): DWord;[internproc:fpc_in_rol_x_x];
  188. function RorQWord(Const AValue : QWord): QWord;[internproc:fpc_in_ror_x];
  189. function RorQWord(Const AValue : QWord;Dist : Byte): QWord;[internproc:fpc_in_ror_x_x];
  190. function RolQWord(Const AValue : QWord): QWord;[internproc:fpc_in_rol_x];
  191. function RolQWord(Const AValue : QWord;Dist : Byte): QWord;[internproc:fpc_in_rol_x_x];
  192. function SarShortint(Const AValue : Shortint): Shortint;[internproc:fpc_in_sar_x];
  193. function SarShortint(Const AValue : Shortint;Shift : Byte): Shortint;[internproc:fpc_in_sar_x_y];
  194. function SarSmallint(Const AValue : Smallint): Smallint;[internproc:fpc_in_sar_x];
  195. function SarSmallint(Const AValue : Smallint;Shift : Byte): Smallint;[internproc:fpc_in_sar_x_y];
  196. function SarLongint(Const AValue : Longint): Longint;[internproc:fpc_in_sar_x];
  197. function SarLongint(Const AValue : Longint;Shift : Byte): Longint;[internproc:fpc_in_sar_x_y];
  198. function SarInt64(Const AValue : Int64): Int64;[internproc:fpc_in_sar_x];
  199. function SarInt64(Const AValue : Int64;Shift : Byte): Int64;[internproc:fpc_in_sar_x_y];
  200. {$i compproc.inc}
  201. {$i ustringh.inc}
  202. {*****************************************************************************}
  203. implementation
  204. {*****************************************************************************}
  205. {i jdynarr.inc}
  206. {
  207. This file is part of the Free Pascal run time library.
  208. Copyright (c) 2011 by Jonas Maebe
  209. member of the Free Pascal development team.
  210. This file implements the helper routines for dyn. Arrays in FPC
  211. See the file COPYING.FPC, included in this distribution,
  212. for details about the copyright.
  213. This program is distributed in the hope that it will be useful,
  214. but WITHOUT ANY WARRANTY; without even the implied warranty of
  215. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  216. **********************************************************************
  217. }
  218. function min(a,b : longint) : longint;
  219. begin
  220. if a<=b then
  221. min:=a
  222. else
  223. min:=b;
  224. end;
  225. {$i sstrings.inc}
  226. {$i astrings.inc}
  227. {$i ustrings.inc}
  228. {$i rtti.inc}
  229. {$i jrec.inc}
  230. {$i jset.inc}
  231. {$i jint64.inc}
  232. {$i jpvar.inc}
  233. { copying helpers }
  234. procedure fpc_copy_shallow_array(src, dst: JLObject; srcstart: jint = -1; srccopylen: jint = -1);
  235. var
  236. srclen, dstlen: jint;
  237. begin
  238. if assigned(src) then
  239. srclen:=JLRArray.getLength(src)
  240. else
  241. srclen:=0;
  242. if assigned(dst) then
  243. dstlen:=JLRArray.getLength(dst)
  244. else
  245. dstlen:=0;
  246. if srcstart=-1 then
  247. srcstart:=0
  248. else if srcstart>=srclen then
  249. exit;
  250. if srccopylen=-1 then
  251. srccopylen:=srclen
  252. else if srcstart+srccopylen>srclen then
  253. srccopylen:=srclen-srcstart;
  254. { causes exception in JLSystem.arraycopy }
  255. if (srccopylen=0) or
  256. (dstlen=0) then
  257. exit;
  258. JLSystem.arraycopy(src,srcstart,dst,0,min(srccopylen,dstlen));
  259. end;
  260. procedure fpc_copy_jrecord_array(src, dst: TJRecordArray; srcstart: jint = -1; srccopylen: jint = -1);
  261. var
  262. i: longint;
  263. srclen, dstlen: jint;
  264. begin
  265. srclen:=length(src);
  266. dstlen:=length(dst);
  267. if srcstart=-1 then
  268. srcstart:=0
  269. else if srcstart>=srclen then
  270. exit;
  271. if srccopylen=-1 then
  272. srccopylen:=srclen
  273. else if srcstart+srccopylen>srclen then
  274. srccopylen:=srclen-srcstart;
  275. { no arraycopy, have to clone each element }
  276. for i:=0 to min(srccopylen,dstlen)-1 do
  277. src[srcstart+i].fpcDeepCopy(dst[i]);
  278. end;
  279. procedure fpc_copy_jenumset_array(src, dst: TJEnumSetArray; srcstart: jint = -1; srccopylen: jint = -1);
  280. var
  281. i: longint;
  282. srclen, dstlen: jint;
  283. begin
  284. srclen:=length(src);
  285. dstlen:=length(dst);
  286. if srcstart=-1 then
  287. srcstart:=0
  288. else if srcstart>=srclen then
  289. exit;
  290. if srccopylen=-1 then
  291. srccopylen:=srclen
  292. else if srcstart+srccopylen>srclen then
  293. srccopylen:=srclen-srcstart;
  294. { no arraycopy, have to clone each element }
  295. for i:=0 to min(srccopylen,dstlen)-1 do
  296. begin
  297. dst[i].clear;
  298. dst[i].addAll(src[srcstart+i]);
  299. end;
  300. end;
  301. procedure fpc_copy_jbitset_array(src, dst: TJBitSetArray; srcstart: jint = -1; srccopylen: jint = -1);
  302. var
  303. i: longint;
  304. srclen, dstlen: jint;
  305. begin
  306. srclen:=length(src);
  307. dstlen:=length(dst);
  308. if srcstart=-1 then
  309. srcstart:=0
  310. else if srcstart>=srclen then
  311. exit;
  312. if srccopylen=-1 then
  313. srccopylen:=srclen
  314. else if srcstart+srccopylen>srclen then
  315. srccopylen:=srclen-srcstart;
  316. { no arraycopy, have to clone each element }
  317. for i:=0 to min(srccopylen,dstlen)-1 do
  318. begin
  319. dst[i].clear;
  320. dst[i].addAll(src[srcstart+i]);
  321. end;
  322. end;
  323. procedure fpc_copy_jprocvar_array(src, dst: TJProcVarArray; srcstart: jint = -1; srccopylen: jint = -1);
  324. var
  325. i: longint;
  326. srclen, dstlen: jint;
  327. begin
  328. srclen:=length(src);
  329. dstlen:=length(dst);
  330. if srcstart=-1 then
  331. srcstart:=0
  332. else if srcstart>=srclen then
  333. exit;
  334. if srccopylen=-1 then
  335. srccopylen:=srclen
  336. else if srcstart+srccopylen>srclen then
  337. srccopylen:=srclen-srcstart;
  338. { no arraycopy, have to clone each element }
  339. for i:=0 to min(srccopylen,dstlen)-1 do
  340. src[srcstart+i].fpcDeepCopy(dst[i]);
  341. end;
  342. procedure fpc_copy_jshortstring_array(src, dst: TShortstringArray; srcstart: jint = -1; srccopylen: jint = -1);
  343. var
  344. i: longint;
  345. srclen, dstlen: jint;
  346. begin
  347. srclen:=length(src);
  348. dstlen:=length(dst);
  349. if srcstart=-1 then
  350. srcstart:=0
  351. else if srcstart>=srclen then
  352. exit;
  353. if srccopylen=-1 then
  354. srccopylen:=srclen
  355. else if srcstart+srccopylen>srclen then
  356. srccopylen:=srclen-srcstart;
  357. { no arraycopy, have to clone each element }
  358. for i:=0 to min(srccopylen,dstlen)-1 do
  359. pshortstring(src[srcstart+i])^:=pshortstring(dst[i])^;
  360. end;
  361. { 1-dimensional setlength routines }
  362. function fpc_setlength_dynarr_generic(aorg, anew: JLObject; deepcopy: boolean; docopy: boolean = true): JLObject;
  363. var
  364. orglen, newlen: jint;
  365. begin
  366. orglen:=0;
  367. newlen:=0;
  368. if not deepcopy then
  369. begin
  370. if assigned(aorg) then
  371. orglen:=JLRArray.getLength(aorg)
  372. else
  373. orglen:=0;
  374. if assigned(anew) then
  375. newlen:=JLRArray.getLength(anew)
  376. else
  377. newlen:=0;
  378. end;
  379. if deepcopy or
  380. (orglen<>newlen) then
  381. begin
  382. if docopy then
  383. fpc_copy_shallow_array(aorg,anew);
  384. result:=anew
  385. end
  386. else
  387. result:=aorg;
  388. end;
  389. function fpc_setlength_dynarr_jrecord(aorg, anew: TJRecordArray; deepcopy: boolean): TJRecordArray;
  390. begin
  391. if deepcopy or
  392. (length(aorg)<>length(anew)) then
  393. begin
  394. fpc_copy_jrecord_array(aorg,anew);
  395. result:=anew
  396. end
  397. else
  398. result:=aorg;
  399. end;
  400. function fpc_setlength_dynarr_jenumset(aorg, anew: TJEnumSetArray; deepcopy: boolean): TJEnumSetArray;
  401. begin
  402. if deepcopy or
  403. (length(aorg)<>length(anew)) then
  404. begin
  405. fpc_copy_jenumset_array(aorg,anew);
  406. result:=anew
  407. end
  408. else
  409. result:=aorg;
  410. end;
  411. function fpc_setlength_dynarr_jbitset(aorg, anew: TJBitSetArray; deepcopy: boolean): TJBitSetArray;
  412. begin
  413. if deepcopy or
  414. (length(aorg)<>length(anew)) then
  415. begin
  416. fpc_copy_jbitset_array(aorg,anew);
  417. result:=anew
  418. end
  419. else
  420. result:=aorg;
  421. end;
  422. function fpc_setlength_dynarr_jprocvar(aorg, anew: TJProcVarArray; deepcopy: boolean): TJProcVarArray;
  423. begin
  424. if deepcopy or
  425. (length(aorg)<>length(anew)) then
  426. begin
  427. fpc_copy_jprocvar_array(aorg,anew);
  428. result:=anew
  429. end
  430. else
  431. result:=aorg;
  432. end;
  433. function fpc_setlength_dynarr_jshortstring(aorg, anew: TShortstringArray; deepcopy: boolean): TShortstringArray;
  434. begin
  435. if deepcopy or
  436. (length(aorg)<>length(anew)) then
  437. begin
  438. fpc_copy_jshortstring_array(aorg,anew);
  439. result:=anew
  440. end
  441. else
  442. result:=aorg;
  443. end;
  444. { multi-dimensional setlength routine }
  445. function fpc_setlength_dynarr_multidim(aorg, anew: TJObjectArray; deepcopy: boolean; ndim: longint; eletype: jchar): TJObjectArray;
  446. var
  447. partdone,
  448. i: longint;
  449. begin
  450. { resize the current dimension; no need to copy the subarrays of the old
  451. array, as the subarrays will be (re-)initialised immediately below }
  452. { the srcstart/srccopylen always refers to the first dimension (since copy()
  453. performs a shallow copy of a dynamic array }
  454. result:=TJObjectArray(fpc_setlength_dynarr_generic(JLObject(aorg),JLObject(anew),deepcopy,false));
  455. { if aorg was empty, there's nothing else to do since result will now
  456. contain anew, of which all other dimensions are already initialised
  457. correctly since there are no aorg elements to copy }
  458. if not assigned(aorg) and
  459. not deepcopy then
  460. exit;
  461. partdone:=min(high(result),high(aorg));
  462. { ndim must be >=2 when this routine is called, since it has to return
  463. an array of java.lang.Object! (arrays are also objects, but primitive
  464. types are not) }
  465. if ndim=2 then
  466. begin
  467. { final dimension -> copy the primitive arrays }
  468. case eletype of
  469. FPCJDynArrTypeRecord:
  470. begin
  471. for i:=low(result) to partdone do
  472. result[i]:=JLObject(fpc_setlength_dynarr_jrecord(TJRecordArray(aorg[i]),TJRecordArray(anew[i]),deepcopy));
  473. for i:=succ(partdone) to high(result) do
  474. result[i]:=JLObject(fpc_setlength_dynarr_jrecord(nil,TJRecordArray(anew[i]),deepcopy));
  475. end;
  476. FPCJDynArrTypeEnumSet:
  477. begin
  478. for i:=low(result) to partdone do
  479. result[i]:=JLObject(fpc_setlength_dynarr_jenumset(TJEnumSetArray(aorg[i]),TJEnumSetArray(anew[i]),deepcopy));
  480. for i:=succ(partdone) to high(result) do
  481. result[i]:=JLObject(fpc_setlength_dynarr_jenumset(nil,TJEnumSetArray(anew[i]),deepcopy));
  482. end;
  483. FPCJDynArrTypeBitSet:
  484. begin
  485. for i:=low(result) to partdone do
  486. result[i]:=JLObject(fpc_setlength_dynarr_jbitset(TJBitSetArray(aorg[i]),TJBitSetArray(anew[i]),deepcopy));
  487. for i:=succ(partdone) to high(result) do
  488. result[i]:=JLObject(fpc_setlength_dynarr_jbitset(nil,TJBitSetArray(anew[i]),deepcopy));
  489. end;
  490. FPCJDynArrTypeProcVar:
  491. begin
  492. for i:=low(result) to partdone do
  493. result[i]:=JLObject(fpc_setlength_dynarr_jprocvar(TJProcVarArray(aorg[i]),TJProcVarArray(anew[i]),deepcopy));
  494. for i:=succ(partdone) to high(result) do
  495. result[i]:=JLObject(fpc_setlength_dynarr_jprocvar(nil,TJProcVarArray(anew[i]),deepcopy));
  496. end;
  497. FPCJDynArrTypeShortstring:
  498. begin
  499. for i:=low(result) to partdone do
  500. result[i]:=JLObject(fpc_setlength_dynarr_jshortstring(TShortstringArray(aorg[i]),TShortstringArray(anew[i]),deepcopy));
  501. for i:=succ(partdone) to high(result) do
  502. result[i]:=JLObject(fpc_setlength_dynarr_jshortstring(nil,TShortstringArray(anew[i]),deepcopy));
  503. end;
  504. else
  505. begin
  506. for i:=low(result) to partdone do
  507. result[i]:=fpc_setlength_dynarr_generic(aorg[i],anew[i],deepcopy);
  508. for i:=succ(partdone) to high(result) do
  509. result[i]:=fpc_setlength_dynarr_generic(nil,anew[i],deepcopy);
  510. end;
  511. end;
  512. end
  513. else
  514. begin
  515. { recursively handle the next dimension }
  516. for i:=low(result) to partdone do
  517. result[i]:=JLObject(fpc_setlength_dynarr_multidim(TJObjectArray(aorg[i]),TJObjectArray(anew[i]),deepcopy,pred(ndim),eletype));
  518. for i:=succ(partdone) to high(result) do
  519. result[i]:=JLObject(fpc_setlength_dynarr_multidim(nil,TJObjectArray(anew[i]),deepcopy,pred(ndim),eletype));
  520. end;
  521. end;
  522. function fpc_dynarray_copy(src: JLObject; start, len: longint; ndim: longint; eletype: jchar): JLObject;
  523. var
  524. i: longint;
  525. srclen: longint;
  526. begin
  527. if not assigned(src) then
  528. begin
  529. result:=nil;
  530. exit;
  531. end;
  532. srclen:=JLRArray.getLength(src);
  533. if (start=-1) and
  534. (len=-1) then
  535. begin
  536. len:=srclen;
  537. start:=0;
  538. end
  539. else if (start+len>srclen) then
  540. len:=srclen-start+1;
  541. result:=JLRArray.newInstance(src.getClass.getComponentType,len);
  542. if ndim=1 then
  543. begin
  544. case eletype of
  545. FPCJDynArrTypeRecord:
  546. fpc_copy_jrecord_array(TJRecordArray(src),TJRecordArray(result),start,len);
  547. FPCJDynArrTypeEnumSet:
  548. fpc_copy_jenumset_array(TJEnumSetArray(src),TJEnumSetArray(result),start,len);
  549. FPCJDynArrTypeBitSet:
  550. fpc_copy_jbitset_array(TJBitSetArray(src),TJBitSetArray(result),start,len);
  551. FPCJDynArrTypeProcvar:
  552. fpc_copy_jprocvar_array(TJProcVarArray(src),TJProcVarArray(result),start,len);
  553. FPCJDynArrTypeShortstring:
  554. fpc_copy_jshortstring_array(TShortstringArray(src),TShortstringArray(result),start,len);
  555. else
  556. fpc_copy_shallow_array(src,result,start,len);
  557. end
  558. end
  559. else
  560. begin
  561. for i:=0 to len-1 do
  562. TJObjectArray(result)[i]:=fpc_dynarray_copy(TJObjectArray(src)[start+i],-1,-1,ndim-1,eletype);
  563. end;
  564. end;
  565. {i jdynarr.inc end}
  566. {*****************************************************************************
  567. Misc. System Dependent Functions
  568. *****************************************************************************}
  569. procedure TObject.Free;
  570. begin
  571. if not DestructorCalled then
  572. begin
  573. DestructorCalled:=true;
  574. Destroy;
  575. end;
  576. end;
  577. destructor TObject.Destroy;
  578. begin
  579. end;
  580. procedure TObject.Finalize;
  581. begin
  582. Free;
  583. end;
  584. {*****************************************************************************
  585. SystemUnit Initialization
  586. *****************************************************************************}
  587. end.