MI parsing: added support for command result values as GDB objects
authorJan Vrany <jan.vrany@fit.cvut.cz>
Thu, 19 Mar 2015 08:25:30 +0000
changeset 73 f5fe22f56f10
parent 72 eb4eea3ebf4c
child 74 d53d325c2930
MI parsing: added support for command result values as GDB objects ...in addition to just a set of properties and values. If a command's resultDescriptor is for an GDBObject then parse it directly and return that object via GDBCommandResult>>value. This helps to avoid unnecessary creation of property dictionary and then creating an object of of individual properties.
GDBCommandResult.st
GDBMIParser.st
--- a/GDBCommandResult.st	Wed Mar 18 14:19:37 2015 +0000
+++ b/GDBCommandResult.st	Thu Mar 19 08:25:30 2015 +0000
@@ -1,7 +1,11 @@
+"{ Encoding: utf8 }"
+
 "{ Package: 'jv:libgdbs' }"
 
+"{ NameSpace: Smalltalk }"
+
 GDBObject subclass:#GDBCommandResult
-	instanceVariableNames:'command status'
+	instanceVariableNames:'command status value'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'GDB-Core-Commands'
@@ -24,6 +28,15 @@
 
 status:something
     status := something.
+!
+
+value
+    "Returns a command result value as GDB object or nil, if
+     command result is just a set of properties. In that case,
+     use #propertyAt: to query individual property values."
+    ^ value
+
+    "Modified (comment): / 19-03-2015 / 08:19:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !GDBCommandResult methodsFor:'accessing-properties'!
@@ -41,8 +54,8 @@
     "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
+propertyAt: name put: val
+    ^ GDBObject setProperty: name of: self to: val
 
     "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>"
--- a/GDBMIParser.st	Wed Mar 18 14:19:37 2015 +0000
+++ b/GDBMIParser.st	Thu Mar 19 08:25:30 2015 +0000
@@ -343,23 +343,38 @@
             descriptor := command resultDescription.        
         ].
     ].
-    [ self peek == $, ] whileTrue:[
-        self next. "/ eat $,
-        propertyName := self parseVariable.
-        propertyDescriptor := descriptor propertyDescriptorAt: propertyName.
-        self expect: $=.
-        propertyDescriptor isNil ifTrue:[ 
-            propertyValue := self parseValue.
-        ] ifFalse:[ 
-            propertyValue := propertyDescriptor parseUsingGDBMIParser:self. 
-        ]. 
-        result propertyAt: propertyName put: propertyValue.
-     ].             
+
+    descriptor klass isNil ifTrue:[ 
+        "/ Command result is not an object but list of properties...
+        [ self peek == $, ] whileTrue:[
+            self next. "/ eat $,
+            propertyName := self parseVariable.
+            propertyDescriptor := descriptor propertyDescriptorAt: propertyName.
+            self expect: $=.
+            propertyDescriptor isNil ifTrue:[ 
+                propertyValue := self parseValue.
+            ] ifFalse:[ 
+                propertyValue := propertyDescriptor parseUsingGDBMIParser:self. 
+            ]. 
+            result propertyAt: propertyName put: propertyValue.
+         ].             
+    ] ifFalse:[ 
+        "/ Command result forms an object.
+        "/ Create an object and parse property list as its properties.
+        | object |
+
+        object := descriptor klass new.
+        self peek == $, ifTrue:[
+            self next. "/ eat first , following command status...
+            self parsePropertiesFor: object describedBy: descriptor.
+        ].
+        result propertyAt: #value put: object.
+    ].
     self parseNl.
     ^ GDBCommandResultEvent new result: result.
 
     "Created: / 30-05-2014 / 09:52:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 23-09-2014 / 23:37:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 19-03-2015 / 08:16:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 parseToken
@@ -698,6 +713,27 @@
 
 !GDBMIParser methodsFor:'parsing-values-typed'!
 
+parsePropertiesFor: object describedBy: descriptor
+    | propertyName propertyValue propertyDescriptor |
+
+    [ 
+        propertyName := self parseVariable.
+        propertyDescriptor := descriptor propertyDescriptorAt: propertyName.
+        self expect: $=.
+        propertyDescriptor isNil ifTrue:[ 
+            propertyValue := self parseValue.
+        ] ifFalse:[ 
+            propertyValue := propertyDescriptor parseUsingGDBMIParser:self. 
+        ].
+        object propertyAt: propertyName put: propertyValue
+    ] doWhile: [ 
+        (self peek == $,) ifTrue:[ self next. true ] ifFalse:[ false ]
+    ].
+    ^ object
+
+    "Created: / 19-03-2015 / 07:52:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 parseValueAsBoolean
     "
     bool → 'y' | 'n' | value
@@ -745,31 +781,19 @@
 !
 
 parseValueAsInstanceOf: class describedBy: descriptor
-    | object propertyName propertyValue propertyDescriptor |
+    | object |
 
     self peek ~~ ${ ifTrue:[ ^ self parseValue ].
-    self next. "/ eat ${
+    self next. "/ eat {
     object := class new.
     self peek ~~ $} ifTrue:[
-        [ 
-            propertyName := self parseVariable.
-            propertyDescriptor := descriptor propertyDescriptorAt: propertyName.
-            self expect: $=.
-            propertyDescriptor isNil ifTrue:[ 
-                propertyValue := self parseValue.
-            ] ifFalse:[ 
-                propertyValue := propertyDescriptor parseUsingGDBMIParser:self. 
-            ].
-            object propertyAt: propertyName put: propertyValue
-        ] doWhile: [ 
-            (self peek == $,) ifTrue:[ self next. true ] ifFalse:[ false ]
-        ].
+        self parsePropertiesFor: object describedBy: descriptor
     ].
     self expect: $}.
     ^ object
 
     "Created: / 18-06-2014 / 20:28:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 18-06-2014 / 23:34:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 19-03-2015 / 07:59:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 parseValueAsInteger