1
0

Kernel-Dag.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. define(["amber/boot", "amber_core/Kernel-Objects"], function($boot){"use strict";
  2. if(!$boot.nilAsReceiver)$boot.nilAsReceiver=$boot.nil;
  3. var $core=$boot.api,nil=$boot.nilAsReceiver,$recv=$boot.asReceiver,$globals=$boot.globals;
  4. if(!$boot.nilAsClass)$boot.nilAsClass=$boot.dnu;
  5. $core.addPackage('Kernel-Dag');
  6. $core.packages["Kernel-Dag"].innerEval = function (expr) { return eval(expr); };
  7. $core.packages["Kernel-Dag"].transport = {"type":"amd","amdNamespace":"amber_core"};
  8. $core.addClass('AbstractDagVisitor', $globals.Object, [], 'Kernel-Dag');
  9. //>>excludeStart("ide", pragmas.excludeIdeData);
  10. $globals.AbstractDagVisitor.comment="I am base class of `DagNode` visitor.\x0a\x0aConcrete classes should implement `visitDagNode:`,\x0athey can reuse possible variants of implementation\x0aoffered directly: `visitDagNodeVariantSimple:`\x0aand `visitDagNodeVariantRedux:`.";
  11. //>>excludeEnd("ide");
  12. $core.addMethod(
  13. $core.method({
  14. selector: "value:",
  15. protocol: 'evaluating',
  16. fn: function (anObject){
  17. var self=this;
  18. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  19. return $core.withContext(function($ctx1) {
  20. //>>excludeEnd("ctx");
  21. return self._visit_(anObject);
  22. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  23. }, function($ctx1) {$ctx1.fill(self,"value:",{anObject:anObject},$globals.AbstractDagVisitor)});
  24. //>>excludeEnd("ctx");
  25. },
  26. //>>excludeStart("ide", pragmas.excludeIdeData);
  27. args: ["anObject"],
  28. source: "value: anObject\x0a\x09^ self visit: anObject",
  29. referencedClasses: [],
  30. //>>excludeEnd("ide");
  31. messageSends: ["visit:"]
  32. }),
  33. $globals.AbstractDagVisitor);
  34. $core.addMethod(
  35. $core.method({
  36. selector: "visit:",
  37. protocol: 'visiting',
  38. fn: function (aNode){
  39. var self=this;
  40. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  41. return $core.withContext(function($ctx1) {
  42. //>>excludeEnd("ctx");
  43. return $recv(aNode)._acceptDagVisitor_(self);
  44. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  45. }, function($ctx1) {$ctx1.fill(self,"visit:",{aNode:aNode},$globals.AbstractDagVisitor)});
  46. //>>excludeEnd("ctx");
  47. },
  48. //>>excludeStart("ide", pragmas.excludeIdeData);
  49. args: ["aNode"],
  50. source: "visit: aNode\x0a\x09^ aNode acceptDagVisitor: self",
  51. referencedClasses: [],
  52. //>>excludeEnd("ide");
  53. messageSends: ["acceptDagVisitor:"]
  54. }),
  55. $globals.AbstractDagVisitor);
  56. $core.addMethod(
  57. $core.method({
  58. selector: "visitAll:",
  59. protocol: 'visiting',
  60. fn: function (aCollection){
  61. var self=this;
  62. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  63. return $core.withContext(function($ctx1) {
  64. //>>excludeEnd("ctx");
  65. return $recv(aCollection)._collect_((function(each){
  66. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  67. return $core.withContext(function($ctx2) {
  68. //>>excludeEnd("ctx");
  69. return self._visit_(each);
  70. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  71. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  72. //>>excludeEnd("ctx");
  73. }));
  74. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  75. }, function($ctx1) {$ctx1.fill(self,"visitAll:",{aCollection:aCollection},$globals.AbstractDagVisitor)});
  76. //>>excludeEnd("ctx");
  77. },
  78. //>>excludeStart("ide", pragmas.excludeIdeData);
  79. args: ["aCollection"],
  80. source: "visitAll: aCollection\x0a\x09^ aCollection collect: [ :each | self visit: each ]",
  81. referencedClasses: [],
  82. //>>excludeEnd("ide");
  83. messageSends: ["collect:", "visit:"]
  84. }),
  85. $globals.AbstractDagVisitor);
  86. $core.addMethod(
  87. $core.method({
  88. selector: "visitAllChildren:",
  89. protocol: 'visiting',
  90. fn: function (aDagNode){
  91. var self=this;
  92. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  93. return $core.withContext(function($ctx1) {
  94. //>>excludeEnd("ctx");
  95. return self._visitAll_($recv(aDagNode)._dagChildren());
  96. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  97. }, function($ctx1) {$ctx1.fill(self,"visitAllChildren:",{aDagNode:aDagNode},$globals.AbstractDagVisitor)});
  98. //>>excludeEnd("ctx");
  99. },
  100. //>>excludeStart("ide", pragmas.excludeIdeData);
  101. args: ["aDagNode"],
  102. source: "visitAllChildren: aDagNode\x0a\x09^ self visitAll: aDagNode dagChildren",
  103. referencedClasses: [],
  104. //>>excludeEnd("ide");
  105. messageSends: ["visitAll:", "dagChildren"]
  106. }),
  107. $globals.AbstractDagVisitor);
  108. $core.addMethod(
  109. $core.method({
  110. selector: "visitDagNode:",
  111. protocol: 'visiting',
  112. fn: function (aNode){
  113. var self=this;
  114. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  115. return $core.withContext(function($ctx1) {
  116. //>>excludeEnd("ctx");
  117. self._subclassResponsibility();
  118. return self;
  119. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  120. }, function($ctx1) {$ctx1.fill(self,"visitDagNode:",{aNode:aNode},$globals.AbstractDagVisitor)});
  121. //>>excludeEnd("ctx");
  122. },
  123. //>>excludeStart("ide", pragmas.excludeIdeData);
  124. args: ["aNode"],
  125. source: "visitDagNode: aNode\x0a\x09self subclassResponsibility",
  126. referencedClasses: [],
  127. //>>excludeEnd("ide");
  128. messageSends: ["subclassResponsibility"]
  129. }),
  130. $globals.AbstractDagVisitor);
  131. $core.addMethod(
  132. $core.method({
  133. selector: "visitDagNodeVariantRedux:",
  134. protocol: 'visiting',
  135. fn: function (aNode){
  136. var self=this;
  137. var newChildren,oldChildren;
  138. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  139. return $core.withContext(function($ctx1) {
  140. //>>excludeEnd("ctx");
  141. var $2,$3,$1,$4,$5;
  142. var $early={};
  143. try {
  144. oldChildren=$recv(aNode)._dagChildren();
  145. newChildren=self._visitAllChildren_(aNode);
  146. $2=$recv(oldChildren)._size();
  147. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  148. $ctx1.sendIdx["size"]=1;
  149. //>>excludeEnd("ctx");
  150. $3=$recv(newChildren)._size();
  151. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  152. $ctx1.sendIdx["size"]=2;
  153. //>>excludeEnd("ctx");
  154. $1=$recv($2).__eq($3);
  155. if($core.assert($1)){
  156. $recv((1)._to_($recv(oldChildren)._size()))._detect_ifNone_((function(i){
  157. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  158. return $core.withContext(function($ctx2) {
  159. //>>excludeEnd("ctx");
  160. $4=$recv(oldChildren)._at_(i);
  161. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  162. $ctx2.sendIdx["at:"]=1;
  163. //>>excludeEnd("ctx");
  164. return $recv($4).__tild_eq($recv(newChildren)._at_(i));
  165. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  166. }, function($ctx2) {$ctx2.fillBlock({i:i},$ctx1,2)});
  167. //>>excludeEnd("ctx");
  168. }),(function(){
  169. throw $early=[aNode];
  170. }));
  171. }
  172. $5=$recv(aNode)._copy();
  173. $recv($5)._dagChildren_(newChildren);
  174. return $recv($5)._yourself();
  175. }
  176. catch(e) {if(e===$early)return e[0]; throw e}
  177. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  178. }, function($ctx1) {$ctx1.fill(self,"visitDagNodeVariantRedux:",{aNode:aNode,newChildren:newChildren,oldChildren:oldChildren},$globals.AbstractDagVisitor)});
  179. //>>excludeEnd("ctx");
  180. },
  181. //>>excludeStart("ide", pragmas.excludeIdeData);
  182. args: ["aNode"],
  183. source: "visitDagNodeVariantRedux: aNode\x0a\x09\x22Immutable-guarded implementation of visitDagNode:.\x0a\x09Visits all children and checks if there were changes.\x0a\x09If not, returns aNode.\x0a\x09If yes, returns copy of aNode with new children.\x22\x0a\x0a\x09| newChildren oldChildren |\x0a\x09oldChildren := aNode dagChildren.\x0a\x09newChildren := self visitAllChildren: aNode.\x0a\x09oldChildren size = newChildren size ifTrue: [\x0a\x09\x09(1 to: oldChildren size) detect: [ :i |\x0a\x09\x09\x09(oldChildren at: i) ~= (newChildren at: i)\x0a\x09\x09] ifNone: [ \x22no change\x22 ^ aNode ] ].\x0a\x09^ aNode copy dagChildren: newChildren; yourself",
  184. referencedClasses: [],
  185. //>>excludeEnd("ide");
  186. messageSends: ["dagChildren", "visitAllChildren:", "ifTrue:", "=", "size", "detect:ifNone:", "to:", "~=", "at:", "dagChildren:", "copy", "yourself"]
  187. }),
  188. $globals.AbstractDagVisitor);
  189. $core.addMethod(
  190. $core.method({
  191. selector: "visitDagNodeVariantSimple:",
  192. protocol: 'visiting',
  193. fn: function (aNode){
  194. var self=this;
  195. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  196. return $core.withContext(function($ctx1) {
  197. //>>excludeEnd("ctx");
  198. self._visitAllChildren_(aNode);
  199. return aNode;
  200. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  201. }, function($ctx1) {$ctx1.fill(self,"visitDagNodeVariantSimple:",{aNode:aNode},$globals.AbstractDagVisitor)});
  202. //>>excludeEnd("ctx");
  203. },
  204. //>>excludeStart("ide", pragmas.excludeIdeData);
  205. args: ["aNode"],
  206. source: "visitDagNodeVariantSimple: aNode\x0a\x09\x22Simple implementation of visitDagNode:.\x0a\x09Visits children, then returns aNode\x22\x0a\x0a\x09self visitAllChildren: aNode.\x0a\x09^ aNode",
  207. referencedClasses: [],
  208. //>>excludeEnd("ide");
  209. messageSends: ["visitAllChildren:"]
  210. }),
  211. $globals.AbstractDagVisitor);
  212. $core.addClass('PathDagVisitor', $globals.AbstractDagVisitor, ['path'], 'Kernel-Dag');
  213. //>>excludeStart("ide", pragmas.excludeIdeData);
  214. $globals.PathDagVisitor.comment="I am base class of `DagNode` visitor.\x0a\x0aI hold the path of ancestors up to actual node\x0ain `self path`.";
  215. //>>excludeEnd("ide");
  216. $core.addMethod(
  217. $core.method({
  218. selector: "initialize",
  219. protocol: 'initialization',
  220. fn: function (){
  221. var self=this;
  222. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  223. return $core.withContext(function($ctx1) {
  224. //>>excludeEnd("ctx");
  225. (
  226. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  227. $ctx1.supercall = true,
  228. //>>excludeEnd("ctx");
  229. ($globals.PathDagVisitor.superclass||$boot.nilAsClass).fn.prototype._initialize.apply($recv(self), []));
  230. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  231. $ctx1.supercall = false;
  232. //>>excludeEnd("ctx");;
  233. self["@path"]=[];
  234. return self;
  235. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  236. }, function($ctx1) {$ctx1.fill(self,"initialize",{},$globals.PathDagVisitor)});
  237. //>>excludeEnd("ctx");
  238. },
  239. //>>excludeStart("ide", pragmas.excludeIdeData);
  240. args: [],
  241. source: "initialize\x0a\x09super initialize.\x0a\x0a\x09path := #()",
  242. referencedClasses: [],
  243. //>>excludeEnd("ide");
  244. messageSends: ["initialize"]
  245. }),
  246. $globals.PathDagVisitor);
  247. $core.addMethod(
  248. $core.method({
  249. selector: "path",
  250. protocol: 'accessing',
  251. fn: function (){
  252. var self=this;
  253. return self["@path"];
  254. },
  255. //>>excludeStart("ide", pragmas.excludeIdeData);
  256. args: [],
  257. source: "path\x0a\x09^ path",
  258. referencedClasses: [],
  259. //>>excludeEnd("ide");
  260. messageSends: []
  261. }),
  262. $globals.PathDagVisitor);
  263. $core.addMethod(
  264. $core.method({
  265. selector: "visit:",
  266. protocol: 'visiting',
  267. fn: function (aNode){
  268. var self=this;
  269. var oldPath,result;
  270. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  271. return $core.withContext(function($ctx1) {
  272. //>>excludeEnd("ctx");
  273. result=aNode;
  274. oldPath=self["@path"];
  275. $recv((function(){
  276. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  277. return $core.withContext(function($ctx2) {
  278. //>>excludeEnd("ctx");
  279. self["@path"]=$recv(self["@path"]).__comma([aNode]);
  280. self["@path"];
  281. result=(
  282. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  283. $ctx2.supercall = true,
  284. //>>excludeEnd("ctx");
  285. ($globals.PathDagVisitor.superclass||$boot.nilAsClass).fn.prototype._visit_.apply($recv(self), [aNode]));
  286. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  287. $ctx2.supercall = false;
  288. //>>excludeEnd("ctx");;
  289. return result;
  290. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  291. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  292. //>>excludeEnd("ctx");
  293. }))._ensure_((function(){
  294. self["@path"]=oldPath;
  295. return self["@path"];
  296. }));
  297. return result;
  298. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  299. }, function($ctx1) {$ctx1.fill(self,"visit:",{aNode:aNode,oldPath:oldPath,result:result},$globals.PathDagVisitor)});
  300. //>>excludeEnd("ctx");
  301. },
  302. //>>excludeStart("ide", pragmas.excludeIdeData);
  303. args: ["aNode"],
  304. source: "visit: aNode\x0a\x09| oldPath result |\x0a\x09result := aNode.\x0a\x09oldPath := path.\x0a\x09[\x0a\x09\x09path := path, {aNode}.\x0a\x09\x09result := super visit: aNode\x0a\x09] ensure: [ path := oldPath ].\x0a\x09^ result",
  305. referencedClasses: [],
  306. //>>excludeEnd("ide");
  307. messageSends: ["ensure:", ",", "visit:"]
  308. }),
  309. $globals.PathDagVisitor);
  310. $core.addMethod(
  311. $core.method({
  312. selector: "visitDagNodeVariantRedux:",
  313. protocol: 'visiting',
  314. fn: function (aNode){
  315. var self=this;
  316. var newNode;
  317. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  318. return $core.withContext(function($ctx1) {
  319. //>>excludeEnd("ctx");
  320. var $1;
  321. newNode=(
  322. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  323. $ctx1.supercall = true,
  324. //>>excludeEnd("ctx");
  325. ($globals.PathDagVisitor.superclass||$boot.nilAsClass).fn.prototype._visitDagNodeVariantRedux_.apply($recv(self), [aNode]));
  326. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  327. $ctx1.supercall = false;
  328. //>>excludeEnd("ctx");;
  329. $1=$recv(aNode).__eq_eq(newNode);
  330. if(!$core.assert($1)){
  331. $recv(self["@path"])._at_put_($recv(self["@path"])._size(),newNode);
  332. }
  333. return newNode;
  334. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  335. }, function($ctx1) {$ctx1.fill(self,"visitDagNodeVariantRedux:",{aNode:aNode,newNode:newNode},$globals.PathDagVisitor)});
  336. //>>excludeEnd("ctx");
  337. },
  338. //>>excludeStart("ide", pragmas.excludeIdeData);
  339. args: ["aNode"],
  340. source: "visitDagNodeVariantRedux: aNode\x0a\x09| newNode |\x0a\x09newNode := super visitDagNodeVariantRedux: aNode.\x0a\x09aNode == newNode ifFalse: [ path at: path size put: newNode ].\x0a\x09^ newNode",
  341. referencedClasses: [],
  342. //>>excludeEnd("ide");
  343. messageSends: ["visitDagNodeVariantRedux:", "ifFalse:", "==", "at:put:", "size"]
  344. }),
  345. $globals.PathDagVisitor);
  346. $core.addClass('DagNode', $globals.Object, [], 'Kernel-Dag');
  347. //>>excludeStart("ide", pragmas.excludeIdeData);
  348. $globals.DagNode.comment="I am the abstract root class of any directed acyclic graph.\x0a\x0aConcrete classes should implement `dagChildren` and `dagChildren:`\x0ato get / set direct successor nodes (aka child nodes / subnodes).";
  349. //>>excludeEnd("ide");
  350. $core.addMethod(
  351. $core.method({
  352. selector: "acceptDagVisitor:",
  353. protocol: 'visiting',
  354. fn: function (aVisitor){
  355. var self=this;
  356. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  357. return $core.withContext(function($ctx1) {
  358. //>>excludeEnd("ctx");
  359. return $recv(aVisitor)._visitDagNode_(self);
  360. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  361. }, function($ctx1) {$ctx1.fill(self,"acceptDagVisitor:",{aVisitor:aVisitor},$globals.DagNode)});
  362. //>>excludeEnd("ctx");
  363. },
  364. //>>excludeStart("ide", pragmas.excludeIdeData);
  365. args: ["aVisitor"],
  366. source: "acceptDagVisitor: aVisitor\x0a\x09^ aVisitor visitDagNode: self",
  367. referencedClasses: [],
  368. //>>excludeEnd("ide");
  369. messageSends: ["visitDagNode:"]
  370. }),
  371. $globals.DagNode);
  372. $core.addMethod(
  373. $core.method({
  374. selector: "allDagChildren",
  375. protocol: 'accessing',
  376. fn: function (){
  377. var self=this;
  378. var allNodes;
  379. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  380. return $core.withContext(function($ctx1) {
  381. //>>excludeEnd("ctx");
  382. var $1;
  383. $1=self._dagChildren();
  384. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  385. $ctx1.sendIdx["dagChildren"]=1;
  386. //>>excludeEnd("ctx");
  387. allNodes=$recv($1)._asSet();
  388. $recv(self._dagChildren())._do_((function(each){
  389. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  390. return $core.withContext(function($ctx2) {
  391. //>>excludeEnd("ctx");
  392. return $recv(allNodes)._addAll_($recv(each)._allDagChildren());
  393. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  394. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  395. //>>excludeEnd("ctx");
  396. }));
  397. return allNodes;
  398. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  399. }, function($ctx1) {$ctx1.fill(self,"allDagChildren",{allNodes:allNodes},$globals.DagNode)});
  400. //>>excludeEnd("ctx");
  401. },
  402. //>>excludeStart("ide", pragmas.excludeIdeData);
  403. args: [],
  404. source: "allDagChildren\x0a\x09| allNodes |\x0a\x09\x0a\x09allNodes := self dagChildren asSet.\x0a\x09self dagChildren do: [ :each | \x0a\x09\x09allNodes addAll: each allDagChildren ].\x0a\x09\x0a\x09^ allNodes",
  405. referencedClasses: [],
  406. //>>excludeEnd("ide");
  407. messageSends: ["asSet", "dagChildren", "do:", "addAll:", "allDagChildren"]
  408. }),
  409. $globals.DagNode);
  410. $core.addMethod(
  411. $core.method({
  412. selector: "dagChildren",
  413. protocol: 'accessing',
  414. fn: function (){
  415. var self=this;
  416. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  417. return $core.withContext(function($ctx1) {
  418. //>>excludeEnd("ctx");
  419. self._subclassResponsibility();
  420. return self;
  421. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  422. }, function($ctx1) {$ctx1.fill(self,"dagChildren",{},$globals.DagNode)});
  423. //>>excludeEnd("ctx");
  424. },
  425. //>>excludeStart("ide", pragmas.excludeIdeData);
  426. args: [],
  427. source: "dagChildren\x0a\x09self subclassResponsibility",
  428. referencedClasses: [],
  429. //>>excludeEnd("ide");
  430. messageSends: ["subclassResponsibility"]
  431. }),
  432. $globals.DagNode);
  433. $core.addMethod(
  434. $core.method({
  435. selector: "dagChildren:",
  436. protocol: 'accessing',
  437. fn: function (aCollection){
  438. var self=this;
  439. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  440. return $core.withContext(function($ctx1) {
  441. //>>excludeEnd("ctx");
  442. self._subclassResponsibility();
  443. return self;
  444. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  445. }, function($ctx1) {$ctx1.fill(self,"dagChildren:",{aCollection:aCollection},$globals.DagNode)});
  446. //>>excludeEnd("ctx");
  447. },
  448. //>>excludeStart("ide", pragmas.excludeIdeData);
  449. args: ["aCollection"],
  450. source: "dagChildren: aCollection\x0a\x09self subclassResponsibility",
  451. referencedClasses: [],
  452. //>>excludeEnd("ide");
  453. messageSends: ["subclassResponsibility"]
  454. }),
  455. $globals.DagNode);
  456. $core.addMethod(
  457. $core.method({
  458. selector: "isDagNode",
  459. protocol: 'testing',
  460. fn: function (){
  461. var self=this;
  462. return true;
  463. },
  464. //>>excludeStart("ide", pragmas.excludeIdeData);
  465. args: [],
  466. source: "isDagNode\x0a\x09^ true",
  467. referencedClasses: [],
  468. //>>excludeEnd("ide");
  469. messageSends: []
  470. }),
  471. $globals.DagNode);
  472. $core.addClass('DagParentNode', $globals.DagNode, ['nodes'], 'Kernel-Dag');
  473. //>>excludeStart("ide", pragmas.excludeIdeData);
  474. $globals.DagParentNode.comment="I am `DagNode` that stores a collection of its children,\x0alazy initialized to empty array.\x0a\x0aI can `addDagChild:` to add a child.";
  475. //>>excludeEnd("ide");
  476. $core.addMethod(
  477. $core.method({
  478. selector: "addDagChild:",
  479. protocol: 'accessing',
  480. fn: function (aDagNode){
  481. var self=this;
  482. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  483. return $core.withContext(function($ctx1) {
  484. //>>excludeEnd("ctx");
  485. $recv(self._dagChildren())._add_(aDagNode);
  486. return self;
  487. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  488. }, function($ctx1) {$ctx1.fill(self,"addDagChild:",{aDagNode:aDagNode},$globals.DagParentNode)});
  489. //>>excludeEnd("ctx");
  490. },
  491. //>>excludeStart("ide", pragmas.excludeIdeData);
  492. args: ["aDagNode"],
  493. source: "addDagChild: aDagNode\x0a\x09self dagChildren add: aDagNode",
  494. referencedClasses: [],
  495. //>>excludeEnd("ide");
  496. messageSends: ["add:", "dagChildren"]
  497. }),
  498. $globals.DagParentNode);
  499. $core.addMethod(
  500. $core.method({
  501. selector: "dagChildren",
  502. protocol: 'accessing',
  503. fn: function (){
  504. var self=this;
  505. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  506. return $core.withContext(function($ctx1) {
  507. //>>excludeEnd("ctx");
  508. var $1,$receiver;
  509. $1=self["@nodes"];
  510. if(($receiver = $1) == null || $receiver.isNil){
  511. self["@nodes"]=$recv($globals.Array)._new();
  512. return self["@nodes"];
  513. } else {
  514. return $1;
  515. }
  516. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  517. }, function($ctx1) {$ctx1.fill(self,"dagChildren",{},$globals.DagParentNode)});
  518. //>>excludeEnd("ctx");
  519. },
  520. //>>excludeStart("ide", pragmas.excludeIdeData);
  521. args: [],
  522. source: "dagChildren\x0a\x09^ nodes ifNil: [ nodes := Array new ]",
  523. referencedClasses: ["Array"],
  524. //>>excludeEnd("ide");
  525. messageSends: ["ifNil:", "new"]
  526. }),
  527. $globals.DagParentNode);
  528. $core.addMethod(
  529. $core.method({
  530. selector: "dagChildren:",
  531. protocol: 'accessing',
  532. fn: function (aCollection){
  533. var self=this;
  534. self["@nodes"]=aCollection;
  535. return self;
  536. },
  537. //>>excludeStart("ide", pragmas.excludeIdeData);
  538. args: ["aCollection"],
  539. source: "dagChildren: aCollection\x0a\x09nodes := aCollection",
  540. referencedClasses: [],
  541. //>>excludeEnd("ide");
  542. messageSends: []
  543. }),
  544. $globals.DagParentNode);
  545. $core.addClass('DagSink', $globals.DagNode, ['nodes'], 'Kernel-Dag');
  546. //>>excludeStart("ide", pragmas.excludeIdeData);
  547. $globals.DagSink.comment="I am `DagNode` with no direct successors.\x0a\x0aSending `dagChildren:` with empty collection is legal.";
  548. //>>excludeEnd("ide");
  549. $core.addMethod(
  550. $core.method({
  551. selector: "dagChildren",
  552. protocol: 'accessing',
  553. fn: function (){
  554. var self=this;
  555. return [];
  556. },
  557. //>>excludeStart("ide", pragmas.excludeIdeData);
  558. args: [],
  559. source: "dagChildren\x0a\x09^ #()",
  560. referencedClasses: [],
  561. //>>excludeEnd("ide");
  562. messageSends: []
  563. }),
  564. $globals.DagSink);
  565. $core.addMethod(
  566. $core.method({
  567. selector: "dagChildren:",
  568. protocol: 'accessing',
  569. fn: function (aCollection){
  570. var self=this;
  571. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  572. return $core.withContext(function($ctx1) {
  573. //>>excludeEnd("ctx");
  574. $recv(aCollection)._ifNotEmpty_((function(){
  575. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  576. return $core.withContext(function($ctx2) {
  577. //>>excludeEnd("ctx");
  578. return self._error_("A DagSink cannot have children.");
  579. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  580. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  581. //>>excludeEnd("ctx");
  582. }));
  583. return self;
  584. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  585. }, function($ctx1) {$ctx1.fill(self,"dagChildren:",{aCollection:aCollection},$globals.DagSink)});
  586. //>>excludeEnd("ctx");
  587. },
  588. //>>excludeStart("ide", pragmas.excludeIdeData);
  589. args: ["aCollection"],
  590. source: "dagChildren: aCollection\x0a\x09aCollection ifNotEmpty: [ self error: 'A DagSink cannot have children.' ]",
  591. referencedClasses: [],
  592. //>>excludeEnd("ide");
  593. messageSends: ["ifNotEmpty:", "error:"]
  594. }),
  595. $globals.DagSink);
  596. $core.addMethod(
  597. $core.method({
  598. selector: "isDagNode",
  599. protocol: '*Kernel-Dag',
  600. fn: function (){
  601. var self=this;
  602. return false;
  603. },
  604. //>>excludeStart("ide", pragmas.excludeIdeData);
  605. args: [],
  606. source: "isDagNode\x0a\x09^ false",
  607. referencedClasses: [],
  608. //>>excludeEnd("ide");
  609. messageSends: []
  610. }),
  611. $globals.Object);
  612. });