get_skel_* code
- From: Mark McLoughlin <mark skynet ie>
- To: <orbit-list gnome org>
- Subject: get_skel_* code
- Date: Wed, 4 Apr 2001 10:48:44 +0100 (IST)
Hi,
I noticed that the code generated for interface functions with
the same prefix wasn't very pretty. Try the output of orbit-idl with
something like this for example
interface testing {
void ReallyBigLongSimilarNames1();
void ReallyBigLongSimilarNames2();
};
Attached is a patch(against 0.5.7) that makes orbit-idl try to
find a index into all the function names that alows it to identify each
function with one switch, rather than a lot of nested ones. Note, I'm
not claiming this is more efficient, just cleaner.
For a realistic example of the cleanup, look at
get_skel_CosEventChannelAdmin_SupplierAdmin in CosEventChannel-skels.c
Cheers,
Mark
P.S. - pls CC me any replies.
diff -urp ORBit-0.5.7.old/src/orbit-idl-compiler/backends/c/orbit-idl-c-skels.c ORBit-0.5.7/src/orbit-idl-compiler/backends/c/orbit-idl-c-skels.c
--- ORBit-0.5.7.old/src/orbit-idl-compiler/backends/c/orbit-idl-c-skels.c Tue Jan 30 19:20:32 2001
+++ ORBit-0.5.7/src/orbit-idl-compiler/backends/c/orbit-idl-c-skels.c Wed Apr 4 11:15:47 2001
@@ -561,6 +561,35 @@ cbe_skel_compare_op_dcls(CBESkelOpInfo *
return strcmp(op1->opname, op2->opname);
}
+static gint
+cbe_skel_find_switch_index(GSList *ops)
+{
+ GSList *p = ops;
+ guint32 bits[8] = {0,0,0,0,0,0,0,0};
+ gint i;
+ char c;
+
+ for(i = 0; ;i++, p = ops) {
+ memset(bits, 0, 32);
+
+ while(p) {
+ c = ((CBESkelOpInfo *)p->data)->opname[i];
+ if ( bits[c/32] & 1<<(31-(c%32)) )
+ break;
+ else
+ bits[c/32] |= 1<<(31-(c%32));
+
+ p = g_slist_next(p);
+ }
+
+ if (p == NULL)
+ return i;
+ if ( bits[0] & 1<<31 )
+ return -1;
+ }
+ return -1;
+}
+
static void
cbe_skel_free_op_info(CBESkelOpInfo *op)
{
@@ -626,23 +655,32 @@ cbe_skel_interface_print_relayers(const
GSList *curnode;
CBESkelOpInfo *opi;
char curchar;
+ gboolean gotIndex;
+ gint index;
curnode = iti->oplist;
- subiti.curlevel = iti->curlevel+1;
- fprintf(iti->ci->fh, "switch(opname[%d]) {\n", iti->curlevel);
+ if ( iti->curlevel == 0 &&
+ (index = cbe_skel_find_switch_index(curnode)) != -1 )
+ gotIndex = TRUE;
+ else {
+ index = iti->curlevel;
+ gotIndex = FALSE;
+ }
+ subiti.curlevel = index+1;
+ fprintf(iti->ci->fh, "switch(opname[%d]) {\n", index);
while(curnode) {
opi = (CBESkelOpInfo *)curnode->data;
- if(iti->curlevel > strlen(opi->opname)) {
+ if(index > strlen(opi->opname)) {
curnode = g_slist_next(curnode);
continue;
}
- curchar = opi->opname[iti->curlevel];
+ curchar = opi->opname[index];
if(curchar)
fprintf(iti->ci->fh, "case '%c':\n", curchar);
else
fprintf(iti->ci->fh, "case '\\0':\n");
subiti.oplist = NULL;
- while(curnode && ((CBESkelOpInfo *)curnode->data)->opname[iti->curlevel]
+ while(curnode && ((CBESkelOpInfo *)curnode->data)->opname[index]
== curchar) {
subiti.oplist = g_slist_append(subiti.oplist, curnode->data);
curnode = g_slist_next(curnode);
@@ -654,12 +692,14 @@ cbe_skel_interface_print_relayers(const
else
g_error("two ops with same name!!!!");
} else {
- if(strlen(opi->opname + iti->curlevel))
- fprintf(iti->ci->fh, "if(strcmp((opname + %d), \"%s\")) break;\n", iti->curlevel + 1, opi->opname + iti->curlevel+1);
+ if(gotIndex)
+ fprintf(iti->ci->fh, "if(strcmp(opname, \"%s\")) break;\n", opi->opname);
+ else if(strlen(opi->opname + index))
+ fprintf(iti->ci->fh, "if(strcmp((opname + %d), \"%s\")) break;\n", index+1, opi->opname+index+1);
fprintf(iti->ci->fh, "*impl = (gpointer)servant->vepv->%s_epv->%s;\n",
- opi->iface_id, opi->opname);
- fprintf(iti->ci->fh, "return (ORBitSkeleton)_ORBIT_skel_%s_%s;\n",
- opi->iface_id, opi->opname);
+ opi->iface_id, opi->opname);
+ fprintf(iti->ci->fh, "return (ORBitSkeleton)_ORBIT_skel_%s_%s;\n",
+ opi->iface_id, opi->opname);
}
fprintf(iti->ci->fh, "break;\n");
g_slist_free(subiti.oplist);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]