/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
public class WrapperGenerator {
/* XLibParser converts Xlib.h to a Java Object that encapsulates the
* X11 API and data structures */
// Charset and decoder for ISO-8859-15
boolean generateLog = true;
boolean wide;
static {
/*
knownSizes64.put("", Integer.valueOf());
knownSizes32.put("", Integer.valueOf());
*/
// knownSizes32.put("XIMStringConversionCallbackStruct", Integer.valueOf(16));
}
private static abstract class BaseType {
return name;
}
return real_type;
}
return name;
}
}
private boolean alias;
int type=-1;
type = TYPE_ARRAY;
type = TYPE_ULONG;
return type;
}
if (referencedType != null) {
if (referencedType instanceof AtomicType) {
} else {
return referencedType.getName();
}
} else {
return getJavaTypeForType(type);
}
}
switch (type) {
case TYPE_INT:
return "int";
case TYPE_CHAR:
return "char";
case TYPE_BYTE:
return "byte";
case TYPE_LONG:
case TYPE_LONG_LONG:
case TYPE_PTR:
case TYPE_ULONG:
return "long";
case TYPE_DOUBLE:
return "double";
case TYPE_FLOAT:
return "float";
case TYPE_SHORT:
return "short";
case TYPE_BOOL:
return "boolean";
case TYPE_ATOM:
return "long";
default:
}
}
if (referencedType != null) {
if (referencedType instanceof StructType) {
} else {
}
} else {
} else {
}
}
}
switch (type) {
case TYPE_STRUCT:
break;
case TYPE_PTR:
} else if (referencedType instanceof AtomicType) {
}
break;
case TYPE_ARRAY:
if (referencedType instanceof StructType) {
} else if (referencedType instanceof AtomicType) {
offset});
}
break;
default:
}
}
if (referencedType != null) {
if (referencedType instanceof StructType) {
return MessageFormat.format("({2} != 0)?(new {0}({1})):(null)", new Object[] {referencedType.getName(),value, base});
} else {
}
} else {
return value;
}
} else {
}
}
return value;
}
return getNativeAccessForType(type);
}
}
switch (type) {
case TYPE_INT:
return "Int";
case TYPE_CHAR:
return "Char";
case TYPE_BYTE:
return "Byte";
case TYPE_LONG:
case TYPE_PTR:
case TYPE_ARRAY:
case TYPE_STRUCT:
case TYPE_ATOM:
case TYPE_LONG_LONG:
return "Long";
case TYPE_ULONG:
case TYPE_DOUBLE:
return "Double";
case TYPE_FLOAT:
return "Float";
case TYPE_SHORT:
return "Short";
case TYPE_BOOL:
return "Int";
default:
}
}
switch (type) {
case TYPE_INT:
return "Int";
case TYPE_CHAR:
return "Char";
case TYPE_BYTE:
return "Byte";
case TYPE_LONG:
case TYPE_PTR:
case TYPE_ARRAY:
case TYPE_STRUCT:
return "Long";
case TYPE_LONG_LONG:
return "Long";
case TYPE_ULONG:
return "ULong";
case TYPE_DOUBLE:
return "Double";
case TYPE_FLOAT:
return "Float";
case TYPE_SHORT:
return "Short";
case TYPE_BOOL:
return "Bool";
case TYPE_ATOM:
return "Long";
default:
}
}
}
if (referencedType != null) {
if (referencedType instanceof StructType) {
} else {
if (type == TYPE_ARRAY) {
} else { // TYPE_PTR
}
}
} else {
}
}
return MessageFormat.format("Native.put{0}({2}, {1})", new Object[] {getNativeAccessForType(type), value, offset});
}
int type;
int offset;
int direction;
boolean autoFree = false;
{
}
{
}
}
public boolean isIn() {
return direction == 0;
}
public boolean isOut() {
return direction == 1;
}
public boolean isInOut() {
return direction == 2;
}
public boolean isAutoFree() {
return autoFree;
}
direction = 0;
direction = 1;
autoFree = true;
}
direction = 2;
alias = true;
if (referencedType == null) {
}
try {
} catch (Exception e) {
}
}
}
}
return referencedType;
}
public int getArrayLength() {
return arrayLength;
}
public void setOffset(int o)
{
offset = o;
}
public int getType() {
return type;
}
switch (type) {
case TYPE_INT:
return "Int";
case TYPE_CHAR:
return "Char";
case TYPE_BYTE:
return "Byte";
case TYPE_LONG:
case TYPE_LONG_LONG:
case TYPE_PTR:
return "Long";
case TYPE_DOUBLE:
return "Double";
case TYPE_FLOAT:
return "Float";
case TYPE_SHORT:
return "Short";
case TYPE_BOOL:
return "Int";
case TYPE_ATOM:
return "Long";
case TYPE_ULONG:
return "ULong";
default: throw new IllegalArgumentException("Uknown type");
}
}
public int getOffset()
{
return offset;
}
public boolean isAlias() {
return alias;
}
return aliasName;
}
}
boolean packed;
int size;
boolean isInterface;
/**
* Construct new structured type.
* Description is used for name and type definition and has the following format:
* structName [ '[' base classe ']' ] [ '{' interfaces '}' ] [ '|' javaClassName ]
*/
{
}
public int getNumFields()
{
}
{
}
public void setSize(int i)
{
size = i;
}
{
return description;
}
{
}
{
}
return baseClass;
}
return interfaces;
}
public boolean getIsInterface() {
return isInterface;
}
return javaClassName;
}
}
}
isInterface = true;
}
}
if (javaClassName == null) {
}
description = _desc;
// System.out.println("Struct " + name + " extends " + baseClass + " implements " + interfaces);
}
/**
* Returns String containing Java code calculating size of the structure depending on the data model
*/
}
return s32;
} else {
return MessageFormat.format("((XlibWrapper.dataModel == 32)?({0}):({1}))", new Object[] {s32, s64});
}
}
}
return s32;
} else {
}
}
}
boolean packed;
int alignment;
{
description = _desc;
}
boolean isVoid() {
return (returnType == null);
}
if (returnType == null) {
return "void";
} else {
return returnType;
}
}
public int getNumArgs()
{
}
{
}
}
}
{
return description;
}
{
return args;
}
{
}
}
{
while (st.hasMoreTokens())
{
}
return ret;
}
switch(size) {
case 1: return "byte";
case 2: return "short";
case 4: return "int";
case 8: return "long";
}
}
{
}
{
return wide == true ? (String) sizeTable64bit.get(stp.getName()) : (String) sizeTable32bit.get(stp.getName());
}
{
return Integer.parseInt(wide == true ? (String)sizeTable64bit.get("long") : (String)sizeTable32bit.get("long"));
}
{
return Integer.parseInt(wide == true ? (String)sizeTable64bit.get("ptr") : (String)sizeTable32bit.get("ptr"));
}
}
return Integer.parseInt(wide == true ? (String)sizeTable64bit.get(ordinal) : (String)sizeTable32bit.get(ordinal));
}
int type;
pw.println("\n\n\tString getFieldsAsString() {\n\t\tStringBuilder ret = new StringBuilder(" + stp.getNumFields() * 40 + ");\n");
{
pw.println("\t\tret.append(\"" + name + " = \" ).append( XAtom.get(get_" + name + "()) ).append(\", \");");
pw.println("\t\tret.append(\"type = \").append( XlibWrapper.eventToString[get_type()] ).append(\", \");");
}
} else {
}
}
}
}
int type;
if (!stp.getIsInterface()) {
prefix = "\t\tabstract ";
} else {
prefix = "\t";
}
{
// Returns pointer to the start of the array
} else {
if (type != AtomicType.TYPE_STRUCT) pw.println(prefix + "void set_" +name +"(" + tp.getJavaType() + " v);");
}
}
}
}
// Make size dividable by bytesPerWord
}
int type;
int i=0;
int acc_size_32 = 0;
int acc_size_64 = 0;
{
new Object[] {
s_log}));
}
// Returns pointer to the start of the array
new Object[] {
}));
pw.println(pref + "long get_" +name+ "() { "+s_log+"return Native.getLong(pData+"+stp.getOffset(tp)+"); }");
} else {
}
}
i++;
}
}
}
}
pw.println("class " + stp.getJavaClassName() + "AccessorImpl" + " extends " + stp.getJavaClassName() + "Accessor {");
pw.println("/*\nThis class serves as a Wrapper for the following X Struct \nsThe offsets here are calculated based on actual compiler.\n\n" +stp.getDescription() + "\n\n */");
}
{
try {
pw.println("// This file is an automatically generated file, please do not edit this file, modify the WrapperGenerator.java file instead !\n" );
}
if (stp.getIsInterface()) {
} else {
}
}
if (!stp.getIsInterface()) {
if (generateLog) {
}
if (generateLog) {
}
if (generateLog) {
}
if (generateLog) {
}
} else {
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
try {
{
{
if (wide) {
} else {
}
}
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
try {
pw.println("// This file is an automatically generated file, please do not edit this file, modify the WrapperGenerator.java file instead !\n" );
} else {
pw.println("\tlong " + at.getName() + "_ptr = unsafe.allocateMemory(Native.get" + at.getTypeUpperCase() + "Size());");
}
}
boolean first = true;
if (!first) {
}
first = false;
}
}
}
}
} else {
}
}
}
}
first = true;
if (!first) {
}
first = false;
} else {
}
}
}
if (at.isAutoFree()) {
}
}
}
} else {
}
} else {
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
// (new File(outputDir, package_path)).mkdirs();
try {
if (tp instanceof StructType) {
} else if (tp instanceof FunctionType) {
}
}
}
catch (Exception e) {
e.printStackTrace();
}
}
{
int type;
int i=0;
int j=0;
try {
pw.println("/* This file is an automatically generated file, please do not edit this file, modify the XlibParser.java file instead !*/\n" );
pw.println("#include <X11/Xlib.h>\n#include <X11/Xutil.h>\n#include <X11/Xos.h>\n#include <X11/Xatom.h>\n#include <stdio.h>\n");
j=0;
if (tp instanceof StructType)
{
if (!stp.getIsInterface()) {
j++;
}
}
}
j=0;
if (tp instanceof StructType)
{
if (stp.getIsInterface()) {
continue;
}
i++;
}
j++;
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
private void initTypes() {
}
initTypes();
try {
{
if (commentStart >= 0) {
// remove comment
}
// skip empty line
continue;
}
{
}
if (bt instanceof StructType) {
} else if (bt instanceof FunctionType) {
}
}
}
}
} else {
}
}
}
}
}
catch (Exception e) {
e.printStackTrace();
}
}
if (wide) {
sizerFileName = "sizer.64.c";
} else {
sizerFileName = "sizer.32.c";
}
}
try {
boolean res = true;
if (f.exists()) {
fis = new FileInputStream(f);
}
if (f.exists()) {
fis = new FileInputStream(f);
}
return res;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
if (readSizeInfo(sizeInfo))
{
}
else {
}
}
System.out.println("Usage:\nWrapperGenerator <output_dir> <xlibtypes.txt> <action> [<platform> | <sizes info file>]");
}
}
}
}