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