Kernel-Dag.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  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;
  248. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  249. return $core.withContext(function($ctx1) {
  250. //>>excludeEnd("ctx");
  251. var $1;
  252. var $early={};
  253. try {
  254. oldPath=self["@path"];
  255. $recv((function(){
  256. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  257. return $core.withContext(function($ctx2) {
  258. //>>excludeEnd("ctx");
  259. self["@path"]=$recv(self["@path"]).__comma([aNode]);
  260. self["@path"];
  261. $1=(
  262. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  263. $ctx2.supercall = true,
  264. //>>excludeEnd("ctx");
  265. ($globals.PathDagVisitor.superclass||$boot.nilAsClass).fn.prototype._visit_.apply($recv(self), [aNode]));
  266. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  267. $ctx2.supercall = false;
  268. //>>excludeEnd("ctx");;
  269. throw $early=[$1];
  270. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  271. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  272. //>>excludeEnd("ctx");
  273. }))._ensure_((function(){
  274. self["@path"]=oldPath;
  275. return self["@path"];
  276. }));
  277. return self;
  278. }
  279. catch(e) {if(e===$early)return e[0]; throw e}
  280. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  281. }, function($ctx1) {$ctx1.fill(self,"visit:",{aNode:aNode,oldPath:oldPath},$globals.PathDagVisitor)});
  282. //>>excludeEnd("ctx");
  283. },
  284. //>>excludeStart("ide", pragmas.excludeIdeData);
  285. args: ["aNode"],
  286. source: "visit: aNode\x0a\x09| oldPath |\x0a\x09oldPath := path.\x0a\x09[\x0a\x09\x09path := path, {aNode}.\x0a\x09\x09^ super visit: aNode\x0a\x09] ensure: [ path := oldPath ]",
  287. referencedClasses: [],
  288. //>>excludeEnd("ide");
  289. messageSends: ["ensure:", ",", "visit:"]
  290. }),
  291. $globals.PathDagVisitor);
  292. $core.addMethod(
  293. $core.method({
  294. selector: "visitDagNodeVariantRedux:",
  295. protocol: 'visiting',
  296. fn: function (aNode){
  297. var self=this;
  298. var newNode;
  299. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  300. return $core.withContext(function($ctx1) {
  301. //>>excludeEnd("ctx");
  302. var $1;
  303. newNode=(
  304. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  305. $ctx1.supercall = true,
  306. //>>excludeEnd("ctx");
  307. ($globals.PathDagVisitor.superclass||$boot.nilAsClass).fn.prototype._visitDagNodeVariantRedux_.apply($recv(self), [aNode]));
  308. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  309. $ctx1.supercall = false;
  310. //>>excludeEnd("ctx");;
  311. $1=$recv(aNode).__eq_eq(newNode);
  312. if(!$core.assert($1)){
  313. $recv(self["@path"])._at_put_($recv(self["@path"])._size(),newNode);
  314. };
  315. return newNode;
  316. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  317. }, function($ctx1) {$ctx1.fill(self,"visitDagNodeVariantRedux:",{aNode:aNode,newNode:newNode},$globals.PathDagVisitor)});
  318. //>>excludeEnd("ctx");
  319. },
  320. //>>excludeStart("ide", pragmas.excludeIdeData);
  321. args: ["aNode"],
  322. source: "visitDagNodeVariantRedux: aNode\x0a\x09| newNode |\x0a\x09newNode := super visitDagNodeVariantRedux: aNode.\x0a\x09aNode == newNode ifFalse: [ path at: path size put: newNode ].\x0a\x09^ newNode",
  323. referencedClasses: [],
  324. //>>excludeEnd("ide");
  325. messageSends: ["visitDagNodeVariantRedux:", "ifFalse:", "==", "at:put:", "size"]
  326. }),
  327. $globals.PathDagVisitor);
  328. $core.addClass('DagNode', $globals.Object, [], 'Kernel-Dag');
  329. //>>excludeStart("ide", pragmas.excludeIdeData);
  330. $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).";
  331. //>>excludeEnd("ide");
  332. $core.addMethod(
  333. $core.method({
  334. selector: "acceptDagVisitor:",
  335. protocol: 'visiting',
  336. fn: function (aVisitor){
  337. var self=this;
  338. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  339. return $core.withContext(function($ctx1) {
  340. //>>excludeEnd("ctx");
  341. return $recv(aVisitor)._visitDagNode_(self);
  342. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  343. }, function($ctx1) {$ctx1.fill(self,"acceptDagVisitor:",{aVisitor:aVisitor},$globals.DagNode)});
  344. //>>excludeEnd("ctx");
  345. },
  346. //>>excludeStart("ide", pragmas.excludeIdeData);
  347. args: ["aVisitor"],
  348. source: "acceptDagVisitor: aVisitor\x0a\x09^ aVisitor visitDagNode: self",
  349. referencedClasses: [],
  350. //>>excludeEnd("ide");
  351. messageSends: ["visitDagNode:"]
  352. }),
  353. $globals.DagNode);
  354. $core.addMethod(
  355. $core.method({
  356. selector: "allDagChildren",
  357. protocol: 'accessing',
  358. fn: function (){
  359. var self=this;
  360. var allNodes;
  361. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  362. return $core.withContext(function($ctx1) {
  363. //>>excludeEnd("ctx");
  364. var $1;
  365. $1=self._dagChildren();
  366. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  367. $ctx1.sendIdx["dagChildren"]=1;
  368. //>>excludeEnd("ctx");
  369. allNodes=$recv($1)._asSet();
  370. $recv(self._dagChildren())._do_((function(each){
  371. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  372. return $core.withContext(function($ctx2) {
  373. //>>excludeEnd("ctx");
  374. return $recv(allNodes)._addAll_($recv(each)._allDagChildren());
  375. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  376. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  377. //>>excludeEnd("ctx");
  378. }));
  379. return allNodes;
  380. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  381. }, function($ctx1) {$ctx1.fill(self,"allDagChildren",{allNodes:allNodes},$globals.DagNode)});
  382. //>>excludeEnd("ctx");
  383. },
  384. //>>excludeStart("ide", pragmas.excludeIdeData);
  385. args: [],
  386. 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",
  387. referencedClasses: [],
  388. //>>excludeEnd("ide");
  389. messageSends: ["asSet", "dagChildren", "do:", "addAll:", "allDagChildren"]
  390. }),
  391. $globals.DagNode);
  392. $core.addMethod(
  393. $core.method({
  394. selector: "dagChildren",
  395. protocol: 'accessing',
  396. fn: function (){
  397. var self=this;
  398. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  399. return $core.withContext(function($ctx1) {
  400. //>>excludeEnd("ctx");
  401. self._subclassResponsibility();
  402. return self;
  403. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  404. }, function($ctx1) {$ctx1.fill(self,"dagChildren",{},$globals.DagNode)});
  405. //>>excludeEnd("ctx");
  406. },
  407. //>>excludeStart("ide", pragmas.excludeIdeData);
  408. args: [],
  409. source: "dagChildren\x0a\x09self subclassResponsibility",
  410. referencedClasses: [],
  411. //>>excludeEnd("ide");
  412. messageSends: ["subclassResponsibility"]
  413. }),
  414. $globals.DagNode);
  415. $core.addMethod(
  416. $core.method({
  417. selector: "dagChildren:",
  418. protocol: 'accessing',
  419. fn: function (aCollection){
  420. var self=this;
  421. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  422. return $core.withContext(function($ctx1) {
  423. //>>excludeEnd("ctx");
  424. self._subclassResponsibility();
  425. return self;
  426. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  427. }, function($ctx1) {$ctx1.fill(self,"dagChildren:",{aCollection:aCollection},$globals.DagNode)});
  428. //>>excludeEnd("ctx");
  429. },
  430. //>>excludeStart("ide", pragmas.excludeIdeData);
  431. args: ["aCollection"],
  432. source: "dagChildren: aCollection\x0a\x09self subclassResponsibility",
  433. referencedClasses: [],
  434. //>>excludeEnd("ide");
  435. messageSends: ["subclassResponsibility"]
  436. }),
  437. $globals.DagNode);
  438. $core.addMethod(
  439. $core.method({
  440. selector: "isDagNode",
  441. protocol: 'testing',
  442. fn: function (){
  443. var self=this;
  444. return true;
  445. },
  446. //>>excludeStart("ide", pragmas.excludeIdeData);
  447. args: [],
  448. source: "isDagNode\x0a\x09^ true",
  449. referencedClasses: [],
  450. //>>excludeEnd("ide");
  451. messageSends: []
  452. }),
  453. $globals.DagNode);
  454. $core.addClass('DagParentNode', $globals.DagNode, ['nodes'], 'Kernel-Dag');
  455. //>>excludeStart("ide", pragmas.excludeIdeData);
  456. $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.";
  457. //>>excludeEnd("ide");
  458. $core.addMethod(
  459. $core.method({
  460. selector: "addDagChild:",
  461. protocol: 'accessing',
  462. fn: function (aDagNode){
  463. var self=this;
  464. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  465. return $core.withContext(function($ctx1) {
  466. //>>excludeEnd("ctx");
  467. $recv(self._dagChildren())._add_(aDagNode);
  468. return self;
  469. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  470. }, function($ctx1) {$ctx1.fill(self,"addDagChild:",{aDagNode:aDagNode},$globals.DagParentNode)});
  471. //>>excludeEnd("ctx");
  472. },
  473. //>>excludeStart("ide", pragmas.excludeIdeData);
  474. args: ["aDagNode"],
  475. source: "addDagChild: aDagNode\x0a\x09self dagChildren add: aDagNode",
  476. referencedClasses: [],
  477. //>>excludeEnd("ide");
  478. messageSends: ["add:", "dagChildren"]
  479. }),
  480. $globals.DagParentNode);
  481. $core.addMethod(
  482. $core.method({
  483. selector: "dagChildren",
  484. protocol: 'accessing',
  485. fn: function (){
  486. var self=this;
  487. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  488. return $core.withContext(function($ctx1) {
  489. //>>excludeEnd("ctx");
  490. var $1,$receiver;
  491. $1=self["@nodes"];
  492. if(($receiver = $1) == null || $receiver.isNil){
  493. self["@nodes"]=$recv($globals.Array)._new();
  494. return self["@nodes"];
  495. } else {
  496. return $1;
  497. };
  498. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  499. }, function($ctx1) {$ctx1.fill(self,"dagChildren",{},$globals.DagParentNode)});
  500. //>>excludeEnd("ctx");
  501. },
  502. //>>excludeStart("ide", pragmas.excludeIdeData);
  503. args: [],
  504. source: "dagChildren\x0a\x09^ nodes ifNil: [ nodes := Array new ]",
  505. referencedClasses: ["Array"],
  506. //>>excludeEnd("ide");
  507. messageSends: ["ifNil:", "new"]
  508. }),
  509. $globals.DagParentNode);
  510. $core.addMethod(
  511. $core.method({
  512. selector: "dagChildren:",
  513. protocol: 'accessing',
  514. fn: function (aCollection){
  515. var self=this;
  516. self["@nodes"]=aCollection;
  517. return self;
  518. },
  519. //>>excludeStart("ide", pragmas.excludeIdeData);
  520. args: ["aCollection"],
  521. source: "dagChildren: aCollection\x0a\x09nodes := aCollection",
  522. referencedClasses: [],
  523. //>>excludeEnd("ide");
  524. messageSends: []
  525. }),
  526. $globals.DagParentNode);
  527. $core.addClass('DagSink', $globals.DagNode, ['nodes'], 'Kernel-Dag');
  528. //>>excludeStart("ide", pragmas.excludeIdeData);
  529. $globals.DagSink.comment="I am `DagNode` with no direct successors.\x0a\x0aSending `dagChildren:` with empty collection is legal.";
  530. //>>excludeEnd("ide");
  531. $core.addMethod(
  532. $core.method({
  533. selector: "dagChildren",
  534. protocol: 'accessing',
  535. fn: function (){
  536. var self=this;
  537. return [];
  538. },
  539. //>>excludeStart("ide", pragmas.excludeIdeData);
  540. args: [],
  541. source: "dagChildren\x0a\x09^ #()",
  542. referencedClasses: [],
  543. //>>excludeEnd("ide");
  544. messageSends: []
  545. }),
  546. $globals.DagSink);
  547. $core.addMethod(
  548. $core.method({
  549. selector: "dagChildren:",
  550. protocol: 'accessing',
  551. fn: function (aCollection){
  552. var self=this;
  553. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  554. return $core.withContext(function($ctx1) {
  555. //>>excludeEnd("ctx");
  556. $recv(aCollection)._ifNotEmpty_((function(){
  557. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  558. return $core.withContext(function($ctx2) {
  559. //>>excludeEnd("ctx");
  560. return self._error_("A DagSink cannot have children.");
  561. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  562. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  563. //>>excludeEnd("ctx");
  564. }));
  565. return self;
  566. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  567. }, function($ctx1) {$ctx1.fill(self,"dagChildren:",{aCollection:aCollection},$globals.DagSink)});
  568. //>>excludeEnd("ctx");
  569. },
  570. //>>excludeStart("ide", pragmas.excludeIdeData);
  571. args: ["aCollection"],
  572. source: "dagChildren: aCollection\x0a\x09aCollection ifNotEmpty: [ self error: 'A DagSink cannot have children.' ]",
  573. referencedClasses: [],
  574. //>>excludeEnd("ide");
  575. messageSends: ["ifNotEmpty:", "error:"]
  576. }),
  577. $globals.DagSink);
  578. $core.addMethod(
  579. $core.method({
  580. selector: "isDagNode",
  581. protocol: '*Kernel-Dag',
  582. fn: function (){
  583. var self=this;
  584. return false;
  585. },
  586. //>>excludeStart("ide", pragmas.excludeIdeData);
  587. args: [],
  588. source: "isDagNode\x0a\x09^ false",
  589. referencedClasses: [],
  590. //>>excludeEnd("ide");
  591. messageSends: []
  592. }),
  593. $globals.Object);
  594. });