make/jdk/src/classes/build/tools/x11wrappergen/WrapperGenerator.java
author ihse
Wed, 28 Feb 2018 20:50:11 +0100
branchihse-cflags-rewrite-branch
changeset 56211 657780f239c4
parent 47216 71c04702a3d5
child 56312 a52bcf4118eb
permissions -rw-r--r--
Fix X11Wrappers.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
56211
657780f239c4 Fix X11Wrappers.
ihse
parents: 47216
diff changeset
     2
 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
22967
bfcfd51c9e5c 8034193: Move X11 wrapper generator files to make/src and make/data
erikj
parents: 17679
diff changeset
    26
package build.tools.x11wrappergen;
bfcfd51c9e5c 8034193: Move X11 wrapper generator files to make/src and make/data
erikj
parents: 17679
diff changeset
    27
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.nio.charset.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.text.MessageFormat;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2473
diff changeset
    32
import java.util.logging.Level;
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2473
diff changeset
    33
import java.util.logging.Logger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
public class WrapperGenerator {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    /* XLibParser converts Xlib.h to a Java Object that encapsulates the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
     * X11 API and data structures */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    // Charset and decoder for ISO-8859-15
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    private final static Logger log = Logger.getLogger("WrapperGenerator");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    boolean generateLog = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    boolean wide;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private static Charset charset = Charset.forName("ISO-8859-15");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    String package_name = "sun.awt.X11";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    String package_path = "sun/awt/X11";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    String sizerFileName = "sizer.c";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    String defaultBaseClass = "XWrapperBase";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    String compile_options = "-lX11";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    static Hashtable symbolTable = new Hashtable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    static Hashtable sizeTable32bit = new Hashtable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    static Hashtable sizeTable64bit = new Hashtable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    static Hashtable knownSizes32 = new Hashtable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    static Hashtable knownSizes64 = new Hashtable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        knownSizes64.put("", Integer.valueOf());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        knownSizes32.put("", Integer.valueOf());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        knownSizes64.put("XComposeStatus", Integer.valueOf(16));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        knownSizes64.put("XTimeCoord", Integer.valueOf(16));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        knownSizes64.put("XExtData", Integer.valueOf(32));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        knownSizes64.put("XWindowChanges", Integer.valueOf(40));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        knownSizes64.put("XOMCharSetList", Integer.valueOf(16));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        knownSizes64.put("XModifierKeymap", Integer.valueOf(16));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        knownSizes32.put("XIMValuesList", Integer.valueOf(8));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        knownSizes32.put("XGCValues", Integer.valueOf(92));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
//          knownSizes32.put("XIMStringConversionCallbackStruct", Integer.valueOf(16));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private static abstract class BaseType {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        String real_type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        public String getRealType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            return real_type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private static class AtomicType extends BaseType {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        private boolean alias;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        private String aliasName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        static final int TYPE_INT=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        static final int TYPE_CHAR=1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        static final int TYPE_LONG=2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        static final int TYPE_LONG_LONG=3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        static final int TYPE_DOUBLE=4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        static final int TYPE_FLOAT=5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        static final int TYPE_PTR=6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        static final int TYPE_SHORT=7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        static final int TYPE_BOOL = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        static final int TYPE_STRUCT = 9;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        static final int TYPE_ARRAY = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        static final int TYPE_BYTE=11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        static final int TYPE_ATOM = 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        static final int TYPE_ULONG = 13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        static int getTypeForString(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            int type=-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            if (str.equals("int"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                type = AtomicType.TYPE_INT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            else if (str.equals("long"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                type = AtomicType.TYPE_LONG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            else if (str.equals("byte"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                type = AtomicType.TYPE_BYTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            else if (str.equals("char"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                type = AtomicType.TYPE_CHAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            else if (str.equals("long long"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                type = AtomicType.TYPE_LONG_LONG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            else if (str.equals("double"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                type = AtomicType.TYPE_DOUBLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            else if (str.equals("float"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                type = AtomicType.TYPE_FLOAT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            else if (str.equals("pointer"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                type = AtomicType.TYPE_PTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            else if (str.equals("short"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                type = AtomicType.TYPE_SHORT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            else if (str.equals("Bool"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                type = AtomicType.TYPE_BOOL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            else if (str.equals("struct"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                type = AtomicType.TYPE_STRUCT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            else if (str.equals("Atom"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                type = AtomicType.TYPE_ATOM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            else if (str.equals("array"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                type = TYPE_ARRAY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            else if (str.equals("ulong"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                type = TYPE_ULONG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            else throw new IllegalArgumentException("Uknown type string: " + str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        String getJavaType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            if (referencedType != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                if (referencedType instanceof AtomicType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                    return ((AtomicType)referencedType).getJavaType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                    return referencedType.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                return getJavaTypeForType(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        static String getJavaTypeForType(int type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            switch (type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
              case TYPE_INT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                  return "int";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
              case TYPE_CHAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                  return "char";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
              case TYPE_BYTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                  return "byte";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
              case TYPE_LONG:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
              case TYPE_LONG_LONG:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
              case TYPE_PTR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
              case TYPE_ULONG:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                  return "long";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
              case TYPE_DOUBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                  return "double";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
              case TYPE_FLOAT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                  return "float";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
              case TYPE_SHORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                  return "short";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
              case TYPE_BOOL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                  return "boolean";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
              case TYPE_ATOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                  return "long";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
              default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                  throw new IllegalArgumentException("Unknown type: " + type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        String getItemSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            if (referencedType != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                  if (referencedType instanceof StructType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                      return ((StructType)referencedType).getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                      return ((AtomicType)referencedType).getItemSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                int i32 = getNativeSizeForAccess(getJavaAccess(false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                int i64 = getNativeSizeForAccess(getJavaAccess(true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                if (i32 != i64) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                    return "Native.get" + getNativeAccess() + "Size()";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                    return Integer.toString(i32);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        String getJavaResult(String offset, String base) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            String res = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            switch (type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
              case TYPE_STRUCT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                  res = "pData + " + offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
              case TYPE_PTR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                  if (referencedType == null || referencedType instanceof StructType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                      res = base + "+" + offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                  } else if (referencedType instanceof AtomicType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                      res = MessageFormat.format("Native.get{0}({1})",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                                                 new Object[] {getNativeAccessForType(((AtomicType)referencedType).type),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                                                               base + "+" + offset});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
              case TYPE_ARRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                  if (referencedType instanceof StructType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                      res = "pData + " + offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                  }  else if (referencedType instanceof AtomicType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                      res = MessageFormat.format("Native.get{0}(pData + {1})",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                                                 new Object[] {getNativeAccessForType(((AtomicType)referencedType).type),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                                                               offset});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
              default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                res = MessageFormat.format("(Native.get{0}(pData+{1}))",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                                           new Object[] {getNativeAccess(), offset});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            return getJavaResultConversion(res, base);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        String getJavaResultConversion(String value, String base) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            if (referencedType != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                if (referencedType instanceof StructType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                    if (type == TYPE_PTR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                        return MessageFormat.format("({2} != 0)?(new {0}({1})):(null)", new Object[] {referencedType.getName(),value, base});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                        return MessageFormat.format("new {0}({1})", new Object[] {referencedType.getName(),value});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                    return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                return getJavaResultConversionForType(type, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        static String getJavaResultConversionForType(int type, String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        String getNativeAccess() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            return getNativeAccessForType(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        String getJavaAccess(boolean wide) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            return getJavaAccessForType(type, wide);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        static String getJavaAccessForType(int type, boolean wide) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            switch (type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
              case TYPE_INT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                  return "Int";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
              case TYPE_CHAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                  return "Char";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
              case TYPE_BYTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                  return "Byte";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
              case TYPE_LONG:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
              case TYPE_PTR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
              case TYPE_ARRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
              case TYPE_STRUCT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
              case TYPE_ATOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                  return (wide?"Long":"Int");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
              case TYPE_LONG_LONG:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                  return "Long";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
              case TYPE_ULONG:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                  return (wide?"ULong":"UInt");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
              case TYPE_DOUBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                  return "Double";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
              case TYPE_FLOAT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                  return "Float";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
              case TYPE_SHORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                  return "Short";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
              case TYPE_BOOL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                  return "Int";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
              default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                  throw new IllegalArgumentException("Unknown type: " + type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        static String getNativeAccessForType(int type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            switch (type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
              case TYPE_INT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                  return "Int";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
              case TYPE_CHAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                  return "Char";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
              case TYPE_BYTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                  return "Byte";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
              case TYPE_LONG:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
              case TYPE_PTR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
              case TYPE_ARRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
              case TYPE_STRUCT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                  return "Long";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
              case TYPE_LONG_LONG:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                  return "Long";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
              case TYPE_ULONG:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                  return "ULong";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
              case TYPE_DOUBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                  return "Double";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
              case TYPE_FLOAT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                  return "Float";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
              case TYPE_SHORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                  return "Short";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
              case TYPE_BOOL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                  return "Bool";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
              case TYPE_ATOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                  return "Long";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
              default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                  throw new IllegalArgumentException("Unknown type: " + type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        static int getNativeSizeForAccess(String access) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            if (access.equals("Int")) return 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            else if (access.equals("Byte")) return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            else if (access.equals("Long")) return 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            else if (access.equals("Double")) return 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            else if (access.equals("Float")) return 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            else if (access.equals("Char")) return 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            else if (access.equals("Short")) return 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            else if (access.equals("ULong")) return 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            else if (access.equals("UInt")) return 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            else throw new IllegalArgumentException("Unknow access type: " + access);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        String getJavaConversion(String offset, String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            if (referencedType != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                if (referencedType instanceof StructType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                    return getJavaConversionForType(TYPE_PTR, offset, value + ".pData");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                    if (type == TYPE_ARRAY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                        return getJavaConversionForType(((AtomicType)referencedType).type, offset, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                    } else { // TYPE_PTR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                        return getJavaConversionForType(TYPE_PTR, offset, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                return getJavaConversionForType(type, offset, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        static String getJavaConversionForType(int type, String offset, String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            return MessageFormat.format("Native.put{0}({2}, {1})", new Object[] {getNativeAccessForType(type), value, offset});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        int type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        int offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        int direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        BaseType referencedType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        int arrayLength = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        boolean autoFree = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        public AtomicType(int _type,String _name, String _real_type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            name = _name.replaceAll("[* \t]","");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            if ((name.indexOf("[") != -1) || (name.indexOf("]") != -1))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                name = name.replaceAll("\\[.*\\]","");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            type = _type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            real_type = _real_type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            if (real_type == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                System.out.println(" real type is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        public boolean isIn() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            return direction == 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        public boolean isOut() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            return direction == 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        public boolean isInOut() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            return direction == 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        public boolean isAutoFree() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            return autoFree;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        public void setAttributes(String[] attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            String mod = attributes[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            if ("in".equals(mod)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                direction = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            } else if ("out".equals(mod)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                direction = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                if (attributes.length > 4 && "free".equals(attributes[4])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                    autoFree = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            } else if ("inout".equals(mod)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                direction = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            } else if ("alias".equals(mod)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                alias = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                aliasName = attributes[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            } else if (type == TYPE_ARRAY || type == TYPE_PTR || type == TYPE_STRUCT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                referencedType = (BaseType)symbolTable.get(mod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                if (referencedType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                    log.warning("Can't find type for name " + mod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                if (attributes.length > 4) { // array length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                        arrayLength = Integer.parseInt(attributes[4]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                    } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        public BaseType getReferencedType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            return referencedType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        public int getArrayLength() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            return arrayLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        public void setOffset(int o)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            offset = o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        public int getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        public String getTypeUpperCase() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            switch (type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
              case TYPE_INT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                  return "Int";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
              case TYPE_CHAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                  return "Char";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
              case TYPE_BYTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                  return "Byte";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
              case TYPE_LONG:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
              case TYPE_LONG_LONG:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
              case TYPE_PTR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                  return "Long";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
              case TYPE_DOUBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                  return "Double";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
              case TYPE_FLOAT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                  return "Float";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
              case TYPE_SHORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                  return "Short";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
              case TYPE_BOOL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                  return "Int";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
              case TYPE_ATOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                  return "Long";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
              case TYPE_ULONG:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                  return "ULong";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
              default: throw new IllegalArgumentException("Uknown type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        public int getOffset()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            return offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        public boolean isAlias() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            return alias;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        public String getAliasName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            return aliasName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    private static class StructType extends BaseType {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        Vector members;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        String description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        boolean packed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        int size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        String baseClass, interfaces;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        boolean isInterface;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        String javaClassName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
         * Construct new structured type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
         * Description is used for name and type definition and has the following format:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
         * structName [ '[' base classe ']' ] [ '{' interfaces '}' ] [ '|' javaClassName ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        public StructType(String _desc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            members = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            parseDescription(_desc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        public int getNumFields()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            return members.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        public void setName(String _name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            _name = _name.replaceAll("[* \t]","");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            parseDescription(_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        public void setSize(int i)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            size = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        public String getDescription()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            return description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        public Enumeration getMembers()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            return members.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        public void addMember(BaseType tp)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            members.add(tp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        public String getBaseClass() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            return baseClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        public String getInterfaces() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            return interfaces;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        public boolean getIsInterface() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            return isInterface;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        public String getJavaClassName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            return javaClassName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        void parseDescription(String _desc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            if (_desc.indexOf('[') != -1) { // Has base class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                baseClass = _desc.substring(_desc.indexOf('[')+1, _desc.indexOf(']'));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                _desc = _desc.substring(0, _desc.indexOf('[')) + _desc.substring(_desc.indexOf(']')+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            if (_desc.indexOf('{') != -1) { // Has base class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                interfaces = _desc.substring(_desc.indexOf('{')+1, _desc.indexOf('}'));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                _desc = _desc.substring(0, _desc.indexOf('{')) + _desc.substring(_desc.indexOf('}')+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            if (_desc.startsWith("-")) { // Interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                isInterface = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                _desc = _desc.substring(1, _desc.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            if (_desc.indexOf("|") != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                javaClassName = _desc.substring(_desc.indexOf('|')+1, _desc.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                _desc = _desc.substring(0, _desc.indexOf('|'));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            name = _desc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            if (javaClassName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                javaClassName = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            description = _desc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
//              System.out.println("Struct " + name + " extends " + baseClass + " implements " + interfaces);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
         * Returns String containing Java code calculating size of the structure depending on the data model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        public String getSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            String s32 = (String) WrapperGenerator.sizeTable32bit.get(getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            String s64 = (String) WrapperGenerator.sizeTable64bit.get(getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            if (s32 == null || s64 == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                return (s32 == null)?(s64):(s32);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            if (s32.equals(s64)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                return s32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                return MessageFormat.format("((XlibWrapper.dataModel == 32)?({0}):({1}))", new Object[] {s32, s64});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        public String getOffset(AtomicType atp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            String key = getName()+"."+(atp.isAlias() ? atp.getAliasName() : atp.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            String s64 = (String) WrapperGenerator.sizeTable64bit.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            String s32 = (String) WrapperGenerator.sizeTable32bit.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            if (s32 == null || s64 == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                return (s32 == null)?(s64):(s32);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            if (s32.equals(s64)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                return s32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                return MessageFormat.format("((XlibWrapper.dataModel == 32)?({0}):({1}))", new Object[]{s32, s64});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    private static class FunctionType extends BaseType {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        Vector args;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        String description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        boolean packed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        String returnType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        int alignment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        public FunctionType(String _desc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            args = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            description = _desc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            setName(_desc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        boolean isVoid() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            return (returnType == null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        String getReturnType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            if (returnType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                return "void";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                return returnType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        public int getNumArgs()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            return args.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        public void setName(String _name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            if (_name.startsWith("!")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                _name = _name.substring(1, _name.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            if (_name.indexOf("|") != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                returnType = _name.substring(_name.indexOf("|")+1, _name.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                _name = _name.substring(0, _name.indexOf("|"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            name = _name.replaceAll("[* \t]","");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        public String getDescription()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            return description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        public Collection getArguments()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            return args;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        public void addArgument(BaseType tp)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            args.add(tp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    public String makeComment(String str)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        StringTokenizer st = new StringTokenizer(str,"\r\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        String ret="";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        while (st.hasMoreTokens())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            ret = ret + "//" + st.nextToken() + "\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    public String getJavaTypeForSize(int size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        switch(size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
          case 1: return "byte";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
          case 2: return "short";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
          case 4: return "int";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
          case 8: return "long";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
          default: throw new RuntimeException("Unsupported size: " + size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    public String getOffsets(StructType stp,AtomicType atp, boolean wide)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        String key = stp.getName()+"."+atp.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        return wide == true ? (String) sizeTable64bit.get(key) : (String) sizeTable32bit.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    public String getStructSize(StructType stp, boolean wide)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        return wide == true ? (String) sizeTable64bit.get(stp.getName()) : (String) sizeTable32bit.get(stp.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    public int getLongSize(boolean wide)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        return Integer.parseInt(wide == true ? (String)sizeTable64bit.get("long") : (String)sizeTable32bit.get("long"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    public int getPtrSize(boolean wide)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        return Integer.parseInt(wide == true ? (String)sizeTable64bit.get("ptr") : (String)sizeTable32bit.get("ptr"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    public int getBoolSize(boolean wide) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        return getOrdinalSize("Bool", wide);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    public int getOrdinalSize(String ordinal, boolean wide) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        return Integer.parseInt(wide == true ? (String)sizeTable64bit.get(ordinal) : (String)sizeTable32bit.get(ordinal));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    public void writeToString(StructType stp, PrintWriter pw) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        int type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        pw.println("\n\n\tString getName() {\n\t\treturn \"" + stp.getName()+ "\"; \n\t}");
10872
4c64f54e8e79 7105529: XAWT: Optimize getFieldsAsString() methods generated by WrapperGenerator
anthony
parents: 5506
diff changeset
   683
        pw.println("\n\n\tString getFieldsAsString() {\n\t\tStringBuilder ret = new StringBuilder(" + stp.getNumFields() * 40 + ");\n");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        for (Enumeration e = stp.getMembers() ; e.hasMoreElements() ;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            AtomicType tp = (AtomicType) e.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            type = tp.getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            String name = tp.getName().replace('.', '_');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            if ((name != null) && (name.length() > 0))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                if (type == AtomicType.TYPE_ATOM) {
10872
4c64f54e8e79 7105529: XAWT: Optimize getFieldsAsString() methods generated by WrapperGenerator
anthony
parents: 5506
diff changeset
   693
                    pw.println("\t\tret.append(\"" + name + " = \" ).append( XAtom.get(get_" + name + "()) ).append(\", \");");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                } else if (name.equals("type")) {
10872
4c64f54e8e79 7105529: XAWT: Optimize getFieldsAsString() methods generated by WrapperGenerator
anthony
parents: 5506
diff changeset
   695
                    pw.println("\t\tret.append(\"type = \").append( XlibWrapper.eventToString[get_type()] ).append(\", \");");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                } else if (name.equals("window")){
10872
4c64f54e8e79 7105529: XAWT: Optimize getFieldsAsString() methods generated by WrapperGenerator
anthony
parents: 5506
diff changeset
   697
                    pw.println("\t\tret.append(\"window = \" ).append( getWindow(get_window()) ).append(\", \");");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                } else if (type == AtomicType.TYPE_ARRAY) {
10872
4c64f54e8e79 7105529: XAWT: Optimize getFieldsAsString() methods generated by WrapperGenerator
anthony
parents: 5506
diff changeset
   699
                    pw.print("\t\tret.append(\"{\")");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                    for (int i = 0; i < tp.getArrayLength(); i++) {
10872
4c64f54e8e79 7105529: XAWT: Optimize getFieldsAsString() methods generated by WrapperGenerator
anthony
parents: 5506
diff changeset
   701
                        pw.print("\n\t\t.append( get_" + name + "(" + i + ") ).append(\" \")");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                    }
10872
4c64f54e8e79 7105529: XAWT: Optimize getFieldsAsString() methods generated by WrapperGenerator
anthony
parents: 5506
diff changeset
   703
                    pw.println(".append( \"}\");");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                } else {
10872
4c64f54e8e79 7105529: XAWT: Optimize getFieldsAsString() methods generated by WrapperGenerator
anthony
parents: 5506
diff changeset
   705
                    pw.println("\t\tret.append(\"" + name +" = \").append( get_"+ name+"() ).append(\", \");");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        }
10872
4c64f54e8e79 7105529: XAWT: Optimize getFieldsAsString() methods generated by WrapperGenerator
anthony
parents: 5506
diff changeset
   710
        pw.println("\t\treturn ret.toString();\n\t}\n\n");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    public void writeStubs(StructType stp, PrintWriter pw) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        int type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        String prefix = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        if (!stp.getIsInterface()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            prefix = "\t\tabstract ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            prefix = "\t";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        for (Enumeration e = stp.getMembers() ; e.hasMoreElements() ;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            AtomicType tp = (AtomicType) e.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            type = tp.getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            String name = tp.getName().replace('.','_');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            if ((name != null) && (name.length() > 0))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                if (type == AtomicType.TYPE_ARRAY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                    // Returns pointer to the start of the array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                    pw.println(prefix + "long get_" +name +"();");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                    pw.println(prefix + tp.getJavaType() + " get_" +name +"(int index);");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                    pw.println(prefix + "void set_" +name +"(int index, " + tp.getJavaType() + " v);");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                    pw.println(prefix + tp.getJavaType() + " get_" +name +"();");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                    if (type != AtomicType.TYPE_STRUCT) pw.println(prefix + "void set_" +name +"(" + tp.getJavaType() + " v);");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    private int padSize(int size, int wordLength) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        int bytesPerWord = wordLength / 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        // Make size dividable by bytesPerWord
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        return (size + bytesPerWord / 2) / bytesPerWord * bytesPerWord;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    public void writeAccessorImpls(StructType stp, PrintWriter pw) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        int type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        int i=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        String s_size_32 = getStructSize(stp, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        String s_size_64 = getStructSize(stp, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        int acc_size_32 = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        int acc_size_64 = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        String s_log = (generateLog?"log.finest(\"\");":"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        for (Enumeration e = stp.getMembers() ; e.hasMoreElements() ;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            AtomicType tp = (AtomicType) e.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            type = tp.getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            String name = tp.getName().replace('.','_');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            String pref = "\tpublic " ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            if ((name != null) && (name.length() > 0))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                String jt = tp.getJavaType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                String ja_32 = tp.getJavaAccess(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                String ja_64 = tp.getJavaAccess(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                String ja = ja_32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                int elemSize_32 = AtomicType.getNativeSizeForAccess(ja_32);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                int elemSize_64 = AtomicType.getNativeSizeForAccess(ja_64);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                String elemSize = tp.getItemSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                if (type == AtomicType.TYPE_ARRAY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                    acc_size_32 += elemSize_32 * tp.getArrayLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                    acc_size_64 += elemSize_64 * tp.getArrayLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                    pw.println(pref + tp.getJavaType() + " get_" +name + "(int index) { " +s_log+"return " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                               tp.getJavaResult(stp.getOffset(tp) + "+index*" + elemSize, null) + "; }");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                    if (tp.getReferencedType() instanceof AtomicType) { // Set for StructType is forbidden
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                        pw.println(MessageFormat.format(pref + "void set_{0}(int index, {1} v) '{' {3} {2}; '}'",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                                                        new Object[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                                                            name, jt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                                                            tp.getJavaConversion("pData+"+stp.getOffset(tp)+" + index*" + elemSize, "v"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                                                            s_log}));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                    // Returns pointer to the start of the array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                    pw.println(pref + "long get_" +name+ "() { "+s_log+"return pData+"+stp.getOffset(tp)+"; }");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                } else if (type == AtomicType.TYPE_PTR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                    pw.println(MessageFormat.format(pref + "{0} get_{1}(int index) '{' {3} return {2}; '}'",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                                         new Object[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                                             jt, name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                                             tp.getJavaResult("index*" + elemSize, "Native.getLong(pData+"+stp.getOffset(tp)+")"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                                             s_log
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                                             }));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                    pw.println(pref + "long get_" +name+ "() { "+s_log+"return Native.getLong(pData+"+stp.getOffset(tp)+"); }");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                    pw.println(MessageFormat.format(pref + "void set_{0}({1} v) '{' {3} {2}; '}'",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                                                    new Object[] {name, "long", "Native.putLong(pData + " + stp.getOffset(tp) + ", v)", s_log}));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                    acc_size_32 += elemSize_32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                    acc_size_64 += elemSize_64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                    acc_size_32 += elemSize_32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                    acc_size_64 += elemSize_64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                    pw.println(pref + tp.getJavaType() + " get_" +name +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                               "() { "+s_log+"return " + tp.getJavaResult(stp.getOffset(tp), null) + "; }");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                    if (type != AtomicType.TYPE_STRUCT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                        pw.println(MessageFormat.format(pref + "void set_{0}({1} v) '{' {3} {2}; '}'",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                                                        new Object[] {name, jt, tp.getJavaConversion("pData+"+stp.getOffset(tp), "v"), s_log}));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        if (s_size_32 != null && !s_size_32.equals(Integer.toString(acc_size_32))) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10872
diff changeset
   811
            if (log.isLoggable(Level.FINE)) {
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10872
diff changeset
   812
                log.fine("32 bits: The size of the structure " + stp.getName() + " " + s_size_32 +
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                        " is not equal to the accumulated size " +acc_size_32 + " of the fields");
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10872
diff changeset
   814
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        } else if (s_size_64 != null && !s_size_64.equals(Integer.toString(acc_size_64))) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10872
diff changeset
   816
            if (log.isLoggable(Level.FINE)) {
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10872
diff changeset
   817
                log.fine("64 bits: The size of the structure " + stp.getName() + " " +s_size_64+
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                        " is not equal to the accumulated size " +acc_size_64+" of the fields");
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10872
diff changeset
   819
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    public void writeWrapperSubclass(StructType stp, PrintWriter pw, boolean wide) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        pw.println("class " + stp.getJavaClassName() + "AccessorImpl"  + " extends " + stp.getJavaClassName() + "Accessor  {");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        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 */");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        writeAccessorImpls(stp, pw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        pw.println("\n\n } \n\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    public void writeWrapper(String outputDir, StructType stp)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        if (stp.getNumFields() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
                FileOutputStream fs =  new FileOutputStream(outputDir + "/"+stp.getJavaClassName()+".java");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
                PrintWriter pw = new PrintWriter(fs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
                pw.println("// This file is an automatically generated file, please do not edit this file, modify the WrapperGenerator.java file instead !\n" );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
                pw.println("package "+package_name+";\n");
33674
566777f73c32 8140606: Update library code to use internal Unsafe
chegar
parents: 22967
diff changeset
   844
                pw.println("import jdk.internal.misc.Unsafe;\n");
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2473
diff changeset
   845
                pw.println("import sun.util.logging.PlatformLogger;");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                String baseClass = stp.getBaseClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                if (baseClass == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                    baseClass = defaultBaseClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                if (stp.getIsInterface()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                    pw.print("public interface ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
                    pw.print(stp.getJavaClassName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
                    pw.print("public class ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
                    pw.print(stp.getJavaClassName() + " extends " + baseClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                if (stp.getInterfaces() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
                    pw.print(" implements " + stp.getInterfaces());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
                pw.println(" { ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
                if (!stp.getIsInterface()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
                    pw.println("\tprivate Unsafe unsafe = XlibWrapper.unsafe; ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                    pw.println("\tprivate final boolean should_free_memory;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                    pw.println("\tpublic static int getSize() { return " + stp.getSize() + "; }");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                    pw.println("\tpublic int getDataSize() { return getSize(); }");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
                    pw.println("\n\tlong pData;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                    pw.println("\n\tpublic long getPData() { return pData; }");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 2
diff changeset
   869
                    pw.println("\n\n\tpublic " + stp.getJavaClassName() + "(long addr) {");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                    if (generateLog) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                        pw.println("\t\tlog.finest(\"Creating\");");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                    pw.println("\t\tpData=addr;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
                    pw.println("\t\tshould_free_memory = false;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                    pw.println("\t}");
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 2
diff changeset
   876
                    pw.println("\n\n\tpublic " + stp.getJavaClassName() + "() {");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
                    if (generateLog) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                        pw.println("\t\tlog.finest(\"Creating\");");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
                    pw.println("\t\tpData = unsafe.allocateMemory(getSize());");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
                    pw.println("\t\tshould_free_memory = true;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
                    pw.println("\t}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
                    pw.println("\n\n\tpublic void dispose() {");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                    if (generateLog) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                        pw.println("\t\tlog.finest(\"Disposing\");");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
                    pw.println("\t\tif (should_free_memory) {");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                    if (generateLog) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
                        pw.println("\t\t\tlog.finest(\"freeing memory\");");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
                    pw.println("\t\t\tunsafe.freeMemory(pData); \n\t}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
                    pw.println("\t\t}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                    writeAccessorImpls(stp, pw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
                    writeToString(stp,pw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
                    pw.println("\n\n\tvoid dispose();");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
                    pw.println("\n\tlong getPData();");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
                    writeStubs(stp,pw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
                pw.println("}\n\n\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
                pw.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
            catch (Exception e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
    private boolean readSizeInfo(InputStream is, boolean wide) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        String line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        String splits[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        BufferedReader in  = new BufferedReader(new InputStreamReader(is));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            while ((line = in.readLine()) != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                splits = line.split("\\p{Space}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                if (splits.length == 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                    if (wide) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                        sizeTable64bit.put(splits[0],splits[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                        sizeTable32bit.put(splits[0],splits[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
    public void writeFunctionCallWrapper(String outputDir, FunctionType ft) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
            FileOutputStream fs =  new FileOutputStream(outputDir + "/" + ft.getName()+".java");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
            PrintWriter pw = new PrintWriter(fs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
            pw.println("// This file is an automatically generated file, please do not edit this file, modify the WrapperGenerator.java file instead !\n" );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
            pw.println("package "+package_name+";\n");
33674
566777f73c32 8140606: Update library code to use internal Unsafe
chegar
parents: 22967
diff changeset
   944
            pw.println("import jdk.internal.misc.Unsafe;\n");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
            pw.println("class " + ft.getName() + " {");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
            pw.println("\tprivate static Unsafe unsafe = XlibWrapper.unsafe;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            pw.println("\tprivate boolean __executed = false;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            pw.println("\tprivate boolean __disposed = false;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            Iterator iter = ft.getArguments().iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            while (iter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                AtomicType at = (AtomicType)iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
                if (at.isIn()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
                    pw.println("\t" + at.getJavaType() + " _" + at.getName() + ";");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                    pw.println("\tlong " + at.getName() + "_ptr = unsafe.allocateMemory(Native.get" + at.getTypeUpperCase() + "Size());");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            pw.println("\tpublic " + ft.getName() + "(");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
            iter = ft.getArguments().iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            boolean first = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            while (iter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                AtomicType at = (AtomicType)iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                if (at.isIn() || at.isInOut()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                    if (!first) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                        pw.println(",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                    first = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                    pw.print("\t\t" + at.getJavaType() + " " + at.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
            pw.println("\t)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
            pw.println("\t{");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
            iter = ft.getArguments().iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
            while (iter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
                AtomicType at = (AtomicType)iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
                if (at.isIn() || at.isInOut()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
                    pw.println("\t\tset_" + at.getName() + "(" + at.getName() + ");");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
            pw.println("\t}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
            pw.println("\tpublic " + ft.getReturnType() + " execute() {");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
            if (ft.isVoid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
                pw.println("\t\texecute(null);");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
                pw.println("\t\treturn execute(null);");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
            pw.println("\t}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
            pw.println("\tpublic " + ft.getReturnType() + " execute(XToolkit.XErrorHandler errorHandler) {");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
            pw.println("\t\tif (__disposed) {");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
            pw.println("\t\t    throw new IllegalStateException(\"Disposed\");");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            pw.println("\t\t}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
            pw.println("\t\tXToolkit.awtLock();");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
            pw.println("\t\ttry {");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
            pw.println("\t\t\tif (__executed) {");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
            pw.println("\t\t\t    throw new IllegalStateException(\"Already executed\");");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
            pw.println("\t\t\t}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
            pw.println("\t\t\t__executed = true;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
            pw.println("\t\t\tif (errorHandler != null) {");
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 16839
diff changeset
  1001
            pw.println("\t\t\t    XErrorHandlerUtil.WITH_XERROR_HANDLER(errorHandler);");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
            pw.println("\t\t\t}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
            iter = ft.getArguments().iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
            while (iter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
                AtomicType at = (AtomicType)iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
                if (!at.isIn() && at.isAutoFree()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                    pw.println("\t\t\tNative.put" + at.getTypeUpperCase() + "(" +at.getName() + "_ptr, 0);");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
            if (!ft.isVoid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
                pw.println("\t\t\t" + ft.getReturnType() + " status = ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
            pw.println("\t\t\tXlibWrapper." + ft.getName() + "(XToolkit.getDisplay(), ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
            iter = ft.getArguments().iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
            first = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
            while (iter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
                AtomicType at = (AtomicType)iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
                if (!first) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
                    pw.println(",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
                first = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
                if (at.isIn()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
                    pw.print("\t\t\t\tget_" + at.getName() + "()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
                    pw.print("\t\t\t\t" + at.getName() + "_ptr");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
            pw.println("\t\t\t);");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
            pw.println("\t\t\tif (errorHandler != null) {");
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 16839
diff changeset
  1030
            pw.println("\t\t\t    XErrorHandlerUtil.RESTORE_XERROR_HANDLER();");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
            pw.println("\t\t\t}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
            if (!ft.isVoid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                pw.println("\t\t\treturn status;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            pw.println("\t\t} finally {");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
            pw.println("\t\t    XToolkit.awtUnlock();");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
            pw.println("\t\t}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
            pw.println("\t}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
            pw.println("\tpublic boolean isExecuted() {");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
            pw.println("\t    return __executed;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
            pw.println("\t}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
            pw.println("\t");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
            pw.println("\tpublic boolean isDisposed() {");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
            pw.println("\t    return __disposed;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
            pw.println("\t}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
            pw.println("\tpublic void finalize() {");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
            pw.println("\t    dispose();");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
            pw.println("\t}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
            pw.println("\tpublic void dispose() {");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
            pw.println("\t\tXToolkit.awtLock();");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
            pw.println("\t\ttry {");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
            pw.println("\t\tif (__disposed || !__executed) {");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
            pw.println("\t\t    return;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
            pw.println("\t\t} finally {");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
            pw.println("\t\t    XToolkit.awtUnlock();");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            pw.println("\t\t}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
            pw.println("\t\t}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
            iter = ft.getArguments().iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
            while (iter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                AtomicType at = (AtomicType)iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                if (!at.isIn()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                    if (at.isAutoFree()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                        pw.println("\t\tif (__executed && get_" + at.getName() + "()!= 0) {");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                        pw.println("\t\t\tXlibWrapper.XFree(get_" + at.getName() + "());");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                        pw.println("\t\t}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
                    pw.println("\t\tunsafe.freeMemory(" + at.getName() + "_ptr);");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
            pw.println("\t\t__disposed = true;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
            pw.println("\t\t}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
            pw.println("\t}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
            iter = ft.getArguments().iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
            while (iter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                AtomicType at = (AtomicType)iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
                pw.println("\tpublic " + at.getJavaType() + " get_" + at.getName() + "() {");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
                pw.println("\t\tif (__disposed) {");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
                pw.println("\t\t    throw new IllegalStateException(\"Disposed\");");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
                pw.println("\t\t}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                pw.println("\t\tif (!__executed) {");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
                pw.println("\t\t    throw new IllegalStateException(\"Not executed\");");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
                pw.println("\t\t}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
                if (at.isIn()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
                    pw.println("\t\treturn _" + at.getName() + ";");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
                    pw.println("\t\treturn Native.get" + at.getTypeUpperCase() + "(" + at.getName() + "_ptr);");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                pw.println("\t}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
                pw.println("\tpublic void set_" + at.getName() + "(" + at.getJavaType() + " data) {");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                if (at.isIn()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
                    pw.println("\t\t_" + at.getName() + " = data;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
                    pw.println("\t\tNative.put" + at.getTypeUpperCase() + "(" + at.getName() + "_ptr, data);");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
                pw.println("\t}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
            pw.println("}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
            pw.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
    public void writeJavaWrapperClass(String outputDir) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
            for (Enumeration e = symbolTable.elements() ; e.hasMoreElements() ;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                BaseType tp = (BaseType) e.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                if (tp instanceof StructType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                    StructType st = (StructType) tp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
                    writeWrapper(outputDir, st);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
                } else if (tp instanceof FunctionType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
                    writeFunctionCallWrapper(outputDir, (FunctionType)tp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
    public void writeNativeSizer(String file)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
        int type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
        int i=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
        int j=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        BaseType tp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        StructType stp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
        Enumeration eo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
            FileOutputStream fs =  new FileOutputStream(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
            PrintWriter pw = new PrintWriter(fs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
            pw.println("/* This file is an automatically generated file, please do not edit this file, modify the XlibParser.java file instead !*/\n" );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
            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");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
            pw.println("#include <X11/extensions/Xdbe.h>");
2473
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2451
diff changeset
  1145
            pw.println("#include <X11/XKBlib.h>");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
            pw.println("#include \"awt_p.h\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
            pw.println("#include \"color.h\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
            pw.println("#include \"colordata.h\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
            pw.println("\ntypedef struct\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
            pw.println("{\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
            pw.println("    unsigned long flags;\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
            pw.println("    unsigned long functions;\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
            pw.println("    unsigned long decorations;\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
            pw.println("    long inputMode;\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
            pw.println("    unsigned long status;\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
            pw.println("} PropMwmHints;\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
            pw.println("\n\nint main(){");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
            j=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
            for ( eo = symbolTable.elements() ; eo.hasMoreElements() ;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
                tp = (BaseType) eo.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
                if (tp instanceof StructType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
                    stp = (StructType) tp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
                    if (!stp.getIsInterface()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
                        pw.println(stp.getName()+"  temp"+ j + ";\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
                        j++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
            j=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
            pw.println("printf(\"long\t%d\\n\",(int)sizeof(long));");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
            pw.println("printf(\"int\t%d\\n\",(int)sizeof(int));");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
            pw.println("printf(\"short\t%d\\n\",(int)sizeof(short));");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
            pw.println("printf(\"ptr\t%d\\n\",(int)sizeof(void *));");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
            pw.println("printf(\"Bool\t%d\\n\",(int)sizeof(Bool));");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
            pw.println("printf(\"Atom\t%d\\n\",(int)sizeof(Atom));");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
            pw.println("printf(\"Window\t%d\\n\",(int)sizeof(Window));");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
            for (eo = symbolTable.elements() ; eo.hasMoreElements() ;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
                tp = (BaseType) eo.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
                if (tp instanceof StructType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
                    stp = (StructType) tp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
                    if (stp.getIsInterface()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
                    for (Enumeration e = stp.getMembers() ; e.hasMoreElements() ;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
                        AtomicType atp = (AtomicType) e.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
                        if (atp.isAlias()) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
                        pw.println("printf(\""+ stp.getName() + "." + atp.getName() + "\t%d\\n\""+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
                                   ",(int)((unsigned long ) &temp"+j+"."+atp.getName()+"- (unsigned long ) &temp" + j + ")  );");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
                        i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
                    pw.println("printf(\""+ stp.getName() + "\t%d\\n\"" + ",(int)sizeof(temp"+j+"));");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
                    j++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
            pw.println("return 0;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
            pw.println("}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
            pw.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
        catch (Exception e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
    private void initTypes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
        symbolTable.put("int", new AtomicType(AtomicType.TYPE_INT, "", "int"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
        symbolTable.put("short", new AtomicType(AtomicType.TYPE_SHORT, "", "short"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
        symbolTable.put("long", new AtomicType(AtomicType.TYPE_LONG, "", "long"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
        symbolTable.put("float", new AtomicType(AtomicType.TYPE_FLOAT, "", "float"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
        symbolTable.put("double", new AtomicType(AtomicType.TYPE_DOUBLE, "", "double"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
        symbolTable.put("Bool", new AtomicType(AtomicType.TYPE_BOOL, "", "Bool"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        symbolTable.put("char", new AtomicType(AtomicType.TYPE_CHAR, "", "char"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
        symbolTable.put("byte", new AtomicType(AtomicType.TYPE_BYTE, "", "byte"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
        symbolTable.put("pointer", new AtomicType(AtomicType.TYPE_PTR, "", "pointer"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
        symbolTable.put("longlong", new AtomicType(AtomicType.TYPE_LONG_LONG, "", "longlong"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
        symbolTable.put("Atom", new AtomicType(AtomicType.TYPE_ATOM, "", "Atom"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
        symbolTable.put("ulong", new AtomicType(AtomicType.TYPE_ULONG, "", "ulong"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
    }
56211
657780f239c4 Fix X11Wrappers.
ihse
parents: 47216
diff changeset
  1232
657780f239c4 Fix X11Wrappers.
ihse
parents: 47216
diff changeset
  1233
    public WrapperGenerator(String xlibFilename) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
        initTypes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
            BufferedReader in  = new BufferedReader(new FileReader(xlibFilename));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
            String line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
            String splits[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
            BaseType curType = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
            while ((line = in.readLine()) != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
                int commentStart = line.indexOf("//");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
                if (commentStart >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
                    // remove comment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
                    line = line.substring(0, commentStart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
                if ("".equals(line)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
                    // skip empty line
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
                splits = line.split("\\p{Space}+");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
                if (splits.length >= 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
                    String struct_name = curType.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
                    String field_name = splits[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
                    String s_type = splits[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
                    BaseType bt = curType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
                    int type = AtomicType.getTypeForString(s_type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
                    AtomicType atp = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
                    if (bt != null && type != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
                        atp = new AtomicType(type,field_name,s_type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
                        if (splits.length > 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
                            atp.setAttributes(splits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
                        if (bt instanceof StructType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
                            StructType  stp = (StructType) bt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
                            stp.addMember(atp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
                        } else if (bt instanceof FunctionType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
                            ((FunctionType)bt).addArgument(atp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
                    else if (bt == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
                        System.out.println("Cannot find " + struct_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
                else  if (line != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
                    BaseType bt = (BaseType) symbolTable.get(line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
                    if (bt == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
                        if (line.startsWith("!")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
                            FunctionType ft = new FunctionType(line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
                            ft.setName(line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
                            symbolTable.put(ft.getName(),ft);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
                            curType = ft;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
                            StructType stp = new StructType(line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
                            stp.setName(line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
                            curType = stp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
                            symbolTable.put(stp.getName(),stp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
            in.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
        catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
        }
56211
657780f239c4 Fix X11Wrappers.
ihse
parents: 47216
diff changeset
  1302
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
56211
657780f239c4 Fix X11Wrappers.
ihse
parents: 47216
diff changeset
  1304
    private void makeSizer(String sizerFileName) {
657780f239c4 Fix X11Wrappers.
ihse
parents: 47216
diff changeset
  1305
        File fp = new File(sizerFileName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
        writeNativeSizer(fp.getAbsolutePath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
    }
56211
657780f239c4 Fix X11Wrappers.
ihse
parents: 47216
diff changeset
  1308
657780f239c4 Fix X11Wrappers.
ihse
parents: 47216
diff changeset
  1309
    private boolean readSizeInfo(String file32, String file64) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
            boolean res = true;
56211
657780f239c4 Fix X11Wrappers.
ihse
parents: 47216
diff changeset
  1312
            if (!file32.equals("IGNORE")) {
657780f239c4 Fix X11Wrappers.
ihse
parents: 47216
diff changeset
  1313
                FileInputStream fis = new FileInputStream(file32);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
                res = readSizeInfo(fis, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
                fis.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
            }
56211
657780f239c4 Fix X11Wrappers.
ihse
parents: 47216
diff changeset
  1317
            if (!file64.equals("IGNORE")) {
657780f239c4 Fix X11Wrappers.
ihse
parents: 47216
diff changeset
  1318
                FileInputStream fis = new FileInputStream(file64);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
                res &= readSizeInfo(fis, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
                fis.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
56211
657780f239c4 Fix X11Wrappers.
ihse
parents: 47216
diff changeset
  1329
    private void startGeneration(String outputDir, String file32, String file64) {
657780f239c4 Fix X11Wrappers.
ihse
parents: 47216
diff changeset
  1330
        if (readSizeInfo(file32, file64))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
            writeJavaWrapperClass(outputDir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
            System.out.println("Error calculating offsets");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
        if (args.length < 4) {
56211
657780f239c4 Fix X11Wrappers.
ihse
parents: 47216
diff changeset
  1342
            System.out.println("Usage:\nWrapperGenerator gen_java <output_dir> <xlibtypes.txt> <sizes-32.txt|IGNORE> <sizes-64.txt|IGNORE>");
657780f239c4 Fix X11Wrappers.
ihse
parents: 47216
diff changeset
  1343
            System.out.println("      or");
657780f239c4 Fix X11Wrappers.
ihse
parents: 47216
diff changeset
  1344
            System.out.println("WrapperGenerator gen_c_source <output_file> <xlibtypes.txt> <platform>");
657780f239c4 Fix X11Wrappers.
ihse
parents: 47216
diff changeset
  1345
            System.out.println("Where <platform>: 32, 64");
657780f239c4 Fix X11Wrappers.
ihse
parents: 47216
diff changeset
  1346
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
            System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
56211
657780f239c4 Fix X11Wrappers.
ihse
parents: 47216
diff changeset
  1350
        WrapperGenerator xparser = new WrapperGenerator(args[2]);
657780f239c4 Fix X11Wrappers.
ihse
parents: 47216
diff changeset
  1351
        if (args[0].equals("gen_c_source")) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
            xparser.wide = args[3].equals("64");
56211
657780f239c4 Fix X11Wrappers.
ihse
parents: 47216
diff changeset
  1353
            xparser.makeSizer(args[1]);
657780f239c4 Fix X11Wrappers.
ihse
parents: 47216
diff changeset
  1354
        } else if (args[0].equals("gen_java")) {
657780f239c4 Fix X11Wrappers.
ihse
parents: 47216
diff changeset
  1355
            xparser.startGeneration(args[1], args[3], args[4]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
}