Unified implementation of #propertyAt: & #propertyAt:put:...
authorJan Vrany <jan.vrany@fit.cvut.cz>
Fri, 20 Jun 2014 09:26:41 +0100
changeset 20 76ac209277a7
parent 19 c48d33e27d34
child 21 83395ca8b257
Unified implementation of #propertyAt: & #propertyAt:put:... ...by moving real implementation to a class method of GDBObject. GDBObject, GDBEvent and GDBCommandResult all call these methods.
GDBCommand.st
GDBCommandResult.st
GDBEvent.st
GDBMICommand.st
GDBObject.st
GDBParser.st
libgdbs.rc
tests/GDBParserTests.st
tests/tests.rc
--- a/GDBCommand.st	Thu Jun 19 22:27:00 2014 +0100
+++ b/GDBCommand.st	Fri Jun 20 09:26:41 2014 +0100
@@ -17,6 +17,14 @@
     token := anInteger.
 ! !
 
+!GDBCommand methodsFor:'accessing-descriptors'!
+
+resultValueDescriptor
+    ^ GDBObjectValueDescriptor new
+
+    "Created: / 19-06-2014 / 21:39:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !GDBCommand methodsFor:'converting'!
 
 asString
--- a/GDBCommandResult.st	Thu Jun 19 22:27:00 2014 +0100
+++ b/GDBCommandResult.st	Fri Jun 20 09:26:41 2014 +0100
@@ -26,6 +26,28 @@
     status := something.
 ! !
 
+!GDBCommandResult methodsFor:'accessing-properties'!
+
+properties
+    ^ GDBObject getPropertiesOf: self.
+
+    "Modified: / 20-06-2014 / 09:04:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+propertyAt: name
+    ^ GDBObject getProperty: name of: self
+
+    "Created: / 31-05-2014 / 00:00:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 20-06-2014 / 09:05:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+propertyAt: name put: value
+    ^ GDBObject setProperty: name of: self to: value
+
+    "Created: / 31-05-2014 / 00:01:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 20-06-2014 / 09:05:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !GDBCommandResult class methodsFor:'documentation'!
 
 version_HG
--- a/GDBEvent.st	Thu Jun 19 22:27:00 2014 +0100
+++ b/GDBEvent.st	Fri Jun 20 09:26:41 2014 +0100
@@ -37,38 +37,23 @@
 !GDBEvent methodsFor:'accessing-properties'!
 
 properties
-    properties isNil ifTrue:[ ^ Dictionary new ].
-    ^ properties
+    ^ GDBObject getPropertiesOf: self.
 
-    "Modified: / 18-06-2014 / 23:56:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 20-06-2014 / 09:04:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 propertyAt: name
-    | index |    
-    index :=  self class allInstVarNames indexOf: name.
-    index ~~ 0 ifTrue:[ 
-        ^ self instVarAt: index
-    ].
-    properties isNil ifTrue:[ Object keyNotFoundError: name ].
-    ^ properties at: name ifAbsent:[ Object keyNotFoundError: name ].
+    ^ GDBObject getProperty: name of: self
 
     "Created: / 31-05-2014 / 00:00:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 18-06-2014 / 23:31:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 20-06-2014 / 09:05:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 propertyAt: name put: value
-    | index |
-
-    index :=  self class allInstVarNames indexOf: name.
-    index ~~ 0 ifTrue:[ 
-        self instVarAt: index put: value
-    ] ifFalse:[    
-        properties isNil ifTrue:[ properties := Dictionary new ].
-        properties at: name put: value
-    ]
+    ^ GDBObject setProperty: name of: self to: value
 
     "Created: / 31-05-2014 / 00:01:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 18-06-2014 / 23:31:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 20-06-2014 / 09:05:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !GDBEvent methodsFor:'testing'!
--- a/GDBMICommand.st	Thu Jun 19 22:27:00 2014 +0100
+++ b/GDBMICommand.st	Fri Jun 20 09:26:41 2014 +0100
@@ -225,14 +225,6 @@
     "Modified: / 12-06-2014 / 00:43:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
-!GDBMICommand methodsFor:'accessing-descriptors'!
-
-resultValueDescriptor
-    ^ GDBObjectValueDescriptor new
-
-    "Created: / 19-06-2014 / 21:39:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
 !GDBMICommand methodsFor:'converting'!
 
 asString
