Simplify privacy stuff to make redirection from WrappedMethod easier.
authorStefan Vogel <sv@exept.de>
Fri, 23 Jan 1998 18:49:18 +0100
changeset 3216 e0f3f49118ed
parent 3215 dbb2ee7a5cb9
child 3217 568eaf667294
Simplify privacy stuff to make redirection from WrappedMethod easier.
Method.st
--- a/Method.st	Fri Jan 23 18:28:57 1998 +0100
+++ b/Method.st	Fri Jan 23 18:49:18 1998 +0100
@@ -111,7 +111,7 @@
 "
     ST/X includes an EXPERIMENTAL implementation of method privacy.
     Individual methods may be set to private or protected via the
-    #setPrivate and #setProtected messages. Also, categories may be
+    #privacy:#private and #privacy:#protected messages. Also, categories may be
     filedIn as a whole as private using #privateMethodsFor: or as
     protected using #protectedMethodsFor: instead of the well known #methodsFor:.
 
@@ -628,16 +628,9 @@
      This is EXPERIMENTAL - and being evaluated for usability.
      It may change or even vanish (if it shows to be not useful)."
 
-%{  /* NOCONTEXT */
-#if defined(F_IGNORED) && defined(M_PRIVACY)
-    INT f = __intVal(__INST(flags));
-
-    if ((f & M_PRIVACY) == F_IGNORED) {
-	RETURN (true);
-    }
-#endif
-%}.
-    ^ false
+    ^ self privacy == #ignored
+
+    "Modified: / 23.1.1998 / 15:23:02 / stefan"
 !
 
 isPrivate
@@ -652,18 +645,9 @@
      This is EXPERIMENTAL - and being evaluated for usability.
      It may change or even vanish (if it shows to be not useful)."
 
-%{  /* NOCONTEXT */
-    /* I made this a primitive to get the define constant from stc.h */
-
-#if defined(F_PRIVATE) && defined(M_PRIVACY)
-    INT f = __intVal(__INST(flags));
-
-    if ((f & M_PRIVACY) == F_PRIVATE) {
-	RETURN (true);
-    }
-#endif
-%}.
-    ^ false
+    ^ self privacy == #private
+
+    "Modified: / 23.1.1998 / 15:23:13 / stefan"
 !
 
 isProtected
@@ -679,18 +663,9 @@
      This is EXPERIMENTAL - and being evaluated for usability.
      It may change or even vanish (if it shows to be not useful)."
 
-%{  /* NOCONTEXT */
-    /* I made this a primitive to get the define constant from stc.h */
-
-#if defined(F_CLASSPRIVATE) && defined(M_PRIVACY)
-    INT f = __intVal(__INST(flags));
-
-    if ((f & M_PRIVACY) == F_CLASSPRIVATE) {
-	RETURN (true);
-    }
-#endif
-%}.
-    ^ false
+    ^ self privacy == #protected
+
+    "Modified: / 23.1.1998 / 15:23:27 / stefan"
 !
 
 isPublic
@@ -703,30 +678,9 @@
      This is EXPERIMENTAL - and being evaluated for usability.
      It may change or even vanish (if it shows to be not useful)."
 
-%{  /* NOCONTEXT */
-    /* I made this a primitive to get the define constant from stc.h */
-
-#if defined(M_PRIVACY) && (defined(F_PRIVATE) || defined(F_CLASSPRIVATE) || defined(F_IGNORED))
-
-    INT f = __intVal(__INST(flags));
-# ifdef F_PRIVATE
-    if ((f & M_PRIVACY) == F_PRIVATE) {
-	RETURN (false);
-    }
-# endif
-# ifdef F_CLASSPRIVATE
-    if ((f & M_PRIVACY) == F_CLASSPRIVATE) {
-	RETURN (false);
-    }
-# endif
-# ifdef F_IGNORED
-    if ((f & M_PRIVACY) == F_IGNORED) {
-	RETURN (false);
-    }
-# endif
-#endif
-%}.
-    ^ true
+    ^ self privacy == #public
+
+    "Modified: / 23.1.1998 / 15:23:40 / stefan"
 !
 
 isRestricted
