Further warning enhancements engendered by 10693.

- Added xpidl_sprint_iid method for printing an nsID to a string.

- Removed "this is a gross hack" code for parsing and printing iids, and replaced with calls to xpidl_sprint_iid

- Made write_classname_iid_define() void, and removed cluttering tests against its failure.

- Cleaned up.
This commit is contained in:
mccabe%netscape.com 1999-08-02 11:19:30 +00:00
parent 3e1e43dd00
commit ed3c4eb1e7
4 changed files with 81 additions and 27 deletions

View File

@ -125,12 +125,30 @@ xpidl_process_node(TreeState *state);
void
xpidl_write_comment(TreeState *state, int indent);
/*
* Functions for parsing and printing UUIDs.
*/
#include "xpt_struct.h"
/*
* How large should the buffer supplied to xpidl_sprint_IID be?
*/
#define UUID_LENGTH 37
/*
* Print an iid to into a supplied buffer; the buffer should be at least
* UUID_LENGTH bytes.
*/
gboolean
xpidl_sprint_iid(struct nsID *iid, char iidbuf[]);
/*
* Parse a uuid string into an nsID struct. We cannot link against libxpcom,
* so we re-implement nsID::Parse here.
*/
gboolean
xpidl_parse_iid(nsID *id, char *str);
xpidl_parse_iid(nsID *id, const char *str);
#endif /* __xpidl_h */

View File

@ -68,7 +68,7 @@ pass_1(TreeState *state)
return TRUE;
}
static gboolean
static void
write_classname_iid_define(FILE *file, const char *className)
{
const char *iidName;
@ -82,7 +82,6 @@ write_classname_iid_define(FILE *file, const char *className)
while (*iidName)
fputc(toupper(*iidName++), file);
fputs("_IID", file);
return TRUE;
}
static gboolean
@ -92,6 +91,8 @@ interface(TreeState *state)
char *className = IDL_IDENT(IDL_INTERFACE(iface).ident).str;
const char *iid;
const char *name_space;
struct nsID id;
char iid_parsed[UUID_LENGTH];
fprintf(state->file, "\n/* starting interface: %s */\n",
className);
@ -107,24 +108,43 @@ interface(TreeState *state)
}
if (iid) {
/* XXX use nsID parsing routines to validate? */
/* Redundant, but a better error than 'cannot parse.' */
if (strlen(iid) != 36) {
IDL_tree_error(state->tree, "IID %s is the wrong length\n", iid);
return FALSE;
}
fprintf(state->file, "\n/* {%s} */\n#define ", iid);
if (!write_classname_iid_define(state->file, className))
/*
* Parse uuid and then output resulting nsID to string, to validate
* uuid and normalize resulting .h files.
*/
if (!xpidl_parse_iid(&id, iid)) {
IDL_tree_error(state->tree, "cannot parse IID %s\n", iid);
return FALSE;
fprintf(state->file, "_STR \"%s\"\n#define ", iid);
if (!write_classname_iid_define(state->file, className))
}
if (!xpidl_sprint_iid(&id, iid_parsed)) {
IDL_tree_error(state->tree, "error formatting IID %s\n", iid);
return FALSE;
/* This is such a gross hack... */
fprintf(state->file, " \\\n {0x%.8s, 0x%.4s, 0x%.4s, \\\n "
"{ 0x%.2s, 0x%.2s, 0x%.2s, 0x%.2s, "
"0x%.2s, 0x%.2s, 0x%.2s, 0x%.2s }}\n\n",
iid, iid + 9, iid + 14, iid + 19, iid + 21, iid + 24,
iid + 26, iid + 28, iid + 30, iid + 32, iid + 34);
}
/* #define NS_ISUPPORTS_IID_STR "00000000-0000-0000-c000-000000000046" */
fprintf(state->file, "\n");
fprintf(state->file, "#define ");
write_classname_iid_define(state->file, className);
fprintf(state->file, "_STR \"%s\"\n", iid_parsed);
/* #define NS_ISUPPORTS_IID { {0x00000000 .... 0x46 }} */
fprintf(state->file, "#define ");
write_classname_iid_define(state->file, className);
fprintf(state->file, " \\\n"
" {0x%.8x, 0x%.4x, 0x%.4x, \\\n"
" { 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, "
"0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x }}\n\n",
id.m0, id.m1, id.m2,
id.m3[0], id.m3[1], id.m3[2], id.m3[3],
id.m3[4], id.m3[5], id.m3[6], id.m3[7]);
}
fprintf(state->file, "class %s", className);
if ((iter = IDL_INTERFACE(iface).inheritance_spec)) {
fputs(" : ", state->file);
@ -139,8 +159,7 @@ interface(TreeState *state)
" public: \n", state->file);
if (iid) {
fputs(" NS_DEFINE_STATIC_IID_ACCESSOR(", state->file);
if (!write_classname_iid_define(state->file, className))
return FALSE;
write_classname_iid_define(state->file, className);
fputs(")\n", state->file);
}

