Browse Source

{Node,RefNode} >> asRef

Herbert Vojčík 9 years ago
parent
commit
6021b31da0
4 changed files with 63 additions and 9 deletions
  1. 45 0
      src/Compiler-AST.js
  2. 12 0
      src/Compiler-AST.st
  3. 5 8
      src/Compiler-Semantic.js
  4. 1 1
      src/Compiler-Semantic.st

+ 45 - 0
src/Compiler-AST.js

@@ -95,6 +95,33 @@ messageSends: ["asSet", "nodes", "do:", "addAll:", "allNodes"]
 }),
 $globals.Node);
 
+$core.addMethod(
+$core.method({
+selector: "asRefNode",
+protocol: 'converting',
+fn: function (){
+var self=this;
+function $RefNode(){return $globals.RefNode||(typeof RefNode=="undefined"?nil:RefNode)}
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+var $1;
+$1=$recv($RefNode())._new();
+$recv($1)._node_(self);
+return $recv($1)._yourself();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"asRefNode",{},$globals.Node)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "asRefNode\x0a\x09^ RefNode new node: self; yourself",
+referencedClasses: ["RefNode"],
+//>>excludeEnd("ide");
+messageSends: ["node:", "new", "yourself"]
+}),
+$globals.Node);
+
 $core.addMethod(
 $core.method({
 selector: "inPosition:",
@@ -2032,6 +2059,24 @@ messageSends: ["visitRefNode:"]
 }),
 $globals.RefNode);
 
+$core.addMethod(
+$core.method({
+selector: "asRefNode",
+protocol: 'converting',
+fn: function (){
+var self=this;
+return self;
+
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "asRefNode\x0a\x09^ self",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: []
+}),
+$globals.RefNode);
+
 $core.addMethod(
 $core.method({
 selector: "isImmutable",

+ 12 - 0
src/Compiler-AST.st

@@ -122,6 +122,12 @@ nodes: aCollection
 	aCollection do: [ :each | each parent: self ]
 ! !
 
+!Node methodsFor: 'converting'!
+
+asRefNode
+	^ RefNode new node: self; yourself
+! !
+
 !Node methodsFor: 'copying'!
 
 postCopy
@@ -486,6 +492,12 @@ node: anObject
 	node := anObject
 ! !
 
+!RefNode methodsFor: 'converting'!
+
+asRefNode
+	^ self
+! !
+
 !RefNode methodsFor: 'testing'!
 
 isImmutable

+ 5 - 8
src/Compiler-Semantic.js

@@ -2300,11 +2300,10 @@ protocol: 'visiting',
 fn: function (aNode){
 var self=this;
 var recv;
-function $RefNode(){return $globals.RefNode||(typeof RefNode=="undefined"?nil:RefNode)}
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-var $2,$1,$3;
+var $2,$1;
 $2=$recv(aNode)._nodes();
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx1.sendIdx["nodes"]=1;
@@ -2315,9 +2314,7 @@ $recv($recv(aNode)._nodes())._do_((function(each){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx2) {
 //>>excludeEnd("ctx");
-$3=$recv($RefNode())._new();
-$recv($3)._node_(recv);
-return $recv(each)._receiver_($recv($3)._yourself());
+return $recv(each)._receiver_($recv(recv)._asRefNode());
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx2.sendIdx["receiver:"]=1;
 //>>excludeEnd("ctx");
@@ -2341,10 +2338,10 @@ return self;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["aNode"],
-source: "visitCascadeNode: aNode\x0a\x09| recv |\x0a\x09recv := aNode nodes first receiver.\x0a\x09aNode nodes do: [ :each | each receiver: (RefNode new node: recv; yourself) ].\x0a\x09aNode receiver: recv.\x0a\x09super visitCascadeNode: aNode",
-referencedClasses: ["RefNode"],
+source: "visitCascadeNode: aNode\x0a\x09| recv |\x0a\x09recv := aNode nodes first receiver.\x0a\x09aNode nodes do: [ :each | each receiver: recv asRefNode ].\x0a\x09aNode receiver: recv.\x0a\x09super visitCascadeNode: aNode",
+referencedClasses: [],
 //>>excludeEnd("ide");
-messageSends: ["receiver", "first", "nodes", "do:", "receiver:", "node:", "new", "yourself", "visitCascadeNode:"]
+messageSends: ["receiver", "first", "nodes", "do:", "receiver:", "asRefNode", "visitCascadeNode:"]
 }),
 $globals.SemanticAnalyzer);
 

+ 1 - 1
src/Compiler-Semantic.st

@@ -560,7 +560,7 @@ visitBlockNode: aNode
 visitCascadeNode: aNode
 	| recv |
 	recv := aNode nodes first receiver.
-	aNode nodes do: [ :each | each receiver: (RefNode new node: recv; yourself) ].
+	aNode nodes do: [ :each | each receiver: recv asRefNode ].
 	aNode receiver: recv.
 	super visitCascadeNode: aNode
 !