Helios-Helpers.js 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215
  1. define("helios/Helios-Helpers", ["amber_vm/smalltalk", "amber_vm/nil", "amber_vm/_st", "amber_vm/globals", "amber_core/Kernel-Objects"], function(smalltalk,nil,_st, globals){
  2. smalltalk.addPackage('Helios-Helpers');
  3. smalltalk.packages["Helios-Helpers"].transport = {"type":"amd","amdNamespace":"helios"};
  4. smalltalk.addClass('HLClassifier', globals.Object, ['next', 'method'], 'Helios-Helpers');
  5. globals.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,$receiver;
  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",{},globals.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. globals.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",{},globals.HLClassifier)})},
  44. args: [],
  45. source: "doClassify\x0a\x09self subclassResponsibility",
  46. messageSends: ["subclassResponsibility"],
  47. referencedClasses: []
  48. }),
  49. globals.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. globals.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,$receiver;
  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},globals.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. globals.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. globals.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. globals.HLClassifier);
  120. smalltalk.addClass('HLAccessorClassifier', globals.HLClassifier, [], 'Helios-Helpers');
  121. globals.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},globals.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. globals.HLAccessorClassifier);
  151. smalltalk.addClass('HLImplementorClassifier', globals.HLClassifier, [], 'Helios-Helpers');
  152. globals.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},globals.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. globals.HLImplementorClassifier);
  193. smalltalk.addClass('HLPrefixClassifier', globals.HLClassifier, ['prefixMapping'], 'Helios-Helpers');
  194. globals.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 globals.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",{},globals.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. globals.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",{},globals.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. globals.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. globals.HLPrefixClassifier.superclass.fn.prototype._initialize.apply(_st(self), []);
  272. self._buildPrefixDictionary();
  273. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},globals.HLPrefixClassifier)})},
  274. args: [],
  275. source: "initialize\x0a\x09super initialize.\x0a\x0a\x09self buildPrefixDictionary",
  276. messageSends: ["initialize", "buildPrefixDictionary"],
  277. referencedClasses: []
  278. }),
  279. globals.HLPrefixClassifier);
  280. smalltalk.addClass('HLSuperclassClassifier', globals.HLClassifier, [], 'Helios-Helpers');
  281. globals.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 globals.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  290. function $HLReferencesModel(){return globals.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. throw $early=[false];
  300. }),(function(){
  301. return smalltalk.withContext(function($ctx2) {
  302. return _st(methods)._do_((function(aMethod){
  303. var protocol;
  304. return smalltalk.withContext(function($ctx3) {
  305. protocol=_st(_st(aMethod)._method())._protocol();
  306. protocol;
  307. $2=_st(self["@method"])._methodClass();
  308. $ctx3.sendIdx["methodClass"]=1;
  309. $1=_st($2).__eq(_st(aMethod)._methodClass());
  310. $ctx3.sendIdx["="]=1;
  311. if(! smalltalk.assert($1)){
  312. $4=_st(_st(protocol)._first()).__eq("*");
  313. $ctx3.sendIdx["="]=2;
  314. $3=_st($4)._or_((function(){
  315. return smalltalk.withContext(function($ctx4) {
  316. return _st(protocol).__eq(_st(self["@method"])._defaultProtocol());
  317. }, function($ctx4) {$ctx4.fillBlock({},$ctx3,5)})}));
  318. if(! smalltalk.assert($3)){
  319. return _st(protocolBag)._at_put_(protocol,_st(_st(protocolBag)._at_ifAbsent_(protocol,(function(){
  320. return (0);
  321. }))).__plus((1)));
  322. };
  323. };
  324. }, function($ctx3) {$ctx3.fillBlock({aMethod:aMethod,protocol:protocol},$ctx2,3)})}));
  325. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}));
  326. _st(protocolBag)._ifEmpty_((function(){
  327. throw $early=[false];
  328. }));
  329. protocolToUse=nil;
  330. counter=(0);
  331. _st(protocolBag)._keysAndValuesDo_((function(key,value){
  332. return smalltalk.withContext(function($ctx2) {
  333. $5=_st(value).__gt(counter);
  334. if(smalltalk.assert($5)){
  335. counter=value;
  336. counter;
  337. protocolToUse=key;
  338. return protocolToUse;
  339. };
  340. }, function($ctx2) {$ctx2.fillBlock({key:key,value:value},$ctx1,9)})}));
  341. _st(self["@method"])._protocol_(protocolToUse);
  342. return true;
  343. }
  344. catch(e) {if(e===$early)return e[0]; throw e}
  345. }, function($ctx1) {$ctx1.fill(self,"doClassify",{protocolBag:protocolBag,methods:methods,protocolToUse:protocolToUse,counter:counter},globals.HLSuperclassClassifier)})},
  346. args: [],
  347. 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",
  348. messageSends: ["new", "implementorsOf:", "selector", "ifEmpty:ifNotEmpty:", "do:", "protocol", "method", "ifFalse:", "=", "methodClass", "or:", "first", "defaultProtocol", "at:put:", "+", "at:ifAbsent:", "ifEmpty:", "keysAndValuesDo:", "ifTrue:", ">", "protocol:"],
  349. referencedClasses: ["Dictionary", "HLReferencesModel"]
  350. }),
  351. globals.HLSuperclassClassifier);
  352. smalltalk.addClass('HLGenerationOutput', globals.Object, ['sourceCodes', 'protocol', 'targetClass'], 'Helios-Helpers');
  353. globals.HLGenerationOutput.comment="I am a simple data object used to store the result of a generation process.";
  354. smalltalk.addMethod(
  355. smalltalk.method({
  356. selector: "addSourceCode:",
  357. protocol: 'protocol',
  358. fn: function (aString){
  359. var self=this;
  360. return smalltalk.withContext(function($ctx1) {
  361. _st(self["@sourceCodes"])._add_(aString);
  362. return self}, function($ctx1) {$ctx1.fill(self,"addSourceCode:",{aString:aString},globals.HLGenerationOutput)})},
  363. args: ["aString"],
  364. source: "addSourceCode: aString\x0a\x09sourceCodes add: aString",
  365. messageSends: ["add:"],
  366. referencedClasses: []
  367. }),
  368. globals.HLGenerationOutput);
  369. smalltalk.addMethod(
  370. smalltalk.method({
  371. selector: "compile",
  372. protocol: 'protocol',
  373. fn: function (){
  374. var self=this;
  375. return smalltalk.withContext(function($ctx1) {
  376. var $1;
  377. _st(self["@sourceCodes"])._do_((function(methodSourceCode){
  378. return smalltalk.withContext(function($ctx2) {
  379. $1=_st(self["@targetClass"])._includesSelector_(_st(methodSourceCode)._selector());
  380. if(! smalltalk.assert($1)){
  381. return _st(self["@targetClass"])._compile_protocol_(_st(methodSourceCode)._sourceCode(),self["@protocol"]);
  382. };
  383. }, function($ctx2) {$ctx2.fillBlock({methodSourceCode:methodSourceCode},$ctx1,1)})}));
  384. return self}, function($ctx1) {$ctx1.fill(self,"compile",{},globals.HLGenerationOutput)})},
  385. args: [],
  386. 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 ] ]",
  387. messageSends: ["do:", "ifFalse:", "includesSelector:", "selector", "compile:protocol:", "sourceCode"],
  388. referencedClasses: []
  389. }),
  390. globals.HLGenerationOutput);
  391. smalltalk.addMethod(
  392. smalltalk.method({
  393. selector: "initialize",
  394. protocol: 'initialization',
  395. fn: function (){
  396. var self=this;
  397. function $OrderedCollection(){return globals.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
  398. return smalltalk.withContext(function($ctx1) {
  399. globals.HLGenerationOutput.superclass.fn.prototype._initialize.apply(_st(self), []);
  400. self["@sourceCodes"]=_st($OrderedCollection())._new();
  401. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},globals.HLGenerationOutput)})},
  402. args: [],
  403. source: "initialize\x0a\x09super initialize.\x0a\x09\x0a\x09sourceCodes := OrderedCollection new",
  404. messageSends: ["initialize", "new"],
  405. referencedClasses: ["OrderedCollection"]
  406. }),
  407. globals.HLGenerationOutput);
  408. smalltalk.addMethod(
  409. smalltalk.method({
  410. selector: "protocol",
  411. protocol: 'accessing',
  412. fn: function (){
  413. var self=this;
  414. var $1;
  415. $1=self["@protocol"];
  416. return $1;
  417. },
  418. args: [],
  419. source: "protocol\x0a\x09^ protocol",
  420. messageSends: [],
  421. referencedClasses: []
  422. }),
  423. globals.HLGenerationOutput);
  424. smalltalk.addMethod(
  425. smalltalk.method({
  426. selector: "protocol:",
  427. protocol: 'accessing',
  428. fn: function (aString){
  429. var self=this;
  430. self["@protocol"]=aString;
  431. return self},
  432. args: ["aString"],
  433. source: "protocol: aString\x0a\x09protocol := aString",
  434. messageSends: [],
  435. referencedClasses: []
  436. }),
  437. globals.HLGenerationOutput);
  438. smalltalk.addMethod(
  439. smalltalk.method({
  440. selector: "sourceCodes",
  441. protocol: 'accessing',
  442. fn: function (){
  443. var self=this;
  444. var $1;
  445. $1=self["@sourceCodes"];
  446. return $1;
  447. },
  448. args: [],
  449. source: "sourceCodes\x0a\x09^ sourceCodes",
  450. messageSends: [],
  451. referencedClasses: []
  452. }),
  453. globals.HLGenerationOutput);
  454. smalltalk.addMethod(
  455. smalltalk.method({
  456. selector: "sourceCodes:",
  457. protocol: 'accessing',
  458. fn: function (aCollection){
  459. var self=this;
  460. self["@sourceCodes"]=aCollection;
  461. return self},
  462. args: ["aCollection"],
  463. source: "sourceCodes: aCollection\x0a\x09sourceCodes := aCollection",
  464. messageSends: [],
  465. referencedClasses: []
  466. }),
  467. globals.HLGenerationOutput);
  468. smalltalk.addMethod(
  469. smalltalk.method({
  470. selector: "targetClass",
  471. protocol: 'accessing',
  472. fn: function (){
  473. var self=this;
  474. var $1;
  475. $1=self["@targetClass"];
  476. return $1;
  477. },
  478. args: [],
  479. source: "targetClass\x0a\x09^ targetClass",
  480. messageSends: [],
  481. referencedClasses: []
  482. }),
  483. globals.HLGenerationOutput);
  484. smalltalk.addMethod(
  485. smalltalk.method({
  486. selector: "targetClass:",
  487. protocol: 'accessing',
  488. fn: function (aClass){
  489. var self=this;
  490. self["@targetClass"]=aClass;
  491. return self},
  492. args: ["aClass"],
  493. source: "targetClass: aClass\x0a\x09targetClass := aClass",
  494. messageSends: [],
  495. referencedClasses: []
  496. }),
  497. globals.HLGenerationOutput);
  498. smalltalk.addClass('HLMethodClassifier', globals.Object, ['firstClassifier'], 'Helios-Helpers');
  499. globals.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?";
  500. smalltalk.addMethod(
  501. smalltalk.method({
  502. selector: "addClassifier:",
  503. protocol: 'private',
  504. fn: function (aClassifier){
  505. var self=this;
  506. return smalltalk.withContext(function($ctx1) {
  507. _st(aClassifier)._next_(self["@firstClassifier"]);
  508. self["@firstClassifier"]=aClassifier;
  509. return self}, function($ctx1) {$ctx1.fill(self,"addClassifier:",{aClassifier:aClassifier},globals.HLMethodClassifier)})},
  510. args: ["aClassifier"],
  511. source: "addClassifier: aClassifier\x0a\x09aClassifier next: firstClassifier.\x0a\x09firstClassifier := aClassifier",
  512. messageSends: ["next:"],
  513. referencedClasses: []
  514. }),
  515. globals.HLMethodClassifier);
  516. smalltalk.addMethod(
  517. smalltalk.method({
  518. selector: "classify:",
  519. protocol: 'protocol',
  520. fn: function (aMethod){
  521. var self=this;
  522. return smalltalk.withContext(function($ctx1) {
  523. var $1,$2;
  524. $1=self["@firstClassifier"];
  525. _st($1)._method_(aMethod);
  526. $2=_st($1)._classify();
  527. return self}, function($ctx1) {$ctx1.fill(self,"classify:",{aMethod:aMethod},globals.HLMethodClassifier)})},
  528. args: ["aMethod"],
  529. source: "classify: aMethod\x0a\x09firstClassifier\x0a\x09\x09method: aMethod;\x0a\x09\x09classify",
  530. messageSends: ["method:", "classify"],
  531. referencedClasses: []
  532. }),
  533. globals.HLMethodClassifier);
  534. smalltalk.addMethod(
  535. smalltalk.method({
  536. selector: "classifyAll:",
  537. protocol: 'protocol',
  538. fn: function (aCollectionOfMethods){
  539. var self=this;
  540. return smalltalk.withContext(function($ctx1) {
  541. _st(aCollectionOfMethods)._do_((function(method){
  542. return smalltalk.withContext(function($ctx2) {
  543. return self._classify_(method);
  544. }, function($ctx2) {$ctx2.fillBlock({method:method},$ctx1,1)})}));
  545. return self}, function($ctx1) {$ctx1.fill(self,"classifyAll:",{aCollectionOfMethods:aCollectionOfMethods},globals.HLMethodClassifier)})},
  546. args: ["aCollectionOfMethods"],
  547. source: "classifyAll: aCollectionOfMethods\x0a\x09aCollectionOfMethods do: [ :method |\x0a\x09\x09self classify: method ]",
  548. messageSends: ["do:", "classify:"],
  549. referencedClasses: []
  550. }),
  551. globals.HLMethodClassifier);
  552. smalltalk.addMethod(
  553. smalltalk.method({
  554. selector: "initialize",
  555. protocol: 'initialization',
  556. fn: function (){
  557. var self=this;
  558. return smalltalk.withContext(function($ctx1) {
  559. globals.HLMethodClassifier.superclass.fn.prototype._initialize.apply(_st(self), []);
  560. self._setupClassifiers();
  561. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},globals.HLMethodClassifier)})},
  562. args: [],
  563. source: "initialize\x0a\x09super initialize.\x0a\x09\x0a\x09self setupClassifiers",
  564. messageSends: ["initialize", "setupClassifiers"],
  565. referencedClasses: []
  566. }),
  567. globals.HLMethodClassifier);
  568. smalltalk.addMethod(
  569. smalltalk.method({
  570. selector: "setupClassifiers",
  571. protocol: 'initialization',
  572. fn: function (){
  573. var self=this;
  574. function $HLImplementorClassifier(){return globals.HLImplementorClassifier||(typeof HLImplementorClassifier=="undefined"?nil:HLImplementorClassifier)}
  575. function $HLPrefixClassifier(){return globals.HLPrefixClassifier||(typeof HLPrefixClassifier=="undefined"?nil:HLPrefixClassifier)}
  576. function $HLSuperclassClassifier(){return globals.HLSuperclassClassifier||(typeof HLSuperclassClassifier=="undefined"?nil:HLSuperclassClassifier)}
  577. function $HLAccessorClassifier(){return globals.HLAccessorClassifier||(typeof HLAccessorClassifier=="undefined"?nil:HLAccessorClassifier)}
  578. return smalltalk.withContext(function($ctx1) {
  579. var $1,$2,$3;
  580. $1=_st($HLImplementorClassifier())._new();
  581. $ctx1.sendIdx["new"]=1;
  582. self._addClassifier_($1);
  583. $ctx1.sendIdx["addClassifier:"]=1;
  584. $2=_st($HLPrefixClassifier())._new();
  585. $ctx1.sendIdx["new"]=2;
  586. self._addClassifier_($2);
  587. $ctx1.sendIdx["addClassifier:"]=2;
  588. $3=_st($HLSuperclassClassifier())._new();
  589. $ctx1.sendIdx["new"]=3;
  590. self._addClassifier_($3);
  591. $ctx1.sendIdx["addClassifier:"]=3;
  592. self._addClassifier_(_st($HLAccessorClassifier())._new());
  593. return self}, function($ctx1) {$ctx1.fill(self,"setupClassifiers",{},globals.HLMethodClassifier)})},
  594. args: [],
  595. source: "setupClassifiers\x0a\x09self addClassifier: HLImplementorClassifier new.\x0a\x09self addClassifier: HLPrefixClassifier new.\x0a\x09self addClassifier: HLSuperclassClassifier new.\x0a\x09self addClassifier: HLAccessorClassifier new",
  596. messageSends: ["addClassifier:", "new"],
  597. referencedClasses: ["HLImplementorClassifier", "HLPrefixClassifier", "HLSuperclassClassifier", "HLAccessorClassifier"]
  598. }),
  599. globals.HLMethodClassifier);
  600. smalltalk.addClass('HLMethodGenerator', globals.Object, ['output'], 'Helios-Helpers');
  601. globals.HLMethodGenerator.comment="I am the abstract super class of the method generators.\x0a\x0aMy main method is `generate` which produces an `output` object accessed with `#output`.";
  602. smalltalk.addMethod(
  603. smalltalk.method({
  604. selector: "class:",
  605. protocol: 'accessing',
  606. fn: function (aClass){
  607. var self=this;
  608. return smalltalk.withContext(function($ctx1) {
  609. _st(self["@output"])._targetClass_(aClass);
  610. return self}, function($ctx1) {$ctx1.fill(self,"class:",{aClass:aClass},globals.HLMethodGenerator)})},
  611. args: ["aClass"],
  612. source: "class: aClass\x0a\x09output targetClass: aClass",
  613. messageSends: ["targetClass:"],
  614. referencedClasses: []
  615. }),
  616. globals.HLMethodGenerator);
  617. smalltalk.addMethod(
  618. smalltalk.method({
  619. selector: "generate",
  620. protocol: 'protocol',
  621. fn: function (){
  622. var self=this;
  623. return smalltalk.withContext(function($ctx1) {
  624. var $1,$receiver;
  625. $1=_st(self["@output"])._targetClass();
  626. if(($receiver = $1) == nil || $receiver == null){
  627. self._error_("class should not be nil");
  628. } else {
  629. $1;
  630. };
  631. return self}, function($ctx1) {$ctx1.fill(self,"generate",{},globals.HLMethodGenerator)})},
  632. args: [],
  633. source: "generate\x0a\x09output targetClass ifNil: [ self error: 'class should not be nil'].",
  634. messageSends: ["ifNil:", "targetClass", "error:"],
  635. referencedClasses: []
  636. }),
  637. globals.HLMethodGenerator);
  638. smalltalk.addMethod(
  639. smalltalk.method({
  640. selector: "initialize",
  641. protocol: 'initialization',
  642. fn: function (){
  643. var self=this;
  644. function $HLGenerationOutput(){return globals.HLGenerationOutput||(typeof HLGenerationOutput=="undefined"?nil:HLGenerationOutput)}
  645. return smalltalk.withContext(function($ctx1) {
  646. globals.HLMethodGenerator.superclass.fn.prototype._initialize.apply(_st(self), []);
  647. self["@output"]=_st($HLGenerationOutput())._new();
  648. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},globals.HLMethodGenerator)})},
  649. args: [],
  650. source: "initialize\x0a\x09super initialize.\x0a\x09\x0a\x09output := HLGenerationOutput new",
  651. messageSends: ["initialize", "new"],
  652. referencedClasses: ["HLGenerationOutput"]
  653. }),
  654. globals.HLMethodGenerator);
  655. smalltalk.addMethod(
  656. smalltalk.method({
  657. selector: "output",
  658. protocol: 'accessing',
  659. fn: function (){
  660. var self=this;
  661. var $1;
  662. $1=self["@output"];
  663. return $1;
  664. },
  665. args: [],
  666. source: "output\x0a\x09^ output",
  667. messageSends: [],
  668. referencedClasses: []
  669. }),
  670. globals.HLMethodGenerator);
  671. smalltalk.addClass('HLAccessorsGenerator', globals.HLMethodGenerator, [], 'Helios-Helpers');
  672. globals.HLAccessorsGenerator.comment="I am a generator used to compile the getters/setters of a class.";
  673. smalltalk.addMethod(
  674. smalltalk.method({
  675. selector: "accessorProtocolForObject",
  676. protocol: 'double-dispatch',
  677. fn: function (){
  678. var self=this;
  679. return smalltalk.withContext(function($ctx1) {
  680. _st(self["@output"])._protocol_("accessing");
  681. return self}, function($ctx1) {$ctx1.fill(self,"accessorProtocolForObject",{},globals.HLAccessorsGenerator)})},
  682. args: [],
  683. source: "accessorProtocolForObject\x0a\x09output protocol: 'accessing'",
  684. messageSends: ["protocol:"],
  685. referencedClasses: []
  686. }),
  687. globals.HLAccessorsGenerator);
  688. smalltalk.addMethod(
  689. smalltalk.method({
  690. selector: "accessorsForObject",
  691. protocol: 'double-dispatch',
  692. fn: function (){
  693. var self=this;
  694. var sources;
  695. function $OrderedCollection(){return globals.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
  696. return smalltalk.withContext(function($ctx1) {
  697. var $1,$2;
  698. sources=_st($OrderedCollection())._new();
  699. _st(_st(_st(_st(self["@output"])._targetClass())._instanceVariableNames())._sorted())._do_((function(each){
  700. return smalltalk.withContext(function($ctx2) {
  701. $1=sources;
  702. _st($1)._add_(self._getterFor_(each));
  703. $ctx2.sendIdx["add:"]=1;
  704. $2=_st($1)._add_(self._setterFor_(each));
  705. return $2;
  706. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  707. _st(self["@output"])._sourceCodes_(sources);
  708. return self}, function($ctx1) {$ctx1.fill(self,"accessorsForObject",{sources:sources},globals.HLAccessorsGenerator)})},
  709. args: [],
  710. 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",
  711. messageSends: ["new", "do:", "sorted", "instanceVariableNames", "targetClass", "add:", "getterFor:", "setterFor:", "sourceCodes:"],
  712. referencedClasses: ["OrderedCollection"]
  713. }),
  714. globals.HLAccessorsGenerator);
  715. smalltalk.addMethod(
  716. smalltalk.method({
  717. selector: "generate",
  718. protocol: 'protocol',
  719. fn: function (){
  720. var self=this;
  721. return smalltalk.withContext(function($ctx1) {
  722. var $1,$2;
  723. globals.HLAccessorsGenerator.superclass.fn.prototype._generate.apply(_st(self), []);
  724. $1=_st(self["@output"])._targetClass();
  725. _st($1)._accessorsSourceCodesWith_(self);
  726. $2=_st($1)._accessorProtocolWith_(self);
  727. return self}, function($ctx1) {$ctx1.fill(self,"generate",{},globals.HLAccessorsGenerator)})},
  728. args: [],
  729. source: "generate\x0a\x09super generate.\x0a\x09\x0a\x09output targetClass \x0a\x09\x09accessorsSourceCodesWith: self;\x0a\x09\x09accessorProtocolWith: self",
  730. messageSends: ["generate", "accessorsSourceCodesWith:", "targetClass", "accessorProtocolWith:"],
  731. referencedClasses: []
  732. }),
  733. globals.HLAccessorsGenerator);
  734. smalltalk.addMethod(
  735. smalltalk.method({
  736. selector: "getterFor:",
  737. protocol: 'private',
  738. fn: function (anInstanceVariable){
  739. var self=this;
  740. function $HLMethodSourceCode(){return globals.HLMethodSourceCode||(typeof HLMethodSourceCode=="undefined"?nil:HLMethodSourceCode)}
  741. function $String(){return globals.String||(typeof String=="undefined"?nil:String)}
  742. return smalltalk.withContext(function($ctx1) {
  743. var $2,$3,$1;
  744. $2=_st($HLMethodSourceCode())._new();
  745. _st($2)._selector_(anInstanceVariable);
  746. $3=_st($2)._sourceCode_(_st($String())._streamContents_((function(stream){
  747. return smalltalk.withContext(function($ctx2) {
  748. _st(stream).__lt_lt(anInstanceVariable);
  749. $ctx2.sendIdx["<<"]=1;
  750. _st(_st(stream)._cr())._tab();
  751. return _st(_st(stream).__lt_lt("^ ")).__lt_lt(anInstanceVariable);
  752. $ctx2.sendIdx["<<"]=2;
  753. }, function($ctx2) {$ctx2.fillBlock({stream:stream},$ctx1,1)})})));
  754. $1=$3;
  755. return $1;
  756. }, function($ctx1) {$ctx1.fill(self,"getterFor:",{anInstanceVariable:anInstanceVariable},globals.HLAccessorsGenerator)})},
  757. args: ["anInstanceVariable"],
  758. 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 ])",
  759. messageSends: ["selector:", "new", "sourceCode:", "streamContents:", "<<", "tab", "cr"],
  760. referencedClasses: ["HLMethodSourceCode", "String"]
  761. }),
  762. globals.HLAccessorsGenerator);
  763. smalltalk.addMethod(
  764. smalltalk.method({
  765. selector: "setterFor:",
  766. protocol: 'private',
  767. fn: function (anInstanceVariable){
  768. var self=this;
  769. function $HLMethodSourceCode(){return globals.HLMethodSourceCode||(typeof HLMethodSourceCode=="undefined"?nil:HLMethodSourceCode)}
  770. function $String(){return globals.String||(typeof String=="undefined"?nil:String)}
  771. return smalltalk.withContext(function($ctx1) {
  772. var $2,$4,$3,$1;
  773. $2=_st($HLMethodSourceCode())._new();
  774. _st($2)._selector_(_st(anInstanceVariable).__comma(":"));
  775. $3=_st($2)._sourceCode_(_st($String())._streamContents_((function(stream){
  776. return smalltalk.withContext(function($ctx2) {
  777. $4=_st(stream).__lt_lt(anInstanceVariable);
  778. $ctx2.sendIdx["<<"]=2;
  779. _st($4).__lt_lt(": anObject");
  780. $ctx2.sendIdx["<<"]=1;
  781. _st(_st(stream)._cr())._tab();
  782. return _st(_st(stream).__lt_lt(anInstanceVariable)).__lt_lt(" := anObject");
  783. $ctx2.sendIdx["<<"]=3;
  784. }, function($ctx2) {$ctx2.fillBlock({stream:stream},$ctx1,1)})})));
  785. $1=$3;
  786. return $1;
  787. }, function($ctx1) {$ctx1.fill(self,"setterFor:",{anInstanceVariable:anInstanceVariable},globals.HLAccessorsGenerator)})},
  788. args: ["anInstanceVariable"],
  789. 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' ])",
  790. messageSends: ["selector:", "new", ",", "sourceCode:", "streamContents:", "<<", "tab", "cr"],
  791. referencedClasses: ["HLMethodSourceCode", "String"]
  792. }),
  793. globals.HLAccessorsGenerator);
  794. smalltalk.addClass('HLInitializeGenerator', globals.HLMethodGenerator, [], 'Helios-Helpers');
  795. globals.HLInitializeGenerator.comment="I am used to double-dispatch the `initialize` method(s) generation. I am a disposable object.\x0a\x0a## Usage\x0a\x0a ^ HLInitializeGenerator new\x0a class: aClass;\x0a generate;\x0a output";
  796. smalltalk.addMethod(
  797. smalltalk.method({
  798. selector: "generate",
  799. protocol: 'protocol',
  800. fn: function (){
  801. var self=this;
  802. return smalltalk.withContext(function($ctx1) {
  803. var $1,$2;
  804. globals.HLInitializeGenerator.superclass.fn.prototype._generate.apply(_st(self), []);
  805. $1=_st(self["@output"])._targetClass();
  806. _st($1)._initializeSourceCodesWith_(self);
  807. $2=_st($1)._initializeProtocolWith_(self);
  808. return self}, function($ctx1) {$ctx1.fill(self,"generate",{},globals.HLInitializeGenerator)})},
  809. args: [],
  810. source: "generate\x0a\x09super generate.\x0a\x09\x0a\x09output targetClass \x0a\x09\x09initializeSourceCodesWith: self;\x0a\x09\x09initializeProtocolWith: self",
  811. messageSends: ["generate", "initializeSourceCodesWith:", "targetClass", "initializeProtocolWith:"],
  812. referencedClasses: []
  813. }),
  814. globals.HLInitializeGenerator);
  815. smalltalk.addMethod(
  816. smalltalk.method({
  817. selector: "generateInitializeCodeForObject",
  818. protocol: 'private',
  819. fn: function (){
  820. var self=this;
  821. function $String(){return globals.String||(typeof String=="undefined"?nil:String)}
  822. return smalltalk.withContext(function($ctx1) {
  823. var $3,$2,$4,$5,$6,$7,$8,$1;
  824. $1=_st($String())._streamContents_((function(str){
  825. var instVars,size;
  826. return smalltalk.withContext(function($ctx2) {
  827. instVars=_st(_st(_st(self["@output"])._targetClass())._instanceVariableNames())._sorted();
  828. instVars;
  829. size=_st(instVars)._size();
  830. size;
  831. _st(str).__lt_lt("initialize");
  832. $ctx2.sendIdx["<<"]=1;
  833. $3=_st(str)._cr();
  834. $ctx2.sendIdx["cr"]=1;
  835. $2=_st($3)._tab();
  836. $ctx2.sendIdx["tab"]=1;
  837. _st($2).__lt_lt("super initialize.");
  838. $ctx2.sendIdx["<<"]=2;
  839. $4=_st($2)._cr();
  840. $ctx2.sendIdx["cr"]=2;
  841. $4;
  842. $5=_st(str)._cr();
  843. $ctx2.sendIdx["cr"]=3;
  844. _st($5)._tab();
  845. $ctx2.sendIdx["tab"]=2;
  846. return _st(instVars)._withIndexDo_((function(name,index){
  847. return smalltalk.withContext(function($ctx3) {
  848. $6=_st(index).__tild_eq((1));
  849. $ctx3.sendIdx["~="]=1;
  850. if(smalltalk.assert($6)){
  851. _st(_st(str)._cr())._tab();
  852. };
  853. $7=_st(str).__lt_lt(name);
  854. $ctx3.sendIdx["<<"]=4;
  855. _st($7).__lt_lt(" := nil");
  856. $ctx3.sendIdx["<<"]=3;
  857. $8=_st(index).__tild_eq(size);
  858. if(smalltalk.assert($8)){
  859. return _st(str).__lt_lt(".");
  860. };
  861. }, function($ctx3) {$ctx3.fillBlock({name:name,index:index},$ctx2,2)})}));
  862. }, function($ctx2) {$ctx2.fillBlock({str:str,instVars:instVars,size:size},$ctx1,1)})}));
  863. return $1;
  864. }, function($ctx1) {$ctx1.fill(self,"generateInitializeCodeForObject",{},globals.HLInitializeGenerator)})},
  865. args: [],
  866. 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 << '.' ] ] ].",
  867. messageSends: ["streamContents:", "sorted", "instanceVariableNames", "targetClass", "size", "<<", "tab", "cr", "withIndexDo:", "ifTrue:", "~="],
  868. referencedClasses: ["String"]
  869. }),
  870. globals.HLInitializeGenerator);
  871. smalltalk.addMethod(
  872. smalltalk.method({
  873. selector: "initializeForObject",
  874. protocol: 'double-dispatch',
  875. fn: function (){
  876. var self=this;
  877. return smalltalk.withContext(function($ctx1) {
  878. _st(self["@output"])._addSourceCode_(self._initializeMethodForObject());
  879. return self}, function($ctx1) {$ctx1.fill(self,"initializeForObject",{},globals.HLInitializeGenerator)})},
  880. args: [],
  881. source: "initializeForObject\x0a\x09output addSourceCode: self initializeMethodForObject",
  882. messageSends: ["addSourceCode:", "initializeMethodForObject"],
  883. referencedClasses: []
  884. }),
  885. globals.HLInitializeGenerator);
  886. smalltalk.addMethod(
  887. smalltalk.method({
  888. selector: "initializeMethodForObject",
  889. protocol: 'private',
  890. fn: function (){
  891. var self=this;
  892. function $HLMethodSourceCode(){return globals.HLMethodSourceCode||(typeof HLMethodSourceCode=="undefined"?nil:HLMethodSourceCode)}
  893. return smalltalk.withContext(function($ctx1) {
  894. var $2,$3,$1;
  895. $2=_st($HLMethodSourceCode())._new();
  896. _st($2)._selector_("initialize");
  897. _st($2)._sourceCode_(self._generateInitializeCodeForObject());
  898. $3=_st($2)._yourself();
  899. $1=$3;
  900. return $1;
  901. }, function($ctx1) {$ctx1.fill(self,"initializeMethodForObject",{},globals.HLInitializeGenerator)})},
  902. args: [],
  903. source: "initializeMethodForObject\x09\x0a\x09^ HLMethodSourceCode new\x0a\x09\x09selector: 'initialize';\x0a\x09\x09sourceCode: self generateInitializeCodeForObject;\x0a\x09\x09yourself",
  904. messageSends: ["selector:", "new", "sourceCode:", "generateInitializeCodeForObject", "yourself"],
  905. referencedClasses: ["HLMethodSourceCode"]
  906. }),
  907. globals.HLInitializeGenerator);
  908. smalltalk.addMethod(
  909. smalltalk.method({
  910. selector: "initializeProtocolForObject",
  911. protocol: 'double-dispatch',
  912. fn: function (){
  913. var self=this;
  914. return smalltalk.withContext(function($ctx1) {
  915. _st(self["@output"])._protocol_("initialization");
  916. return self}, function($ctx1) {$ctx1.fill(self,"initializeProtocolForObject",{},globals.HLInitializeGenerator)})},
  917. args: [],
  918. source: "initializeProtocolForObject\x0a\x09output protocol: 'initialization'",
  919. messageSends: ["protocol:"],
  920. referencedClasses: []
  921. }),
  922. globals.HLInitializeGenerator);
  923. smalltalk.addClass('HLMethodSourceCode', globals.Object, ['selector', 'sourceCode'], 'Helios-Helpers');
  924. globals.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.";
  925. smalltalk.addMethod(
  926. smalltalk.method({
  927. selector: "selector",
  928. protocol: 'accessing',
  929. fn: function (){
  930. var self=this;
  931. var $1;
  932. $1=self["@selector"];
  933. return $1;
  934. },
  935. args: [],
  936. source: "selector\x0a\x09^ selector",
  937. messageSends: [],
  938. referencedClasses: []
  939. }),
  940. globals.HLMethodSourceCode);
  941. smalltalk.addMethod(
  942. smalltalk.method({
  943. selector: "selector:",
  944. protocol: 'accessing',
  945. fn: function (aSelector){
  946. var self=this;
  947. self["@selector"]=aSelector;
  948. return self},
  949. args: ["aSelector"],
  950. source: "selector: aSelector\x0a\x09selector := aSelector",
  951. messageSends: [],
  952. referencedClasses: []
  953. }),
  954. globals.HLMethodSourceCode);
  955. smalltalk.addMethod(
  956. smalltalk.method({
  957. selector: "sourceCode",
  958. protocol: 'accessing',
  959. fn: function (){
  960. var self=this;
  961. var $1;
  962. $1=self["@sourceCode"];
  963. return $1;
  964. },
  965. args: [],
  966. source: "sourceCode\x0a\x09^ sourceCode",
  967. messageSends: [],
  968. referencedClasses: []
  969. }),
  970. globals.HLMethodSourceCode);
  971. smalltalk.addMethod(
  972. smalltalk.method({
  973. selector: "sourceCode:",
  974. protocol: 'accessing',
  975. fn: function (aString){
  976. var self=this;
  977. self["@sourceCode"]=aString;
  978. return self},
  979. args: ["aString"],
  980. source: "sourceCode: aString\x0a\x09sourceCode := aString",
  981. messageSends: [],
  982. referencedClasses: []
  983. }),
  984. globals.HLMethodSourceCode);
  985. smalltalk.addClass('HLPackageCommitErrorHelper', globals.Object, ['model'], 'Helios-Helpers');
  986. smalltalk.addMethod(
  987. smalltalk.method({
  988. selector: "commitPackage",
  989. protocol: 'actions',
  990. fn: function (){
  991. var self=this;
  992. function $HLCommitPackageCommand(){return globals.HLCommitPackageCommand||(typeof HLCommitPackageCommand=="undefined"?nil:HLCommitPackageCommand)}
  993. return smalltalk.withContext(function($ctx1) {
  994. _st(_st($HLCommitPackageCommand())._for_(self._model()))._execute();
  995. return self}, function($ctx1) {$ctx1.fill(self,"commitPackage",{},globals.HLPackageCommitErrorHelper)})},
  996. args: [],
  997. source: "commitPackage\x0a\x09(HLCommitPackageCommand for: self model)\x0a\x09\x09execute",
  998. messageSends: ["execute", "for:", "model"],
  999. referencedClasses: ["HLCommitPackageCommand"]
  1000. }),
  1001. globals.HLPackageCommitErrorHelper);
  1002. smalltalk.addMethod(
  1003. smalltalk.method({
  1004. selector: "commitToPath:",
  1005. protocol: 'actions',
  1006. fn: function (aString){
  1007. var self=this;
  1008. return smalltalk.withContext(function($ctx1) {
  1009. _st(_st(self._package())._transport())._setPath_(aString);
  1010. self._commitPackage();
  1011. return self}, function($ctx1) {$ctx1.fill(self,"commitToPath:",{aString:aString},globals.HLPackageCommitErrorHelper)})},
  1012. args: ["aString"],
  1013. source: "commitToPath: aString\x0a\x09\x22We only take AMD package transport into account for now\x22\x0a\x09\x0a\x09self package transport setPath: aString.\x0a\x09\x0a\x09self commitPackage",
  1014. messageSends: ["setPath:", "transport", "package", "commitPackage"],
  1015. referencedClasses: []
  1016. }),
  1017. globals.HLPackageCommitErrorHelper);
  1018. smalltalk.addMethod(
  1019. smalltalk.method({
  1020. selector: "model",
  1021. protocol: 'accessing',
  1022. fn: function (){
  1023. var self=this;
  1024. var $1;
  1025. $1=self["@model"];
  1026. return $1;
  1027. },
  1028. args: [],
  1029. source: "model\x0a\x09^ model",
  1030. messageSends: [],
  1031. referencedClasses: []
  1032. }),
  1033. globals.HLPackageCommitErrorHelper);
  1034. smalltalk.addMethod(
  1035. smalltalk.method({
  1036. selector: "model:",
  1037. protocol: 'accessing',
  1038. fn: function (aToolModel){
  1039. var self=this;
  1040. self["@model"]=aToolModel;
  1041. return self},
  1042. args: ["aToolModel"],
  1043. source: "model: aToolModel\x0a\x09model := aToolModel",
  1044. messageSends: [],
  1045. referencedClasses: []
  1046. }),
  1047. globals.HLPackageCommitErrorHelper);
  1048. smalltalk.addMethod(
  1049. smalltalk.method({
  1050. selector: "package",
  1051. protocol: 'accessing',
  1052. fn: function (){
  1053. var self=this;
  1054. return smalltalk.withContext(function($ctx1) {
  1055. var $1;
  1056. $1=_st(self._model())._packageToCommit();
  1057. return $1;
  1058. }, function($ctx1) {$ctx1.fill(self,"package",{},globals.HLPackageCommitErrorHelper)})},
  1059. args: [],
  1060. source: "package\x0a\x09^ self model packageToCommit",
  1061. messageSends: ["packageToCommit", "model"],
  1062. referencedClasses: []
  1063. }),
  1064. globals.HLPackageCommitErrorHelper);
  1065. smalltalk.addMethod(
  1066. smalltalk.method({
  1067. selector: "showHelp",
  1068. protocol: 'actions',
  1069. fn: function (){
  1070. var self=this;
  1071. function $HLConfirmationWidget(){return globals.HLConfirmationWidget||(typeof HLConfirmationWidget=="undefined"?nil:HLConfirmationWidget)}
  1072. return smalltalk.withContext(function($ctx1) {
  1073. var $1,$2,$3,$4;
  1074. $1=_st($HLConfirmationWidget())._new();
  1075. $2=$1;
  1076. $3=_st("Commit failed for namespace \x22".__comma(_st(_st(self._package())._transport())._namespace())).__comma("\x22. Do you want to commit to another path?");
  1077. $ctx1.sendIdx[","]=1;
  1078. _st($2)._confirmationString_($3);
  1079. _st($1)._actionBlock_((function(){
  1080. return smalltalk.withContext(function($ctx2) {
  1081. return self._showNewCommitPath();
  1082. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
  1083. _st($1)._cancelButtonLabel_("Abandon");
  1084. _st($1)._confirmButtonLabel_("Set path");
  1085. $4=_st($1)._show();
  1086. return self}, function($ctx1) {$ctx1.fill(self,"showHelp",{},globals.HLPackageCommitErrorHelper)})},
  1087. args: [],
  1088. source: "showHelp\x0a\x09HLConfirmationWidget new\x0a\x09\x09confirmationString: 'Commit failed for namespace \x22', self package transport namespace, '\x22. Do you want to commit to another path?';\x0a\x09\x09actionBlock: [ self showNewCommitPath ];\x0a\x09\x09cancelButtonLabel: 'Abandon';\x0a\x09\x09confirmButtonLabel: 'Set path';\x0a\x09\x09show\x0a\x09",
  1089. messageSends: ["confirmationString:", "new", ",", "namespace", "transport", "package", "actionBlock:", "showNewCommitPath", "cancelButtonLabel:", "confirmButtonLabel:", "show"],
  1090. referencedClasses: ["HLConfirmationWidget"]
  1091. }),
  1092. globals.HLPackageCommitErrorHelper);
  1093. smalltalk.addMethod(
  1094. smalltalk.method({
  1095. selector: "showNewCommitPath",
  1096. protocol: 'actions',
  1097. fn: function (){
  1098. var self=this;
  1099. function $HLRequestWidget(){return globals.HLRequestWidget||(typeof HLRequestWidget=="undefined"?nil:HLRequestWidget)}
  1100. return smalltalk.withContext(function($ctx1) {
  1101. var $1,$2;
  1102. $1=_st($HLRequestWidget())._new();
  1103. _st($1)._beSingleline();
  1104. _st($1)._confirmationString_("Set commit path");
  1105. _st($1)._actionBlock_((function(url){
  1106. return smalltalk.withContext(function($ctx2) {
  1107. return self._commitToPath_(url);
  1108. }, function($ctx2) {$ctx2.fillBlock({url:url},$ctx1,1)})}));
  1109. _st($1)._confirmButtonLabel_("Commit with new path");
  1110. _st($1)._value_("/src");
  1111. $2=_st($1)._show();
  1112. return self}, function($ctx1) {$ctx1.fill(self,"showNewCommitPath",{},globals.HLPackageCommitErrorHelper)})},
  1113. args: [],
  1114. source: "showNewCommitPath\x0a\x09HLRequestWidget new\x0a\x09\x09beSingleline;\x0a\x09\x09confirmationString: 'Set commit path';\x0a\x09\x09actionBlock: [ :url | self commitToPath: url ];\x0a\x09\x09confirmButtonLabel: 'Commit with new path';\x0a\x09\x09value: '/src';\x0a\x09\x09show",
  1115. messageSends: ["beSingleline", "new", "confirmationString:", "actionBlock:", "commitToPath:", "confirmButtonLabel:", "value:", "show"],
  1116. referencedClasses: ["HLRequestWidget"]
  1117. }),
  1118. globals.HLPackageCommitErrorHelper);
  1119. smalltalk.addMethod(
  1120. smalltalk.method({
  1121. selector: "on:",
  1122. protocol: 'instance creation',
  1123. fn: function (aToolModel){
  1124. var self=this;
  1125. return smalltalk.withContext(function($ctx1) {
  1126. var $2,$3,$1;
  1127. $2=self._new();
  1128. _st($2)._model_(aToolModel);
  1129. $3=_st($2)._yourself();
  1130. $1=$3;
  1131. return $1;
  1132. }, function($ctx1) {$ctx1.fill(self,"on:",{aToolModel:aToolModel},globals.HLPackageCommitErrorHelper.klass)})},
  1133. args: ["aToolModel"],
  1134. source: "on: aToolModel\x0a\x09^ self new\x0a\x09\x09model: aToolModel;\x0a\x09\x09yourself",
  1135. messageSends: ["model:", "new", "yourself"],
  1136. referencedClasses: []
  1137. }),
  1138. globals.HLPackageCommitErrorHelper.klass);
  1139. });