--- a/GDBObject.st	Thu Jun 19 22:27:00 2014 +0100
+++ b/GDBObject.st	Fri Jun 20 09:26:41 2014 +0100
@@ -15,41 +15,90 @@
     "Created: / 18-06-2014 / 23:12:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!GDBObject class methodsFor:'utilities - properties'!
+
+getPropertiesOf: object
+
+    | names index properties |
+
+    names := object class allInstVarNames.
+    index := names indexOf: #properties.
+    index ~~ 0 ifTrue:[ 
+        properties := object instVarAt: index.
+        properties isNil ifTrue:[ 
+            properties := Dictionary new.
+            object instVarAt: index put: properties.
+            ^ properties
+        ].
+    ].
+    ^ nil
+
+    "Created: / 20-06-2014 / 09:03:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+getProperty: nm of: object
+
+    | names index properties |
+
+    index := (names := object class allInstVarNames) indexOf: nm.
+    index ~~ 0 ifTrue:[ 
+        ^ object instVarAt: index.
+    ].
+    index := names indexOf: #properties.
+    index ~~ 0 ifTrue:[ 
+        properties := object instVarAt: index.
+        properties notNil ifTrue:[ 
+            ^ properties at: nm ifAbsent:[ nil ]
+        ].
+    ].
+    ^ nil
+
+    "Created: / 20-06-2014 / 08:59:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+setProperty: nm of: object to: value
+
+    | names index properties |
+
+    index := (names := object class allInstVarNames) indexOf: nm.
+    index ~~ 0 ifTrue:[ 
+        object instVarAt: index put: value.
+
+    ] ifFalse:[
+        index := names indexOf: #properties.
+        index ~~ 0 ifTrue:[ 
+            properties := object instVarAt: index.
+            properties isNil ifTrue:[ 
+                properties := Dictionary new.
+                object instVarAt: index put: properties.
+            ].
+            properties at: nm put: value.
+        ].
+    ].
+
+    "Created: / 20-06-2014 / 09:01:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !GDBObject methodsFor:'accessing-properties'!
 
 properties
-    properties isNil ifTrue:[ ^ Dictionary new ].
-    ^ properties
+    ^ GDBObject getPropertiesOf: self.
 
-    "Modified: / 18-06-2014 / 23:54:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 20-06-2014 / 09:04:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 propertyAt: name
-    | index |    
-    index :=  self class allInstVarNames indexOf: name.
-    index ~~ 0 ifTrue:[ 
-        ^ self instVarAt: index
-    ].
-    properties isNil ifTrue:[ Object keyNotFoundError: name ].
-    ^ properties at: name ifAbsent:[ Object keyNotFoundError: name ].
+    ^ GDBObject getProperty: name of: self
 
     "Created: / 31-05-2014 / 00:00:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 18-06-2014 / 23:31:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 20-06-2014 / 09:05:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 propertyAt: name put: value
-    | index |
-
-    index :=  self class allInstVarNames indexOf: name.
-    index ~~ 0 ifTrue:[ 
-        self instVarAt: index put: value
-    ] ifFalse:[    
-        properties isNil ifTrue:[ properties := Dictionary new ].
-        properties at: name put: value
-    ]
+    ^ GDBObject setProperty: name of: self to: value
 
     "Created: / 31-05-2014 / 00:01:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 18-06-2014 / 23:31:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 20-06-2014 / 09:05:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !GDBObject methodsFor:'attributes access'!