@@ -766,12 +720,34 @@
      This is EXPERIMENTAL - and being evaluated for usability.
      It may change or even vanish (if it shows to be not useful)."
 
-    self isPrivate ifTrue:[^ #private].
-    self isProtected ifTrue:[^ #protected].
-    self isIgnored ifTrue:[^ #ignored].
+%{  /* NOCONTEXT */
+    /* I made this a primitive to get the define constant from stc.h */
+
+#if defined(M_PRIVACY) && (defined(F_PRIVATE) || defined(F_CLASSPRIVATE) || defined(F_IGNORED))
+
+    INT f = __intVal(__INST(flags));
+    switch (f & M_PRIVACY) {
+
+# ifdef F_PRIVATE
+    case F_PRIVATE:
+        RETURN (@symbol(private));
+        break;
+# endif
+# ifdef F_CLASSPRIVATE
+    case F_CLASSPRIVATE:
+        RETURN (@symbol(protected));
+        break;
+# endif
+# ifdef F_IGNORED
+    case F_IGNORED:
+        RETURN (@symbol(ignored));
+        break;
+# endif
+    }
+#endif
+%}.
+
     ^ #public
-
-    "Modified: 27.8.1995 / 22:53:31 / claus"
 !
 
 privacy:aSymbol
@@ -787,30 +763,20 @@
      This is EXPERIMENTAL - and being evaluated for usability.
      It may change or even vanish (if it shows to be not useful)."
 
-    aSymbol == #public ifTrue:[
-	"/
-	"/ no need to flush, if changing from private to public
-	"/
-	self isIgnored ifFalse:[
-	    ^ self setToPublic
-	].
-	self setToPublic
-    ] ifFalse:[
-	aSymbol == #private ifTrue:[
-	    self setToPrivate
-	] ifFalse:[
-	    aSymbol == #protected ifTrue:[
-		self setToProtected
-	    ] ifFalse:[
-		aSymbol == #ignored ifTrue:[
-		    self setToIgnored
-		]
-	    ]
-	]
-    ].
-    ObjectMemory flushCaches.
-
-    "Modified: 27.8.1995 / 22:58:08 / claus"
+    |old|
+
+    old := self privacy.
+    self setPrivacy:aSymbol.
+
+    "/
+    "/ no need to flush, if changing from private to public
+    "/
+    (aSymbol == #public and:[old ~~ #ignored]) ifFalse:[
+        ObjectMemory flushCaches.
+    ]
+
+    "Modified: / 27.8.1995 / 22:58:08 / claus"
+    "Modified: / 23.1.1998 / 15:19:07 / stefan"
 !
 
 restricted:aBoolean
@@ -851,34 +817,11 @@
     "Created: 7.11.1995 / 20:36:19 / stefan"
 !
 
