Kernel-Dag.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  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, "Kernel-Dag");
  185. $core.setSlots($globals.PathDagVisitor, ["path"]);
  186. //>>excludeStart("ide", pragmas.excludeIdeData);
  187. $globals.PathDagVisitor.comment="I am base class of `DagNode` visitor.\x0a\x0aI hold the path of ancestors up to actual node\x0ain `self path`.";
  188. //>>excludeEnd("ide");
  189. $core.addMethod(
  190. $core.method({
  191. selector: "initialize",
  192. protocol: "initialization",
  193. //>>excludeStart("ide", pragmas.excludeIdeData);
  194. args: [],
  195. source: "initialize\x0a\x09super initialize.\x0a\x0a\x09path := #()",
  196. referencedClasses: [],
  197. //>>excludeEnd("ide");
  198. pragmas: [],
  199. messageSends: ["initialize"]
  200. }, function ($methodClass){ return function (){
  201. var self=this,$self=this;
  202. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  203. return $core.withContext(function($ctx1) {
  204. //>>excludeEnd("ctx");
  205. [(
  206. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  207. $ctx1.supercall = true,
  208. //>>excludeEnd("ctx");
  209. ($methodClass.superclass||$boot.nilAsClass).fn.prototype._initialize.call($self))
  210. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  211. ,$ctx1.supercall = false
  212. //>>excludeEnd("ctx");
  213. ][0];
  214. $self.path=[];
  215. return self;
  216. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  217. }, function($ctx1) {$ctx1.fill(self,"initialize",{})});
  218. //>>excludeEnd("ctx");
  219. }; }),
  220. $globals.PathDagVisitor);
  221. $core.addMethod(
  222. $core.method({
  223. selector: "path",
  224. protocol: "accessing",
  225. //>>excludeStart("ide", pragmas.excludeIdeData);
  226. args: [],
  227. source: "path\x0a\x09^ path",
  228. referencedClasses: [],
  229. //>>excludeEnd("ide");
  230. pragmas: [],
  231. messageSends: []
  232. }, function ($methodClass){ return function (){
  233. var self=this,$self=this;
  234. return $self.path;
  235. }; }),
  236. $globals.PathDagVisitor);
  237. $core.addMethod(
  238. $core.method({
  239. selector: "visit:",
  240. protocol: "visiting",
  241. //>>excludeStart("ide", pragmas.excludeIdeData);
  242. args: ["aNode"],
  243. 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",
  244. referencedClasses: [],
  245. //>>excludeEnd("ide");
  246. pragmas: [],
  247. messageSends: ["ensure:", ",", "visit:"]
  248. }, function ($methodClass){ return function (aNode){
  249. var self=this,$self=this;
  250. var oldPath,result;
  251. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  252. return $core.withContext(function($ctx1) {
  253. //>>excludeEnd("ctx");
  254. result=aNode;
  255. oldPath=$self.path;
  256. $recv((function(){
  257. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  258. return $core.withContext(function($ctx2) {
  259. //>>excludeEnd("ctx");
  260. $self.path=$recv($self.path).__comma([aNode]);
  261. result=[(
  262. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  263. $ctx2.supercall = true,
  264. //>>excludeEnd("ctx");
  265. ($methodClass.superclass||$boot.nilAsClass).fn.prototype._visit_.call($self,aNode))
  266. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  267. ,$ctx2.supercall = false
  268. //>>excludeEnd("ctx");
  269. ][0];
  270. return result;
  271. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  272. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  273. //>>excludeEnd("ctx");
  274. }))._ensure_((function(){
  275. $self.path=oldPath;
  276. return $self.path;
  277. }));
  278. return result;
  279. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  280. }, function($ctx1) {$ctx1.fill(self,"visit:",{aNode:aNode,oldPath:oldPath,result:result})});
  281. //>>excludeEnd("ctx");
  282. }; }),
  283. $globals.PathDagVisitor);
  284. $core.addMethod(
  285. $core.method({
  286. selector: "visitDagNodeVariantRedux:",
  287. protocol: "visiting",
  288. //>>excludeStart("ide", pragmas.excludeIdeData);
  289. args: ["aNode"],
  290. source: "visitDagNodeVariantRedux: aNode\x0a\x09| newNode |\x0a\x09newNode := super visitDagNodeVariantRedux: aNode.\x0a\x09aNode == newNode ifFalse: [ path at: path size put: newNode ].\x0a\x09^ newNode",
  291. referencedClasses: [],
  292. //>>excludeEnd("ide");
  293. pragmas: [],
  294. messageSends: ["visitDagNodeVariantRedux:", "ifFalse:", "==", "at:put:", "size"]
  295. }, function ($methodClass){ return function (aNode){
  296. var self=this,$self=this;
  297. var newNode;
  298. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  299. return $core.withContext(function($ctx1) {
  300. //>>excludeEnd("ctx");
  301. newNode=[(
  302. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  303. $ctx1.supercall = true,
  304. //>>excludeEnd("ctx");
  305. ($methodClass.superclass||$boot.nilAsClass).fn.prototype._visitDagNodeVariantRedux_.call($self,aNode))
  306. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  307. ,$ctx1.supercall = false
  308. //>>excludeEnd("ctx");
  309. ][0];
  310. if(!$core.assert($recv(aNode).__eq_eq(newNode))){
  311. $recv($self.path)._at_put_($recv($self.path)._size(),newNode);
  312. }
  313. return newNode;
  314. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  315. }, function($ctx1) {$ctx1.fill(self,"visitDagNodeVariantRedux:",{aNode:aNode,newNode:newNode})});
  316. //>>excludeEnd("ctx");
  317. }; }),
  318. $globals.PathDagVisitor);
  319. $core.addClass("DagNode", $globals.Object, "Kernel-Dag");
  320. //>>excludeStart("ide", pragmas.excludeIdeData);
  321. $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).";
  322. //>>excludeEnd("ide");
  323. $core.addMethod(
  324. $core.method({
  325. selector: "acceptDagVisitor:",
  326. protocol: "visiting",
  327. //>>excludeStart("ide", pragmas.excludeIdeData);
  328. args: ["aVisitor"],
  329. source: "acceptDagVisitor: aVisitor\x0a\x09^ aVisitor visitDagNode: self",
  330. referencedClasses: [],
  331. //>>excludeEnd("ide");
  332. pragmas: [],
  333. messageSends: ["visitDagNode:"]
  334. }, function ($methodClass){ return function (aVisitor){
  335. var self=this,$self=this;
  336. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  337. return $core.withContext(function($ctx1) {
  338. //>>excludeEnd("ctx");
  339. return $recv(aVisitor)._visitDagNode_(self);
  340. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  341. }, function($ctx1) {$ctx1.fill(self,"acceptDagVisitor:",{aVisitor:aVisitor})});
  342. //>>excludeEnd("ctx");
  343. }; }),
  344. $globals.DagNode);
  345. $core.addMethod(
  346. $core.method({
  347. selector: "allDagChildren",
  348. protocol: "accessing",
  349. //>>excludeStart("ide", pragmas.excludeIdeData);
  350. args: [],
  351. 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",
  352. referencedClasses: [],
  353. //>>excludeEnd("ide");
  354. pragmas: [],
  355. messageSends: ["asSet", "dagChildren", "do:", "addAll:", "allDagChildren"]
  356. }, function ($methodClass){ return function (){
  357. var self=this,$self=this;
  358. var allNodes;
  359. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  360. return $core.withContext(function($ctx1) {
  361. //>>excludeEnd("ctx");
  362. allNodes=$recv([$self._dagChildren()
  363. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  364. ,$ctx1.sendIdx["dagChildren"]=1
  365. //>>excludeEnd("ctx");
  366. ][0])._asSet();
  367. $recv($self._dagChildren())._do_((function(each){
  368. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  369. return $core.withContext(function($ctx2) {
  370. //>>excludeEnd("ctx");
  371. return $recv(allNodes)._addAll_($recv(each)._allDagChildren());
  372. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  373. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  374. //>>excludeEnd("ctx");
  375. }));
  376. return allNodes;
  377. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  378. }, function($ctx1) {$ctx1.fill(self,"allDagChildren",{allNodes:allNodes})});
  379. //>>excludeEnd("ctx");
  380. }; }),
  381. $globals.DagNode);
  382. $core.addMethod(
  383. $core.method({
  384. selector: "dagChildren",
  385. protocol: "accessing",
  386. //>>excludeStart("ide", pragmas.excludeIdeData);
  387. args: [],
  388. source: "dagChildren\x0a\x09self subclassResponsibility",
  389. referencedClasses: [],
  390. //>>excludeEnd("ide");
  391. pragmas: [],
  392. messageSends: ["subclassResponsibility"]
  393. }, function ($methodClass){ return function (){
  394. var self=this,$self=this;
  395. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  396. return $core.withContext(function($ctx1) {
  397. //>>excludeEnd("ctx");
  398. $self._subclassResponsibility();
  399. return self;
  400. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  401. }, function($ctx1) {$ctx1.fill(self,"dagChildren",{})});
  402. //>>excludeEnd("ctx");
  403. }; }),
  404. $globals.DagNode);
  405. $core.addMethod(
  406. $core.method({
  407. selector: "dagChildren:",
  408. protocol: "accessing",
  409. //>>excludeStart("ide", pragmas.excludeIdeData);
  410. args: ["aCollection"],
  411. source: "dagChildren: aCollection\x0a\x09self subclassResponsibility",
  412. referencedClasses: [],
  413. //>>excludeEnd("ide");
  414. pragmas: [],
  415. messageSends: ["subclassResponsibility"]
  416. }, function ($methodClass){ return function (aCollection){
  417. var self=this,$self=this;
  418. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  419. return $core.withContext(function($ctx1) {
  420. //>>excludeEnd("ctx");
  421. $self._subclassResponsibility();
  422. return self;
  423. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  424. }, function($ctx1) {$ctx1.fill(self,"dagChildren:",{aCollection:aCollection})});
  425. //>>excludeEnd("ctx");
  426. }; }),
  427. $globals.DagNode);
  428. $core.addMethod(
  429. $core.method({
  430. selector: "isDagNode",
  431. protocol: "testing",
  432. //>>excludeStart("ide", pragmas.excludeIdeData);
  433. args: [],
  434. source: "isDagNode\x0a\x09^ true",
  435. referencedClasses: [],
  436. //>>excludeEnd("ide");
  437. pragmas: [],
  438. messageSends: []
  439. }, function ($methodClass){ return function (){
  440. var self=this,$self=this;
  441. return true;
  442. }; }),
  443. $globals.DagNode);
  444. $core.addClass("DagParentNode", $globals.DagNode, "Kernel-Dag");
  445. $core.setSlots($globals.DagParentNode, ["nodes"]);
  446. //>>excludeStart("ide", pragmas.excludeIdeData);
  447. $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.";
  448. //>>excludeEnd("ide");
  449. $core.addMethod(
  450. $core.method({
  451. selector: "addDagChild:",
  452. protocol: "accessing",
  453. //>>excludeStart("ide", pragmas.excludeIdeData);
  454. args: ["aDagNode"],
  455. source: "addDagChild: aDagNode\x0a\x09self dagChildren add: aDagNode",
  456. referencedClasses: [],
  457. //>>excludeEnd("ide");
  458. pragmas: [],
  459. messageSends: ["add:", "dagChildren"]
  460. }, function ($methodClass){ return function (aDagNode){
  461. var self=this,$self=this;
  462. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  463. return $core.withContext(function($ctx1) {
  464. //>>excludeEnd("ctx");
  465. $recv($self._dagChildren())._add_(aDagNode);
  466. return self;
  467. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  468. }, function($ctx1) {$ctx1.fill(self,"addDagChild:",{aDagNode:aDagNode})});
  469. //>>excludeEnd("ctx");
  470. }; }),
  471. $globals.DagParentNode);
  472. $core.addMethod(
  473. $core.method({
  474. selector: "dagChildren",
  475. protocol: "accessing",
  476. //>>excludeStart("ide", pragmas.excludeIdeData);
  477. args: [],
  478. source: "dagChildren\x0a\x09^ nodes ifNil: [ nodes := Array new ]",
  479. referencedClasses: ["Array"],
  480. //>>excludeEnd("ide");
  481. pragmas: [],
  482. messageSends: ["ifNil:", "new"]
  483. }, function ($methodClass){ return function (){
  484. var self=this,$self=this;
  485. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  486. return $core.withContext(function($ctx1) {
  487. //>>excludeEnd("ctx");
  488. var $1;
  489. $1=$self.nodes;
  490. if($1 == null || $1.a$nil){
  491. $self.nodes=$recv($globals.Array)._new();
  492. return $self.nodes;
  493. } else {
  494. return $1;
  495. }
  496. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  497. }, function($ctx1) {$ctx1.fill(self,"dagChildren",{})});
  498. //>>excludeEnd("ctx");
  499. }; }),
  500. $globals.DagParentNode);
  501. $core.addMethod(
  502. $core.method({
  503. selector: "dagChildren:",
  504. protocol: "accessing",
  505. //>>excludeStart("ide", pragmas.excludeIdeData);
  506. args: ["aCollection"],
  507. source: "dagChildren: aCollection\x0a\x09nodes := aCollection",
  508. referencedClasses: [],
  509. //>>excludeEnd("ide");
  510. pragmas: [],
  511. messageSends: []
  512. }, function ($methodClass){ return function (aCollection){
  513. var self=this,$self=this;
  514. $self.nodes=aCollection;
  515. return self;
  516. }; }),
  517. $globals.DagParentNode);
  518. $core.addClass("DagSink", $globals.DagNode, "Kernel-Dag");
  519. //>>excludeStart("ide", pragmas.excludeIdeData);
  520. $globals.DagSink.comment="I am `DagNode` with no direct successors.\x0a\x0aSending `dagChildren:` with empty collection is legal.";
  521. //>>excludeEnd("ide");
  522. $core.addTrait("TDagSink", "Kernel-Dag");
  523. $core.addMethod(
  524. $core.method({
  525. selector: "dagChildren",
  526. protocol: "accessing",
  527. //>>excludeStart("ide", pragmas.excludeIdeData);
  528. args: [],
  529. source: "dagChildren\x0a\x09^ #()",
  530. referencedClasses: [],
  531. //>>excludeEnd("ide");
  532. pragmas: [],
  533. messageSends: []
  534. }, function ($methodClass){ return function (){
  535. var self=this,$self=this;
  536. return [];
  537. }; }),
  538. $globals.TDagSink);
  539. $core.addMethod(
  540. $core.method({
  541. selector: "dagChildren:",
  542. protocol: "accessing",
  543. //>>excludeStart("ide", pragmas.excludeIdeData);
  544. args: ["aCollection"],
  545. source: "dagChildren: aCollection\x0a\x09aCollection ifNotEmpty: [ self error: 'A DagSink cannot have children.' ]",
  546. referencedClasses: [],
  547. //>>excludeEnd("ide");
  548. pragmas: [],
  549. messageSends: ["ifNotEmpty:", "error:"]
  550. }, function ($methodClass){ return function (aCollection){
  551. var self=this,$self=this;
  552. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  553. return $core.withContext(function($ctx1) {
  554. //>>excludeEnd("ctx");
  555. $recv(aCollection)._ifNotEmpty_((function(){
  556. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  557. return $core.withContext(function($ctx2) {
  558. //>>excludeEnd("ctx");
  559. return $self._error_("A DagSink cannot have children.");
  560. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  561. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  562. //>>excludeEnd("ctx");
  563. }));
  564. return self;
  565. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  566. }, function($ctx1) {$ctx1.fill(self,"dagChildren:",{aCollection:aCollection})});
  567. //>>excludeEnd("ctx");
  568. }; }),
  569. $globals.TDagSink);
  570. $core.addTrait("TDerivedDagChildren", "Kernel-Dag");
  571. $core.addMethod(
  572. $core.method({
  573. selector: "addDagChild:",
  574. protocol: "accessing",
  575. //>>excludeStart("ide", pragmas.excludeIdeData);
  576. args: ["aDagNode"],
  577. source: "addDagChild: aDagNode\x0a\x09self error: 'Cannot add child for a TDerivedChildren.'",
  578. referencedClasses: [],
  579. //>>excludeEnd("ide");
  580. pragmas: [],
  581. messageSends: ["error:"]
  582. }, function ($methodClass){ return function (aDagNode){
  583. var self=this,$self=this;
  584. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  585. return $core.withContext(function($ctx1) {
  586. //>>excludeEnd("ctx");
  587. $self._error_("Cannot add child for a TDerivedChildren.");
  588. return self;
  589. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  590. }, function($ctx1) {$ctx1.fill(self,"addDagChild:",{aDagNode:aDagNode})});
  591. //>>excludeEnd("ctx");
  592. }; }),
  593. $globals.TDerivedDagChildren);
  594. $core.addMethod(
  595. $core.method({
  596. selector: "dagChildren",
  597. protocol: "accessing",
  598. //>>excludeStart("ide", pragmas.excludeIdeData);
  599. args: [],
  600. source: "dagChildren\x0a\x09self subclassResponsibility",
  601. referencedClasses: [],
  602. //>>excludeEnd("ide");
  603. pragmas: [],
  604. messageSends: ["subclassResponsibility"]
  605. }, function ($methodClass){ return function (){
  606. var self=this,$self=this;
  607. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  608. return $core.withContext(function($ctx1) {
  609. //>>excludeEnd("ctx");
  610. $self._subclassResponsibility();
  611. return self;
  612. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  613. }, function($ctx1) {$ctx1.fill(self,"dagChildren",{})});
  614. //>>excludeEnd("ctx");
  615. }; }),
  616. $globals.TDerivedDagChildren);
  617. $core.addMethod(
  618. $core.method({
  619. selector: "dagChildren:",
  620. protocol: "accessing",
  621. //>>excludeStart("ide", pragmas.excludeIdeData);
  622. args: ["aCollection"],
  623. source: "dagChildren: aCollection\x0a\x09self error: 'Cannot set children of a TDerivedChildren.'",
  624. referencedClasses: [],
  625. //>>excludeEnd("ide");
  626. pragmas: [],
  627. messageSends: ["error:"]
  628. }, function ($methodClass){ return function (aCollection){
  629. var self=this,$self=this;
  630. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  631. return $core.withContext(function($ctx1) {
  632. //>>excludeEnd("ctx");
  633. $self._error_("Cannot set children of a TDerivedChildren.");
  634. return self;
  635. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  636. }, function($ctx1) {$ctx1.fill(self,"dagChildren:",{aCollection:aCollection})});
  637. //>>excludeEnd("ctx");
  638. }; }),
  639. $globals.TDerivedDagChildren);
  640. $core.addTrait("TSingleDagChild", "Kernel-Dag");
  641. $core.addMethod(
  642. $core.method({
  643. selector: "dagChild",
  644. protocol: "accessing",
  645. //>>excludeStart("ide", pragmas.excludeIdeData);
  646. args: [],
  647. source: "dagChild\x0a\x09self subclassResponsibility",
  648. referencedClasses: [],
  649. //>>excludeEnd("ide");
  650. pragmas: [],
  651. messageSends: ["subclassResponsibility"]
  652. }, function ($methodClass){ return function (){
  653. var self=this,$self=this;
  654. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  655. return $core.withContext(function($ctx1) {
  656. //>>excludeEnd("ctx");
  657. $self._subclassResponsibility();
  658. return self;
  659. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  660. }, function($ctx1) {$ctx1.fill(self,"dagChild",{})});
  661. //>>excludeEnd("ctx");
  662. }; }),
  663. $globals.TSingleDagChild);
  664. $core.addMethod(
  665. $core.method({
  666. selector: "dagChildren",
  667. protocol: "accessing",
  668. //>>excludeStart("ide", pragmas.excludeIdeData);
  669. args: [],
  670. source: "dagChildren\x0a\x09^ { self dagChild }",
  671. referencedClasses: [],
  672. //>>excludeEnd("ide");
  673. pragmas: [],
  674. messageSends: ["dagChild"]
  675. }, function ($methodClass){ return function (){
  676. var self=this,$self=this;
  677. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  678. return $core.withContext(function($ctx1) {
  679. //>>excludeEnd("ctx");
  680. return [$self._dagChild()];
  681. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  682. }, function($ctx1) {$ctx1.fill(self,"dagChildren",{})});
  683. //>>excludeEnd("ctx");
  684. }; }),
  685. $globals.TSingleDagChild);
  686. $core.setTraitComposition([{trait: $globals.TDerivedDagChildren}], $globals.TDagSink);
  687. $core.setTraitComposition([{trait: $globals.TDerivedDagChildren}], $globals.TSingleDagChild);
  688. $core.setTraitComposition([{trait: $globals.TDagSink}], $globals.DagSink);
  689. $core.addMethod(
  690. $core.method({
  691. selector: "isDagNode",
  692. protocol: "*Kernel-Dag",
  693. //>>excludeStart("ide", pragmas.excludeIdeData);
  694. args: [],
  695. source: "isDagNode\x0a\x09^ false",
  696. referencedClasses: [],
  697. //>>excludeEnd("ide");
  698. pragmas: [],
  699. messageSends: []
  700. }, function ($methodClass){ return function (){
  701. var self=this,$self=this;
  702. return false;
  703. }; }),
  704. $globals.Object);
  705. });