Browse Source

ParentFakingPathDagVisitor.

Herbert Vojčík 8 years ago
parent
commit
5e58b068da
6 changed files with 55 additions and 97 deletions
  1. 29 14
      src/Compiler-AST.js
  2. 16 8
      src/Compiler-AST.st
  3. 1 1
      src/Compiler-IR.js
  4. 1 1
      src/Compiler-IR.st
  5. 7 59
      src/Kernel-Dag.js
  6. 1 14
      src/Kernel-Dag.st

+ 29 - 14
src/Compiler-AST.js

@@ -2980,42 +2980,57 @@ $globals.VariableNode);
 
 
 
-$core.addClass('NodeVisitor', $globals.PathDagVisitor, [], 'Compiler-AST');
+$core.addClass('ParentFakingPathDagVisitor', $globals.PathDagVisitor, ['setParentSelector'], 'Compiler-AST');
 //>>excludeStart("ide", pragmas.excludeIdeData);
-$globals.NodeVisitor.comment="I am the abstract super class of all AST node visitors.";
+$globals.ParentFakingPathDagVisitor.comment="I am base class of `DagNode` visitor.\x0a\x0aI hold the path of ancestors up to actual node\x0ain `self path`.";
 //>>excludeEnd("ide");
 $core.addMethod(
 $core.method({
-selector: "initialize",
-protocol: 'initialization',
-fn: function (){
+selector: "visit:",
+protocol: 'visiting',
+fn: function (aNode){
 var self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-(
+var $1;
+$recv(self._path())._ifNotEmpty_((function(p){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
+return $recv(aNode)._parent_($recv(p)._last());
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({p:p},$ctx1,1)});
+//>>excludeEnd("ctx");
+}));
+$1=(
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx1.supercall = true,
 //>>excludeEnd("ctx");
-($globals.NodeVisitor.superclass||$boot.nilAsClass).fn.prototype._initialize.apply($recv(self), []));
+($globals.ParentFakingPathDagVisitor.superclass||$boot.nilAsClass).fn.prototype._visit_.apply($recv(self), [aNode]));
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx1.supercall = false;
 //>>excludeEnd("ctx");;
-self._setParentSelector_("parent:");
-return self;
+return $1;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"initialize",{},$globals.NodeVisitor)});
+}, function($ctx1) {$ctx1.fill(self,"visit:",{aNode:aNode},$globals.ParentFakingPathDagVisitor)});
 //>>excludeEnd("ctx");
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
-args: [],
-source: "initialize\x0a\x09super initialize.\x0a\x0a\x09self setParentSelector: #parent:",
+args: ["aNode"],
+source: "visit: aNode\x0a\x09self path ifNotEmpty: [ :p | aNode parent: p last ].\x0a\x09^ super visit: aNode",
 referencedClasses: [],
 //>>excludeEnd("ide");
-messageSends: ["initialize", "setParentSelector:"]
+messageSends: ["ifNotEmpty:", "path", "parent:", "last", "visit:"]
 }),
-$globals.NodeVisitor);
+$globals.ParentFakingPathDagVisitor);
 
