rtl.js 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273
  1. var pas = {};
  2. var rtl = {
  3. version: 10301,
  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;
  333. obj[name].$destroy(rtl.tObjectDestroy);
  334. obj[name]=null;
  335. },
  336. freeLoc: function(obj){
  337. if (obj==null) return;
  338. obj.$destroy(rtl.tObjectDestroy);
  339. return null;
  340. },
  341. recNewT: function(parent,name,initfn,full){
  342. var t = {};
  343. if (parent) parent[name] = t;
  344. function hide(prop){
  345. Object.defineProperty(t,prop,{enumerable:false});
  346. }
  347. if (full){
  348. rtl.initStruct(t,parent,name);
  349. t.$record = t;
  350. hide('$record');
  351. hide('$name');
  352. hide('$parent');
  353. hide('$module');
  354. }
  355. initfn.call(t);
  356. if (!t.$new){
  357. t.$new = function(){ return Object.create(this); };
  358. }
  359. t.$clone = function(r){ return this.$new().$assign(r); };
  360. hide('$new');
  361. hide('$clone');
  362. hide('$eq');
  363. hide('$assign');
  364. return t;
  365. },
  366. is: function(instance,type){
  367. return type.isPrototypeOf(instance) || (instance===type);
  368. },
  369. isExt: function(instance,type,mode){
  370. // mode===1 means instance must be a Pascal class instance
  371. // mode===2 means instance must be a Pascal class
  372. // Notes:
  373. // isPrototypeOf and instanceof return false on equal
  374. // isPrototypeOf does not work for Date.isPrototypeOf(new Date())
  375. // so if isPrototypeOf is false test with instanceof
  376. // instanceof needs a function on right side
  377. if (instance == null) return false; // Note: ==null checks for undefined too
  378. if ((typeof(type) !== 'object') && (typeof(type) !== 'function')) return false;
  379. if (instance === type){
  380. if (mode===1) return false;
  381. if (mode===2) return rtl.isPasClass(instance);
  382. return true;
  383. }
  384. if (type.isPrototypeOf && type.isPrototypeOf(instance)){
  385. if (mode===1) return rtl.isPasClassInstance(instance);
  386. if (mode===2) return rtl.isPasClass(instance);
  387. return true;
  388. }
  389. if ((typeof type == 'function') && (instance instanceof type)) return true;
  390. return false;
  391. },
  392. Exception: null,
  393. EInvalidCast: null,
  394. EAbstractError: null,
  395. ERangeError: null,
  396. raiseE: function(typename){
  397. var t = rtl[typename];
  398. if (t==null){
  399. var mod = pas.SysUtils;
  400. if (!mod) mod = pas.sysutils;
  401. if (mod){
  402. t = mod[typename];
  403. if (!t) t = mod[typename.toLowerCase()];
  404. if (!t) t = mod['Exception'];
  405. if (!t) t = mod['exception'];
  406. }
  407. }
  408. if (t){
  409. if (t.Create){
  410. throw t.$create("Create");
  411. } else if (t.create){
  412. throw t.$create("create");
  413. }
  414. }
  415. if (typename === "EInvalidCast") throw "invalid type cast";
  416. if (typename === "EAbstractError") throw "Abstract method called";
  417. if (typename === "ERangeError") throw "range error";
  418. throw typename;
  419. },
  420. as: function(instance,type){
  421. if((instance === null) || rtl.is(instance,type)) return instance;
  422. rtl.raiseE("EInvalidCast");
  423. },
  424. asExt: function(instance,type,mode){
  425. if((instance === null) || rtl.isExt(instance,type,mode)) return instance;
  426. rtl.raiseE("EInvalidCast");
  427. },
  428. createInterface: function(module, name, guid, fnnames, ancestor, initfn){
  429. //console.log('createInterface name="'+name+'" guid="'+guid+'" names='+fnnames);
  430. var i = ancestor?Object.create(ancestor):{};
  431. module[name] = i;
  432. i.$module = module;
  433. i.$name = name;
  434. i.$fullname = module.$name+'.'+name;
  435. i.$guid = guid;
  436. i.$guidr = null;
  437. i.$names = fnnames?fnnames:[];
  438. if (rtl.isFunction(initfn)){
  439. // rtti
  440. if (rtl.debug_rtti) rtl.debug('createInterface '+i.$fullname);
  441. var t = i.$module.$rtti.$Interface(name,{ "interface": i, module: module });
  442. i.$rtti = t;
  443. if (ancestor) t.ancestor = ancestor.$rtti;
  444. if (!t.ancestor) t.ancestor = null;
  445. initfn.call(i);
  446. }
  447. return i;
  448. },
  449. strToGUIDR: function(s,g){
  450. var p = 0;
  451. function n(l){
  452. var h = s.substr(p,l);
  453. p+=l;
  454. return parseInt(h,16);
  455. }
  456. p+=1; // skip {
  457. g.D1 = n(8);
  458. p+=1; // skip -
  459. g.D2 = n(4);
  460. p+=1; // skip -
  461. g.D3 = n(4);
  462. p+=1; // skip -
  463. if (!g.D4) g.D4=[];
  464. g.D4[0] = n(2);
  465. g.D4[1] = n(2);
  466. p+=1; // skip -
  467. for(var i=2; i<8; i++) g.D4[i] = n(2);
  468. return g;
  469. },
  470. guidrToStr: function(g){
  471. if (g.$intf) return g.$intf.$guid;
  472. var h = rtl.hexStr;
  473. var s='{'+h(g.D1,8)+'-'+h(g.D2,4)+'-'+h(g.D3,4)+'-'+h(g.D4[0],2)+h(g.D4[1],2)+'-';
  474. for (var i=2; i<8; i++) s+=h(g.D4[i],2);
  475. s+='}';
  476. return s;
  477. },
  478. createTGUID: function(guid){
  479. var TGuid = (pas.System)?pas.System.TGuid:pas.system.tguid;
  480. var g = rtl.strToGUIDR(guid,TGuid.$new());
  481. return g;
  482. },
  483. getIntfGUIDR: function(intfTypeOrVar){
  484. if (!intfTypeOrVar) return null;
  485. if (!intfTypeOrVar.$guidr){
  486. var g = rtl.createTGUID(intfTypeOrVar.$guid);
  487. if (!intfTypeOrVar.hasOwnProperty('$guid')) intfTypeOrVar = Object.getPrototypeOf(intfTypeOrVar);
  488. g.$intf = intfTypeOrVar;
  489. intfTypeOrVar.$guidr = g;
  490. }
  491. return intfTypeOrVar.$guidr;
  492. },
  493. addIntf: function (aclass, intf, map){
  494. function jmp(fn){
  495. if (typeof(fn)==="function"){
  496. return function(){ return fn.apply(this.$o,arguments); };
  497. } else {
  498. return function(){ rtl.raiseE('EAbstractError'); };
  499. }
  500. }
  501. if(!map) map = {};
  502. var t = intf;
  503. var item = Object.create(t);
  504. if (!aclass.hasOwnProperty('$intfmaps')) aclass.$intfmaps = {};
  505. aclass.$intfmaps[intf.$guid] = item;
  506. do{
  507. var names = t.$names;
  508. if (!names) break;
  509. for (var i=0; i<names.length; i++){
  510. var intfname = names[i];
  511. var fnname = map[intfname];
  512. if (!fnname) fnname = intfname;
  513. //console.log('addIntf: intftype='+t.$name+' index='+i+' intfname="'+intfname+'" fnname="'+fnname+'" old='+typeof(item[intfname]));
  514. item[intfname] = jmp(aclass[fnname]);
  515. }
  516. t = Object.getPrototypeOf(t);
  517. }while(t!=null);
  518. },
  519. getIntfG: function (obj, guid, query){
  520. if (!obj) return null;
  521. //console.log('getIntfG: obj='+obj.$classname+' guid='+guid+' query='+query);
  522. // search
  523. var maps = obj.$intfmaps;
  524. if (!maps) return null;
  525. var item = maps[guid];
  526. if (!item) return null;
  527. // check delegation
  528. //console.log('getIntfG: obj='+obj.$classname+' guid='+guid+' query='+query+' item='+typeof(item));
  529. if (typeof item === 'function') return item.call(obj); // delegate. Note: COM contains _AddRef
  530. // check cache
  531. var intf = null;
  532. if (obj.$interfaces){
  533. intf = obj.$interfaces[guid];
  534. //console.log('getIntfG: obj='+obj.$classname+' guid='+guid+' cache='+typeof(intf));
  535. }
  536. if (!intf){ // intf can be undefined!
  537. intf = Object.create(item);
  538. intf.$o = obj;
  539. if (!obj.$interfaces) obj.$interfaces = {};
  540. obj.$interfaces[guid] = intf;
  541. }
  542. if (typeof(query)==='object'){
  543. // called by queryIntfT
  544. var o = null;
  545. if (intf.QueryInterface(rtl.getIntfGUIDR(query),
  546. {get:function(){ return o; }, set:function(v){ o=v; }}) === 0){
  547. return o;
  548. } else {
  549. return null;
  550. }
  551. } else if(query===2){
  552. // called by TObject.GetInterfaceByStr
  553. if (intf.$kind === 'com') intf._AddRef();
  554. }
  555. return intf;
  556. },
  557. getIntfT: function(obj,intftype){
  558. return rtl.getIntfG(obj,intftype.$guid);
  559. },
  560. queryIntfT: function(obj,intftype){
  561. return rtl.getIntfG(obj,intftype.$guid,intftype);
  562. },
  563. queryIntfIsT: function(obj,intftype){
  564. var i = rtl.queryIntfG(obj,intftype.$guid);
  565. if (!i) return false;
  566. if (i.$kind === 'com') i._Release();
  567. return true;
  568. },
  569. asIntfT: function (obj,intftype){
  570. var i = rtl.getIntfG(obj,intftype.$guid);
  571. if (i!==null) return i;
  572. rtl.raiseEInvalidCast();
  573. },
  574. intfIsClass: function(intf,classtype){
  575. return (intf!=null) && (rtl.is(intf.$o,classtype));
  576. },
  577. intfAsClass: function(intf,classtype){
  578. if (intf==null) return null;
  579. return rtl.as(intf.$o,classtype);
  580. },
  581. intfToClass: function(intf,classtype){
  582. if ((intf!==null) && rtl.is(intf.$o,classtype)) return intf.$o;
  583. return null;
  584. },
  585. // interface reference counting
  586. intfRefs: { // base object for temporary interface variables
  587. ref: function(id,intf){
  588. // called for temporary interface references needing delayed release
  589. var old = this[id];
  590. //console.log('rtl.intfRefs.ref: id='+id+' old="'+(old?old.$name:'null')+'" intf="'+(intf?intf.$name:'null')+' $o='+(intf?intf.$o:'null'));
  591. if (old){
  592. // called again, e.g. in a loop
  593. delete this[id];
  594. old._Release(); // may fail
  595. }
  596. this[id]=intf;
  597. return intf;
  598. },
  599. free: function(){
  600. //console.log('rtl.intfRefs.free...');
  601. for (var id in this){
  602. if (this.hasOwnProperty(id)){
  603. //console.log('rtl.intfRefs.free: id='+id+' '+this[id].$name+' $o='+this[id].$o.$classname);
  604. this[id]._Release();
  605. }
  606. }
  607. }
  608. },
  609. createIntfRefs: function(){
  610. //console.log('rtl.createIntfRefs');
  611. return Object.create(rtl.intfRefs);
  612. },
  613. setIntfP: function(path,name,value,skipAddRef){
  614. var old = path[name];
  615. //console.log('rtl.setIntfP path='+path+' name='+name+' old="'+(old?old.$name:'null')+'" value="'+(value?value.$name:'null')+'"');
  616. if (old === value) return;
  617. if (old !== null){
  618. path[name]=null;
  619. old._Release();
  620. }
  621. if (value !== null){
  622. if (!skipAddRef) value._AddRef();
  623. path[name]=value;
  624. }
  625. },
  626. setIntfL: function(old,value,skipAddRef){
  627. //console.log('rtl.setIntfL old="'+(old?old.$name:'null')+'" value="'+(value?value.$name:'null')+'"');
  628. if (old !== value){
  629. if (value!==null){
  630. if (!skipAddRef) value._AddRef();
  631. }
  632. if (old!==null){
  633. old._Release(); // Release after AddRef, to avoid double Release if Release creates an exception
  634. }
  635. } else if (skipAddRef){
  636. if (old!==null){
  637. old._Release(); // value has an AddRef
  638. }
  639. }
  640. return value;
  641. },
  642. _AddRef: function(intf){
  643. //if (intf) console.log('rtl._AddRef intf="'+(intf?intf.$name:'null')+'"');
  644. if (intf) intf._AddRef();
  645. return intf;
  646. },
  647. _Release: function(intf){
  648. //if (intf) console.log('rtl._Release intf="'+(intf?intf.$name:'null')+'"');
  649. if (intf) intf._Release();
  650. return intf;
  651. },
  652. checkMethodCall: function(obj,type){
  653. if (rtl.isObject(obj) && rtl.is(obj,type)) return;
  654. rtl.raiseE("EInvalidCast");
  655. },
  656. rc: function(i,minval,maxval){
  657. // range check integer
  658. if ((Math.floor(i)===i) && (i>=minval) && (i<=maxval)) return i;
  659. rtl.raiseE('ERangeError');
  660. },
  661. rcc: function(c,minval,maxval){
  662. // range check char
  663. if ((typeof(c)==='string') && (c.length===1)){
  664. var i = c.charCodeAt(0);
  665. if ((i>=minval) && (i<=maxval)) return c;
  666. }
  667. rtl.raiseE('ERangeError');
  668. },
  669. rcSetCharAt: function(s,index,c){
  670. // range check setCharAt
  671. if ((typeof(s)!=='string') || (index<0) || (index>=s.length)) rtl.raiseE('ERangeError');
  672. return rtl.setCharAt(s,index,c);
  673. },
  674. rcCharAt: function(s,index){
  675. // range check charAt
  676. if ((typeof(s)!=='string') || (index<0) || (index>=s.length)) rtl.raiseE('ERangeError');
  677. return s.charAt(index);
  678. },
  679. rcArrR: function(arr,index){
  680. // range check read array
  681. if (Array.isArray(arr) && (typeof(index)==='number') && (index>=0) && (index<arr.length)){
  682. if (arguments.length>2){
  683. // arr,index1,index2,...
  684. arr=arr[index];
  685. for (var i=2; i<arguments.length; i++) arr=rtl.rcArrR(arr,arguments[i]);
  686. return arr;
  687. }
  688. return arr[index];
  689. }
  690. rtl.raiseE('ERangeError');
  691. },
  692. rcArrW: function(arr,index,value){
  693. // range check write array
  694. // arr,index1,index2,...,value
  695. for (var i=3; i<arguments.length; i++){
  696. arr=rtl.rcArrR(arr,index);
  697. index=arguments[i-1];
  698. value=arguments[i];
  699. }
  700. if (Array.isArray(arr) && (typeof(index)==='number') && (index>=0) && (index<arr.length)){
  701. return arr[index]=value;
  702. }
  703. rtl.raiseE('ERangeError');
  704. },
  705. length: function(arr){
  706. return (arr == null) ? 0 : arr.length;
  707. },
  708. arraySetLength: function(arr,defaultvalue,newlength){
  709. // multi dim: (arr,defaultvalue,dim1,dim2,...)
  710. if (arr == null) arr = [];
  711. var p = arguments;
  712. function setLength(a,argNo){
  713. var oldlen = a.length;
  714. var newlen = p[argNo];
  715. if (oldlen!==newlength){
  716. a.length = newlength;
  717. if (argNo === p.length-1){
  718. if (rtl.isArray(defaultvalue)){
  719. for (var i=oldlen; i<newlen; i++) a[i]=[]; // nested array
  720. } else if (rtl.isObject(defaultvalue)) {
  721. if (rtl.isTRecord(defaultvalue)){
  722. for (var i=oldlen; i<newlen; i++) a[i]=defaultvalue.$new(); // e.g. record
  723. } else {
  724. for (var i=oldlen; i<newlen; i++) a[i]={}; // e.g. set
  725. }
  726. } else {
  727. for (var i=oldlen; i<newlen; i++) a[i]=defaultvalue;
  728. }
  729. } else {
  730. for (var i=oldlen; i<newlen; i++) a[i]=[]; // nested array
  731. }
  732. }
  733. if (argNo < p.length-1){
  734. // multi argNo
  735. for (var i=0; i<newlen; i++) a[i]=setLength(a[i],argNo+1);
  736. }
  737. return a;
  738. }
  739. return setLength(arr,2);
  740. },
  741. arrayEq: function(a,b){
  742. if (a===null) return b===null;
  743. if (b===null) return false;
  744. if (a.length!==b.length) return false;
  745. for (var i=0; i<a.length; i++) if (a[i]!==b[i]) return false;
  746. return true;
  747. },
  748. arrayClone: function(type,src,srcpos,endpos,dst,dstpos){
  749. // type: 0 for references, "refset" for calling refSet(), a function for new type()
  750. // src must not be null
  751. // This function does not range check.
  752. if(type === 'refSet') {
  753. for (; srcpos<endpos; srcpos++) dst[dstpos++] = rtl.refSet(src[srcpos]); // ref set
  754. } else if (rtl.isTRecord(type)){
  755. for (; srcpos<endpos; srcpos++) dst[dstpos++] = type.$clone(src[srcpos]); // clone record
  756. } else {
  757. for (; srcpos<endpos; srcpos++) dst[dstpos++] = src[srcpos]; // reference
  758. };
  759. },
  760. arrayConcat: function(type){
  761. // type: see rtl.arrayClone
  762. var a = [];
  763. var l = 0;
  764. for (var i=1; i<arguments.length; i++){
  765. var src = arguments[i];
  766. if (src !== null) l+=src.length;
  767. };
  768. a.length = l;
  769. l=0;
  770. for (var i=1; i<arguments.length; i++){
  771. var src = arguments[i];
  772. if (src === null) continue;
  773. rtl.arrayClone(type,src,0,src.length,a,l);
  774. l+=src.length;
  775. };
  776. return a;
  777. },
  778. arrayConcatN: function(){
  779. var a = null;
  780. for (var i=1; i<arguments.length; i++){
  781. var src = arguments[i];
  782. if (src === null) continue;
  783. if (a===null){
  784. a=src; // Note: concat(a) does not clone
  785. } else {
  786. a=a.concat(src);
  787. }
  788. };
  789. return a;
  790. },
  791. arrayCopy: function(type, srcarray, index, count){
  792. // type: see rtl.arrayClone
  793. // if count is missing, use srcarray.length
  794. if (srcarray === null) return [];
  795. if (index < 0) index = 0;
  796. if (count === undefined) count=srcarray.length;
  797. var end = index+count;
  798. if (end>srcarray.length) end = srcarray.length;
  799. if (index>=end) return [];
  800. if (type===0){
  801. return srcarray.slice(index,end);
  802. } else {
  803. var a = [];
  804. a.length = end-index;
  805. rtl.arrayClone(type,srcarray,index,end,a,0);
  806. return a;
  807. }
  808. },
  809. setCharAt: function(s,index,c){
  810. return s.substr(0,index)+c+s.substr(index+1);
  811. },
  812. getResStr: function(mod,name){
  813. var rs = mod.$resourcestrings[name];
  814. return rs.current?rs.current:rs.org;
  815. },
  816. createSet: function(){
  817. var s = {};
  818. for (var i=0; i<arguments.length; i++){
  819. if (arguments[i]!=null){
  820. s[arguments[i]]=true;
  821. } else {
  822. var first=arguments[i+=1];
  823. var last=arguments[i+=1];
  824. for(var j=first; j<=last; j++) s[j]=true;
  825. }
  826. }
  827. return s;
  828. },
  829. cloneSet: function(s){
  830. var r = {};
  831. for (var key in s) r[key]=true;
  832. return r;
  833. },
  834. refSet: function(s){
  835. Object.defineProperty(s, '$shared', {
  836. enumerable: false,
  837. configurable: true,
  838. writable: true,
  839. value: true
  840. });
  841. return s;
  842. },
  843. includeSet: function(s,enumvalue){
  844. if (s.$shared) s = rtl.cloneSet(s);
  845. s[enumvalue] = true;
  846. return s;
  847. },
  848. excludeSet: function(s,enumvalue){
  849. if (s.$shared) s = rtl.cloneSet(s);
  850. delete s[enumvalue];
  851. return s;
  852. },
  853. diffSet: function(s,t){
  854. var r = {};
  855. for (var key in s) if (!t[key]) r[key]=true;
  856. return r;
  857. },
  858. unionSet: function(s,t){
  859. var r = {};
  860. for (var key in s) r[key]=true;
  861. for (var key in t) r[key]=true;
  862. return r;
  863. },
  864. intersectSet: function(s,t){
  865. var r = {};
  866. for (var key in s) if (t[key]) r[key]=true;
  867. return r;
  868. },
  869. symDiffSet: function(s,t){
  870. var r = {};
  871. for (var key in s) if (!t[key]) r[key]=true;
  872. for (var key in t) if (!s[key]) r[key]=true;
  873. return r;
  874. },
  875. eqSet: function(s,t){
  876. for (var key in s) if (!t[key]) return false;
  877. for (var key in t) if (!s[key]) return false;
  878. return true;
  879. },
  880. neSet: function(s,t){
  881. return !rtl.eqSet(s,t);
  882. },
  883. leSet: function(s,t){
  884. for (var key in s) if (!t[key]) return false;
  885. return true;
  886. },
  887. geSet: function(s,t){
  888. for (var key in t) if (!s[key]) return false;
  889. return true;
  890. },
  891. strSetLength: function(s,newlen){
  892. var oldlen = s.length;
  893. if (oldlen > newlen){
  894. return s.substring(0,newlen);
  895. } else if (s.repeat){
  896. // Note: repeat needs ECMAScript6!
  897. return s+' '.repeat(newlen-oldlen);
  898. } else {
  899. while (oldlen<newlen){
  900. s+=' ';
  901. oldlen++;
  902. };
  903. return s;
  904. }
  905. },
  906. spaceLeft: function(s,width){
  907. var l=s.length;
  908. if (l>=width) return s;
  909. if (s.repeat){
  910. // Note: repeat needs ECMAScript6!
  911. return ' '.repeat(width-l) + s;
  912. } else {
  913. while (l<width){
  914. s=' '+s;
  915. l++;
  916. };
  917. };
  918. },
  919. floatToStr: function(d,w,p){
  920. // input 1-3 arguments: double, width, precision
  921. if (arguments.length>2){
  922. return rtl.spaceLeft(d.toFixed(p),w);
  923. } else {
  924. // exponent width
  925. var pad = "";
  926. var ad = Math.abs(d);
  927. if (ad<1.0e+10) {
  928. pad='00';
  929. } else if (ad<1.0e+100) {
  930. pad='0';
  931. }
  932. if (arguments.length<2) {
  933. w=9;
  934. } else if (w<9) {
  935. w=9;
  936. }
  937. var p = w-8;
  938. var s=(d>0 ? " " : "" ) + d.toExponential(p);
  939. s=s.replace(/e(.)/,'E$1'+pad);
  940. return rtl.spaceLeft(s,w);
  941. }
  942. },
  943. valEnum: function(s, enumType, setCodeFn){
  944. s = s.toLowerCase();
  945. for (var key in enumType){
  946. if((typeof(key)==='string') && (key.toLowerCase()===s)){
  947. setCodeFn(0);
  948. return enumType[key];
  949. }
  950. }
  951. setCodeFn(1);
  952. return 0;
  953. },
  954. initRTTI: function(){
  955. if (rtl.debug_rtti) rtl.debug('initRTTI');
  956. // base types
  957. rtl.tTypeInfo = { name: "tTypeInfo" };
  958. function newBaseTI(name,kind,ancestor){
  959. if (!ancestor) ancestor = rtl.tTypeInfo;
  960. if (rtl.debug_rtti) rtl.debug('initRTTI.newBaseTI "'+name+'" '+kind+' ("'+ancestor.name+'")');
  961. var t = Object.create(ancestor);
  962. t.name = name;
  963. t.kind = kind;
  964. rtl[name] = t;
  965. return t;
  966. };
  967. function newBaseInt(name,minvalue,maxvalue,ordtype){
  968. var t = newBaseTI(name,1 /* tkInteger */,rtl.tTypeInfoInteger);
  969. t.minvalue = minvalue;
  970. t.maxvalue = maxvalue;
  971. t.ordtype = ordtype;
  972. return t;
  973. };
  974. newBaseTI("tTypeInfoInteger",1 /* tkInteger */);
  975. newBaseInt("shortint",-0x80,0x7f,0);
  976. newBaseInt("byte",0,0xff,1);
  977. newBaseInt("smallint",-0x8000,0x7fff,2);
  978. newBaseInt("word",0,0xffff,3);
  979. newBaseInt("longint",-0x80000000,0x7fffffff,4);
  980. newBaseInt("longword",0,0xffffffff,5);
  981. newBaseInt("nativeint",-0x10000000000000,0xfffffffffffff,6);
  982. newBaseInt("nativeuint",0,0xfffffffffffff,7);
  983. newBaseTI("char",2 /* tkChar */);
  984. newBaseTI("string",3 /* tkString */);
  985. newBaseTI("tTypeInfoEnum",4 /* tkEnumeration */,rtl.tTypeInfoInteger);
  986. newBaseTI("tTypeInfoSet",5 /* tkSet */);
  987. newBaseTI("double",6 /* tkDouble */);
  988. newBaseTI("boolean",7 /* tkBool */);
  989. newBaseTI("tTypeInfoProcVar",8 /* tkProcVar */);
  990. newBaseTI("tTypeInfoMethodVar",9 /* tkMethod */,rtl.tTypeInfoProcVar);
  991. newBaseTI("tTypeInfoArray",10 /* tkArray */);
  992. newBaseTI("tTypeInfoDynArray",11 /* tkDynArray */);
  993. newBaseTI("tTypeInfoPointer",15 /* tkPointer */);
  994. var t = newBaseTI("pointer",15 /* tkPointer */,rtl.tTypeInfoPointer);
  995. t.reftype = null;
  996. newBaseTI("jsvalue",16 /* tkJSValue */);
  997. newBaseTI("tTypeInfoRefToProcVar",17 /* tkRefToProcVar */,rtl.tTypeInfoProcVar);
  998. // member kinds
  999. rtl.tTypeMember = {};
  1000. function newMember(name,kind){
  1001. var m = Object.create(rtl.tTypeMember);
  1002. m.name = name;
  1003. m.kind = kind;
  1004. rtl[name] = m;
  1005. };
  1006. newMember("tTypeMemberField",1); // tmkField
  1007. newMember("tTypeMemberMethod",2); // tmkMethod
  1008. newMember("tTypeMemberProperty",3); // tmkProperty
  1009. // base object for storing members: a simple object
  1010. rtl.tTypeMembers = {};
  1011. // tTypeInfoStruct - base object for tTypeInfoClass, tTypeInfoRecord, tTypeInfoInterface
  1012. var tis = newBaseTI("tTypeInfoStruct",0);
  1013. tis.$addMember = function(name,ancestor,options){
  1014. if (rtl.debug_rtti){
  1015. if (!rtl.hasString(name) || (name.charAt()==='$')) throw 'invalid member "'+name+'", this="'+this.name+'"';
  1016. if (!rtl.is(ancestor,rtl.tTypeMember)) throw 'invalid ancestor "'+ancestor+':'+ancestor.name+'", "'+this.name+'.'+name+'"';
  1017. if ((options!=undefined) && (typeof(options)!='object')) throw 'invalid options "'+options+'", "'+this.name+'.'+name+'"';
  1018. };
  1019. var t = Object.create(ancestor);
  1020. t.name = name;
  1021. this.members[name] = t;
  1022. this.names.push(name);
  1023. if (rtl.isObject(options)){
  1024. for (var key in options) if (options.hasOwnProperty(key)) t[key] = options[key];
  1025. };
  1026. return t;
  1027. };
  1028. tis.addField = function(name,type,options){
  1029. var t = this.$addMember(name,rtl.tTypeMemberField,options);
  1030. if (rtl.debug_rtti){
  1031. if (!rtl.is(type,rtl.tTypeInfo)) throw 'invalid type "'+type+'", "'+this.name+'.'+name+'"';
  1032. };
  1033. t.typeinfo = type;
  1034. this.fields.push(name);
  1035. return t;
  1036. };
  1037. tis.addFields = function(){
  1038. var i=0;
  1039. while(i<arguments.length){
  1040. var name = arguments[i++];
  1041. var type = arguments[i++];
  1042. if ((i<arguments.length) && (typeof(arguments[i])==='object')){
  1043. this.addField(name,type,arguments[i++]);
  1044. } else {
  1045. this.addField(name,type);
  1046. };
  1047. };
  1048. };
  1049. tis.addMethod = function(name,methodkind,params,result,options){
  1050. var t = this.$addMember(name,rtl.tTypeMemberMethod,options);
  1051. t.methodkind = methodkind;
  1052. t.procsig = rtl.newTIProcSig(params);
  1053. t.procsig.resulttype = result?result:null;
  1054. this.methods.push(name);
  1055. return t;
  1056. };
  1057. tis.addProperty = function(name,flags,result,getter,setter,options){
  1058. var t = this.$addMember(name,rtl.tTypeMemberProperty,options);
  1059. t.flags = flags;
  1060. t.typeinfo = result;
  1061. t.getter = getter;
  1062. t.setter = setter;
  1063. // Note: in options: params, stored, defaultvalue
  1064. if (rtl.isArray(t.params)) t.params = rtl.newTIParams(t.params);
  1065. this.properties.push(name);
  1066. if (!rtl.isString(t.stored)) t.stored = "";
  1067. return t;
  1068. };
  1069. tis.getField = function(index){
  1070. return this.members[this.fields[index]];
  1071. };
  1072. tis.getMethod = function(index){
  1073. return this.members[this.methods[index]];
  1074. };
  1075. tis.getProperty = function(index){
  1076. return this.members[this.properties[index]];
  1077. };
  1078. newBaseTI("tTypeInfoRecord",12 /* tkRecord */,rtl.tTypeInfoStruct);
  1079. newBaseTI("tTypeInfoClass",13 /* tkClass */,rtl.tTypeInfoStruct);
  1080. newBaseTI("tTypeInfoClassRef",14 /* tkClassRef */);
  1081. newBaseTI("tTypeInfoInterface",18 /* tkInterface */,rtl.tTypeInfoStruct);
  1082. newBaseTI("tTypeInfoHelper",19 /* tkHelper */,rtl.tTypeInfoStruct);
  1083. },
  1084. tSectionRTTI: {
  1085. $module: null,
  1086. $inherited: function(name,ancestor,o){
  1087. if (rtl.debug_rtti){
  1088. rtl.debug('tSectionRTTI.newTI "'+(this.$module?this.$module.$name:"(no module)")
  1089. +'"."'+name+'" ('+ancestor.name+') '+(o?'init':'forward'));
  1090. };
  1091. var t = this[name];
  1092. if (t){
  1093. if (!t.$forward) throw 'duplicate type "'+name+'"';
  1094. if (!ancestor.isPrototypeOf(t)) throw 'typeinfo ancestor mismatch "'+name+'" ancestor="'+ancestor.name+'" t.name="'+t.name+'"';
  1095. } else {
  1096. t = Object.create(ancestor);
  1097. t.name = name;
  1098. t.$module = this.$module;
  1099. this[name] = t;
  1100. }
  1101. if (o){
  1102. delete t.$forward;
  1103. for (var key in o) if (o.hasOwnProperty(key)) t[key]=o[key];
  1104. } else {
  1105. t.$forward = true;
  1106. }
  1107. return t;
  1108. },
  1109. $Scope: function(name,ancestor,o){
  1110. var t=this.$inherited(name,ancestor,o);
  1111. t.members = {};
  1112. t.names = [];
  1113. t.fields = [];
  1114. t.methods = [];
  1115. t.properties = [];
  1116. return t;
  1117. },
  1118. $TI: function(name,kind,o){ var t=this.$inherited(name,rtl.tTypeInfo,o); t.kind = kind; return t; },
  1119. $Int: function(name,o){ return this.$inherited(name,rtl.tTypeInfoInteger,o); },
  1120. $Enum: function(name,o){ return this.$inherited(name,rtl.tTypeInfoEnum,o); },
  1121. $Set: function(name,o){ return this.$inherited(name,rtl.tTypeInfoSet,o); },
  1122. $StaticArray: function(name,o){ return this.$inherited(name,rtl.tTypeInfoArray,o); },
  1123. $DynArray: function(name,o){ return this.$inherited(name,rtl.tTypeInfoDynArray,o); },
  1124. $ProcVar: function(name,o){ return this.$inherited(name,rtl.tTypeInfoProcVar,o); },
  1125. $RefToProcVar: function(name,o){ return this.$inherited(name,rtl.tTypeInfoRefToProcVar,o); },
  1126. $MethodVar: function(name,o){ return this.$inherited(name,rtl.tTypeInfoMethodVar,o); },
  1127. $Record: function(name,o){ return this.$Scope(name,rtl.tTypeInfoRecord,o); },
  1128. $Class: function(name,o){ return this.$Scope(name,rtl.tTypeInfoClass,o); },
  1129. $ClassRef: function(name,o){ return this.$inherited(name,rtl.tTypeInfoClassRef,o); },
  1130. $Pointer: function(name,o){ return this.$inherited(name,rtl.tTypeInfoPointer,o); },
  1131. $Interface: function(name,o){ return this.$Scope(name,rtl.tTypeInfoInterface,o); }
  1132. $Helper: function(name,o){ return this.$Scope(name,rtl.tTypeInfoHelper,o); }
  1133. },
  1134. newTIParam: function(param){
  1135. // param is an array, 0=name, 1=type, 2=optional flags
  1136. var t = {
  1137. name: param[0],
  1138. typeinfo: param[1],
  1139. flags: (rtl.isNumber(param[2]) ? param[2] : 0)
  1140. };
  1141. return t;
  1142. },
  1143. newTIParams: function(list){
  1144. // list: optional array of [paramname,typeinfo,optional flags]
  1145. var params = [];
  1146. if (rtl.isArray(list)){
  1147. for (var i=0; i<list.length; i++) params.push(rtl.newTIParam(list[i]));
  1148. };
  1149. return params;
  1150. },
  1151. newTIProcSig: function(params,result,flags){
  1152. var s = {
  1153. params: rtl.newTIParams(params),
  1154. resulttype: result,
  1155. flags: flags
  1156. };
  1157. return s;
  1158. }
  1159. }