Parser.st
changeset 629 6dbcd3bb1c9d
parent 628 54fa351ac6be
child 636 0b9a84a006f3
--- a/Parser.st	Tue Oct 28 20:13:48 1997 +0100
+++ b/Parser.st	Sun Nov 02 18:50:20 1997 +0100
@@ -10,8 +10,6 @@
  hereby transferred.
 "
 
-'From Smalltalk/X, Version:3.2.1 on 25-oct-1997 at 9:36:52 pm'                  !
-
 Scanner subclass:#Parser
 	instanceVariableNames:'classToCompileFor selfValue contextToEvaluateIn selector
 		methodArgs methodArgNames methodVars methodVarNames tree
@@ -896,6 +894,45 @@
     "Modified: 14.2.1997 / 16:51:25 / cg"
 !
 
+checkMethod:aString in:aClass ignoreErrors:noErrors ignoreWarnings:noWarnings
+    "parse a method in a given class.
+     Return a parser (if ok), nil (empty) or #Error (syntax).
+     The parser can be queried for selector, receiver, args, locals,
+     used selectors, modified instvars, referenced classvars etc.
+     The noErrors and noWarnings arguments specify if error and warning 
+     messages should be sent to the Transcript or suppressed."
+
+    |parser tree|
+
+    aString isNil ifTrue:[^ nil].
+    parser := self for:(ReadStream on:aString) in:aClass.
+    noErrors ifTrue:[
+        parser ignoreErrors
+    ].
+    noWarnings ifTrue:[
+        parser ignoreWarnings
+    ].
+    tree := parser parseMethod.
+    (parser errorFlag or:[tree == #Error]) ifTrue:[^ nil].
+
+    ReadBeforeWrittenTester searchForReadBeforeWrittenIn:tree
+
+    "
+     self
+        checkMethod:'foo
+                        |local1 local2 local3|
+
+                        local1 := local2.
+                        ^ local3
+                    '
+        in:UndefinedObject 
+        ignoreErrors:true 
+        ignoreWarnings:true 
+    "
+
+    "Modified: / 30.10.1997 / 16:38:31 / cg"
+!
+
 parseExpression:aString
     "parse aString as an expression; 
      Return the parseTree (if ok), nil (for an empty string 
@@ -1721,9 +1758,9 @@
 
 defineAsUndeclaredVariable:aName
     "define varName as undeclared variable
-     (actually, it will be installed as a funny global named 'Undeclared:<name>').
+     (actually, it will be installed as a funny global named 'Undeclared:::<name>').
      You can browse for methods with undeclareds by searching for global accesses
-     to Undeclared::*."
+     to 'Undeclared:::*' (or use the search-undeclared item in the launchers menu)."
 
     |varName|
 
@@ -1732,10 +1769,10 @@
     "/ install as Undeclared:<name>, remember in Undeclared
 
     (Smalltalk includesKey:#Undeclared) ifFalse:[
-	Smalltalk at:#Undeclared put:(IdentitySet new).
+        Smalltalk at:#Undeclared put:(IdentitySet new).
     ].
     (Smalltalk at:#Undeclared) add:tokenName asSymbol.
-    varName := 'Undeclared:' , tokenName.
+    varName := (Smalltalk underclaredPrefix) , tokenName.
     varName := varName asSymbol.
     Smalltalk at:varName put:nil.
 
@@ -1743,7 +1780,7 @@
 
     ^ VariableNode type:#GlobalVariable name:varName
 
-    "Modified: 30.8.1997 / 02:16:17 / cg"
+    "Modified: / 31.10.1997 / 01:16:03 / cg"
 !
 
 findBestSelectorsFor:aString
@@ -4299,6 +4336,6 @@
 !Parser class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libcomp/Parser.st,v 1.149 1997-10-28 19:13:48 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libcomp/Parser.st,v 1.150 1997-11-02 17:50:20 cg Exp $'
 ! !
 Parser initialize!