Parser.st
changeset 1683 faa80a7dac3d
parent 1675 7812281ecfbd
child 1685 bd86bb0dfb8c
--- a/Parser.st	Mon Feb 20 10:48:11 2006 +0100
+++ b/Parser.st	Mon Feb 20 10:48:21 2006 +0100
@@ -3638,6 +3638,102 @@
 
 !Parser methodsFor:'evaluating expressions'!
 
+evaluate:aStringOrStream
+    "return the result of evaluating aStringOrStream, errors are reported to requestor. 
+     Allow access to anObject as self and to its instVars (used in the inspector).
+     If logged is true, an entry is added to the change-file. If the failBlock argument
+     is non-nil, it is evaluated if an error occurs.
+     Finally, compile specifies if the string should be compiled down to 
+     bytecode or instead be interpreted from the parseTree.
+     The first should be done for doIts etc, where a readable walkback is
+     required.
+     The latter is better done for constants, styleSheet and resource
+     reading and simple sends, where the overhead of compilation is bigger
+     than the interpretation overhead."
+
+    ^ self
+        evaluate:aStringOrStream 
+        in:nil 
+        receiver:nil 
+        notifying:requestor 
+        logged:logged 
+        ifFail:[ self error:'error in eval' ] 
+        compile:false 
+        checkForEndOfInput:true
+!
+
+evaluate:aStringOrStream ifFail:failBlock
+    "return the result of evaluating aStringOrStream, errors are reported to requestor. 
+     Allow access to anObject as self and to its instVars (used in the inspector).
+     If logged is true, an entry is added to the change-file. If the failBlock argument
+     is non-nil, it is evaluated if an error occurs.
+     Finally, compile specifies if the string should be compiled down to 
+     bytecode or instead be interpreted from the parseTree.
+     The first should be done for doIts etc, where a readable walkback is
+     required.
+     The latter is better done for constants, styleSheet and resource
+     reading and simple sends, where the overhead of compilation is bigger
+     than the interpretation overhead."
+
+    ^ self
+        evaluate:aStringOrStream 
+        in:nil 
+        receiver:nil 
+        notifying:requestor 
+        logged:logged 
+        ifFail:failBlock 
+        compile:false 
+        checkForEndOfInput:true
+!
+
+evaluate:aStringOrStream in:aContext receiver:anObject
+    "return the result of evaluating aStringOrStream, errors are reported to requestor. 
+     Allow access to anObject as self and to its instVars (used in the inspector).
+     If logged is true, an entry is added to the change-file. If the failBlock argument
+     is non-nil, it is evaluated if an error occurs.
+     Finally, compile specifies if the string should be compiled down to 
+     bytecode or instead be interpreted from the parseTree.
+     The first should be done for doIts etc, where a readable walkback is
+     required.
+     The latter is better done for constants, styleSheet and resource
+     reading and simple sends, where the overhead of compilation is bigger
+     than the interpretation overhead."
+
+    ^ self
+        evaluate:aStringOrStream 
+        in:aContext 
+        receiver:anObject 
+        notifying:requestor 
+        logged:logged 
+        ifFail:[ self error:'error in eval' ] 
+        compile:false 
+        checkForEndOfInput:true
+!
+
+evaluate:aStringOrStream in:aContext receiver:anObject ifFail:failBlock
+    "return the result of evaluating aStringOrStream, errors are reported to requestor. 
+     Allow access to anObject as self and to its instVars (used in the inspector).
+     If logged is true, an entry is added to the change-file. If the failBlock argument
+     is non-nil, it is evaluated if an error occurs.
+     Finally, compile specifies if the string should be compiled down to 
+     bytecode or instead be interpreted from the parseTree.
+     The first should be done for doIts etc, where a readable walkback is
+     required.
+     The latter is better done for constants, styleSheet and resource
+     reading and simple sends, where the overhead of compilation is bigger
+     than the interpretation overhead."
+
+    ^ self
+        evaluate:aStringOrStream 
+        in:aContext 
+        receiver:anObject 
+        notifying:requestor 
+        logged:logged 
+        ifFail:failBlock 
+        compile:false 
+        checkForEndOfInput:true
+!
+
 evaluate:aStringOrStream in:aContext receiver:anObject notifying:requestor logged:logged ifFail:failBlock compile:compile
     "return the result of evaluating aStringOrStream, errors are reported to requestor. 
      Allow access to anObject as self and to its instVars (used in the inspector).
