123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- define(["amber/boot", "amber_core/Kernel-Objects"], function($boot){"use strict";
- if(!$boot.nilAsReceiver)$boot.nilAsReceiver=$boot.nil;
- var $core=$boot.api,nil=$boot.nilAsReceiver,$recv=$boot.asReceiver,$globals=$boot.globals;
- if(!$boot.nilAsClass)$boot.nilAsClass=$boot.dnu;
- $core.addPackage('Kernel-Dag');
- $core.packages["Kernel-Dag"].innerEval = function (expr) { return eval(expr); };
- $core.packages["Kernel-Dag"].transport = {"type":"amd","amdNamespace":"amber_core"};
- $core.addClass('DagNode', $globals.Object, [], 'Kernel-Dag');
- //>>excludeStart("ide", pragmas.excludeIdeData);
- $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).";
- //>>excludeEnd("ide");
- $core.addMethod(
- $core.method({
- selector: "allDagChildren",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- var allNodes;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- return $core.withContext(function($ctx1) {
- //>>excludeEnd("ctx");
- var $1;
- $1=self._dagChildren();
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- $ctx1.sendIdx["dagChildren"]=1;
- //>>excludeEnd("ctx");
- allNodes=$recv($1)._asSet();
- $recv(self._dagChildren())._do_((function(each){
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- return $core.withContext(function($ctx2) {
- //>>excludeEnd("ctx");
- return $recv(allNodes)._addAll_($recv(each)._allDagChildren());
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
- //>>excludeEnd("ctx");
- }));
- return allNodes;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- }, function($ctx1) {$ctx1.fill(self,"allDagChildren",{allNodes:allNodes},$globals.DagNode)});
- //>>excludeEnd("ctx");
- },
- //>>excludeStart("ide", pragmas.excludeIdeData);
- args: [],
- 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",
- referencedClasses: [],
- //>>excludeEnd("ide");
- messageSends: ["asSet", "dagChildren", "do:", "addAll:", "allDagChildren"]
- }),
- $globals.DagNode);
- $core.addMethod(
- $core.method({
- selector: "dagChildren",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- return $core.withContext(function($ctx1) {
- //>>excludeEnd("ctx");
- self._subclassResponsibility();
- return self;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- }, function($ctx1) {$ctx1.fill(self,"dagChildren",{},$globals.DagNode)});
- //>>excludeEnd("ctx");
- },
- //>>excludeStart("ide", pragmas.excludeIdeData);
- args: [],
- source: "dagChildren\x0a\x09self subclassResponsibility",
- referencedClasses: [],
- //>>excludeEnd("ide");
- messageSends: ["subclassResponsibility"]
- }),
- $globals.DagNode);
- $core.addMethod(
- $core.method({
- selector: "dagChildren:",
- protocol: 'accessing',
- fn: function (aCollection){
- var self=this;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- return $core.withContext(function($ctx1) {
- //>>excludeEnd("ctx");
- self._subclassResponsibility();
- return self;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- }, function($ctx1) {$ctx1.fill(self,"dagChildren:",{aCollection:aCollection},$globals.DagNode)});
- //>>excludeEnd("ctx");
- },
- //>>excludeStart("ide", pragmas.excludeIdeData);
- args: ["aCollection"],
- source: "dagChildren: aCollection\x0a\x09self subclassResponsibility",
- referencedClasses: [],
- //>>excludeEnd("ide");
- messageSends: ["subclassResponsibility"]
- }),
- $globals.DagNode);
- $core.addMethod(
- $core.method({
- selector: "isDagNode",
- protocol: 'testing',
- fn: function (){
- var self=this;
- return true;
- },
- //>>excludeStart("ide", pragmas.excludeIdeData);
- args: [],
- source: "isDagNode\x0a\x09^ true",
- referencedClasses: [],
- //>>excludeEnd("ide");
- messageSends: []
- }),
- $globals.DagNode);
- $core.addClass('DagParentNode', $globals.DagNode, ['nodes'], 'Kernel-Dag');
- //>>excludeStart("ide", pragmas.excludeIdeData);
- $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.";
- //>>excludeEnd("ide");
- $core.addMethod(
- $core.method({
- selector: "addDagChild:",
- protocol: 'accessing',
- fn: function (aDagNode){
- var self=this;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- return $core.withContext(function($ctx1) {
- //>>excludeEnd("ctx");
- $recv(self._dagChildren())._add_(aDagNode);
- return self;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- }, function($ctx1) {$ctx1.fill(self,"addDagChild:",{aDagNode:aDagNode},$globals.DagParentNode)});
- //>>excludeEnd("ctx");
- },
- //>>excludeStart("ide", pragmas.excludeIdeData);
- args: ["aDagNode"],
- source: "addDagChild: aDagNode\x0a\x09self dagChildren add: aDagNode",
- referencedClasses: [],
- //>>excludeEnd("ide");
- messageSends: ["add:", "dagChildren"]
- }),
- $globals.DagParentNode);
- $core.addMethod(
- $core.method({
- selector: "dagChildren",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- return $core.withContext(function($ctx1) {
- //>>excludeEnd("ctx");
- var $1,$receiver;
- $1=self["@nodes"];
- if(($receiver = $1) == null || $receiver.isNil){
- self["@nodes"]=$recv($globals.Array)._new();
- return self["@nodes"];
- } else {
- return $1;
- };
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- }, function($ctx1) {$ctx1.fill(self,"dagChildren",{},$globals.DagParentNode)});
- //>>excludeEnd("ctx");
- },
- //>>excludeStart("ide", pragmas.excludeIdeData);
- args: [],
- source: "dagChildren\x0a\x09^ nodes ifNil: [ nodes := Array new ]",
- referencedClasses: ["Array"],
- //>>excludeEnd("ide");
- messageSends: ["ifNil:", "new"]
- }),
- $globals.DagParentNode);
- $core.addMethod(
- $core.method({
- selector: "dagChildren:",
- protocol: 'accessing',
- fn: function (aCollection){
- var self=this;
- self["@nodes"]=aCollection;
- return self;
- },
- //>>excludeStart("ide", pragmas.excludeIdeData);
- args: ["aCollection"],
- source: "dagChildren: aCollection\x0a\x09nodes := aCollection",
- referencedClasses: [],
- //>>excludeEnd("ide");
- messageSends: []
- }),
- $globals.DagParentNode);
- $core.addClass('DagSink', $globals.DagNode, ['nodes'], 'Kernel-Dag');
- //>>excludeStart("ide", pragmas.excludeIdeData);
- $globals.DagSink.comment="I am `DagNode` with no direct successors.\x0a\x0aSending `dagChildren:` with empty collection is legal.";
- //>>excludeEnd("ide");
- $core.addMethod(
- $core.method({
- selector: "dagChildren",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- return [];
- },
- //>>excludeStart("ide", pragmas.excludeIdeData);
- args: [],
- source: "dagChildren\x0a\x09^ #()",
- referencedClasses: [],
- //>>excludeEnd("ide");
- messageSends: []
- }),
- $globals.DagSink);
- $core.addMethod(
- $core.method({
- selector: "dagChildren:",
- protocol: 'accessing',
- fn: function (aCollection){
- var self=this;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- return $core.withContext(function($ctx1) {
- //>>excludeEnd("ctx");
- $recv(aCollection)._ifNotEmpty_((function(){
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- return $core.withContext(function($ctx2) {
- //>>excludeEnd("ctx");
- return self._error_("A DagSink cannot have children.");
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
- //>>excludeEnd("ctx");
- }));
- return self;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- }, function($ctx1) {$ctx1.fill(self,"dagChildren:",{aCollection:aCollection},$globals.DagSink)});
- //>>excludeEnd("ctx");
- },
- //>>excludeStart("ide", pragmas.excludeIdeData);
- args: ["aCollection"],
- source: "dagChildren: aCollection\x0a\x09aCollection ifNotEmpty: [ self error: 'A DagSink cannot have children.' ]",
- referencedClasses: [],
- //>>excludeEnd("ide");
- messageSends: ["ifNotEmpty:", "error:"]
- }),
- $globals.DagSink);
- $core.addMethod(
- $core.method({
- selector: "isDagNode",
- protocol: '*Kernel-Dag',
- fn: function (){
- var self=this;
- return false;
- },
- //>>excludeStart("ide", pragmas.excludeIdeData);
- args: [],
- source: "isDagNode\x0a\x09^ false",
- referencedClasses: [],
- //>>excludeEnd("ide");
- messageSends: []
- }),
- $globals.Object);
- });
|