Kernel-Dag.js 21 KB

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