@@ -3854,6 +3950,54 @@
     "Created: / 8.2.1997 / 19:34:44 / cg"
     "Modified: / 18.3.1999 / 18:25:40 / stefan"
     "Modified: / 6.2.2000 / 15:01:57 / cg"
+!
+
+evaluate:aStringOrStream receiver:anObject
+    "return the result of evaluating aStringOrStream, errors are reported to requestor. 
+     Allow access to anObject as self and to its instVars (used in the inspector).
+     If logged is true, an entry is added to the change-file. If the failBlock argument
+     is non-nil, it is evaluated if an error occurs.
+     Finally, compile specifies if the string should be compiled down to 
+     bytecode or instead be interpreted from the parseTree.
+     The first should be done for doIts etc, where a readable walkback is
+     required.
+     The latter is better done for constants, styleSheet and resource
+     reading and simple sends, where the overhead of compilation is bigger
+     than the interpretation overhead."
+
+    ^ self
+        evaluate:aStringOrStream 
+        in:nil 
+        receiver:anObject 
+        notifying:requestor 
+        logged:logged 
+        ifFail:[ self error:'error in eval' ] 
+        compile:false 
+        checkForEndOfInput:true
+!
+
+evaluate:aStringOrStream receiver:anObject ifFail:failBlock
+    "return the result of evaluating aStringOrStream, errors are reported to requestor. 
+     Allow access to anObject as self and to its instVars (used in the inspector).
+     If logged is true, an entry is added to the change-file. If the failBlock argument
+     is non-nil, it is evaluated if an error occurs.
+     Finally, compile specifies if the string should be compiled down to 
+     bytecode or instead be interpreted from the parseTree.
+     The first should be done for doIts etc, where a readable walkback is
+     required.
+     The latter is better done for constants, styleSheet and resource
+     reading and simple sends, where the overhead of compilation is bigger
+     than the interpretation overhead."
+
+    ^ self
+        evaluate:aStringOrStream 
+        in:nil 
+        receiver:anObject 
+        notifying:requestor 
+        logged:logged 
+        ifFail:failBlock 
+        compile:false 
+        checkForEndOfInput:true
 ! !
 
 !Parser methodsFor:'parsing'!
@@ -4065,6 +4209,7 @@
     | returnsSelf returnsBoolean returnsNonBooleanLiteral|
 
     ignoreWarnings ifTrue:[^ self].
+    parserFlags warnInconsistentReturnValues ifFalse:[^ self].
     returnedValues isNil ifTrue:[^ self].
 
     returnsBoolean := returnedValues contains:[:node | node isConstant and:[node value isBoolean]].
@@ -4075,6 +4220,7 @@
         (returnsNonBooleanLiteral or:[returnsSelf]) ifTrue:[
             self 
                 warning:'Possible Error Warning:\\Method returns both boolean and non-boolean values.' withCRs
+                doNotShowAgainAction:[ ParserFlags warnInconsistentReturnValues:false ]
                 position:1 to:tokenPosition
         ]
     ].
@@ -4341,6 +4487,7 @@
                     (methodArgNames includes:tokenName) ifTrue:[
                         self 
                             warning:'local variable "' , tokenName allBold , '" hides method argument.'
+                            doNotShowAgainAction:[ ParserFlags warnHiddenVariables:false ]
                             position:tokenPosition to:pos2
                     ]
                 ].
