[glibmm/glibmm-gir-gmmproc: 3/4] gmmproc: added base class for c <-> c++ conversion classes
- From: Marcin Kolny <mkolny src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm/glibmm-gir-gmmproc: 3/4] gmmproc: added base class for c <-> c++ conversion classes
- Date: Mon, 13 Oct 2014 22:35:11 +0000 (UTC)
commit b0276ebb9b290c10842b5e799476d48561d04e29
Author: Marcin Kolny <marcin kolny gmail com>
Date: Tue Oct 14 00:20:04 2014 +0200
gmmproc: added base class for c <-> c++ conversion classes
* tools/defs_gen/girparser.py: added a few helper classes
(ObjectInfo, EnumMemberInfo, ReturnValueInfo, MethodParameterInfo,
MethodObjectInfo, ClassObject), which are helper classes for
defs generator.
* tools/defs_gen/girprinter.py: minor in enum printer fix.
tools/defs_gen/girparser.py | 56 +++++++++++++++++++++++++++++++++--------
tools/defs_gen/girprinter.py | 6 ++--
2 files changed, 48 insertions(+), 14 deletions(-)
---
diff --git a/tools/defs_gen/girparser.py b/tools/defs_gen/girparser.py
index 2360d03..cfcbb46 100644
--- a/tools/defs_gen/girparser.py
+++ b/tools/defs_gen/girparser.py
@@ -1,43 +1,77 @@
import xml.dom.minidom
-class EnumMember:
- def __init__(self, name, c_name, value):
- self.name = name
- self.c_name = c_name
+class ObjectInfo:
+ def __init__(self, type_name, c_type_name):
+ self.name = type_name
+ self.c_name = c_type_name
+
+
+class EnumMemberInfo(ObjectInfo):
+ def __init__(self, type_name, c_type_name, value):
+ ObjectInfo.__init__(self, type_name, c_type_name)
self.value = value
-class EnumObject:
+class EnumObjectInfo(ObjectInfo):
def __init__(self, xml_root, module):
- self.type_name = xml_root.getAttribute("name")
- self.is_flag = self.type_name.endswith("Flags")
- self.c_type_name = xml_root.getAttribute("c:type")
+ ObjectInfo.__init__(self, xml_root.getAttribute("name"), xml_root.getAttribute("c:type"))
+ self.is_flag = self.name.endswith("Flags")
self.module = module
self.members = []
for value in xml_root.childNodes:
if value.nodeType == xml.dom.Node.ELEMENT_NODE and value.tagName == "member":
self.members.append(
- EnumMember(
+ EnumMemberInfo(
value.getAttribute("name"),
value.getAttribute("c:identifier"),
value.getAttribute("value")))
+class ReturnValueInfo(ObjectInfo):
+ def __init__(self, type_name, c_type_name):
+ ObjectInfo.__init__(type_name, c_type_name)
+
+
+class MethodParameterInfo(ObjectInfo):
+ def __init__(self, xml_root):
+ self.name = xml_root.getAttribute("name")
+ for type_info in xml_root.getElementsByTagName("type"):
+ ObjectInfo.__init__(self, type_info.getAttribute("name"), type_info.getAttribute("c:type"))
+ break
+
+
+class MethodObjectInfo:
+ def __init__(self, xml_root):
+ self.name = xml_root.getAttribute("name")
+ self.c_name = xml_root.getAttribute("c:identifier")
+ self.parameters = []
+
+ for return_xml in xml_root.getElementsByTagName("return-value"):
+ self.return_type = return_xml.get_name
+ break
+
+
+class ClassObject:
+ def __init__(self, xml_root, module):
+ self.type_name = xml_root.getAttribute("name")
+ self.c_type_name = xml_root.getAttribute("c:type")
+ self.module = module
+
+
class GirParser:
def __init__(self):
self._enums = []
def parse_file(self, gir_file):
- print("trying to parse", gir_file)
document = xml.dom.minidom.parse(gir_file)
for namespace in document.documentElement.getElementsByTagName('namespace'):
module = namespace.getAttribute("c:identifier-prefixes")
for element in namespace.childNodes:
if element.nodeType == xml.dom.Node.ELEMENT_NODE and \
(element.tagName == "enumeration" or element.tagName == "bitfield"):
- self._enums.append(EnumObject(element, module))
+ self._enums.append(EnumObjectInfo(element, module))
def get_enumerations(self):
return self._enums
diff --git a/tools/defs_gen/girprinter.py b/tools/defs_gen/girprinter.py
index c02cdcc..3b061ba 100644
--- a/tools/defs_gen/girprinter.py
+++ b/tools/defs_gen/girprinter.py
@@ -7,11 +7,11 @@ class GirPrinter:
if enum_object.is_flag:
enum_type = "flags"
else:
- enum_type = "extended"
+ enum_type = "enum"
- print("(define-enum-" + enum_type + " " + enum_object.type_name)
+ print("(define-" + enum_type + "-extended " + enum_object.name)
print(" (in-module \"" + enum_object.module + "\")")
- print(" (c-name \"" + enum_object.c_type_name + "\")")
+ print(" (c-name \"" + enum_object.c_name + "\")")
print(" (values")
for member in enum_object.members:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]