Parser.st
changeset 4442 cf3be3b51fa9
parent 4440 d1d7238142f6
child 4445 e7ddd0229265
--- a/Parser.st	Sat Jun 08 19:13:07 2019 +0200
+++ b/Parser.st	Sun Jun 09 15:25:49 2019 +0200
@@ -2196,53 +2196,17 @@
     "Modified: / 22-10-2006 / 02:25:37 / cg"
 !
 
-make:anObject immutable:whichImmutableClass
-    "helper to optionally make Arrays, ByteArrays and Strings immutable."
+makeImmutable:anObject
+    "helper to optionally make Array-, ByteArray- and String literals immutable.
+     Creates and returns an immutable copy of the object"
 
     |newObject|
 
-    newObject := anObject copy.
-    whichImmutableClass notNil ifTrue:[
-        newObject changeClassTo:whichImmutableClass.
-    ].
+    newObject := anObject shallowCopy.
     newObject beImmutable.
     ^ newObject
-!
-
-makeImmutableArray:anArray
-    "helper to optionally make an array immutable."
-
-    ^ self make:anArray immutable:ImmutableArray
-!
-
-makeImmutableByteArray:aByteArray
-    "helper to optionally make a byte array immutable."
-
-    ^ self make:aByteArray immutable:ImmutableByteArray
-!
-
-makeImmutableString:aString
-    "helper to optionally make a string immutable."
-
-    |width immutableStringClass|
-
-    (width := aString bitsPerCharacter) > 8 ifTrue:[
-        width > 16 ifTrue:[
-            immutableStringClass := (Smalltalk at:#ImmutableUnicode32String)
-        ] ifFalse:[
-            immutableStringClass := (Smalltalk at:#ImmutableUnicode16String)
-        ].
-    ] ifFalse:[
-        immutableStringClass := ImmutableString
-    ].
-
-    "/ a temporary hack, which will still work, 
-    "/ when the new immutable string classes are present.
-    immutableStringClass isNil ifTrue:[
-        "/ not yet avail: leave it as a regular, mutable string
-        ^ aString
-    ].
-    ^ self make:aString immutable:immutableStringClass
+
+    "Created: / 09-06-2019 / 15:18:58 / Claus Gittinger"
 ! !
 
 !Parser class methodsFor:'unparsing'!
@@ -6754,12 +6718,12 @@
     arr := elements asArray.
 
     parserFlags arraysAreImmutable ifTrue:[
-        ^ self makeImmutableArray:arr
+        ^ self makeImmutable:arr
     ].
     ^ arr
 
     "Modified: / 30-07-2013 / 19:33:43 / cg"
-    "Modified: / 08-06-2019 / 15:51:18 / Claus Gittinger"
+    "Modified: / 09-06-2019 / 15:23:27 / Claus Gittinger"
 !
 
 arrayConstant
@@ -6783,7 +6747,9 @@
         ^ tokenValue
     ].
     (tokenType == #String) ifTrue:[
-        parserFlags stringsAreImmutable ifTrue:[^ self makeImmutableString:tokenValue].
+        parserFlags stringsAreImmutable ifTrue:[
+            ^ self makeImmutable:tokenValue
+        ].
         ^ tokenValue
     ].
     (tokenType == #Character) ifTrue:[
@@ -6882,7 +6848,7 @@
     ^ ParseError raiseRequest.
 
     "Modified: / 22-08-2006 / 14:21:16 / cg"
-    "Modified: / 08-06-2019 / 15:50:01 / Claus Gittinger"
+    "Modified (format): / 09-06-2019 / 15:23:56 / Claus Gittinger"
 !
 
 arrayIndexingExpression
@@ -7131,9 +7097,11 @@
     newArray := ByteArray uninitializedNew:index.
     newArray replaceFrom:1 to:index with:bytes startingAt:1.
     parserFlags arraysAreImmutable ifTrue:[
-        ^ self class makeImmutableByteArray:newArray
+        ^ self makeImmutable:newArray
     ].
     ^ newArray
+
+    "Modified: / 09-06-2019 / 15:23:35 / Claus Gittinger"
 !
 
 degeneratedKeywordExpressionForSelector
@@ -8023,7 +7991,7 @@
     (tokenType == #RegexString) ifTrue:[
         |s const expr|
 
-        s := self makeImmutableString:tokenValue.
+        s := self makeImmutable:tokenValue.
         const := ConstantNode type:#String value:s from:tokenPosition to:tokenLastEndPosition.
         expr := MessageNode receiver:const selector:#'asRegex'.
         self nextToken.
@@ -8060,7 +8028,7 @@
     "Created: / 13-09-1995 / 12:50:50 / claus"
     "Modified: / 01-08-2011 / 12:04:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 26-07-2012 / 11:35:46 / cg"
-    "Modified: / 08-06-2019 / 15:49:12 / Claus Gittinger"
+    "Modified: / 09-06-2019 / 15:24:10 / Claus Gittinger"
 !
 
 primary_dolphinComputedLiteral
@@ -8687,7 +8655,7 @@
             "/ ImmutableStrings are experimental
             "/
             parserFlags stringsAreImmutable ifTrue:[
-                token := tokenValue := self makeImmutableString:tokenValue.
+                token := tokenValue := self makeImmutable:tokenValue.
             ].
         ].
     ].
@@ -8728,7 +8696,7 @@
 
     "Modified: / 21-08-2011 / 08:10:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 26-07-2012 / 11:37:44 / cg"
-    "Modified: / 15-02-2019 / 16:42:59 / Claus Gittinger"
+    "Modified: / 09-06-2019 / 15:24:17 / Claus Gittinger"
 !
 
 primary_squeakComputedArray
@@ -9023,7 +8991,7 @@
     "/ now make this a message send.
 
     parserFlags stringsAreImmutable ifTrue:[
-        collectedString := self makeImmutableString:collectedString.
+        collectedString := self makeImmutable:collectedString.
     ].
     receiver := ConstantNode type:#String value:collectedString from:pos1 to:pos2.
     node := MessageNode
@@ -9033,13 +9001,18 @@
     ^ node
 
     "Created: / 22-05-2019 / 20:58:24 / Claus Gittinger"
+    "Modified: / 09-06-2019 / 15:21:58 / Claus Gittinger"
 !
 
 typedArray:typeSymbol
     "parse a typed array's elements.
      This is an ST/X extension, which is not supported by other Smalltalk implementations.
-     For now, the support is disabled; enable with:
+     For now, the support is disabled by default; 
+     enable with:
         ParserFlags allowSTXExtendedArrayLiterals:true
+     or a pragma, like:
+        <pragma: +allowSTXExtendedArrayLiterals>
+        
      Typed literal arrays are written in scheme-style as:
         #u8( element... )   - unsigned 8-bit bytes (i.e. a regular ByteArray)
         #u16( element... )  - unsigned 16-bit shorts (i.e. a WordArray)
@@ -9057,8 +9030,6 @@
         #d( element... )    - same as f64(...)
     "
 
-    "literal bytearrays started with ST-80 R4 - byteArray constants are written as #[ ... ]"
-
     |idx containerType container elStream newArray elem pos1 pos2|
 
     idx := #( #u1 #u8 #u16 #u32 #u64
@@ -9114,10 +9085,12 @@
         self nextToken.
     ].
     newArray := elStream contents.
