VirtualBox

Changeset 29118 in vbox for trunk/src/libs/xpcom18a4/xpcom


Ignore:
Timestamp:
May 6, 2010 3:05:29 AM (15 years ago)
Author:
vboxsync
Message:

xpidl,java/Makefile.kmk: Hacked the java mode of xpidl into producing output equivalent to that of genjifaces. There are some minor diffs still and the output spec needs fixing (file -> directory), the .java output compiles but has not been tested. xpidl is able to generate the enum constants used in VirtualBox, genjifaces isn't.

Location:
trunk/src/libs/xpcom18a4/xpcom/typelib/xpidl
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/xpcom18a4/xpcom/typelib/xpidl/xpidl.h

    r1 r29118  
    1515 * The Original Code is mozilla.org code.
    1616 *
    17  * The Initial Developer of the Original Code is 
     17 * The Initial Developer of the Original Code is
    1818 * Netscape Communications Corporation.
    1919 * Portions created by the Initial Developer are Copyright (C) 1998
     
    2323 *
    2424 * Alternatively, the contents of this file may be used under the terms of
    25  * either the GNU General Public License Version 2 or later (the "GPL"), or 
     25 * either the GNU General Public License Version 2 or later (the "GPL"), or
    2626 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
    2727 * in which case the provisions of the GPL or the LGPL are applicable instead
     
    108108/* Function that produces a struct of output-generation functions */
    109109typedef backend *(*backendFactory)();
    110  
     110
    111111extern backend *xpidl_header_dispatch(void);
    112112extern backend *xpidl_typelib_dispatch(void);
     
    135135    nodeHandler      *dispatch;
    136136    void             *priv;     /* mode-private data */
     137#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
     138    char             *real_outname;
     139#endif
     140
    137141};
    138142
     
    257261/*
    258262 * Verifies the interface declaration
    259  */ 
     263 */
    260264gboolean
    261265verify_interface_declaration(IDL_tree method_tree);
  • trunk/src/libs/xpcom18a4/xpcom/typelib/xpidl/xpidl_idl.c

    r1 r29118  
    1515 * The Original Code is mozilla.org code.
    1616 *
    17  * The Initial Developer of the Original Code is 
     17 * The Initial Developer of the Original Code is
    1818 * Netscape Communications Corporation.
    1919 * Portions created by the Initial Developer are Copyright (C) 1998
     
    2424 *
    2525 * Alternatively, the contents of this file may be used under the terms of
    26  * either the GNU General Public License Version 2 or later (the "GPL"), or 
     26 * either the GNU General Public License Version 2 or later (the "GPL"), or
    2727 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
    2828 * in which case the provisions of the GPL or the LGPL are applicable instead
     
    117117 */
    118118typedef struct input_callback_state {
    119     struct input_data *input_stack; /* linked list of input_data */   
     119    struct input_data *input_stack; /* linked list of input_data */
    120120    GHashTable *already_included;   /* to prevent redundant includes */
    121121    IncludePathEntry *include_path; /* search path for included files */
     
    266266    if (!(data->point[0] == '%' && data->point[1] == '{'))
    267267        return 0;
    268        
     268
    269269    start = *startp = data->point;
    270    
     270
    271271    end = NULL;
    272272    while (start < data->max && (end = strstr(start, "%}"))) {
     
    305305        int skippedLines = 0;
    306306        char *tempPoint;
    307        
     307
    308308        /* get current lineno */
    309309        IDL_file_get(NULL,(int *)&data->lineno);
     
    317317        data->lineno += skippedLines;
    318318        IDL_file_set(data->filename, (int)data->lineno);
    319        
     319
    320320        *startp = end + 2;
    321321
     
    355355        return 0;
    356356    }
    357    
     357
    358358    filename = data->point + 10; /* skip #include " */
    359359    XPT_ASSERT(filename < data->max);
     
    379379        }
    380380        *end = '\0';
    381        
     381
    382382        /* make sure we have accurate line info */
    383383        IDL_file_get(&scratch, (int *)&data->lineno);
     
    400400         */
    401401        char *filename_cp = xpidl_strdup(filename);
    402        
     402
    403403        /* note that g_slist_append accepts and likes null as list-start. */
    404404        callback_state->base_includes =
     
    436436    *lenp = 0;               /* this is magic, see the comment below */
    437437    return 1;
    438 }   
     438}
    439439
    440440static void
     
    454454                                 (point > data->point &&                     \
    455455                                  (point[-1] == '\r' || point[-1] == '\n')))
    456                                                  
     456
    457457    while (point < data->max) {
    458458        if (point[0] == '/' && point[1] == '*')
     
    536536            IDL_inhibit_pop();
    537537        }
    538        
     538
    539539        /*
    540540         * Now we scan for sequences which require special attention:
     
    542542         *   \n%{                         begins a raw-source block
    543543         *   /\*                          begins a comment
    544          * 
     544         *
    545545         * We used to be fancier here, so make sure that we sent the most
    546546         * data possible at any given time.  To that end, we skipped over
    547547         * \n%{ raw \n%} blocks and then _continued_ the search for special
    548548         * sequences like \n#include or /\* comments .
    549          * 
     549         *
    550550         * It was really ugly, though -- liberal use of goto!  lots of implicit
    551551         * state!  what fun! -- so now we just do this:
     
    739739            real_outname = g_strdup(outname);
    740740        } else {
    741 /* 
     741/*
    742742 *This combination seems a little strange, what about OS/2?
    743743 * Assume it's some build issue
     
    766766    }
    767767    state.tree = top;
     768#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
     769    state.real_outname = real_outname;
     770#endif
    768771
    769772    if (emitter->emit_prolog)
  • trunk/src/libs/xpcom18a4/xpcom/typelib/xpidl/xpidl_java.c

    r1 r29118  
    1313 * The Original Code is mozilla.org code.
    1414 *
    15  * The Initial Developer of the Original Code is Sun Microsystems, 
     15 * The Initial Developer of the Original Code is Sun Microsystems,
    1616 * Inc. Portions created by Sun are
    1717 * Copyright (C) 1999 Sun Microsystems, Inc. All
    1818 * Rights Reserved.
    1919 *
    20  * Contributor(s): 
     20 * Contributor(s):
    2121 *    Michael Allen ([email protected])
    2222 *    Frank Mitchell ([email protected])
     
    6161java_prolog(TreeState *state)
    6262{
     63#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
     64    const char *basename;
     65    const char *ext;
     66#endif
     67
    6368    state->priv = calloc(1, sizeof(struct java_priv_data));
    6469    if (!state->priv)
     
    7176        return FALSE;
    7277    }
    73    
     78
    7479    /*
    7580     * First pass
    7681     */
    77    
     82
     83#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
     84    basename = xpidl_basename(state->real_outname ? state->real_outname : state->basename);
     85    ext = strrchr(basename, '.');
     86    if (!ext)
     87        ext = strchr(basename, '\0');
     88    fprintf(state->file,
     89            "/**\n"
     90            " * NOTE: THIS IS A GENERATED FILE. PLEASE CONSULT THE ORIGINAL IDL FILE\n"
     91            " * FOR THE FULL DOCUMENTION AND LICENSE.\n"
     92            " *\n"
     93            " * @see <a href=\"http://lxr.mozilla.org/mozilla/search?string=interface+%.*s\">\n"
     94            " **/\n"
     95            "\n"
     96            "package org.mozilla.interfaces;\n"
     97            "\n"
     98            , ext - basename >= 19 ? 19 : (int)(ext - basename), basename);
     99#else
    78100    fputs("/*\n * ************* DO NOT EDIT THIS FILE ***********\n",
    79101          state->file);
    80    
    81     fprintf(state->file, 
    82             " *\n * This file was automatically generated from %s.idl.\n", 
     102
     103    fprintf(state->file,
     104            " *\n * This file was automatically generated from %s.idl.\n",
    83105            state->basename);
    84    
     106
    85107    fputs(" */\n\n", state->file);
    86        
    87     return TRUE;
    88 }
    89 
    90 static gboolean
     108#endif
     109
     110    return TRUE;
     111}
     112
     113static gboolean
    91114java_epilog(TreeState *state)
    92115{
     
    95118    free(state->priv);
    96119    state->priv = NULL;
    97    
     120
     121#ifndef VBOX_XPIDL_EMULATE_GENJIFACES
    98122    /*
    99123     * Last pass
    100124     */
    101    
     125
    102126    fprintf(state->file, "\n/*\n * end\n */\n");
    103 
    104     return TRUE;
    105 }
    106 
    107 static gboolean
    108 forward_declaration(TreeState *state)
    109 {
    110     /*
    111      * Java doesn't need forward declarations unless the declared
     127#endif
     128
     129    return TRUE;
     130}
     131
     132static gboolean
     133forward_declaration(TreeState *state)
     134{
     135    /*
     136     * Java doesn't need forward declarations unless the declared
    112137     * class resides in a different package.
    113138     */
     
    126151
    127152static gboolean
    128 interface_declaration(TreeState *state) 
     153interface_declaration(TreeState *state)
    129154{
    130155    IDL_tree interface = state->tree;
     
    135160    if (!verify_interface_declaration(interface))
    136161        return FALSE;
     162#ifndef VBOX_XPIDL_EMULATE_GENJIFACES
    137163    /*
    138164     * Write out JavaDoc comment
     
    140166
    141167    fprintf(state->file, "\n/**\n * Interface %s\n", interface_name);
     168#endif
    142169
    143170#ifndef LIBIDL_MAJOR_VERSION
     
    147174#endif
    148175
     176#ifndef VBOX_XPIDL_EMULATE_GENJIFACES
    149177    if (iid != NULL) {
    150178        fprintf(state->file, " *\n * IID: 0x%s\n */\n\n", iid);
     
    152180        fputs(" */\n\n", state->file);
    153181    }
    154 
     182#endif
    155183
    156184    /*
     
    170198        do {
    171199
    172             fprintf(state->file, "%s", 
     200            fprintf(state->file, "%s",
    173201                    IDL_IDENT(IDL_LIST(iterator).data).str);
    174            
     202
    175203            if (IDL_LIST(iterator).next) {
    176204                fputs(", ", state->file);
     
    181209
    182210    fputs("\n{\n", state->file);
    183    
     211
    184212    if (iid) {
    185213        /*
     
    187215         */
    188216
     217#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
     218        fputs("  public static final String ", state->file);
     219#else
    189220        fputs("    public static final String ", state->file);
     221#endif
    190222
    191223        /* XXX s.b just "IID" ? */
     
    194226        }
    195227
     228#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
     229        fprintf(state->file, " =\n    \"{%s}\";\n", iid);
     230
     231#else
    196232        fprintf(state->file, "_STRING =\n        \"%s\";\n\n", iid);
    197233
     
    204240
    205241        fprintf(state->file, " =\n        new nsID(\"%s\");\n\n", iid);
     242#endif
    206243    }
    207244
     
    209246     * Advance the state of the tree, go on to process more
    210247     */
    211    
     248
    212249    state->tree = IDL_INTERFACE(interface).body;
    213250
     
    225262process_list(TreeState *state)
    226263{
     264#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
     265    /* To make the diffing simple, group the constants, methods and attributes. */
     266    IDL_tree list = state->tree;
     267    IDL_tree iter;
     268    for (iter = list; iter; iter = IDL_LIST(iter).next) {
     269        if (IDL_NODE_TYPE(IDL_LIST(iter).data) == IDLN_CONST_DCL) {
     270            state->tree = IDL_LIST(iter).data;
     271            if (!xpidl_process_node(state))
     272                return FALSE;
     273        }
     274    }
     275    for (iter = list; iter; iter = IDL_LIST(iter).next) {
     276        if (IDL_NODE_TYPE(IDL_LIST(iter).data) == IDLN_ATTR_DCL) {
     277            state->tree = IDL_LIST(iter).data;
     278            if (!xpidl_process_node(state))
     279                return FALSE;
     280        }
     281    }
     282    for (iter = list; iter; iter = IDL_LIST(iter).next) {
     283        if (IDL_NODE_TYPE(IDL_LIST(iter).data) == IDLN_OP_DCL) {
     284            state->tree = IDL_LIST(iter).data;
     285            if (!xpidl_process_node(state))
     286                return FALSE;
     287        }
     288    }
     289    for (iter = list; iter; iter = IDL_LIST(iter).next) {
     290        if (   IDL_NODE_TYPE(IDL_LIST(iter).data) != IDLN_CONST_DCL
     291            && IDL_NODE_TYPE(IDL_LIST(iter).data) != IDLN_OP_DCL
     292            && IDL_NODE_TYPE(IDL_LIST(iter).data) != IDLN_ATTR_DCL ) {
     293            state->tree = IDL_LIST(iter).data;
     294            if (!xpidl_process_node(state))
     295                return FALSE;
     296        }
     297    }
     298
     299#else
    227300    IDL_tree iter;
    228301    for (iter = state->tree; iter; iter = IDL_LIST(iter).next) {
     
    231304            return FALSE;
    232305    }
    233     return TRUE;
    234 }
    235 
    236 static gboolean
    237 xpcom_to_java_type (TreeState *state)
     306#endif
     307    return TRUE;
     308}
     309
     310#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
     311static gboolean
     312interface_declaration_wrapper(TreeState *state)
     313{
     314    IDL_tree interface = state->tree;
     315    char *interface_name = IDL_IDENT(IDL_INTERFACE(interface).ident).str;
     316    FILE *org_file = state->file;
     317    char *org_name = state->real_outname;
     318    void *org_priv = state->priv;
     319    gboolean rc;
     320
     321    /*
     322     * Skip non-scriptable interfaces.
     323     */
     324    if (   !IDL_tree_property_get(IDL_INTERFACE(interface).ident, "scriptable")
     325         && strcmp(interface_name, "nsIAppShell") )
     326        return TRUE;
     327
     328    /*
     329     * GROSS HACK: If the interface isn't the same as the file name,
     330     *             temporarily switch output file.
     331     */
     332    if (state->real_outname) {
     333        const char *basename = xpidl_basename(state->real_outname);
     334        const char *ext      = strrchr(basename, '.');
     335        if (   ext
     336            && !strcmp(ext, ".java")
     337            && (   strncmp(interface_name, basename, ext - basename)
     338                || interface_name[ext - basename] != '.') ) {
     339            size_t needed = strlen(state->real_outname) + strlen(interface_name) + strlen(".java") + 4;
     340            char  *tmp = malloc(needed);
     341            if (basename != state->real_outname)
     342                sprintf(tmp,"%.*s/%s.java", (int)(basename - state->real_outname - 1), state->real_outname, interface_name);
     343            else
     344                sprintf(tmp,"%s.java", interface_name);
     345            state->file = fopen(tmp, "w");
     346            if (!state->file) {
     347                perror("error opening output file");
     348                state->file = org_file;
     349                free(tmp);
     350                return FALSE;
     351            }
     352            state->real_outname = tmp;
     353            java_prolog(state);
     354        }
     355    }
     356
     357    rc = interface_declaration(state);
     358
     359    if (state->file != org_file) {
     360        java_epilog(state);
     361        fclose(state->file);
     362        free(state->real_outname);
     363        state->file = org_file;
     364        state->real_outname = org_name;
     365        state->priv = org_priv;
     366    }
     367    return rc;
     368}
     369#endif /* VBOX_XPIDL_EMULATE_GENJIFACES */
     370
     371static gboolean
     372xpcom_to_java_type (TreeState *state)
    238373{
    239374    if (!state->tree) {
     
    249384
    250385        case IDL_INTEGER_TYPE_SHORT:
     386#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
     387            if (IDL_TYPE_INTEGER(state->tree).f_signed)
     388                fputs("short", state->file);
     389            else
     390                fputs("int", state->file);
     391#else
    251392            fputs("short", state->file);
     393#endif
    252394            break;
    253395
    254396        case IDL_INTEGER_TYPE_LONG:
     397#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
     398            if (IDL_TYPE_INTEGER(state->tree).f_signed)
     399                fputs("int", state->file);
     400            else
     401                fputs("long", state->file);
     402#else
    255403            fputs("int", state->file);
     404#endif
    256405            break;
    257406
    258407        case IDL_INTEGER_TYPE_LONGLONG:
     408#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
     409            if (IDL_TYPE_INTEGER(state->tree).f_signed)
     410                fputs("long", state->file);
     411            else
     412                fputs("double", state->file);
     413#else
    259414            fputs("long", state->file);
     415#endif
    260416            break;
    261            
     417
    262418        default:
    263419            g_error("   Unknown integer type: %d\n",
     
    285441
    286442    case IDLN_TYPE_OCTET:
     443#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
     444        fputs("short", state->file);
     445#else
    287446        fputs("byte", state->file);
     447#endif
    288448        break;
    289449
     
    298458            fputs("double", state->file);
    299459            break;
    300            
     460
    301461        default:
    302462            g_error("    Unknown floating point typ: %d\n",
     
    312472            const char *user_type = IDL_NATIVE(IDL_NODE_UP(state->tree)).user_type;
    313473            if (strcmp(user_type, "void") == 0) {
     474#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
     475                fputs("nsISupports", state->file);
     476#else
    314477                fputs("Object", state->file);
     478#endif
    315479            }
    316480            else if (strcmp(user_type, "nsID") == 0 ||
     
    319483                /* XXX: s.b test for "iid" attribute */
    320484                /* XXX: special class for nsIDs */
     485#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
     486                fputs("String", state->file);
     487#else
    321488                fputs("nsID", state->file);
     489#endif
    322490            }
    323491            else {
    324492                /* XXX: special class for opaque types */
     493#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
     494                fputs("String", state->file);
     495#else
    325496                fputs("OpaqueValue", state->file);
     497#endif
    326498            }
    327499        } else {
     
    329501
    330502            /* XXX: big kludge; s.b. way to match to typedefs */
     503#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
     504            if (strcmp(ident_str, "PRInt8") == 0) {
     505                fputs("byte", state->file);
     506            }
     507            else if (strcmp(ident_str, "PRInt16") == 0 ||
     508                     strcmp(ident_str, "PRUint8") == 0) {
     509                fputs("short", state->file);
     510            }
     511            else if (strcmp(ident_str, "PRInt32") == 0 ||
     512                     strcmp(ident_str, "PRUint16") == 0) {
     513                fputs("int", state->file);
     514            }
     515            else if (strcmp(ident_str, "PRInt64") == 0 ||
     516                     strcmp(ident_str, "PRUint32") == 0 ||
     517                     strcmp(ident_str, "PRThreadPriority") == 0 ||
     518                     strcmp(ident_str, "PRThreadScope")    == 0 ||
     519                     strcmp(ident_str, "PRThreadState")    == 0) {
     520                fputs("long", state->file);
     521            }
     522            else if (strcmp(ident_str, "PRUint64") == 0) {
     523                fputs("double", state->file);
     524            }
     525#else
    331526            if (strcmp(ident_str, "PRInt8") == 0 ||
    332527                strcmp(ident_str, "PRUint8") == 0) {
     
    345540                fputs("long", state->file);
    346541            }
     542#endif
    347543            else if (strcmp(ident_str, "PRBool") == 0) {
    348544                fputs("boolean", state->file);
     
    351547                fputs("int", state->file);
    352548            }
     549#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
     550            /* XXX: Use find_underlying_type instead? */
     551            else if (   strcmp(ident_str, "nsresult") == 0
     552                     || strcmp(ident_str, "size_t") == 0) {
     553                fputs("long", state->file);
     554            }
     555            else if (   strcmp(ident_str, "PRTime") == 0) {
     556                fputs("double", state->file);
     557            }
     558            /* In Javaconnect, we handle weak references internally; no need for the
     559              |nsIWeakReference| interface.  So just return |nsISupports|. */
     560            else if (strcmp(ident_str, "nsIWeakReference") == 0) {
     561                fputs("nsISupports", state->file);
     562            }
     563#endif
    353564            else {
    354                 IDL_tree real_type = 
     565                IDL_tree real_type =
    355566                    g_hash_table_lookup(TYPEDEFS(state), ident_str);
    356567
     
    384595
    385596static gboolean
    386 xpcom_to_java_param(TreeState *state)
     597#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
     598xpcom_to_java_param(TreeState *state, unsigned nparam)
     599#else
     600xpcom_to_java_param(TreeState *state)
     601#endif
    387602{
    388603    IDL_tree param = state->tree;
     
    402617     */
    403618
     619#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
     620    /* XXX: Causes nsILineInputStream::readLine(String[] arg1) where genjifaces drops the []. */
     621#endif
    404622    if (IDL_PARAM_DCL(param).attr != IDL_PARAM_IN) {
    405623        fputs("[]", state->file);
    406624    }
    407 
    408     /*
    409      * Put in name of parameter
     625#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
     626    /*XXX: nsIConsoleService::getMessageArray ends up with [][] arg1... */
     627    /*else*/ if (IDL_tree_property_get(IDL_PARAM_DCL(param).simple_declarator, "array")) {
     628        fputs("[]", state->file);
     629    }
     630#endif
     631
     632    /*
     633     * Put in name of parameter
    410634     */
    411635
    412636    fputc(' ', state->file);
    413637
     638#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
     639    fprintf(state->file, "arg%u", nparam+1);
     640#else
    414641    fputs(IDL_IDENT(IDL_PARAM_DCL(param).simple_declarator).str, state->file);
    415 
    416     return TRUE;
    417 }
    418 
    419 
    420 static gboolean
    421 type_declaration(TreeState *state)
     642#endif
     643
     644    return TRUE;
     645}
     646
     647#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
     648static gboolean is_java_keyword(char ch0, const char *name)
     649{
     650    static const char * const kJavaKeywords[] = {
     651        "abstract", "default", "if"        , "private"     , "this"     ,
     652        "boolean" , "do"     , "implements", "protected"   , "throw"    ,
     653        "break"   , "double" , "import",     "public"      , "throws"   ,
     654        "byte"    , "else"   , "instanceof", "return"      , "transient",
     655        "case"    , "extends", "int"       , "short"       , "try"      ,
     656        "catch"   , "final"  , "interface" , "static"      , "void"     ,
     657        "char"    , "finally", "long"      , "strictfp"    , "volatile" ,
     658        "class"   , "float"  , "native"    , "super"       , "while"    ,
     659        "const"   , "for"    , "new"       , "switch"      ,
     660        "continue", "goto"   , "package"   , "synchronized",
     661        "assert"  ,  /* added in Java 1.4 */
     662        "enum"    ,  /* added in Java 5.0 */
     663        "clone"   ,  /* clone is a member function of java.lang.Object */
     664        "finalize"   /* finalize is a member function of java.lang.Object */
     665    };
     666    unsigned i;
     667    for (i = 0; i < sizeof(kJavaKeywords) / sizeof(kJavaKeywords[0]); i++) {
     668        if (kJavaKeywords[i][0] == ch0 && !strcmp(&kJavaKeywords[i][1], &name[1])) {
     669            return TRUE;
     670        }
     671    }
     672    return FALSE;
     673}
     674#endif
     675
     676static gboolean
     677type_declaration(TreeState *state)
    422678{
    423679    /*
     
    439695
    440696static gboolean
    441 method_declaration(TreeState *state) 
     697method_declaration(TreeState *state)
    442698{
    443699    /* IDL_tree method_tree = state->tree; */
    444700    struct _IDL_OP_DCL *method = &IDL_OP_DCL(state->tree);
    445     gboolean method_notxpcom = 
     701    gboolean method_notxpcom =
    446702        (IDL_tree_property_get(method->ident, "notxpcom") != NULL);
    447     gboolean method_noscript = 
     703    gboolean method_noscript =
    448704        (IDL_tree_property_get(method->ident, "noscript") != NULL);
    449705    IDL_tree iterator = NULL;
    450706    IDL_tree retval_param = NULL;
    451707    const char *method_name = IDL_IDENT(method->ident).str;
     708#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
     709    unsigned nparam = 0;
     710#endif
    452711
    453712    if (!verify_method_declaration(state->tree))
    454713        return FALSE;
    455714
     715#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
     716    /*
     717     * Skip most (todo) non-scriptable and not-xpcom methods.
     718     */
     719    if (method_noscript || method_notxpcom) {
     720        return TRUE;
     721    }
     722#endif
     723
    456724    fputc('\n', state->file);
     725#ifndef VBOX_XPIDL_EMULATE_GENJIFACES
    457726    xpidl_write_comment(state, 4);
     727#endif
    458728
    459729    /*
    460730     * Write beginning of method declaration
    461731     */
     732#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
     733    fputs("  ", state->file);
     734#else
    462735    fputs("    ", state->file);
     736#endif
    463737    if (!method_noscript) {
    464738        /* Nonscriptable methods become package-protected */
     
    468742    /*
    469743     * Write return type
    470      * Unlike C++ headers, Java interfaces return the declared 
     744     * Unlike C++ headers, Java interfaces return the declared
    471745     * return value; an exception indicates XPCOM method failure.
    472746     */
     
    478752    } else {
    479753        /* Check for retval attribute */
    480         for (iterator = method->parameter_dcls; iterator != NULL; 
     754        for (iterator = method->parameter_dcls; iterator != NULL;
    481755             iterator = IDL_LIST(iterator).next) {
    482756
     
    485759            state->tree = IDL_LIST(iterator).data;
    486760
    487             if (IDL_tree_property_get(IDL_PARAM_DCL(state->tree).simple_declarator, 
     761            if (IDL_tree_property_get(IDL_PARAM_DCL(state->tree).simple_declarator,
    488762                                      "retval")) {
    489763                retval_param = iterator;
     
    498772                    return FALSE;
    499773                }
     774#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
     775                if (IDL_tree_property_get(IDL_PARAM_DCL(IDL_LIST(iterator).data).simple_declarator, "array")) {
     776                    fputs("[]", state->file);
     777                }
     778#endif
    500779            }
    501780
     
    507786        }
    508787    }
    509  
     788
    510789    /*
    511790     * Write method name
    512791     */
     792#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
     793    if (is_java_keyword(tolower(method_name[0]), method_name)) {
     794        fprintf(state->file, " %c%s_(", tolower(method_name[0]), method_name + 1);
     795    } else {
     796        fprintf(state->file, " %c%s(", tolower(method_name[0]), method_name + 1);
     797    }
     798#else
    513799    fprintf(state->file, " %c%s(", tolower(method_name[0]), method_name + 1);
     800#endif
    514801
    515802    /*
    516803     * Write parameters
    517804     */
    518     for (iterator = method->parameter_dcls; iterator != NULL; 
     805    for (iterator = method->parameter_dcls; iterator != NULL;
    519806         iterator = IDL_LIST(iterator).next) {
    520807
     
    527814            fputs(", ", state->file);
    528815        }
    529        
     816
    530817        state->tree = IDL_LIST(iterator).data;
    531818
     819#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
     820        if (!xpcom_to_java_param(state, nparam++)) {
     821#else
    532822        if (!xpcom_to_java_param(state)) {
     823#endif
    533824            return FALSE;
    534825        }
     
    555846
    556847    return TRUE;
    557    
     848
    558849}
    559850
     
    565856    const char *name = IDL_IDENT(declaration->ident).str;
    566857    IDL_tree real_type;
     858#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
     859    IDL_tree saved_tree;
     860#endif
    567861
    568862    if (!verify_const_declaration(state->tree))
     
    574868
    575869    fputc('\n', state->file);
     870#ifndef VBOX_XPIDL_EMULATE_GENJIFACES
    576871    xpidl_write_comment(state, 4);
    577 
     872#endif
     873
     874#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
     875/* XXX: We get the WRONG signedness of stuff here. PRInt32 -> unsigned long and stuff like that. */
     876    fputs("  public static final ", state->file);
     877    switch(IDL_NODE_TYPE(real_type)) {
     878
     879    case IDLN_TYPE_INTEGER: {
     880        switch(IDL_TYPE_INTEGER(real_type).f_type) {
     881
     882        case IDL_INTEGER_TYPE_SHORT:
     883            if (IDL_TYPE_INTEGER(real_type).f_signed)
     884                fprintf(state->file, "int %s = %d;\n", name, (int)IDL_INTEGER(declaration->const_exp).value);
     885            else
     886                fprintf(state->file, "int %s = %u;\n", name, (unsigned)IDL_INTEGER(declaration->const_exp).value);
     887            break;
     888
     889        case IDL_INTEGER_TYPE_LONG:
     890            if (IDL_TYPE_INTEGER(state->tree).f_signed)
     891                fprintf(state->file, "int %s = %d;\n", name, (int)IDL_INTEGER(declaration->const_exp).value);
     892            else
     893                fprintf(state->file, "long %s = %uL;\n", name, (unsigned)IDL_INTEGER(declaration->const_exp).value);
     894            break;
     895
     896        case IDL_INTEGER_TYPE_LONGLONG:
     897            if (IDL_TYPE_INTEGER(state->tree).f_signed)
     898                fprintf(state->file, "long %lldL;\n", name, (long long)IDL_INTEGER(declaration->const_exp).value);
     899            else
     900                fprintf(state->file, "double %lluL;\n", name, (unsigned long long)IDL_INTEGER(declaration->const_exp).value);
     901            break;
     902
     903        default:
     904            g_error("   Unknown integer type: %d\n",
     905                    IDL_TYPE_INTEGER(state->tree).f_type);
     906            return FALSE;
     907
     908        }
     909        break;
     910    }
     911    default:
     912        g_error("   Unknown constant type: %d\n", IDL_NODE_TYPE(real_type));
     913        return FALSE;
     914    }
     915#else
    578916    fprintf(state->file, "    public static final %s %s = %d;\n",
    579917            (IDL_TYPE_INTEGER(real_type).f_type == IDL_INTEGER_TYPE_LONG
    580918             ? "long" : "short"),
    581919            name, (int) IDL_INTEGER(declaration->const_exp).value);
     920#endif
    582921
    583922    return TRUE;
     
    596935    char *attribute_name = ATTR_IDENT(state->tree).str;
    597936
    598     gboolean method_noscript = 
     937    gboolean method_noscript =
    599938        (IDL_tree_property_get(ATTR_PROPS(state->tree), "noscript") != NULL);
     939
     940#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
     941    /*
     942     * Skip most non-scriptable attributes.
     943     */
     944    if (method_noscript) {
     945        return TRUE;
     946    }
     947#endif
    600948
    601949#if 0
     
    610958    /* Comment */
    611959    fputc('\n', state->file);
     960#ifndef VBOX_XPIDL_EMULATE_GENJIFACES
    612961    xpidl_write_comment(state, 4);
     962#endif
    613963
    614964    state->tree = ATTR_TYPE_DECL(state->tree);
     
    617967     * Write access permission ("public" unless nonscriptable)
    618968     */
     969#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
     970    fputs("  ", state->file);
     971#else
    619972    fputs("    ", state->file);
     973#endif
    620974    if (!method_noscript) {
    621975        fputs("public ", state->file);
     
    628982        return FALSE;
    629983    }
    630    
     984
    631985    /*
    632986     * Write the name of the accessor ("get") method.
     
    638992    if (!read_only) {
    639993        /* Nonscriptable methods become package-protected */
     994#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
     995        fputs("\n  ", state->file);
     996#else
    640997        fputs("    ", state->file);
     998#endif
    641999        if (!method_noscript) {
    6421000            fputs("public ", state->file);
     
    6471005         */
    6481006        fprintf(state->file, "void set%c%s(",
    649                 toupper(attribute_name[0]), 
     1007                toupper(attribute_name[0]),
    6501008                attribute_name+1);
    651        
     1009
    6521010        /*
    6531011         * Write the proper Java type for the set operation
     
    6601018         * Write the name of the formal parameter.
    6611019         */
     1020#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
     1021        fputs(" arg1);\n", state->file);
     1022#else
    6621023        fputs(" value);\n", state->file);
     1024#endif
    6631025    }
    6641026
     
    6871049
    6881050    if (!initialized) {
     1051#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
     1052        table[IDLN_INTERFACE] = interface_declaration_wrapper;
     1053#else
    6891054        table[IDLN_INTERFACE] = interface_declaration;
     1055#endif
    6901056        table[IDLN_LIST] = process_list;
    6911057
     
    7051071    return &result;
    7061072}
     1073
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette