Kernel-Dag.js 20 KB

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