Kernel-Dag.js 21 KB

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