gobject-introspection 2.0.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +118 -0
- data/ext/gobject-introspection/depend +10 -0
- data/ext/gobject-introspection/extconf.rb +97 -0
- data/ext/gobject-introspection/gobject_introspection.def +5 -0
- data/ext/gobject-introspection/rb-gi-arg-info.c +151 -0
- data/ext/gobject-introspection/rb-gi-argument.c +1015 -0
- data/ext/gobject-introspection/rb-gi-base-info.c +218 -0
- data/ext/gobject-introspection/rb-gi-boxed-info.c +48 -0
- data/ext/gobject-introspection/rb-gi-callable-info.c +104 -0
- data/ext/gobject-introspection/rb-gi-callback-info.c +48 -0
- data/ext/gobject-introspection/rb-gi-constant-info.c +77 -0
- data/ext/gobject-introspection/rb-gi-constructor-info.c +120 -0
- data/ext/gobject-introspection/rb-gi-conversions.h +116 -0
- data/ext/gobject-introspection/rb-gi-enum-info.c +145 -0
- data/ext/gobject-introspection/rb-gi-field-info.c +153 -0
- data/ext/gobject-introspection/rb-gi-flags-info.c +48 -0
- data/ext/gobject-introspection/rb-gi-function-info.c +658 -0
- data/ext/gobject-introspection/rb-gi-interface-info.c +222 -0
- data/ext/gobject-introspection/rb-gi-loader.c +162 -0
- data/ext/gobject-introspection/rb-gi-method-info.c +109 -0
- data/ext/gobject-introspection/rb-gi-object-info.c +345 -0
- data/ext/gobject-introspection/rb-gi-private.h +110 -0
- data/ext/gobject-introspection/rb-gi-property-info.c +77 -0
- data/ext/gobject-introspection/rb-gi-registered-type-info.c +86 -0
- data/ext/gobject-introspection/rb-gi-repository.c +164 -0
- data/ext/gobject-introspection/rb-gi-signal-info.c +77 -0
- data/ext/gobject-introspection/rb-gi-struct-info.c +190 -0
- data/ext/gobject-introspection/rb-gi-type-info.c +143 -0
- data/ext/gobject-introspection/rb-gi-type-tag.c +43 -0
- data/ext/gobject-introspection/rb-gi-types.h +71 -0
- data/ext/gobject-introspection/rb-gi-union-info.c +206 -0
- data/ext/gobject-introspection/rb-gi-unresolved-info.c +48 -0
- data/ext/gobject-introspection/rb-gi-value-info.c +57 -0
- data/ext/gobject-introspection/rb-gi-vfunc-info.c +91 -0
- data/ext/gobject-introspection/rb-gobject-introspection.c +44 -0
- data/ext/gobject-introspection/rb-gobject-introspection.h +57 -0
- data/extconf.rb +71 -0
- data/lib/1.9/gobject_introspection.so +0 -0
- data/lib/2.0/gobject_introspection.so +0 -0
- data/lib/gobject-introspection.rb +52 -0
- data/lib/gobject-introspection/callable-info.rb +91 -0
- data/lib/gobject-introspection/collection-reader.rb +34 -0
- data/lib/gobject-introspection/interface-info.rb +32 -0
- data/lib/gobject-introspection/loader.rb +328 -0
- data/lib/gobject-introspection/object-info.rb +33 -0
- data/lib/gobject-introspection/repository.rb +32 -0
- data/lib/gobject-introspection/struct-info.rb +28 -0
- data/lib/gobject-introspection/union-info.rb +28 -0
- data/test/gobject-introspection-test-utils.rb +26 -0
- data/test/run-test.rb +45 -0
- data/test/test-arg-info.rb +68 -0
- data/test/test-base-info.rb +31 -0
- data/test/test-boxed-info.rb +21 -0
- data/test/test-callable-info.rb +49 -0
- data/test/test-callback-info.rb +29 -0
- data/test/test-constant-info.rb +24 -0
- data/test/test-enum-info.rb +56 -0
- data/test/test-field-type.rb +42 -0
- data/test/test-flags-info.rb +27 -0
- data/test/test-function-info.rb +37 -0
- data/test/test-interface-info.rb +97 -0
- data/test/test-loader.rb +30 -0
- data/test/test-object-info.rb +131 -0
- data/test/test-property-info.rb +38 -0
- data/test/test-registered-type-info.rb +35 -0
- data/test/test-repository.rb +59 -0
- data/test/test-signal-info.rb +37 -0
- data/test/test-struct-info.rb +57 -0
- data/test/test-type-info.rb +62 -0
- data/test/test-type-tag.rb +29 -0
- data/test/test-union-info.rb +21 -0
- data/test/test-value-info.rb +28 -0
- data/test/test-vfunc-info.rb +42 -0
- data/vendor/local/bin/g-ir-compiler.exe +0 -0
- data/vendor/local/bin/g-ir-generate.exe +0 -0
- data/vendor/local/bin/libgirepository-1.0-1.dll +0 -0
- data/vendor/local/include/gobject-introspection-1.0/giarginfo.h +52 -0
- data/vendor/local/include/gobject-introspection-1.0/gibaseinfo.h +89 -0
- data/vendor/local/include/gobject-introspection-1.0/gicallableinfo.h +74 -0
- data/vendor/local/include/gobject-introspection-1.0/giconstantinfo.h +46 -0
- data/vendor/local/include/gobject-introspection-1.0/gienuminfo.h +56 -0
- data/vendor/local/include/gobject-introspection-1.0/gifieldinfo.h +52 -0
- data/vendor/local/include/gobject-introspection-1.0/gifunctioninfo.h +77 -0
- data/vendor/local/include/gobject-introspection-1.0/giinterfaceinfo.h +68 -0
- data/vendor/local/include/gobject-introspection-1.0/giobjectinfo.h +137 -0
- data/vendor/local/include/gobject-introspection-1.0/gipropertyinfo.h +44 -0
- data/vendor/local/include/gobject-introspection-1.0/giregisteredtypeinfo.h +53 -0
- data/vendor/local/include/gobject-introspection-1.0/girepository.h +179 -0
- data/vendor/local/include/gobject-introspection-1.0/girffi.h +80 -0
- data/vendor/local/include/gobject-introspection-1.0/gisignalinfo.h +45 -0
- data/vendor/local/include/gobject-introspection-1.0/gistructinfo.h +53 -0
- data/vendor/local/include/gobject-introspection-1.0/gitypeinfo.h +56 -0
- data/vendor/local/include/gobject-introspection-1.0/gitypelib.h +55 -0
- data/vendor/local/include/gobject-introspection-1.0/gitypes.h +453 -0
- data/vendor/local/include/gobject-introspection-1.0/giunioninfo.h +57 -0
- data/vendor/local/include/gobject-introspection-1.0/givfuncinfo.h +56 -0
- data/vendor/local/lib/girepository-1.0/DBus-1.0.typelib +0 -0
- data/vendor/local/lib/girepository-1.0/DBusGLib-1.0.typelib +0 -0
- data/vendor/local/lib/girepository-1.0/GIRepository-2.0.typelib +0 -0
- data/vendor/local/lib/girepository-1.0/GL-1.0.typelib +0 -0
- data/vendor/local/lib/girepository-1.0/GLib-2.0.typelib +0 -0
- data/vendor/local/lib/girepository-1.0/GModule-2.0.typelib +0 -0
- data/vendor/local/lib/girepository-1.0/GObject-2.0.typelib +0 -0
- data/vendor/local/lib/girepository-1.0/Gio-2.0.typelib +0 -0
- data/vendor/local/lib/girepository-1.0/cairo-1.0.typelib +0 -0
- data/vendor/local/lib/girepository-1.0/fontconfig-2.0.typelib +0 -0
- data/vendor/local/lib/girepository-1.0/freetype2-2.0.typelib +0 -0
- data/vendor/local/lib/girepository-1.0/libxml2-2.0.typelib +0 -0
- data/vendor/local/lib/girepository-1.0/xfixes-4.0.typelib +0 -0
- data/vendor/local/lib/girepository-1.0/xft-2.0.typelib +0 -0
- data/vendor/local/lib/girepository-1.0/xlib-2.0.typelib +0 -0
- data/vendor/local/lib/girepository-1.0/xrandr-1.3.typelib +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/__init__.py +24 -0
- data/vendor/local/lib/gobject-introspection/giscanner/__init__.pyc +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/__init__.pyo +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/annotationmain.py +74 -0
- data/vendor/local/lib/gobject-introspection/giscanner/annotationmain.pyc +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/annotationmain.pyo +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/annotationparser.py +1204 -0
- data/vendor/local/lib/gobject-introspection/giscanner/annotationparser.pyc +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/annotationparser.pyo +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/ast.py +1100 -0
- data/vendor/local/lib/gobject-introspection/giscanner/ast.pyc +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/ast.pyo +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/cachestore.py +196 -0
- data/vendor/local/lib/gobject-introspection/giscanner/cachestore.pyc +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/cachestore.pyo +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/codegen.py +140 -0
- data/vendor/local/lib/gobject-introspection/giscanner/codegen.pyc +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/codegen.pyo +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/docmain.py +60 -0
- data/vendor/local/lib/gobject-introspection/giscanner/docmain.pyc +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/docmain.pyo +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/C/class.tmpl +2 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/C/constructor.tmpl +1 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/C/default.tmpl +1 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/C/enum.tmpl +2 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/C/function.tmpl +61 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/C/method.tmpl +1 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/C/namespace.tmpl +1 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/C/property.tmpl +5 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/C/record.tmpl +1 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/C/signal.tmpl +5 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/C/vfunc.tmpl +4 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/Gjs/class.tmpl +18 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/Gjs/constructor.tmpl +1 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/Gjs/default.tmpl +1 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/Gjs/enum.tmpl +13 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/Gjs/function.tmpl +48 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/Gjs/method.tmpl +1 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/Gjs/namespace.tmpl +2 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/Gjs/property.tmpl +10 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/Gjs/record.tmpl +2 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/Gjs/signal.tmpl +37 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/Gjs/vfunc.tmpl +27 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/Python/class.tmpl +17 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/Python/constructor.tmpl +1 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/Python/default.tmpl +1 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/Python/enum.tmpl +13 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/Python/function.tmpl +53 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/Python/method.tmpl +1 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/Python/namespace.tmpl +2 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/Python/property.tmpl +10 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/Python/record.tmpl +2 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/Python/signal.tmpl +42 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/Python/vfunc.tmpl +33 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/base.tmpl +29 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/class.tmpl +40 -0
- data/vendor/local/lib/gobject-introspection/giscanner/doctemplates/namespace.tmpl +19 -0
- data/vendor/local/lib/gobject-introspection/giscanner/docwriter.py +635 -0
- data/vendor/local/lib/gobject-introspection/giscanner/docwriter.pyc +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/docwriter.pyo +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/dumper.py +363 -0
- data/vendor/local/lib/gobject-introspection/giscanner/dumper.pyc +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/dumper.pyo +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/gdumpparser.py +551 -0
- data/vendor/local/lib/gobject-introspection/giscanner/gdumpparser.pyc +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/gdumpparser.pyo +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/girparser.py +581 -0
- data/vendor/local/lib/gobject-introspection/giscanner/girparser.pyc +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/girparser.pyo +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/girwriter.py +584 -0
- data/vendor/local/lib/gobject-introspection/giscanner/girwriter.pyc +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/girwriter.pyo +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/introspectablepass.py +236 -0
- data/vendor/local/lib/gobject-introspection/giscanner/introspectablepass.pyc +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/introspectablepass.pyo +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/libtoolimporter.py +76 -0
- data/vendor/local/lib/gobject-introspection/giscanner/libtoolimporter.pyc +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/libtoolimporter.pyo +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/maintransformer.py +1337 -0
- data/vendor/local/lib/gobject-introspection/giscanner/maintransformer.pyc +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/maintransformer.pyo +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/message.py +185 -0
- data/vendor/local/lib/gobject-introspection/giscanner/message.pyc +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/message.pyo +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/odict.py +50 -0
- data/vendor/local/lib/gobject-introspection/giscanner/odict.pyc +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/odict.pyo +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/scannermain.py +497 -0
- data/vendor/local/lib/gobject-introspection/giscanner/scannermain.pyc +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/scannermain.pyo +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/sectionparser.py +78 -0
- data/vendor/local/lib/gobject-introspection/giscanner/sectionparser.pyc +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/sectionparser.pyo +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/shlibs.py +132 -0
- data/vendor/local/lib/gobject-introspection/giscanner/shlibs.pyc +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/shlibs.pyo +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/sourcescanner.py +324 -0
- data/vendor/local/lib/gobject-introspection/giscanner/sourcescanner.pyc +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/sourcescanner.pyo +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/testcodegen.py +119 -0
- data/vendor/local/lib/gobject-introspection/giscanner/testcodegen.pyc +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/testcodegen.pyo +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/transformer.py +999 -0
- data/vendor/local/lib/gobject-introspection/giscanner/transformer.pyc +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/transformer.pyo +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/utils.py +141 -0
- data/vendor/local/lib/gobject-introspection/giscanner/utils.pyc +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/utils.pyo +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/xmlwriter.py +197 -0
- data/vendor/local/lib/gobject-introspection/giscanner/xmlwriter.pyc +0 -0
- data/vendor/local/lib/gobject-introspection/giscanner/xmlwriter.pyo +0 -0
- data/vendor/local/lib/libgirepository-1.0.a +0 -0
- data/vendor/local/lib/libgirepository-1.0.dll.a +0 -0
- data/vendor/local/lib/libgirepository-1.0.la +41 -0
- data/vendor/local/lib/pkgconfig/gobject-introspection-1.0.pc +26 -0
- data/vendor/local/lib/pkgconfig/gobject-introspection-no-export-1.0.pc +23 -0
- data/vendor/local/share/aclocal/introspection.m4 +96 -0
- data/vendor/local/share/gir-1.0/DBus-1.0.gir +32 -0
- data/vendor/local/share/gir-1.0/DBusGLib-1.0.gir +18 -0
- data/vendor/local/share/gir-1.0/GIRepository-2.0.gir +3833 -0
- data/vendor/local/share/gir-1.0/GL-1.0.gir +31 -0
- data/vendor/local/share/gir-1.0/GLib-2.0.gir +44304 -0
- data/vendor/local/share/gir-1.0/GModule-2.0.gir +184 -0
- data/vendor/local/share/gir-1.0/GObject-2.0.gir +13947 -0
- data/vendor/local/share/gir-1.0/Gio-2.0.gir +73619 -0
- data/vendor/local/share/gir-1.0/cairo-1.0.gir +70 -0
- data/vendor/local/share/gir-1.0/fontconfig-2.0.gir +18 -0
- data/vendor/local/share/gir-1.0/freetype2-2.0.gir +22 -0
- data/vendor/local/share/gir-1.0/libxml2-2.0.gir +25 -0
- data/vendor/local/share/gir-1.0/xfixes-4.0.gir +10 -0
- data/vendor/local/share/gir-1.0/xft-2.0.gir +23 -0
- data/vendor/local/share/gir-1.0/xlib-2.0.gir +67 -0
- data/vendor/local/share/gir-1.0/xrandr-1.3.gir +16 -0
- data/vendor/local/share/gobject-introspection-1.0/Makefile.introspection +166 -0
- data/vendor/local/share/gobject-introspection-1.0/gdump.c +564 -0
- data/vendor/local/share/gobject-introspection-1.0/tests/annotation.c +835 -0
- data/vendor/local/share/gobject-introspection-1.0/tests/annotation.h +198 -0
- data/vendor/local/share/gobject-introspection-1.0/tests/drawable.c +55 -0
- data/vendor/local/share/gobject-introspection-1.0/tests/drawable.h +33 -0
- data/vendor/local/share/gobject-introspection-1.0/tests/everything.c +1473 -0
- data/vendor/local/share/gobject-introspection-1.0/tests/everything.h +428 -0
- data/vendor/local/share/gobject-introspection-1.0/tests/foo.c +790 -0
- data/vendor/local/share/gobject-introspection-1.0/tests/foo.h +437 -0
- data/vendor/local/share/gobject-introspection-1.0/tests/gimarshallingtests.c +5256 -0
- data/vendor/local/share/gobject-introspection-1.0/tests/gimarshallingtests.h +1158 -0
- data/vendor/local/share/gobject-introspection-1.0/tests/regress.c +4009 -0
- data/vendor/local/share/gobject-introspection-1.0/tests/regress.h +944 -0
- data/vendor/local/share/gobject-introspection-1.0/tests/utility.c +45 -0
- data/vendor/local/share/gobject-introspection-1.0/tests/utility.h +95 -0
- data/vendor/local/share/gobject-introspection-1.0/tests/warnlib.c +33 -0
- data/vendor/local/share/gobject-introspection-1.0/tests/warnlib.h +36 -0
- data/vendor/local/share/license/gobject-introspection/AUTHORS +9 -0
- data/vendor/local/share/license/gobject-introspection/COPYING +12 -0
- data/vendor/local/share/man/man1/g-ir-compiler.1 +51 -0
- data/vendor/local/share/man/man1/g-ir-generate.1 +29 -0
- metadata +343 -0
Binary file
|
Binary file
|
@@ -0,0 +1,236 @@
|
|
1
|
+
# -*- Mode: Python -*-
|
2
|
+
# Copyright (C) 2010 Red Hat, Inc.
|
3
|
+
#
|
4
|
+
# This library is free software; you can redistribute it and/or
|
5
|
+
# modify it under the terms of the GNU Lesser General Public
|
6
|
+
# License as published by the Free Software Foundation; either
|
7
|
+
# version 2 of the License, or (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This library is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
+
# Lesser General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU Lesser General Public
|
15
|
+
# License along with this library; if not, write to the
|
16
|
+
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
17
|
+
# Boston, MA 02111-1307, USA.
|
18
|
+
#
|
19
|
+
|
20
|
+
from . import ast
|
21
|
+
from . import message
|
22
|
+
from .annotationparser import TAG_RETURNS
|
23
|
+
|
24
|
+
class IntrospectablePass(object):
|
25
|
+
|
26
|
+
def __init__(self, transformer, blocks):
|
27
|
+
self._transformer = transformer
|
28
|
+
self._namespace = transformer.namespace
|
29
|
+
self._blocks = blocks
|
30
|
+
|
31
|
+
# Public API
|
32
|
+
|
33
|
+
def validate(self):
|
34
|
+
self._namespace.walk(self._introspectable_alias_analysis)
|
35
|
+
self._namespace.walk(self._propagate_callable_skips)
|
36
|
+
self._namespace.walk(self._analyze_node)
|
37
|
+
self._namespace.walk(self._introspectable_callable_analysis)
|
38
|
+
self._namespace.walk(self._introspectable_callable_analysis)
|
39
|
+
self._namespace.walk(self._introspectable_pass3)
|
40
|
+
self._namespace.walk(self._remove_non_reachable_backcompat_copies)
|
41
|
+
|
42
|
+
def _parameter_warning(self, parent, param, text, position=None):
|
43
|
+
# Suppress VFunctions and Callbacks warnings for now
|
44
|
+
# they cause more problems then they are worth
|
45
|
+
if isinstance(parent, (ast.VFunction, ast.Callback)):
|
46
|
+
return
|
47
|
+
|
48
|
+
block = None
|
49
|
+
if hasattr(parent, 'symbol'):
|
50
|
+
prefix = '%s: ' % (parent.symbol, )
|
51
|
+
block = self._blocks.get(parent.symbol)
|
52
|
+
if block:
|
53
|
+
position = block.position
|
54
|
+
else:
|
55
|
+
prefix = ''
|
56
|
+
if isinstance(param, ast.Parameter):
|
57
|
+
context = "argument %s: " % (param.argname, )
|
58
|
+
else:
|
59
|
+
context = "return value: "
|
60
|
+
if block:
|
61
|
+
return_tag = block.get_tag(TAG_RETURNS)
|
62
|
+
if return_tag:
|
63
|
+
position = return_tag.position
|
64
|
+
message.warn_node(parent, prefix + context + text,
|
65
|
+
positions=position)
|
66
|
+
|
67
|
+
def _introspectable_param_analysis(self, parent, node):
|
68
|
+
is_return = isinstance(node, ast.Return)
|
69
|
+
is_parameter = isinstance(node, ast.Parameter)
|
70
|
+
assert is_return or is_parameter
|
71
|
+
|
72
|
+
if node.type.target_giname is not None:
|
73
|
+
target = self._transformer.lookup_typenode(node.type)
|
74
|
+
else:
|
75
|
+
target = None
|
76
|
+
|
77
|
+
if node.skip:
|
78
|
+
return
|
79
|
+
|
80
|
+
if not node.type.resolved:
|
81
|
+
self._parameter_warning(parent, node,
|
82
|
+
"Unresolved type: %r" % (node.type.unresolved_string, ))
|
83
|
+
parent.introspectable = False
|
84
|
+
return
|
85
|
+
|
86
|
+
if isinstance(node.type, ast.Varargs):
|
87
|
+
parent.introspectable = False
|
88
|
+
return
|
89
|
+
|
90
|
+
if (isinstance(node.type, (ast.List, ast.Array))
|
91
|
+
and node.type.element_type == ast.TYPE_ANY):
|
92
|
+
self._parameter_warning(parent, node, "Missing (element-type) annotation")
|
93
|
+
parent.introspectable = False
|
94
|
+
return
|
95
|
+
|
96
|
+
if (is_parameter
|
97
|
+
and isinstance(target, ast.Callback)
|
98
|
+
and not node.type.target_giname in ('GLib.DestroyNotify',
|
99
|
+
'Gio.AsyncReadyCallback')
|
100
|
+
and node.scope is None):
|
101
|
+
self._parameter_warning(parent, node,
|
102
|
+
("Missing (scope) annotation for callback" +
|
103
|
+
" without GDestroyNotify (valid: %s, %s)")
|
104
|
+
% (ast.PARAM_SCOPE_CALL, ast.PARAM_SCOPE_ASYNC))
|
105
|
+
parent.introspectable = False
|
106
|
+
return
|
107
|
+
|
108
|
+
if is_return and isinstance(target, ast.Callback):
|
109
|
+
self._parameter_warning(parent, node, "Callbacks cannot be return values; use (skip)")
|
110
|
+
parent.introspectable = False
|
111
|
+
return
|
112
|
+
|
113
|
+
if (is_return
|
114
|
+
and isinstance(target, (ast.Record, ast.Union))
|
115
|
+
and target.get_type is None
|
116
|
+
and not target.foreign):
|
117
|
+
if node.transfer != ast.PARAM_TRANSFER_NONE:
|
118
|
+
self._parameter_warning(parent, node,
|
119
|
+
"Invalid non-constant return of bare structure or union; register as boxed type or (skip)")
|
120
|
+
parent.introspectable = False
|
121
|
+
return
|
122
|
+
|
123
|
+
if node.transfer is None:
|
124
|
+
self._parameter_warning(parent, node, "Missing (transfer) annotation")
|
125
|
+
parent.introspectable = False
|
126
|
+
return
|
127
|
+
|
128
|
+
def _type_is_introspectable(self, typeval, warn=False):
|
129
|
+
if not typeval.resolved:
|
130
|
+
return False
|
131
|
+
if isinstance(typeval, ast.TypeUnknown):
|
132
|
+
return False
|
133
|
+
if isinstance(typeval, (ast.Array, ast.List)):
|
134
|
+
return self._type_is_introspectable(typeval.element_type)
|
135
|
+
elif isinstance(typeval, ast.Map):
|
136
|
+
return (self._type_is_introspectable(typeval.key_type)
|
137
|
+
and self._type_is_introspectable(typeval.value_type))
|
138
|
+
if typeval.target_foreign:
|
139
|
+
return True
|
140
|
+
if typeval.target_fundamental:
|
141
|
+
if typeval.is_equiv(ast.TYPE_VALIST):
|
142
|
+
return False
|
143
|
+
# These are not introspectable pending us adding
|
144
|
+
# larger type tags to the typelib (in theory these could
|
145
|
+
# be 128 bit or larger)
|
146
|
+
if typeval.is_equiv((ast.TYPE_LONG_LONG, ast.TYPE_LONG_ULONG,
|
147
|
+
ast.TYPE_LONG_DOUBLE)):
|
148
|
+
return False
|
149
|
+
return True
|
150
|
+
target = self._transformer.lookup_typenode(typeval)
|
151
|
+
if not target:
|
152
|
+
return False
|
153
|
+
return target.introspectable and (not target.skip)
|
154
|
+
|
155
|
+
def _propagate_parameter_skip(self, parent, node):
|
156
|
+
if node.type.target_giname is not None:
|
157
|
+
target = self._transformer.lookup_typenode(node.type)
|
158
|
+
if target is None:
|
159
|
+
return
|
160
|
+
else:
|
161
|
+
return
|
162
|
+
|
163
|
+
if target.skip:
|
164
|
+
parent.skip = True
|
165
|
+
|
166
|
+
def _introspectable_alias_analysis(self, obj, stack):
|
167
|
+
if isinstance(obj, ast.Alias):
|
168
|
+
if not self._type_is_introspectable(obj.target):
|
169
|
+
obj.introspectable = False
|
170
|
+
return True
|
171
|
+
|
172
|
+
def _propagate_callable_skips(self, obj, stack):
|
173
|
+
if isinstance(obj, ast.Callable):
|
174
|
+
for param in obj.parameters:
|
175
|
+
self._propagate_parameter_skip(obj, param)
|
176
|
+
self._propagate_parameter_skip(obj, obj.retval)
|
177
|
+
return True
|
178
|
+
|
179
|
+
def _analyze_node(self, obj, stack):
|
180
|
+
if obj.skip:
|
181
|
+
return False
|
182
|
+
# Our first pass for scriptability
|
183
|
+
if isinstance(obj, ast.Callable):
|
184
|
+
for param in obj.parameters:
|
185
|
+
self._introspectable_param_analysis(obj, param)
|
186
|
+
self._introspectable_param_analysis(obj, obj.retval)
|
187
|
+
if isinstance(obj, (ast.Class, ast.Interface, ast.Record, ast.Union)):
|
188
|
+
for field in obj.fields:
|
189
|
+
if field.type:
|
190
|
+
if not self._type_is_introspectable(field.type):
|
191
|
+
field.introspectable = False
|
192
|
+
return True
|
193
|
+
|
194
|
+
def _introspectable_callable_analysis(self, obj, stack):
|
195
|
+
if obj.skip:
|
196
|
+
return False
|
197
|
+
# Propagate introspectability of parameters to entire functions
|
198
|
+
if isinstance(obj, ast.Callable):
|
199
|
+
for param in obj.parameters:
|
200
|
+
if not self._type_is_introspectable(param.type):
|
201
|
+
obj.introspectable = False
|
202
|
+
return True
|
203
|
+
if not self._type_is_introspectable(obj.retval.type):
|
204
|
+
obj.introspectable = False
|
205
|
+
return True
|
206
|
+
return True
|
207
|
+
|
208
|
+
def _introspectable_pass3(self, obj, stack):
|
209
|
+
if obj.skip:
|
210
|
+
return False
|
211
|
+
# Propagate introspectability for fields
|
212
|
+
if isinstance(obj, (ast.Class, ast.Interface, ast.Record, ast.Union)):
|
213
|
+
for field in obj.fields:
|
214
|
+
if field.anonymous_node:
|
215
|
+
if not field.anonymous_node.introspectable:
|
216
|
+
field.introspectable = False
|
217
|
+
else:
|
218
|
+
if not self._type_is_introspectable(field.type):
|
219
|
+
field.introspectable = False
|
220
|
+
# Propagate introspectability for properties
|
221
|
+
if isinstance(obj, (ast.Class, ast.Interface)):
|
222
|
+
for prop in obj.properties:
|
223
|
+
if not self._type_is_introspectable(prop.type):
|
224
|
+
prop.introspectable = False
|
225
|
+
for sig in obj.signals:
|
226
|
+
self._introspectable_callable_analysis(sig, [obj])
|
227
|
+
return True
|
228
|
+
|
229
|
+
def _remove_non_reachable_backcompat_copies(self, obj, stack):
|
230
|
+
if obj.skip:
|
231
|
+
return False
|
232
|
+
if (isinstance(obj, ast.Function) and obj.moved_to is not None):
|
233
|
+
# remove functions that are not introspectable
|
234
|
+
if not obj.introspectable:
|
235
|
+
obj.internal_skipped = True
|
236
|
+
return True
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# -*- Mode: Python -*-
|
2
|
+
# GObject-Introspection - a framework for introspecting GObject libraries
|
3
|
+
# Copyright (C) 2008 Johan Dahlin
|
4
|
+
#
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License as published by the Free Software Foundation; either
|
8
|
+
# version 2 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the
|
17
|
+
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
18
|
+
# Boston, MA 02111-1307, USA.
|
19
|
+
#
|
20
|
+
|
21
|
+
import imp
|
22
|
+
import os
|
23
|
+
import platform
|
24
|
+
import sys
|
25
|
+
|
26
|
+
from .utils import extract_libtool
|
27
|
+
|
28
|
+
|
29
|
+
class LibtoolImporter(object):
|
30
|
+
|
31
|
+
def __init__(self, name, path):
|
32
|
+
self.name = name
|
33
|
+
self.path = path
|
34
|
+
|
35
|
+
@classmethod
|
36
|
+
def find_module(cls, name, packagepath=None):
|
37
|
+
modparts = name.split('.')
|
38
|
+
filename = modparts.pop() + '.la'
|
39
|
+
|
40
|
+
# Given some.package.module 'path' is where subpackages of some.package
|
41
|
+
# should be looked for. See if we can find a ".libs/module.la" relative
|
42
|
+
# to those directories and failing that look for file
|
43
|
+
# "some/package/.libs/module.la" relative to sys.path
|
44
|
+
if len(modparts) > 0:
|
45
|
+
modprefix = os.path.join(*modparts)
|
46
|
+
modprefix = os.path.join(modprefix, '.libs')
|
47
|
+
else:
|
48
|
+
modprefix = '.libs'
|
49
|
+
|
50
|
+
for path in sys.path:
|
51
|
+
full = os.path.join(path, modprefix, filename)
|
52
|
+
if os.path.exists(full):
|
53
|
+
return cls(name, full)
|
54
|
+
|
55
|
+
def load_module(self, name):
|
56
|
+
realpath = extract_libtool(self.path)
|
57
|
+
platform_system = platform.system()
|
58
|
+
|
59
|
+
if platform_system == 'Darwin':
|
60
|
+
extension = '.dylib'
|
61
|
+
elif platform_system == 'Windows':
|
62
|
+
extension = '.dll'
|
63
|
+
else:
|
64
|
+
extension = '.so'
|
65
|
+
|
66
|
+
mod = imp.load_module(name, open(realpath), realpath, (extension, 'rb', 3))
|
67
|
+
mod.__loader__ = self
|
68
|
+
return mod
|
69
|
+
|
70
|
+
@classmethod
|
71
|
+
def __enter__(cls):
|
72
|
+
sys.meta_path.append(cls)
|
73
|
+
|
74
|
+
@classmethod
|
75
|
+
def __exit__(cls, type, value, traceback):
|
76
|
+
sys.meta_path.remove(cls)
|
@@ -0,0 +1,1337 @@
|
|
1
|
+
# -*- Mode: Python -*-
|
2
|
+
# Copyright (C) 2010 Red Hat, Inc.
|
3
|
+
#
|
4
|
+
# This library is free software; you can redistribute it and/or
|
5
|
+
# modify it under the terms of the GNU Lesser General Public
|
6
|
+
# License as published by the Free Software Foundation; either
|
7
|
+
# version 2 of the License, or (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This library is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
+
# Lesser General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU Lesser General Public
|
15
|
+
# License along with this library; if not, write to the
|
16
|
+
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
17
|
+
# Boston, MA 02111-1307, USA.
|
18
|
+
#
|
19
|
+
|
20
|
+
import re
|
21
|
+
|
22
|
+
from . import ast
|
23
|
+
from . import message
|
24
|
+
from .annotationparser import (TAG_VFUNC, TAG_SINCE, TAG_DEPRECATED, TAG_RETURNS,
|
25
|
+
TAG_ATTRIBUTES, TAG_RENAME_TO, TAG_TYPE,
|
26
|
+
TAG_UNREF_FUNC, TAG_REF_FUNC, TAG_SET_VALUE_FUNC,
|
27
|
+
TAG_GET_VALUE_FUNC, TAG_VALUE, TAG_TRANSFER,
|
28
|
+
TAG_STABILITY)
|
29
|
+
from .annotationparser import (OPT_ALLOW_NONE, OPT_ARRAY, OPT_ATTRIBUTE,
|
30
|
+
OPT_ELEMENT_TYPE, OPT_IN, OPT_INOUT,
|
31
|
+
OPT_INOUT_ALT, OPT_OUT, OPT_SCOPE,
|
32
|
+
OPT_OUT_CALLER_ALLOCATES, OPT_OUT_CALLEE_ALLOCATES,
|
33
|
+
OPT_TYPE, OPT_CLOSURE, OPT_DESTROY, OPT_TRANSFER, OPT_SKIP,
|
34
|
+
OPT_FOREIGN, OPT_ARRAY_FIXED_SIZE,
|
35
|
+
OPT_ARRAY_LENGTH, OPT_ARRAY_ZERO_TERMINATED,
|
36
|
+
OPT_CONSTRUCTOR, OPT_METHOD,
|
37
|
+
OPT_TRANSFER_NONE, OPT_TRANSFER_FLOATING)
|
38
|
+
from .annotationparser import AnnotationParser
|
39
|
+
from .transformer import TransformerException
|
40
|
+
from .utils import to_underscores, to_underscores_noprefix
|
41
|
+
|
42
|
+
class MainTransformer(object):
|
43
|
+
|
44
|
+
def __init__(self, transformer, blocks):
|
45
|
+
self._transformer = transformer
|
46
|
+
self._blocks = blocks
|
47
|
+
self._namespace = transformer.namespace
|
48
|
+
self._uscore_type_names = {}
|
49
|
+
|
50
|
+
# Public API
|
51
|
+
|
52
|
+
def transform(self):
|
53
|
+
contents = list(self._namespace.itervalues())
|
54
|
+
if len(contents) == 0:
|
55
|
+
message.fatal("""Namespace is empty; likely causes are:
|
56
|
+
* Not including .h files to be scanned
|
57
|
+
* Broken --identifier-prefix
|
58
|
+
""")
|
59
|
+
|
60
|
+
# Some initial namespace surgery
|
61
|
+
self._namespace.walk(self._pass_fixup_hidden_fields)
|
62
|
+
|
63
|
+
# We have a rough tree which should have most of of the types
|
64
|
+
# we know about. Let's attempt closure; walk over all of the
|
65
|
+
# Type() types and see if they match up with something.
|
66
|
+
self._namespace.walk(self._pass_type_resolution)
|
67
|
+
|
68
|
+
# Read in annotations needed early
|
69
|
+
self._namespace.walk(self._pass_read_annotations_early)
|
70
|
+
|
71
|
+
# Determine some default values for transfer etc.
|
72
|
+
# based on the current tree.
|
73
|
+
self._namespace.walk(self._pass_callable_defaults)
|
74
|
+
|
75
|
+
# Read in most annotations now.
|
76
|
+
self._namespace.walk(self._pass_read_annotations)
|
77
|
+
|
78
|
+
# Now that we've possibly seen more types from annotations,
|
79
|
+
# do another type resolution pass.
|
80
|
+
self._namespace.walk(self._pass_type_resolution)
|
81
|
+
|
82
|
+
# Generate a reverse mapping "bar_baz" -> BarBaz
|
83
|
+
for node in self._namespace.itervalues():
|
84
|
+
if isinstance(node, ast.Registered) and node.get_type is not None:
|
85
|
+
self._uscore_type_names[node.c_symbol_prefix] = node
|
86
|
+
elif isinstance(node, (ast.Record, ast.Union)):
|
87
|
+
uscored = to_underscores_noprefix(node.name).lower()
|
88
|
+
self._uscore_type_names[uscored] = node
|
89
|
+
|
90
|
+
for node in list(self._namespace.itervalues()):
|
91
|
+
if isinstance(node, ast.Function):
|
92
|
+
# Discover which toplevel functions are actually methods
|
93
|
+
self._pair_function(node)
|
94
|
+
if isinstance(node, (ast.Class, ast.Interface)):
|
95
|
+
self._pair_class_virtuals(node)
|
96
|
+
|
97
|
+
# Some annotations need to be post function pairing
|
98
|
+
self._namespace.walk(self._pass_read_annotations2)
|
99
|
+
|
100
|
+
# Another type resolution pass after we've parsed virtuals, etc.
|
101
|
+
self._namespace.walk(self._pass_type_resolution)
|
102
|
+
|
103
|
+
self._namespace.walk(self._pass3)
|
104
|
+
|
105
|
+
# TODO - merge into pass3
|
106
|
+
self._pair_quarks_with_enums()
|
107
|
+
|
108
|
+
# Private
|
109
|
+
|
110
|
+
def _pass_fixup_hidden_fields(self, node, chain):
|
111
|
+
"""Hide all callbacks starting with _; the typical
|
112
|
+
usage is void (*_gtk_reserved1)(void);"""
|
113
|
+
if not isinstance(node, (ast.Class, ast.Interface,
|
114
|
+
ast.Record, ast.Union)):
|
115
|
+
return True
|
116
|
+
for field in node.fields:
|
117
|
+
if field is None:
|
118
|
+
continue
|
119
|
+
if (field.name.startswith('_')
|
120
|
+
and field.anonymous_node is not None
|
121
|
+
and isinstance(field.anonymous_node, ast.Callback)):
|
122
|
+
field.introspectable = False
|
123
|
+
return True
|
124
|
+
|
125
|
+
def _get_validate_parameter_name(self, parent, param_name, origin):
|
126
|
+
try:
|
127
|
+
param = parent.get_parameter(param_name)
|
128
|
+
except ValueError:
|
129
|
+
param = None
|
130
|
+
if param is None:
|
131
|
+
if isinstance(origin, ast.Parameter):
|
132
|
+
origin_name = 'parameter %s' % (origin.argname, )
|
133
|
+
else:
|
134
|
+
origin_name = 'return value'
|
135
|
+
message.log_node(
|
136
|
+
message.FATAL, parent,
|
137
|
+
"can't find parameter %s referenced by %s of %r"
|
138
|
+
% (param_name, origin_name, parent.name))
|
139
|
+
|
140
|
+
return param.argname
|
141
|
+
|
142
|
+
def _apply_annotation_rename_to(self, node, chain, block):
|
143
|
+
if not block:
|
144
|
+
return
|
145
|
+
rename_to = block.get_tag(TAG_RENAME_TO)
|
146
|
+
if not rename_to:
|
147
|
+
return
|
148
|
+
rename_to = rename_to.value
|
149
|
+
target = self._namespace.get_by_symbol(rename_to)
|
150
|
+
if not target:
|
151
|
+
message.warn_node(node,
|
152
|
+
"Can't find symbol %r referenced by Rename annotation" % (
|
153
|
+
rename_to, ))
|
154
|
+
elif target.shadowed_by:
|
155
|
+
message.warn_node(node,
|
156
|
+
"Function %r already shadowed by %r, can't overwrite with %r" % (
|
157
|
+
target.symbol,
|
158
|
+
target.shadowed_by,
|
159
|
+
rename_to))
|
160
|
+
elif target.shadows:
|
161
|
+
message.warn_node(node,
|
162
|
+
"Function %r already shadows %r, can't multiply shadow with %r" % (
|
163
|
+
target.symbol,
|
164
|
+
target.shadows,
|
165
|
+
rename_to))
|
166
|
+
else:
|
167
|
+
target.shadowed_by = node.name
|
168
|
+
node.shadows = target.name
|
169
|
+
|
170
|
+
def _apply_annotations_function(self, node, chain):
|
171
|
+
block = self._blocks.get(node.symbol)
|
172
|
+
self._apply_annotations_callable(node, chain, block)
|
173
|
+
|
174
|
+
def _pass_read_annotations_early(self, node, chain):
|
175
|
+
if isinstance(node, ast.Record):
|
176
|
+
if node.ctype is not None:
|
177
|
+
block = self._blocks.get(node.ctype)
|
178
|
+
else:
|
179
|
+
block = self._blocks.get(node.c_name)
|
180
|
+
self._apply_annotations_annotated(node, block)
|
181
|
+
return True
|
182
|
+
|
183
|
+
def _pass_callable_defaults(self, node, chain):
|
184
|
+
if isinstance(node, (ast.Callable, ast.Signal)):
|
185
|
+
for param in node.parameters:
|
186
|
+
if param.transfer is None:
|
187
|
+
param.transfer = self._get_transfer_default(node, param)
|
188
|
+
if node.retval.transfer is None:
|
189
|
+
node.retval.transfer = self._get_transfer_default(node, node.retval)
|
190
|
+
return True
|
191
|
+
|
192
|
+
def _get_annotation_name(self, node):
|
193
|
+
if isinstance(node, (ast.Class, ast.Interface, ast.Record,
|
194
|
+
ast.Union, ast.Enum, ast.Bitfield,
|
195
|
+
ast.Callback, ast.Alias, ast.Constant)):
|
196
|
+
if node.ctype is not None:
|
197
|
+
return node.ctype
|
198
|
+
elif isinstance(node, ast.Registered) and node.gtype_name is not None:
|
199
|
+
return node.gtype_name
|
200
|
+
return node.c_name
|
201
|
+
raise AssertionError("Unhandled node %r" % (node, ))
|
202
|
+
|
203
|
+
def _get_block(self, node):
|
204
|
+
return self._blocks.get(self._get_annotation_name(node))
|
205
|
+
|
206
|
+
def _pass_read_annotations(self, node, chain):
|
207
|
+
if not node.namespace:
|
208
|
+
return False
|
209
|
+
if isinstance(node, ast.Alias):
|
210
|
+
self._apply_annotations_alias(node, chain)
|
211
|
+
if isinstance(node, ast.Function):
|
212
|
+
self._apply_annotations_function(node, chain)
|
213
|
+
if isinstance(node, ast.Callback):
|
214
|
+
self._apply_annotations_callable(node, chain, block = self._get_block(node))
|
215
|
+
if isinstance(node, (ast.Class, ast.Interface, ast.Union, ast.Enum,
|
216
|
+
ast.Bitfield, ast.Callback)):
|
217
|
+
self._apply_annotations_annotated(node, self._get_block(node))
|
218
|
+
if isinstance(node, (ast.Enum, ast.Bitfield)):
|
219
|
+
self._apply_annotations_enum_members(node, self._get_block(node))
|
220
|
+
if isinstance(node, (ast.Class, ast.Interface, ast.Record, ast.Union)):
|
221
|
+
block = self._get_block(node)
|
222
|
+
for field in node.fields:
|
223
|
+
self._apply_annotations_field(node, block, field)
|
224
|
+
name = self._get_annotation_name(node)
|
225
|
+
section_name = 'SECTION:' + name.lower()
|
226
|
+
block = self._blocks.get(section_name)
|
227
|
+
if block:
|
228
|
+
node.doc = block.comment if block.comment else ''
|
229
|
+
if isinstance(node, (ast.Class, ast.Interface)):
|
230
|
+
for prop in node.properties:
|
231
|
+
self._apply_annotations_property(node, prop)
|
232
|
+
for sig in node.signals:
|
233
|
+
self._apply_annotations_signal(node, sig)
|
234
|
+
if isinstance(node, ast.Class):
|
235
|
+
block = self._get_block(node)
|
236
|
+
if block:
|
237
|
+
tag = block.get_tag(TAG_UNREF_FUNC)
|
238
|
+
node.unref_func = tag.value if tag else None
|
239
|
+
tag = block.get_tag(TAG_REF_FUNC)
|
240
|
+
node.ref_func = tag.value if tag else None
|
241
|
+
tag = block.get_tag(TAG_SET_VALUE_FUNC)
|
242
|
+
node.set_value_func = tag.value if tag else None
|
243
|
+
tag = block.get_tag(TAG_GET_VALUE_FUNC)
|
244
|
+
node.get_value_func = tag.value if tag else None
|
245
|
+
if isinstance(node, ast.Constant):
|
246
|
+
self._apply_annotations_constant(node)
|
247
|
+
return True
|
248
|
+
|
249
|
+
def _adjust_container_type(self, parent, node, options):
|
250
|
+
has_element_type = OPT_ELEMENT_TYPE in options
|
251
|
+
has_array = OPT_ARRAY in options
|
252
|
+
|
253
|
+
if has_array:
|
254
|
+
self._apply_annotations_array(parent, node, options)
|
255
|
+
elif has_element_type:
|
256
|
+
self._apply_annotations_element_type(parent, node, options)
|
257
|
+
|
258
|
+
if isinstance(node.type, ast.Array):
|
259
|
+
self._check_array_element_type(node.type, options)
|
260
|
+
|
261
|
+
def _resolve(self, type_str, type_node=None, node=None, parent=None):
|
262
|
+
def grab_one(type_str, resolver, top_combiner, combiner):
|
263
|
+
"""Return a complete type, and the trailing string part after it.
|
264
|
+
Use resolver() on each identifier, and combiner() on the parts of
|
265
|
+
each complete type. (top_combiner is used on the top-most type.)"""
|
266
|
+
bits = re.split(r'([,<>()])', type_str, 1)
|
267
|
+
first, sep, rest = [bits[0], '', ''] if (len(bits)==1) else bits
|
268
|
+
args = [resolver(first)]
|
269
|
+
if sep == '<' or sep == '(':
|
270
|
+
lastsep = '>' if (sep == '<') else ')'
|
271
|
+
while sep != lastsep:
|
272
|
+
next, rest = grab_one(rest, resolver, combiner, combiner)
|
273
|
+
args.append(next)
|
274
|
+
sep, rest = rest[0], rest[1:]
|
275
|
+
else:
|
276
|
+
rest = sep + rest
|
277
|
+
return top_combiner(*args), rest
|
278
|
+
def resolver(ident):
|
279
|
+
res = self._transformer.create_type_from_user_string(ident)
|
280
|
+
return res
|
281
|
+
def combiner(base, *rest):
|
282
|
+
if not rest:
|
283
|
+
return base
|
284
|
+
if isinstance(base, ast.List) and len(rest) == 1:
|
285
|
+
return ast.List(base.name, *rest)
|
286
|
+
if isinstance(base, ast.Map) and len(rest) == 2:
|
287
|
+
return ast.Map(*rest)
|
288
|
+
message.warn(
|
289
|
+
"Too many parameters in type specification %r" % (type_str, ))
|
290
|
+
return base
|
291
|
+
def top_combiner(base, *rest):
|
292
|
+
if type_node is not None and isinstance(type_node, ast.Type):
|
293
|
+
base.is_const = type_node.is_const
|
294
|
+
return combiner(base, *rest)
|
295
|
+
|
296
|
+
result, rest = grab_one(type_str, resolver, top_combiner, combiner)
|
297
|
+
if rest:
|
298
|
+
message.warn("Trailing components in type specification %r" % (
|
299
|
+
type_str, ))
|
300
|
+
|
301
|
+
if not result.resolved:
|
302
|
+
position = None
|
303
|
+
if parent is not None and isinstance(parent, ast.Function):
|
304
|
+
text = parent.symbol
|
305
|
+
position = self._get_position(parent, node)
|
306
|
+
else:
|
307
|
+
text = type_str
|
308
|
+
message.warn_node(parent, "%s: Unknown type: %r" %
|
309
|
+
(text, type_str), positions=position)
|
310
|
+
return result
|
311
|
+
|
312
|
+
def _resolve_toplevel(self, type_str, type_node=None, node=None, parent=None):
|
313
|
+
"""Like _resolve(), but attempt to preserve more attributes of original type."""
|
314
|
+
result = self._resolve(type_str, type_node=type_node, node=node, parent=parent)
|
315
|
+
# If we replace a node with a new type (such as an annotated) we
|
316
|
+
# might lose the ctype from the original node.
|
317
|
+
if type_node is not None:
|
318
|
+
result.ctype = type_node.ctype
|
319
|
+
return result
|
320
|
+
|
321
|
+
def _get_position(self, func, param):
|
322
|
+
block = self._blocks.get(func.symbol)
|
323
|
+
if block:
|
324
|
+
if isinstance(param, ast.Parameter):
|
325
|
+
tag = block.params.get(param.argname)
|
326
|
+
elif isinstance(param, ast.Return):
|
327
|
+
tag = block.tags.get(TAG_RETURNS)
|
328
|
+
else:
|
329
|
+
tag = None
|
330
|
+
|
331
|
+
if tag.position:
|
332
|
+
return tag.position
|
333
|
+
|
334
|
+
return block.position
|
335
|
+
|
336
|
+
def _check_array_element_type(self, array, options):
|
337
|
+
# GPtrArrays are allowed to contain non basic types
|
338
|
+
# (except enums and flags) or basic types that are
|
339
|
+
# as big as a gpointer
|
340
|
+
if array.array_type == ast.Array.GLIB_PTRARRAY and \
|
341
|
+
((array.element_type in ast.BASIC_GIR_TYPES
|
342
|
+
and not array.element_type in ast.POINTER_TYPES) or
|
343
|
+
isinstance(array.element_type, ast.Enum) or
|
344
|
+
isinstance(array.element_type, ast.Bitfield)):
|
345
|
+
message.warn("invalid (element-type) for a GPtrArray, "
|
346
|
+
"must be a pointer", options.position)
|
347
|
+
|
348
|
+
# GByteArrays have (element-type) guint8 by default
|
349
|
+
if array.array_type == ast.Array.GLIB_BYTEARRAY:
|
350
|
+
if array.element_type == ast.TYPE_ANY:
|
351
|
+
array.element_type = ast.TYPE_UINT8
|
352
|
+
elif not array.element_type in [ast.TYPE_UINT8,
|
353
|
+
ast.TYPE_INT8,
|
354
|
+
ast.TYPE_CHAR]:
|
355
|
+
message.warn("invalid (element-type) for a GByteArray, "
|
356
|
+
"must be one of guint8, gint8 or gchar",
|
357
|
+
options.position)
|
358
|
+
|
359
|
+
def _apply_annotations_array(self, parent, node, options):
|
360
|
+
array_opt = options.get(OPT_ARRAY)
|
361
|
+
if array_opt:
|
362
|
+
array_values = array_opt.all()
|
363
|
+
else:
|
364
|
+
array_values = {}
|
365
|
+
|
366
|
+
element_type = options.get(OPT_ELEMENT_TYPE)
|
367
|
+
if element_type is not None:
|
368
|
+
element_type_node = self._resolve(element_type.one(),
|
369
|
+
node.type, node, parent)
|
370
|
+
elif isinstance(node.type, ast.Array):
|
371
|
+
element_type_node = node.type.element_type
|
372
|
+
else:
|
373
|
+
# We're assuming here that Foo* with an (array) annotation
|
374
|
+
# and no (element-type) means array of Foo
|
375
|
+
element_type_node = node.type.clone()
|
376
|
+
# The element's ctype is the array's dereferenced
|
377
|
+
if element_type_node.ctype is not None and \
|
378
|
+
element_type_node.ctype.endswith('*'):
|
379
|
+
element_type_node.ctype = element_type_node.ctype[:-1]
|
380
|
+
|
381
|
+
if isinstance(node.type, ast.Array):
|
382
|
+
array_type = node.type.array_type
|
383
|
+
else:
|
384
|
+
array_type = None
|
385
|
+
container_type = ast.Array(array_type, element_type_node,
|
386
|
+
ctype=node.type.ctype,
|
387
|
+
is_const=node.type.is_const)
|
388
|
+
if OPT_ARRAY_ZERO_TERMINATED in array_values:
|
389
|
+
container_type.zeroterminated = array_values.get(
|
390
|
+
OPT_ARRAY_ZERO_TERMINATED) == '1'
|
391
|
+
else:
|
392
|
+
container_type.zeroterminated = False
|
393
|
+
length = array_values.get(OPT_ARRAY_LENGTH)
|
394
|
+
if length is not None:
|
395
|
+
paramname = self._get_validate_parameter_name(parent, length, node)
|
396
|
+
if paramname:
|
397
|
+
param = parent.get_parameter(paramname)
|
398
|
+
param.direction = node.direction
|
399
|
+
if param.direction == ast.PARAM_DIRECTION_OUT:
|
400
|
+
param.transfer = ast.PARAM_TRANSFER_FULL
|
401
|
+
container_type.length_param_name = param.argname
|
402
|
+
fixed = array_values.get(OPT_ARRAY_FIXED_SIZE)
|
403
|
+
if fixed:
|
404
|
+
try:
|
405
|
+
container_type.size = int(fixed)
|
406
|
+
except ValueError:
|
407
|
+
# Already warned in annotationparser.py
|
408
|
+
return
|
409
|
+
node.type = container_type
|
410
|
+
|
411
|
+
def _apply_annotations_element_type(self, parent, node, options):
|
412
|
+
element_type_opt = options.get(OPT_ELEMENT_TYPE)
|
413
|
+
if element_type_opt is None:
|
414
|
+
message.warn(
|
415
|
+
'element-type annotation takes at least one option, '
|
416
|
+
'none given',
|
417
|
+
options.position)
|
418
|
+
return
|
419
|
+
|
420
|
+
if isinstance(node.type, ast.List):
|
421
|
+
if element_type_opt.length() != 1:
|
422
|
+
message.warn(
|
423
|
+
'element-type annotation for a list must have exactly '
|
424
|
+
'one option, not %d options' % (element_type_opt.length(), ),
|
425
|
+
options.position)
|
426
|
+
return
|
427
|
+
node.type.element_type = self._resolve(element_type_opt.one(),
|
428
|
+
node.type, node, parent)
|
429
|
+
elif isinstance(node.type, ast.Map):
|
430
|
+
if element_type_opt.length() != 2:
|
431
|
+
message.warn(
|
432
|
+
'element-type annotation for a hash table must have exactly '
|
433
|
+
'two options, not %d option(s)' % (element_type_opt.length(), ),
|
434
|
+
options.position)
|
435
|
+
return
|
436
|
+
element_type = element_type_opt.flat()
|
437
|
+
node.type.key_type = self._resolve(element_type[0],
|
438
|
+
node.type, node, parent)
|
439
|
+
node.type.value_type = self._resolve(element_type[1],
|
440
|
+
node.type, node, parent)
|
441
|
+
elif isinstance(node.type, ast.Array):
|
442
|
+
if element_type_opt.length() != 1:
|
443
|
+
message.warn(
|
444
|
+
'element-type annotation for an array must have exactly '
|
445
|
+
'one option, not %d options' % (element_type_opt.length(), ),
|
446
|
+
options.position)
|
447
|
+
return
|
448
|
+
node.type.element_type = self._resolve(element_type_opt.one(),
|
449
|
+
node.type, node, parent)
|
450
|
+
else:
|
451
|
+
message.warn_node(parent,
|
452
|
+
"Unknown container %r for element-type annotation" % (node.type, ))
|
453
|
+
|
454
|
+
def _get_transfer_default_param(self, parent, node):
|
455
|
+
if node.direction in [ast.PARAM_DIRECTION_INOUT,
|
456
|
+
ast.PARAM_DIRECTION_OUT]:
|
457
|
+
if node.caller_allocates:
|
458
|
+
return ast.PARAM_TRANSFER_NONE
|
459
|
+
return ast.PARAM_TRANSFER_FULL
|
460
|
+
return ast.PARAM_TRANSFER_NONE
|
461
|
+
|
462
|
+
def _get_transfer_default_returntype_basic(self, typeval):
|
463
|
+
if (typeval.is_equiv(ast.BASIC_GIR_TYPES)
|
464
|
+
or typeval.is_const
|
465
|
+
or typeval.is_equiv(ast.TYPE_NONE)):
|
466
|
+
return ast.PARAM_TRANSFER_NONE
|
467
|
+
elif typeval.is_equiv(ast.TYPE_STRING):
|
468
|
+
# Non-const strings default to FULL
|
469
|
+
return ast.PARAM_TRANSFER_FULL
|
470
|
+
elif typeval.target_fundamental:
|
471
|
+
# This looks like just GType right now
|
472
|
+
return None
|
473
|
+
return None
|
474
|
+
|
475
|
+
def _is_gi_subclass(self, typeval, supercls_type):
|
476
|
+
cls = self._transformer.lookup_typenode(typeval)
|
477
|
+
assert cls, str(typeval)
|
478
|
+
supercls = self._transformer.lookup_typenode(supercls_type)
|
479
|
+
assert supercls
|
480
|
+
if cls is supercls:
|
481
|
+
return True
|
482
|
+
if cls.parent_type and cls.parent_type.target_giname != 'GObject.Object':
|
483
|
+
return self._is_gi_subclass(cls.parent_type, supercls_type)
|
484
|
+
return False
|
485
|
+
|
486
|
+
def _get_transfer_default_return(self, parent, node):
|
487
|
+
typeval = node.type
|
488
|
+
basic = self._get_transfer_default_returntype_basic(typeval)
|
489
|
+
if basic:
|
490
|
+
return basic
|
491
|
+
if not typeval.target_giname:
|
492
|
+
return None
|
493
|
+
target = self._transformer.lookup_typenode(typeval)
|
494
|
+
if isinstance(target, ast.Alias):
|
495
|
+
return self._get_transfer_default_returntype_basic(target.target)
|
496
|
+
elif (isinstance(target, ast.Boxed)
|
497
|
+
or (isinstance(target, (ast.Record, ast.Union))
|
498
|
+
and (target.gtype_name is not None or target.foreign))):
|
499
|
+
return ast.PARAM_TRANSFER_FULL
|
500
|
+
elif isinstance(target, (ast.Enum, ast.Bitfield)):
|
501
|
+
return ast.PARAM_TRANSFER_NONE
|
502
|
+
# Handle constructors specially here
|
503
|
+
elif isinstance(parent, ast.Function) and parent.is_constructor:
|
504
|
+
if isinstance(target, ast.Class):
|
505
|
+
initially_unowned_type = ast.Type(target_giname='GObject.InitiallyUnowned')
|
506
|
+
initially_unowned = self._transformer.lookup_typenode(initially_unowned_type)
|
507
|
+
if initially_unowned and self._is_gi_subclass(typeval, initially_unowned_type):
|
508
|
+
return ast.PARAM_TRANSFER_NONE
|
509
|
+
else:
|
510
|
+
return ast.PARAM_TRANSFER_FULL
|
511
|
+
elif isinstance(target, (ast.Record, ast.Union)):
|
512
|
+
return ast.PARAM_TRANSFER_FULL
|
513
|
+
else:
|
514
|
+
raise AssertionError("Invalid constructor")
|
515
|
+
elif isinstance(target, (ast.Class, ast.Record, ast.Union)):
|
516
|
+
# Explicitly no default for these
|
517
|
+
return None
|
518
|
+
else:
|
519
|
+
return None
|
520
|
+
|
521
|
+
def _get_transfer_default(self, parent, node):
|
522
|
+
if node.type.is_equiv(ast.TYPE_NONE) or isinstance(node.type, ast.Varargs):
|
523
|
+
return ast.PARAM_TRANSFER_NONE
|
524
|
+
elif isinstance(node, ast.Parameter):
|
525
|
+
return self._get_transfer_default_param(parent, node)
|
526
|
+
elif isinstance(node, ast.Return):
|
527
|
+
return self._get_transfer_default_return(parent, node)
|
528
|
+
elif isinstance(node, ast.Field):
|
529
|
+
return ast.PARAM_TRANSFER_NONE
|
530
|
+
elif isinstance(node, ast.Property):
|
531
|
+
return ast.PARAM_TRANSFER_NONE
|
532
|
+
else:
|
533
|
+
raise AssertionError(node)
|
534
|
+
|
535
|
+
def _apply_annotations_param_ret_common(self, parent, node, tag):
|
536
|
+
options = getattr(tag, 'options', {})
|
537
|
+
|
538
|
+
param_type = options.get(OPT_TYPE)
|
539
|
+
if param_type:
|
540
|
+
node.type = self._resolve_toplevel(param_type.one(),
|
541
|
+
node.type, node, parent)
|
542
|
+
|
543
|
+
caller_allocates = False
|
544
|
+
annotated_direction = None
|
545
|
+
if (OPT_INOUT in options or
|
546
|
+
OPT_INOUT_ALT in options):
|
547
|
+
annotated_direction = ast.PARAM_DIRECTION_INOUT
|
548
|
+
elif OPT_OUT in options:
|
549
|
+
subtype = options[OPT_OUT]
|
550
|
+
if subtype is not None:
|
551
|
+
subtype = subtype.one()
|
552
|
+
annotated_direction = ast.PARAM_DIRECTION_OUT
|
553
|
+
if subtype in (None, ''):
|
554
|
+
if node.type.target_giname and node.type.ctype:
|
555
|
+
target = self._transformer.lookup_giname(node.type.target_giname)
|
556
|
+
target = self._transformer.resolve_aliases(target)
|
557
|
+
has_double_indirection = '**' in node.type.ctype
|
558
|
+
is_structure_or_union = isinstance(target, (ast.Record, ast.Union))
|
559
|
+
caller_allocates = (not has_double_indirection and is_structure_or_union)
|
560
|
+
else:
|
561
|
+
caller_allocates = False
|
562
|
+
elif subtype == OPT_OUT_CALLER_ALLOCATES:
|
563
|
+
caller_allocates = True
|
564
|
+
elif subtype == OPT_OUT_CALLEE_ALLOCATES:
|
565
|
+
caller_allocates = False
|
566
|
+
elif OPT_IN in options:
|
567
|
+
annotated_direction = ast.PARAM_DIRECTION_IN
|
568
|
+
|
569
|
+
if (annotated_direction is not None) and (annotated_direction != node.direction):
|
570
|
+
node.direction = annotated_direction
|
571
|
+
node.caller_allocates = caller_allocates
|
572
|
+
# Also reset the transfer default if we're toggling direction
|
573
|
+
node.transfer = self._get_transfer_default(parent, node)
|
574
|
+
|
575
|
+
transfer_tag = options.get(OPT_TRANSFER)
|
576
|
+
if transfer_tag and transfer_tag.length() == 1:
|
577
|
+
transfer = transfer_tag.one()
|
578
|
+
if transfer == OPT_TRANSFER_FLOATING:
|
579
|
+
transfer = OPT_TRANSFER_NONE
|
580
|
+
node.transfer = transfer
|
581
|
+
|
582
|
+
self._adjust_container_type(parent, node, options)
|
583
|
+
|
584
|
+
if (OPT_ALLOW_NONE in options or
|
585
|
+
node.type.target_giname == 'Gio.AsyncReadyCallback' or
|
586
|
+
node.type.target_giname == 'Gio.Cancellable'):
|
587
|
+
node.allow_none = True
|
588
|
+
|
589
|
+
if tag is not None and tag.comment is not None:
|
590
|
+
node.doc = tag.comment
|
591
|
+
|
592
|
+
if OPT_SKIP in options:
|
593
|
+
node.skip = True
|
594
|
+
|
595
|
+
if options:
|
596
|
+
for attribute in options.getall(OPT_ATTRIBUTE):
|
597
|
+
node.attributes.append(attribute.flat())
|
598
|
+
|
599
|
+
def _apply_annotations_annotated(self, node, block):
|
600
|
+
if block is None:
|
601
|
+
return
|
602
|
+
|
603
|
+
node.doc = block.comment if block.comment else ''
|
604
|
+
|
605
|
+
since_tag = block.get_tag(TAG_SINCE)
|
606
|
+
if since_tag is not None:
|
607
|
+
node.version = since_tag.value
|
608
|
+
|
609
|
+
deprecated_tag = block.get_tag(TAG_DEPRECATED)
|
610
|
+
if deprecated_tag is not None:
|
611
|
+
value = deprecated_tag.value
|
612
|
+
if ': ' in value:
|
613
|
+
colon = value.find(': ')
|
614
|
+
version = value[:colon]
|
615
|
+
desc = value[colon+2:]
|
616
|
+
else:
|
617
|
+
desc = value
|
618
|
+
version = None
|
619
|
+
node.deprecated = desc
|
620
|
+
if version is not None:
|
621
|
+
node.deprecated_version = version
|
622
|
+
|
623
|
+
stability_tag = block.get_tag(TAG_STABILITY)
|
624
|
+
if stability_tag is not None:
|
625
|
+
stability = stability_tag.value.capitalize()
|
626
|
+
if stability in ["Stable", "Unstable", "Private", "Internal"]:
|
627
|
+
node.stability = stability
|
628
|
+
else:
|
629
|
+
message.warn('unknown value "%s" for Stability tag' % (
|
630
|
+
stability_tag.value), stability_tag.position)
|
631
|
+
|
632
|
+
annos_tag = block.get_tag(TAG_ATTRIBUTES)
|
633
|
+
if annos_tag is not None:
|
634
|
+
for key, value in annos_tag.options.items():
|
635
|
+
if value:
|
636
|
+
node.attributes.append((key, value.one()))
|
637
|
+
|
638
|
+
if OPT_SKIP in block.options:
|
639
|
+
node.skip = True
|
640
|
+
|
641
|
+
if OPT_FOREIGN in block.options:
|
642
|
+
node.foreign = True
|
643
|
+
|
644
|
+
if OPT_CONSTRUCTOR in block.options and isinstance(node, ast.Function):
|
645
|
+
node.is_constructor = True
|
646
|
+
|
647
|
+
if OPT_METHOD in block.options:
|
648
|
+
node.is_method = True
|
649
|
+
|
650
|
+
def _apply_annotations_alias(self, node, chain):
|
651
|
+
block = self._get_block(node)
|
652
|
+
self._apply_annotations_annotated(node, block)
|
653
|
+
|
654
|
+
def _apply_annotations_param(self, parent, param, tag):
|
655
|
+
if tag:
|
656
|
+
options = tag.options
|
657
|
+
else:
|
658
|
+
options = {}
|
659
|
+
if isinstance(parent, (ast.Function, ast.VFunction)):
|
660
|
+
scope = options.get(OPT_SCOPE)
|
661
|
+
if scope and scope.length() == 1:
|
662
|
+
param.scope = scope.one()
|
663
|
+
param.transfer = ast.PARAM_TRANSFER_NONE
|
664
|
+
|
665
|
+
destroy = options.get(OPT_DESTROY)
|
666
|
+
if destroy:
|
667
|
+
param.destroy_name = self._get_validate_parameter_name(parent,
|
668
|
+
destroy.one(),
|
669
|
+
param)
|
670
|
+
if param.destroy_name is not None:
|
671
|
+
param.scope = ast.PARAM_SCOPE_NOTIFIED
|
672
|
+
destroy_param = parent.get_parameter(param.destroy_name)
|
673
|
+
# This is technically bogus; we're setting the scope on the destroy
|
674
|
+
# itself. But this helps avoid tripping a warning from finaltransformer,
|
675
|
+
# since we don't have a way right now to flag this callback a destroy.
|
676
|
+
destroy_param.scope = ast.PARAM_SCOPE_NOTIFIED
|
677
|
+
closure = options.get(OPT_CLOSURE)
|
678
|
+
if closure and closure.length() == 1:
|
679
|
+
param.closure_name = self._get_validate_parameter_name(parent,
|
680
|
+
closure.one(),
|
681
|
+
param)
|
682
|
+
elif isinstance(parent, ast.Callback):
|
683
|
+
if OPT_CLOSURE in options:
|
684
|
+
# For callbacks, (closure) appears without an
|
685
|
+
# argument, and tags a parameter that is a closure. We
|
686
|
+
# represent it (weirdly) in the gir and typelib by
|
687
|
+
# setting param.closure_name to itself.
|
688
|
+
param.closure_name = param.argname
|
689
|
+
|
690
|
+
self._apply_annotations_param_ret_common(parent, param, tag)
|
691
|
+
|
692
|
+
def _apply_annotations_return(self, parent, return_, block):
|
693
|
+
if block:
|
694
|
+
tag = block.get_tag(TAG_RETURNS)
|
695
|
+
else:
|
696
|
+
tag = None
|
697
|
+
self._apply_annotations_param_ret_common(parent, return_, tag)
|
698
|
+
|
699
|
+
def _apply_annotations_params(self, parent, params, block):
|
700
|
+
declparams = set([])
|
701
|
+
if parent.instance_parameter:
|
702
|
+
declparams.add(parent.instance_parameter.argname)
|
703
|
+
for param in params:
|
704
|
+
if block:
|
705
|
+
tag = block.get_param(param.argname)
|
706
|
+
else:
|
707
|
+
tag = None
|
708
|
+
self._apply_annotations_param(parent, param, tag)
|
709
|
+
declparams.add(param.argname)
|
710
|
+
|
711
|
+
if not block:
|
712
|
+
return
|
713
|
+
docparams = set(block.params)
|
714
|
+
|
715
|
+
unknown = docparams - declparams
|
716
|
+
unused = declparams - docparams
|
717
|
+
|
718
|
+
for doc_name in unknown:
|
719
|
+
# Skip varargs, see #629759
|
720
|
+
if doc_name.lower() in ['...', 'varargs', TAG_RETURNS]:
|
721
|
+
continue
|
722
|
+
if len(unused) == 0:
|
723
|
+
text = ''
|
724
|
+
elif len(unused) == 1:
|
725
|
+
(param, ) = unused
|
726
|
+
text = ', should be %r' % (param, )
|
727
|
+
else:
|
728
|
+
text = ', should be one of %s' % (
|
729
|
+
', '.join(repr(p) for p in unused), )
|
730
|
+
|
731
|
+
tag = block.get_param(doc_name)
|
732
|
+
message.warn(
|
733
|
+
'%s: unknown parameter %r in documentation comment%s' % (
|
734
|
+
block.name, doc_name, text),
|
735
|
+
tag.position)
|
736
|
+
|
737
|
+
def _apply_annotations_callable(self, node, chain, block):
|
738
|
+
self._apply_annotations_annotated(node, block)
|
739
|
+
self._apply_annotations_params(node, node.parameters, block)
|
740
|
+
self._apply_annotations_return(node, node.retval, block)
|
741
|
+
|
742
|
+
def _check_arg_annotations(self, parent, params, block):
|
743
|
+
if block is None:
|
744
|
+
return
|
745
|
+
for tag in block.tags.keys():
|
746
|
+
if tag == TAG_RETURNS:
|
747
|
+
continue
|
748
|
+
for param in params:
|
749
|
+
if param.argname == tag:
|
750
|
+
break
|
751
|
+
else:
|
752
|
+
message.warn(
|
753
|
+
"Annotation for '%s' refers to unknown argument '%s'"
|
754
|
+
% (parent.name, tag))
|
755
|
+
|
756
|
+
def _apply_annotations_field(self, parent, block, field):
|
757
|
+
if not block:
|
758
|
+
return
|
759
|
+
tag = block.get_param(field.name)
|
760
|
+
if not tag:
|
761
|
+
return
|
762
|
+
t = tag.options.get(OPT_TYPE)
|
763
|
+
if t:
|
764
|
+
field.type = self._transformer.create_type_from_user_string(t.one())
|
765
|
+
|
766
|
+
try:
|
767
|
+
self._adjust_container_type(parent, field, tag.options)
|
768
|
+
except AttributeError:
|
769
|
+
pass
|
770
|
+
|
771
|
+
def _apply_annotations_property(self, parent, prop):
|
772
|
+
prefix = self._get_annotation_name(parent)
|
773
|
+
block = self._blocks.get('%s:%s' % (prefix, prop.name))
|
774
|
+
self._apply_annotations_annotated(prop, block)
|
775
|
+
if not block:
|
776
|
+
return
|
777
|
+
transfer_tag = block.get_tag(TAG_TRANSFER)
|
778
|
+
if transfer_tag is not None:
|
779
|
+
transfer = transfer_tag.value
|
780
|
+
if transfer == OPT_TRANSFER_FLOATING:
|
781
|
+
transfer = OPT_TRANSFER_NONE
|
782
|
+
prop.transfer = transfer
|
783
|
+
else:
|
784
|
+
prop.transfer = self._get_transfer_default(parent, prop)
|
785
|
+
type_tag = block.get_tag(TAG_TYPE)
|
786
|
+
if type_tag:
|
787
|
+
prop.type = self._resolve_toplevel(type_tag.value, prop.type, prop, parent)
|
788
|
+
|
789
|
+
def _apply_annotations_signal(self, parent, signal):
|
790
|
+
prefix = self._get_annotation_name(parent)
|
791
|
+
block = self._blocks.get('%s::%s' % (prefix, signal.name))
|
792
|
+
self._apply_annotations_annotated(signal, block)
|
793
|
+
# We're only attempting to name the signal parameters if
|
794
|
+
# the number of parameters (@foo) is the same or greater
|
795
|
+
# than the number of signal parameters
|
796
|
+
if block and len(block.params) > len(signal.parameters):
|
797
|
+
names = block.params.items()
|
798
|
+
# Resolve real parameter names early, so that in later
|
799
|
+
# phase we can refer to them while resolving annotations.
|
800
|
+
for i, param in enumerate(signal.parameters):
|
801
|
+
param.argname, tag = names[i+1]
|
802
|
+
else:
|
803
|
+
names = []
|
804
|
+
for i, param in enumerate(signal.parameters):
|
805
|
+
if names:
|
806
|
+
name, tag = names[i+1]
|
807
|
+
options = getattr(tag, 'options', {})
|
808
|
+
param_type = options.get(OPT_TYPE)
|
809
|
+
if param_type:
|
810
|
+
param.type = self._resolve_toplevel(param_type.one(), param.type,
|
811
|
+
param, parent)
|
812
|
+
else:
|
813
|
+
tag = None
|
814
|
+
self._apply_annotations_param(signal, param, tag)
|
815
|
+
self._apply_annotations_return(signal, signal.retval, block)
|
816
|
+
|
817
|
+
def _apply_annotations_constant(self, node):
|
818
|
+
block = self._get_block(node)
|
819
|
+
if block is None:
|
820
|
+
return
|
821
|
+
|
822
|
+
self._apply_annotations_annotated(node, block)
|
823
|
+
|
824
|
+
tag = block.get_tag(TAG_VALUE)
|
825
|
+
if tag:
|
826
|
+
node.value = tag.value
|
827
|
+
|
828
|
+
def _apply_annotations_enum_members(self, node, block):
|
829
|
+
if block is None:
|
830
|
+
return
|
831
|
+
|
832
|
+
for m in node.members:
|
833
|
+
tag = block.params.get(m.symbol, None)
|
834
|
+
if tag is not None:
|
835
|
+
m.doc = tag.comment
|
836
|
+
|
837
|
+
def _pass_read_annotations2(self, node, chain):
|
838
|
+
if isinstance(node, ast.Function):
|
839
|
+
self._apply_annotations2_function(node, chain)
|
840
|
+
return True
|
841
|
+
|
842
|
+
def _apply_annotations2_function(self, node, chain):
|
843
|
+
block = self._blocks.get(node.symbol)
|
844
|
+
|
845
|
+
self._apply_annotation_rename_to(node, chain, block)
|
846
|
+
|
847
|
+
# Handle virtual invokers
|
848
|
+
parent = chain[-1] if chain else None
|
849
|
+
if not (block and parent):
|
850
|
+
return
|
851
|
+
virtual = block.get_tag(TAG_VFUNC)
|
852
|
+
if not virtual:
|
853
|
+
return
|
854
|
+
invoker_name = virtual.value
|
855
|
+
matched = False
|
856
|
+
for vfunc in parent.virtual_methods:
|
857
|
+
if vfunc.name == invoker_name:
|
858
|
+
matched = True
|
859
|
+
vfunc.invoker = node.name
|
860
|
+
# Also merge in annotations
|
861
|
+
self._apply_annotations_callable(vfunc, [parent], block)
|
862
|
+
break
|
863
|
+
if not matched:
|
864
|
+
message.warn_node(node,
|
865
|
+
"Virtual slot %r not found for %r annotation" % (invoker_name, TAG_VFUNC))
|
866
|
+
|
867
|
+
def _resolve_and_filter_type_list(self, typelist):
|
868
|
+
"""Given a list of Type instances, return a new list of types with
|
869
|
+
the ones that failed to resolve removed."""
|
870
|
+
# Create a copy we'll modify
|
871
|
+
new_typelist = list(typelist)
|
872
|
+
for typeval in typelist:
|
873
|
+
resolved = self._transformer.resolve_type(typeval)
|
874
|
+
if not resolved:
|
875
|
+
new_typelist.remove(typeval)
|
876
|
+
return new_typelist
|
877
|
+
|
878
|
+
def _pass_type_resolution(self, node, chain):
|
879
|
+
if isinstance(node, ast.Alias):
|
880
|
+
self._transformer.resolve_type(node.target)
|
881
|
+
if isinstance(node, ast.Callable):
|
882
|
+
for parameter in node.parameters:
|
883
|
+
self._transformer.resolve_type(parameter.type)
|
884
|
+
self._transformer.resolve_type(node.retval.type)
|
885
|
+
if isinstance(node, ast.Constant):
|
886
|
+
self._transformer.resolve_type(node.value_type)
|
887
|
+
if isinstance(node, (ast.Class, ast.Interface, ast.Record, ast.Union)):
|
888
|
+
for field in node.fields:
|
889
|
+
if field.anonymous_node:
|
890
|
+
pass
|
891
|
+
else:
|
892
|
+
self._transformer.resolve_type(field.type)
|
893
|
+
if isinstance(node, (ast.Class, ast.Interface)):
|
894
|
+
for parent in node.parent_chain:
|
895
|
+
try:
|
896
|
+
self._transformer.resolve_type(parent)
|
897
|
+
except ValueError:
|
898
|
+
continue
|
899
|
+
target = self._transformer.lookup_typenode(parent)
|
900
|
+
if target:
|
901
|
+
node.parent_type = parent
|
902
|
+
break
|
903
|
+
else:
|
904
|
+
if isinstance(node, ast.Interface):
|
905
|
+
node.parent_type = ast.Type(target_giname='GObject.Object')
|
906
|
+
for prop in node.properties:
|
907
|
+
self._transformer.resolve_type(prop.type)
|
908
|
+
for sig in node.signals:
|
909
|
+
for param in sig.parameters:
|
910
|
+
self._transformer.resolve_type(param.type)
|
911
|
+
if isinstance(node, ast.Class):
|
912
|
+
node.interfaces = self._resolve_and_filter_type_list(node.interfaces)
|
913
|
+
if isinstance(node, ast.Interface):
|
914
|
+
node.prerequisites = self._resolve_and_filter_type_list(node.prerequisites)
|
915
|
+
return True
|
916
|
+
|
917
|
+
def _pair_quarks_with_enums(self):
|
918
|
+
# self._uscore_type_names is an authoritative mapping of types
|
919
|
+
# to underscored versions, since it is based on get_type() methods;
|
920
|
+
# but only covers enums that are registered as GObject enums.
|
921
|
+
# Create a fallback mapping based on all known enums in this module.
|
922
|
+
uscore_enums = {}
|
923
|
+
for enum in self._namespace.itervalues():
|
924
|
+
if not isinstance(enum, ast.Enum):
|
925
|
+
continue
|
926
|
+
uscored = to_underscores_noprefix(enum.name).lower()
|
927
|
+
uscore_enums[uscored] = enum
|
928
|
+
uscore_enums[enum.name] = enum
|
929
|
+
|
930
|
+
for node in self._namespace.itervalues():
|
931
|
+
if not isinstance(node, ast.ErrorQuarkFunction):
|
932
|
+
continue
|
933
|
+
full = node.symbol[:-len('_quark')]
|
934
|
+
ns, short = self._transformer.split_csymbol(node.symbol)
|
935
|
+
short = short[:-len('_quark')]
|
936
|
+
if full == "g_io_error":
|
937
|
+
# Special case; GIOError was already taken forcing GIOErrorEnum
|
938
|
+
assert self._namespace.name == 'Gio'
|
939
|
+
enum = self._namespace.get('IOErrorEnum')
|
940
|
+
else:
|
941
|
+
enum = self._uscore_type_names.get(short)
|
942
|
+
if enum is None:
|
943
|
+
enum = uscore_enums.get(short)
|
944
|
+
if enum is not None:
|
945
|
+
enum.error_domain = node.error_domain
|
946
|
+
else:
|
947
|
+
message.warn_node(node,
|
948
|
+
"""%s: Couldn't find corresponding enumeration""" % (node.symbol, ))
|
949
|
+
|
950
|
+
def _split_uscored_by_type(self, uscored):
|
951
|
+
"""'uscored' should be an un-prefixed uscore string. This
|
952
|
+
function searches through the namespace for the longest type which
|
953
|
+
prefixes uscored, and returns (type, suffix). Example, assuming
|
954
|
+
namespace Gtk, type is TextBuffer:
|
955
|
+
|
956
|
+
_split_uscored_by_type(text_buffer_try_new) -> (ast.Class(TextBuffer), 'try_new')"""
|
957
|
+
node = None
|
958
|
+
count = 0
|
959
|
+
prev_split_count = -1
|
960
|
+
while True:
|
961
|
+
components = uscored.rsplit('_', count)
|
962
|
+
if len(components) == prev_split_count:
|
963
|
+
return None
|
964
|
+
prev_split_count = len(components)
|
965
|
+
type_string = components[0]
|
966
|
+
node = self._uscore_type_names.get(type_string)
|
967
|
+
if node:
|
968
|
+
return (node, '_'.join(components[1:]))
|
969
|
+
count += 1
|
970
|
+
|
971
|
+
def _pair_function(self, func):
|
972
|
+
"""Check to see whether a toplevel function should be a
|
973
|
+
method or constructor of some type."""
|
974
|
+
|
975
|
+
# Ignore internal symbols and type metadata functions
|
976
|
+
if func.symbol.startswith('_') or func.is_type_meta_function():
|
977
|
+
return
|
978
|
+
|
979
|
+
(ns, subsymbol) = self._transformer.split_csymbol(func.symbol)
|
980
|
+
assert ns == self._namespace
|
981
|
+
if self._is_constructor(func, subsymbol):
|
982
|
+
self._set_up_constructor(func, subsymbol)
|
983
|
+
return
|
984
|
+
elif self._is_method(func, subsymbol):
|
985
|
+
self._setup_method(func, subsymbol)
|
986
|
+
return
|
987
|
+
elif self._pair_static_method(func, subsymbol):
|
988
|
+
return
|
989
|
+
|
990
|
+
def _uscored_identifier_for_type(self, typeval):
|
991
|
+
"""Given a Type(target_giname='Foo.BarBaz'), return 'bar_baz'."""
|
992
|
+
name = typeval.get_giname()
|
993
|
+
return to_underscores_noprefix(name).lower()
|
994
|
+
|
995
|
+
def _is_method(self, func, subsymbol):
|
996
|
+
if not func.parameters:
|
997
|
+
if func.is_method:
|
998
|
+
message.warn_node(func,
|
999
|
+
'%s: Methods must have parameters' % (func.symbol, ))
|
1000
|
+
return False
|
1001
|
+
first = func.parameters[0]
|
1002
|
+
target = self._transformer.lookup_typenode(first.type)
|
1003
|
+
if not isinstance(target, (ast.Class, ast.Interface,
|
1004
|
+
ast.Record, ast.Union,
|
1005
|
+
ast.Boxed)):
|
1006
|
+
if func.is_method:
|
1007
|
+
message.warn_node(func,
|
1008
|
+
'%s: Methods must have a pointer as their first '
|
1009
|
+
'parameter' % (func.symbol, ))
|
1010
|
+
return False
|
1011
|
+
if target.namespace != self._namespace:
|
1012
|
+
if func.is_method:
|
1013
|
+
message.warn_node(func,
|
1014
|
+
'%s: Methods must belong to the same namespace as the '
|
1015
|
+
'class they belong to' % (func.symbol, ))
|
1016
|
+
return False
|
1017
|
+
if first.direction == ast.PARAM_DIRECTION_OUT:
|
1018
|
+
if func.is_method:
|
1019
|
+
message.warn_node(func,
|
1020
|
+
'%s: The first argument of methods cannot be an '
|
1021
|
+
'out-argument' % (func.symbol, ))
|
1022
|
+
return False
|
1023
|
+
|
1024
|
+
# A quick hack here...in the future we should catch C signature/GI signature
|
1025
|
+
# mismatches in a general way in finaltransformer
|
1026
|
+
if first.type.ctype is not None and first.type.ctype.count('*') > 1:
|
1027
|
+
return False
|
1028
|
+
|
1029
|
+
if not func.is_method:
|
1030
|
+
uscored_prefix = self._get_uscored_prefix(func, subsymbol)
|
1031
|
+
if not subsymbol.startswith(uscored_prefix):
|
1032
|
+
return False
|
1033
|
+
|
1034
|
+
return True
|
1035
|
+
|
1036
|
+
def _setup_method(self, func, subsymbol):
|
1037
|
+
uscored_prefix = self._get_uscored_prefix(func, subsymbol)
|
1038
|
+
target = self._transformer.lookup_typenode(func.parameters[0].type)
|
1039
|
+
|
1040
|
+
func.instance_parameter = func.parameters.pop(0)
|
1041
|
+
self._namespace.float(func)
|
1042
|
+
|
1043
|
+
if not func.is_method:
|
1044
|
+
subsym_idx = func.symbol.find(subsymbol)
|
1045
|
+
func.name = func.symbol[(subsym_idx + len(uscored_prefix) + 1):]
|
1046
|
+
func.is_method = True
|
1047
|
+
|
1048
|
+
target.methods.append(func)
|
1049
|
+
|
1050
|
+
def _get_uscored_prefix(self, func, subsymbol):
|
1051
|
+
# Here we check both the c_symbol_prefix and (if that fails),
|
1052
|
+
# attempt to do a default uscoring of the type. The reason we
|
1053
|
+
# look at a default underscore transformation is for
|
1054
|
+
# gdk_window_object_get_type(), which says to us that the
|
1055
|
+
# prefix is "gdk_window_object", when really it's just
|
1056
|
+
# "gdk_window". Possibly need an annotation to override this.
|
1057
|
+
prefix_matches = False
|
1058
|
+
uscored_prefix = None
|
1059
|
+
first_arg = func.parameters[0]
|
1060
|
+
target = self._transformer.lookup_typenode(first_arg.type)
|
1061
|
+
if hasattr(target, 'c_symbol_prefix') and target.c_symbol_prefix is not None:
|
1062
|
+
prefix_matches = subsymbol.startswith(target.c_symbol_prefix)
|
1063
|
+
if prefix_matches:
|
1064
|
+
uscored_prefix = target.c_symbol_prefix
|
1065
|
+
if not prefix_matches:
|
1066
|
+
uscored_prefix = self._uscored_identifier_for_type(first_arg.type)
|
1067
|
+
|
1068
|
+
return uscored_prefix
|
1069
|
+
|
1070
|
+
def _pair_static_method(self, func, subsymbol):
|
1071
|
+
split = self._split_uscored_by_type(subsymbol)
|
1072
|
+
if split is None:
|
1073
|
+
return False
|
1074
|
+
(node, funcname) = split
|
1075
|
+
if funcname == '':
|
1076
|
+
return False
|
1077
|
+
|
1078
|
+
if isinstance(node, ast.Class):
|
1079
|
+
self._namespace.float(func)
|
1080
|
+
func.name = funcname
|
1081
|
+
node.static_methods.append(func)
|
1082
|
+
return True
|
1083
|
+
elif isinstance(node, (ast.Interface, ast.Record, ast.Union,
|
1084
|
+
ast.Boxed, ast.Enum, ast.Bitfield)):
|
1085
|
+
# prior to the introduction of this part of the code, only
|
1086
|
+
# ast.Class could have static methods. so for backwards
|
1087
|
+
# compatibility, instead of removing the func from the namespace,
|
1088
|
+
# leave it there and get a copy instead. modify the copy and push
|
1089
|
+
# it onto static_methods. we need to copy the parameters list
|
1090
|
+
# separately, because in the third pass functions are flagged as
|
1091
|
+
# 'throws' depending on the presence of a GError parameter which is
|
1092
|
+
# then removed from the parameters list. without the explicit
|
1093
|
+
# copy, only one of the two functions would thus get flagged as
|
1094
|
+
# 'throws'. clone() does this for us.
|
1095
|
+
new_func = func.clone()
|
1096
|
+
new_func.name = funcname
|
1097
|
+
node.static_methods.append(new_func)
|
1098
|
+
# flag the func as a backwards-comptability kludge (thus it will
|
1099
|
+
# get pruned in the introspectable pass if introspectable=0).
|
1100
|
+
func.moved_to = node.name + '.' + new_func.name
|
1101
|
+
return True
|
1102
|
+
|
1103
|
+
return False
|
1104
|
+
|
1105
|
+
def _set_up_constructor(self, func, subsymbol):
|
1106
|
+
self._namespace.float(func)
|
1107
|
+
|
1108
|
+
func.name = self._get_constructor_name(func, subsymbol)
|
1109
|
+
|
1110
|
+
origin_node = self._get_constructor_class(func, subsymbol)
|
1111
|
+
origin_node.constructors.append(func)
|
1112
|
+
|
1113
|
+
func.is_constructor = True
|
1114
|
+
|
1115
|
+
# Constructors have default return semantics
|
1116
|
+
if not func.retval.transfer:
|
1117
|
+
func.retval.transfer = self._get_transfer_default_return(func,
|
1118
|
+
func.retval)
|
1119
|
+
|
1120
|
+
def _get_constructor_class(self, func, subsymbol):
|
1121
|
+
origin_node = None
|
1122
|
+
split = self._split_uscored_by_type(subsymbol)
|
1123
|
+
if split is None:
|
1124
|
+
if func.is_constructor:
|
1125
|
+
origin_node = self._transformer.lookup_typenode(func.retval.type)
|
1126
|
+
else:
|
1127
|
+
origin_node, _ = split
|
1128
|
+
|
1129
|
+
return origin_node
|
1130
|
+
|
1131
|
+
def _get_constructor_name(self, func, subsymbol):
|
1132
|
+
name = None
|
1133
|
+
split = self._split_uscored_by_type(subsymbol)
|
1134
|
+
if split is None:
|
1135
|
+
if func.is_constructor:
|
1136
|
+
name = func.name
|
1137
|
+
else:
|
1138
|
+
_, name = split
|
1139
|
+
|
1140
|
+
return name
|
1141
|
+
|
1142
|
+
def _guess_constructor_by_name(self, symbol):
|
1143
|
+
# Normal constructors, gtk_button_new etc
|
1144
|
+
if symbol.endswith('_new'):
|
1145
|
+
return True
|
1146
|
+
# Alternative constructor, gtk_button_new_with_label
|
1147
|
+
if '_new_' in symbol:
|
1148
|
+
return True
|
1149
|
+
# gtk_list_store_newv,gtk_tree_store_newv etc
|
1150
|
+
if symbol.endswith('_newv'):
|
1151
|
+
return True
|
1152
|
+
return False
|
1153
|
+
|
1154
|
+
def _is_constructor(self, func, subsymbol):
|
1155
|
+
# func.is_constructor will be True if we have a (constructor) annotation
|
1156
|
+
if not func.is_constructor:
|
1157
|
+
if not self._guess_constructor_by_name(func.symbol):
|
1158
|
+
return False
|
1159
|
+
target = self._transformer.lookup_typenode(func.retval.type)
|
1160
|
+
if not (isinstance(target, ast.Class)
|
1161
|
+
or (isinstance(target, (ast.Record, ast.Union, ast.Boxed))
|
1162
|
+
and (target.get_type is not None or target.foreign))):
|
1163
|
+
if func.is_constructor:
|
1164
|
+
message.warn_node(func,
|
1165
|
+
'%s: Constructors must return an instance of their class'
|
1166
|
+
% (func.symbol, ))
|
1167
|
+
return False
|
1168
|
+
|
1169
|
+
origin_node = self._get_constructor_class(func, subsymbol)
|
1170
|
+
if origin_node is None:
|
1171
|
+
if func.is_constructor:
|
1172
|
+
message.warn_node(func,
|
1173
|
+
"Can't find matching type for constructor; symbol=%r" \
|
1174
|
+
% (func.symbol, ))
|
1175
|
+
return False
|
1176
|
+
|
1177
|
+
# Some sanity checks; only objects and boxeds can have ctors
|
1178
|
+
if not (isinstance(origin_node, ast.Class)
|
1179
|
+
or (isinstance(origin_node, (ast.Record, ast.Union, ast.Boxed))
|
1180
|
+
and (origin_node.get_type is not None or origin_node.foreign))):
|
1181
|
+
return False
|
1182
|
+
# Verify the namespace - don't want to append to foreign namespaces!
|
1183
|
+
if origin_node.namespace != self._namespace:
|
1184
|
+
if func.is_constructor:
|
1185
|
+
message.warn_node(func,
|
1186
|
+
'%s: Constructors must belong to the same namespace as the '
|
1187
|
+
'class they belong to' % (func.symbol, ))
|
1188
|
+
return False
|
1189
|
+
# If it takes the object as a first arg, guess it's not a constructor
|
1190
|
+
if not func.is_constructor and len(func.parameters) > 0:
|
1191
|
+
first_arg = self._transformer.lookup_typenode(func.parameters[0].type)
|
1192
|
+
if (first_arg is not None) and first_arg.gi_name == origin_node.gi_name:
|
1193
|
+
return False
|
1194
|
+
|
1195
|
+
if isinstance(target, ast.Class):
|
1196
|
+
parent = origin_node
|
1197
|
+
while parent and (not parent.gi_name == 'GObject.Object'):
|
1198
|
+
if parent == target:
|
1199
|
+
break
|
1200
|
+
if parent.parent_type:
|
1201
|
+
parent = self._transformer.lookup_typenode(parent.parent_type)
|
1202
|
+
else:
|
1203
|
+
parent = None
|
1204
|
+
if parent is None:
|
1205
|
+
message.warn_node(func,
|
1206
|
+
"Return value is not superclass for constructor; "
|
1207
|
+
"symbol=%r constructed=%r return=%r" % (
|
1208
|
+
func.symbol,
|
1209
|
+
str(origin_node.create_type()),
|
1210
|
+
str(func.retval.type)))
|
1211
|
+
return False
|
1212
|
+
else:
|
1213
|
+
if origin_node != target:
|
1214
|
+
message.warn_node(func,
|
1215
|
+
"Constructor return type mismatch symbol=%r "
|
1216
|
+
"constructed=%r return=%r" % (
|
1217
|
+
func.symbol,
|
1218
|
+
str(origin_node.create_type()),
|
1219
|
+
str(func.retval.type)))
|
1220
|
+
return False
|
1221
|
+
|
1222
|
+
return True
|
1223
|
+
|
1224
|
+
def _pair_class_virtuals(self, node):
|
1225
|
+
"""Look for virtual methods from the class structure."""
|
1226
|
+
if not node.glib_type_struct:
|
1227
|
+
# https://bugzilla.gnome.org/show_bug.cgi?id=629080
|
1228
|
+
#message.warn_node(node,
|
1229
|
+
# "Failed to find class structure for %r" % (node.name, ))
|
1230
|
+
return
|
1231
|
+
|
1232
|
+
node_type = node.create_type()
|
1233
|
+
class_struct = self._transformer.lookup_typenode(node.glib_type_struct)
|
1234
|
+
|
1235
|
+
# Object class fields are assumed to be read-only
|
1236
|
+
# (see also _introspect_object and transformer.py)
|
1237
|
+
for field in class_struct.fields:
|
1238
|
+
if isinstance(field, ast.Field):
|
1239
|
+
field.writable = False
|
1240
|
+
|
1241
|
+
for field in class_struct.fields:
|
1242
|
+
if not isinstance(field.anonymous_node, ast.Callback):
|
1243
|
+
continue
|
1244
|
+
callback = field.anonymous_node
|
1245
|
+
# Check the first parameter is the object
|
1246
|
+
if len(callback.parameters) == 0:
|
1247
|
+
continue
|
1248
|
+
firstparam_type = callback.parameters[0].type
|
1249
|
+
if firstparam_type != node_type:
|
1250
|
+
continue
|
1251
|
+
vfunc = ast.VFunction.from_callback(callback)
|
1252
|
+
vfunc.instance_parameter = callback.parameters[0]
|
1253
|
+
vfunc.inherit_file_positions(callback)
|
1254
|
+
|
1255
|
+
prefix = self._get_annotation_name(class_struct)
|
1256
|
+
block = self._blocks.get('%s::%s' % (prefix, vfunc.name))
|
1257
|
+
self._apply_annotations_callable(vfunc, [node], block)
|
1258
|
+
node.virtual_methods.append(vfunc)
|
1259
|
+
|
1260
|
+
# Take the set of virtual methods we found, and try
|
1261
|
+
# to pair up with any matching methods using the
|
1262
|
+
# name+signature.
|
1263
|
+
for vfunc in node.virtual_methods:
|
1264
|
+
for method in node.methods:
|
1265
|
+
if method.name != vfunc.name:
|
1266
|
+
continue
|
1267
|
+
if method.retval.type != vfunc.retval.type:
|
1268
|
+
continue
|
1269
|
+
if len(method.parameters) != len(vfunc.parameters):
|
1270
|
+
continue
|
1271
|
+
for i in xrange(len(method.parameters)):
|
1272
|
+
m_type = method.parameters[i].type
|
1273
|
+
v_type = vfunc.parameters[i].type
|
1274
|
+
if m_type != v_type:
|
1275
|
+
continue
|
1276
|
+
vfunc.invoker = method.name
|
1277
|
+
# Apply any annotations we have from the invoker to
|
1278
|
+
# the vfunc
|
1279
|
+
block = self._blocks.get(method.symbol)
|
1280
|
+
self._apply_annotations_callable(vfunc, [], block)
|
1281
|
+
break
|
1282
|
+
|
1283
|
+
def _pass3(self, node, chain):
|
1284
|
+
"""Pass 3 is after we've loaded GType data and performed type
|
1285
|
+
closure."""
|
1286
|
+
if isinstance(node, ast.Callable):
|
1287
|
+
self._pass3_callable_callbacks(node)
|
1288
|
+
self._pass3_callable_throws(node)
|
1289
|
+
return True
|
1290
|
+
|
1291
|
+
def _pass3_callable_callbacks(self, node):
|
1292
|
+
"""Check to see if we have anything that looks like a
|
1293
|
+
callback+user_data+GDestroyNotify set."""
|
1294
|
+
|
1295
|
+
params = node.parameters
|
1296
|
+
|
1297
|
+
# First, do defaults for well-known callback types
|
1298
|
+
for param in params:
|
1299
|
+
argnode = self._transformer.lookup_typenode(param.type)
|
1300
|
+
if isinstance(argnode, ast.Callback):
|
1301
|
+
if param.type.target_giname in ('Gio.AsyncReadyCallback',
|
1302
|
+
'GLib.DestroyNotify'):
|
1303
|
+
param.scope = ast.PARAM_SCOPE_ASYNC
|
1304
|
+
param.transfer = ast.PARAM_TRANSFER_NONE
|
1305
|
+
|
1306
|
+
callback_param = None
|
1307
|
+
for param in params:
|
1308
|
+
argnode = self._transformer.lookup_typenode(param.type)
|
1309
|
+
is_destroynotify = False
|
1310
|
+
if isinstance(argnode, ast.Callback):
|
1311
|
+
if param.type.target_giname == 'GLib.DestroyNotify':
|
1312
|
+
is_destroynotify = True
|
1313
|
+
else:
|
1314
|
+
callback_param = param
|
1315
|
+
continue
|
1316
|
+
if callback_param is None:
|
1317
|
+
continue
|
1318
|
+
if is_destroynotify:
|
1319
|
+
callback_param.destroy_name = param.argname
|
1320
|
+
callback_param.scope = ast.PARAM_SCOPE_NOTIFIED
|
1321
|
+
callback_param.transfer = ast.PARAM_TRANSFER_NONE
|
1322
|
+
elif (param.type.is_equiv(ast.TYPE_ANY) and
|
1323
|
+
param.argname is not None and
|
1324
|
+
param.argname.endswith('data')):
|
1325
|
+
callback_param.closure_name = param.argname
|
1326
|
+
|
1327
|
+
def _pass3_callable_throws(self, node):
|
1328
|
+
"""Check to see if we have anything that looks like a
|
1329
|
+
callback+user_data+GDestroyNotify set."""
|
1330
|
+
if not node.parameters:
|
1331
|
+
return
|
1332
|
+
last_param = node.parameters[-1]
|
1333
|
+
# Checking type.name=='GLib.Error' generates false positives
|
1334
|
+
# on methods that take a 'GError *'
|
1335
|
+
if last_param.type.ctype == 'GError**':
|
1336
|
+
node.parameters.pop()
|
1337
|
+
node.throws = True
|