浏览代码

Keep track of the source in nodes.

Nicolas Petton 10 年之前
父节点
当前提交
c883b23461
共有 4 个文件被更改,包括 44 次插入6 次删除
  1. 6 4
      js/Compiler-AST.js
  2. 2 0
      st/Compiler-AST.st
  3. 18 1
      support/parser.js
  4. 18 1
      support/parser.pegjs

+ 6 - 4
js/Compiler-AST.js

@@ -1915,6 +1915,7 @@ return smalltalk.withContext(function($ctx1) {
 var $2,$3,$5,$4,$6,$1;
 $2=_st($SendNode())._new();
 _st($2)._position_(self._position());
+_st($2)._source_(self._source());
 $3=$2;
 $5=self._receiver();
 $ctx1.sendIdx["receiver"]=1;
@@ -1931,8 +1932,8 @@ $1=$6;
 return $1;
 }, function($ctx1) {$ctx1.fill(self,"valueForReceiver:",{anObject:anObject},globals.SendNode)})},
 args: ["anObject"],
-source: "valueForReceiver: anObject\x0a\x09^ SendNode new\x0a\x09\x09position: self position;\x0a\x09\x09receiver: (self receiver\x0a\x09\x09ifNil: [ anObject ] \x0a\x09\x09ifNotNil: [ self receiver valueForReceiver: anObject ]);\x0a\x09\x09selector: self selector;\x0a\x09\x09arguments: self arguments;\x0a\x09\x09yourself",
-messageSends: ["position:", "new", "position", "receiver:", "ifNil:ifNotNil:", "receiver", "valueForReceiver:", "selector:", "selector", "arguments:", "arguments", "yourself"],
+source: "valueForReceiver: anObject\x0a\x09^ SendNode new\x0a\x09\x09position: self position;\x0a\x09\x09source: self source;\x0a\x09\x09receiver: (self receiver\x0a\x09\x09ifNil: [ anObject ] \x0a\x09\x09ifNotNil: [ self receiver valueForReceiver: anObject ]);\x0a\x09\x09selector: self selector;\x0a\x09\x09arguments: self arguments;\x0a\x09\x09yourself",
+messageSends: ["position:", "new", "position", "source:", "source", "receiver:", "ifNil:ifNotNil:", "receiver", "valueForReceiver:", "selector:", "selector", "arguments:", "arguments", "yourself"],
 referencedClasses: ["SendNode"]
 }),
 globals.SendNode);
@@ -1970,6 +1971,7 @@ return smalltalk.withContext(function($ctx1) {
 var $2,$3,$1;
 $2=_st($BlockSequenceNode())._new();
 _st($2)._position_(self._position());
+_st($2)._source_(self._source());
 _st($2)._nodes_(self._nodes());
 _st($2)._temps_(self._temps());
 $3=_st($2)._yourself();
@@ -1977,8 +1979,8 @@ $1=$3;
 return $1;
 }, function($ctx1) {$ctx1.fill(self,"asBlockSequenceNode",{},globals.SequenceNode)})},
 args: [],
-source: "asBlockSequenceNode\x0a\x09^ BlockSequenceNode new\x0a\x09\x09position: self position;\x0a\x09\x09nodes: self nodes;\x0a\x09\x09temps: self temps;\x0a\x09\x09yourself",
-messageSends: ["position:", "new", "position", "nodes:", "nodes", "temps:", "temps", "yourself"],
+source: "asBlockSequenceNode\x0a\x09^ BlockSequenceNode new\x0a\x09\x09position: self position;\x0a\x09\x09source: self source;\x0a\x09\x09nodes: self nodes;\x0a\x09\x09temps: self temps;\x0a\x09\x09yourself",
+messageSends: ["position:", "new", "position", "source:", "source", "nodes:", "nodes", "temps:", "temps", "yourself"],
 referencedClasses: ["BlockSequenceNode"]
 }),
 globals.SequenceNode);

+ 2 - 0
st/Compiler-AST.st

@@ -555,6 +555,7 @@ superSend: aBoolean
 valueForReceiver: anObject
 	^ SendNode new
 		position: self position;
