ソースを参照

Compiler-AST/Node: add position instance var + accessors

mkroehnert 11 年 前
コミット
73d0e1f41c
3 ファイル変更83 行追加5 行削除
  1. 30 1
      js/Compiler-AST.deploy.js
  2. 41 2
      js/Compiler-AST.js
  3. 12 2
      st/Compiler-AST.st

+ 30 - 1
js/Compiler-AST.deploy.js

@@ -1,5 +1,5 @@
 smalltalk.addPackage('Compiler-AST', {});
-smalltalk.addClass('Node', smalltalk.Object, ['nodes', 'shouldBeInlined', 'shouldBeAliased'], 'Compiler-AST');
+smalltalk.addClass('Node', smalltalk.Object, ['position', 'nodes', 'shouldBeInlined', 'shouldBeAliased'], 'Compiler-AST');
 smalltalk.addMethod(
 "_accept_",
 smalltalk.method({
@@ -119,6 +119,35 @@ return self}
 }),
 smalltalk.Node);
 
+smalltalk.addMethod(
+"_position",
+smalltalk.method({
+selector: "position",
+fn: function (){
+var self=this;
+var $1;
+if(($receiver = self["@position"]) == nil || $receiver == undefined){
+self["@position"]=_st((0)).__at((0));
+$1=self["@position"];
+} else {
+$1=self["@position"];
+};
+return $1;
+}
+}),
+smalltalk.Node);
+
+smalltalk.addMethod(
+"_position_",
+smalltalk.method({
+selector: "position:",
+fn: function (aPosition){
+var self=this;
+self["@position"]=aPosition;
+return self}
+}),
+smalltalk.Node);
+
 smalltalk.addMethod(
 "_shouldBeAliased",
 smalltalk.method({

+ 41 - 2
js/Compiler-AST.js

@@ -1,6 +1,6 @@
 smalltalk.addPackage('Compiler-AST', {});
-smalltalk.addClass('Node', smalltalk.Object, ['nodes', 'shouldBeInlined', 'shouldBeAliased'], 'Compiler-AST');
-smalltalk.Node.comment="I am the abstract root class of the abstract syntax tree."
+smalltalk.addClass('Node', smalltalk.Object, ['position', 'nodes', 'shouldBeInlined', 'shouldBeAliased'], 'Compiler-AST');
+smalltalk.Node.comment="I am the abstract root class of the abstract syntax tree.\x0a\x0aposition: holds a point containing lline- and column number of the symbol location in the original source file"
 smalltalk.addMethod(
 "_accept_",
 smalltalk.method({
@@ -170,6 +170,45 @@ referencedClasses: []
 }),
 smalltalk.Node);
 
+smalltalk.addMethod(
+"_position",
+smalltalk.method({
+selector: "position",
+category: 'accessing',
+fn: function (){
+var self=this;
+var $1;
+if(($receiver = self["@position"]) == nil || $receiver == undefined){
+self["@position"]=_st((0)).__at((0));
+$1=self["@position"];
+} else {
+$1=self["@position"];
+};
+return $1;
+},
+args: [],
+source: "position\x0a\x09^position ifNil: [position := 0@0]",
+messageSends: ["ifNil:", "@"],
+referencedClasses: []
+}),
+smalltalk.Node);
+
+smalltalk.addMethod(
+"_position_",
+smalltalk.method({
+selector: "position:",
+category: 'building',
+fn: function (aPosition){
+var self=this;
+self["@position"]=aPosition;
+return self},
+args: ["aPosition"],
+source: "position: aPosition\x0a\x09position := aPosition",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.Node);
+
 smalltalk.addMethod(
 "_shouldBeAliased",
 smalltalk.method({

+ 12 - 2
st/Compiler-AST.st

@@ -1,9 +1,11 @@
 Smalltalk current createPackage: 'Compiler-AST' properties: #{}!
 Object subclass: #Node
-	instanceVariableNames: 'nodes shouldBeInlined shouldBeAliased'
+	instanceVariableNames: 'position nodes shouldBeInlined shouldBeAliased'
 	package: 'Compiler-AST'!
 !Node commentStamp!
-I am the abstract root class of the abstract syntax tree.!
+I am the abstract root class of the abstract syntax tree.
+
+position: holds a point containing lline- and column number of the symbol location in the original source file!
 
 !Node methodsFor: 'accessing'!
 
@@ -15,6 +17,10 @@ nodes
 	^nodes ifNil: [nodes := Array new]
 !
 
+position
+	^position ifNil: [position := 0@0]
+!
+
 shouldBeAliased
 	^ shouldBeAliased ifNil: [ false ]
 !
@@ -35,6 +41,10 @@ shouldBeInlined: aBoolean
 
 nodes: aCollection
 	nodes := aCollection
+!
+
+position: aPosition
+	position := aPosition
 ! !
 
 !Node methodsFor: 'testing'!