Kernel-Dag.js 20 KB

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