@@ -4349,10 +4496,12 @@
                         classToCompileFor isMeta ifTrue:[
                             self 
                                 warning:'local variable "' , tokenName allBold , '" hides class instance variable.'
+                                doNotShowAgainAction:[ ParserFlags warnHiddenVariables:false ]
                                 position:tokenPosition to:pos2
                         ] ifFalse:[
                             self 
                                 warning:'local variable "' , tokenName allBold , '" hides instance variable.'
+                                doNotShowAgainAction:[ ParserFlags warnHiddenVariables:false ]
                                 position:tokenPosition to:pos2
                         ]
                     ]
@@ -4786,7 +4935,16 @@
     |val|
 
     (tokenType == #Nil) ifTrue:[
-        ^ nil
+        self warnPossibleIncompatibility:'nil in array constant is interpreted as #nil (symbol) in other smalltalks' position:tokenPosition to:tokenPosition+token size - 1.
+        ^ tokenValue
+    ].
+    (tokenType == #True) ifTrue:[
+        self warnPossibleIncompatibility:'true in array constant is interpreted as #true (symbol) in other smalltalks' position:tokenPosition to:tokenPosition+token size - 1.
+        ^ tokenValue
+    ].
+    (tokenType == #False) ifTrue:[
+        self warnPossibleIncompatibility:'false in array constant is interpreted as #false (symbol) in other smalltalks' position:tokenPosition to:tokenPosition+token size - 1.
+        ^ tokenValue
     ].
     ((tokenType == #Integer) 
     or:[tokenType == #Float]) ifTrue:[
@@ -4799,12 +4957,6 @@
     (tokenType == #Character) ifTrue:[
         ^ tokenValue
     ].
-    (tokenType == #True) ifTrue:[
-        ^ true
-    ].
-    (tokenType == #False) ifTrue:[
-        ^ false
-    ].
     (tokenType == #Error) ifTrue:[
         ^ ParseErrorSignal raise.
     ].
@@ -4855,7 +5007,7 @@
         val := self qualifiedName.
         val := QualifiedName for:val name.
         ^ val
-    ].
+    ].                         
     (tokenType == #Symbol) ifTrue:[
         parseForCode ifFalse:[
             self rememberSymbolUsed:tokenValue.
@@ -5010,7 +5162,8 @@
                 self nextToken
             ] ifFalse:[
                 sel := '-'.
-                token := tokenValue := tokenValue negated
+                token := tokenValue := tokenValue negated.
+                tokenPosition := tokenPosition + 1. "/ to skip the sign
             ]
         ].
 
@@ -5036,7 +5189,6 @@
             self rememberSelectorUsed:sel receiver:receiver
         ].
         receiver := expr.   "/ for next message
-
     ].
     ^ receiver
 
@@ -5750,7 +5902,6 @@
     ].
 
     tokenType == #HashHashLeftParen ifTrue:[
-self halt.
         self nextToken.
         parserFlags allowDolphinExtensions == true ifFalse:[
             self parseError:'non-Standard Dolphin extension: ##(..). Enable in settings.' position:pos to:tokenPosition.
@@ -6309,8 +6460,14 @@
     ].
     val := ConstantNode type:tokenType value:tokenValue.
 
-    tokenValue isSymbol ifTrue:[
+    ((tokenType == #Symbol) or:[tokenType == #ESSymbol]) ifTrue:[
         self markSymbolFrom:tokenPosition to:tokenPosition+tokenValue size-1.
+    ] ifFalse:[
+        tokenType == #String ifTrue:[
+            self markStringFrom:pos to:source position1Based-1.
+        ] ifFalse:[
+            self markConstantFrom:pos to:source position1Based-1.
+        ].
     ].
 
     self nextToken.
@@ -8052,7 +8209,7 @@
 !Parser class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libcomp/Parser.st,v 1.479 2006-02-17 12:04:28 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libcomp/Parser.st,v 1.480 2006-02-20 09:48:21 cg Exp $'
 ! !
 
 Parser initialize!