--- a/GDBParser.st	Thu Jun 19 22:27:00 2014 +0100
+++ b/GDBParser.st	Fri Jun 20 09:26:41 2014 +0100
@@ -383,13 +383,13 @@
 
 parseString
     ^ String streamContents:[:s|
-        [ self peek isLetterOrDigit or:['-' includes: self peek ] ]  whileTrue:[
+        [ self peek isLetterOrDigit or:['-_' includes: self peek ] ]  whileTrue:[
             s nextPut: self next.
         ]
     ].
 
     "Created: / 30-05-2014 / 10:32:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 18-06-2014 / 07:07:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 20-06-2014 / 09:20:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 parseVariable
--- a/libgdbs.rc	Thu Jun 19 22:27:00 2014 +0100
+++ b/libgdbs.rc	Fri Jun 20 09:26:41 2014 +0100
@@ -25,7 +25,7 @@
       VALUE "LegalCopyright", "My CopyRight or CopyLeft\0"
       VALUE "ProductName", "LibraryName\0"
       VALUE "ProductVersion", "6.2.4.0\0"
-      VALUE "ProductDate", "Thu, 19 Jun 2014 21:24:32 GMT\0"
+      VALUE "ProductDate", "Fri, 20 Jun 2014 08:24:37 GMT\0"
     END
 
   END
--- a/tests/GDBParserTests.st	Thu Jun 19 22:27:00 2014 +0100
+++ b/tests/GDBParserTests.st	Fri Jun 20 09:26:41 2014 +0100
@@ -25,38 +25,23 @@
 !GDBParserTests methodsFor:'accessing-properties'!
 
 properties
-    properties isNil ifTrue:[ ^ Dictionary new ].
-    ^ properties
+    ^ GDBObject getPropertiesOf: self.
 
-    "Modified: / 18-06-2014 / 23:54:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 20-06-2014 / 09:04:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 propertyAt: name
-    | index |    
-    index :=  self class allInstVarNames indexOf: name.
-    index ~~ 0 ifTrue:[ 
-        ^ self instVarAt: index
-    ].
-    properties isNil ifTrue:[ Object keyNotFoundError: name ].
-    ^ properties at: name ifAbsent:[ Object keyNotFoundError: name ].
+    ^ GDBObject getProperty: name of: self
 
     "Created: / 31-05-2014 / 00:00:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 18-06-2014 / 23:31:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 20-06-2014 / 09:05:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 propertyAt: name put: value
-    | index |
-
-    index :=  self class allInstVarNames indexOf: name.
-    index ~~ 0 ifTrue:[ 
-        self instVarAt: index put: value
-    ] ifFalse:[    
-        properties isNil ifTrue:[ properties := Dictionary new ].
-        properties at: name put: value
-    ]
+    ^ GDBObject setProperty: name of: self to: value
 
     "Created: / 31-05-2014 / 00:01:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 18-06-2014 / 23:31:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 20-06-2014 / 09:05:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !GDBParserTests methodsFor:'running'!
@@ -88,6 +73,22 @@
 
 !GDBParserTests methodsFor:'tests - commands'!
 
+test_command_break_list_01
+
+    | parser events |
+
+    parser := GDBParser on:'1^done,BreakpointTable={nr_rows="1",nr_cols="6",hdr=[{width="3",alignment="-1",col_name="number",colhdr="Num"},{width="14",alignment="-1",col_name="type",colhdr="Type"},{width="4",alignment="-1",col_name="disp",colhdr="Disp"},{width="3",alignment="-1",col_name="enabled",colhdr="Enb"},{width="10",alignment="-1",col_name="addr",colhdr="Address"},{width="40",alignment="2",col_name="what",colhdr="What"}],body=[bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],times="0",ignore="3"}]}
+'.
+    parser token2CommandMappingBlock: [ :token | GDBMI_break_list new ].  
+    events := parser parseOutput.
+
+    self assert: events size == 1.
+    self assert:  (events first result propertyAt: 'BreakpointTable') notNil.
+    self assert: ((events first result propertyAt: 'BreakpointTable') at: 'body') notNil.
+
+    "Created: / 20-06-2014 / 09:08:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 test_command_stack_list_frames_01
 
     | parser events |
@@ -97,7 +98,11 @@
     parser token2CommandMappingBlock: [ :token | GDBMI_stack_list_frames new ].  
     events := parser parseOutput.
 
+    self assert: events size == 1.
+    self assert: (events first result propertyAt: 'stack') size == 5.
+
     "Created: / 19-06-2014 / 22:00:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 20-06-2014 / 09:18:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !GDBParserTests methodsFor:'tests - examples'!
--- a/tests/tests.rc	Thu Jun 19 22:27:00 2014 +0100
+++ b/tests/tests.rc	Fri Jun 20 09:26:41 2014 +0100
@@ -25,7 +25,7 @@
       VALUE "LegalCopyright", "My CopyRight or CopyLeft\0"
       VALUE "ProductName", "LibraryName\0"
       VALUE "ProductVersion", "6.2.4.0\0"
-      VALUE "ProductDate", "Thu, 19 Jun 2014 21:24:34 GMT\0"
+      VALUE "ProductDate", "Fri, 20 Jun 2014 08:24:39 GMT\0"
     END
 
   END