Kernel-Dag.js 21 KB

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