+		source: self source;
 		receiver: (self receiver
 		ifNil: [ anObject ] 
 		ifNotNil: [ self receiver valueForReceiver: anObject ]);
@@ -628,6 +629,7 @@ temps: aCollection
 asBlockSequenceNode
 	^ BlockSequenceNode new
 		position: self position;
+		source: self source;
 		nodes: self nodes;
 		temps: self temps;
 		yourself

+ 18 - 1
support/parser.js

@@ -63,6 +63,7 @@ smalltalk.parser = (function() {
         peg$c27 = function(val) {
                              return smalltalk.ValueNode._new()
                                     ._position_((line()).__at(column()))
+                                    ._source_(text())
                                     ._value_(val.join("").replace(/\"/ig, '"'));
                          },
         peg$c28 = "#",
@@ -72,11 +73,13 @@ smalltalk.parser = (function() {
         peg$c32 = function(val) {
                               return smalltalk.ValueNode._new()
                                      ._position_((line()).__at(column()))
+                                     ._source_(text())
                                      ._value_(val);
                           },
         peg$c33 = function(n) {
                              return smalltalk.ValueNode._new()
                                     ._position_((line()).__at(column()))
+                                    ._source_(text())
                                     ._value_(n);
                          },
         peg$c34 = "e",
@@ -106,6 +109,7 @@ smalltalk.parser = (function() {
         peg$c58 = function(lits) {
                              return smalltalk.ValueNode._new()
                                     ._position_((line()).__at(column()))
+                                    ._source_(text())
                                     ._value_(lits);
                          },
         peg$c59 = "{",
@@ -115,6 +119,7 @@ smalltalk.parser = (function() {
         peg$c63 = function(expressions) {
                              return smalltalk.DynamicArrayNode._new()
                                     ._position_((line()).__at(column()))
+                                    ._source_(text())
                                     ._nodes_(expressions || []);
                          },
         peg$c64 = "#{",
@@ -122,6 +127,7 @@ smalltalk.parser = (function() {
         peg$c66 = function(expressions) {
                                 return smalltalk.DynamicDictionaryNode._new()
                                        ._position_((line()).__at(column()))
+                                       ._source_(text())
                                        ._nodes_(expressions || []);
                             },
         peg$c67 = "true",
@@ -136,11 +142,13 @@ smalltalk.parser = (function() {
         peg$c76 = function(val) {
                                return smalltalk.ValueNode._new()
                                       ._position_((line()).__at(column()))
+                                      ._source_(text())
                                       ._value_(val);
                            },
         peg$c77 = function(identifier) {
                              return smalltalk.VariableNode._new()
                                     ._position_((line()).__at(column()))
+                                    ._source_(text())
                                     ._value_(identifier);
                          },
         peg$c78 = function(key, arg) {return {key:key, arg: arg};},
@@ -174,6 +182,7 @@ smalltalk.parser = (function() {
         peg$c89 = function(variable, expression) {
                              return smalltalk.AssignmentNode._new()
                                     ._position_((line()).__at(column()))
+                                    ._source_(text())
                                     ._left_(variable)
                                     ._right_(expression);
                          },
@@ -182,6 +191,7 @@ smalltalk.parser = (function() {
         peg$c92 = function(expression) {
                              return smalltalk.ReturnNode._new()
                                     ._position_((line()).__at(column()))
+                                    ._source_(text())
                                     ._nodes_([expression]);
                          },
         peg$c93 = "|",
@@ -206,6 +216,7 @@ smalltalk.parser = (function() {
         peg$c106 = function(temps, statements) {
                              return smalltalk.SequenceNode._new()
                                     ._position_((line()).__at(column()))
+                                    ._source_(text())
                                     ._temps_(temps || [])
                                     ._nodes_(statements || []);
                          },
@@ -216,6 +227,7 @@ smalltalk.parser = (function() {
         peg$c111 = function(params, sequence) {
                              return smalltalk.BlockNode._new()
                                     ._position_((line()).__at(column()))
+                                    ._source_(text())
                                     ._parameters_(params || [])
                                     ._nodes_([sequence._asBlockSequenceNode()]);
                          },
@@ -223,6 +235,7 @@ smalltalk.parser = (function() {
         peg$c113 = function(selector) {
                              return smalltalk.SendNode._new()
                                     ._position_((line()).__at(column()))
+                                    ._source_(text())
                                     ._selector_(selector);
                          },
         peg$c114 = function(message, tail) {
@@ -244,6 +257,7 @@ smalltalk.parser = (function() {
         peg$c116 = function(selector, arg) {
                              return smalltalk.SendNode._new()
                                     ._position_((line()).__at(column()))
+                                    ._source_(text())
                                     ._selector_(selector)
                                     ._arguments_([arg]);
                          },
@@ -265,6 +279,7 @@ smalltalk.parser = (function() {
                               }
                               return smalltalk.SendNode._new()
                                      ._position_((line()).__at(column()))
+                                     ._source_(text())
                                      ._selector_(selector.join(""))
                                      ._arguments_(args);
                          },
@@ -282,6 +297,7 @@ smalltalk.parser = (function() {
                              }
                              return smalltalk.CascadeNode._new()
                                     ._position_((line()).__at(column()))
+                                    ._source_(text())
                                     ._receiver_(send._receiver())
                                     ._nodes_(cascade);
                          },
@@ -297,11 +313,12 @@ smalltalk.parser = (function() {
         peg$c134 = function(val) {
                              return smalltalk.JSStatementNode._new()
                                     ._position_((line()).__at(column()))
-                                    ._source_(val.join(""));
+                                    ._source_(val.join(""))
                          },
         peg$c135 = function(pattern, sequence) {
                               return smalltalk.MethodNode._new()
                                      ._position_((line()).__at(column()))
+                                     ._source_(text())
                                      ._selector_(pattern[0])
                                      ._arguments_(pattern[1])
                                      ._nodes_([sequence]);

+ 18 - 1
support/parser.pegjs

@@ -10,6 +10,7 @@ className      = first:[A-Z] others:[a-zA-Z0-9]* {return first + others.join("")
 string         = ['] val:(("''" {return "'";} / [^'])*) ['] {
                      return smalltalk.ValueNode._new()
                             ._position_((line()).__at(column()))
+                            ._source_(text())
                             ._value_(val.join("").replace(/\"/ig, '"'));
                  }
 
@@ -18,11 +19,13 @@ bareSymbol         = val:(selector / binarySelector / node:string {return node._
                   {
                       return smalltalk.ValueNode._new()
                              ._position_((line()).__at(column()))
+                             ._source_(text())
                              ._value_(val);
                   }
 number         = n:(numberExp / hex / float / integer) {
                      return smalltalk.ValueNode._new()
                             ._position_((line()).__at(column()))
+                            ._source_(text())
                             ._value_(n);
                  }
 numberExp      = n:((float / integer) "e" integer) {return parseFloat(n.join(""));}
@@ -35,16 +38,19 @@ bareLiteralArray   = "(" rest:literalArrayRest {return rest;}
 literalArrayRest   = ws lits:(lit:(parseTimeLiteral / bareLiteralArray / bareSymbol) ws {return lit._value();})* ws ")" {
                      return smalltalk.ValueNode._new()
                             ._position_((line()).__at(column()))
+                            ._source_(text())
                             ._value_(lits);
                  }
 dynamicArray   = "{" ws expressions:expressions? ws "."? "}" {
                      return smalltalk.DynamicArrayNode._new()
                             ._position_((line()).__at(column()))
+                            ._source_(text())
                             ._nodes_(expressions || []);
                  }
 dynamicDictionary = "#{" ws expressions: expressions? ws "}" {
                         return smalltalk.DynamicDictionaryNode._new()
                                ._position_((line()).__at(column()))
+                               ._source_(text())
                                ._nodes_(expressions || []);
                     }
 pseudoVariable = val:(
@@ -53,6 +59,7 @@ pseudoVariable = val:(
                  / 'nil' {return nil;}) {
                        return smalltalk.ValueNode._new()
                               ._position_((line()).__at(column()))
+                              ._source_(text())
                               ._value_(val);
                    }
 parseTimeLiteral        = pseudoVariable / number / literalArray / string / symbol
@@ -63,6 +70,7 @@ literal        = runtimeLiteral / parseTimeLiteral
 variable       = identifier:identifier {
                      return smalltalk.VariableNode._new()
                             ._position_((line()).__at(column()))
+                            ._source_(text())
                             ._value_(identifier);
                  }
 
@@ -102,6 +110,7 @@ expressions    = first:expression others:expressionList* {
 assignment     = variable:variable ws ':=' ws expression:expression {
                      return smalltalk.AssignmentNode._new()
                             ._position_((line()).__at(column()))
+                            ._source_(text())
                             ._left_(variable)
                             ._right_(expression);
                  }
@@ -109,6 +118,7 @@ assignment     = variable:variable ws ':=' ws expression:expression {
 ret            = '^' ws expression:expression ws '.'? {
                      return smalltalk.ReturnNode._new()
                             ._position_((line()).__at(column()))
+                            ._source_(text())
                             ._nodes_([expression]);
                  }
   
@@ -133,6 +143,7 @@ sequence       = jsSequence / stSequence
 stSequence     = temps:temps? ws statements:statements? ws {
                      return smalltalk.SequenceNode._new()
                             ._position_((line()).__at(column()))
+                            ._source_(text())
                             ._temps_(temps || [])
                             ._nodes_(statements || []);
                  }
@@ -142,6 +153,7 @@ jsSequence     = jsStatement
 block          = '[' ws params:blockParamList? ws sequence:sequence? ws ']' {
                      return smalltalk.BlockNode._new()
                             ._position_((line()).__at(column()))
+                            ._source_(text())
                             ._parameters_(params || [])
                             ._nodes_([sequence._asBlockSequenceNode()]);
                  }
@@ -153,6 +165,7 @@ operand        = literal / reference / subexpression
 unaryMessage   = ws selector:unarySelector ![:] {
                      return smalltalk.SendNode._new()
                             ._position_((line()).__at(column()))
+                            ._source_(text())
                             ._selector_(selector);
                  }
 
@@ -177,6 +190,7 @@ unarySend      = receiver:operand ws tail:unaryTail? {
 binaryMessage  = ws selector:binarySelector ws arg:(unarySend / operand) {
                      return smalltalk.SendNode._new()
                             ._position_((line()).__at(column()))
+                            ._source_(text())
                             ._selector_(selector)
                             ._arguments_([arg]);
                  }
@@ -209,6 +223,7 @@ keywordMessage = ws pairs:(pair:keywordPair ws {return pair;})+ {
                       }
                       return smalltalk.SendNode._new()
                              ._position_((line()).__at(column()))
+                             ._source_(text())
                              ._selector_(selector.join(""))
                              ._arguments_(args);
                  }
@@ -227,6 +242,7 @@ cascade        = ws send:(keywordSend / binarySend) messages:(ws ";" ws mess:mes
                      }
                      return smalltalk.CascadeNode._new()
                             ._position_((line()).__at(column()))
+                            ._source_(text())
                             ._receiver_(send._receiver())
                             ._nodes_(cascade);
                  }
@@ -234,13 +250,14 @@ cascade        = ws send:(keywordSend / binarySend) messages:(ws ";" ws mess:mes
 jsStatement    = "<" val:((">>" {return ">";} / [^>])*) ">" {
                      return smalltalk.JSStatementNode._new()
                             ._position_((line()).__at(column()))
-                            ._source_(val.join(""));
+                            ._source_(val.join(""))
                  }
 
 
 method         = ws pattern:(keywordPattern / binaryPattern / unaryPattern) ws sequence:sequence? ws {
                       return smalltalk.MethodNode._new()
                              ._position_((line()).__at(column()))
+                             ._source_(text())
                              ._selector_(pattern[0])
                              ._arguments_(pattern[1])
                              ._nodes_([sequence]);