Kernel-Dag.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  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 = newChildren\x0a\x09\x09ifTrue: [ ^ aNode ]\x0a\x09\x09ifFalse: [ ^ aNode copy dagChildren: newChildren; yourself ]",
  136. referencedClasses: [],
  137. //>>excludeEnd("ide");
  138. pragmas: [],
  139. messageSends: ["dagChildren", "visitAllChildren:", "ifTrue:ifFalse:", "=", "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 $1;
  147. oldChildren=$recv(aNode)._dagChildren();
  148. newChildren=$self._visitAllChildren_(aNode);
  149. if($core.assert($recv(oldChildren).__eq(newChildren))){
  150. return aNode;
  151. } else {
  152. $1=$recv(aNode)._copy();
  153. $recv($1)._dagChildren_(newChildren);
  154. return $recv($1)._yourself();
  155. }
  156. return self;
  157. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  158. }, function($ctx1) {$ctx1.fill(self,"visitDagNodeVariantRedux:",{aNode:aNode,newChildren:newChildren,oldChildren:oldChildren})});
  159. //>>excludeEnd("ctx");
  160. }; }),
  161. $globals.AbstractDagVisitor);
  162. $core.addMethod(
  163. $core.method({
  164. selector: "visitDagNodeVariantSimple:",
  165. protocol: "visiting",
  166. //>>excludeStart("ide", pragmas.excludeIdeData);
  167. args: ["aNode"],
  168. source: "visitDagNodeVariantSimple: aNode\x0a\x09\x22Simple implementation of visitDagNode:.\x0a\x09Visits children, then returns aNode\x22\x0a\x0a\x09self visitAllChildren: aNode.\x0a\x09^ aNode",
  169. referencedClasses: [],
  170. //>>excludeEnd("ide");
  171. pragmas: [],
  172. messageSends: ["visitAllChildren:"]
  173. }, function ($methodClass){ return function (aNode){
  174. var self=this,$self=this;
  175. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  176. return $core.withContext(function($ctx1) {
  177. //>>excludeEnd("ctx");
  178. $self._visitAllChildren_(aNode);
  179. return aNode;
  180. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  181. }, function($ctx1) {$ctx1.fill(self,"visitDagNodeVariantSimple:",{aNode:aNode})});
  182. //>>excludeEnd("ctx");
  183. }; }),
  184. $globals.AbstractDagVisitor);
  185. $core.addClass("PathDagVisitor", $globals.AbstractDagVisitor, ["path"], "Kernel-Dag");
  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, ["nodes"], "Kernel-Dag");
  445. //>>excludeStart("ide", pragmas.excludeIdeData);
  446. $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.";
  447. //>>excludeEnd("ide");
  448. $core.addMethod(
  449. $core.method({
  450. selector: "addDagChild:",
  451. protocol: "accessing",
  452. //>>excludeStart("ide", pragmas.excludeIdeData);
  453. args: ["aDagNode"],
  454. source: "addDagChild: aDagNode\x0a\x09self dagChildren add: aDagNode",
  455. referencedClasses: [],
  456. //>>excludeEnd("ide");
  457. pragmas: [],
  458. messageSends: ["add:", "dagChildren"]
  459. }, function ($methodClass){ return function (aDagNode){
  460. var self=this,$self=this;
  461. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  462. return $core.withContext(function($ctx1) {
  463. //>>excludeEnd("ctx");
  464. $recv($self._dagChildren())._add_(aDagNode);
  465. return self;
  466. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  467. }, function($ctx1) {$ctx1.fill(self,"addDagChild:",{aDagNode:aDagNode})});
  468. //>>excludeEnd("ctx");
  469. }; }),
  470. $globals.DagParentNode);
  471. $core.addMethod(
  472. $core.method({
  473. selector: "dagChildren",
  474. protocol: "accessing",
  475. //>>excludeStart("ide", pragmas.excludeIdeData);
  476. args: [],
  477. source: "dagChildren\x0a\x09^ nodes ifNil: [ nodes := Array new ]",
  478. referencedClasses: ["Array"],
  479. //>>excludeEnd("ide");
  480. pragmas: [],
  481. messageSends: ["ifNil:", "new"]
  482. }, function ($methodClass){ return function (){
  483. var self=this,$self=this;
  484. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  485. return $core.withContext(function($ctx1) {
  486. //>>excludeEnd("ctx");
  487. var $1;
  488. $1=$self.nodes;
  489. if($1 == null || $1.a$nil){
  490. $self.nodes=$recv($globals.Array)._new();
  491. return $self.nodes;
  492. } else {
  493. return $1;
  494. }
  495. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  496. }, function($ctx1) {$ctx1.fill(self,"dagChildren",{})});
  497. //>>excludeEnd("ctx");
  498. }; }),
  499. $globals.DagParentNode);
  500. $core.addMethod(
  501. $core.method({
  502. selector: "dagChildren:",
  503. protocol: "accessing",
  504. //>>excludeStart("ide", pragmas.excludeIdeData);
  505. args: ["aCollection"],
  506. source: "dagChildren: aCollection\x0a\x09nodes := aCollection",
  507. referencedClasses: [],
  508. //>>excludeEnd("ide");
  509. pragmas: [],
  510. messageSends: []
  511. }, function ($methodClass){ return function (aCollection){
  512. var self=this,$self=this;
  513. $self.nodes=aCollection;
  514. return self;
  515. }; }),
  516. $globals.DagParentNode);
  517. $core.addClass("DagSink", $globals.DagNode, [], "Kernel-Dag");
  518. //>>excludeStart("ide", pragmas.excludeIdeData);
  519. $globals.DagSink.comment="I am `DagNode` with no direct successors.\x0a\x0aSending `dagChildren:` with empty collection is legal.";
  520. //>>excludeEnd("ide");
  521. $core.addTrait("TDagSink", "Kernel-Dag");
  522. $core.addMethod(
  523. $core.method({
  524. selector: "dagChildren",
  525. protocol: "accessing",
  526. //>>excludeStart("ide", pragmas.excludeIdeData);
  527. args: [],
  528. source: "dagChildren\x0a\x09^ #()",
  529. referencedClasses: [],
  530. //>>excludeEnd("ide");
  531. pragmas: [],
  532. messageSends: []
  533. }, function ($methodClass){ return function (){
  534. var self=this,$self=this;
  535. return [];
  536. }; }),
  537. $globals.TDagSink);
  538. $core.addMethod(
  539. $core.method({
  540. selector: "dagChildren:",
  541. protocol: "accessing",
  542. //>>excludeStart("ide", pragmas.excludeIdeData);
  543. args: ["aCollection"],
  544. source: "dagChildren: aCollection\x0a\x09aCollection ifNotEmpty: [ self error: 'A DagSink cannot have children.' ]",
  545. referencedClasses: [],
  546. //>>excludeEnd("ide");
  547. pragmas: [],
  548. messageSends: ["ifNotEmpty:", "error:"]
  549. }, function ($methodClass){ return function (aCollection){
  550. var self=this,$self=this;
  551. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  552. return $core.withContext(function($ctx1) {
  553. //>>excludeEnd("ctx");
  554. $recv(aCollection)._ifNotEmpty_((function(){
  555. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  556. return $core.withContext(function($ctx2) {
  557. //>>excludeEnd("ctx");
  558. return $self._error_("A DagSink cannot have children.");
  559. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  560. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  561. //>>excludeEnd("ctx");
  562. }));
  563. return self;
  564. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  565. }, function($ctx1) {$ctx1.fill(self,"dagChildren:",{aCollection:aCollection})});
  566. //>>excludeEnd("ctx");
  567. }; }),
  568. $globals.TDagSink);
  569. $core.addTrait("TDerivedDagChildren", "Kernel-Dag");
  570. $core.addMethod(
  571. $core.method({
  572. selector: "addDagChild:",
  573. protocol: "accessing",
  574. //>>excludeStart("ide", pragmas.excludeIdeData);
  575. args: ["aDagNode"],
  576. source: "addDagChild: aDagNode\x0a\x09self error: 'Cannot add child for a TDerivedChildren.'",
  577. referencedClasses: [],
  578. //>>excludeEnd("ide");
  579. pragmas: [],
  580. messageSends: ["error:"]
  581. }, function ($methodClass){ return function (aDagNode){
  582. var self=this,$self=this;
  583. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  584. return $core.withContext(function($ctx1) {
  585. //>>excludeEnd("ctx");
  586. $self._error_("Cannot add child for a TDerivedChildren.");
  587. return self;
  588. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  589. }, function($ctx1) {$ctx1.fill(self,"addDagChild:",{aDagNode:aDagNode})});
  590. //>>excludeEnd("ctx");
  591. }; }),
  592. $globals.TDerivedDagChildren);
  593. $core.addMethod(
  594. $core.method({
  595. selector: "dagChildren",
  596. protocol: "accessing",
  597. //>>excludeStart("ide", pragmas.excludeIdeData);
  598. args: [],
  599. source: "dagChildren\x0a\x09self subclassResponsibility",
  600. referencedClasses: [],
  601. //>>excludeEnd("ide");
  602. pragmas: [],
  603. messageSends: ["subclassResponsibility"]
  604. }, function ($methodClass){ return function (){
  605. var self=this,$self=this;
  606. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  607. return $core.withContext(function($ctx1) {
  608. //>>excludeEnd("ctx");
  609. $self._subclassResponsibility();
  610. return self;
  611. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  612. }, function($ctx1) {$ctx1.fill(self,"dagChildren",{})});
  613. //>>excludeEnd("ctx");
  614. }; }),
  615. $globals.TDerivedDagChildren);
  616. $core.addMethod(
  617. $core.method({
  618. selector: "dagChildren:",
  619. protocol: "accessing",
  620. //>>excludeStart("ide", pragmas.excludeIdeData);
  621. args: ["aCollection"],
  622. source: "dagChildren: aCollection\x0a\x09self error: 'Cannot set children of a TDerivedChildren.'",
  623. referencedClasses: [],
  624. //>>excludeEnd("ide");
  625. pragmas: [],
  626. messageSends: ["error:"]
  627. }, function ($methodClass){ return function (aCollection){
  628. var self=this,$self=this;
  629. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  630. return $core.withContext(function($ctx1) {
  631. //>>excludeEnd("ctx");
  632. $self._error_("Cannot set children of a TDerivedChildren.");
  633. return self;
  634. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  635. }, function($ctx1) {$ctx1.fill(self,"dagChildren:",{aCollection:aCollection})});
  636. //>>excludeEnd("ctx");
  637. }; }),
  638. $globals.TDerivedDagChildren);
  639. $core.addTrait("TSingleDagChild", "Kernel-Dag");
  640. $core.addMethod(
  641. $core.method({
  642. selector: "dagChild",
  643. protocol: "accessing",
  644. //>>excludeStart("ide", pragmas.excludeIdeData);
  645. args: [],
  646. source: "dagChild\x0a\x09self subclassResponsibility",
  647. referencedClasses: [],
  648. //>>excludeEnd("ide");
  649. pragmas: [],
  650. messageSends: ["subclassResponsibility"]
  651. }, function ($methodClass){ return function (){
  652. var self=this,$self=this;
  653. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  654. return $core.withContext(function($ctx1) {
  655. //>>excludeEnd("ctx");
  656. $self._subclassResponsibility();
  657. return self;
  658. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  659. }, function($ctx1) {$ctx1.fill(self,"dagChild",{})});
  660. //>>excludeEnd("ctx");
  661. }; }),
  662. $globals.TSingleDagChild);
  663. $core.addMethod(
  664. $core.method({
  665. selector: "dagChildren",
  666. protocol: "accessing",
  667. //>>excludeStart("ide", pragmas.excludeIdeData);
  668. args: [],
  669. source: "dagChildren\x0a\x09^ { self dagChild }",
  670. referencedClasses: [],
  671. //>>excludeEnd("ide");
  672. pragmas: [],
  673. messageSends: ["dagChild"]
  674. }, function ($methodClass){ return function (){
  675. var self=this,$self=this;
  676. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  677. return $core.withContext(function($ctx1) {
  678. //>>excludeEnd("ctx");
  679. return [$self._dagChild()];
  680. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  681. }, function($ctx1) {$ctx1.fill(self,"dagChildren",{})});
  682. //>>excludeEnd("ctx");
  683. }; }),
  684. $globals.TSingleDagChild);
  685. $core.setTraitComposition([{trait: $globals.TDerivedDagChildren}], $globals.TDagSink);
  686. $core.setTraitComposition([{trait: $globals.TDerivedDagChildren}], $globals.TSingleDagChild);
  687. $core.setTraitComposition([{trait: $globals.TDagSink}], $globals.DagSink);
  688. $core.addMethod(
  689. $core.method({
  690. selector: "isDagNode",
  691. protocol: "*Kernel-Dag",
  692. //>>excludeStart("ide", pragmas.excludeIdeData);
  693. args: [],
  694. source: "isDagNode\x0a\x09^ false",
  695. referencedClasses: [],
  696. //>>excludeEnd("ide");
  697. pragmas: [],
  698. messageSends: []
  699. }, function ($methodClass){ return function (){
  700. var self=this,$self=this;
  701. return false;
  702. }; }),
  703. $globals.Object);
  704. });