Kernel-Dag.js 24 KB

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