Helios-Helpers.js 40 KB

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