Kernel-Dag.js 24 KB

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