+
+
+$core.addClass('NodeVisitor', $globals.ParentFakingPathDagVisitor, [], 'Compiler-AST');
+//>>excludeStart("ide", pragmas.excludeIdeData);
+$globals.NodeVisitor.comment="I am the abstract super class of all AST node visitors.";
+//>>excludeEnd("ide");
 $core.addMethod(
 $core.method({
 selector: "visitAssignmentNode:",

+ 16 - 8
src/Compiler-AST.st

@@ -725,20 +725,28 @@ acceptDagVisitor: aVisitor
 	^ aVisitor visitVariableNode: self
 ! !
 
-PathDagVisitor subclass: #NodeVisitor
-	instanceVariableNames: ''
+PathDagVisitor subclass: #ParentFakingPathDagVisitor
+	instanceVariableNames: 'setParentSelector'
 	package: 'Compiler-AST'!
-!NodeVisitor commentStamp!
-I am the abstract super class of all AST node visitors.!
+!ParentFakingPathDagVisitor commentStamp!
+I am base class of `DagNode` visitor.
 
-!NodeVisitor methodsFor: 'initialization'!
+I hold the path of ancestors up to actual node
+in `self path`.!
 
-initialize
-	super initialize.
+!ParentFakingPathDagVisitor methodsFor: 'visiting'!
 
-	self setParentSelector: #parent:
+visit: aNode
+	self path ifNotEmpty: [ :p | aNode parent: p last ].
+	^ super visit: aNode
 ! !
 
+ParentFakingPathDagVisitor subclass: #NodeVisitor
+	instanceVariableNames: ''
+	package: 'Compiler-AST'!
+!NodeVisitor commentStamp!
+I am the abstract super class of all AST node visitors.!
+
 !NodeVisitor methodsFor: 'visiting'!
 
 visitAssignmentNode: aNode

+ 1 - 1
src/Compiler-IR.js

@@ -2972,7 +2972,7 @@ $globals.IRVerbatim);
 
 
 
-$core.addClass('IRVisitor', $globals.PathDagVisitor, [], 'Compiler-IR');
+$core.addClass('IRVisitor', $globals.ParentFakingPathDagVisitor, [], 'Compiler-IR');
 $core.addMethod(
 $core.method({
 selector: "visitDagNode:",

+ 1 - 1
src/Compiler-IR.st

@@ -772,7 +772,7 @@ acceptDagVisitor: aVisitor
 	^ aVisitor visitIRVerbatim: self
 ! !
 
-PathDagVisitor subclass: #IRVisitor
+ParentFakingPathDagVisitor subclass: #IRVisitor
 	instanceVariableNames: ''
 	package: 'Compiler-IR'!
 

+ 7 - 59
src/Kernel-Dag.js

@@ -197,7 +197,7 @@ $globals.AbstractDagVisitor);
 
 
 
-$core.addClass('PathDagVisitor', $globals.AbstractDagVisitor, ['path', 'setParentSelector'], 'Kernel-Dag');
+$core.addClass('PathDagVisitor', $globals.AbstractDagVisitor, ['path'], 'Kernel-Dag');
 //>>excludeStart("ide", pragmas.excludeIdeData);
 $globals.PathDagVisitor.comment="I am base class of `DagNode` visitor.\x0a\x0aI hold the path of ancestors up to actual node\x0ain `self path`.";
 //>>excludeEnd("ide");
@@ -218,7 +218,6 @@ $ctx1.supercall = true,
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx1.supercall = false;
 //>>excludeEnd("ctx");;
-self["@setParentSelector"]=nil;
 self["@path"]=[];
 return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
@@ -227,7 +226,7 @@ return self;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "initialize\x0a\x09super initialize.\x0a\x0a\x09setParentSelector := nil.\x0a\x09path := #()",
+source: "initialize\x0a\x09super initialize.\x0a\x0a\x09path := #()",
 referencedClasses: [],
 //>>excludeEnd("ide");
 messageSends: ["initialize"]
@@ -252,43 +251,6 @@ messageSends: []
 }),
 $globals.PathDagVisitor);
 
-$core.addMethod(
-$core.method({
-selector: "setParentSelector",
-protocol: 'accessing',
-fn: function (){
-var self=this;
-return self["@setParentSelector"];
-
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: [],
-source: "setParentSelector\x0a\x09^ setParentSelector",
-referencedClasses: [],
-//>>excludeEnd("ide");
-messageSends: []
-}),
-$globals.PathDagVisitor);
-
-$core.addMethod(
-$core.method({
-selector: "setParentSelector:",
-protocol: 'accessing',
-fn: function (anObject){
-var self=this;
-self["@setParentSelector"]=anObject;
-return self;
-
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: ["anObject"],
-source: "setParentSelector: anObject\x0a\x09setParentSelector := anObject",
-referencedClasses: [],
-//>>excludeEnd("ide");
-messageSends: []
-}),
-$globals.PathDagVisitor);
-
 $core.addMethod(
 $core.method({
 selector: "visit:",
@@ -299,7 +261,7 @@ var oldPath;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-var $1,$2,$receiver;
+var $1;
 var $early={};
 try {
 oldPath=self["@path"];
@@ -309,21 +271,7 @@ return $core.withContext(function($ctx2) {
 //>>excludeEnd("ctx");
 self["@path"]=$recv(self["@path"]).__comma([aNode]);
 self["@path"];
-$1=self["@setParentSelector"];
-if(($receiver = $1) == null || $receiver.isNil){
-$1;
-} else {
-$recv(oldPath)._ifNotEmpty_((function(){
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx3) {
-//>>excludeEnd("ctx");
-return $recv(aNode)._perform_withArguments_(self["@setParentSelector"],[$recv(oldPath)._last()]);
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx3) {$ctx3.fillBlock({},$ctx2,3)});
-//>>excludeEnd("ctx");
-}));
-};
-$2=(
+$1=(
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx2.supercall = true,
 //>>excludeEnd("ctx");
@@ -331,7 +279,7 @@ $ctx2.supercall = true,
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx2.supercall = false;
 //>>excludeEnd("ctx");;
-throw $early=[$2];
+throw $early=[$1];
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
 //>>excludeEnd("ctx");
@@ -349,10 +297,10 @@ catch(e) {if(e===$early)return e[0]; throw e}
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["aNode"],
-source: "visit: aNode\x0a\x09| oldPath |\x0a\x09oldPath := path.\x0a\x09[\x0a\x09\x09path := path, {aNode}.\x0a\x09\x09setParentSelector ifNotNil: [ oldPath ifNotEmpty: [\x0a\x09\x09\x09aNode\x0a\x09\x09\x09\x09perform: setParentSelector\x0a\x09\x09\x09\x09withArguments: {oldPath last} ] ].\x0a\x09\x09^ super visit: aNode\x0a\x09] ensure: [ path := oldPath ]",
+source: "visit: aNode\x0a\x09| oldPath |\x0a\x09oldPath := path.\x0a\x09[\x0a\x09\x09path := path, {aNode}.\x0a\x09\x09^ super visit: aNode\x0a\x09] ensure: [ path := oldPath ]",
 referencedClasses: [],
 //>>excludeEnd("ide");
-messageSends: ["ensure:", ",", "ifNotNil:", "ifNotEmpty:", "perform:withArguments:", "last", "visit:"]
+messageSends: ["ensure:", ",", "visit:"]
 }),
 $globals.PathDagVisitor);
 

+ 1 - 14
src/Kernel-Dag.st

@@ -53,7 +53,7 @@ visitDagNodeVariantSimple: aNode
 ! !
 
 AbstractDagVisitor subclass: #PathDagVisitor
-	instanceVariableNames: 'path setParentSelector'
+	instanceVariableNames: 'path'
 	package: 'Kernel-Dag'!
 !PathDagVisitor commentStamp!
 I am base class of `DagNode` visitor.
@@ -65,14 +65,6 @@ in `self path`.!
 
 path
 	^ path
-!
-
-setParentSelector
-	^ setParentSelector
-!
-
-setParentSelector: anObject
-	setParentSelector := anObject
 ! !
 
 !PathDagVisitor methodsFor: 'initialization'!
@@ -80,7 +72,6 @@ setParentSelector: anObject
 initialize
 	super initialize.
 
-	setParentSelector := nil.
 	path := #()
 ! !
 
@@ -91,10 +82,6 @@ visit: aNode
 	oldPath := path.
 	[
 		path := path, {aNode}.
-		setParentSelector ifNotNil: [ oldPath ifNotEmpty: [
-			aNode
-				perform: setParentSelector
-				withArguments: {oldPath last} ] ].
 		^ super visit: aNode
 	] ensure: [ path := oldPath ]
 !