static gboolean do_const_dcl(TreeState *state) { struct _IDL_CONST_DCL *dcl = &IDL_CONST_DCL(state->tree); const char *name = IDL_IDENT(dcl->ident).str; gboolean is_signed; GSList *doc_comments = IDL_IDENT(dcl->ident).comments; IDL_tree real_type; const char *const_format; if (!verify_const_declaration(state->tree)) return FALSE; if (doc_comments != NULL) { write_indent(state->file); printlist(state->file, doc_comments); } /* Could be a typedef; try to map it to the real type. */ real_type = find_underlying_type(dcl->const_type); real_type = real_type ? real_type : dcl->const_type; is_signed = IDL_TYPE_INTEGER(real_type).f_signed; const_format = is_signed ? "%" IDL_LL "d" : "%" IDL_LL "uU"; write_indent(state->file); fprintf(state->file, "enum { %s = ", name); fprintf(state->file, const_format, IDL_INTEGER(dcl->const_exp).value); fprintf(state->file, " };\n\n"); return TRUE; }
static gboolean typelib_const_dcl(TreeState *state) { struct _IDL_CONST_DCL *dcl = &IDL_CONST_DCL(state->tree); const char *name = IDL_IDENT(dcl->ident).str; gboolean is_long; gboolean sign; IDL_tree real_type; XPTInterfaceDescriptor *id; XPTConstDescriptor *cd; IDL_longlong_t value; if (!verify_const_declaration(state->tree)) return FALSE; /* Could be a typedef; try to map it to the real type. */ real_type = find_underlying_type(dcl->const_type); real_type = real_type ? real_type : dcl->const_type; is_long = (IDL_TYPE_INTEGER(real_type).f_type == IDL_INTEGER_TYPE_LONG); id = CURRENT(state); if (!XPT_InterfaceDescriptorAddConsts(ARENA(state), id, 1)) return FALSE; cd = &id->const_descriptors[NEXT_CONST(state)]; cd->name = IDL_IDENT(dcl->ident).str; #ifdef DEBUG_shaver_const fprintf(stderr, "DBG: adding const %s\n", cd->name); #endif if (!fill_td_from_type(state, &cd->type, dcl->const_type)) return FALSE; value = IDL_INTEGER(dcl->const_exp).value; sign = IDL_TYPE_INTEGER(dcl->const_type).f_signed; if (is_long) { if (sign) cd->value.i32 = value; else cd->value.ui32 = value; } else { if (sign) cd->value.i16 = value; else cd->value.ui16 = value; } NEXT_CONST(state)++; return TRUE; }
static gboolean constant_declaration(TreeState *state) { /* * The C++ header XPIDL module only allows for shorts and longs (ints) * to be constants, so we will follow the same convention */ struct _IDL_CONST_DCL *declaration = &IDL_CONST_DCL(state->tree); const char *name = IDL_IDENT(declaration->ident).str; IDL_tree real_type; gboolean success; gboolean isshort = FALSE; if (!verify_const_declaration(state->tree)) return FALSE; /* Could be a typedef; try to map it to the real type. */ real_type = find_underlying_type(declaration->const_type); real_type = real_type ? real_type : declaration->const_type; /* * Consts must be in an interface */ if (!IDL_NODE_UP(IDL_NODE_UP(state->tree)) || IDL_NODE_TYPE(IDL_NODE_UP(IDL_NODE_UP(state->tree))) != IDLN_INTERFACE) { XPIDL_WARNING((state->tree, IDL_WARNING1, "A constant \"%s\" was declared outside an interface." " It was ignored.", name)); return TRUE; } /* * Make sure this is a numeric short or long constant. */ success = (IDLN_TYPE_INTEGER == IDL_NODE_TYPE(real_type)); if (success) { /* * We aren't successful yet, we know it's an integer, but what *kind* * of integer? */ switch(IDL_TYPE_INTEGER(real_type).f_type) { case IDL_INTEGER_TYPE_SHORT: /* * We're OK */ isshort = TRUE; break; case IDL_INTEGER_TYPE_LONG: /* * We're OK */ break; default: /* * Whoops, it's some other kind of number */ success = FALSE; } } else { IDL_tree_error(state->tree, "const declaration \'%s\' must be of type short or long", name); return FALSE; } /* if (doc_comments != NULL) { fputs(" ", state->file); printlist(state->file, doc_comments); } */ if (success) { /* Since Java does not have any concept of 'unsigned short', we need * to check that the value is in the proper range. If not, promote * it to an 'int'. */ int value = (int) IDL_INTEGER(declaration->const_exp).value; if (isshort && (value < -32768 || value > 32767)) isshort = FALSE; fputc('\n', state->file); xpidl_write_comment(state, 4); /* write_comment(state); */ fprintf(state->file, " public static final %s %s = %d;\n", (isshort ? "short" : "int"), subscriptIdentifier(state, (char*) name), (int) IDL_INTEGER(declaration->const_exp).value); } else { XPIDL_WARNING((state->tree, IDL_WARNING1, "A constant \"%s\" was not of type short or long." " It was ignored.", name)); } return TRUE; }