Helios-Helpers.js 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106
  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('HLMethodClassifier', smalltalk.Object, ['firstLink'], 'Helios-Helpers');
  545. 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?";
  546. smalltalk.addMethod(
  547. smalltalk.method({
  548. selector: "addLink:",
  549. protocol: 'private',
  550. fn: function (aLink){
  551. var self=this;
  552. return smalltalk.withContext(function($ctx1) {
  553. _st(aLink)._next_(self["@firstLink"]);
  554. self["@firstLink"]=aLink;
  555. return self}, function($ctx1) {$ctx1.fill(self,"addLink:",{aLink:aLink},smalltalk.HLMethodClassifier)})},
  556. args: ["aLink"],
  557. source: "addLink: aLink\x0a\x09aLink next: firstLink.\x0a\x09firstLink := aLink",
  558. messageSends: ["next:"],
  559. referencedClasses: []
  560. }),
  561. smalltalk.HLMethodClassifier);
  562. smalltalk.addMethod(
  563. smalltalk.method({
  564. selector: "buildChainOfResponsibility",
  565. protocol: 'initialization',
  566. fn: function (){
  567. var self=this;
  568. function $HLImplementorClassifierLink(){return smalltalk.HLImplementorClassifierLink||(typeof HLImplementorClassifierLink=="undefined"?nil:HLImplementorClassifierLink)}
  569. function $HLPrefixClassifierLink(){return smalltalk.HLPrefixClassifierLink||(typeof HLPrefixClassifierLink=="undefined"?nil:HLPrefixClassifierLink)}
  570. function $HLSuperclassClassifierLink(){return smalltalk.HLSuperclassClassifierLink||(typeof HLSuperclassClassifierLink=="undefined"?nil:HLSuperclassClassifierLink)}
  571. function $HLAccessorClassifierLink(){return smalltalk.HLAccessorClassifierLink||(typeof HLAccessorClassifierLink=="undefined"?nil:HLAccessorClassifierLink)}
  572. return smalltalk.withContext(function($ctx1) {
  573. var $1,$2,$3;
  574. $1=_st($HLImplementorClassifierLink())._new();
  575. $ctx1.sendIdx["new"]=1;
  576. self._addLink_($1);
  577. $ctx1.sendIdx["addLink:"]=1;
  578. $2=_st($HLPrefixClassifierLink())._new();
  579. $ctx1.sendIdx["new"]=2;
  580. self._addLink_($2);
  581. $ctx1.sendIdx["addLink:"]=2;
  582. $3=_st($HLSuperclassClassifierLink())._new();
  583. $ctx1.sendIdx["new"]=3;
  584. self._addLink_($3);
  585. $ctx1.sendIdx["addLink:"]=3;
  586. self._addLink_(_st($HLAccessorClassifierLink())._new());
  587. return self}, function($ctx1) {$ctx1.fill(self,"buildChainOfResponsibility",{},smalltalk.HLMethodClassifier)})},
  588. args: [],
  589. source: "buildChainOfResponsibility\x0a\x09self addLink: HLImplementorClassifierLink new.\x0a\x09self addLink: HLPrefixClassifierLink new.\x0a\x09self addLink: HLSuperclassClassifierLink new.\x0a\x09self addLink: HLAccessorClassifierLink new",
  590. messageSends: ["addLink:", "new"],
  591. referencedClasses: ["HLImplementorClassifierLink", "HLPrefixClassifierLink", "HLSuperclassClassifierLink", "HLAccessorClassifierLink"]
  592. }),
  593. smalltalk.HLMethodClassifier);
  594. smalltalk.addMethod(
  595. smalltalk.method({
  596. selector: "classify:",
  597. protocol: 'protocol',
  598. fn: function (aMethod){
  599. var self=this;
  600. return smalltalk.withContext(function($ctx1) {
  601. var $1,$2;
  602. $1=self["@firstLink"];
  603. _st($1)._method_(aMethod);
  604. $2=_st($1)._classify();
  605. return self}, function($ctx1) {$ctx1.fill(self,"classify:",{aMethod:aMethod},smalltalk.HLMethodClassifier)})},
  606. args: ["aMethod"],
  607. source: "classify: aMethod\x0a\x09firstLink\x0a\x09\x09method: aMethod;\x0a\x09\x09classify",
  608. messageSends: ["method:", "classify"],
  609. referencedClasses: []
  610. }),
  611. smalltalk.HLMethodClassifier);
  612. smalltalk.addMethod(
  613. smalltalk.method({
  614. selector: "classifyAll:",
  615. protocol: 'protocol',
  616. fn: function (aCollectionOfMethods){
  617. var self=this;
  618. return smalltalk.withContext(function($ctx1) {
  619. _st(aCollectionOfMethods)._do_((function(method){
  620. return smalltalk.withContext(function($ctx2) {
  621. return self._classify_(method);
  622. }, function($ctx2) {$ctx2.fillBlock({method:method},$ctx1,1)})}));
  623. return self}, function($ctx1) {$ctx1.fill(self,"classifyAll:",{aCollectionOfMethods:aCollectionOfMethods},smalltalk.HLMethodClassifier)})},
  624. args: ["aCollectionOfMethods"],
  625. source: "classifyAll: aCollectionOfMethods\x0a\x09aCollectionOfMethods do: [ :method |\x0a\x09\x09self classify: method ]",
  626. messageSends: ["do:", "classify:"],
  627. referencedClasses: []
  628. }),
  629. smalltalk.HLMethodClassifier);
  630. smalltalk.addMethod(
  631. smalltalk.method({
  632. selector: "initialize",
  633. protocol: 'initialization',
  634. fn: function (){
  635. var self=this;
  636. return smalltalk.withContext(function($ctx1) {
  637. smalltalk.HLMethodClassifier.superclass.fn.prototype._initialize.apply(_st(self), []);
  638. self._buildChainOfResponsibility();
  639. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.HLMethodClassifier)})},
  640. args: [],
  641. source: "initialize\x0a\x09super initialize.\x0a\x09\x0a\x09self buildChainOfResponsibility",
  642. messageSends: ["initialize", "buildChainOfResponsibility"],
  643. referencedClasses: []
  644. }),
  645. smalltalk.HLMethodClassifier);
  646. smalltalk.addClass('HLMethodGenerator', smalltalk.Object, ['output'], 'Helios-Helpers');
  647. smalltalk.HLMethodGenerator.comment="I am the abstract super class of the method generators.\x0a\x0aMy main method is `generate` which produce an `output` object";
  648. smalltalk.addMethod(
  649. smalltalk.method({
  650. selector: "class:",
  651. protocol: 'accessing',
  652. fn: function (aClass){
  653. var self=this;
  654. return smalltalk.withContext(function($ctx1) {
  655. _st(self["@output"])._targetClass_(aClass);
  656. return self}, function($ctx1) {$ctx1.fill(self,"class:",{aClass:aClass},smalltalk.HLMethodGenerator)})},
  657. args: ["aClass"],
  658. source: "class: aClass\x0a\x09output targetClass: aClass",
  659. messageSends: ["targetClass:"],
  660. referencedClasses: []
  661. }),
  662. smalltalk.HLMethodGenerator);
  663. smalltalk.addMethod(
  664. smalltalk.method({
  665. selector: "generate",
  666. protocol: 'protocol',
  667. fn: function (){
  668. var self=this;
  669. return smalltalk.withContext(function($ctx1) {
  670. var $1;
  671. $1=_st(self["@output"])._targetClass();
  672. if(($receiver = $1) == nil || $receiver == null){
  673. self._error_("class should not be nil");
  674. } else {
  675. $1;
  676. };
  677. return self}, function($ctx1) {$ctx1.fill(self,"generate",{},smalltalk.HLMethodGenerator)})},
  678. args: [],
  679. source: "generate\x0a\x09output targetClass ifNil: [ self error: 'class should not be nil'].",
  680. messageSends: ["ifNil:", "targetClass", "error:"],
  681. referencedClasses: []
  682. }),
  683. smalltalk.HLMethodGenerator);
  684. smalltalk.addMethod(
  685. smalltalk.method({
  686. selector: "initialize",
  687. protocol: 'initialization',
  688. fn: function (){
  689. var self=this;
  690. function $HLGenerationOutput(){return smalltalk.HLGenerationOutput||(typeof HLGenerationOutput=="undefined"?nil:HLGenerationOutput)}
  691. return smalltalk.withContext(function($ctx1) {
  692. smalltalk.HLMethodGenerator.superclass.fn.prototype._initialize.apply(_st(self), []);
  693. self["@output"]=_st($HLGenerationOutput())._new();
  694. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.HLMethodGenerator)})},
  695. args: [],
  696. source: "initialize\x0a\x09super initialize.\x0a\x09\x0a\x09output := HLGenerationOutput new",
  697. messageSends: ["initialize", "new"],
  698. referencedClasses: ["HLGenerationOutput"]
  699. }),
  700. smalltalk.HLMethodGenerator);
  701. smalltalk.addMethod(
  702. smalltalk.method({
  703. selector: "output",
  704. protocol: 'accessing',
  705. fn: function (){
  706. var self=this;
  707. return smalltalk.withContext(function($ctx1) {
  708. var $1;
  709. $1=self["@output"];
  710. return $1;
  711. }, function($ctx1) {$ctx1.fill(self,"output",{},smalltalk.HLMethodGenerator)})},
  712. args: [],
  713. source: "output\x0a\x09^ output",
  714. messageSends: [],
  715. referencedClasses: []
  716. }),
  717. smalltalk.HLMethodGenerator);
  718. smalltalk.addClass('HLAccessorsGenerator', smalltalk.HLMethodGenerator, [], 'Helios-Helpers');
  719. smalltalk.HLAccessorsGenerator.comment="I am a generator used to compile the getters/setters of a class";
  720. smalltalk.addMethod(
  721. smalltalk.method({
  722. selector: "accessorProtocolForObject",
  723. protocol: 'double-dispatch',
  724. fn: function (){
  725. var self=this;
  726. return smalltalk.withContext(function($ctx1) {
  727. _st(self["@output"])._protocol_("accessing");
  728. return self}, function($ctx1) {$ctx1.fill(self,"accessorProtocolForObject",{},smalltalk.HLAccessorsGenerator)})},
  729. args: [],
  730. source: "accessorProtocolForObject\x0a\x09output protocol: 'accessing'",
  731. messageSends: ["protocol:"],
  732. referencedClasses: []
  733. }),
  734. smalltalk.HLAccessorsGenerator);
  735. smalltalk.addMethod(
  736. smalltalk.method({
  737. selector: "accessorsForObject",
  738. protocol: 'double-dispatch',
  739. fn: function (){
  740. var self=this;
  741. var sources;
  742. function $OrderedCollection(){return smalltalk.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
  743. return smalltalk.withContext(function($ctx1) {
  744. var $1,$2;
  745. sources=_st($OrderedCollection())._new();
  746. _st(_st(_st(_st(self["@output"])._targetClass())._instanceVariableNames())._sorted())._do_((function(each){
  747. return smalltalk.withContext(function($ctx2) {
  748. $1=sources;
  749. _st($1)._add_(self._getterFor_(each));
  750. $ctx2.sendIdx["add:"]=1;
  751. $2=_st($1)._add_(self._setterFor_(each));
  752. return $2;
  753. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  754. _st(self["@output"])._sourceCodes_(sources);
  755. return self}, function($ctx1) {$ctx1.fill(self,"accessorsForObject",{sources:sources},smalltalk.HLAccessorsGenerator)})},
  756. args: [],
  757. source: "accessorsForObject\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",
  758. messageSends: ["new", "do:", "sorted", "instanceVariableNames", "targetClass", "add:", "getterFor:", "setterFor:", "sourceCodes:"],
  759. referencedClasses: ["OrderedCollection"]
  760. }),
  761. smalltalk.HLAccessorsGenerator);
  762. smalltalk.addMethod(
  763. smalltalk.method({
  764. selector: "generate",
  765. protocol: 'protocol',
  766. fn: function (){
  767. var self=this;
  768. return smalltalk.withContext(function($ctx1) {
  769. var $1,$2;
  770. smalltalk.HLAccessorsGenerator.superclass.fn.prototype._generate.apply(_st(self), []);
  771. $1=_st(self["@output"])._targetClass();
  772. _st($1)._accessorsSourceCodesWith_(self);
  773. $2=_st($1)._accessorProtocolWith_(self);
  774. return self}, function($ctx1) {$ctx1.fill(self,"generate",{},smalltalk.HLAccessorsGenerator)})},
  775. args: [],
  776. source: "generate\x0a\x09super generate.\x0a\x09\x0a\x09output targetClass \x0a\x09\x09accessorsSourceCodesWith: self;\x0a\x09\x09accessorProtocolWith: self",
  777. messageSends: ["generate", "accessorsSourceCodesWith:", "targetClass", "accessorProtocolWith:"],
  778. referencedClasses: []
  779. }),
  780. smalltalk.HLAccessorsGenerator);
  781. smalltalk.addMethod(
  782. smalltalk.method({
  783. selector: "getterFor:",
  784. protocol: 'private',
  785. fn: function (anInstanceVariable){
  786. var self=this;
  787. function $HLMethodSourceCode(){return smalltalk.HLMethodSourceCode||(typeof HLMethodSourceCode=="undefined"?nil:HLMethodSourceCode)}
  788. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  789. return smalltalk.withContext(function($ctx1) {
  790. var $2,$3,$1;
  791. $2=_st($HLMethodSourceCode())._new();
  792. _st($2)._selector_(anInstanceVariable);
  793. $3=_st($2)._sourceCode_(_st($String())._streamContents_((function(stream){
  794. return smalltalk.withContext(function($ctx2) {
  795. _st(stream).__lt_lt(anInstanceVariable);
  796. $ctx2.sendIdx["<<"]=1;
  797. _st(_st(stream)._cr())._tab();
  798. return _st(_st(stream).__lt_lt("^ ")).__lt_lt(anInstanceVariable);
  799. $ctx2.sendIdx["<<"]=2;
  800. }, function($ctx2) {$ctx2.fillBlock({stream:stream},$ctx1,1)})})));
  801. $1=$3;
  802. return $1;
  803. }, function($ctx1) {$ctx1.fill(self,"getterFor:",{anInstanceVariable:anInstanceVariable},smalltalk.HLAccessorsGenerator)})},
  804. args: ["anInstanceVariable"],
  805. 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 ])",
  806. messageSends: ["selector:", "new", "sourceCode:", "streamContents:", "<<", "tab", "cr"],
  807. referencedClasses: ["HLMethodSourceCode", "String"]
  808. }),
  809. smalltalk.HLAccessorsGenerator);
  810. smalltalk.addMethod(
  811. smalltalk.method({
  812. selector: "setterFor:",
  813. protocol: 'private',
  814. fn: function (anInstanceVariable){
  815. var self=this;
  816. function $HLMethodSourceCode(){return smalltalk.HLMethodSourceCode||(typeof HLMethodSourceCode=="undefined"?nil:HLMethodSourceCode)}
  817. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  818. return smalltalk.withContext(function($ctx1) {
  819. var $2,$4,$3,$1;
  820. $2=_st($HLMethodSourceCode())._new();
  821. _st($2)._selector_(_st(anInstanceVariable).__comma(":"));
  822. $3=_st($2)._sourceCode_(_st($String())._streamContents_((function(stream){
  823. return smalltalk.withContext(function($ctx2) {
  824. $4=_st(stream).__lt_lt(anInstanceVariable);
  825. $ctx2.sendIdx["<<"]=2;
  826. _st($4).__lt_lt(": anObject");
  827. $ctx2.sendIdx["<<"]=1;
  828. _st(_st(stream)._cr())._tab();
  829. return _st(_st(stream).__lt_lt(anInstanceVariable)).__lt_lt(" := anObject");
  830. $ctx2.sendIdx["<<"]=3;
  831. }, function($ctx2) {$ctx2.fillBlock({stream:stream},$ctx1,1)})})));
  832. $1=$3;
  833. return $1;
  834. }, function($ctx1) {$ctx1.fill(self,"setterFor:",{anInstanceVariable:anInstanceVariable},smalltalk.HLAccessorsGenerator)})},
  835. args: ["anInstanceVariable"],
  836. 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' ])",
  837. messageSends: ["selector:", "new", ",", "sourceCode:", "streamContents:", "<<", "tab", "cr"],
  838. referencedClasses: ["HLMethodSourceCode", "String"]
  839. }),
  840. smalltalk.HLAccessorsGenerator);
  841. smalltalk.addClass('HLInitializeGenerator', smalltalk.HLMethodGenerator, [], 'Helios-Helpers');
  842. 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";
  843. smalltalk.addMethod(
  844. smalltalk.method({
  845. selector: "generate",
  846. protocol: 'protocol',
  847. fn: function (){
  848. var self=this;
  849. return smalltalk.withContext(function($ctx1) {
  850. var $1,$2;
  851. smalltalk.HLInitializeGenerator.superclass.fn.prototype._generate.apply(_st(self), []);
  852. $1=_st(self["@output"])._targetClass();
  853. _st($1)._initializeSourceCodesWith_(self);
  854. $2=_st($1)._initializeProtocolWith_(self);
  855. return self}, function($ctx1) {$ctx1.fill(self,"generate",{},smalltalk.HLInitializeGenerator)})},
  856. args: [],
  857. source: "generate\x0a\x09super generate.\x0a\x09\x0a\x09output targetClass \x0a\x09\x09initializeSourceCodesWith: self;\x0a\x09\x09initializeProtocolWith: self",
  858. messageSends: ["generate", "initializeSourceCodesWith:", "targetClass", "initializeProtocolWith:"],
  859. referencedClasses: []
  860. }),
  861. smalltalk.HLInitializeGenerator);
  862. smalltalk.addMethod(
  863. smalltalk.method({
  864. selector: "generateInitializeCodeForObject",
  865. protocol: 'private',
  866. fn: function (){
  867. var self=this;
  868. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  869. return smalltalk.withContext(function($ctx1) {
  870. var $3,$2,$4,$5,$6,$7,$8,$1;
  871. $1=_st($String())._streamContents_((function(str){
  872. var instVars,size;
  873. return smalltalk.withContext(function($ctx2) {
  874. instVars=_st(_st(_st(self["@output"])._targetClass())._instanceVariableNames())._sorted();
  875. instVars;
  876. size=_st(instVars)._size();
  877. size;
  878. _st(str).__lt_lt("initialize");
  879. $ctx2.sendIdx["<<"]=1;
  880. $3=_st(str)._cr();
  881. $ctx2.sendIdx["cr"]=1;
  882. $2=_st($3)._tab();
  883. $ctx2.sendIdx["tab"]=1;
  884. _st($2).__lt_lt("super initialize.");
  885. $ctx2.sendIdx["<<"]=2;
  886. $4=_st($2)._cr();
  887. $ctx2.sendIdx["cr"]=2;
  888. $4;
  889. $5=_st(str)._cr();
  890. $ctx2.sendIdx["cr"]=3;
  891. _st($5)._tab();
  892. $ctx2.sendIdx["tab"]=2;
  893. return _st(instVars)._withIndexDo_((function(name,index){
  894. return smalltalk.withContext(function($ctx3) {
  895. $6=_st(index).__tild_eq((1));
  896. $ctx3.sendIdx["~="]=1;
  897. if(smalltalk.assert($6)){
  898. _st(_st(str)._cr())._tab();
  899. };
  900. $7=_st(str).__lt_lt(name);
  901. $ctx3.sendIdx["<<"]=4;
  902. _st($7).__lt_lt(" := nil");
  903. $ctx3.sendIdx["<<"]=3;
  904. $8=_st(index).__tild_eq(size);
  905. if(smalltalk.assert($8)){
  906. return _st(str).__lt_lt(".");
  907. };
  908. }, function($ctx3) {$ctx3.fillBlock({name:name,index:index},$ctx2,2)})}));
  909. }, function($ctx2) {$ctx2.fillBlock({str:str,instVars:instVars,size:size},$ctx1,1)})}));
  910. return $1;
  911. }, function($ctx1) {$ctx1.fill(self,"generateInitializeCodeForObject",{},smalltalk.HLInitializeGenerator)})},
  912. args: [],
  913. 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 << '.' ] ] ].",
  914. messageSends: ["streamContents:", "sorted", "instanceVariableNames", "targetClass", "size", "<<", "tab", "cr", "withIndexDo:", "ifTrue:", "~="],
  915. referencedClasses: ["String"]
  916. }),
  917. smalltalk.HLInitializeGenerator);
  918. smalltalk.addMethod(
  919. smalltalk.method({
  920. selector: "initializeForObject",
  921. protocol: 'double-dispatch',
  922. fn: function (){
  923. var self=this;
  924. return smalltalk.withContext(function($ctx1) {
  925. _st(self["@output"])._addSourceCode_(self._initializeMethodForObject());
  926. return self}, function($ctx1) {$ctx1.fill(self,"initializeForObject",{},smalltalk.HLInitializeGenerator)})},
  927. args: [],
  928. source: "initializeForObject\x0a\x09output addSourceCode: self initializeMethodForObject",
  929. messageSends: ["addSourceCode:", "initializeMethodForObject"],
  930. referencedClasses: []
  931. }),
  932. smalltalk.HLInitializeGenerator);
  933. smalltalk.addMethod(
  934. smalltalk.method({
  935. selector: "initializeMethodForObject",
  936. protocol: 'private',
  937. fn: function (){
  938. var self=this;
  939. function $HLMethodSourceCode(){return smalltalk.HLMethodSourceCode||(typeof HLMethodSourceCode=="undefined"?nil:HLMethodSourceCode)}
  940. return smalltalk.withContext(function($ctx1) {
  941. var $2,$3,$1;
  942. $2=_st($HLMethodSourceCode())._new();
  943. _st($2)._selector_("initialize");
  944. _st($2)._sourceCode_(self._generateInitializeCodeForObject());
  945. $3=_st($2)._yourself();
  946. $1=$3;
  947. return $1;
  948. }, function($ctx1) {$ctx1.fill(self,"initializeMethodForObject",{},smalltalk.HLInitializeGenerator)})},
  949. args: [],
  950. source: "initializeMethodForObject\x09\x0a\x09^ HLMethodSourceCode new\x0a\x09\x09selector: 'initialize';\x0a\x09\x09sourceCode: self generateInitializeCodeForObject;\x0a\x09\x09yourself",
  951. messageSends: ["selector:", "new", "sourceCode:", "generateInitializeCodeForObject", "yourself"],
  952. referencedClasses: ["HLMethodSourceCode"]
  953. }),
  954. smalltalk.HLInitializeGenerator);
  955. smalltalk.addMethod(
  956. smalltalk.method({
  957. selector: "initializeProtocolForObject",
  958. protocol: 'double-dispatch',
  959. fn: function (){
  960. var self=this;
  961. return smalltalk.withContext(function($ctx1) {
  962. _st(self["@output"])._protocol_("initialization");
  963. return self}, function($ctx1) {$ctx1.fill(self,"initializeProtocolForObject",{},smalltalk.HLInitializeGenerator)})},
  964. args: [],
  965. source: "initializeProtocolForObject\x0a\x09output protocol: 'initialization'",
  966. messageSends: ["protocol:"],
  967. referencedClasses: []
  968. }),
  969. smalltalk.HLInitializeGenerator);
  970. smalltalk.addClass('HLMethodSourceCode', smalltalk.Object, ['selector', 'sourceCode'], 'Helios-Helpers');
  971. 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";
  972. smalltalk.addMethod(
  973. smalltalk.method({
  974. selector: "selector",
  975. protocol: 'accessing',
  976. fn: function (){
  977. var self=this;
  978. return smalltalk.withContext(function($ctx1) {
  979. var $1;
  980. $1=self["@selector"];
  981. return $1;
  982. }, function($ctx1) {$ctx1.fill(self,"selector",{},smalltalk.HLMethodSourceCode)})},
  983. args: [],
  984. source: "selector\x0a\x09^ selector",
  985. messageSends: [],
  986. referencedClasses: []
  987. }),
  988. smalltalk.HLMethodSourceCode);
  989. smalltalk.addMethod(
  990. smalltalk.method({
  991. selector: "selector:",
  992. protocol: 'accessing',
  993. fn: function (aSelector){
  994. var self=this;
  995. return smalltalk.withContext(function($ctx1) {
  996. self["@selector"]=aSelector;
  997. return self}, function($ctx1) {$ctx1.fill(self,"selector:",{aSelector:aSelector},smalltalk.HLMethodSourceCode)})},
  998. args: ["aSelector"],
  999. source: "selector: aSelector\x0a\x09selector := aSelector",
  1000. messageSends: [],
  1001. referencedClasses: []
  1002. }),
  1003. smalltalk.HLMethodSourceCode);
  1004. smalltalk.addMethod(
  1005. smalltalk.method({
  1006. selector: "sourceCode",
  1007. protocol: 'accessing',
  1008. fn: function (){
  1009. var self=this;
  1010. return smalltalk.withContext(function($ctx1) {
  1011. var $1;
  1012. $1=self["@sourceCode"];
  1013. return $1;
  1014. }, function($ctx1) {$ctx1.fill(self,"sourceCode",{},smalltalk.HLMethodSourceCode)})},
  1015. args: [],
  1016. source: "sourceCode\x0a\x09^ sourceCode",
  1017. messageSends: [],
  1018. referencedClasses: []
  1019. }),
  1020. smalltalk.HLMethodSourceCode);
  1021. smalltalk.addMethod(
  1022. smalltalk.method({
  1023. selector: "sourceCode:",
  1024. protocol: 'accessing',
  1025. fn: function (aString){
  1026. var self=this;
  1027. return smalltalk.withContext(function($ctx1) {
  1028. self["@sourceCode"]=aString;
  1029. return self}, function($ctx1) {$ctx1.fill(self,"sourceCode:",{aString:aString},smalltalk.HLMethodSourceCode)})},
  1030. args: ["aString"],
  1031. source: "sourceCode: aString\x0a\x09sourceCode := aString",
  1032. messageSends: [],
  1033. referencedClasses: []
  1034. }),
  1035. smalltalk.HLMethodSourceCode);
  1036. });