Permalink
Browse files

Fix constructor return value and enumerations.

Define return values of constructors as owned by the caller.
Fix enumerations parsing by getting values from the GIR data.
  • Loading branch information...
respawner committed Aug 17, 2013
1 parent 40991c2 commit 85417fce11c1a5ab0686199497bdeb5d94bcef9b
@@ -1,7 +1,7 @@
/*
* java-gnome, a UI library for writing GTK and GNOME programs from Java!
*
* Copyright © 2007-2010 Operational Dynamics Consulting, Pty Ltd
* Copyright © 2007-2013 Operational Dynamics Consulting, Pty Ltd and Others
* Copyright © 2007 Vreixo Formoso
*
* The code in this file, and the program it is a part of, is made available
@@ -31,10 +31,11 @@
*
* @author Andrew Cowie
* @author Vreixo Formoso
* @author Guillaume Mazoyer
*/
public class EnumGenerator extends TypeGenerator
{
private String[] values;
private String[][] values;
/**
*
@@ -48,7 +49,7 @@
public EnumGenerator(DefsFile data, String[][] values) {
super(data);
this.values = new String[values.length];
this.values = new String[values.length][2];
for (int i = 0; i < values.length; ++i) {
String value = values[i][0];
@@ -57,7 +58,13 @@ public EnumGenerator(DefsFile data, String[][] values) {
* We need to convert values in the form: create-folder to
* CREATE_FOLDER, etc.
*/
this.values[i] = toAllCaps(value);
this.values[i][0] = toAllCaps(value);
/*
* If a specified value for the enumeration field is given use it,
* if not use default numbers starting from 0.
*/
this.values[i][1] = (values[i].length == 3) ? values[i][2] : Integer.toString(i);
}
}
@@ -69,13 +76,12 @@ public void writeTranslationCode(final PrintWriter out) {
// This is overridden by FlagsGenerator...
protected void writeTranslationValues(final PrintWriter out) {
for (int i = 0; i < values.length; ++i) {
out.print("\n");
out.print(" ");
out.print("static final int ");
out.print(values[i]);
out.print(values[i][0]);
out.print(" = ");
out.print(i);
out.print(values[i][1]);
out.print(";\n");
}
}
@@ -406,10 +406,13 @@ private static final boolean hasVarArgs(Element function) {
final Element parameter;
Element type;
String name, typeString;
boolean fromName;
boolean allowNone, fromName;
parameter = list.get(parameterIndex);
name = parameter.getAttributeValue("name");
allowNone = (parameter.getAttributeValue("allow-none") != null)
|| ((parameter.getAttribute("direction") != null) && parameter.getAttributeValue(
"direction").equals("out"));
fromName = false;
if (name != null) {
@@ -479,7 +482,7 @@ private static final boolean hasVarArgs(Element function) {
parameters.add(new String[] {
typeString,
name,
(parameter.getAttributeValue("allow-none") != null) ? "yes" : "no"
allowNone ? "yes" : "no"
});
}
}
@@ -504,7 +507,6 @@ private static final FunctionBlock parseConstructor(Element object, Element cons
String namespace) throws IgnoreIntrospectionException {
final String isConstructorOf, cName;
final List<String[]> constructorCharacteristics;
final String[] callerOwnsReturn;
final List<String[]> parameters;
final boolean throwsGError;
@@ -535,15 +537,18 @@ private static final FunctionBlock parseConstructor(Element object, Element cons
});
/*
* Handle return value and its owner.
* FIXME: should we let constructor always own the return value?
*/
constructorCharacteristics.add(new String[] {
"caller-owns-return",
"#t"
});
constructorCharacteristics.add(getReturnType(constructor, namespace));
callerOwnsReturn = getCallerOwnsReturn(constructor);
/*
* Handle return value.
*/
if (callerOwnsReturn != null) {
constructorCharacteristics.add(callerOwnsReturn);
}
constructorCharacteristics.add(getReturnType(constructor, namespace));
if (hasVarArgs(constructor)) {
constructorCharacteristics.add(new String[] {
@@ -1337,11 +1342,12 @@ private static final VirtualBlock parseSignal(Element object, Element signal, St
for (int valueIndex = 0; valueIndex < valuesList.size(); valueIndex++) {
final Element value;
String nick, identifier;
String nick, identifier, real;
value = valuesList.get(valueIndex);
nick = value.getAttributeValue("nick", GLIB_NAMESPACE);
identifier = value.getAttributeValue("identifier", C_NAMESPACE);
real = value.getAttributeValue("value");
if (nick == null) {
nick = value.getAttributeValue("name");
@@ -1357,7 +1363,8 @@ private static final VirtualBlock parseSignal(Element object, Element signal, St
values.add(new String[] {
nick,
identifier
identifier,
real
});
}

0 comments on commit 85417fc

Please sign in to comment.