Add and use gapi.xsd to validate GAPI XML files

The structure of a GAPI XML file is now defined by the XML schema in
gapi.xsd.

This XSD is now used by the generator to do a first sanity check on an
XML file before trying to generate code from it. Each generatable object
still does its own validation.

The XSD can also be seen as a documentation of the GAPI XML format, and
can be used by third-parties that produce GAPI XML to validate their
output.
This commit is contained in:
Bertrand Lorentz 2012-11-25 17:54:25 +01:00
parent a406b87c26
commit 7180011c22
5 changed files with 376 additions and 4 deletions

View file

@ -1,6 +1,7 @@
SUBDIRS = sources generator parser glib gio cairo pango atk gdk gtk gtkdotnet sample doc
EXTRA_DIST = \
gapi.xsd \
gtk-sharp.snk \
policy.config.in \
AssemblyInfo.cs.in \

View file

@ -6,11 +6,13 @@ ASSEMBLY_NAME = $(pkg)-sharp
ASSEMBLY_NAME_VERSION = $(ASSEMBLY_NAME),Version=$(API_VERSION)
ASSEMBLY = $(ASSEMBLY_NAME).dll
GAPI_XSD=$(top_srcdir)/gapi.xsd
TARGET = $(pkg:=-sharp.dll) $(pkg:=-sharp.dll.config) $(POLICY_ASSEMBLIES)
noinst_DATA = $(TARGET)
TARGET_API = $(pkg:=-api.xml)
gapidir = $(datadir)/gapi-3.0
gapi_DATA = $(TARGET_API)
gapi_DATA = $(TARGET_API) $(GAPI_XSD)
CLEANFILES = $(ASSEMBLY) $(ASSEMBLY).mdb $(POLICY_ASSEMBLIES) generated-stamp generated/*.cs $(API) glue/generated.c $(POLICY_CONFIGS)
DISTCLEANFILES = $(ASSEMBLY).config
@ -31,13 +33,14 @@ $(API): $(METADATA) $(RAW_API) $(SYMBOLS) $(top_builddir)/parser/gapi-fixup.exe
api_includes = $(addprefix -I:, $(INCLUDE_API))
generated-stamp: $(API) $(INCLUDE_API) $(top_builddir)/generator/gapi_codegen.exe
generated-stamp: $(API) $(INCLUDE_API) $(top_builddir)/generator/gapi_codegen.exe $(GAPI_XSD)
rm -f generated/* && \
$(RUNTIME) $(top_builddir)/generator/gapi_codegen.exe --generate $(API) \
$(api_includes) \
--outdir=generated --assembly-name=$(ASSEMBLY_NAME) \
--gluelib-name=$(pkg)sharpglue-3 --glue-filename=glue/generated.c \
--glue-includes=$(glue_includes) \
--schema=$(GAPI_XSD) \
&& touch generated-stamp
policy.%.config: $(top_builddir)/policy.config

362
gapi.xsd Normal file
View file

@ -0,0 +1,362 @@
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:annotation>
<xs:documentation xml:lang="en">
GAPI XML schema.
Copyright 2013 Bertrand Lorentz.
This program is free software; you can redistribute it and/or
modify it under the terms of version 2 of the Lesser GNU General
Public License as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
</xs:documentation>
</xs:annotation>
<!-- Top-level tag-->
<xs:element name="api">
<xs:complexType>
<xs:sequence>
<xs:element name="namespace" type="namespaceType" maxOccurs="unbounded"/>
<xs:element name="symbol" type="symbolType" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
<xs:attribute type="xs:positiveInteger" name="parser_version"/>
</xs:complexType>
</xs:element>
<xs:complexType name="namespaceType">
<xs:choice maxOccurs="unbounded">
<xs:element name="enum" type="enumType"/>
<xs:element name="callback" type="callbackType"/>
<xs:element name="interface" type="interfaceType"/>
<xs:element name="object" type="objectType"/>
<xs:element name="struct" type="structType"/>
<xs:element name="boxed" type="boxedType"/>
<xs:element name="alias" type="aliasType"/>
<xs:element name="class" type="classType"/>
</xs:choice>
<xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:string" name="library"/>
</xs:complexType>
<xs:complexType name="symbolType">
<xs:attribute type="xs:string" name="type"/>
<xs:attribute type="xs:string" name="cname"/>
<xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:string" name="default_value" use="optional"/>
<xs:attribute type="xs:string" name="marshal_type" use="optional"/>
<xs:attribute type="xs:string" name="call_fmt" use="optional"/>
<xs:attribute type="xs:string" name="from_fmt" use="optional"/>
</xs:complexType>
<!-- Definitions for Generatables -->
<xs:complexType name="aliasType">
<xs:sequence>
<xs:element name="field" type="fieldType" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
<xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:string" name="cname"/>
<xs:attribute type="xs:string" name="type"/>
</xs:complexType>
<xs:complexType name="boxedType">
<xs:choice maxOccurs="unbounded" minOccurs="0">
<xs:element name="method" type="methodType"/>
<xs:element name="constructor" type="constructorType"/>
<xs:element name="field" type="fieldType"/>
</xs:choice>
<xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:string" name="cname"/>
<xs:attribute type="xs:boolean" name="opaque" use="optional"/>
<xs:attribute type="xs:boolean" name="hidden" use="optional"/>
<xs:attribute type="xs:boolean" name="nohash" use="optional"/>
</xs:complexType>
<xs:complexType name="callbackType">
<xs:sequence>
<xs:element name="return-type" type="return-typeType"/>
<xs:element name="parameters" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="parameter" type="method-parameterType" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:string" name="cname"/>
<xs:attribute type="xs:boolean" name="hidden" use="optional"/>
</xs:complexType>
<xs:complexType name="classType">
<xs:sequence>
<xs:element name="method" type="methodType" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
<xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:string" name="cname"/>
<xs:attribute type="xs:boolean" name="hidden" use="optional"/>
<xs:attribute type="xs:boolean" name="internal" use="optional"/>
</xs:complexType>
<xs:complexType name="enumType">
<xs:sequence>
<xs:element name="member" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:attribute type="xs:string" name="cname"/>
<xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:string" name="value"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:string" name="cname"/>
<xs:attribute type="xs:string" name="gtype" use="optional"/>
<xs:attribute type="xs:string" name="type" use="optional"/>
<xs:attribute type="xs:boolean" name="deprecated" use="optional"/>
<xs:attribute type="xs:boolean" name="hidden" use="optional"/>
</xs:complexType>
<xs:complexType name="interfaceType">
<xs:choice maxOccurs="unbounded" minOccurs="0">
<xs:element name="class_struct" type="class_structType"/>
<xs:element name="constructor" type="constructorType"/>
<xs:element name="property" type="propertyType"/>
<xs:element name="method" type="methodType"/>
<xs:element name="virtual_method" type="virtual_methodType"/>
<xs:element name="signal" type="signalType"/>
</xs:choice>
<xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:string" name="cname"/>
<xs:attribute type="xs:boolean" name="consume_only" use="optional"/>
<xs:attribute type="xs:boolean" name="hidden" use="optional"/>
</xs:complexType>
<xs:complexType name="objectType">
<xs:choice maxOccurs="unbounded" minOccurs="0">
<xs:element name="class_struct" type="class_structType"/>
<xs:element name="implements" type="implementsType"/>
<xs:element name="constructor" type="constructorType"/>
<xs:element name="field" type="fieldType"/>
<xs:element name="property" type="propertyType"/>
<xs:element name="childprop" type="propertyType"/>
<xs:element name="method" type="methodType"/>
<xs:element name="virtual_method" type="virtual_methodType"/>
<xs:element name="signal" type="signalType"/>
<xs:element name="static-string" type="static-stringType"/>
<xs:element name="custom-attribute" type="xs:string"/>
</xs:choice>
<xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:string" name="cname"/>
<xs:attribute type="xs:boolean" name="hidden" use="optional"/>
<xs:attribute type="xs:string" name="parent" use="optional"/>
</xs:complexType>
<xs:complexType name="structType">
<xs:choice maxOccurs="unbounded" minOccurs="0">
<xs:element name="method" type="methodType"/>
<xs:element name="constructor" type="constructorType"/>
<xs:element name="field" type="fieldType"/>
<xs:element name="callback" type="callbackType"/>
</xs:choice>
<xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:string" name="cname"/>
<xs:attribute type="xs:boolean" name="deprecated" use="optional"/>
<xs:attribute type="xs:boolean" name="hidden" use="optional"/>
<xs:attribute type="xs:boolean" name="opaque" use="optional"/>
</xs:complexType>
<!-- Definitions for the elements in Generatables -->
<xs:complexType name="class_structType">
<xs:choice maxOccurs="unbounded">
<xs:element name="field" type="fieldType" maxOccurs="unbounded"/>
<xs:element name="method" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:attribute type="xs:string" name="vm" use="optional"/>
<xs:attribute type="xs:string" name="signal_vm" use="optional"/>
</xs:complexType>
</xs:element>
</xs:choice>
<xs:attribute type="xs:string" name="cname"/>
</xs:complexType>
<xs:complexType name="constructorType">
<xs:choice maxOccurs="unbounded" minOccurs="0">
<xs:element name="parameters">
<xs:complexType>
<xs:sequence>
<xs:element name="parameter" type="constructor-parameterType" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="return-type" type="return-typeType"/>
</xs:choice>
<xs:attribute type="xs:string" name="cname"/>
<xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:boolean" name="deprecated" use="optional"/>
<xs:attribute type="xs:boolean" name="hidden" use="optional"/>
<xs:attribute type="xs:boolean" name="preferred" use="optional"/>
<xs:attribute type="xs:boolean" name="shared" use="optional"/>
<xs:attribute type="xs:boolean" name="win32_utf8_variant" use="optional"/>
</xs:complexType>
<xs:complexType name="fieldType">
<xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:string" name="cname"/>
<xs:attribute type="xs:string" name="type"/>
<xs:attribute type="xs:boolean" name="array" use="optional"/>
<xs:attribute type="xs:string" name="array_len" use="optional"/>
<xs:attribute type="xs:boolean" name="hidden" use="optional"/>
<xs:attribute type="xs:string" name="access" use="optional"/>
<xs:attribute type="xs:boolean" name="writeable" use="optional"/>
<xs:attribute type="xs:positiveInteger" name="bits" use="optional"/>
</xs:complexType>
<xs:complexType name="implementsType">
<xs:sequence>
<xs:element name="interface" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute type="xs:string" name="cname"/>
<xs:attribute type="xs:boolean" name="hidden" use="optional"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="methodType">
<xs:sequence>
<xs:element name="return-type" type="return-typeType"/>
<xs:element name="parameters" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="parameter" type="method-parameterType" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:string" name="cname"/>
<xs:attribute type="xs:boolean" name="shared" use="optional"/>
<xs:attribute type="xs:boolean" name="new_flag" use="optional"/>
<xs:attribute type="xs:string" name="library" use="optional"/>
<xs:attribute type="xs:boolean" name="deprecated" use="optional"/>
<xs:attribute type="xs:boolean" name="hidden" use="optional"/>
<xs:attribute type="xs:boolean" name="win32_utf8_variant" use="optional"/>
</xs:complexType>
<xs:complexType name="propertyType">
<xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:string" name="cname"/>
<xs:attribute type="xs:string" name="type"/>
<xs:attribute type="xs:boolean" name="construct" use="optional"/>
<xs:attribute type="xs:boolean" name="construct-only" use="optional"/>
<xs:attribute type="xs:boolean" name="new_flag" use="optional"/>
<xs:attribute type="xs:boolean" name="hidden" use="optional"/>
<xs:attribute type="xs:boolean" name="readable" use="optional"/>
<xs:attribute type="xs:boolean" name="writeable" use="optional"/>
</xs:complexType>
<xs:complexType name="signalType">
<xs:complexContent>
<xs:extension base="methodType">
<xs:attribute type="whenType" name="when" use="optional"/>
<xs:attribute type="xs:string" name="field_name" use="optional"/>
<xs:attribute type="xs:boolean" name="block_glue" use="optional"/>
<xs:attribute type="xs:boolean" name="manual" use="optional"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="static-stringType">
<xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:string" name="cname"/>
<xs:attribute type="xs:string" name="value"/>
</xs:complexType>
<xs:complexType name="virtual_methodType">
<xs:complexContent>
<xs:extension base="methodType">
<xs:attribute type="override_inType" name="override_in" use="optional"/>
<xs:attribute type="xs:boolean" name="padding" use="optional"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<!-- Definitions for lower-level elements -->
<xs:complexType name="parameterType">
<xs:attribute type="xs:string" name="type"/>
<xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:boolean" name="array" use="optional"/>
<xs:attribute type="xs:boolean" name="null_term_array" use="optional"/>
<xs:attribute type="xs:boolean" name="ellipsis" use="optional"/>
<xs:attribute type="xs:boolean" name="owned" use="optional"/>
<xs:attribute type="xs:boolean" name="printf_format" use="optional"/>
<xs:attribute type="xs:boolean" name="printf_format_args" use="optional"/>
<xs:attribute type="scopeType" name="scope" use="optional"/>
</xs:complexType>
<xs:complexType name="constructor-parameterType">
<xs:complexContent>
<xs:extension base="parameterType">
<xs:attribute type="xs:string" name="property_name" use="optional"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="method-parameterType">
<xs:complexContent>
<xs:extension base="parameterType">
<xs:attribute type="pass_asType" name="pass_as" use="optional"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="return-typeType">
<xs:attribute type="xs:string" name="type"/>
<xs:attribute type="xs:string" name="element_type" use="optional"/>
<xs:attribute type="xs:boolean" name="owned" use="optional"/>
<xs:attribute type="xs:boolean" name="elements_owned" use="optional"/>
<xs:attribute type="xs:boolean" name="null_term_array" use="optional"/>
<xs:attribute type="xs:string" name="array_length_param" use="optional"/>
</xs:complexType>
<!-- Definitions for allowed values -->
<xs:simpleType name="pass_asType">
<xs:restriction base="xs:string">
<xs:enumeration value="out"/>
<xs:enumeration value="ref"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="override_inType">
<xs:restriction base="xs:string">
<xs:enumeration value="declaring_class"/>
<xs:enumeration value="implementing_class"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="scopeType">
<xs:restriction base="xs:string">
<xs:enumeration value="call"/>
<xs:enumeration value="async"/>
<xs:enumeration value="notify"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="whenType">
<xs:restriction base="xs:string">
<xs:enumeration value="CLEANUP"/>
<xs:enumeration value="FIRST"/>
<xs:enumeration value="LAST"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>

View file

@ -18,7 +18,10 @@ libopaque_la_LIBADD = $(GTK_LIBS)
INCLUDES = $(GTK_CFLAGS)
generated/*.cs: opaque-api.xml
$(RUNTIME) ../../generator/gapi_codegen.exe --generate $(srcdir)/opaque-api.xml --include=../../gtk/gtk-api.xml --include=../../gdk/gdk-api.xml --outdir=generated --assembly-name=opaque-sharp
$(RUNTIME) ../../generator/gapi_codegen.exe --generate $(srcdir)/opaque-api.xml \
--include=../../gtk/gtk-api.xml --include=../../gdk/gdk-api.xml \
--outdir=generated --assembly-name=opaque-sharp \
--schema=$(top_srcdir)/gapi.xsd
api:
PATH=../../parser:$(PATH) $(RUNTIME) ../../parser/gapi-parser.exe opaque-sources.xml

View file

@ -18,7 +18,10 @@ libvalobj_la_LIBADD = $(GTK_LIBS)
INCLUDES = $(GTK_CFLAGS)
Valobj.cs: valobj-api.xml
$(RUNTIME) ../../generator/gapi_codegen.exe --generate $(srcdir)/valobj-api.xml --include=../../gtk/gtk-api.xml --include=../../gdk/gdk-api.xml --outdir=. --assembly-name=valobj-sharp
$(RUNTIME) ../../generator/gapi_codegen.exe --generate $(srcdir)/valobj-api.xml \
--include=../../gtk/gtk-api.xml --include=../../gdk/gdk-api.xml \
--outdir=. --assembly-name=valobj-sharp \
--schema=$(top_srcdir)/gapi.xsd
api:
PATH=../../parser:$(PATH) $(RUNTIME) ../../parser/gapi-parser.exe valobj-sources.xml