[gobject-introspection/ebassi/property-default-value: 2/2] Add an optional attribute for the property default value
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection/ebassi/property-default-value: 2/2] Add an optional attribute for the property default value
- Date: Tue, 30 Aug 2022 22:48:34 +0000 (UTC)
commit a954af996da01f210983b94d4844bad95a419296
Author: Emmanuele Bassi <ebassi gnome org>
Date: Tue Aug 30 23:45:50 2022 +0100
Add an optional attribute for the property default value
The default-value attribute for a property element is fundamentally
meant for documentation generators.
We only care about the GIR data, as the conversion from the default
value to a string is lossy by definition, and may very well not
roundtrip.
docs/gir-1.2.rnc | 2 +
giscanner/ast.py | 1 +
giscanner/gdumpparser.py | 7 ++-
giscanner/girparser.py | 1 +
giscanner/girwriter.py | 2 +
tests/scanner/Regress-1.0-expected.gir | 87 +++++++++++++++++++++++++---------
6 files changed, 75 insertions(+), 25 deletions(-)
---
diff --git a/docs/gir-1.2.rnc b/docs/gir-1.2.rnc
index 10c6927c2..706cbea3d 100644
--- a/docs/gir-1.2.rnc
+++ b/docs/gir-1.2.rnc
@@ -350,6 +350,8 @@ grammar {
attribute setter { xsd:string }?,
## The getter function for this property
attribute getter { xsd:string }?,
+ ## The default value of the property, as a string; if missing, the default value is zero for integer
types, and null for pointer types
+ attribute default-value { xsd:string }?,
# Define the transfer of ownership of the property element
TransferOwnership?,
diff --git a/giscanner/ast.py b/giscanner/ast.py
index 2cfd81fca..dac326cb7 100644
--- a/giscanner/ast.py
+++ b/giscanner/ast.py
@@ -1304,6 +1304,7 @@ class Property(Node):
self.transfer = transfer
self.setter = None
self.getter = None
+ self.default_value = None
self.parent = None # A Class or Interface
diff --git a/giscanner/gdumpparser.py b/giscanner/gdumpparser.py
index 1a0794d42..21fbadf40 100644
--- a/giscanner/gdumpparser.py
+++ b/giscanner/gdumpparser.py
@@ -414,10 +414,13 @@ different --identifier-prefix.""" % (xmlnode.attrib['name'], self._namespace.ide
writable = (flags & G_PARAM_WRITABLE) != 0
construct = (flags & G_PARAM_CONSTRUCT) != 0
construct_only = (flags & G_PARAM_CONSTRUCT_ONLY) != 0
- node.properties.append(ast.Property(
+ default_value = pspec.attrib['default-value']
+ prop = ast.Property(
pspec.attrib['name'],
ast.Type.create_from_gtype_name(ctype),
- readable, writable, construct, construct_only))
+ readable, writable, construct, construct_only)
+ prop.default_value = default_value
+ node.properties.append(prop)
node.properties = node.properties
def _introspect_signals(self, node, xmlnode):
diff --git a/giscanner/girparser.py b/giscanner/girparser.py
index edaaa9921..5fc228990 100644
--- a/giscanner/girparser.py
+++ b/giscanner/girparser.py
@@ -609,6 +609,7 @@ class GIRParser(object):
node.attrib.get('transfer-ownership'))
prop.setter = node.attrib.get('setter')
prop.getter = node.attrib.get('getter')
+ prop.default_value = node.attrib.get('default-value')
prop.parent = parent
self._parse_generic_attribs(node, prop)
return prop
diff --git a/giscanner/girwriter.py b/giscanner/girwriter.py
index 9ff10d317..a3b3bc3ef 100644
--- a/giscanner/girwriter.py
+++ b/giscanner/girwriter.py
@@ -560,6 +560,8 @@ class GIRWriter(XMLWriter):
attrs.append(('setter', prop.setter))
if prop.getter:
attrs.append(('getter', prop.getter))
+ if prop.default_value:
+ attrs.append(('default-value', prop.default_value))
with self.tagcontext('property', attrs):
self._write_generic(prop)
self._write_type(prop.type)
diff --git a/tests/scanner/Regress-1.0-expected.gir b/tests/scanner/Regress-1.0-expected.gir
index 99d682713..0b5b4735b 100644
--- a/tests/scanner/Regress-1.0-expected.gir
+++ b/tests/scanner/Regress-1.0-expected.gir
@@ -1088,7 +1088,8 @@ regress_annotation_object_watch_full().</doc>
<property name="function-property"
writable="1"
construct="1"
- transfer-ownership="none">
+ transfer-ownership="none"
+ default-value="NULL">
<type name="AnnotationCallback" c:type="gpointer"/>
</property>
<property name="string-property"
@@ -1097,7 +1098,8 @@ regress_annotation_object_watch_full().</doc>
deprecated-version="1.2"
writable="1"
construct="1"
- transfer-ownership="none">
+ transfer-ownership="none"
+ default-value="NULL">
<doc xml:space="preserve"
filename="annotation.c"
line="156">This is a property which is a string</doc>
@@ -1108,7 +1110,8 @@ regress_annotation_object_watch_full().</doc>
version="1.2"
writable="1"
construct="1"
- transfer-ownership="none">
+ transfer-ownership="none"
+ default-value="NULL">
<doc xml:space="preserve"
filename="annotation.c"
line="181">This is a property annotation intentionally indented with a mix
@@ -2144,13 +2147,15 @@ uses a C sugar return type.</doc>
introspectable="0"
writable="1"
construct-only="1"
- transfer-ownership="none">
+ transfer-ownership="none"
+ default-value="NULL">
<type/>
</property>
<property name="string"
writable="1"
construct="1"
- transfer-ownership="none">
+ transfer-ownership="none"
+ default-value="NULL">
<type name="utf8" c:type="gchar*"/>
</property>
<field name="parent_instance">
@@ -3912,7 +3917,8 @@ use it should be.</doc>
<property name="number"
writable="1"
construct="1"
- transfer-ownership="none">
+ transfer-ownership="none"
+ default-value="0">
<type name="gint" c:type="gint"/>
</property>
<glib:signal name="interface-signal" when="last">
@@ -4834,30 +4840,47 @@ raise an error.</doc>
<property name="bare"
writable="1"
transfer-ownership="none"
- setter="set_bare">
+ setter="set_bare"
+ default-value="NULL">
<type name="GObject.Object"/>
</property>
- <property name="boxed" writable="1" transfer-ownership="none">
+ <property name="boxed"
+ writable="1"
+ transfer-ownership="none"
+ default-value="NULL">
<type name="TestBoxed"/>
</property>
<property name="byte-array"
writable="1"
construct="1"
- transfer-ownership="none">
+ transfer-ownership="none"
+ default-value="NULL">
<array name="GLib.ByteArray">
<type name="guint8" c:type="guint8"/>
</array>
</property>
- <property name="double" writable="1" transfer-ownership="none">
+ <property name="double"
+ writable="1"
+ transfer-ownership="none"
+ default-value="1.000000">
<type name="gdouble" c:type="gdouble"/>
</property>
- <property name="float" writable="1" transfer-ownership="none">
+ <property name="float"
+ writable="1"
+ transfer-ownership="none"
+ default-value="1.000000">
<type name="gfloat" c:type="gfloat"/>
</property>
- <property name="gtype" writable="1" transfer-ownership="none">
+ <property name="gtype"
+ writable="1"
+ transfer-ownership="none"
+ default-value="NULL">
<type name="GType" c:type="GType"/>
</property>
- <property name="hash-table" writable="1" transfer-ownership="container">
+ <property name="hash-table"
+ writable="1"
+ transfer-ownership="container"
+ default-value="NULL">
<type name="GLib.HashTable">
<type name="utf8"/>
<type name="gint8"/>
@@ -4865,21 +4888,31 @@ raise an error.</doc>
</property>
<property name="hash-table-old"
writable="1"
- transfer-ownership="container">
+ transfer-ownership="container"
+ default-value="NULL">
<type name="GLib.HashTable">
<type name="utf8"/>
<type name="gint8"/>
</type>
</property>
- <property name="int" writable="1" transfer-ownership="none">
+ <property name="int"
+ writable="1"
+ transfer-ownership="none"
+ default-value="0">
<type name="gint" c:type="gint"/>
</property>
- <property name="list" writable="1" transfer-ownership="none">
+ <property name="list"
+ writable="1"
+ transfer-ownership="none"
+ default-value="NULL">
<type name="GLib.List" c:type="gpointer">
<type name="utf8"/>
</type>
</property>
- <property name="list-old" writable="1" transfer-ownership="none">
+ <property name="list-old"
+ writable="1"
+ transfer-ownership="none"
+ default-value="NULL">
<type name="GLib.List" c:type="gpointer">
<type name="utf8"/>
</type>
@@ -4887,10 +4920,14 @@ raise an error.</doc>
<property name="name-conflict"
writable="1"
construct="1"
- transfer-ownership="none">
+ transfer-ownership="none"
+ default-value="42">
<type name="gint" c:type="gint"/>
</property>
- <property name="pptrarray" writable="1" transfer-ownership="none">
+ <property name="pptrarray"
+ writable="1"
+ transfer-ownership="none"
+ default-value="NULL">
<array name="GLib.PtrArray" c:type="gpointer">
<type name="utf8"/>
</array>
@@ -4899,13 +4936,15 @@ raise an error.</doc>
writable="1"
transfer-ownership="none"
setter="set_string"
- getter="get_string">
+ getter="get_string"
+ default-value="NULL">
<type name="utf8" c:type="gchar*"/>
</property>
<property name="write-only"
readable="0"
writable="1"
- transfer-ownership="none">
+ transfer-ownership="none"
+ default-value="FALSE">
<type name="gboolean" c:type="gboolean"/>
</property>
<field name="parent_instance">
@@ -5709,7 +5748,8 @@ the introspection client langage.</doc>
<property name="boolean"
writable="1"
construct="1"
- transfer-ownership="none">
+ transfer-ownership="none"
+ default-value="TRUE">
<type name="gboolean" c:type="gboolean"/>
</property>
<field name="parent_instance">
@@ -5789,7 +5829,8 @@ the introspection client langage.</doc>
writable="1"
transfer-ownership="none"
setter="set_testbool"
- getter="get_testbool">
+ getter="get_testbool"
+ default-value="TRUE">
<type name="gboolean" c:type="gboolean"/>
</property>
<field name="parent_instance">
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]