rtl.js 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306
  1. var pas = {};
  2. var rtl = {
  3. version: 10501,
  4. quiet: false,
  5. debug_load_units: false,
  6. debug_rtti: false,
  7. debug: function(){
  8. if (rtl.quiet || !console || !console.log) return;
  9. console.log(arguments);
  10. },
  11. error: function(s){
  12. rtl.debug('Error: ',s);
  13. throw s;
  14. },
  15. warn: function(s){
  16. rtl.debug('Warn: ',s);
  17. },
  18. checkVersion: function(v){
  19. if (rtl.version != v) throw "expected rtl version "+v+", but found "+rtl.version;
  20. },
  21. hasString: function(s){
  22. return rtl.isString(s) && (s.length>0);
  23. },
  24. isArray: function(a) {
  25. return Array.isArray(a);
  26. },
  27. isFunction: function(f){
  28. return typeof(f)==="function";
  29. },
  30. isModule: function(m){
  31. return rtl.isObject(m) && rtl.hasString(m.$name) && (pas[m.$name]===m);
  32. },
  33. isImplementation: function(m){
  34. return rtl.isObject(m) && rtl.isModule(m.$module) && (m.$module.$impl===m);
  35. },
  36. isNumber: function(n){
  37. return typeof(n)==="number";
  38. },
  39. isObject: function(o){
  40. var s=typeof(o);
  41. return (typeof(o)==="object") && (o!=null);
  42. },
  43. isString: function(s){
  44. return typeof(s)==="string";
  45. },
  46. getNumber: function(n){
  47. return typeof(n)==="number"?n:NaN;
  48. },
  49. getChar: function(c){
  50. return ((typeof(c)==="string") && (c.length===1)) ? c : "";
  51. },
  52. getObject: function(o){
  53. return ((typeof(o)==="object") || (typeof(o)==='function')) ? o : null;
  54. },
  55. isTRecord: function(type){
  56. return (rtl.isObject(type) && type.hasOwnProperty('$new') && (typeof(type.$new)==='function'));
  57. },
  58. isPasClass: function(type){
  59. return (rtl.isObject(type) && type.hasOwnProperty('$classname') && rtl.isObject(type.$module));
  60. },
  61. isPasClassInstance: function(type){
  62. return (rtl.isObject(type) && rtl.isPasClass(type.$class));
  63. },
  64. hexStr: function(n,digits){
  65. return ("000000000000000"+n.toString(16).toUpperCase()).slice(-digits);
  66. },
  67. m_loading: 0,
  68. m_loading_intf: 1,
  69. m_intf_loaded: 2,
  70. m_loading_impl: 3, // loading all used unit
  71. m_initializing: 4, // running initialization
  72. m_initialized: 5,
  73. module: function(module_name, intfuseslist, intfcode, impluseslist, implcode){
  74. if (rtl.debug_load_units) rtl.debug('rtl.module name="'+module_name+'" intfuses='+intfuseslist+' impluses='+impluseslist+' hasimplcode='+rtl.isFunction(implcode));
  75. if (!rtl.hasString(module_name)) rtl.error('invalid module name "'+module_name+'"');
  76. if (!rtl.isArray(intfuseslist)) rtl.error('invalid interface useslist of "'+module_name+'"');
  77. if (!rtl.isFunction(intfcode)) rtl.error('invalid interface code of "'+module_name+'"');
  78. if (!(impluseslist==undefined) && !rtl.isArray(impluseslist)) rtl.error('invalid implementation useslist of "'+module_name+'"');
  79. if (!(implcode==undefined) && !rtl.isFunction(implcode)) rtl.error('invalid implementation code of "'+module_name+'"');
  80. if (pas[module_name])
  81. rtl.error('module "'+module_name+'" is already registered');
  82. var module = pas[module_name] = {
  83. $name: module_name,
  84. $intfuseslist: intfuseslist,
  85. $impluseslist: impluseslist,
  86. $state: rtl.m_loading,
  87. $intfcode: intfcode,
  88. $implcode: implcode,
  89. $impl: null,
  90. $rtti: Object.create(rtl.tSectionRTTI)
  91. };
  92. module.$rtti.$module = module;
  93. if (implcode) module.$impl = {
  94. $module: module,
  95. $rtti: module.$rtti
  96. };
  97. },
  98. exitcode: 0,
  99. run: function(module_name){
  100. function doRun(){
  101. if (!rtl.hasString(module_name)) module_name='program';
  102. if (rtl.debug_load_units) rtl.debug('rtl.run module="'+module_name+'"');
  103. rtl.initRTTI();
  104. var module = pas[module_name];
  105. if (!module) rtl.error('rtl.run module "'+module_name+'" missing');
  106. rtl.loadintf(module);
  107. rtl.loadimpl(module);
  108. if (module_name=='program'){
  109. if (rtl.debug_load_units) rtl.debug('running $main');
  110. var r = pas.program.$main();
  111. if (rtl.isNumber(r)) rtl.exitcode = r;
  112. }
  113. }
  114. if (rtl.showUncaughtExceptions) {
  115. try{
  116. doRun();
  117. } catch(re) {
  118. var errMsg = rtl.hasString(re.$classname) ? re.$classname : '';
  119. errMsg += ((errMsg) ? ': ' : '') + (re.hasOwnProperty('fMessage') ? re.fMessage : re);
  120. alert('Uncaught Exception : '+errMsg);
  121. rtl.exitCode = 216;
  122. }
  123. } else {
  124. doRun();
  125. }
  126. return rtl.exitcode;
  127. },
  128. loadintf: function(module){
  129. if (module.$state>rtl.m_loading_intf) return; // already finished
  130. if (rtl.debug_load_units) rtl.debug('loadintf: "'+module.$name+'"');
  131. if (module.$state===rtl.m_loading_intf)
  132. rtl.error('unit cycle detected "'+module.$name+'"');
  133. module.$state=rtl.m_loading_intf;
  134. // load interfaces of interface useslist
  135. rtl.loaduseslist(module,module.$intfuseslist,rtl.loadintf);
  136. // run interface
  137. if (rtl.debug_load_units) rtl.debug('loadintf: run intf of "'+module.$name+'"');
  138. module.$intfcode(module.$intfuseslist);
  139. // success
  140. module.$state=rtl.m_intf_loaded;
  141. // Note: units only used in implementations are not yet loaded (not even their interfaces)
  142. },
  143. loaduseslist: function(module,useslist,f){
  144. if (useslist==undefined) return;
  145. for (var i in useslist){
  146. var unitname=useslist[i];
  147. if (rtl.debug_load_units) rtl.debug('loaduseslist of "'+module.$name+'" uses="'+unitname+'"');
  148. if (pas[unitname]==undefined)
  149. rtl.error('module "'+module.$name+'" misses "'+unitname+'"');
  150. f(pas[unitname]);
  151. }
  152. },
  153. loadimpl: function(module){
  154. if (module.$state>=rtl.m_loading_impl) return; // already processing
  155. if (module.$state<rtl.m_intf_loaded) rtl.error('loadimpl: interface not loaded of "'+module.$name+'"');
  156. if (rtl.debug_load_units) rtl.debug('loadimpl: load uses of "'+module.$name+'"');
  157. module.$state=rtl.m_loading_impl;
  158. // load interfaces of implementation useslist
  159. rtl.loaduseslist(module,module.$impluseslist,rtl.loadintf);
  160. // load implementation of interfaces useslist
  161. rtl.loaduseslist(module,module.$intfuseslist,rtl.loadimpl);
  162. // load implementation of implementation useslist
  163. rtl.loaduseslist(module,module.$impluseslist,rtl.loadimpl);
  164. // Note: At this point all interfaces used by this unit are loaded. If
  165. // there are implementation uses cycles some used units might not yet be
  166. // initialized. This is by design.
  167. // run implementation
  168. if (rtl.debug_load_units) rtl.debug('loadimpl: run impl of "'+module.$name+'"');
  169. if (rtl.isFunction(module.$implcode)) module.$implcode(module.$impluseslist);
  170. // run initialization
  171. if (rtl.debug_load_units) rtl.debug('loadimpl: run init of "'+module.$name+'"');
  172. module.$state=rtl.m_initializing;
  173. if (rtl.isFunction(module.$init)) module.$init();
  174. // unit initialized
  175. module.$state=rtl.m_initialized;
  176. },
  177. createCallback: function(scope, fn){
  178. var cb;
  179. if (typeof(fn)==='string'){
  180. cb = function(){
  181. return scope[fn].apply(scope,arguments);
  182. };
  183. } else {
  184. cb = function(){
  185. return fn.apply(scope,arguments);
  186. };
  187. };
  188. cb.scope = scope;
  189. cb.fn = fn;
  190. return cb;
  191. },
  192. cloneCallback: function(cb){
  193. return rtl.createCallback(cb.scope,cb.fn);
  194. },
  195. eqCallback: function(a,b){
  196. // can be a function or a function wrapper
  197. if (a==b){
  198. return true;
  199. } else {
  200. return (a!=null) && (b!=null) && (a.fn) && (a.scope===b.scope) && (a.fn==b.fn);
  201. }
  202. },
  203. initStruct: function(c,parent,name){
  204. if ((parent.$module) && (parent.$module.$impl===parent)) parent=parent.$module;
  205. c.$parent = parent;
  206. if (rtl.isModule(parent)){
  207. c.$module = parent;
  208. c.$name = name;
  209. } else {
  210. c.$module = parent.$module;
  211. c.$name = parent.$name+'.'+name;
  212. };
  213. return parent;
  214. },
  215. initClass: function(c,parent,name,initfn){
  216. parent[name] = c;
  217. c.$class = c; // Note: o.$class === Object.getPrototypeOf(o)
  218. c.$classname = name;
  219. parent = rtl.initStruct(c,parent,name);
  220. c.$fullname = parent.$name+'.'+name;
  221. // rtti
  222. if (rtl.debug_rtti) rtl.debug('initClass '+c.$fullname);
  223. var t = c.$module.$rtti.$Class(c.$name,{ "class": c });
  224. c.$rtti = t;
  225. if (rtl.isObject(c.$ancestor)) t.ancestor = c.$ancestor.$rtti;
  226. if (!t.ancestor) t.ancestor = null;
  227. // init members
  228. initfn.call(c);
  229. },
  230. createClass: function(parent,name,ancestor,initfn){
  231. // create a normal class,
  232. // ancestor must be null or a normal class,
  233. // the root ancestor can be an external class
  234. var c = null;
  235. if (ancestor != null){
  236. c = Object.create(ancestor);
  237. c.$ancestor = ancestor;
  238. // Note:
  239. // if root is an "object" then c.$ancestor === Object.getPrototypeOf(c)
  240. // if root is a "function" then c.$ancestor === c.__proto__, Object.getPrototypeOf(c) returns the root
  241. } else {
  242. c = {};
  243. c.$create = function(fn,args){
  244. if (args == undefined) args = [];
  245. var o = Object.create(this);
  246. o.$init();
  247. try{
  248. if (typeof(fn)==="string"){
  249. o[fn].apply(o,args);
  250. } else {
  251. fn.apply(o,args);
  252. };
  253. o.AfterConstruction();
  254. } catch($e){
  255. // do not call BeforeDestruction
  256. if (o.Destroy) o.Destroy();
  257. o.$final();
  258. throw $e;
  259. }
  260. return o;
  261. };
  262. c.$destroy = function(fnname){
  263. this.BeforeDestruction();
  264. if (this[fnname]) this[fnname]();
  265. this.$final();
  266. };
  267. };
  268. rtl.initClass(c,parent,name,initfn);
  269. },
  270. createClassExt: function(parent,name,ancestor,newinstancefnname,initfn){
  271. // Create a class using an external ancestor.
  272. // If newinstancefnname is given, use that function to create the new object.
  273. // If exist call BeforeDestruction and AfterConstruction.
  274. var c = Object.create(ancestor);
  275. c.$create = function(fn,args){
  276. if (args == undefined) args = [];
  277. var o = null;
  278. if (newinstancefnname.length>0){
  279. o = this[newinstancefnname](fn,args);
  280. } else {
  281. o = Object.create(this);
  282. }
  283. if (o.$init) o.$init();
  284. try{
  285. if (typeof(fn)==="string"){
  286. o[fn].apply(o,args);
  287. } else {
  288. fn.apply(o,args);
  289. };
  290. if (o.AfterConstruction) o.AfterConstruction();
  291. } catch($e){
  292. // do not call BeforeDestruction
  293. if (o.Destroy) o.Destroy();
  294. if (o.$final) this.$final();
  295. throw $e;
  296. }
  297. return o;
  298. };
  299. c.$destroy = function(fnname){
  300. if (this.BeforeDestruction) this.BeforeDestruction();
  301. if (this[fnname]) this[fnname]();
  302. if (this.$final) this.$final();
  303. };
  304. rtl.initClass(c,parent,name,initfn);
  305. },
  306. createHelper: function(parent,name,ancestor,initfn){
  307. // create a helper,
  308. // ancestor must be null or a helper,
  309. var c = null;
  310. if (ancestor != null){
  311. c = Object.create(ancestor);
  312. c.$ancestor = ancestor;
  313. // c.$ancestor === Object.getPrototypeOf(c)
  314. } else {
  315. c = {};
  316. };
  317. parent[name] = c;
  318. c.$class = c; // Note: o.$class === Object.getPrototypeOf(o)
  319. c.$classname = name;
  320. parent = rtl.initStruct(c,parent,name);
  321. c.$fullname = parent.$name+'.'+name;
  322. // rtti
  323. var t = c.$module.$rtti.$Helper(c.$name,{ "helper": c });
  324. c.$rtti = t;
  325. if (rtl.isObject(ancestor)) t.ancestor = ancestor.$rtti;
  326. if (!t.ancestor) t.ancestor = null;
  327. // init members
  328. initfn.call(c);
  329. },
  330. tObjectDestroy: "Destroy",
  331. free: function(obj,name){
  332. if (obj[name]==null) return null;
  333. obj[name].$destroy(rtl.tObjectDestroy);
  334. obj[name]=null;
  335. },
  336. freeLoc: function(obj){
  337. if (obj==null) return null;
  338. obj.$destroy(rtl.tObjectDestroy);
  339. return null;
  340. },
  341. recNewT: function(parent,name,initfn,full){
  342. // create new record type
  343. var t = {};
  344. if (parent) parent[name] = t;
  345. function hide(prop){
  346. Object.defineProperty(t,prop,{enumerable:false});
  347. }
  348. if (full){
  349. rtl.initStruct(t,parent,name);
  350. t.$record = t;
  351. hide('$record');
  352. hide('$name');
  353. hide('$parent');
  354. hide('$module');
  355. }
  356. initfn.call(t);
  357. if (!t.$new){
  358. t.$new = function(){ return Object.create(this); };
  359. }
  360. t.$clone = function(r){ return this.$new().$assign(r); };
  361. hide('$new');
  362. hide('$clone');
  363. hide('$eq');
  364. hide('$assign');
  365. return t;
  366. },
  367. is: function(instance,type){
  368. return type.isPrototypeOf(instance) || (instance===type);
  369. },
  370. isExt: function(instance,type,mode){
  371. // mode===1 means instance must be a Pascal class instance
  372. // mode===2 means instance must be a Pascal class
  373. // Notes:
  374. // isPrototypeOf and instanceof return false on equal
  375. // isPrototypeOf does not work for Date.isPrototypeOf(new Date())
  376. // so if isPrototypeOf is false test with instanceof
  377. // instanceof needs a function on right side
  378. if (instance == null) return false; // Note: ==null checks for undefined too
  379. if ((typeof(type) !== 'object') && (typeof(type) !== 'function')) return false;
  380. if (instance === type){
  381. if (mode===1) return false;
  382. if (mode===2) return rtl.isPasClass(instance);
  383. return true;
  384. }
  385. if (type.isPrototypeOf && type.isPrototypeOf(instance)){
  386. if (mode===1) return rtl.isPasClassInstance(instance);
  387. if (mode===2) return rtl.isPasClass(instance);
  388. return true;
  389. }
  390. if ((typeof type == 'function') && (instance instanceof type)) return true;
  391. return false;
  392. },
  393. Exception: null,
  394. EInvalidCast: null,
  395. EAbstractError: null,
  396. ERangeError: null,
  397. EIntOverflow: null,
  398. EPropWriteOnly: null,
  399. raiseE: function(typename){
  400. var t = rtl[typename];
  401. if (t==null){
  402. var mod = pas.SysUtils;
  403. if (!mod) mod = pas.sysutils;
  404. if (mod){
  405. t = mod[typename];
  406. if (!t) t = mod[typename.toLowerCase()];
  407. if (!t) t = mod['Exception'];
  408. if (!t) t = mod['exception'];
  409. }
  410. }
  411. if (t){
  412. if (t.Create){
  413. throw t.$create("Create");
  414. } else if (t.create){
  415. throw t.$create("create");
  416. }
  417. }
  418. if (typename === "EInvalidCast") throw "invalid type cast";
  419. if (typename === "EAbstractError") throw "Abstract method called";
  420. if (typename === "ERangeError") throw "range error";
  421. throw typename;
  422. },
  423. as: function(instance,type){
  424. if((instance === null) || rtl.is(instance,type)) return instance;
  425. rtl.raiseE("EInvalidCast");
  426. },
  427. asExt: function(instance,type,mode){
  428. if((instance === null) || rtl.isExt(instance,type,mode)) return instance;
  429. rtl.raiseE("EInvalidCast");
  430. },
  431. createInterface: function(module, name, guid, fnnames, ancestor, initfn){
  432. //console.log('createInterface name="'+name+'" guid="'+guid+'" names='+fnnames);
  433. var i = ancestor?Object.create(ancestor):{};
  434. module[name] = i;
  435. i.$module = module;
  436. i.$name = name;
  437. i.$fullname = module.$name+'.'+name;
  438. i.$guid = guid;
  439. i.$guidr = null;
  440. i.$names = fnnames?fnnames:[];
  441. if (rtl.isFunction(initfn)){
  442. // rtti
  443. if (rtl.debug_rtti) rtl.debug('createInterface '+i.$fullname);
  444. var t = i.$module.$rtti.$Interface(name,{ "interface": i, module: module });
  445. i.$rtti = t;
  446. if (ancestor) t.ancestor = ancestor.$rtti;
  447. if (!t.ancestor) t.ancestor = null;
  448. initfn.call(i);
  449. }
  450. return i;
  451. },
  452. strToGUIDR: function(s,g){
  453. var p = 0;
  454. function n(l){
  455. var h = s.substr(p,l);
  456. p+=l;
  457. return parseInt(h,16);
  458. }
  459. p+=1; // skip {
  460. g.D1 = n(8);
  461. p+=1; // skip -
  462. g.D2 = n(4);
  463. p+=1; // skip -
  464. g.D3 = n(4);
  465. p+=1; // skip -
  466. if (!g.D4) g.D4=[];
  467. g.D4[0] = n(2);
  468. g.D4[1] = n(2);
  469. p+=1; // skip -
  470. for(var i=2; i<8; i++) g.D4[i] = n(2);
  471. return g;
  472. },
  473. guidrToStr: function(g){
  474. if (g.$intf) return g.$intf.$guid;
  475. var h = rtl.hexStr;
  476. var s='{'+h(g.D1,8)+'-'+h(g.D2,4)+'-'+h(g.D3,4)+'-'+h(g.D4[0],2)+h(g.D4[1],2)+'-';
  477. for (var i=2; i<8; i++) s+=h(g.D4[i],2);
  478. s+='}';
  479. return s;
  480. },
  481. createTGUID: function(guid){
  482. var TGuid = (pas.System)?pas.System.TGuid:pas.system.tguid;
  483. var g = rtl.strToGUIDR(guid,TGuid.$new());
  484. return g;
  485. },
  486. getIntfGUIDR: function(intfTypeOrVar){
  487. if (!intfTypeOrVar) return null;
  488. if (!intfTypeOrVar.$guidr){
  489. var g = rtl.createTGUID(intfTypeOrVar.$guid);
  490. if (!intfTypeOrVar.hasOwnProperty('$guid')) intfTypeOrVar = Object.getPrototypeOf(intfTypeOrVar);
  491. g.$intf = intfTypeOrVar;
  492. intfTypeOrVar.$guidr = g;
  493. }
  494. return intfTypeOrVar.$guidr;
  495. },
  496. addIntf: function (aclass, intf, map){
  497. function jmp(fn){
  498. if (typeof(fn)==="function"){
  499. return function(){ return fn.apply(this.$o,arguments); };
  500. } else {
  501. return function(){ rtl.raiseE('EAbstractError'); };
  502. }
  503. }
  504. if(!map) map = {};
  505. var t = intf;
  506. var item = Object.create(t);
  507. if (!aclass.hasOwnProperty('$intfmaps')) aclass.$intfmaps = {};
  508. aclass.$intfmaps[intf.$guid] = item;
  509. do{
  510. var names = t.$names;
  511. if (!names) break;
  512. for (var i=0; i<names.length; i++){
  513. var intfname = names[i];
  514. var fnname = map[intfname];
  515. if (!fnname) fnname = intfname;
  516. //console.log('addIntf: intftype='+t.$name+' index='+i+' intfname="'+intfname+'" fnname="'+fnname+'" old='+typeof(item[intfname]));
  517. item[intfname] = jmp(aclass[fnname]);
  518. }
  519. t = Object.getPrototypeOf(t);
  520. }while(t!=null);
  521. },
  522. getIntfG: function (obj, guid, query){
  523. if (!obj) return null;
  524. //console.log('getIntfG: obj='+obj.$classname+' guid='+guid+' query='+query);
  525. // search
  526. var maps = obj.$intfmaps;
  527. if (!maps) return null;
  528. var item = maps[guid];
  529. if (!item) return null;
  530. // check delegation
  531. //console.log('getIntfG: obj='+obj.$classname+' guid='+guid+' query='+query+' item='+typeof(item));
  532. if (typeof item === 'function') return item.call(obj); // delegate. Note: COM contains _AddRef
  533. // check cache
  534. var intf = null;
  535. if (obj.$interfaces){
  536. intf = obj.$interfaces[guid];
  537. //console.log('getIntfG: obj='+obj.$classname+' guid='+guid+' cache='+typeof(intf));
  538. }
  539. if (!intf){ // intf can be undefined!
  540. intf = Object.create(item);
  541. intf.$o = obj;
  542. if (!obj.$interfaces) obj.$interfaces = {};
  543. obj.$interfaces[guid] = intf;
  544. }
  545. if (typeof(query)==='object'){
  546. // called by queryIntfT
  547. var o = null;
  548. if (intf.QueryInterface(rtl.getIntfGUIDR(query),
  549. {get:function(){ return o; }, set:function(v){ o=v; }}) === 0){
  550. return o;
  551. } else {
  552. return null;
  553. }
  554. } else if(query===2){
  555. // called by TObject.GetInterfaceByStr
  556. if (intf.$kind === 'com') intf._AddRef();
  557. }
  558. return intf;
  559. },
  560. getIntfT: function(obj,intftype){
  561. return rtl.getIntfG(obj,intftype.$guid);
  562. },
  563. queryIntfT: function(obj,intftype){
  564. return rtl.getIntfG(obj,intftype.$guid,intftype);
  565. },
  566. queryIntfIsT: function(obj,intftype){
  567. var i = rtl.queryIntfG(obj,intftype.$guid);
  568. if (!i) return false;
  569. if (i.$kind === 'com') i._Release();
  570. return true;
  571. },
  572. asIntfT: function (obj,intftype){
  573. var i = rtl.getIntfG(obj,intftype.$guid);
  574. if (i!==null) return i;
  575. rtl.raiseEInvalidCast();
  576. },
  577. intfIsClass: function(intf,classtype){
  578. return (intf!=null) && (rtl.is(intf.$o,classtype));
  579. },
  580. intfAsClass: function(intf,classtype){
  581. if (intf==null) return null;
  582. return rtl.as(intf.$o,classtype);
  583. },
  584. intfToClass: function(intf,classtype){
  585. if ((intf!==null) && rtl.is(intf.$o,classtype)) return intf.$o;
  586. return null;
  587. },
  588. // interface reference counting
  589. intfRefs: { // base object for temporary interface variables
  590. ref: function(id,intf){
  591. // called for temporary interface references needing delayed release
  592. var old = this[id];
  593. //console.log('rtl.intfRefs.ref: id='+id+' old="'+(old?old.$name:'null')+'" intf="'+(intf?intf.$name:'null')+' $o='+(intf?intf.$o:'null'));
  594. if (old){
  595. // called again, e.g. in a loop
  596. delete this[id];
  597. old._Release(); // may fail
  598. }
  599. this[id]=intf;
  600. return intf;
  601. },
  602. free: function(){
  603. //console.log('rtl.intfRefs.free...');
  604. for (var id in this){
  605. if (this.hasOwnProperty(id)){
  606. //console.log('rtl.intfRefs.free: id='+id+' '+this[id].$name+' $o='+this[id].$o.$classname);
  607. this[id]._Release();
  608. }
  609. }
  610. }
  611. },
  612. createIntfRefs: function(){
  613. //console.log('rtl.createIntfRefs');
  614. return Object.create(rtl.intfRefs);
  615. },
  616. setIntfP: function(path,name,value,skipAddRef){
  617. var old = path[name];
  618. //console.log('rtl.setIntfP path='+path+' name='+name+' old="'+(old?old.$name:'null')+'" value="'+(value?value.$name:'null')+'"');
  619. if (old === value) return;
  620. if (old !== null){
  621. path[name]=null;
  622. old._Release();
  623. }
  624. if (value !== null){
  625. if (!skipAddRef) value._AddRef();
  626. path[name]=value;
  627. }
  628. },
  629. setIntfL: function(old,value,skipAddRef){
  630. //console.log('rtl.setIntfL old="'+(old?old.$name:'null')+'" value="'+(value?value.$name:'null')+'"');
  631. if (old !== value){
  632. if (value!==null){
  633. if (!skipAddRef) value._AddRef();
  634. }
  635. if (old!==null){
  636. old._Release(); // Release after AddRef, to avoid double Release if Release creates an exception
  637. }
  638. } else if (skipAddRef){
  639. if (old!==null){
  640. old._Release(); // value has an AddRef
  641. }
  642. }
  643. return value;
  644. },
  645. _AddRef: function(intf){
  646. //if (intf) console.log('rtl._AddRef intf="'+(intf?intf.$name:'null')+'"');
  647. if (intf) intf._AddRef();
  648. return intf;
  649. },
  650. _Release: function(intf){
  651. //if (intf) console.log('rtl._Release intf="'+(intf?intf.$name:'null')+'"');
  652. if (intf) intf._Release();
  653. return intf;
  654. },
  655. checkMethodCall: function(obj,type){
  656. if (rtl.isObject(obj) && rtl.is(obj,type)) return;
  657. rtl.raiseE("EInvalidCast");
  658. },
  659. oc: function(i){
  660. // overflow check integer
  661. if ((Math.floor(i)===i) && (i>=-0x1fffffffffffff) && (i<=0x1fffffffffffff)) return i;
  662. rtl.raiseE('EIntOverflow');
  663. },
  664. rc: function(i,minval,maxval){
  665. // range check integer
  666. if ((Math.floor(i)===i) && (i>=minval) && (i<=maxval)) return i;
  667. rtl.raiseE('ERangeError');
  668. },
  669. rcc: function(c,minval,maxval){
  670. // range check char
  671. if ((typeof(c)==='string') && (c.length===1)){
  672. var i = c.charCodeAt(0);
  673. if ((i>=minval) && (i<=maxval)) return c;
  674. }
  675. rtl.raiseE('ERangeError');
  676. },
  677. rcSetCharAt: function(s,index,c){
  678. // range check setCharAt
  679. if ((typeof(s)!=='string') || (index<0) || (index>=s.length)) rtl.raiseE('ERangeError');
  680. return rtl.setCharAt(s,index,c);
  681. },
  682. rcCharAt: function(s,index){
  683. // range check charAt
  684. if ((typeof(s)!=='string') || (index<0) || (index>=s.length)) rtl.raiseE('ERangeError');
  685. return s.charAt(index);
  686. },
  687. rcArrR: function(arr,index){
  688. // range check read array
  689. if (Array.isArray(arr) && (typeof(index)==='number') && (index>=0) && (index<arr.length)){
  690. if (arguments.length>2){
  691. // arr,index1,index2,...
  692. arr=arr[index];
  693. for (var i=2; i<arguments.length; i++) arr=rtl.rcArrR(arr,arguments[i]);
  694. return arr;
  695. }
  696. return arr[index];
  697. }
  698. rtl.raiseE('ERangeError');
  699. },
  700. rcArrW: function(arr,index,value){
  701. // range check write array
  702. // arr,index1,index2,...,value
  703. for (var i=3; i<arguments.length; i++){
  704. arr=rtl.rcArrR(arr,index);
  705. index=arguments[i-1];
  706. value=arguments[i];
  707. }
  708. if (Array.isArray(arr) && (typeof(index)==='number') && (index>=0) && (index<arr.length)){
  709. return arr[index]=value;
  710. }
  711. rtl.raiseE('ERangeError');
  712. },
  713. length: function(arr){
  714. return (arr == null) ? 0 : arr.length;
  715. },
  716. arraySetLength: function(arr,defaultvalue,newlength){
  717. // multi dim: (arr,defaultvalue,dim1,dim2,...)
  718. if (arr == null) arr = [];
  719. var p = arguments;
  720. function setLength(a,argNo){
  721. var oldlen = a.length;
  722. var newlen = p[argNo];
  723. if (oldlen!==newlength){
  724. a.length = newlength;
  725. if (argNo === p.length-1){
  726. if (rtl.isArray(defaultvalue)){
  727. for (var i=oldlen; i<newlen; i++) a[i]=[]; // nested array
  728. } else if (rtl.isObject(defaultvalue)) {
  729. if (rtl.isTRecord(defaultvalue)){
  730. for (var i=oldlen; i<newlen; i++) a[i]=defaultvalue.$new(); // e.g. record
  731. } else {
  732. for (var i=oldlen; i<newlen; i++) a[i]={}; // e.g. set
  733. }
  734. } else {
  735. for (var i=oldlen; i<newlen; i++) a[i]=defaultvalue;
  736. }
  737. } else {
  738. for (var i=oldlen; i<newlen; i++) a[i]=[]; // nested array
  739. }
  740. }
  741. if (argNo < p.length-1){
  742. // multi argNo
  743. for (var i=0; i<newlen; i++) a[i]=setLength(a[i],argNo+1);
  744. }
  745. return a;
  746. }
  747. return setLength(arr,2);
  748. },
  749. arrayEq: function(a,b){
  750. if (a===null) return b===null;
  751. if (b===null) return false;
  752. if (a.length!==b.length) return false;
  753. for (var i=0; i<a.length; i++) if (a[i]!==b[i]) return false;
  754. return true;
  755. },
  756. arrayClone: function(type,src,srcpos,endpos,dst,dstpos){
  757. // type: 0 for references, "refset" for calling refSet(), a function for new type()
  758. // src must not be null
  759. // This function does not range check.
  760. if(type === 'refSet') {
  761. for (; srcpos<endpos; srcpos++) dst[dstpos++] = rtl.refSet(src[srcpos]); // ref set
  762. } else if (rtl.isTRecord(type)){
  763. for (; srcpos<endpos; srcpos++) dst[dstpos++] = type.$clone(src[srcpos]); // clone record
  764. } else {
  765. for (; srcpos<endpos; srcpos++) dst[dstpos++] = src[srcpos]; // reference
  766. };
  767. },
  768. arrayConcat: function(type){
  769. // type: see rtl.arrayClone
  770. var a = [];
  771. var l = 0;
  772. for (var i=1; i<arguments.length; i++){
  773. var src = arguments[i];
  774. if (src !== null) l+=src.length;
  775. };
  776. a.length = l;
  777. l=0;
  778. for (var i=1; i<arguments.length; i++){
  779. var src = arguments[i];
  780. if (src === null) continue;
  781. rtl.arrayClone(type,src,0,src.length,a,l);
  782. l+=src.length;
  783. };
  784. return a;
  785. },
  786. arrayConcatN: function(){
  787. var a = null;
  788. for (var i=1; i<arguments.length; i++){
  789. var src = arguments[i];
  790. if (src === null) continue;
  791. if (a===null){
  792. a=src; // Note: concat(a) does not clone
  793. } else {
  794. a=a.concat(src);
  795. }
  796. };
  797. return a;
  798. },
  799. arrayCopy: function(type, srcarray, index, count){
  800. // type: see rtl.arrayClone
  801. // if count is missing, use srcarray.length
  802. if (srcarray === null) return [];
  803. if (index < 0) index = 0;
  804. if (count === undefined) count=srcarray.length;
  805. var end = index+count;
  806. if (end>srcarray.length) end = srcarray.length;
  807. if (index>=end) return [];
  808. if (type===0){
  809. return srcarray.slice(index,end);
  810. } else {
  811. var a = [];
  812. a.length = end-index;
  813. rtl.arrayClone(type,srcarray,index,end,a,0);
  814. return a;
  815. }
  816. },
  817. setCharAt: function(s,index,c){
  818. return s.substr(0,index)+c+s.substr(index+1);
  819. },
  820. getResStr: function(mod,name){
  821. var rs = mod.$resourcestrings[name];
  822. return rs.current?rs.current:rs.org;
  823. },
  824. createSet: function(){
  825. var s = {};
  826. for (var i=0; i<arguments.length; i++){
  827. if (arguments[i]!=null){
  828. s[arguments[i]]=true;
  829. } else {
  830. var first=arguments[i+=1];
  831. var last=arguments[i+=1];
  832. for(var j=first; j<=last; j++) s[j]=true;
  833. }
  834. }
  835. return s;
  836. },
  837. cloneSet: function(s){
  838. var r = {};
  839. for (var key in s) r[key]=true;
  840. return r;
  841. },
  842. refSet: function(s){
  843. Object.defineProperty(s, '$shared', {
  844. enumerable: false,
  845. configurable: true,
  846. writable: true,
  847. value: true
  848. });
  849. return s;
  850. },
  851. includeSet: function(s,enumvalue){
  852. if (s.$shared) s = rtl.cloneSet(s);
  853. s[enumvalue] = true;
  854. return s;
  855. },
  856. excludeSet: function(s,enumvalue){
  857. if (s.$shared) s = rtl.cloneSet(s);
  858. delete s[enumvalue];
  859. return s;
  860. },
  861. diffSet: function(s,t){
  862. var r = {};
  863. for (var key in s) if (!t[key]) r[key]=true;
  864. return r;
  865. },
  866. unionSet: function(s,t){
  867. var r = {};
  868. for (var key in s) r[key]=true;
  869. for (var key in t) r[key]=true;
  870. return r;
  871. },
  872. intersectSet: function(s,t){
  873. var r = {};
  874. for (var key in s) if (t[key]) r[key]=true;
  875. return r;
  876. },
  877. symDiffSet: function(s,t){
  878. var r = {};
  879. for (var key in s) if (!t[key]) r[key]=true;
  880. for (var key in t) if (!s[key]) r[key]=true;
  881. return r;
  882. },
  883. eqSet: function(s,t){
  884. for (var key in s) if (!t[key]) return false;
  885. for (var key in t) if (!s[key]) return false;
  886. return true;
  887. },
  888. neSet: function(s,t){
  889. return !rtl.eqSet(s,t);
  890. },
  891. leSet: function(s,t){
  892. for (var key in s) if (!t[key]) return false;
  893. return true;
  894. },
  895. geSet: function(s,t){
  896. for (var key in t) if (!s[key]) return false;
  897. return true;
  898. },
  899. strSetLength: function(s,newlen){
  900. var oldlen = s.length;
  901. if (oldlen > newlen){
  902. return s.substring(0,newlen);
  903. } else if (s.repeat){
  904. // Note: repeat needs ECMAScript6!
  905. return s+' '.repeat(newlen-oldlen);
  906. } else {
  907. while (oldlen<newlen){
  908. s+=' ';
  909. oldlen++;
  910. };
  911. return s;
  912. }
  913. },
  914. spaceLeft: function(s,width){
  915. var l=s.length;
  916. if (l>=width) return s;
  917. if (s.repeat){
  918. // Note: repeat needs ECMAScript6!
  919. return ' '.repeat(width-l) + s;
  920. } else {
  921. while (l<width){
  922. s=' '+s;
  923. l++;
  924. };
  925. };
  926. },
  927. floatToStr: function(d,w,p){
  928. // input 1-3 arguments: double, width, precision
  929. if (arguments.length>2){
  930. return rtl.spaceLeft(d.toFixed(p),w);
  931. } else {
  932. // exponent width
  933. var pad = "";
  934. var ad = Math.abs(d);
  935. if (ad<1.0e+10) {
  936. pad='00';
  937. } else if (ad<1.0e+100) {
  938. pad='0';
  939. }
  940. if (arguments.length<2) {
  941. w=9;
  942. } else if (w<9) {
  943. w=9;
  944. }
  945. var p = w-8;
  946. var s=(d>0 ? " " : "" ) + d.toExponential(p);
  947. s=s.replace(/e(.)/,'E$1'+pad);
  948. return rtl.spaceLeft(s,w);
  949. }
  950. },
  951. valEnum: function(s, enumType, setCodeFn){
  952. s = s.toLowerCase();
  953. for (var key in enumType){
  954. if((typeof(key)==='string') && (key.toLowerCase()===s)){
  955. setCodeFn(0);
  956. return enumType[key];
  957. }
  958. }
  959. setCodeFn(1);
  960. return 0;
  961. },
  962. and: function(a,b){
  963. var hi = 0x80000000;
  964. var low = 0x7fffffff;
  965. var h = (a / hi) & (b / hi);
  966. var l = (a & low) & (b & low);
  967. return h*hi + l;
  968. },
  969. or: function(a,b){
  970. var hi = 0x80000000;
  971. var low = 0x7fffffff;
  972. var h = (a / hi) | (b / hi);
  973. var l = (a & low) | (b & low);
  974. return h*hi + l;
  975. },
  976. xor: function(a,b){
  977. var hi = 0x80000000;
  978. var low = 0x7fffffff;
  979. var h = (a / hi) ^ (b / hi);
  980. var l = (a & low) ^ (b & low);
  981. return h*hi + l;
  982. },
  983. initRTTI: function(){
  984. if (rtl.debug_rtti) rtl.debug('initRTTI');
  985. // base types
  986. rtl.tTypeInfo = { name: "tTypeInfo" };
  987. function newBaseTI(name,kind,ancestor){
  988. if (!ancestor) ancestor = rtl.tTypeInfo;
  989. if (rtl.debug_rtti) rtl.debug('initRTTI.newBaseTI "'+name+'" '+kind+' ("'+ancestor.name+'")');
  990. var t = Object.create(ancestor);
  991. t.name = name;
  992. t.kind = kind;
  993. rtl[name] = t;
  994. return t;
  995. };
  996. function newBaseInt(name,minvalue,maxvalue,ordtype){
  997. var t = newBaseTI(name,1 /* tkInteger */,rtl.tTypeInfoInteger);
  998. t.minvalue = minvalue;
  999. t.maxvalue = maxvalue;
  1000. t.ordtype = ordtype;
  1001. return t;
  1002. };
  1003. newBaseTI("tTypeInfoInteger",1 /* tkInteger */);
  1004. newBaseInt("shortint",-0x80,0x7f,0);
  1005. newBaseInt("byte",0,0xff,1);
  1006. newBaseInt("smallint",-0x8000,0x7fff,2);
  1007. newBaseInt("word",0,0xffff,3);
  1008. newBaseInt("longint",-0x80000000,0x7fffffff,4);
  1009. newBaseInt("longword",0,0xffffffff,5);
  1010. newBaseInt("nativeint",-0x10000000000000,0xfffffffffffff,6);
  1011. newBaseInt("nativeuint",0,0xfffffffffffff,7);
  1012. newBaseTI("char",2 /* tkChar */);
  1013. newBaseTI("string",3 /* tkString */);
  1014. newBaseTI("tTypeInfoEnum",4 /* tkEnumeration */,rtl.tTypeInfoInteger);
  1015. newBaseTI("tTypeInfoSet",5 /* tkSet */);
  1016. newBaseTI("double",6 /* tkDouble */);
  1017. newBaseTI("boolean",7 /* tkBool */);
  1018. newBaseTI("tTypeInfoProcVar",8 /* tkProcVar */);
  1019. newBaseTI("tTypeInfoMethodVar",9 /* tkMethod */,rtl.tTypeInfoProcVar);
  1020. newBaseTI("tTypeInfoArray",10 /* tkArray */);
  1021. newBaseTI("tTypeInfoDynArray",11 /* tkDynArray */);
  1022. newBaseTI("tTypeInfoPointer",15 /* tkPointer */);
  1023. var t = newBaseTI("pointer",15 /* tkPointer */,rtl.tTypeInfoPointer);
  1024. t.reftype = null;
  1025. newBaseTI("jsvalue",16 /* tkJSValue */);
  1026. newBaseTI("tTypeInfoRefToProcVar",17 /* tkRefToProcVar */,rtl.tTypeInfoProcVar);
  1027. // member kinds
  1028. rtl.tTypeMember = {};
  1029. function newMember(name,kind){
  1030. var m = Object.create(rtl.tTypeMember);
  1031. m.name = name;
  1032. m.kind = kind;
  1033. rtl[name] = m;
  1034. };
  1035. newMember("tTypeMemberField",1); // tmkField
  1036. newMember("tTypeMemberMethod",2); // tmkMethod
  1037. newMember("tTypeMemberProperty",3); // tmkProperty
  1038. // base object for storing members: a simple object
  1039. rtl.tTypeMembers = {};
  1040. // tTypeInfoStruct - base object for tTypeInfoClass, tTypeInfoRecord, tTypeInfoInterface
  1041. var tis = newBaseTI("tTypeInfoStruct",0);
  1042. tis.$addMember = function(name,ancestor,options){
  1043. if (rtl.debug_rtti){
  1044. if (!rtl.hasString(name) || (name.charAt()==='$')) throw 'invalid member "'+name+'", this="'+this.name+'"';
  1045. if (!rtl.is(ancestor,rtl.tTypeMember)) throw 'invalid ancestor "'+ancestor+':'+ancestor.name+'", "'+this.name+'.'+name+'"';
  1046. if ((options!=undefined) && (typeof(options)!='object')) throw 'invalid options "'+options+'", "'+this.name+'.'+name+'"';
  1047. };
  1048. var t = Object.create(ancestor);
  1049. t.name = name;
  1050. this.members[name] = t;
  1051. this.names.push(name);
  1052. if (rtl.isObject(options)){
  1053. for (var key in options) if (options.hasOwnProperty(key)) t[key] = options[key];
  1054. };
  1055. return t;
  1056. };
  1057. tis.addField = function(name,type,options){
  1058. var t = this.$addMember(name,rtl.tTypeMemberField,options);
  1059. if (rtl.debug_rtti){
  1060. if (!rtl.is(type,rtl.tTypeInfo)) throw 'invalid type "'+type+'", "'+this.name+'.'+name+'"';
  1061. };
  1062. t.typeinfo = type;
  1063. this.fields.push(name);
  1064. return t;
  1065. };
  1066. tis.addFields = function(){
  1067. var i=0;
  1068. while(i<arguments.length){
  1069. var name = arguments[i++];
  1070. var type = arguments[i++];
  1071. if ((i<arguments.length) && (typeof(arguments[i])==='object')){
  1072. this.addField(name,type,arguments[i++]);
  1073. } else {
  1074. this.addField(name,type);
  1075. };
  1076. };
  1077. };
  1078. tis.addMethod = function(name,methodkind,params,result,options){
  1079. var t = this.$addMember(name,rtl.tTypeMemberMethod,options);
  1080. t.methodkind = methodkind;
  1081. t.procsig = rtl.newTIProcSig(params);
  1082. t.procsig.resulttype = result?result:null;
  1083. this.methods.push(name);
  1084. return t;
  1085. };
  1086. tis.addProperty = function(name,flags,result,getter,setter,options){
  1087. var t = this.$addMember(name,rtl.tTypeMemberProperty,options);
  1088. t.flags = flags;
  1089. t.typeinfo = result;
  1090. t.getter = getter;
  1091. t.setter = setter;
  1092. // Note: in options: params, stored, defaultvalue
  1093. if (rtl.isArray(t.params)) t.params = rtl.newTIParams(t.params);
  1094. this.properties.push(name);
  1095. if (!rtl.isString(t.stored)) t.stored = "";
  1096. return t;
  1097. };
  1098. tis.getField = function(index){
  1099. return this.members[this.fields[index]];
  1100. };
  1101. tis.getMethod = function(index){
  1102. return this.members[this.methods[index]];
  1103. };
  1104. tis.getProperty = function(index){
  1105. return this.members[this.properties[index]];
  1106. };
  1107. newBaseTI("tTypeInfoRecord",12 /* tkRecord */,rtl.tTypeInfoStruct);
  1108. newBaseTI("tTypeInfoClass",13 /* tkClass */,rtl.tTypeInfoStruct);
  1109. newBaseTI("tTypeInfoClassRef",14 /* tkClassRef */);
  1110. newBaseTI("tTypeInfoInterface",18 /* tkInterface */,rtl.tTypeInfoStruct);
  1111. newBaseTI("tTypeInfoHelper",19 /* tkHelper */,rtl.tTypeInfoStruct);
  1112. },
  1113. tSectionRTTI: {
  1114. $module: null,
  1115. $inherited: function(name,ancestor,o){
  1116. if (rtl.debug_rtti){
  1117. rtl.debug('tSectionRTTI.newTI "'+(this.$module?this.$module.$name:"(no module)")
  1118. +'"."'+name+'" ('+ancestor.name+') '+(o?'init':'forward'));
  1119. };
  1120. var t = this[name];
  1121. if (t){
  1122. if (!t.$forward) throw 'duplicate type "'+name+'"';
  1123. if (!ancestor.isPrototypeOf(t)) throw 'typeinfo ancestor mismatch "'+name+'" ancestor="'+ancestor.name+'" t.name="'+t.name+'"';
  1124. } else {
  1125. t = Object.create(ancestor);
  1126. t.name = name;
  1127. t.$module = this.$module;
  1128. this[name] = t;
  1129. }
  1130. if (o){
  1131. delete t.$forward;
  1132. for (var key in o) if (o.hasOwnProperty(key)) t[key]=o[key];
  1133. } else {
  1134. t.$forward = true;
  1135. }
  1136. return t;
  1137. },
  1138. $Scope: function(name,ancestor,o){
  1139. var t=this.$inherited(name,ancestor,o);
  1140. t.members = {};
  1141. t.names = [];
  1142. t.fields = [];
  1143. t.methods = [];
  1144. t.properties = [];
  1145. return t;
  1146. },
  1147. $TI: function(name,kind,o){ var t=this.$inherited(name,rtl.tTypeInfo,o); t.kind = kind; return t; },
  1148. $Int: function(name,o){ return this.$inherited(name,rtl.tTypeInfoInteger,o); },
  1149. $Enum: function(name,o){ return this.$inherited(name,rtl.tTypeInfoEnum,o); },
  1150. $Set: function(name,o){ return this.$inherited(name,rtl.tTypeInfoSet,o); },
  1151. $StaticArray: function(name,o){ return this.$inherited(name,rtl.tTypeInfoArray,o); },
  1152. $DynArray: function(name,o){ return this.$inherited(name,rtl.tTypeInfoDynArray,o); },
  1153. $ProcVar: function(name,o){ return this.$inherited(name,rtl.tTypeInfoProcVar,o); },
  1154. $RefToProcVar: function(name,o){ return this.$inherited(name,rtl.tTypeInfoRefToProcVar,o); },
  1155. $MethodVar: function(name,o){ return this.$inherited(name,rtl.tTypeInfoMethodVar,o); },
  1156. $Record: function(name,o){ return this.$Scope(name,rtl.tTypeInfoRecord,o); },
  1157. $Class: function(name,o){ return this.$Scope(name,rtl.tTypeInfoClass,o); },
  1158. $ClassRef: function(name,o){ return this.$inherited(name,rtl.tTypeInfoClassRef,o); },
  1159. $Pointer: function(name,o){ return this.$inherited(name,rtl.tTypeInfoPointer,o); },
  1160. $Interface: function(name,o){ return this.$Scope(name,rtl.tTypeInfoInterface,o); },
  1161. $Helper: function(name,o){ return this.$Scope(name,rtl.tTypeInfoHelper,o); }
  1162. },
  1163. newTIParam: function(param){
  1164. // param is an array, 0=name, 1=type, 2=optional flags
  1165. var t = {
  1166. name: param[0],
  1167. typeinfo: param[1],
  1168. flags: (rtl.isNumber(param[2]) ? param[2] : 0)
  1169. };
  1170. return t;
  1171. },
  1172. newTIParams: function(list){
  1173. // list: optional array of [paramname,typeinfo,optional flags]
  1174. var params = [];
  1175. if (rtl.isArray(list)){
  1176. for (var i=0; i<list.length; i++) params.push(rtl.newTIParam(list[i]));
  1177. };
  1178. return params;
  1179. },
  1180. newTIProcSig: function(params,result,flags){
  1181. var s = {
  1182. params: rtl.newTIParams(params),
  1183. resulttype: result,
  1184. flags: flags
  1185. };
  1186. return s;
  1187. }
  1188. }