-"/    parserFlags arraysAreImmutable ifTrue:[
-"/        ^ self class makeImmutable:newArray
-"/    ].
+    parserFlags arraysAreImmutable ifTrue:[
+        ^ self makeImmutable:newArray.
+    ].
     ^ newArray
+
+    "Modified: / 09-06-2019 / 15:24:35 / Claus Gittinger"
 !
 
 unaryExpression
@@ -9972,7 +9945,7 @@
       <pragma: +functionCallSyntaxForBlockEvaluation>
     "
 
-    |type flagValue setterInParserFlags|
+    |type flagValue setterInParserFlags pagmaIsKnown|
 
     type := token.
     type ~= 'pragma:' ifTrue:[
@@ -9985,17 +9958,13 @@
         flagValue := (token = '+').
         self nextToken.
         (tokenType == #Identifier) ifTrue:[
-            setterInParserFlags := ('allow',token asUppercaseFirst) asMutator.
-            (
-                parserFlags class implements:setterInParserFlags
-"/            ( #(
-"/                    'arrayIndexSyntaxExtension'
-"/                    'STXSyntaxExtensions'
-"/                    'lazyValueExtension'
-"/                    'functionCallSyntaxForBlockEvaluation'
-"/                    "possibly add more here"
-"/               ) includes:token
-            ) ifTrue:[
+            setterInParserFlags := token asMutator.
+            pagmaIsKnown := parserFlags class implements:setterInParserFlags.
+            pagmaIsKnown ifFalse:[
+                setterInParserFlags := ('allow',token asUppercaseFirst) asMutator.
+                pagmaIsKnown := parserFlags class implements:setterInParserFlags.
+            ].    
+            pagmaIsKnown ifTrue:[
                 parserFlags perform:setterInParserFlags with:flagValue.
                 self nextToken.
                 self checkForClosingAngle.
@@ -10010,7 +9979,7 @@
     self parseError:'+/- expected'.
     ^ self
 
-    "Modified: / 09-02-2019 / 15:41:44 / Claus Gittinger"
+    "Modified: / 09-06-2019 / 15:06:45 / Claus Gittinger"
 !
 
 parsePrimitive
@@ -10721,12 +10690,10 @@
     "
 !
 
-makeImmutableArray:anArray
-    ^ self class makeImmutableArray:anArray
-!
-
-makeImmutableString:aString
-    ^ self class makeImmutableString:aString
+makeImmutable:anObject
+    ^ self class makeImmutable:anObject
+
+    "Created: / 09-06-2019 / 15:21:50 / Claus Gittinger"
 !
 
 makeReferenceFor:aNode