-setToIgnored
-    "make this method be ignored w.r.t. method lookup.
-     (i.e. setting a method to #ignored, and sending that selector,
-      leads to either the superclasses implementation to be called, 
-      or a doesNotUnderstand exception to be raised)
-
-     Notice: ignored methods are a nonstandard feature, not supported
-     by other smalltalk implementations and not specified in the ANSI spec.
-
-     This is EXPERIMENTAL - and being evaluated for usability.
-     It may change or even vanish (if it shows to be not useful)."
-
-%{  /* NOCONTEXT */
-    INT f = __intVal(__INST(flags));
-
-#if defined(F_IGNORED) && defined(M_PRIVACY)
-    f = (f & ~M_PRIVACY) | F_IGNORED;
-#endif
-    __INST(flags) = __MKSMALLINT(f);
-%}
-!
-
-setToPrivate
-    "set the flag bit stating that this method is private. 
-     Execution of the receiver will only be allowed for self/super-sends from 
-     the class, superclasses or subclasses (or via #perform).
-     If a private method is called by some other class, a runtime
-     error (PrivateMethodSignal) is raised.
+setPrivacy:aSymbol
+    "set the methods access rights (privacy) from a symbol;
+     Currently, this must be one of #private, #protected, #public or #ignored.
+     #setPrivacy: simply sets the attribute. When changing methods, that 
+     have already been called, #privacy: should be used.
 
      Notice: method privacy is a nonstandard feature, not supported
      by other smalltalk implementations and not specified in the ANSI spec.
@@ -890,70 +833,31 @@
      It may change or even vanish (if it shows to be not useful)."
 
 %{  /* NOCONTEXT */
-    /* I made this a primitive to get the define constant from stc.h */
-
-#if defined(F_PRIVATE) && defined(M_PRIVACY)
+
+#if defined(M_PRIVACY)
     INT f = __intVal(__INST(flags));
-
-    f = (f & ~M_PRIVACY) | F_PRIVATE;
+    INT p;
+
+    if (aSymbol == @symbol(public))
+        p = 0;
+    else if (aSymbol == @symbol(private))
+        p = F_PRIVATE;
+    else if (aSymbol == @symbol(protected))
+        p = F_CLASSPRIVATE;
+    else if (aSymbol == @symbol(ignored))
+        p = F_IGNORED;
+    else
+        RETURN(false);  /* illegal symbol */
+        
+
+    f = (f & ~M_PRIVACY) | p;
     __INST(flags) = __MKSMALLINT(f);
 #endif
-%}
-!
-
-setToProtected
-    "set the flag bit stating that this method is protected. 
-     Execution of the receiver will only be allowed for self sends from
-     the class or superclasses. (or via #perform).
-     If a private method is called by some other class, a runtime
-     error (PrivateMethodSignal) is raised.
-
-     Notice: method privacy is a nonstandard feature, not supported
-     by other smalltalk implementations and not specified in the ANSI spec.
-     If at all, use it for debugging purposes, to catch messagesends
-     which are not supposed to be sent by others.
-     (especially, if working in a team, while integrating other peoples work)
-
-     This is EXPERIMENTAL - and being evaluated for usability.
-     It may change or even vanish (if it shows to be not useful)."
-
-%{  /* NOCONTEXT */
-    /* I made this a primitive to get the define constant from stc.h */
-
-#if defined(F_CLASSPRIVATE) && defined(M_PRIVACY)
-    INT f = __intVal(__INST(flags));
-
-    f = (f & ~M_PRIVACY) | F_CLASSPRIVATE;
-    __INST(flags) = __MKSMALLINT(f);
-#endif
-%}
-!
-
-setToPublic
-    "clear any privacy/ignoreFlag of the receiver. 
-     The receiver may be executed by any send. 
-     This is the default anyway for methods, and how other smalltalk
-     implementations treat all methods.
-
-     Notice: method privacy is a nonstandard feature, not supported
-     by other smalltalk implementations and not specified in the ANSI spec.
-     If at all, use it for debugging purposes, to catch messagesends
-     which are not supposed to be sent by others.
-     (especially, if working in a team, while integrating other peoples work)
-
-     This is EXPERIMENTAL - and being evaluated for usability.
-     It may change or even vanish (if it shows to be not useful)."
-
-%{  /* NOCONTEXT */
-    /* I made this a primitive to get the define constant from stc.h */
-
-#ifdef M_PRIVACY
-    INT f = __intVal(__INST(flags));
-
-    f = f & ~M_PRIVACY;
-    __INST(flags) = __MKSMALLINT(f);
-#endif
-%}
+
+%}.
+    ^ true
+
+    "Modified: 27.8.1995 / 22:58:08 / claus"
 ! !
 
 !Method methodsFor:'binary storage'!
@@ -1809,59 +1713,58 @@
     privInfo := ''.
 
     self isWrapped ifTrue:[
-	(MessageTracer isCounting:self) ifTrue:[
-	    (MessageTracer isCountingMemoryUsage:self) ifTrue:[
-		moreInfo := moreInfo , 
-		     ' (mem usage ' , (MessageTracer memoryUsageOfMethod:self) printString , ' Bytes)'.
-	    ] ifFalse:[
-		moreInfo := moreInfo , 
-		     ' (called ' , (MessageTracer executionCountOfMethod:self) printString , ' times)'.
-	    ]
-	] ifFalse:[
-	    (MessageTracer isTiming:self) ifTrue:[
-		i := MessageTracer executionTimesOfMethod:self.
-		i notNil ifTrue:[
-		    moreInfo := moreInfo , 
-				' (avg: ' , (i at:#avgTime) printString,
-				' min: ' , (i at:#minTime) printString , 
-				' max: ' , (i at:#maxTime) printString ,
-				' cnt: ' , (i at:#count) printString , ')'
-		].
-	    ] ifFalse:[
-		moreInfo := ' !!'
-	    ]
-	].
-	p := self originalMethod privacy
-    ] ifFalse:[
-	p := self privacy
-    ].
+        (MessageTracer isCounting:self) ifTrue:[
+            (MessageTracer isCountingMemoryUsage:self) ifTrue:[
+                moreInfo := moreInfo , 
+                     ' (mem usage ' , (MessageTracer memoryUsageOfMethod:self) printString , ' Bytes)'.
+            ] ifFalse:[
+                moreInfo := moreInfo , 
+                     ' (called ' , (MessageTracer executionCountOfMethod:self) printString , ' times)'.
+            ]
+        ] ifFalse:[
+            (MessageTracer isTiming:self) ifTrue:[
+                i := MessageTracer executionTimesOfMethod:self.
+                i notNil ifTrue:[
+                    moreInfo := moreInfo , 
+                                ' (avg: ' , (i at:#avgTime) printString,
+                                ' min: ' , (i at:#minTime) printString , 
+                                ' max: ' , (i at:#maxTime) printString ,
+                                ' cnt: ' , (i at:#count) printString , ')'
+                ].
+            ] ifFalse:[
+                moreInfo := ' !!'
+            ]
+        ].
+    ]. 
+    p := self privacy.
 
     p ~~ #public ifTrue:[
-	privInfo := (' (* ' , p , ' *)') asText emphasizeAllWith:#italic.
+        privInfo := (' (* ' , p , ' *)') asText emphasizeAllWith:#italic.
     ].
 
     self isInvalid ifTrue:[
-	moreInfo := ' (** not executable **)'.
+        moreInfo := ' (** not executable **)'.
     ].
 
     (self isLazyMethod not and:[self isUnloaded]) ifTrue:[
-	moreInfo := ' (** unloaded **)'
+        moreInfo := ' (** unloaded **)'
     ].
 
     privInfo size ~~ 0 ifTrue:[
-	moreInfo := privInfo , ' ' , moreInfo
+        moreInfo := privInfo , ' ' , moreInfo
     ].
 
     moreInfo size == 0 ifTrue:[^ selector].
 
     s := selector , moreInfo.
     self isInvalid ifTrue:[
-	s := s asText emphasizeAllWith:#color->Color red.
+        s := s asText emphasizeAllWith:#color->Color red.
     ].
     ^ s
 
-    "Created: 16.4.1996 / 20:11:12 / cg"
-    "Modified: 23.10.1996 / 21:01:57 / cg"
+    "Created: / 16.4.1996 / 20:11:12 / cg"
+    "Modified: / 23.10.1996 / 21:01:57 / cg"
+    "Modified: / 23.1.1998 / 13:15:15 / stefan"
 !
 
 whoString
@@ -2650,6 +2553,6 @@
 !Method class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Method.st,v 1.148 1998-01-12 18:21:41 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Method.st,v 1.149 1998-01-23 17:49:18 stefan Exp $'
 ! !
 Method initialize!