Helios-Helpers.js 39 KB

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