View File

@ -739,6 +739,25 @@ xpidl_write_comment(TreeState *state, int indent)
fputs(" */\n", state->file);
}
/*
* Print an iid to into a supplied buffer; the buffer should be at least
* UUID_LENGTH bytes.
*/
gboolean
xpidl_sprint_iid(struct nsID *id, char iidbuf[])
{
int printed;
printed = sprintf(iidbuf,
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
(PRUint32) id->m0, (PRUint32) id->m1,(PRUint32) id->m2,
(PRUint32) id->m3[0], (PRUint32) id->m3[1],
(PRUint32) id->m3[2], (PRUint32) id->m3[3],
(PRUint32) id->m3[4], (PRUint32) id->m3[5],
(PRUint32) id->m3[6], (PRUint32) id->m3[7]);
return (printed == 36);
}
/* We only parse the {}-less format. (xpidl_header never has, so we're safe.) */
static const char nsIDFmt2[] =
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x";
@ -748,7 +767,7 @@ static const char nsIDFmt2[] =
* so we re-implement nsID::Parse here.
*/
gboolean
xpidl_parse_iid(struct nsID *id, char *str)
xpidl_parse_iid(struct nsID *id, const char *str)
{
PRInt32 count = 0;
PRInt32 n1, n2, n3[8];

View File

@ -197,20 +197,13 @@ find_interfaces(IDL_tree_func_data *tfd, gpointer user_data)
#ifdef DEBUG_shaver
/* for calling from gdb */
/* this should (instead) print to a string... and be the validator for iid
* handling in header mode. Don't forget also to check in the code in
* nsID.cpp.
*/
static void
print_IID(struct nsID *iid, FILE *file)
{
fprintf(file, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
(PRUint32) iid->m0, (PRUint32) iid->m1,(PRUint32) iid->m2,
(PRUint32) iid->m3[0], (PRUint32) iid->m3[1],
(PRUint32) iid->m3[2], (PRUint32) iid->m3[3],
(PRUint32) iid->m3[4], (PRUint32) iid->m3[5],
(PRUint32) iid->m3[6], (PRUint32) iid->m3[7]);
char iid_buf[UUID_LENGTH];
xpidl_sprint_iid(id, iid_buf);
fprintf(file, "%s\n", iid_buf);
}
#endif
@ -230,6 +223,11 @@ fill_ide_table(gpointer key, gpointer value, gpointer user_data)
#endif
if (holder->iid) {
if (strlen(holder->iid) != 36) {
IDL_tree_error(state->tree, "IID %s is the wrong length\n",
holder->iid);
return FALSE;
}
if (!xpidl_parse_iid(&id, holder->iid)) {
IDL_tree_error(state->tree, "cannot parse IID %s\n", holder->iid);
return FALSE;