[pkg-java] r6270 - in trunk/java-gnome: . debian src src/generator src/generator/com src/generator/com/operationaldynamics src/generator/com/operationaldynamics/codegen src/generator/com/operationaldynamics/defsparser
zuch-guest at alioth.debian.org
zuch-guest at alioth.debian.org
Sat Apr 26 10:21:33 UTC 2008
Author: zuch-guest
Date: 2008-04-26 10:21:32 +0000 (Sat, 26 Apr 2008)
New Revision: 6270
Added:
trunk/java-gnome/Makefile
trunk/java-gnome/debian/
trunk/java-gnome/debian/changelog
trunk/java-gnome/debian/compat
trunk/java-gnome/debian/control
trunk/java-gnome/debian/copyright
trunk/java-gnome/debian/dirs
trunk/java-gnome/debian/docs
trunk/java-gnome/debian/rules
trunk/java-gnome/src/
trunk/java-gnome/src/generator/
trunk/java-gnome/src/generator/com/
trunk/java-gnome/src/generator/com/operationaldynamics/
trunk/java-gnome/src/generator/com/operationaldynamics/codegen/
trunk/java-gnome/src/generator/com/operationaldynamics/codegen/FunctionGenerator.java
trunk/java-gnome/src/generator/com/operationaldynamics/defsparser/
trunk/java-gnome/src/generator/com/operationaldynamics/defsparser/FunctionBlock.java
Log:
[svn-inject] Applying Debian modifications to trunk
Added: trunk/java-gnome/Makefile
===================================================================
--- trunk/java-gnome/Makefile (rev 0)
+++ trunk/java-gnome/Makefile 2008-04-26 10:21:32 UTC (rev 6270)
@@ -0,0 +1,169 @@
+#
+# Makefile, part of Equivalence
+#
+# Copyright (c) 2006-2007 Operational Dynamics Consulting Pty Ltd
+#
+# The code in this file, and the library it is a part of, are made available
+# to you by the authors under the terms of the "GNU General Public Licence,
+# version 2". See the LICENCE file for the terms governing usage and
+# redistribution.
+#
+
+ifdef V
+else
+MAKEFLAGS=-s
+REDIRECT=>/dev/null
+endif
+
+-include .config
+
+ifdef GCJ
+all: build-java build-native
+else
+all: build-java
+endif
+
+.PHONY: test demo doc clean distlcean install
+
+
+# --------------------------------------------------------------------
+# Source compilation
+# --------------------------------------------------------------------
+
+build-java:
+ build/faster
+
+build-native: .config tmp/gtk-$(APIVERSION).jar
+ make -f build/gcj.make
+
+# --------------------------------------------------------------------
+# Install (run as root, or specify DESTDIR on Make command line)
+# --------------------------------------------------------------------
+
+ifdef GCJ
+install: build-java build-native install-dirs install-java install-native
+else
+install: build-java install-dirs install-java
+endif
+ rm $(DESTDIR)$(PREFIX)/.java-gnome-install-dirs
+
+install-dirs: $(DESTDIR)$(PREFIX)/.java-gnome-install-dirs
+$(DESTDIR)$(PREFIX)/.java-gnome-install-dirs:
+ @test -d $(DESTDIR)$(PREFIX)/share/java || echo -e "MKDIR\tinstallation directories"
+ -mkdir -p $(DESTDIR)$(PREFIX)
+ -touch $@ 2>/dev/null
+ test -w $@ || ( echo -e "\nYou don't seem to have write permissions to $(DESDIR)$(PREFIX)\nPerhaps you need to be root?\n" && exit 7 )
+ mkdir -p $(DESTDIR)$(PREFIX)/share/java
+ mkdir -p $(DESTDIR)$(PREFIX)/lib/jni
+
+install-java: build-java \
+ $(DESTDIR)$(PREFIX)/share/java/gtk-$(APIVERSION).jar \
+ $(DESTDIR)$(PREFIX)/lib/jni/libgtkjni-$(APIVERSION).so
+
+install-native: build-native install-java \
+ $(DESTDIR)$(PREFIX)/lib/libgtkjava-$(APIVERSION).so
+
+$(DESTDIR)$(PREFIX)/share/java/gtk-$(APIVERSION).jar: tmp/gtk-$(APIVERSION).jar
+ @echo -e "INSTALL\t$@"
+ cp -f $< $@
+ @echo -e "SYMLINK\t$(@D)/gtk.jar -> gtk-$(APIVERSION).jar"
+ cd $(@D) && rm -f gtk.jar && ln -s gtk-$(APIVERSION).jar gtk.jar
+
+$(DESTDIR)$(PREFIX)/lib/jni/libgtkjni-$(APIVERSION).so: tmp/libgtkjni-$(APIVERSION).so
+ @echo -e "INSTALL\t$@"
+ cp -f $< $@
+
+$(DESTDIR)$(PREFIX)/lib/libgtkjava-$(APIVERSION).so: tmp/libgtkjava-$(APIVERSION).so
+ @echo -e "INSTALL\t$@"
+ cp -f $< $@
+
+
+# --------------------------------------------------------------------
+# Tests
+# --------------------------------------------------------------------
+
+test:
+ build/faster test
+
+demo:
+ build/faster demo
+
+# --------------------------------------------------------------------
+# Documentation generation
+# --------------------------------------------------------------------
+
+ifdef V
+else
+JAVADOC:=$(JAVADOC) -quiet
+endif
+
+doc:
+ @echo "$(JAVADOC_CMD) doc/api/*.html"
+ $(JAVADOC) \
+ -d doc/api \
+ -classpath tmp/bindings \
+ -public \
+ -nodeprecated \
+ -source 1.4 \
+ -notree \
+ -noindex \
+ -nohelp \
+ -version \
+ -author \
+ -windowtitle "java-gnome $(APIVERSION) API Documentation" \
+ -doctitle "<h1>java-gnome $(APIVERSION) API Documentation</h1>" \
+ -header "java-gnome version $(VERSION)" \
+ -footer "<img src=\"/images/java-gnome_JavaDocLogo.png\" style=\"padding-right:25px;\"><br> <span style=\"font-family: Arial; font-style: normal; font-size: large;\">java-gnome</span>" \
+ -breakiterator \
+ -stylesheetfile src/bindings/stylesheet.css \
+ -overview src/bindings/overview.html \
+ -sourcepath src/bindings \
+ -subpackages org \
+ -exclude "org.freedesktop.bindings" \
+ $(REDIRECT)
+
+
+#
+# Remember that if you bump the version number you need to commit the change
+# and re-./configure before being able to run this! On the other hand, we
+# don't have to distclean before calling this.
+#
+dist: all
+ @echo -e "CHECK\tfully committed state"
+ bzr diff > /dev/null || ( echo -e "\nYou need to commit all changes before running make dist\n" ; exit 4 )
+ @echo -e "EXPORT\ttmp/java-gnome-$(VERSION)"
+ -rm -rf tmp/java-gnome-$(VERSION)
+ bzr export --format=dir tmp/java-gnome-$(VERSION)
+ @echo -e "RM\tnon essential files"
+ rm -r tmp/java-gnome-$(VERSION)/web
+ rm tmp/java-gnome-$(VERSION)/.aspell.en.pws
+ @echo -e "TAR\tjava-gnome-$(VERSION).tar.bz2"
+ tar cjf java-gnome-$(VERSION).tar.bz2 -C tmp java-gnome-$(VERSION)
+ rm -r tmp/java-gnome-$(VERSION)
+
+clean:
+ @echo -e "RM\tgenerated code"
+ rm -rf generated/bindings/*
+ @echo -e "RM\tcompiled output"
+ rm -rf tmp/generator/* tmp/bindings/* tmp/tests/*
+ rm -rf tmp/include/* tmp/native/* tmp/objects/*
+ @echo -e "RM\ttemporary files"
+ rm -rf tmp/stamp/*
+ rm -f hs_err_*
+ @echo -e "RM\tbuilt .jar and .so"
+ rm -f tmp/gtk-*.jar \
+ tmp/libgtkjni-*.so \
+ tmp/libgtkjava-*.so
+
+distclean: clean
+ @echo -e "RM\tbuild configuration information"
+ -rm -f .config .config.tmp
+ @echo -e "RM\tgenerated documentation"
+ -rm -rf doc/api/*
+ -rm -f java-gnome-*.tar.bz2
+ @echo -e "RM\ttemporary directories"
+ -rm -rf tmp generated
+ @echo -e "RM\tglade cruft"
+ find . -name '*.glade.bak' -o -name '*.gladep*' -type f | xargs rm -f
+
+# vim: set filetype=make textwidth=78 nowrap:
Property changes on: trunk/java-gnome/debian
___________________________________________________________________
Name: mergeWithUpstream
+ 1
Added: trunk/java-gnome/debian/changelog
===================================================================
--- trunk/java-gnome/debian/changelog (rev 0)
+++ trunk/java-gnome/debian/changelog 2008-04-26 10:21:32 UTC (rev 6270)
@@ -0,0 +1,11 @@
+java-gnome (4.0.6-1) unstable; urgency=low
+
+ [ Manu Mahajan ]
+ * Initial release, Closes: Bug#467442
+ * Changed location of libgtkjni from usr/lib to usr/lib/jni
+ * Tweaked the MakeFile to build with java-gcj-compat-dev
+
+ [ Thomas Girard ]
+ * Backport changeset 449: "Remove 15 warnings related to sentinels"
+
+ -- Manu Mahajan <manu at codepencil.com> Mon, 24 Mar 2008 01:01:11 +0530
Added: trunk/java-gnome/debian/compat
===================================================================
--- trunk/java-gnome/debian/compat (rev 0)
+++ trunk/java-gnome/debian/compat 2008-04-26 10:21:32 UTC (rev 6270)
@@ -0,0 +1 @@
+5
Added: trunk/java-gnome/debian/control
===================================================================
--- trunk/java-gnome/debian/control (rev 0)
+++ trunk/java-gnome/debian/control 2008-04-26 10:21:32 UTC (rev 6270)
@@ -0,0 +1,22 @@
+Source: java-gnome
+Priority: optional
+Maintainer: Debian Java maintainers <pkg-java-maintainers at lists.alioth.debian.org>
+Uploaders: Manu Mahajan <manu at codepencil.com>, Thomas Girard <thomas.g.girard at free.fr>
+Build-Depends: debhelper (>= 5), libgtk2.0-dev, junit, libglade2-dev, libgnome2-0, java-gcj-compat-dev
+Standards-Version: 3.7.3
+Section: libs
+
+Package: libjava-gnome-java
+Section: libs
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}
+Description: The java-gnome language bindings project
+ These are the Java bindings for GTK+ and GNOME! Featuring a robust
+ engineering design, completely generated internals, a lovingly crafted
+ layer presenting the public API, and steadily increasing coverage of
+ the underlying libraries.
+ .
+ You can use java-gnome to develop sophisticated user interfaces for
+ Linux applications so that they richly integrate with the GNOME Desktop
+ while leveraging the power of the Java language and your expertise with
+ it.
Added: trunk/java-gnome/debian/copyright
===================================================================
--- trunk/java-gnome/debian/copyright (rev 0)
+++ trunk/java-gnome/debian/copyright 2008-04-26 10:21:32 UTC (rev 6270)
@@ -0,0 +1,99 @@
+This package was debianized by Manu Mahajan <manu at codepencil.com> on
+Mon, 25 Feb 2008 00:43:11 +0530.
+
+It was downloaded from http://ftp.gnome.org/pub/gnome/sources/java-gnome/4.0/
+
+Upstream Authors:
+ Andrew Cowie <andrew at operationaldynamics.com>
+ Srichand Pendyala <srichand.pendyala at gmail.com>
+ Vreixo Formoso Lopes <metalpain2002 at yahoo.es>
+ Sebastian Mancke <s.mancke at tarent.de>
+
+Copyright Holders:
+ Copyright (c) 2006-2008 Operational Dynamics Consulting Pty Ltd, and
+ Others.
+ Copyright (c) 2004-2008 Operational Dynamics Consulting Pty Ltd
+ Copyright (c) 1997-1998 Andrew Cowie
+ Copyright (c) 1998-2005 The java-gnome Team
+ Copyright (c) 2007 Vreixo Formoso Lopes
+ Copyright (C) 2006 Emmanuele Bassi
+ Copyright (C) 2001-2006 Jonathan Blandford
+ Copyright (c) 1998-2006 James Henstridge, John Finlay, and Others
+
+License:
+ java-gnome is Logiciel Libre and is Open Source; you can
+ redistribute it and/or modify it under the terms of the GNU General
+ Public License, version 2("GPL").
+
+ Linking this library statically or dynamically with other modules is
+ making a combined work based on this library. Thus, the terms and
+ conditions of the GPL cover the whole combination.
+
+ As a special exception, the copyright holders of this library give
+ you permission to link this library with independent modules to
+ produce an executable, regardless of the license terms of these
+ independent modules, and to copy and distribute the resulting
+ executable under terms of your choice, provided that you also meet,
+ for each linked independent module, the terms and conditions of the
+ license of that module. An independent module is a module which is
+ not derived from or based on this library. If you modify this
+ library, you may extend this exception to your version of the
+ library, but you are not obligated to do so. If you do not wish to
+ do so, delete this exceptionstatement from your version.
+
+ java-gnome 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 GPL for
+ more details. In particular, note that if you use this and lose your
+ data, you're on your own.
+
+ You should have received a copy of the GNU General Public License
+ with the Debian GNU/Linux distribution in file
+ /usr/share/common-licenses/GPL. If not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301,
+ USA.
+
+On Debian systems, the complete text of the GNU General Public
+License, version 2, can be found in /usr/share/common-licenses/GPL-2.
+
+
+java-gnome sources include markdown (in lib/utilities/markdown):
+Authors:
+ John Gruber <http://daringfireball.net>
+ Michel Fortin <http://www.michelf.com/>
+
+Copyright Holders:
+ Copyright (c) 2003-2006 John Gruber
+ Copyright (c) 2004-2006 Michel Fortin
+
+License:
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ * Neither the name "Markdown" nor the names of its contributors may
+ be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ This software is provided by the copyright holders and contributors "as
+ is" and any express or implied warranties, including, but not limited
+ to, the implied warranties of merchantability and fitness for a
+ particular purpose are disclaimed. In no event shall the copyright owner
+ or contributors be liable for any direct, indirect, incidental, special,
+ exemplary, or consequential damages (including, but not limited to,
+ procurement of substitute goods or services; loss of use, data, or
+ profits; or business interruption) however caused and on any theory of
+ liability, whether in contract, strict liability, or tort (including
+ negligence or otherwise) arising in any way out of the use of this
+ software, even if advised of the possibility of such damage.
+
+
+The Debian packaging is (C) 2008, Manu Mahajan <manu at codepencil.com>
+and is licensed under the GPL, see above.
Added: trunk/java-gnome/debian/dirs
===================================================================
--- trunk/java-gnome/debian/dirs (rev 0)
+++ trunk/java-gnome/debian/dirs 2008-04-26 10:21:32 UTC (rev 6270)
@@ -0,0 +1,2 @@
+usr/lib/jni
+usr/share/java
Added: trunk/java-gnome/debian/docs
===================================================================
--- trunk/java-gnome/debian/docs (rev 0)
+++ trunk/java-gnome/debian/docs 2008-04-26 10:21:32 UTC (rev 6270)
@@ -0,0 +1,2 @@
+NEWS
+README
Added: trunk/java-gnome/debian/rules
===================================================================
--- trunk/java-gnome/debian/rules (rev 0)
+++ trunk/java-gnome/debian/rules 2008-04-26 10:21:32 UTC (rev 6270)
@@ -0,0 +1,70 @@
+#!/usr/bin/make -f
+# -*- makefile -*-
+# Sample debian/rules that uses debhelper.
+# This file was originally written by Joey Hess and Craig Small.
+# As a special exception, when this file is copied by dh-make into a
+# dh-make output file, you may use that output file without restriction.
+# This special exception was added by Craig Small in version 0.37 of dh-make.
+
+
+#configure
+.config:
+ dh_testdir
+ # Add here commands to configure the package.
+ ./configure --prefix=/usr jdk=/usr/lib/jvm/java-gcj compiler=ecj
+
+
+build: build-stamp
+build-stamp: .config
+ dh_testdir
+
+ # Add here commands to compile the package.
+ $(MAKE)
+
+ touch $@
+
+clean:
+ dh_testdir
+ dh_testroot
+ rm -f build-stamp
+
+ # Add here commands to clean up after the build process.
+ $(MAKE) distclean
+
+ dh_clean
+
+install: build
+ dh_testdir
+ dh_testroot
+ dh_clean -k
+ dh_installdirs
+
+ # Add here commands to install the package into debian/tmp
+ $(MAKE) DESTDIR=debian/libjava-gnome-java install
+ # We don't install this one
+ -rm -f debian/libjava-gnome-java/usr/lib/libgtkjava-4.0.so
+
+
+# Build architecture-independent files here.
+binary-indep: build install
+# We have nothing to do by default.
+
+# Build architecture-dependent files here.
+binary-arch: build install
+ dh_testdir
+ dh_testroot
+ dh_installchangelogs
+ dh_installdocs
+ dh_install
+ dh_strip
+ dh_compress
+ dh_fixperms
+ dh_makeshlibs
+ dh_installdeb
+ dh_shlibdeps
+ dh_gencontrol
+ dh_md5sums
+ dh_builddeb
+
+binary: binary-indep binary-arch
+.PHONY: build clean binary-indep binary-arch binary install
Property changes on: trunk/java-gnome/debian/rules
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/java-gnome/src/generator/com/operationaldynamics/codegen/FunctionGenerator.java
===================================================================
--- trunk/java-gnome/src/generator/com/operationaldynamics/codegen/FunctionGenerator.java (rev 0)
+++ trunk/java-gnome/src/generator/com/operationaldynamics/codegen/FunctionGenerator.java 2008-04-26 10:21:32 UTC (rev 6270)
@@ -0,0 +1,649 @@
+/*
+ * FunctionGenerator.java
+ *
+ * Copyright (c) 2007-2008 Operational Dynamics Consulting Pty Ltd
+ * Copyright (c) 2007 Vreixo Formoso
+ *
+ * The code in this file, and the library it is a part of, are made available
+ * to you by the authors under the terms of the "GNU General Public Licence,
+ * version 2" See the LICENCE file for the terms governing usage and
+ * redistribution.
+ */
+package com.operationaldynamics.codegen;
+
+import java.io.PrintWriter;
+
+import com.operationaldynamics.driver.DefsFile;
+
+/**
+ * Generate Java and C code for constructors, methods and other kind of
+ * functions.
+ * <p>
+ * Subclasses can override the individual steps of the generation sequence if
+ * they wish, however adjusting input passing up to this classes's constructor
+ * has been thus far been enough for constructors blocks and methods blocks.
+ *
+ * @author Andrew Cowie
+ * @author Vreixo Formoso
+ */
+public class FunctionGenerator extends Generator
+{
+ /**
+ * The Thing describing the object we are generating code relative to.
+ */
+ protected final ProxiedThing proxyType;
+
+ /**
+ * The name of the method that is exposed package visible to bindings
+ * hackers. Expected to be overridden by subclasses such as
+ * ConstuctorGenerator.
+ */
+ protected String translationMethodName;
+
+ /**
+ * Not final so that we can play with the return type variable in the JNI
+ * conversion code section.
+ */
+ protected Thing returnType;
+
+ protected final String nativeMethodName;
+
+ /**
+ * These are ordered collections so that sublcasses like MethodGenerator
+ * can insert the reference-to-self as a first argument.
+ */
+ protected final Thing[] parameterTypes;
+
+ protected final String[] parameterNames;
+
+ /**
+ * This is filled with true if the parameter can be null (indicated with a
+ * null-ok in .defs).
+ */
+ protected final boolean[] parameterNullOk;
+
+ /**
+ * If a blacklistedType type is detected in this block, set it here.
+ */
+ private Thing blacklistedType;
+
+ private final boolean addSentinal;
+
+ /**
+ * @param data
+ * the information about the class to which the block we are
+ * generating code for pertains.
+ * @param blockName
+ * however the .defs data named this block. Usually it's a
+ * "short" name such as "set_label". Will be transformed into
+ * the translation method name.
+ * @param gReturnType
+ * the return type, as specified in the .defs data
+ * @param cFunctionName
+ * the C function name, as specified in the .defs data. This
+ * will be used to name the native method.
+ * @param gParameters
+ * an array of String[2] arrays, listing the type and name of
+ * each parameter.
+ */
+ public FunctionGenerator(final DefsFile data, final String blockName, final String gReturnType,
+ final String cFunctionName, final String[][] gParameters) {
+ super(data);
+ final int len;
+
+ this.proxyType = (ProxiedThing) data.getType();
+
+ this.translationMethodName = toCamel(blockName);
+
+ this.returnType = Thing.lookup(gReturnType);
+
+ this.nativeMethodName = cFunctionName;
+
+ /*
+ * If ... is passed through as the last parameter, it means that we
+ * have a varargs and will need to a) add a NULL sentinel to the arg
+ * list, and b) chop this pseudo-parameter off the end of the array.
+ * This is a bit ugly, but the alternative was adding a boolean to
+ * *every* Generator constructor. This is better: varargs *is* a
+ * parameter type, and one we may someday choose to deal with.
+ */
+
+ if ((gParameters.length > 0) && ("...".equals(gParameters[gParameters.length - 1][0]))) {
+ this.addSentinal = true;
+ len = gParameters.length - 1;
+ } else {
+ this.addSentinal = false;
+ len = gParameters.length;
+ }
+
+ parameterTypes = new Thing[len];
+ parameterNames = new String[len];
+ parameterNullOk = new boolean[len];
+
+ for (int i = 0; i < len; i++) {
+ parameterTypes[i] = Thing.lookup(gParameters[i][0]);
+ parameterNames[i] = toCamel(gParameters[i][1]);
+ parameterNullOk[i] = "yes".equals(gParameters[i][2]);
+ }
+
+ blacklistedType = null;
+ }
+
+ protected void translationMethodDeclaration(PrintWriter out) {
+ boolean hasGError = false;
+
+ out.print("\n");
+ out.print(" ");
+ out.print("static final ");
+ out.print(returnType.javaTypeInContext(data));
+ out.print(" ");
+ out.print(translationMethodName);
+
+ out.print("(");
+
+ for (int i = 0; i < parameterTypes.length; i++) {
+ if (parameterTypes[i] instanceof GErrorThing) {
+ hasGError = true;
+ continue;
+ }
+
+ if (i > 0) {
+ out.print(", ");
+ }
+
+ out.print(parameterTypes[i].javaTypeInContext(data));
+ out.print(" ");
+ out.print(parameterNames[i]);
+ }
+
+ out.print(")");
+
+ if (hasGError && !blockContainsBlacklistedThings()) {
+ out.print(" throws GlibException");
+ }
+
+ }
+
+ protected void translationMethodThrowBlacklisted(PrintWriter out) {
+ out.print(" throws BlacklistedMethodError {\n");
+
+ out.print(" ");
+ out.print("throw new BlacklistedMethodError(\"");
+ out.print(blacklistedType.gType);
+ out.print("\");\n");
+
+ out.print(" ");
+ out.print("}\n");
+ }
+
+ protected void translationMethodConversionCode(PrintWriter out) {
+ int declarations = 0;
+
+ out.print(" {\n");
+
+ /*
+ * Declare translation variables as necessary
+ */
+
+ if (!returnType.javaType.equals("void")) {
+ out.print(" ");
+ out.print(returnType.nativeType);
+ out.print(" result;\n");
+ declarations++;
+ }
+
+ for (int i = 0; i < parameterTypes.length; i++) {
+ if (parameterTypes[i] instanceof GErrorThing) {
+ continue;
+ }
+ if (parameterTypes[i].needExtraTranslation()) {
+ out.print(" ");
+ out.print(parameterTypes[i].nativeType);
+ out.print(" _" + parameterNames[i] + ";\n");
+ declarations++;
+ }
+ }
+
+ if (declarations > 0) {
+ out.print("\n");
+ }
+
+ /*
+ * Guard against null in parameters that can't be null
+ */
+ for (int i = 0; i < parameterTypes.length; i++) {
+ if (parameterTypes[i] instanceof GErrorThing) {
+ continue;
+ }
+ if (!parameterNullOk[i] && !(parameterTypes[i] instanceof FundamentalThing)) {
+ out.print(" if (" + parameterNames[i] + " == null) {\n");
+ out.print(" throw new IllegalArgumentException(\"" + parameterNames[i]
+ + " can't be null\");\n");
+ out.print(" }\n\n");
+ }
+ }
+
+ /*
+ * convert (translate) variables from public Java to JNI boundary
+ * crossing (ie, out-parameters)
+ */
+
+ for (int i = 0; i < parameterTypes.length; i++) {
+ if (parameterTypes[i] instanceof GErrorThing) {
+ continue;
+ }
+ if (parameterTypes[i].needExtraTranslation()) {
+ out.print(" ");
+ out.print("_" + parameterNames[i] + " = ");
+ out.print(parameterTypes[i].extraTranslationToNative(parameterNames[i]));
+ out.print(";\n\n");
+ }
+ }
+
+ /*
+ * And now enter the GDK lock prior to making the native calls. FUTURE
+ * this might have to be conditional if we ever have an environment
+ * where there is strictly zero possibility of a library depending on
+ * GTK. At the moment we're not allowing that as a strict KISS
+ * measure, and besides, most of the GNOME libraries need to be thread
+ * safe via the global GDK lock regardless.
+ */
+
+ out.print(" ");
+ out.print("synchronized (lock) {\n");
+ }
+
+ protected void translationMethodNativeCall(PrintWriter out) {
+ out.print(" ");
+ if (!returnType.javaType.equals("void")) {
+ out.print("result = ");
+ }
+ out.print(nativeMethodName);
+ out.print("(");
+
+ for (int i = 0; i < parameterTypes.length; i++) {
+ if (parameterTypes[i] instanceof GErrorThing) {
+ continue;
+ }
+ if (i > 0) {
+ out.print(", ");
+ }
+
+ out.print(parameterTypes[i].translationToNative(parameterNames[i]));
+ }
+
+ out.print(");\n");
+ }
+
+ protected void translationMethodParamConversion(PrintWriter out) {
+ for (int i = 0; i < parameterTypes.length; i++) {
+ if (parameterTypes[i] instanceof GErrorThing) {
+ continue;
+ }
+ if (parameterTypes[i].needExtraTranslation()) {
+ out.print(" ");
+ out.print(parameterTypes[i].extraTranslationToJava(parameterNames[i], data));
+ out.print(";\n");
+ }
+ }
+ }
+
+ protected void translationMethodReturnCode(PrintWriter out) {
+ if (!returnType.nativeType.equals("void")) {
+ out.print("\n");
+ out.print(" ");
+ out.print("return ");
+ out.print(returnType.translationToJava("result", data));
+ out.print(";\n");
+ }
+ out.print(" }\n");
+ out.print(" }\n");
+ }
+
+ protected void nativeMethodDeclaration(PrintWriter out) {
+ boolean hasGError = false;
+
+ out.print(" ");
+ out.print("private static native final ");
+ out.print(returnType.nativeType);
+ out.print(" ");
+ out.print(nativeMethodName);
+ out.print("(");
+
+ for (int i = 0; i < parameterTypes.length; i++) {
+ if (parameterTypes[i] instanceof GErrorThing) {
+ hasGError = true;
+ continue;
+ }
+ if (i > 0) {
+ out.print(", ");
+ }
+
+ out.print(parameterTypes[i].nativeType);
+ out.print(" ");
+ out.print(parameterNames[i]);
+ }
+
+ if (hasGError) {
+ out.print(") throws GlibException;\n");
+ } else {
+ out.print(");\n");
+ }
+ }
+
+ protected void jniFunctionDeclaration(PrintWriter out) {
+ out.print("\n");
+ out.print("JNIEXPORT ");
+ out.print(returnType.jniType);
+ out.print(" JNICALL\n");
+
+ out.print("Java_");
+ out.print(encodeJavaClassName(proxyType.bindingsPackage, proxyType.bindingsClass));
+ out.print("_");
+ out.print(encodeJavaMethodName(nativeMethodName));
+ out.print("\n(\n");
+ out.print("\tJNIEnv* env,\n");
+ out.print("\tjclass cls");
+
+ for (int i = 0; i < parameterTypes.length; i++) {
+ if (parameterTypes[i] instanceof GErrorThing) {
+ continue;
+ }
+ out.print(",\n\t");
+
+ out.print(parameterTypes[i].jniType);
+ out.print(" _");
+ out.print(parameterNames[i]);
+ }
+
+ out.print("\n)\n{\n");
+ }
+
+ protected void jniFunctionConversionCode(PrintWriter out) {
+ /*
+ * Declare conversion variables as necessary
+ */
+ if (!returnType.javaType.equals("void")) {
+ out.print("\t");
+ out.print(returnType.cType);
+ out.print(" result;\n");
+ }
+
+ for (int i = 0; i < parameterTypes.length; i++) {
+ out.print("\t");
+
+ out.print(parameterTypes[i].cType);
+ out.print(" ");
+ out.print(parameterNames[i]);
+ if (parameterTypes[i] instanceof GErrorThing) {
+ out.print(" = NULL");
+ }
+ out.print(";\n");
+ }
+
+ for (int i = 0; i < parameterTypes.length; i++) {
+ if (parameterTypes[i] instanceof GErrorThing) {
+ continue;
+ }
+ /*
+ * Comment
+ */
+ out.print("\n\t// convert parameter ");
+ out.print(parameterNames[i]);
+ out.print("\n");
+
+ /*
+ * If a parameter can be null, we need an extra if to avoid the
+ * conversion if it is in fact NULL
+ */
+ if (parameterNullOk[i] && !parameterTypes[i].jniConversionHandlesNull()) {
+ out.print("\tif (_" + parameterNames[i] + " == NULL) {\n");
+ out.print("\t\t" + parameterNames[i] + " = NULL;\n");
+ out.print("\t} else {\n");
+ out.print("\t");
+ }
+
+ /*
+ * variable equals
+ */
+ out.print("\t");
+ out.print(parameterNames[i]);
+
+ /*
+ * always a cast
+ */
+ out.print(" = (");
+ out.print(parameterTypes[i].cType);
+ out.print(") ");
+
+ /*
+ * and now a type specific decode. For many types, the cast is
+ * enough, so it's just the plain name.
+ */
+
+ out.print(parameterTypes[i].jniConversionDecode(parameterNames[i]));
+ out.print(";\n");
+ if (parameterTypes[i].jniConversionCanFail()) {
+ jniReturnIfExceptionThrown(out, i);
+ }
+
+ if (parameterNullOk[i] && !parameterTypes[i].jniConversionHandlesNull()) {
+ /* close the "else" */
+ out.print("\t}\n");
+ }
+ }
+ }
+
+ /**
+ * If a JNI access function hits a problem (ie, OutOfMemoryError) it needs
+ * to exit immediately. A Java Exception is already thown, so we just need
+ * to bail. This is tricky, however, since the return statement must
+ * return something of the return type of the function.
+ *
+ * @param i
+ * the index into the parameterNames array (you're calling this
+ * from inside a for loop iterating over the parameters).
+ */
+ private void jniReturnIfExceptionThrown(PrintWriter out, int i) {
+ String extraTab;
+
+ /*
+ * When the parameter can be null, we need an extra tab because of the
+ * if.
+ */
+ extraTab = parameterNullOk[i] && !parameterTypes[i].jniConversionHandlesNull() ? "\t" : "";
+
+ out.print(extraTab + "\tif (");
+ out.print(parameterNames[i]);
+ out.print(" == NULL) {\n");
+ out.print(extraTab + "\t\treturn");
+
+ if (!("void".equals(returnType.jniType))) {
+ out.print(" ");
+ out.print(returnType.jniReturnErrorValue());
+ }
+
+ out.print("; // Java Exception already thrown\n");
+ out.print(extraTab + "\t}\n");
+ }
+
+ protected void jniFunctionLibraryCall(PrintWriter out) {
+ out.print("\n");
+ out.print("\t// call function\n");
+
+ out.print("\t");
+ if (!returnType.jniType.equals("void")) {
+ out.print("result = ");
+ }
+ out.print(nativeMethodName);
+ out.print("(");
+
+ for (int i = 0; i < parameterTypes.length; i++) {
+ if (i > 0) {
+ out.print(", ");
+ }
+
+ if (parameterTypes[i] instanceof GErrorThing) {
+ /*
+ * We pass the GError address
+ */
+ out.print("&" + parameterNames[i]);
+ } else {
+ out.print(parameterNames[i]);
+ }
+
+ }
+
+ if (addSentinal) {
+ out.print(", NULL");
+ }
+
+ out.print(");\n");
+ }
+
+ /**
+ * Cleanup and return the result if not a void function.
+ */
+ protected void jniFunctionReturnCode(PrintWriter out) {
+ String cleanup;
+ String paramGError = null;
+
+ /*
+ * type specific cleanup:
+ */
+
+ for (int i = 0; i < parameterTypes.length; i++) {
+
+ if (parameterTypes[i] instanceof GErrorThing) {
+ paramGError = parameterNames[i];
+ continue;
+ }
+
+ out.print("\n");
+ out.print("\t// cleanup parameter ");
+ out.print(parameterNames[i]);
+ out.print("\n");
+
+ cleanup = parameterTypes[i].jniConversionCleanup(parameterNames[i]);
+
+ if (cleanup == null) {
+ continue;
+ }
+
+ /*
+ * clean-up is not needed when the parameter is null
+ */
+ if (parameterNullOk[i] && !parameterTypes[i].jniConversionHandlesNull()) {
+ out.print("\tif (" + parameterNames[i] + " != NULL) {\n");
+ out.print("\t");
+ }
+ out.print("\t");
+ out.print(cleanup);
+ out.print(";\n");
+ if (parameterNullOk[i] && !parameterTypes[i].jniConversionHandlesNull()) {
+ out.print("\t}\n");
+ }
+ }
+
+ /*
+ * When the function takes a GError** as a parameter, we need to check
+ * if the function has efectivelly thrown an error. After doing the
+ * needed clean-up, we check for that situation and throw an exception
+ * from JNI side.
+ */
+ if (paramGError != null) {
+ out.print("\n");
+ out.print("\t// check for error\n");
+
+ out.print("\tif (" + paramGError + ") {\n");
+
+ out.print("\t\tbindings_java_throw_gerror(env, ");
+ out.print(paramGError);
+ out.print(");\n");
+ out.print("\t\treturn");
+ if (!returnType.jniType.equals("void")) {
+ out.print(" " + returnType.jniReturnErrorValue());
+ }
+ out.print(";\n");
+ out.print("\t}\n");
+ }
+
+ /*
+ * return result if applicable. Specific code for certain types; most
+ * others, just a cast.
+ */
+
+ if (!returnType.jniType.equals("void")) {
+ out.print("\n");
+ out.print("\t// and finally\n");
+
+ out.print("\treturn ");
+
+ out.print("(");
+ out.print(returnType.jniType);
+ out.print(") ");
+ out.print(returnType.jniReturnEncode("result"));
+ out.print(";\n");
+ }
+ out.print("}\n");
+ }
+
+ /**
+ * Quickly scan the type information to see if there is a blacklistedType
+ * type present. If so, we use that to output a throws declaration instead
+ * of a real method block. As this gets called twice, we could cache this,
+ * but whatever.
+ */
+ private boolean blockContainsBlacklistedThings() {
+ if (returnType.blacklisted) {
+ blacklistedType = returnType;
+ return true;
+ }
+ for (int i = 0; i < parameterTypes.length; i++) {
+ if (parameterTypes[i].blacklisted) {
+ blacklistedType = parameterTypes[i];
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * See {@link DefsFile#generatePublicLayer(PrintWriter)} for a discussion
+ * of why this is not to be touched. I'm serious. Don't even think about
+ * it.
+ */
+ public final void writePublicCode(final PrintWriter out) {
+ System.err.println("Not paying attention, are we? Abort.");
+ System.exit(2);
+ }
+
+ public void writeTranslationCode(final PrintWriter out) {
+ translationMethodDeclaration(out);
+
+ if (blockContainsBlacklistedThings()) {
+ translationMethodThrowBlacklisted(out);
+ return;
+ }
+
+ translationMethodConversionCode(out);
+ translationMethodNativeCall(out);
+ translationMethodParamConversion(out);
+ translationMethodReturnCode(out);
+
+ out.print("\n");
+
+ nativeMethodDeclaration(out);
+ }
+
+ public void writeJniCode(final PrintWriter out) {
+ if (blockContainsBlacklistedThings()) {
+ return;
+ }
+
+ jniFunctionDeclaration(out);
+ jniFunctionConversionCode(out);
+ jniFunctionLibraryCall(out);
+ jniFunctionReturnCode(out);
+ }
+}
Added: trunk/java-gnome/src/generator/com/operationaldynamics/defsparser/FunctionBlock.java
===================================================================
--- trunk/java-gnome/src/generator/com/operationaldynamics/defsparser/FunctionBlock.java (rev 0)
+++ trunk/java-gnome/src/generator/com/operationaldynamics/defsparser/FunctionBlock.java 2008-04-26 10:21:32 UTC (rev 6270)
@@ -0,0 +1,191 @@
+/*
+ * FunctionBlock.java
+ *
+ * Copyright (c) 2007-2008 Operational Dynamics Consulting Pty Ltd
+ *
+ * The code in this file, and the library it is a part of, are made available
+ * to you by the authors under the terms of the "GNU General Public Licence,
+ * version 2" See the LICENCE file for the terms governing usage and
+ * redistribution.
+ */
+package com.operationaldynamics.defsparser;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.operationaldynamics.codegen.ConstructorGenerator;
+import com.operationaldynamics.codegen.FunctionGenerator;
+import com.operationaldynamics.codegen.Generator;
+import com.operationaldynamics.codegen.InterfaceThing;
+import com.operationaldynamics.codegen.Thing;
+import com.operationaldynamics.driver.DefsFile;
+
+/**
+ * A .defs (define-function...) block, and the superclass for other entities
+ * that are represented in C with functions. This also includes functions with
+ * the "is-constructor-of" attributes, i.e. constructors.
+ *
+ * @author Andrew Cowie
+ * @author Vreixo Formoso
+ */
+public class FunctionBlock extends Block
+{
+ /**
+ * Strictly speaking, this isn't here, but down in MethodBlock and
+ * VirtualBlock. But it needs to be figured out before FunctionGenerator
+ * can be used in a (define-function ...), and it's present for all the
+ * sub block types.
+ */
+ protected String ofObject;
+
+ protected String returnType;
+
+ protected String cName;
+
+ protected String[][] parameters;
+
+ protected String callerOwnsReturn;
+
+ protected String varargs;
+
+ protected String isConstructorOf;
+
+ FunctionBlock(final String blockName, final List characteristics, final List parameters) {
+ super(blockName, characteristics);
+
+ processParameters(parameters);
+
+ if (varargs != null) {
+ appendVarargsMark();
+ }
+ }
+
+ final void setOfObject(final String ofObject) {
+ this.ofObject = ofObject;
+ }
+
+ private void processParameters(final List parameters) {
+ this.parameters = (String[][]) parameters.toArray(new String[parameters.size()][]);
+ }
+
+ protected final void setCallerOwnsReturn(final String callerOwnsReturn) {
+ this.callerOwnsReturn = callerOwnsReturn;
+ }
+
+ protected final void setIsConstructorOf(final String isConstructorOf) {
+ this.isConstructorOf = isConstructorOf;
+ }
+
+ protected final void setCName(final String name) {
+ this.cName = name;
+ }
+
+ protected final void setReturnType(final String returnType) {
+ this.returnType = returnType;
+ }
+
+ /*
+ * We don't model variable length arguments in java-gnome, but we do need
+ * to pass this along so that we can stick a NULL as a last argument to
+ * avoid "warning: not enough variable arguments to fit a sentinel" from
+ * the C compiler.
+ */
+ protected final void setVarargs(final String value) {
+ this.varargs = value;
+ }
+
+ /**
+ * Only the TypeBlock class hierarchy can create and return Things that
+ * match a given Block.
+ */
+ public Thing createThing() {
+ throw new UnsupportedOperationException();
+ }
+
+ /*
+ * Special cases will probably be needed for at least VirtualBlock, but
+ * this is a good start.
+ */
+ public List usesTypes() {
+ List types;
+ Thing t;
+
+ types = new ArrayList(parameters.length + 1);
+
+ /*
+ * For constructors, our translation layer method will return long and
+ * not the actual type, so we don't need to import it.
+ */
+ if (isConstructorOf == null) {
+ t = Thing.lookup(returnType).getTypeToImport();
+ if (t != null) {
+ types.add(t);
+ }
+ }
+
+ for (int i = 0; i < parameters.length; i++) {
+ t = Thing.lookup(parameters[i][0]);
+ t = t.getTypeToImport();
+ if (t == null) {
+ continue;
+ }
+ types.add(t);
+
+ if (t instanceof InterfaceThing) {
+ types.add(Thing.lookup("GObject*"));
+ }
+ }
+
+ return types;
+ }
+
+ /**
+ * Load the reference-to-self that all "method" functions start with onto
+ * the beginning of the parameters List. Used by MethodBlock and
+ * AccessorBlock, in case you're wondering what this is doing here.
+ */
+ protected void prependReferenceToSelf() {
+ String[][] target;
+
+ target = new String[parameters.length + 1][3];
+ System.arraycopy(parameters, 0, target, 1, parameters.length);
+
+ target[0][0] = addPointerSymbol(ofObject);
+ target[0][1] = "self";
+ target[0][2] = "no"; /* self can't never be null */
+
+ parameters = target;
+ }
+
+ /**
+ * The varrags case is handled, essentially, an artificial last parameter.
+ * This utility method appends a marker to show that the function being
+ * described by this Block was declared as taking variable arguments. We
+ * do not actually present this with any kind of public API (and may never
+ * do so), but we do need to deal with this at the C library call layer
+ * because those functions require a NULL in the argument list to signal
+ * the end of the list.
+ *
+ * The FunctionGenerator constructor will strip it off the end of the
+ * parameters list (thus allowing us to avoid needing a SentinalThing).
+ */
+ protected void appendVarargsMark() {
+ String[][] target;
+
+ target = new String[parameters.length + 1][3];
+ System.arraycopy(parameters, 0, target, 0, parameters.length);
+
+ target[parameters.length][0] = "...";
+
+ parameters = target;
+ }
+
+ public Generator createGenerator(final DefsFile data) {
+ if (isConstructorOf != null) {
+ return new ConstructorGenerator(data, returnType, cName, parameters);
+ } else {
+ return new FunctionGenerator(data, blockName, returnType, cName, parameters);
+ }
+ }
+
+}
More information about the pkg-java-commits
mailing list