ParseNodeValidator.st
changeset 2611 42a3145f3ff5
parent 2600 d3d8ebf7b07f
child 2622 3a766e3136fa
--- a/ParseNodeValidator.st	Wed Jul 27 17:00:21 2011 +0200
+++ b/ParseNodeValidator.st	Wed Jul 27 17:01:34 2011 +0200
@@ -1,7 +1,7 @@
 "{ Package: 'stx:libcomp' }"
 
 ParseNodeVisitor subclass:#ParseNodeValidator
-	instanceVariableNames:'stack'
+	instanceVariableNames:'stack source'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'System-Compiler-Support'
@@ -28,11 +28,11 @@
 
 !ParseNodeValidator class methodsFor:'validation'!
 
-validate: aParseNode
+validate: aParseNode source: source
 
-    ^self basicNew validate: aParseNode
+    ^self basicNew validate: aParseNode source: source
 
-    "Created: / 20-07-2011 / 20:31:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Created: / 27-07-2011 / 13:43:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 validateImage
@@ -49,7 +49,9 @@
             Transcript nextPut:$..
             cls methodsDo:[:mth|
                 [ 
-                    self validate: (Parser parseMethod: mth source) tree 
+                    | src |
+                    src := mth source.
+                    self validate: (Parser parseMethod: src) tree source: src.
                 ] on: Error do:[:ex|
                     Transcript 
                         cr;
@@ -69,39 +71,45 @@
 
 !ParseNodeValidator methodsFor:'validation'!
 
-validate: tree
+validate: tree source: src
 
     tree isNil ifTrue:[^self].
 
+    source := src.
     stack := Stack with: nil.
 
     ^self visit: tree
 
-    "Created: / 20-07-2011 / 20:31:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Created: / 27-07-2011 / 13:43:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+validateNode:node 
+
+    self assert: node startPosition isInteger.
+    self assert: node endPosition isInteger.
+    self assert: node parent == stack top
+
+    "Modified: / 27-07-2011 / 13:47:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !ParseNodeValidator methodsFor:'visiting'!
 
 visit:anObject 
-
-    | accept stmt |
-
-    accept := [:node|
-        self assert: node parent == stack top.
-        stack push: node.
-        node acceptVisitor:self.        
-        stack pop.        
-    ].
+    |accept stmt|
 
-    ^anObject isStatementNode ifTrue:[
-        stmt := anObject.
-        [ stmt isNil ] whileFalse:[
-            accept value: stmt.
-            stmt := stmt nextStatement.
-        ]
-    ] ifFalse:[
-        accept value: anObject.
-    ]
+    accept := 
+            [:node | 
+            stack push:node.
+            node acceptVisitor:self.
+            stack pop.
+            self validateNode:node. ].
+    ^ anObject isStatementNode 
+        ifTrue:
+            [ stmt := anObject.
+            [ stmt isNil ] whileFalse:
+                    [ accept value:stmt.
+                    stmt := stmt nextStatement. ] ]
+        ifFalse:[ accept value:anObject. ]
 
     "Created: / 25-07-2011 / 23:14:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
@@ -109,9 +117,9 @@
 !ParseNodeValidator class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libcomp/ParseNodeValidator.st,v 1.3 2011-07-25 22:35:11 vrany Exp $'
+    ^ '$Header: /cvs/stx/stx/libcomp/ParseNodeValidator.st,v 1.4 2011-07-27 15:01:34 vrany Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libcomp/ParseNodeValidator.st,v 1.3 2011-07-25 22:35:11 vrany Exp $'
+    ^ '$Header: /cvs/stx/stx/libcomp/ParseNodeValidator.st,v 1.4 2011-07-27 15:01:34 vrany Exp $'
 ! !