Parser.st
changeset 1499 69439abfdb93
parent 1495 63d2a1a94504
child 1507 bd29313cd901
--- a/Parser.st	Fri Mar 19 14:14:20 2004 +0100
+++ b/Parser.st	Fri Mar 19 14:20:32 2004 +0100
@@ -2166,13 +2166,18 @@
 !
 
 checkSelector:selector inClass:cls
-    "check wether a method with selector exists in class cls an
-     that the methos is not obsolete.
+    "check wether a method with selector exists in class cls and
+     that the method is not obsolete.
+     If cls is nil, check all classes for the selector.
      Return an error string on error or nil on success"
 
     |err mthd implementor implementors|
 
     cls isNil ifTrue:[
+        SystemBrowser isNil ifTrue:[
+            ^ nil
+        ].
+        "beware, this is sort of slow, especially for the SyntaxHighlighter"
         implementors := SystemBrowser 
                          findImplementorsOf:selector
                          in:(Smalltalk allClasses)
@@ -2180,15 +2185,19 @@
         implementors size == 0 ifTrue:[
             ^ 'is nowhere implemented'
         ].
+
+        (implementors conform:[:eachMethod| eachMethod isObsolete]) ifTrue:[
+            ^ 'each implementation of this selector in the system is deprecated'
+        ].
         ^ nil
     ].
 
     mthd := cls lookupMethodFor:selector.
     mthd isNil ifTrue:[
         cls == Boolean ifTrue:[
-            mthd := True lookupMethodFor:selector.
+            mthd := True compiledMethodAt:selector.
             mthd isNil ifTrue:[
-                mthd := False lookupMethodFor:selector.
+                mthd := False compiledMethodAt:selector.
             ].
         ]
     ].
