Kernel-Dag.js 21 KB

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