2
0

Helios-Helpers.js 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186
  1. define("amber_core/Helios-Helpers", ["amber_vm/smalltalk", "amber_vm/nil", "amber_vm/_st", "amber_core/Kernel-Objects"], function(smalltalk,nil,_st){
  2. smalltalk.addPackage('Helios-Helpers');
  3. smalltalk.packages["Helios-Helpers"].transport = {"type":"amd","amdNamespace":"amber_core"};
  4. smalltalk.addClass('HLClassifierLink', smalltalk.Object, ['next', 'method'], 'Helios-Helpers');
  5. smalltalk.HLClassifierLink.comment="I am an abstract class implementing a link in a `chain of responsibility` pattern.\x0a\x0ay subclasses are in charge of classifying a method according to multiple strategies";
  6. smalltalk.addMethod(
  7. smalltalk.method({
  8. selector: "classify",
  9. protocol: 'protocol',
  10. fn: function (){
  11. var self=this;
  12. return smalltalk.withContext(function($ctx1) {
  13. var $1,$3,$2;
  14. $1=self._next();
  15. $ctx1.sendIdx["next"]=1;
  16. if(($receiver = $1) == nil || $receiver == null){
  17. return false;
  18. } else {
  19. $1;
  20. };
  21. $3=self._doClassify();
  22. if(smalltalk.assert($3)){
  23. $2=true;
  24. } else {
  25. $2=_st(self._next())._execute();
  26. };
  27. return $2;
  28. }, function($ctx1) {$ctx1.fill(self,"classify",{},smalltalk.HLClassifierLink)})},
  29. args: [],
  30. source: "classify\x0a\x09self next ifNil: [ ^ false ].\x0a\x09\x0a\x09^ self doClassify\x0a\x09\x09ifTrue: [ true ]\x0a\x09\x09ifFalse: [ self next execute ]",
  31. messageSends: ["ifNil:", "next", "ifTrue:ifFalse:", "doClassify", "execute"],
  32. referencedClasses: []
  33. }),
  34. smalltalk.HLClassifierLink);
  35. smalltalk.addMethod(
  36. smalltalk.method({
  37. selector: "doClassify",
  38. protocol: 'private',
  39. fn: function (){
  40. var self=this;
  41. return smalltalk.withContext(function($ctx1) {
  42. self._subclassResponsibility();
  43. return self}, function($ctx1) {$ctx1.fill(self,"doClassify",{},smalltalk.HLClassifierLink)})},
  44. args: [],
  45. source: "doClassify\x0a\x09self subclassResponsibility",
  46. messageSends: ["subclassResponsibility"],
  47. referencedClasses: []
  48. }),
  49. smalltalk.HLClassifierLink);
  50. smalltalk.addMethod(
  51. smalltalk.method({
  52. selector: "method",
  53. protocol: 'accessing',
  54. fn: function (){
  55. var self=this;
  56. return smalltalk.withContext(function($ctx1) {
  57. var $1;
  58. $1=self["@method"];
  59. return $1;
  60. }, function($ctx1) {$ctx1.fill(self,"method",{},smalltalk.HLClassifierLink)})},
  61. args: [],
  62. source: "method\x0a\x09^ method",
  63. messageSends: [],
  64. referencedClasses: []
  65. }),
  66. smalltalk.HLClassifierLink);
  67. smalltalk.addMethod(
  68. smalltalk.method({
  69. selector: "method:",
  70. protocol: 'accessing',
  71. fn: function (anObject){
  72. var self=this;
  73. return smalltalk.withContext(function($ctx1) {
  74. var $1;
  75. self["@method"]=anObject;
  76. $1=self._next();
  77. if(($receiver = $1) == nil || $receiver == null){
  78. $1;
  79. } else {
  80. var nextLink;
  81. nextLink=$receiver;
  82. _st(nextLink)._method_(anObject);
  83. };
  84. return self}, function($ctx1) {$ctx1.fill(self,"method:",{anObject:anObject},smalltalk.HLClassifierLink)})},
  85. args: ["anObject"],
  86. source: "method: anObject\x0a\x09method := anObject.\x0a\x09self next\x0a\x09\x09ifNotNil: [ :nextLink | nextLink method: anObject ]",
  87. messageSends: ["ifNotNil:", "next", "method:"],
  88. referencedClasses: []
  89. }),
  90. smalltalk.HLClassifierLink);
  91. smalltalk.addMethod(
  92. smalltalk.method({
  93. selector: "next",
  94. protocol: 'accessing',
  95. fn: function (){
  96. var self=this;
  97. return smalltalk.withContext(function($ctx1) {
  98. var $1;
  99. $1=self["@next"];
  100. return $1;
  101. }, function($ctx1) {$ctx1.fill(self,"next",{},smalltalk.HLClassifierLink)})},
  102. args: [],
  103. source: "next\x0a\x09^ next",
  104. messageSends: [],
  105. referencedClasses: []
  106. }),
  107. smalltalk.HLClassifierLink);
  108. smalltalk.addMethod(
  109. smalltalk.method({
  110. selector: "next:",
  111. protocol: 'accessing',
  112. fn: function (anObject){
  113. var self=this;
  114. return smalltalk.withContext(function($ctx1) {
  115. self["@next"]=anObject;
  116. return self}, function($ctx1) {$ctx1.fill(self,"next:",{anObject:anObject},smalltalk.HLClassifierLink)})},
  117. args: ["anObject"],
  118. source: "next: anObject\x0a\x09next := anObject",
  119. messageSends: [],
  120. referencedClasses: []
  121. }),
  122. smalltalk.HLClassifierLink);
  123. smalltalk.addClass('HLAccessorClassifierLink', smalltalk.HLClassifierLink, [], 'Helios-Helpers');
  124. smalltalk.HLAccessorClassifierLink.comment="I am a classifier checking the method selector matches an instance variable name";
  125. smalltalk.addMethod(
  126. smalltalk.method({
  127. selector: "doClassify",
  128. protocol: 'private',
  129. fn: function (){
  130. var self=this;
  131. var names,selector;
  132. return smalltalk.withContext(function($ctx1) {
  133. var $1,$2;
  134. names=_st(_st(self["@method"])._methodClass())._allInstanceVariableNames();
  135. selector=_st(self["@method"])._selector();
  136. $1=_st(_st(selector)._last()).__eq(":");
  137. if(smalltalk.assert($1)){
  138. selector=_st(selector)._allButLast();
  139. selector;
  140. };
  141. $2=_st(names)._includes_(selector);
  142. if(! smalltalk.assert($2)){
  143. return false;
  144. };
  145. _st(self["@method"])._protocol_("accessing");
  146. return true;
  147. }, function($ctx1) {$ctx1.fill(self,"doClassify",{names:names,selector:selector},smalltalk.HLAccessorClassifierLink)})},
  148. args: [],
  149. source: "doClassify\x0a\x09| names selector |\x0a\x09\x0a\x09names := method methodClass allInstanceVariableNames.\x0a\x09selector := method selector.\x0a\x09\x0a\x09(selector last = ':')\x0a\x09\x09ifTrue: [ \x22selector might be a setter\x22\x0a\x09\x09\x09selector := selector allButLast ].\x0a\x09\x0a\x09(names includes: selector)\x0a\x09\x09ifFalse: [ ^ false ].\x0a\x09\x09\x0a\x09method protocol: 'accessing'.\x0a\x09^ true.",
  150. messageSends: ["allInstanceVariableNames", "methodClass", "selector", "ifTrue:", "=", "last", "allButLast", "ifFalse:", "includes:", "protocol:"],
  151. referencedClasses: []
  152. }),
  153. smalltalk.HLAccessorClassifierLink);
  154. smalltalk.addClass('HLImplementorClassifierLink', smalltalk.HLClassifierLink, [], 'Helios-Helpers');
  155. smalltalk.HLImplementorClassifierLink.comment="I am a classifier checking the other implementations of the same selector and choose the protocol the most populated";
  156. smalltalk.addMethod(
  157. smalltalk.method({
  158. selector: "doClassify",
  159. protocol: 'private',
  160. fn: function (){
  161. var self=this;
  162. var currentClass;
  163. return smalltalk.withContext(function($ctx1) {
  164. var $1,$3,$4,$2;
  165. var $early={};
  166. try {
  167. currentClass=_st(self["@method"])._methodClass();
  168. _st((function(){
  169. return smalltalk.withContext(function($ctx2) {
  170. $1=_st(currentClass)._superclass();
  171. $ctx2.sendIdx["superclass"]=1;
  172. return _st($1)._isNil();
  173. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}))._whileFalse_((function(){
  174. return smalltalk.withContext(function($ctx2) {
  175. currentClass=_st(currentClass)._superclass();
  176. currentClass;
  177. $3=currentClass;
  178. $4=_st(self["@method"])._selector();
  179. $ctx2.sendIdx["selector"]=1;
  180. $2=_st($3)._includesSelector_($4);
  181. if(smalltalk.assert($2)){
  182. _st(self["@method"])._protocol_(_st(_st(currentClass).__gt_gt(_st(self["@method"])._selector()))._protocol());
  183. throw $early=[true];
  184. };
  185. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}));
  186. return false;
  187. }
  188. catch(e) {if(e===$early)return e[0]; throw e}
  189. }, function($ctx1) {$ctx1.fill(self,"doClassify",{currentClass:currentClass},smalltalk.HLImplementorClassifierLink)})},
  190. args: [],
  191. source: "doClassify\x0a\x09| currentClass |\x0a\x09currentClass := method methodClass.\x0a\x09\x0a\x09[ currentClass superclass isNil ] whileFalse: [\x0a\x09\x09currentClass := currentClass superclass.\x0a\x09\x09(currentClass includesSelector: method selector)\x0a\x09\x09\x09ifTrue: [ \x0a\x09\x09\x09\x09method protocol: (currentClass >> method selector) protocol.\x0a\x09\x09\x09\x09^ true ]].\x0a\x09\x0a\x09^ false.",
  192. messageSends: ["methodClass", "whileFalse:", "isNil", "superclass", "ifTrue:", "includesSelector:", "selector", "protocol:", "protocol", ">>"],
  193. referencedClasses: []
  194. }),
  195. smalltalk.HLImplementorClassifierLink);
  196. smalltalk.addClass('HLPrefixClassifierLink', smalltalk.HLClassifierLink, ['prefixMapping'], 'Helios-Helpers');
  197. smalltalk.HLPrefixClassifierLink.comment="I am classifier checking the method selector to know if it begins with a known prefix";
  198. smalltalk.addMethod(
  199. smalltalk.method({
  200. selector: "buildPrefixDictionary",
  201. protocol: 'initialization',
  202. fn: function (){
  203. var self=this;
  204. function $Dictionary(){return smalltalk.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  205. return smalltalk.withContext(function($ctx1) {
  206. var $1,$2;
  207. self["@prefixMapping"]=_st($Dictionary())._new();
  208. $1=self["@prefixMapping"];
  209. _st($1)._at_put_("test","tests");
  210. $ctx1.sendIdx["at:put:"]=1;
  211. _st($1)._at_put_("bench","benchmarking");
  212. $ctx1.sendIdx["at:put:"]=2;
  213. _st($1)._at_put_("copy","copying");
  214. $ctx1.sendIdx["at:put:"]=3;
  215. _st($1)._at_put_("initialize","initialization");
  216. $ctx1.sendIdx["at:put:"]=4;
  217. _st($1)._at_put_("accept","visitor");
  218. $ctx1.sendIdx["at:put:"]=5;
  219. _st($1)._at_put_("visit","visitor");
  220. $ctx1.sendIdx["at:put:"]=6;
  221. _st($1)._at_put_("signal","signalling");
  222. $ctx1.sendIdx["at:put:"]=7;
  223. _st($1)._at_put_("parse","parsing");
  224. $ctx1.sendIdx["at:put:"]=8;
  225. _st($1)._at_put_("add","adding");
  226. $ctx1.sendIdx["at:put:"]=9;
  227. _st($1)._at_put_("is","testing");
  228. $ctx1.sendIdx["at:put:"]=10;
  229. _st($1)._at_put_("as","converting");
  230. $ctx1.sendIdx["at:put:"]=11;
  231. $2=_st($1)._at_put_("new","instance creation");
  232. return self}, function($ctx1) {$ctx1.fill(self,"buildPrefixDictionary",{},smalltalk.HLPrefixClassifierLink)})},
  233. args: [],
  234. source: "buildPrefixDictionary\x0a\x09prefixMapping := Dictionary new.\x0a\x09prefixMapping \x0a\x09\x09at: 'test' put: 'tests';\x0a\x09 \x09at: 'bench' put: 'benchmarking';\x0a\x09 \x09at: 'copy' put: 'copying';\x0a\x09\x09at: 'initialize' put: 'initialization';\x0a\x09\x09at: 'accept' put: 'visitor';\x0a\x09\x09at: 'visit' put: 'visitor';\x0a\x09\x09at: 'signal' put: 'signalling';\x0a\x09\x09at: 'parse' put: 'parsing';\x0a\x09\x09at: 'add' put: 'adding';\x0a\x09\x09at: 'is' put: 'testing';\x0a\x09\x09at: 'as' put: 'converting';\x0a\x09\x09at: 'new' put: 'instance creation'.",
  235. messageSends: ["new", "at:put:"],
  236. referencedClasses: ["Dictionary"]
  237. }),
  238. smalltalk.HLPrefixClassifierLink);
  239. smalltalk.addMethod(
  240. smalltalk.method({
  241. selector: "doClassify",
  242. protocol: 'private',
  243. fn: function (){
  244. var self=this;
  245. return smalltalk.withContext(function($ctx1) {
  246. var $1;
  247. var $early={};
  248. try {
  249. _st(self["@prefixMapping"])._keysAndValuesDo_((function(prefix,protocol){
  250. return smalltalk.withContext(function($ctx2) {
  251. $1=_st(_st(self["@method"])._selector())._beginsWith_(prefix);
  252. if(smalltalk.assert($1)){
  253. _st(self["@method"])._protocol_(protocol);
  254. throw $early=[true];
  255. };
  256. }, function($ctx2) {$ctx2.fillBlock({prefix:prefix,protocol:protocol},$ctx1,1)})}));
  257. return false;
  258. }
  259. catch(e) {if(e===$early)return e[0]; throw e}
  260. }, function($ctx1) {$ctx1.fill(self,"doClassify",{},smalltalk.HLPrefixClassifierLink)})},
  261. args: [],
  262. source: "doClassify\x0a\x09prefixMapping keysAndValuesDo: [ :prefix :protocol |\x0a\x09\x09(method selector beginsWith: prefix)\x0a\x09\x09\x09ifTrue: [\x0a\x09\x09\x09\x09method protocol: protocol.\x0a\x09\x09\x09\x09^ true ]].\x0a\x09^ false.",
  263. messageSends: ["keysAndValuesDo:", "ifTrue:", "beginsWith:", "selector", "protocol:"],
  264. referencedClasses: []
  265. }),
  266. smalltalk.HLPrefixClassifierLink);
  267. smalltalk.addMethod(
  268. smalltalk.method({
  269. selector: "initialize",
  270. protocol: 'initialization',
  271. fn: function (){
  272. var self=this;
  273. return smalltalk.withContext(function($ctx1) {
  274. smalltalk.HLPrefixClassifierLink.superclass.fn.prototype._initialize.apply(_st(self), []);
  275. self._buildPrefixDictionary();
  276. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.HLPrefixClassifierLink)})},
  277. args: [],
  278. source: "initialize\x0a\x09super initialize.\x0a\x0a\x09self buildPrefixDictionary",
  279. messageSends: ["initialize", "buildPrefixDictionary"],
  280. referencedClasses: []
  281. }),
  282. smalltalk.HLPrefixClassifierLink);
  283. smalltalk.addClass('HLSuperClassClassifierLink', smalltalk.HLClassifierLink, [], 'Helios-Helpers');
  284. smalltalk.HLSuperClassClassifierLink.comment="I am a classifier checking the superclass chain to find a matching selector";
  285. smalltalk.addMethod(
  286. smalltalk.method({
  287. selector: "doClassify",
  288. protocol: 'private',
  289. fn: function (){
  290. var self=this;
  291. var protocolBag,methods,protocolToUse,counter;
  292. function $Dictionary(){return smalltalk.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  293. function $HLReferencesModel(){return smalltalk.HLReferencesModel||(typeof HLReferencesModel=="undefined"?nil:HLReferencesModel)}
  294. return smalltalk.withContext(function($ctx1) {
  295. var $2,$1,$4,$3,$5;
  296. var $early={};
  297. try {
  298. protocolBag=_st($Dictionary())._new();
  299. $ctx1.sendIdx["new"]=1;
  300. methods=_st(_st($HLReferencesModel())._new())._implementorsOf_(_st(self["@method"])._selector());
  301. _st(methods)._ifEmpty_ifNotEmpty_((function(){
  302. return smalltalk.withContext(function($ctx2) {
  303. throw $early=[false];
  304. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),(function(){
  305. return smalltalk.withContext(function($ctx2) {
  306. return _st(methods)._do_((function(aMethod){
  307. var protocol;
  308. return smalltalk.withContext(function($ctx3) {
  309. protocol=_st(_st(aMethod)._method())._protocol();
  310. protocol;
  311. $2=_st(self["@method"])._methodClass();
  312. $ctx3.sendIdx["methodClass"]=1;
  313. $1=_st($2).__eq(_st(aMethod)._methodClass());
  314. $ctx3.sendIdx["="]=1;
  315. if(! smalltalk.assert($1)){
  316. $4=_st(_st(protocol)._first()).__eq("*");
  317. $ctx3.sendIdx["="]=2;
  318. $3=_st($4)._or_((function(){
  319. return smalltalk.withContext(function($ctx4) {
  320. return _st(protocol).__eq(_st(self["@method"])._defaultProtocol());
  321. }, function($ctx4) {$ctx4.fillBlock({},$ctx3,5)})}));
  322. if(! smalltalk.assert($3)){
  323. return _st(protocolBag)._at_put_(protocol,_st(_st(protocolBag)._at_ifAbsent_(protocol,(function(){
  324. return smalltalk.withContext(function($ctx4) {
  325. return (0);
  326. }, function($ctx4) {$ctx4.fillBlock({},$ctx3,7)})}))).__plus((1)));
  327. };
  328. };
  329. }, function($ctx3) {$ctx3.fillBlock({aMethod:aMethod,protocol:protocol},$ctx2,3)})}));
  330. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}));
  331. _st(protocolBag)._ifEmpty_((function(){
  332. return smalltalk.withContext(function($ctx2) {
  333. throw $early=[false];
  334. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,8)})}));
  335. protocolToUse=nil;
  336. counter=(0);
  337. _st(protocolBag)._keysAndValuesDo_((function(key,value){
  338. return smalltalk.withContext(function($ctx2) {
  339. $5=_st(value).__gt(counter);
  340. if(smalltalk.assert($5)){
  341. counter=value;
  342. counter;
  343. protocolToUse=key;
  344. return protocolToUse;
  345. };
  346. }, function($ctx2) {$ctx2.fillBlock({key:key,value:value},$ctx1,9)})}));
  347. _st(self["@method"])._protocol_(protocolToUse);
  348. return true;
  349. }
  350. catch(e) {if(e===$early)return e[0]; throw e}
  351. }, function($ctx1) {$ctx1.fill(self,"doClassify",{protocolBag:protocolBag,methods:methods,protocolToUse:protocolToUse,counter:counter},smalltalk.HLSuperClassClassifierLink)})},
  352. args: [],
  353. source: "doClassify\x0a\x09| protocolBag methods protocolToUse counter |\x0a\x09\x0a\x09protocolBag := Dictionary new.\x0a\x09methods := HLReferencesModel new implementorsOf: method selector.\x0a\x09methods\x0a\x09\x09ifEmpty: [ ^ false ]\x0a\x09\x09ifNotEmpty: [\x0a\x09\x09\x09methods \x0a\x09\x09\x09\x09do: [ :aMethod || protocol |\x0a\x09\x09\x09\x09\x09protocol := aMethod method protocol.\x0a\x09\x09\x09\x09\x09(method methodClass = aMethod methodClass)\x0a\x09\x09\x09\x09\x09\x09ifFalse: [\x0a\x09\x09\x09\x09\x09\x09((protocol first = '*') or: [ protocol = method defaultProtocol ])\x0a\x09\x09\x09\x09\x09\x09\x09ifFalse: [ \x0a\x09\x09\x09\x09\x09\x09\x09\x09protocolBag \x0a\x09\x09\x09\x09\x09\x09\x09\x09\x09at: protocol \x0a\x09\x09\x09\x09\x09\x09\x09\x09\x09put: (protocolBag at: protocol ifAbsent: [ 0 ]) + 1 ] ] ] ].\x0a\x09\x09\x09\x0a\x09protocolBag ifEmpty: [ ^ false ].\x0a\x09protocolToUse := nil.\x0a\x09counter := 0.\x0a\x09protocolBag keysAndValuesDo: [ :key :value | value > counter \x0a\x09\x09ifTrue: [\x0a\x09\x09\x09counter := value.\x0a\x09\x09\x09protocolToUse := key ] ].\x0a\x09method protocol: protocolToUse.\x0a\x09^ true",
  354. messageSends: ["new", "implementorsOf:", "selector", "ifEmpty:ifNotEmpty:", "do:", "protocol", "method", "ifFalse:", "=", "methodClass", "or:", "first", "defaultProtocol", "at:put:", "+", "at:ifAbsent:", "ifEmpty:", "keysAndValuesDo:", "ifTrue:", ">", "protocol:"],
  355. referencedClasses: ["Dictionary", "HLReferencesModel"]
  356. }),
  357. smalltalk.HLSuperClassClassifierLink);
  358. smalltalk.addClass('HLGenerationOutput', smalltalk.Object, ['sourceCodes', 'protocol', 'targetClass'], 'Helios-Helpers');
  359. smalltalk.HLGenerationOutput.comment="I am a simple data object used to store the result of a generation process";
  360. smalltalk.addMethod(
  361. smalltalk.method({
  362. selector: "addSourceCode:",
  363. protocol: 'protocol',
  364. fn: function (aString){
  365. var self=this;
  366. return smalltalk.withContext(function($ctx1) {
  367. _st(self["@sourceCodes"])._add_(aString);
  368. return self}, function($ctx1) {$ctx1.fill(self,"addSourceCode:",{aString:aString},smalltalk.HLGenerationOutput)})},
  369. args: ["aString"],
  370. source: "addSourceCode: aString\x0a\x09sourceCodes add: aString",
  371. messageSends: ["add:"],
  372. referencedClasses: []
  373. }),
  374. smalltalk.HLGenerationOutput);
  375. smalltalk.addMethod(
  376. smalltalk.method({
  377. selector: "compile",
  378. protocol: 'protocol',
  379. fn: function (){
  380. var self=this;
  381. return smalltalk.withContext(function($ctx1) {
  382. var $1;
  383. _st(self["@sourceCodes"])._do_((function(methodSourceCode){
  384. return smalltalk.withContext(function($ctx2) {
  385. $1=_st(self["@targetClass"])._includesSelector_(_st(methodSourceCode)._selector());
  386. if(! smalltalk.assert($1)){
  387. return _st(self["@targetClass"])._compile_protocol_(_st(methodSourceCode)._sourceCode(),self["@protocol"]);
  388. };
  389. }, function($ctx2) {$ctx2.fillBlock({methodSourceCode:methodSourceCode},$ctx1,1)})}));
  390. return self}, function($ctx1) {$ctx1.fill(self,"compile",{},smalltalk.HLGenerationOutput)})},
  391. args: [],
  392. source: "compile\x0a\x09sourceCodes do: [ :methodSourceCode |\x0a\x09\x09(targetClass includesSelector: methodSourceCode selector)\x0a\x09\x09\x09ifFalse: [ \x0a\x09\x09\x09\x09targetClass \x0a\x09\x09\x09\x09\x09compile: methodSourceCode sourceCode\x0a\x09\x09\x09\x09\x09protocol: protocol ] ]",
  393. messageSends: ["do:", "ifFalse:", "includesSelector:", "selector", "compile:protocol:", "sourceCode"],
  394. referencedClasses: []
  395. }),
  396. smalltalk.HLGenerationOutput);
  397. smalltalk.addMethod(
  398. smalltalk.method({
  399. selector: "initialize",
  400. protocol: 'initialization',
  401. fn: function (){
  402. var self=this;
  403. function $OrderedCollection(){return smalltalk.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
  404. return smalltalk.withContext(function($ctx1) {
  405. smalltalk.HLGenerationOutput.superclass.fn.prototype._initialize.apply(_st(self), []);
  406. self["@sourceCodes"]=_st($OrderedCollection())._new();
  407. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.HLGenerationOutput)})},
  408. args: [],
  409. source: "initialize\x0a\x09super initialize.\x0a\x09\x0a\x09sourceCodes := OrderedCollection new",
  410. messageSends: ["initialize", "new"],
  411. referencedClasses: ["OrderedCollection"]
  412. }),
  413. smalltalk.HLGenerationOutput);
  414. smalltalk.addMethod(
  415. smalltalk.method({
  416. selector: "protocol",
  417. protocol: 'accessing',
  418. fn: function (){
  419. var self=this;
  420. return smalltalk.withContext(function($ctx1) {
  421. var $1;
  422. $1=self["@protocol"];
  423. return $1;
  424. }, function($ctx1) {$ctx1.fill(self,"protocol",{},smalltalk.HLGenerationOutput)})},
  425. args: [],
  426. source: "protocol\x0a\x09^ protocol",
  427. messageSends: [],
  428. referencedClasses: []
  429. }),
  430. smalltalk.HLGenerationOutput);
  431. smalltalk.addMethod(
  432. smalltalk.method({
  433. selector: "protocol:",
  434. protocol: 'accessing',
  435. fn: function (aString){
  436. var self=this;
  437. return smalltalk.withContext(function($ctx1) {
  438. self["@protocol"]=aString;
  439. return self}, function($ctx1) {$ctx1.fill(self,"protocol:",{aString:aString},smalltalk.HLGenerationOutput)})},
  440. args: ["aString"],
  441. source: "protocol: aString\x0a\x09protocol := aString",
  442. messageSends: [],
  443. referencedClasses: []
  444. }),
  445. smalltalk.HLGenerationOutput);
  446. smalltalk.addMethod(
  447. smalltalk.method({
  448. selector: "sourceCodes",
  449. protocol: 'accessing',
  450. fn: function (){
  451. var self=this;
  452. return smalltalk.withContext(function($ctx1) {
  453. var $1;
  454. $1=self["@sourceCodes"];
  455. return $1;
  456. }, function($ctx1) {$ctx1.fill(self,"sourceCodes",{},smalltalk.HLGenerationOutput)})},
  457. args: [],
  458. source: "sourceCodes\x0a\x09^ sourceCodes",
  459. messageSends: [],
  460. referencedClasses: []
  461. }),
  462. smalltalk.HLGenerationOutput);
  463. smalltalk.addMethod(
  464. smalltalk.method({
  465. selector: "sourceCodes:",
  466. protocol: 'accessing',
  467. fn: function (aCollection){
  468. var self=this;
  469. return smalltalk.withContext(function($ctx1) {
  470. self["@sourceCodes"]=aCollection;
  471. return self}, function($ctx1) {$ctx1.fill(self,"sourceCodes:",{aCollection:aCollection},smalltalk.HLGenerationOutput)})},
  472. args: ["aCollection"],
  473. source: "sourceCodes: aCollection\x0a\x09sourceCodes := aCollection",
  474. messageSends: [],
  475. referencedClasses: []
  476. }),
  477. smalltalk.HLGenerationOutput);
  478. smalltalk.addMethod(
  479. smalltalk.method({
  480. selector: "targetClass",
  481. protocol: 'accessing',
  482. fn: function (){
  483. var self=this;
  484. return smalltalk.withContext(function($ctx1) {
  485. var $1;
  486. $1=self["@targetClass"];
  487. return $1;
  488. }, function($ctx1) {$ctx1.fill(self,"targetClass",{},smalltalk.HLGenerationOutput)})},
  489. args: [],
  490. source: "targetClass\x0a\x09^ targetClass",
  491. messageSends: [],
  492. referencedClasses: []
  493. }),
  494. smalltalk.HLGenerationOutput);
  495. smalltalk.addMethod(
  496. smalltalk.method({
  497. selector: "targetClass:",
  498. protocol: 'accessing',
  499. fn: function (aClass){
  500. var self=this;
  501. return smalltalk.withContext(function($ctx1) {
  502. self["@targetClass"]=aClass;
  503. return self}, function($ctx1) {$ctx1.fill(self,"targetClass:",{aClass:aClass},smalltalk.HLGenerationOutput)})},
  504. args: ["aClass"],
  505. source: "targetClass: aClass\x0a\x09targetClass := aClass",
  506. messageSends: [],
  507. referencedClasses: []
  508. }),
  509. smalltalk.HLGenerationOutput);
  510. smalltalk.addClass('HLGenerationOutputWithIndex', smalltalk.HLGenerationOutput, ['index'], 'Helios-Helpers');
  511. smalltalk.HLGenerationOutputWithIndex.comment="I am a simple data object used to store the result of a generation process.\x0a\x0aIn addition of my super class, I have an index where to put the cursor at the end of the process for the first method created (aka. the first in `sourceCodes`)";
  512. smalltalk.addMethod(
  513. smalltalk.method({
  514. selector: "index",
  515. protocol: 'accessing',
  516. fn: function (){
  517. var self=this;
  518. return smalltalk.withContext(function($ctx1) {
  519. var $1;
  520. $1=self["@index"];
  521. return $1;
  522. }, function($ctx1) {$ctx1.fill(self,"index",{},smalltalk.HLGenerationOutputWithIndex)})},
  523. args: [],
  524. source: "index\x0a\x09^ index",
  525. messageSends: [],
  526. referencedClasses: []
  527. }),
  528. smalltalk.HLGenerationOutputWithIndex);
  529. smalltalk.addMethod(
  530. smalltalk.method({
  531. selector: "index:",
  532. protocol: 'accessing',
  533. fn: function (anIndex){
  534. var self=this;
  535. return smalltalk.withContext(function($ctx1) {
  536. self["@index"]=anIndex;
  537. return self}, function($ctx1) {$ctx1.fill(self,"index:",{anIndex:anIndex},smalltalk.HLGenerationOutputWithIndex)})},
  538. args: ["anIndex"],
  539. source: "index: anIndex\x0a\x09index := anIndex",
  540. messageSends: [],
  541. referencedClasses: []
  542. }),
  543. smalltalk.HLGenerationOutputWithIndex);
  544. smalltalk.addClass('HLGenerator', smalltalk.Object, ['output'], 'Helios-Helpers');
  545. smalltalk.HLGenerator.comment="I am the abstract super class of the generators.\x0a\x0aMy main method is `generate` which produce an `output` object";
  546. smalltalk.addMethod(
  547. smalltalk.method({
  548. selector: "class:",
  549. protocol: 'accessing',
  550. fn: function (aClass){
  551. var self=this;
  552. return smalltalk.withContext(function($ctx1) {
  553. _st(self["@output"])._targetClass_(aClass);
  554. return self}, function($ctx1) {$ctx1.fill(self,"class:",{aClass:aClass},smalltalk.HLGenerator)})},
  555. args: ["aClass"],
  556. source: "class: aClass\x0a\x09output targetClass: aClass",
  557. messageSends: ["targetClass:"],
  558. referencedClasses: []
  559. }),
  560. smalltalk.HLGenerator);
  561. smalltalk.addMethod(
  562. smalltalk.method({
  563. selector: "generate",
  564. protocol: 'protocol',
  565. fn: function (){
  566. var self=this;
  567. return smalltalk.withContext(function($ctx1) {
  568. var $1;
  569. $1=_st(self["@output"])._targetClass();
  570. if(($receiver = $1) == nil || $receiver == null){
  571. self._error_("class should not be nil");
  572. } else {
  573. $1;
  574. };
  575. return self}, function($ctx1) {$ctx1.fill(self,"generate",{},smalltalk.HLGenerator)})},
  576. args: [],
  577. source: "generate\x0a\x09output targetClass ifNil: [ self error: 'class should not be nil'].",
  578. messageSends: ["ifNil:", "targetClass", "error:"],
  579. referencedClasses: []
  580. }),
  581. smalltalk.HLGenerator);
  582. smalltalk.addMethod(
  583. smalltalk.method({
  584. selector: "initialize",
  585. protocol: 'initialization',
  586. fn: function (){
  587. var self=this;
  588. function $HLGenerationOutput(){return smalltalk.HLGenerationOutput||(typeof HLGenerationOutput=="undefined"?nil:HLGenerationOutput)}
  589. return smalltalk.withContext(function($ctx1) {
  590. smalltalk.HLGenerator.superclass.fn.prototype._initialize.apply(_st(self), []);
  591. self["@output"]=_st($HLGenerationOutput())._new();
  592. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.HLGenerator)})},
  593. args: [],
  594. source: "initialize\x0a\x09super initialize.\x0a\x09\x0a\x09output := HLGenerationOutput new",
  595. messageSends: ["initialize", "new"],
  596. referencedClasses: ["HLGenerationOutput"]
  597. }),
  598. smalltalk.HLGenerator);
  599. smalltalk.addMethod(
  600. smalltalk.method({
  601. selector: "output",
  602. protocol: 'accessing',
  603. fn: function (){
  604. var self=this;
  605. return smalltalk.withContext(function($ctx1) {
  606. var $1;
  607. $1=self["@output"];
  608. return $1;
  609. }, function($ctx1) {$ctx1.fill(self,"output",{},smalltalk.HLGenerator)})},
  610. args: [],
  611. source: "output\x0a\x09^ output",
  612. messageSends: [],
  613. referencedClasses: []
  614. }),
  615. smalltalk.HLGenerator);
  616. smalltalk.addClass('HLAccessorsGenerator', smalltalk.HLGenerator, [], 'Helios-Helpers');
  617. smalltalk.HLAccessorsGenerator.comment="I am a generator used to compile the getters/setters of a class";
  618. smalltalk.addMethod(
  619. smalltalk.method({
  620. selector: "accessorProtocolForObject",
  621. protocol: 'double-dispatch',
  622. fn: function (){
  623. var self=this;
  624. return smalltalk.withContext(function($ctx1) {
  625. _st(self["@output"])._protocol_("accessing");
  626. return self}, function($ctx1) {$ctx1.fill(self,"accessorProtocolForObject",{},smalltalk.HLAccessorsGenerator)})},
  627. args: [],
  628. source: "accessorProtocolForObject\x0a\x09output protocol: 'accessing'",
  629. messageSends: ["protocol:"],
  630. referencedClasses: []
  631. }),
  632. smalltalk.HLAccessorsGenerator);
  633. smalltalk.addMethod(
  634. smalltalk.method({
  635. selector: "accessorsSourceCodesForObject",
  636. protocol: 'double-dispatch',
  637. fn: function (){
  638. var self=this;
  639. var sources;
  640. function $OrderedCollection(){return smalltalk.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
  641. return smalltalk.withContext(function($ctx1) {
  642. var $1,$2;
  643. sources=_st($OrderedCollection())._new();
  644. _st(_st(_st(_st(self["@output"])._targetClass())._instanceVariableNames())._sorted())._do_((function(each){
  645. return smalltalk.withContext(function($ctx2) {
  646. $1=sources;
  647. _st($1)._add_(self._getterFor_(each));
  648. $ctx2.sendIdx["add:"]=1;
  649. $2=_st($1)._add_(self._setterFor_(each));
  650. return $2;
  651. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  652. _st(self["@output"])._sourceCodes_(sources);
  653. return self}, function($ctx1) {$ctx1.fill(self,"accessorsSourceCodesForObject",{sources:sources},smalltalk.HLAccessorsGenerator)})},
  654. args: [],
  655. source: "accessorsSourceCodesForObject\x0a\x09| sources |\x0a\x09\x0a\x09sources := OrderedCollection new.\x0a\x09output targetClass instanceVariableNames sorted do: [ :each | \x0a\x09\x09sources \x0a\x09\x09\x09add: (self getterFor: each);\x0a\x09\x09\x09add: (self setterFor: each) ].\x0a\x09output sourceCodes: sources",
  656. messageSends: ["new", "do:", "sorted", "instanceVariableNames", "targetClass", "add:", "getterFor:", "setterFor:", "sourceCodes:"],
  657. referencedClasses: ["OrderedCollection"]
  658. }),
  659. smalltalk.HLAccessorsGenerator);
  660. smalltalk.addMethod(
  661. smalltalk.method({
  662. selector: "generate",
  663. protocol: 'protocol',
  664. fn: function (){
  665. var self=this;
  666. return smalltalk.withContext(function($ctx1) {
  667. var $1,$2;
  668. smalltalk.HLAccessorsGenerator.superclass.fn.prototype._generate.apply(_st(self), []);
  669. $1=_st(self["@output"])._targetClass();
  670. _st($1)._accessorsSourceCodesWith_(self);
  671. $2=_st($1)._accessorProtocolWith_(self);
  672. return self}, function($ctx1) {$ctx1.fill(self,"generate",{},smalltalk.HLAccessorsGenerator)})},
  673. args: [],
  674. source: "generate\x0a\x09super generate.\x0a\x09\x0a\x09output targetClass \x0a\x09\x09accessorsSourceCodesWith: self;\x0a\x09\x09accessorProtocolWith: self",
  675. messageSends: ["generate", "accessorsSourceCodesWith:", "targetClass", "accessorProtocolWith:"],
  676. referencedClasses: []
  677. }),
  678. smalltalk.HLAccessorsGenerator);
  679. smalltalk.addMethod(
  680. smalltalk.method({
  681. selector: "getterFor:",
  682. protocol: 'private',
  683. fn: function (anInstanceVariable){
  684. var self=this;
  685. function $HLMethodSourceCode(){return smalltalk.HLMethodSourceCode||(typeof HLMethodSourceCode=="undefined"?nil:HLMethodSourceCode)}
  686. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  687. return smalltalk.withContext(function($ctx1) {
  688. var $2,$3,$1;
  689. $2=_st($HLMethodSourceCode())._new();
  690. _st($2)._selector_(anInstanceVariable);
  691. $3=_st($2)._sourceCode_(_st($String())._streamContents_((function(stream){
  692. return smalltalk.withContext(function($ctx2) {
  693. _st(stream).__lt_lt(anInstanceVariable);
  694. $ctx2.sendIdx["<<"]=1;
  695. _st(_st(stream)._cr())._tab();
  696. return _st(_st(stream).__lt_lt("^ ")).__lt_lt(anInstanceVariable);
  697. $ctx2.sendIdx["<<"]=2;
  698. }, function($ctx2) {$ctx2.fillBlock({stream:stream},$ctx1,1)})})));
  699. $1=$3;
  700. return $1;
  701. }, function($ctx1) {$ctx1.fill(self,"getterFor:",{anInstanceVariable:anInstanceVariable},smalltalk.HLAccessorsGenerator)})},
  702. args: ["anInstanceVariable"],
  703. source: "getterFor: anInstanceVariable\x0a\x09^ HLMethodSourceCode new\x0a\x09\x09selector:anInstanceVariable;\x0a\x09\x09sourceCode: (String streamContents: [ :stream |\x0a\x09\x09stream << anInstanceVariable.\x0a\x09\x09stream cr tab.\x0a\x09\x09stream << '^ ' << anInstanceVariable ])",
  704. messageSends: ["selector:", "new", "sourceCode:", "streamContents:", "<<", "tab", "cr"],
  705. referencedClasses: ["HLMethodSourceCode", "String"]
  706. }),
  707. smalltalk.HLAccessorsGenerator);
  708. smalltalk.addMethod(
  709. smalltalk.method({
  710. selector: "setterFor:",
  711. protocol: 'private',
  712. fn: function (anInstanceVariable){
  713. var self=this;
  714. function $HLMethodSourceCode(){return smalltalk.HLMethodSourceCode||(typeof HLMethodSourceCode=="undefined"?nil:HLMethodSourceCode)}
  715. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  716. return smalltalk.withContext(function($ctx1) {
  717. var $2,$4,$3,$1;
  718. $2=_st($HLMethodSourceCode())._new();
  719. _st($2)._selector_(_st(anInstanceVariable).__comma(":"));
  720. $3=_st($2)._sourceCode_(_st($String())._streamContents_((function(stream){
  721. return smalltalk.withContext(function($ctx2) {
  722. $4=_st(stream).__lt_lt(anInstanceVariable);
  723. $ctx2.sendIdx["<<"]=2;
  724. _st($4).__lt_lt(": anObject");
  725. $ctx2.sendIdx["<<"]=1;
  726. _st(_st(stream)._cr())._tab();
  727. return _st(_st(stream).__lt_lt(anInstanceVariable)).__lt_lt(" := anObject");
  728. $ctx2.sendIdx["<<"]=3;
  729. }, function($ctx2) {$ctx2.fillBlock({stream:stream},$ctx1,1)})})));
  730. $1=$3;
  731. return $1;
  732. }, function($ctx1) {$ctx1.fill(self,"setterFor:",{anInstanceVariable:anInstanceVariable},smalltalk.HLAccessorsGenerator)})},
  733. args: ["anInstanceVariable"],
  734. source: "setterFor: anInstanceVariable\x0a\x09^ HLMethodSourceCode new\x0a\x09\x09selector: anInstanceVariable, ':';\x0a\x09\x09sourceCode: (String streamContents: [ :stream |\x0a\x09\x09stream << anInstanceVariable << ': anObject'.\x0a\x09\x09stream cr tab.\x0a\x09\x09stream << anInstanceVariable << ' := anObject' ])",
  735. messageSends: ["selector:", "new", ",", "sourceCode:", "streamContents:", "<<", "tab", "cr"],
  736. referencedClasses: ["HLMethodSourceCode", "String"]
  737. }),
  738. smalltalk.HLAccessorsGenerator);
  739. smalltalk.addClass('HLInitializeGenerator', smalltalk.HLGenerator, [], 'Helios-Helpers');
  740. smalltalk.HLInitializeGenerator.comment="I am used to double-dispatch the `initialize` method(s) generation.\x0a\x0aUsage:\x0a\x0a ^ HLInitializeGenerator new\x0a class: aClass;\x0a generate;\x0a output\x0a\x0aI am a disposable object";
  741. smalltalk.addMethod(
  742. smalltalk.method({
  743. selector: "computeIndexForObject",
  744. protocol: 'private',
  745. fn: function (){
  746. var self=this;
  747. var instVars,headerSize,firstInstVarSize;
  748. return smalltalk.withContext(function($ctx1) {
  749. var $1;
  750. headerSize=(32);
  751. instVars=_st(_st(self["@output"])._targetClass())._instanceVariableNames();
  752. firstInstVarSize=_st(_st(instVars)._sorted())._ifEmpty_ifNotEmpty_((function(){
  753. return smalltalk.withContext(function($ctx2) {
  754. return (0);
  755. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),(function(){
  756. return smalltalk.withContext(function($ctx2) {
  757. return _st(_st(_st(instVars)._first())._size()).__plus((4));
  758. $ctx2.sendIdx["+"]=1;
  759. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}));
  760. $1=_st(headerSize).__plus(firstInstVarSize);
  761. return $1;
  762. }, function($ctx1) {$ctx1.fill(self,"computeIndexForObject",{instVars:instVars,headerSize:headerSize,firstInstVarSize:firstInstVarSize},smalltalk.HLInitializeGenerator)})},
  763. args: [],
  764. source: "computeIndexForObject\x0a\x09| instVars headerSize firstInstVarSize |\x0a\x09\x0a\x09\x2232 is the size of the `initiliaze super initialize` part\x22\x0a\x09headerSize := 32.\x0a\x09instVars := output targetClass instanceVariableNames.\x0a\x09firstInstVarSize := instVars sorted\x0a\x09\x09ifEmpty: [ 0 ]\x0a\x09\x09ifNotEmpty:[ instVars first size + 4 ].\x0a\x09^ headerSize + firstInstVarSize",
  765. messageSends: ["instanceVariableNames", "targetClass", "ifEmpty:ifNotEmpty:", "sorted", "+", "size", "first"],
  766. referencedClasses: []
  767. }),
  768. smalltalk.HLInitializeGenerator);
  769. smalltalk.addMethod(
  770. smalltalk.method({
  771. selector: "generate",
  772. protocol: 'protocol',
  773. fn: function (){
  774. var self=this;
  775. return smalltalk.withContext(function($ctx1) {
  776. var $1,$2;
  777. smalltalk.HLInitializeGenerator.superclass.fn.prototype._generate.apply(_st(self), []);
  778. $1=_st(self["@output"])._targetClass();
  779. _st($1)._initializeSourceCodesWith_(self);
  780. _st($1)._initializeIndexWith_(self);
  781. $2=_st($1)._initializeProtocolWith_(self);
  782. return self}, function($ctx1) {$ctx1.fill(self,"generate",{},smalltalk.HLInitializeGenerator)})},
  783. args: [],
  784. source: "generate\x0a\x09super generate.\x0a\x09\x0a\x09output targetClass \x0a\x09\x09initializeSourceCodesWith: self;\x0a\x09\x09initializeIndexWith: self;\x0a\x09\x09initializeProtocolWith: self",
  785. messageSends: ["generate", "initializeSourceCodesWith:", "targetClass", "initializeIndexWith:", "initializeProtocolWith:"],
  786. referencedClasses: []
  787. }),
  788. smalltalk.HLInitializeGenerator);
  789. smalltalk.addMethod(
  790. smalltalk.method({
  791. selector: "generateInitializeCodeForObject",
  792. protocol: 'private',
  793. fn: function (){
  794. var self=this;
  795. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  796. return smalltalk.withContext(function($ctx1) {
  797. var $3,$2,$4,$5,$6,$7,$8,$1;
  798. $1=_st($String())._streamContents_((function(str){
  799. var instVars,size;
  800. return smalltalk.withContext(function($ctx2) {
  801. instVars=_st(_st(_st(self["@output"])._targetClass())._instanceVariableNames())._sorted();
  802. instVars;
  803. size=_st(instVars)._size();
  804. size;
  805. _st(str).__lt_lt("initialize");
  806. $ctx2.sendIdx["<<"]=1;
  807. $3=_st(str)._cr();
  808. $ctx2.sendIdx["cr"]=1;
  809. $2=_st($3)._tab();
  810. $ctx2.sendIdx["tab"]=1;
  811. _st($2).__lt_lt("super initialize.");
  812. $ctx2.sendIdx["<<"]=2;
  813. $4=_st($2)._cr();
  814. $ctx2.sendIdx["cr"]=2;
  815. $4;
  816. $5=_st(str)._cr();
  817. $ctx2.sendIdx["cr"]=3;
  818. _st($5)._tab();
  819. $ctx2.sendIdx["tab"]=2;
  820. return _st(instVars)._withIndexDo_((function(name,index){
  821. return smalltalk.withContext(function($ctx3) {
  822. $6=_st(index).__tild_eq((1));
  823. $ctx3.sendIdx["~="]=1;
  824. if(smalltalk.assert($6)){
  825. _st(_st(str)._cr())._tab();
  826. };
  827. $7=_st(str).__lt_lt(name);
  828. $ctx3.sendIdx["<<"]=4;
  829. _st($7).__lt_lt(" := nil");
  830. $ctx3.sendIdx["<<"]=3;
  831. $8=_st(index).__tild_eq(size);
  832. if(smalltalk.assert($8)){
  833. return _st(str).__lt_lt(".");
  834. };
  835. }, function($ctx3) {$ctx3.fillBlock({name:name,index:index},$ctx2,2)})}));
  836. }, function($ctx2) {$ctx2.fillBlock({str:str,instVars:instVars,size:size},$ctx1,1)})}));
  837. return $1;
  838. }, function($ctx1) {$ctx1.fill(self,"generateInitializeCodeForObject",{},smalltalk.HLInitializeGenerator)})},
  839. args: [],
  840. source: "generateInitializeCodeForObject\x09\x0a\x09^ String streamContents: [ :str || instVars size |\x0a\x09\x09instVars := output targetClass instanceVariableNames sorted.\x0a\x09\x09size := instVars size.\x0a\x09\x09str << 'initialize'.\x0a\x09\x09str cr tab << 'super initialize.';cr.\x0a\x09\x09str cr tab.\x0a\x09\x09instVars withIndexDo: [ :name :index |\x0a\x09\x09\x09index ~= 1 ifTrue: [ str cr tab ].\x0a\x09\x09\x09str << name << ' := nil'.\x0a\x09\x09\x09index ~= size ifTrue: [ str << '.' ] ] ].",
  841. messageSends: ["streamContents:", "sorted", "instanceVariableNames", "targetClass", "size", "<<", "tab", "cr", "withIndexDo:", "ifTrue:", "~="],
  842. referencedClasses: ["String"]
  843. }),
  844. smalltalk.HLInitializeGenerator);
  845. smalltalk.addMethod(
  846. smalltalk.method({
  847. selector: "initialize",
  848. protocol: 'initialization',
  849. fn: function (){
  850. var self=this;
  851. function $HLGenerationOutputWithIndex(){return smalltalk.HLGenerationOutputWithIndex||(typeof HLGenerationOutputWithIndex=="undefined"?nil:HLGenerationOutputWithIndex)}
  852. return smalltalk.withContext(function($ctx1) {
  853. smalltalk.HLInitializeGenerator.superclass.fn.prototype._initialize.apply(_st(self), []);
  854. self["@output"]=_st($HLGenerationOutputWithIndex())._new();
  855. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.HLInitializeGenerator)})},
  856. args: [],
  857. source: "initialize\x0a\x09super initialize.\x0a\x09\x0a\x09output := HLGenerationOutputWithIndex new",
  858. messageSends: ["initialize", "new"],
  859. referencedClasses: ["HLGenerationOutputWithIndex"]
  860. }),
  861. smalltalk.HLInitializeGenerator);
  862. smalltalk.addMethod(
  863. smalltalk.method({
  864. selector: "initializeCodeForObject",
  865. protocol: 'private',
  866. fn: function (){
  867. var self=this;
  868. function $HLMethodSourceCode(){return smalltalk.HLMethodSourceCode||(typeof HLMethodSourceCode=="undefined"?nil:HLMethodSourceCode)}
  869. return smalltalk.withContext(function($ctx1) {
  870. var $2,$3,$1;
  871. $2=_st($HLMethodSourceCode())._new();
  872. _st($2)._selector_("initialize");
  873. _st($2)._sourceCode_(self._generateInitializeCodeForObject());
  874. $3=_st($2)._yourself();
  875. $1=$3;
  876. return $1;
  877. }, function($ctx1) {$ctx1.fill(self,"initializeCodeForObject",{},smalltalk.HLInitializeGenerator)})},
  878. args: [],
  879. source: "initializeCodeForObject\x09\x0a\x09^ HLMethodSourceCode new\x0a\x09\x09selector: 'initialize';\x0a\x09\x09sourceCode: self generateInitializeCodeForObject;\x0a\x09\x09yourself",
  880. messageSends: ["selector:", "new", "sourceCode:", "generateInitializeCodeForObject", "yourself"],
  881. referencedClasses: ["HLMethodSourceCode"]
  882. }),
  883. smalltalk.HLInitializeGenerator);
  884. smalltalk.addMethod(
  885. smalltalk.method({
  886. selector: "initializeForObject",
  887. protocol: 'double-dispatch',
  888. fn: function (){
  889. var self=this;
  890. return smalltalk.withContext(function($ctx1) {
  891. _st(self["@output"])._addSourceCode_(self._initializeCodeForObject());
  892. return self}, function($ctx1) {$ctx1.fill(self,"initializeForObject",{},smalltalk.HLInitializeGenerator)})},
  893. args: [],
  894. source: "initializeForObject\x0a\x09output addSourceCode: self initializeCodeForObject",
  895. messageSends: ["addSourceCode:", "initializeCodeForObject"],
  896. referencedClasses: []
  897. }),
  898. smalltalk.HLInitializeGenerator);
  899. smalltalk.addMethod(
  900. smalltalk.method({
  901. selector: "initializeIndexForObject",
  902. protocol: 'double-dispatch',
  903. fn: function (){
  904. var self=this;
  905. return smalltalk.withContext(function($ctx1) {
  906. _st(self["@output"])._index_(self._computeIndexForObject());
  907. return self}, function($ctx1) {$ctx1.fill(self,"initializeIndexForObject",{},smalltalk.HLInitializeGenerator)})},
  908. args: [],
  909. source: "initializeIndexForObject\x0a\x09output index: self computeIndexForObject",
  910. messageSends: ["index:", "computeIndexForObject"],
  911. referencedClasses: []
  912. }),
  913. smalltalk.HLInitializeGenerator);
  914. smalltalk.addMethod(
  915. smalltalk.method({
  916. selector: "initializeProtocolForObject",
  917. protocol: 'double-dispatch',
  918. fn: function (){
  919. var self=this;
  920. return smalltalk.withContext(function($ctx1) {
  921. _st(self["@output"])._protocol_(self._retrieveProtocolForObject());
  922. return self}, function($ctx1) {$ctx1.fill(self,"initializeProtocolForObject",{},smalltalk.HLInitializeGenerator)})},
  923. args: [],
  924. source: "initializeProtocolForObject\x0a\x09output protocol: self retrieveProtocolForObject",
  925. messageSends: ["protocol:", "retrieveProtocolForObject"],
  926. referencedClasses: []
  927. }),
  928. smalltalk.HLInitializeGenerator);
  929. smalltalk.addMethod(
  930. smalltalk.method({
  931. selector: "retrieveProtocolForObject",
  932. protocol: 'private',
  933. fn: function (){
  934. var self=this;
  935. return smalltalk.withContext(function($ctx1) {
  936. return "initialization";
  937. }, function($ctx1) {$ctx1.fill(self,"retrieveProtocolForObject",{},smalltalk.HLInitializeGenerator)})},
  938. args: [],
  939. source: "retrieveProtocolForObject\x0a\x09^ 'initialization'",
  940. messageSends: [],
  941. referencedClasses: []
  942. }),
  943. smalltalk.HLInitializeGenerator);
  944. smalltalk.addClass('HLMethodClassifier', smalltalk.Object, ['firstLink'], 'Helios-Helpers');
  945. smalltalk.HLMethodClassifier.comment="I am in charge of categorizing methods following this strategy:\x0a\x0a- is it an accessor?\x0a- is it overriding a superclass method?\x0a- is it starting with a know prefix?\x0a- how are categorized the other implementations?";
  946. smalltalk.addMethod(
  947. smalltalk.method({
  948. selector: "addLink:",
  949. protocol: 'private',
  950. fn: function (aLink){
  951. var self=this;
  952. return smalltalk.withContext(function($ctx1) {
  953. _st(aLink)._next_(self["@firstLink"]);
  954. self["@firstLink"]=aLink;
  955. return self}, function($ctx1) {$ctx1.fill(self,"addLink:",{aLink:aLink},smalltalk.HLMethodClassifier)})},
  956. args: ["aLink"],
  957. source: "addLink: aLink\x0a\x09aLink next: firstLink.\x0a\x09firstLink := aLink",
  958. messageSends: ["next:"],
  959. referencedClasses: []
  960. }),
  961. smalltalk.HLMethodClassifier);
  962. smalltalk.addMethod(
  963. smalltalk.method({
  964. selector: "buildChainOfResponsibility",
  965. protocol: 'initialization',
  966. fn: function (){
  967. var self=this;
  968. function $HLImplementorClassifierLink(){return smalltalk.HLImplementorClassifierLink||(typeof HLImplementorClassifierLink=="undefined"?nil:HLImplementorClassifierLink)}
  969. function $HLPrefixClassifierLink(){return smalltalk.HLPrefixClassifierLink||(typeof HLPrefixClassifierLink=="undefined"?nil:HLPrefixClassifierLink)}
  970. function $HLSuperclassClassifierLink(){return smalltalk.HLSuperclassClassifierLink||(typeof HLSuperclassClassifierLink=="undefined"?nil:HLSuperclassClassifierLink)}
  971. function $HLAccessorClassifierLink(){return smalltalk.HLAccessorClassifierLink||(typeof HLAccessorClassifierLink=="undefined"?nil:HLAccessorClassifierLink)}
  972. return smalltalk.withContext(function($ctx1) {
  973. var $1,$2,$3;
  974. $1=_st($HLImplementorClassifierLink())._new();
  975. $ctx1.sendIdx["new"]=1;
  976. self._addLink_($1);
  977. $ctx1.sendIdx["addLink:"]=1;
  978. $2=_st($HLPrefixClassifierLink())._new();
  979. $ctx1.sendIdx["new"]=2;
  980. self._addLink_($2);
  981. $ctx1.sendIdx["addLink:"]=2;
  982. $3=_st($HLSuperclassClassifierLink())._new();
  983. $ctx1.sendIdx["new"]=3;
  984. self._addLink_($3);
  985. $ctx1.sendIdx["addLink:"]=3;
  986. self._addLink_(_st($HLAccessorClassifierLink())._new());
  987. return self}, function($ctx1) {$ctx1.fill(self,"buildChainOfResponsibility",{},smalltalk.HLMethodClassifier)})},
  988. args: [],
  989. source: "buildChainOfResponsibility\x0a\x09self addLink: HLImplementorClassifierLink new.\x0a\x09self addLink: HLPrefixClassifierLink new.\x0a\x09self addLink: HLSuperclassClassifierLink new.\x0a\x09self addLink: HLAccessorClassifierLink new",
  990. messageSends: ["addLink:", "new"],
  991. referencedClasses: ["HLImplementorClassifierLink", "HLPrefixClassifierLink", "HLSuperclassClassifierLink", "HLAccessorClassifierLink"]
  992. }),
  993. smalltalk.HLMethodClassifier);
  994. smalltalk.addMethod(
  995. smalltalk.method({
  996. selector: "classify:",
  997. protocol: 'protocol',
  998. fn: function (aMethod){
  999. var self=this;
  1000. return smalltalk.withContext(function($ctx1) {
  1001. var $1,$2;
  1002. $1=self["@firstLink"];
  1003. _st($1)._method_(aMethod);
  1004. $2=_st($1)._classify();
  1005. return self}, function($ctx1) {$ctx1.fill(self,"classify:",{aMethod:aMethod},smalltalk.HLMethodClassifier)})},
  1006. args: ["aMethod"],
  1007. source: "classify: aMethod\x0a\x09firstLink\x0a\x09\x09method: aMethod;\x0a\x09\x09classify",
  1008. messageSends: ["method:", "classify"],
  1009. referencedClasses: []
  1010. }),
  1011. smalltalk.HLMethodClassifier);
  1012. smalltalk.addMethod(
  1013. smalltalk.method({
  1014. selector: "classifyAll:",
  1015. protocol: 'protocol',
  1016. fn: function (aCollectionOfMethods){
  1017. var self=this;
  1018. return smalltalk.withContext(function($ctx1) {
  1019. _st(aCollectionOfMethods)._do_((function(method){
  1020. return smalltalk.withContext(function($ctx2) {
  1021. return self._classify_(method);
  1022. }, function($ctx2) {$ctx2.fillBlock({method:method},$ctx1,1)})}));
  1023. return self}, function($ctx1) {$ctx1.fill(self,"classifyAll:",{aCollectionOfMethods:aCollectionOfMethods},smalltalk.HLMethodClassifier)})},
  1024. args: ["aCollectionOfMethods"],
  1025. source: "classifyAll: aCollectionOfMethods\x0a\x09aCollectionOfMethods do: [ :method |\x0a\x09\x09self classify: method ]",
  1026. messageSends: ["do:", "classify:"],
  1027. referencedClasses: []
  1028. }),
  1029. smalltalk.HLMethodClassifier);
  1030. smalltalk.addMethod(
  1031. smalltalk.method({
  1032. selector: "initialize",
  1033. protocol: 'initialization',
  1034. fn: function (){
  1035. var self=this;
  1036. return smalltalk.withContext(function($ctx1) {
  1037. smalltalk.HLMethodClassifier.superclass.fn.prototype._initialize.apply(_st(self), []);
  1038. self._buildChainOfResponsibility();
  1039. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.HLMethodClassifier)})},
  1040. args: [],
  1041. source: "initialize\x0a\x09super initialize.\x0a\x09\x0a\x09self buildChainOfResponsibility",
  1042. messageSends: ["initialize", "buildChainOfResponsibility"],
  1043. referencedClasses: []
  1044. }),
  1045. smalltalk.HLMethodClassifier);
  1046. smalltalk.addClass('HLMethodSourceCode', smalltalk.Object, ['selector', 'sourceCode'], 'Helios-Helpers');
  1047. smalltalk.HLMethodSourceCode.comment="I am a simple data object keeping track of the information about a method that will be compiled at the end of the generation process";
  1048. smalltalk.addMethod(
  1049. smalltalk.method({
  1050. selector: "selector",
  1051. protocol: 'accessing',
  1052. fn: function (){
  1053. var self=this;
  1054. return smalltalk.withContext(function($ctx1) {
  1055. var $1;
  1056. $1=self["@selector"];
  1057. return $1;
  1058. }, function($ctx1) {$ctx1.fill(self,"selector",{},smalltalk.HLMethodSourceCode)})},
  1059. args: [],
  1060. source: "selector\x0a\x09^ selector",
  1061. messageSends: [],
  1062. referencedClasses: []
  1063. }),
  1064. smalltalk.HLMethodSourceCode);
  1065. smalltalk.addMethod(
  1066. smalltalk.method({
  1067. selector: "selector:",
  1068. protocol: 'accessing',
  1069. fn: function (aSelector){
  1070. var self=this;
  1071. return smalltalk.withContext(function($ctx1) {
  1072. self["@selector"]=aSelector;
  1073. return self}, function($ctx1) {$ctx1.fill(self,"selector:",{aSelector:aSelector},smalltalk.HLMethodSourceCode)})},
  1074. args: ["aSelector"],
  1075. source: "selector: aSelector\x0a\x09selector := aSelector",
  1076. messageSends: [],
  1077. referencedClasses: []
  1078. }),
  1079. smalltalk.HLMethodSourceCode);
  1080. smalltalk.addMethod(
  1081. smalltalk.method({
  1082. selector: "sourceCode",
  1083. protocol: 'accessing',
  1084. fn: function (){
  1085. var self=this;
  1086. return smalltalk.withContext(function($ctx1) {
  1087. var $1;
  1088. $1=self["@sourceCode"];
  1089. return $1;
  1090. }, function($ctx1) {$ctx1.fill(self,"sourceCode",{},smalltalk.HLMethodSourceCode)})},
  1091. args: [],
  1092. source: "sourceCode\x0a\x09^ sourceCode",
  1093. messageSends: [],
  1094. referencedClasses: []
  1095. }),
  1096. smalltalk.HLMethodSourceCode);
  1097. smalltalk.addMethod(
  1098. smalltalk.method({
  1099. selector: "sourceCode:",
  1100. protocol: 'accessing',
  1101. fn: function (aString){
  1102. var self=this;
  1103. return smalltalk.withContext(function($ctx1) {
  1104. self["@sourceCode"]=aString;
  1105. return self}, function($ctx1) {$ctx1.fill(self,"sourceCode:",{aString:aString},smalltalk.HLMethodSourceCode)})},
  1106. args: ["aString"],
  1107. source: "sourceCode: aString\x0a\x09sourceCode := aString",
  1108. messageSends: [],
  1109. referencedClasses: []
  1110. }),
  1111. smalltalk.HLMethodSourceCode);
  1112. });