@@ -2199,9 +2208,14 @@
             err := 'is not implemented'
         ].
     ] ifFalse:[
-        mthd isObsolete ifTrue:[
+        (mthd sends:#shouldNotImplement) ifTrue:[
+            err := 'is not (should not be) implemented'
+        ] ifFalse:[(cls ~~ classToCompileFor and:[mthd sends:#subclassResponsibility]) ifTrue:[
+            "methods in abstract classes may send messages to abstract methods in the same class"
+            err := 'is subclassResponsibility'
+        ] ifFalse:[mthd isObsolete ifTrue:[
             err := 'is deprecated'.
-        ].
+        ]]].
     ].
     ^ err.
 !
@@ -2833,23 +2847,26 @@
      has the same name as a variable, cannot be understood or is obsolete.
      Simple, but catches many typos"
 
-    |err sym rec names recType selClass newSelector nm nowhereImplemented pos1 pos2 canDefine|
-
-    canDefine := false.
-
-    pos1 := posVector first start.
-    pos2 := posVector last stop.
+    |isSyntaxHighlighter err selectorSymbol rec names recType selClass newSelector nm nowhereImplemented 
+     pos1 pos2 canDefine|
+
+    isSyntaxHighlighter := self isSyntaxHighlighter.
 
     "
      if compiling lazy, or errors are to be ignored, or there
      is no requestor, do not check
     "
     (LazyCompilation == true) ifTrue:[^ aSelectorString].
-    self isSyntaxHighlighter ifFalse:[
+    isSyntaxHighlighter ifFalse:[
         (ignoreErrors or:[ignoreWarnings]) ifTrue:[^ aSelectorString].
         (requestor isNil or:[requestor isStream]) ifTrue:[^ aSelectorString].
     ].
 
+    canDefine := false.
+
+    pos1 := posVector first start.
+    pos2 := posVector last stop.
+
     aSelectorString = '#' ifTrue:[
         self warnPossibleIncompatibility:'''#'' might not be a valid selector in other smalltalk systems' position:pos1 to:pos2.
     ].
@@ -2860,11 +2877,11 @@
     "
     nowhereImplemented := false.
 
-    sym := aSelectorString asSymbolIfInterned.
-    sym isNil ifTrue:[
+    selectorSymbol := aSelectorString asSymbolIfInterned.
+    selectorSymbol isNil ifTrue:[
         nowhereImplemented := true.
 "/    ] ifFalse:[
-"/        nowhereImplemented := (self implementedInAnyClass:sym) not.
+"/        nowhereImplemented := (self implementedInAnyClass:selectorSymbol) not.
     ].
 
     nowhereImplemented ifTrue:[
@@ -2875,12 +2892,11 @@
         "
         ((methodVarNames notNil and:[methodVarNames includes:aSelectorString])
           or:[(methodArgNames notNil and:[methodArgNames includes:aSelectorString])
-          or:[(classToCompileFor notNil
-               and:[((names := self classesInstVarNames) notNil and:[names includes:aSelectorString])])
-          or:[(classToCompileFor notNil
-                and:[((names := self classesClassInstVarNames) notNil and:[names includes:aSelectorString])])
-          or:[classToCompileFor notNil 
-               and:[((names := self classesClassVarNames) notNil and:[names includes:aSelectorString])]]]]]) ifTrue:[
+          or:[classToCompileFor notNil
+              and:[((names := self classesInstVarNames) notNil and:[names includes:aSelectorString])
+                   or:[((names := self classesClassInstVarNames) notNil and:[names includes:aSelectorString])
+                   or:[(names := self classesClassVarNames) notNil and:[names includes:aSelectorString]
+        ]]]]]) ifTrue:[
             err := ' is currently nowhere implemented ..
 .. but a variable with that name is defined. 
 
@@ -2891,7 +2907,8 @@
         receiver notNil ifTrue:[
             selClass := self typeOfNode:receiver.
             selClass notNil ifTrue:[
-                err := self checkSelector:sym inClass:selClass.
+                "this could be performed if selClass isNil, but it is too slow"
+                err := self checkSelector:selectorSymbol inClass:selClass.
             ].
 
             (receiver isConstant or:[receiver isBlock]) ifTrue:[
@@ -2933,7 +2950,7 @@
                     classToCompileFor allSubclassesDo:[:eachSubclass |
                         subErr isNil ifTrue:[
                             selClass := eachSubclass.
-                            subErr := self checkSelector:sym inClass:selClass.     
+                            subErr := self checkSelector:selectorSymbol inClass:selClass.     
                         ].
                     ].   
                     subErr notNil ifTrue:[
@@ -2950,13 +2967,13 @@
                 err notNil ifTrue:[
                     classToCompileFor isMeta ifTrue:[
                         err := err, ' for the classes class'.
-                        (self checkSelector:sym inClass:classToCompileFor) isNil ifTrue:[
+                        (self checkSelector:selectorSymbol inClass:classToCompileFor) isNil ifTrue:[
                             err := err, '...\\...but its implemented for the class itself. You probably do not want the #class message here.'.
                             err := err withCRs.
                         ].
                     ] ifFalse:[
                         err := err, ' for my class'.
-                        (self checkSelector:sym inClass:classToCompileFor) isNil ifTrue:[
+                        (self checkSelector:selectorSymbol inClass:classToCompileFor) isNil ifTrue:[
                             err := err, '...\\...but its implemented for instances. You may want to remove the #class message.'.
                             err := err withCRs.
                         ].
@@ -2966,12 +2983,12 @@
                 "if it is an uninitialized variable ..."
                 ((modifiedLocalVars isNil or:[(modifiedLocalVars includes:receiver name) not])
                  and:[hasPrimitiveCode not
-                 and:[ currentBlock isNil
+                 and:[currentBlock isNil
                  and:[alreadyWarnedUninitializedVars isNil 
                       or:[(alreadyWarnedUninitializedVars includes:receiver name) not]]]]) 
                 ifTrue:[
-                    ((#(at: at:put: basicAt: basicAt:put:) includes:sym) 
-                     or:[(nil respondsTo:sym) not])ifTrue:[
+                    ((#(at: at:put: basicAt: basicAt:put:) includes:selectorSymbol) 
+                     or:[(nil respondsTo:selectorSymbol) not])ifTrue:[
                         "/ avoid trouble in miniTalk
                         "/ during bootstrap
                         nm := receiver name.    
@@ -2986,7 +3003,7 @@
                     ]
                 ]
             ] ifFalse:[
-                err notNil ifTrue:[
+                (err notNil and:[selClass notNil]) ifTrue:[
                     err := err, ' (message to ' , selClass nameWithArticle , ')'.
                 ].
             ]]]]]].
@@ -3013,7 +3030,7 @@
             ].
         ].
         Text notNil ifTrue:[
-            err := '"' , aSelectorString allBold "allItalic" , '" ', err
+            err := '"' , aSelectorString allBold, '" ', err
         ] ifFalse:[
             err := aSelectorString , ' ', err
         ].
@@ -3021,7 +3038,7 @@
         (selector = aSelectorString and:[ receiver isSelf]) ifTrue:[
             ^ aSelectorString
         ].
-        self isSyntaxHighlighter ifTrue:[
+        isSyntaxHighlighter ifTrue:[
             posVector do:[:p |
                 self markUnknownIdentifierFrom:(p start) to:(p stop).
             ].
@@ -7437,7 +7454,7 @@
 !Parser class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libcomp/Parser.st,v 1.416 2004-03-16 16:10:00 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libcomp/Parser.st,v 1.417 2004-03-19 13:20:32 stefan Exp $'
 ! !
 
 Parser initialize!