1
0

Kernel-Dag.js 21 KB

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