Helios-Helpers.js 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068
  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('HLClassifier', smalltalk.Object, ['next', 'method'], 'Helios-Helpers');
  5. smalltalk.HLClassifier.comment="I am an abstract class implementing a link in a `chain of responsibility` pattern.\x0a\x0aSubclasses 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())._classify();
  26. };
  27. return $2;
  28. }, function($ctx1) {$ctx1.fill(self,"classify",{},smalltalk.HLClassifier)})},
  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 classify ]",
  31. messageSends: ["ifNil:", "next", "ifTrue:ifFalse:", "doClassify", "classify"],
  32. referencedClasses: []
  33. }),
  34. smalltalk.HLClassifier);
  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.HLClassifier)})},
  44. args: [],
  45. source: "doClassify\x0a\x09self subclassResponsibility",
  46. messageSends: ["subclassResponsibility"],
  47. referencedClasses: []
  48. }),
  49. smalltalk.HLClassifier);
  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.HLClassifier)})},
  61. args: [],
  62. source: "method\x0a\x09^ method",
  63. messageSends: [],
  64. referencedClasses: []
  65. }),
  66. smalltalk.HLClassifier);
  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.HLClassifier)})},
  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.HLClassifier);
  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.HLClassifier)})},
  102. args: [],
  103. source: "next\x0a\x09^ next",
  104. messageSends: [],
  105. referencedClasses: []
  106. }),
  107. smalltalk.HLClassifier);
  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.HLClassifier)})},
  117. args: ["anObject"],
  118. source: "next: anObject\x0a\x09next := anObject",
  119. messageSends: [],
  120. referencedClasses: []
  121. }),
  122. smalltalk.HLClassifier);
  123. smalltalk.addClass('HLAccessorClassifier', smalltalk.HLClassifier, [], 'Helios-Helpers');
  124. smalltalk.HLAccessorClassifier.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.HLAccessorClassifier)})},
  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.HLAccessorClassifier);
  154. smalltalk.addClass('HLImplementorClassifier', smalltalk.HLClassifier, [], 'Helios-Helpers');
  155. smalltalk.HLImplementorClassifier.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.HLImplementorClassifier)})},
  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.HLImplementorClassifier);
  196. smalltalk.addClass('HLPrefixClassifier', smalltalk.HLClassifier, ['prefixMapping'], 'Helios-Helpers');
  197. smalltalk.HLPrefixClassifier.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.HLPrefixClassifier)})},
  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.HLPrefixClassifier);
  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.HLPrefixClassifier)})},
  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.HLPrefixClassifier);
  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.HLPrefixClassifier.superclass.fn.prototype._initialize.apply(_st(self), []);
  275. self._buildPrefixDictionary();
  276. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.HLPrefixClassifier)})},
  277. args: [],
  278. source: "initialize\x0a\x09super initialize.\x0a\x0a\x09self buildPrefixDictionary",
  279. messageSends: ["initialize", "buildPrefixDictionary"],
  280. referencedClasses: []
  281. }),
  282. smalltalk.HLPrefixClassifier);
  283. smalltalk.addClass('HLSuperclassClassifier', smalltalk.HLClassifier, [], 'Helios-Helpers');
  284. smalltalk.HLSuperclassClassifier.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.HLSuperclassClassifier)})},
  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.HLSuperclassClassifier);
  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('HLMethodClassifier', smalltalk.Object, ['firstClassifier'], 'Helios-Helpers');
  511. 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?";
  512. smalltalk.addMethod(
  513. smalltalk.method({
  514. selector: "addClassifier:",
  515. protocol: 'private',
  516. fn: function (aClassifier){
  517. var self=this;
  518. return smalltalk.withContext(function($ctx1) {
  519. _st(aClassifier)._next_(self["@firstClassifier"]);
  520. self["@firstClassifier"]=aClassifier;
  521. return self}, function($ctx1) {$ctx1.fill(self,"addClassifier:",{aClassifier:aClassifier},smalltalk.HLMethodClassifier)})},
  522. args: ["aClassifier"],
  523. source: "addClassifier: aClassifier\x0a\x09aClassifier next: firstClassifier.\x0a\x09firstClassifier := aClassifier",
  524. messageSends: ["next:"],
  525. referencedClasses: []
  526. }),
  527. smalltalk.HLMethodClassifier);
  528. smalltalk.addMethod(
  529. smalltalk.method({
  530. selector: "classify:",
  531. protocol: 'protocol',
  532. fn: function (aMethod){
  533. var self=this;
  534. return smalltalk.withContext(function($ctx1) {
  535. var $1,$2;
  536. $1=self["@firstClassifier"];
  537. _st($1)._method_(aMethod);
  538. $2=_st($1)._classify();
  539. return self}, function($ctx1) {$ctx1.fill(self,"classify:",{aMethod:aMethod},smalltalk.HLMethodClassifier)})},
  540. args: ["aMethod"],
  541. source: "classify: aMethod\x0a\x09firstClassifier\x0a\x09\x09method: aMethod;\x0a\x09\x09classify",
  542. messageSends: ["method:", "classify"],
  543. referencedClasses: []
  544. }),
  545. smalltalk.HLMethodClassifier);
  546. smalltalk.addMethod(
  547. smalltalk.method({
  548. selector: "classifyAll:",
  549. protocol: 'protocol',
  550. fn: function (aCollectionOfMethods){
  551. var self=this;
  552. return smalltalk.withContext(function($ctx1) {
  553. _st(aCollectionOfMethods)._do_((function(method){
  554. return smalltalk.withContext(function($ctx2) {
  555. return self._classify_(method);
  556. }, function($ctx2) {$ctx2.fillBlock({method:method},$ctx1,1)})}));
  557. return self}, function($ctx1) {$ctx1.fill(self,"classifyAll:",{aCollectionOfMethods:aCollectionOfMethods},smalltalk.HLMethodClassifier)})},
  558. args: ["aCollectionOfMethods"],
  559. source: "classifyAll: aCollectionOfMethods\x0a\x09aCollectionOfMethods do: [ :method |\x0a\x09\x09self classify: method ]",
  560. messageSends: ["do:", "classify:"],
  561. referencedClasses: []
  562. }),
  563. smalltalk.HLMethodClassifier);
  564. smalltalk.addMethod(
  565. smalltalk.method({
  566. selector: "initialize",
  567. protocol: 'initialization',
  568. fn: function (){
  569. var self=this;
  570. return smalltalk.withContext(function($ctx1) {
  571. smalltalk.HLMethodClassifier.superclass.fn.prototype._initialize.apply(_st(self), []);
  572. self._setupClassifiers();
  573. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.HLMethodClassifier)})},
  574. args: [],
  575. source: "initialize\x0a\x09super initialize.\x0a\x09\x0a\x09self setupClassifiers",
  576. messageSends: ["initialize", "setupClassifiers"],
  577. referencedClasses: []
  578. }),
  579. smalltalk.HLMethodClassifier);
  580. smalltalk.addMethod(
  581. smalltalk.method({
  582. selector: "setupClassifiers",
  583. protocol: 'initialization',
  584. fn: function (){
  585. var self=this;
  586. function $HLImplementorClassifier(){return smalltalk.HLImplementorClassifier||(typeof HLImplementorClassifier=="undefined"?nil:HLImplementorClassifier)}
  587. function $HLPrefixClassifier(){return smalltalk.HLPrefixClassifier||(typeof HLPrefixClassifier=="undefined"?nil:HLPrefixClassifier)}
  588. function $HLSuperclassClassifier(){return smalltalk.HLSuperclassClassifier||(typeof HLSuperclassClassifier=="undefined"?nil:HLSuperclassClassifier)}
  589. function $HLAccessorClassifier(){return smalltalk.HLAccessorClassifier||(typeof HLAccessorClassifier=="undefined"?nil:HLAccessorClassifier)}
  590. return smalltalk.withContext(function($ctx1) {
  591. var $1,$2,$3;
  592. $1=_st($HLImplementorClassifier())._new();
  593. $ctx1.sendIdx["new"]=1;
  594. self._addClassifier_($1);
  595. $ctx1.sendIdx["addClassifier:"]=1;
  596. $2=_st($HLPrefixClassifier())._new();
  597. $ctx1.sendIdx["new"]=2;
  598. self._addClassifier_($2);
  599. $ctx1.sendIdx["addClassifier:"]=2;
  600. $3=_st($HLSuperclassClassifier())._new();
  601. $ctx1.sendIdx["new"]=3;
  602. self._addClassifier_($3);
  603. $ctx1.sendIdx["addClassifier:"]=3;
  604. self._addClassifier_(_st($HLAccessorClassifier())._new());
  605. return self}, function($ctx1) {$ctx1.fill(self,"setupClassifiers",{},smalltalk.HLMethodClassifier)})},
  606. args: [],
  607. source: "setupClassifiers\x0a\x09self addClassifier: HLImplementorClassifier new.\x0a\x09self addClassifier: HLPrefixClassifier new.\x0a\x09self addClassifier: HLSuperclassClassifier new.\x0a\x09self addClassifier: HLAccessorClassifier new",
  608. messageSends: ["addClassifier:", "new"],
  609. referencedClasses: ["HLImplementorClassifier", "HLPrefixClassifier", "HLSuperclassClassifier", "HLAccessorClassifier"]
  610. }),
  611. smalltalk.HLMethodClassifier);
  612. smalltalk.addClass('HLMethodGenerator', smalltalk.Object, ['output'], 'Helios-Helpers');
  613. smalltalk.HLMethodGenerator.comment="I am the abstract super class of the method generators.\x0a\x0aMy main method is `generate` which produce an `output` object";
  614. smalltalk.addMethod(
  615. smalltalk.method({
  616. selector: "class:",
  617. protocol: 'accessing',
  618. fn: function (aClass){
  619. var self=this;
  620. return smalltalk.withContext(function($ctx1) {
  621. _st(self["@output"])._targetClass_(aClass);
  622. return self}, function($ctx1) {$ctx1.fill(self,"class:",{aClass:aClass},smalltalk.HLMethodGenerator)})},
  623. args: ["aClass"],
  624. source: "class: aClass\x0a\x09output targetClass: aClass",
  625. messageSends: ["targetClass:"],
  626. referencedClasses: []
  627. }),
  628. smalltalk.HLMethodGenerator);
  629. smalltalk.addMethod(
  630. smalltalk.method({
  631. selector: "generate",
  632. protocol: 'protocol',
  633. fn: function (){
  634. var self=this;
  635. return smalltalk.withContext(function($ctx1) {
  636. var $1;
  637. $1=_st(self["@output"])._targetClass();
  638. if(($receiver = $1) == nil || $receiver == null){
  639. self._error_("class should not be nil");
  640. } else {
  641. $1;
  642. };
  643. return self}, function($ctx1) {$ctx1.fill(self,"generate",{},smalltalk.HLMethodGenerator)})},
  644. args: [],
  645. source: "generate\x0a\x09output targetClass ifNil: [ self error: 'class should not be nil'].",
  646. messageSends: ["ifNil:", "targetClass", "error:"],
  647. referencedClasses: []
  648. }),
  649. smalltalk.HLMethodGenerator);
  650. smalltalk.addMethod(
  651. smalltalk.method({
  652. selector: "initialize",
  653. protocol: 'initialization',
  654. fn: function (){
  655. var self=this;
  656. function $HLGenerationOutput(){return smalltalk.HLGenerationOutput||(typeof HLGenerationOutput=="undefined"?nil:HLGenerationOutput)}
  657. return smalltalk.withContext(function($ctx1) {
  658. smalltalk.HLMethodGenerator.superclass.fn.prototype._initialize.apply(_st(self), []);
  659. self["@output"]=_st($HLGenerationOutput())._new();
  660. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.HLMethodGenerator)})},
  661. args: [],
  662. source: "initialize\x0a\x09super initialize.\x0a\x09\x0a\x09output := HLGenerationOutput new",
  663. messageSends: ["initialize", "new"],
  664. referencedClasses: ["HLGenerationOutput"]
  665. }),
  666. smalltalk.HLMethodGenerator);
  667. smalltalk.addMethod(
  668. smalltalk.method({
  669. selector: "output",
  670. protocol: 'accessing',
  671. fn: function (){
  672. var self=this;
  673. return smalltalk.withContext(function($ctx1) {
  674. var $1;
  675. $1=self["@output"];
  676. return $1;
  677. }, function($ctx1) {$ctx1.fill(self,"output",{},smalltalk.HLMethodGenerator)})},
  678. args: [],
  679. source: "output\x0a\x09^ output",
  680. messageSends: [],
  681. referencedClasses: []
  682. }),
  683. smalltalk.HLMethodGenerator);
  684. smalltalk.addClass('HLAccessorsGenerator', smalltalk.HLMethodGenerator, [], 'Helios-Helpers');
  685. smalltalk.HLAccessorsGenerator.comment="I am a generator used to compile the getters/setters of a class";
  686. smalltalk.addMethod(
  687. smalltalk.method({
  688. selector: "accessorProtocolForObject",
  689. protocol: 'double-dispatch',
  690. fn: function (){
  691. var self=this;
  692. return smalltalk.withContext(function($ctx1) {
  693. _st(self["@output"])._protocol_("accessing");
  694. return self}, function($ctx1) {$ctx1.fill(self,"accessorProtocolForObject",{},smalltalk.HLAccessorsGenerator)})},
  695. args: [],
  696. source: "accessorProtocolForObject\x0a\x09output protocol: 'accessing'",
  697. messageSends: ["protocol:"],
  698. referencedClasses: []
  699. }),
  700. smalltalk.HLAccessorsGenerator);
  701. smalltalk.addMethod(
  702. smalltalk.method({
  703. selector: "accessorsForObject",
  704. protocol: 'double-dispatch',
  705. fn: function (){
  706. var self=this;
  707. var sources;
  708. function $OrderedCollection(){return smalltalk.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
  709. return smalltalk.withContext(function($ctx1) {
  710. var $1,$2;
  711. sources=_st($OrderedCollection())._new();
  712. _st(_st(_st(_st(self["@output"])._targetClass())._instanceVariableNames())._sorted())._do_((function(each){
  713. return smalltalk.withContext(function($ctx2) {
  714. $1=sources;
  715. _st($1)._add_(self._getterFor_(each));
  716. $ctx2.sendIdx["add:"]=1;
  717. $2=_st($1)._add_(self._setterFor_(each));
  718. return $2;
  719. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  720. _st(self["@output"])._sourceCodes_(sources);
  721. return self}, function($ctx1) {$ctx1.fill(self,"accessorsForObject",{sources:sources},smalltalk.HLAccessorsGenerator)})},
  722. args: [],
  723. 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",
  724. messageSends: ["new", "do:", "sorted", "instanceVariableNames", "targetClass", "add:", "getterFor:", "setterFor:", "sourceCodes:"],
  725. referencedClasses: ["OrderedCollection"]
  726. }),
  727. smalltalk.HLAccessorsGenerator);
  728. smalltalk.addMethod(
  729. smalltalk.method({
  730. selector: "generate",
  731. protocol: 'protocol',
  732. fn: function (){
  733. var self=this;
  734. return smalltalk.withContext(function($ctx1) {
  735. var $1,$2;
  736. smalltalk.HLAccessorsGenerator.superclass.fn.prototype._generate.apply(_st(self), []);
  737. $1=_st(self["@output"])._targetClass();
  738. _st($1)._accessorsSourceCodesWith_(self);
  739. $2=_st($1)._accessorProtocolWith_(self);
  740. return self}, function($ctx1) {$ctx1.fill(self,"generate",{},smalltalk.HLAccessorsGenerator)})},
  741. args: [],
  742. source: "generate\x0a\x09super generate.\x0a\x09\x0a\x09output targetClass \x0a\x09\x09accessorsSourceCodesWith: self;\x0a\x09\x09accessorProtocolWith: self",
  743. messageSends: ["generate", "accessorsSourceCodesWith:", "targetClass", "accessorProtocolWith:"],
  744. referencedClasses: []
  745. }),
  746. smalltalk.HLAccessorsGenerator);
  747. smalltalk.addMethod(
  748. smalltalk.method({
  749. selector: "getterFor:",
  750. protocol: 'private',
  751. fn: function (anInstanceVariable){
  752. var self=this;
  753. function $HLMethodSourceCode(){return smalltalk.HLMethodSourceCode||(typeof HLMethodSourceCode=="undefined"?nil:HLMethodSourceCode)}
  754. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  755. return smalltalk.withContext(function($ctx1) {
  756. var $2,$3,$1;
  757. $2=_st($HLMethodSourceCode())._new();
  758. _st($2)._selector_(anInstanceVariable);
  759. $3=_st($2)._sourceCode_(_st($String())._streamContents_((function(stream){
  760. return smalltalk.withContext(function($ctx2) {
  761. _st(stream).__lt_lt(anInstanceVariable);
  762. $ctx2.sendIdx["<<"]=1;
  763. _st(_st(stream)._cr())._tab();
  764. return _st(_st(stream).__lt_lt("^ ")).__lt_lt(anInstanceVariable);
  765. $ctx2.sendIdx["<<"]=2;
  766. }, function($ctx2) {$ctx2.fillBlock({stream:stream},$ctx1,1)})})));
  767. $1=$3;
  768. return $1;
  769. }, function($ctx1) {$ctx1.fill(self,"getterFor:",{anInstanceVariable:anInstanceVariable},smalltalk.HLAccessorsGenerator)})},
  770. args: ["anInstanceVariable"],
  771. 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 ])",
  772. messageSends: ["selector:", "new", "sourceCode:", "streamContents:", "<<", "tab", "cr"],
  773. referencedClasses: ["HLMethodSourceCode", "String"]
  774. }),
  775. smalltalk.HLAccessorsGenerator);
  776. smalltalk.addMethod(
  777. smalltalk.method({
  778. selector: "setterFor:",
  779. protocol: 'private',
  780. fn: function (anInstanceVariable){
  781. var self=this;
  782. function $HLMethodSourceCode(){return smalltalk.HLMethodSourceCode||(typeof HLMethodSourceCode=="undefined"?nil:HLMethodSourceCode)}
  783. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  784. return smalltalk.withContext(function($ctx1) {
  785. var $2,$4,$3,$1;
  786. $2=_st($HLMethodSourceCode())._new();
  787. _st($2)._selector_(_st(anInstanceVariable).__comma(":"));
  788. $3=_st($2)._sourceCode_(_st($String())._streamContents_((function(stream){
  789. return smalltalk.withContext(function($ctx2) {
  790. $4=_st(stream).__lt_lt(anInstanceVariable);
  791. $ctx2.sendIdx["<<"]=2;
  792. _st($4).__lt_lt(": anObject");
  793. $ctx2.sendIdx["<<"]=1;
  794. _st(_st(stream)._cr())._tab();
  795. return _st(_st(stream).__lt_lt(anInstanceVariable)).__lt_lt(" := anObject");
  796. $ctx2.sendIdx["<<"]=3;
  797. }, function($ctx2) {$ctx2.fillBlock({stream:stream},$ctx1,1)})})));
  798. $1=$3;
  799. return $1;
  800. }, function($ctx1) {$ctx1.fill(self,"setterFor:",{anInstanceVariable:anInstanceVariable},smalltalk.HLAccessorsGenerator)})},
  801. args: ["anInstanceVariable"],
  802. 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' ])",
  803. messageSends: ["selector:", "new", ",", "sourceCode:", "streamContents:", "<<", "tab", "cr"],
  804. referencedClasses: ["HLMethodSourceCode", "String"]
  805. }),
  806. smalltalk.HLAccessorsGenerator);
  807. smalltalk.addClass('HLInitializeGenerator', smalltalk.HLMethodGenerator, [], 'Helios-Helpers');
  808. 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";
  809. smalltalk.addMethod(
  810. smalltalk.method({
  811. selector: "generate",
  812. protocol: 'protocol',
  813. fn: function (){
  814. var self=this;
  815. return smalltalk.withContext(function($ctx1) {
  816. var $1,$2;
  817. smalltalk.HLInitializeGenerator.superclass.fn.prototype._generate.apply(_st(self), []);
  818. $1=_st(self["@output"])._targetClass();
  819. _st($1)._initializeSourceCodesWith_(self);
  820. $2=_st($1)._initializeProtocolWith_(self);
  821. return self}, function($ctx1) {$ctx1.fill(self,"generate",{},smalltalk.HLInitializeGenerator)})},
  822. args: [],
  823. source: "generate\x0a\x09super generate.\x0a\x09\x0a\x09output targetClass \x0a\x09\x09initializeSourceCodesWith: self;\x0a\x09\x09initializeProtocolWith: self",
  824. messageSends: ["generate", "initializeSourceCodesWith:", "targetClass", "initializeProtocolWith:"],
  825. referencedClasses: []
  826. }),
  827. smalltalk.HLInitializeGenerator);
  828. smalltalk.addMethod(
  829. smalltalk.method({
  830. selector: "generateInitializeCodeForObject",
  831. protocol: 'private',
  832. fn: function (){
  833. var self=this;
  834. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  835. return smalltalk.withContext(function($ctx1) {
  836. var $3,$2,$4,$5,$6,$7,$8,$1;
  837. $1=_st($String())._streamContents_((function(str){
  838. var instVars,size;
  839. return smalltalk.withContext(function($ctx2) {
  840. instVars=_st(_st(_st(self["@output"])._targetClass())._instanceVariableNames())._sorted();
  841. instVars;
  842. size=_st(instVars)._size();
  843. size;
  844. _st(str).__lt_lt("initialize");
  845. $ctx2.sendIdx["<<"]=1;
  846. $3=_st(str)._cr();
  847. $ctx2.sendIdx["cr"]=1;
  848. $2=_st($3)._tab();
  849. $ctx2.sendIdx["tab"]=1;
  850. _st($2).__lt_lt("super initialize.");
  851. $ctx2.sendIdx["<<"]=2;
  852. $4=_st($2)._cr();
  853. $ctx2.sendIdx["cr"]=2;
  854. $4;
  855. $5=_st(str)._cr();
  856. $ctx2.sendIdx["cr"]=3;
  857. _st($5)._tab();
  858. $ctx2.sendIdx["tab"]=2;
  859. return _st(instVars)._withIndexDo_((function(name,index){
  860. return smalltalk.withContext(function($ctx3) {
  861. $6=_st(index).__tild_eq((1));
  862. $ctx3.sendIdx["~="]=1;
  863. if(smalltalk.assert($6)){
  864. _st(_st(str)._cr())._tab();
  865. };
  866. $7=_st(str).__lt_lt(name);
  867. $ctx3.sendIdx["<<"]=4;
  868. _st($7).__lt_lt(" := nil");
  869. $ctx3.sendIdx["<<"]=3;
  870. $8=_st(index).__tild_eq(size);
  871. if(smalltalk.assert($8)){
  872. return _st(str).__lt_lt(".");
  873. };
  874. }, function($ctx3) {$ctx3.fillBlock({name:name,index:index},$ctx2,2)})}));
  875. }, function($ctx2) {$ctx2.fillBlock({str:str,instVars:instVars,size:size},$ctx1,1)})}));
  876. return $1;
  877. }, function($ctx1) {$ctx1.fill(self,"generateInitializeCodeForObject",{},smalltalk.HLInitializeGenerator)})},
  878. args: [],
  879. 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 << '.' ] ] ].",
  880. messageSends: ["streamContents:", "sorted", "instanceVariableNames", "targetClass", "size", "<<", "tab", "cr", "withIndexDo:", "ifTrue:", "~="],
  881. referencedClasses: ["String"]
  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._initializeMethodForObject());
  892. return self}, function($ctx1) {$ctx1.fill(self,"initializeForObject",{},smalltalk.HLInitializeGenerator)})},
  893. args: [],
  894. source: "initializeForObject\x0a\x09output addSourceCode: self initializeMethodForObject",
  895. messageSends: ["addSourceCode:", "initializeMethodForObject"],
  896. referencedClasses: []
  897. }),
  898. smalltalk.HLInitializeGenerator);
  899. smalltalk.addMethod(
  900. smalltalk.method({
  901. selector: "initializeMethodForObject",
  902. protocol: 'private',
  903. fn: function (){
  904. var self=this;
  905. function $HLMethodSourceCode(){return smalltalk.HLMethodSourceCode||(typeof HLMethodSourceCode=="undefined"?nil:HLMethodSourceCode)}
  906. return smalltalk.withContext(function($ctx1) {
  907. var $2,$3,$1;
  908. $2=_st($HLMethodSourceCode())._new();
  909. _st($2)._selector_("initialize");
  910. _st($2)._sourceCode_(self._generateInitializeCodeForObject());
  911. $3=_st($2)._yourself();
  912. $1=$3;
  913. return $1;
  914. }, function($ctx1) {$ctx1.fill(self,"initializeMethodForObject",{},smalltalk.HLInitializeGenerator)})},
  915. args: [],
  916. source: "initializeMethodForObject\x09\x0a\x09^ HLMethodSourceCode new\x0a\x09\x09selector: 'initialize';\x0a\x09\x09sourceCode: self generateInitializeCodeForObject;\x0a\x09\x09yourself",
  917. messageSends: ["selector:", "new", "sourceCode:", "generateInitializeCodeForObject", "yourself"],
  918. referencedClasses: ["HLMethodSourceCode"]
  919. }),
  920. smalltalk.HLInitializeGenerator);
  921. smalltalk.addMethod(
  922. smalltalk.method({
  923. selector: "initializeProtocolForObject",
  924. protocol: 'double-dispatch',
  925. fn: function (){
  926. var self=this;
  927. return smalltalk.withContext(function($ctx1) {
  928. _st(self["@output"])._protocol_("initialization");
  929. return self}, function($ctx1) {$ctx1.fill(self,"initializeProtocolForObject",{},smalltalk.HLInitializeGenerator)})},
  930. args: [],
  931. source: "initializeProtocolForObject\x0a\x09output protocol: 'initialization'",
  932. messageSends: ["protocol:"],
  933. referencedClasses: []
  934. }),
  935. smalltalk.HLInitializeGenerator);
  936. smalltalk.addClass('HLMethodSourceCode', smalltalk.Object, ['selector', 'sourceCode'], 'Helios-Helpers');
  937. 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";
  938. smalltalk.addMethod(
  939. smalltalk.method({
  940. selector: "selector",
  941. protocol: 'accessing',
  942. fn: function (){
  943. var self=this;
  944. return smalltalk.withContext(function($ctx1) {
  945. var $1;
  946. $1=self["@selector"];
  947. return $1;
  948. }, function($ctx1) {$ctx1.fill(self,"selector",{},smalltalk.HLMethodSourceCode)})},
  949. args: [],
  950. source: "selector\x0a\x09^ selector",
  951. messageSends: [],
  952. referencedClasses: []
  953. }),
  954. smalltalk.HLMethodSourceCode);
  955. smalltalk.addMethod(
  956. smalltalk.method({
  957. selector: "selector:",
  958. protocol: 'accessing',
  959. fn: function (aSelector){
  960. var self=this;
  961. return smalltalk.withContext(function($ctx1) {
  962. self["@selector"]=aSelector;
  963. return self}, function($ctx1) {$ctx1.fill(self,"selector:",{aSelector:aSelector},smalltalk.HLMethodSourceCode)})},
  964. args: ["aSelector"],
  965. source: "selector: aSelector\x0a\x09selector := aSelector",
  966. messageSends: [],
  967. referencedClasses: []
  968. }),
  969. smalltalk.HLMethodSourceCode);
  970. smalltalk.addMethod(
  971. smalltalk.method({
  972. selector: "sourceCode",
  973. protocol: 'accessing',
  974. fn: function (){
  975. var self=this;
  976. return smalltalk.withContext(function($ctx1) {
  977. var $1;
  978. $1=self["@sourceCode"];
  979. return $1;
  980. }, function($ctx1) {$ctx1.fill(self,"sourceCode",{},smalltalk.HLMethodSourceCode)})},
  981. args: [],
  982. source: "sourceCode\x0a\x09^ sourceCode",
  983. messageSends: [],
  984. referencedClasses: []
  985. }),
  986. smalltalk.HLMethodSourceCode);
  987. smalltalk.addMethod(
  988. smalltalk.method({
  989. selector: "sourceCode:",
  990. protocol: 'accessing',
  991. fn: function (aString){
  992. var self=this;
  993. return smalltalk.withContext(function($ctx1) {
  994. self["@sourceCode"]=aString;
  995. return self}, function($ctx1) {$ctx1.fill(self,"sourceCode:",{aString:aString},smalltalk.HLMethodSourceCode)})},
  996. args: ["aString"],
  997. source: "sourceCode: aString\x0a\x09sourceCode := aString",
  998. messageSends: [],
  999. referencedClasses: []
  1000. }),
  1001. smalltalk.HLMethodSourceCode);
  1002. });